当前位置: 首页>>代码示例>>Python>>正文


Python units.dimensionless_unscaled方法代码示例

本文整理汇总了Python中astropy.units.dimensionless_unscaled方法的典型用法代码示例。如果您正苦于以下问题:Python units.dimensionless_unscaled方法的具体用法?Python units.dimensionless_unscaled怎么用?Python units.dimensionless_unscaled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy.units的用法示例。


在下文中一共展示了units.dimensionless_unscaled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_gen_sma

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def test_gen_sma(self):
        r"""Test gen_sma method.

        Approach: Ensures the output is set, of the correct type, length, and units.
        Check that they are in the correct range and follow the distribution.
        """

        plan_pop = self.fixture
        n = 10000
        sma = plan_pop.gen_sma(n)

        # ensure the units are length
        self.assertEqual((sma/u.km).decompose().unit, u.dimensionless_unscaled)
        # sma > 0
        self.assertTrue(np.all(sma.value >= 0))
        # sma >= arange[0], sma <= arange[1]
        self.assertTrue(np.all(sma - plan_pop.arange[0] >= 0))
        self.assertTrue(np.all(plan_pop.arange[1] - sma >= 0))

        h = np.histogram(sma.to('AU').value,100,density=True)
        hx = np.diff(h[1])/2.+h[1][:-1]
        hp = plan_pop.dist_sma(hx)

        chi2 = scipy.stats.chisquare(h[0],hp)
        self.assertGreaterEqual(chi2[1],0.95) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:27,代码来源:test_KeplerLike2.py

示例2: test_gen_radius

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def test_gen_radius(self):
        r"""Test gen_radius method.

        Approach: Ensures the output is set, of the correct type, length, and units.
        Check distributional agreement.
        """
        plan_pop = self.fixture
        n = 10000
        radii = plan_pop.gen_radius(n)

        # ensure the units are length
        self.assertEqual((radii/u.km).decompose().unit, u.dimensionless_unscaled)
        # radius > 0
        self.assertTrue(np.all(radii.value > 0))
        self.assertTrue(np.all(np.isfinite(radii.value)))

        h = np.histogram(radii.to('earthRad').value,bins=plan_pop.Rs)
        np.testing.assert_allclose(plan_pop.Rvals.sum()*h[0]/float(n),plan_pop.Rvals,rtol=0.05) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:20,代码来源:test_KeplerLike1.py

示例3: i8_mag15s

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def i8_mag15s(starttime, endtime):
    identifier = 'I8_15SEC_MAG'
    units = OrderedDict([('N_of_points', u.dimensionless_unscaled),
                         ('SourceFlag', u.dimensionless_unscaled),
                         ('|B|', u.nT),
                         ('Bx gse', u.nT), ('By gse', u.nT),
                         ('Bz gse', u.nT), ('By gsm', u.nT),
                         ('Bz gsm', u.nT), ('Bxx gse', u.nT**2),
                         ('Byy gse', u.nT**2), ('Bzz gse', u.nT**2),
                         ('Byx gse', u.nT**2), ('Bzx gse', u.nT**2),
                         ('Bzy gse', u.nT**2), ('Time shift', u.s),
                         ('SW_flag', u.dimensionless_unscaled)])
    for coord in ['GSE', 'GSET', 'GSM', 'GSMT']:
        for i in range(3):
            units[f'SC_Pos_{coord}_{i}'] = u.earthRad
    return _imp8(starttime, endtime, identifier, units=units) 
开发者ID:heliopython,项目名称:heliopy,代码行数:18,代码来源:imp.py

示例4: __init__

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def __init__(self, name, extension_name, extension_wave=None,
                 extension_ivar=None, extension_mask=None, db_table='spaxel',
                 unit=u.dimensionless_unscaled, scale=1, formats={},
                 pixmask_flag='MANGA_DRP3PIXMASK', description=''):

        self.name = name

        self._extension_name = extension_name
        self._extension_wave = extension_wave
        self._extension_ivar = extension_ivar
        self._extension_mask = extension_mask

        self.pixmask_flag = pixmask_flag

        self.db_table = db_table

        self._parent = None

        self.formats = formats

        self.description = description

        self.unit = u.CompositeUnit(scale, unit.bases, unit.powers) 
开发者ID:sdss,项目名称:marvin,代码行数:25,代码来源:base.py

示例5: test_set_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def test_set_units():

    p = Parameter('test_parameter',1.0, unit=u.keV)

    p.value = 3.0 * u.MeV

    assert p.value == 3000.0

    with pytest.raises(u.UnitConversionError):

        p.value = 3.0 * u.cm

    with pytest.raises(CannotConvertValueToNewUnits):

        p.unit = u.cm

    with pytest.raises(CannotConvertValueToNewUnits):

        p.unit = u.dimensionless_unscaled

    p.unit = u.MeV

    assert p.unit == u.MeV

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:27,代码来源:test_parameter.py

示例6: _set_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def _set_units(self, x_unit, y_unit):
        # The index is always dimensionless
        self.index.unit = astropy_units.dimensionless_unscaled
        self.gamma.unit = astropy_units.dimensionless_unscaled

        # The pivot energy has always the same dimension as the x variable
        self.piv.unit = x_unit

        # The cutoff has the same dimensions as x
        self.xc.unit = x_unit

        # The normalization has the same units as the y

        self.K.unit = y_unit

    # noinspection PyPep8Naming 
开发者ID:threeML,项目名称:astromodels,代码行数:18,代码来源:functions.py

示例7: evaluate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def evaluate(self, x, NH, redshift):

            if isinstance(x, astropy_units.Quantity):

                _unit = astropy_units.cm ** 2
                _y_unit = astropy_units.dimensionless_unscaled
                _x = x.value

            else:

                _unit = 1.0
                _y_unit = 1.0

                _x = x

            xsect_interp = self._cached_interp(_x * (1 + redshift))

            spec = np.exp(-NH * xsect_interp * _unit) * _y_unit

            return spec


    # TbAbs class 
开发者ID:threeML,项目名称:astromodels,代码行数:25,代码来源:apec.py

示例8: set_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def set_units(self, x_unit, y_unit, relaxed=False):

        if relaxed and (x_unit is None) and (y_unit is None):

            # This can happen when rebuilding a composite function during unpickling, when
            # there are more than two functions composed together. We do not need to to anything in that case
            pass

        else:

            self._requested_x_unit = x_unit
            self._requested_y_unit = y_unit

            # Just rely on the single functions to adjust themselves.

            for function in self.functions:

                if hasattr(function, '_make_dimensionless'):

                    function.set_units(x_unit, u.dimensionless_unscaled)

                else:

                    function.set_units(x_unit, y_unit) 
开发者ID:threeML,项目名称:astromodels,代码行数:26,代码来源:function.py

示例9: _set_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def _set_units(self, x_unit, y_unit, z_unit, w_unit):

        # lon0 and lat0 and rdiff have most probably all units of degrees. However,
        # let's set them up here just to save for the possibility of using the
        # formula with other units (although it is probably never going to happen)

        self.lon0.unit = x_unit
        self.lat0.unit = y_unit
        self.rdiff0.unit = x_unit

        # Delta is of course unitless

        self.delta.unit = u.dimensionless_unscaled
        self.b.unit = u.dimensionless_unscaled
        self.incl.unit = x_unit
        self.elongation.unit = u.dimensionless_unscaled

        # Piv has the same unit as energy (which is z)

        self.piv.unit = z_unit
        self.piv2.unit = z_unit 
开发者ID:threeML,项目名称:astromodels,代码行数:23,代码来源:functions_3D.py

示例10: _calculate_conversion

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def _calculate_conversion(self):

        # convert the model to the right units so that we can
        # convert back later for speed

        tmp = self._model_converter[self._flux_type](self._test_value)

        if (
            tmp.unit == u.dimensionless_unscaled
            or tmp.unit == self._test_value.unit
            or tmp.unit == (self._test_value.unit) ** 2
        ):

            # this is a multiplicative model
            self._conversion = 1.0
            self._is_dimensionless = True

        else:

            self._conversion = tmp.unit.to(self._flux_unit, equivalencies=u.spectral())
            self._is_dimensionless = False 
开发者ID:threeML,项目名称:threeML,代码行数:23,代码来源:fitted_point_sources.py

示例11: test_mul_div_unit_spherical

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def test_mul_div_unit_spherical(self):
        s1 = self.unit_spherical * self.distance
        assert isinstance(s1, SphericalRepresentation)
        assert np.all(s1.lon == self.unit_spherical.lon)
        assert np.all(s1.lat == self.unit_spherical.lat)
        assert np.all(s1.distance == self.spherical.distance)
        s2 = self.unit_spherical / u.s
        assert isinstance(s2, SphericalRepresentation)
        assert np.all(s2.lon == self.unit_spherical.lon)
        assert np.all(s2.lat == self.unit_spherical.lat)
        assert np.all(s2.distance == 1./u.s)
        u3 = -self.unit_spherical
        assert isinstance(u3, UnitSphericalRepresentation)
        assert_quantity_allclose(u3.lon, self.unit_spherical.lon + 180.*u.deg)
        assert np.all(u3.lat == -self.unit_spherical.lat)
        assert_quantity_allclose(u3.to_cartesian().xyz,
                                 -self.unit_spherical.to_cartesian().xyz,
                                 atol=1.e-10*u.dimensionless_unscaled)
        u4 = +self.unit_spherical
        assert isinstance(u4, UnitSphericalRepresentation)
        assert u4 is not self.unit_spherical
        assert np.all(representation_equal(u4, self.unit_spherical)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:test_representation_arithmetic.py

示例12: test_dot

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def test_dot(self, representation):
        in_rep = self.cartesian.represent_as(representation)
        r_dot_r = in_rep.dot(in_rep)
        assert isinstance(r_dot_r, u.Quantity)
        assert r_dot_r.shape == in_rep.shape
        assert_quantity_allclose(np.sqrt(r_dot_r), self.distance)
        r_dot_r_rev = in_rep.dot(in_rep[::-1])
        assert isinstance(r_dot_r_rev, u.Quantity)
        assert r_dot_r_rev.shape == in_rep.shape
        expected = [-25., -126., 2., 4., 2., -126., -25.] * u.kpc**2
        assert_quantity_allclose(r_dot_r_rev, expected)
        for axis in 'xyz':
            project = CartesianRepresentation(*(
                (1. if axis == _axis else 0.) * u.dimensionless_unscaled
                for _axis in 'xyz'))
            assert_quantity_allclose(in_rep.dot(project),
                                     getattr(self.cartesian, axis),
                                     atol=1.*u.upc)
        with pytest.raises(TypeError):
            in_rep.dot(self.cartesian.xyz) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_representation_arithmetic.py

示例13: test_critical_density

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def test_critical_density():
    from astropy.constants import codata2014

    # WMAP7 but with Omega_relativistic = 0
    # These tests will fail if astropy.const starts returning non-mks
    #  units by default; see the comment at the top of core.py.
    # critical_density0 is inversely proportional to G.
    tcos = core.FlatLambdaCDM(70.4, 0.272, Tcmb0=0.0)
    fac = (const.G / codata2014.G).to(u.dimensionless_unscaled).value
    assert allclose(tcos.critical_density0 * fac,
                    9.309668456020899e-30 * (u.g / u.cm**3))
    assert allclose(tcos.critical_density0,
                    tcos.critical_density(0))
    assert allclose(
        tcos.critical_density([1, 5]) * fac,
        [2.70352772e-29, 5.53739080e-28] * (u.g / u.cm**3))
    assert allclose(
        tcos.critical_density([1., 5.]) * fac,
        [2.70352772e-29, 5.53739080e-28] * (u.g / u.cm**3)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_cosmology.py

示例14: default

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def default(self, obj):
        from astropy import units as u
        import numpy as np
        if isinstance(obj, u.Quantity):
            return dict(value=obj.value, unit=obj.unit.to_string())
        if isinstance(obj, (np.number, np.ndarray)):
            return obj.tolist()
        elif isinstance(obj, complex):
            return [obj.real, obj.imag]
        elif isinstance(obj, set):
            return list(obj)
        elif isinstance(obj, bytes):  # pragma: py3
            return obj.decode()
        elif isinstance(obj, (u.UnitBase, u.FunctionUnitBase)):
            if obj == u.dimensionless_unscaled:
                obj = 'dimensionless_unit'
            else:
                return obj.to_string()

        return json.JSONEncoder.default(self, obj) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:misc.py

示例15: _create_augmented_matrix

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import dimensionless_unscaled [as 别名]
def _create_augmented_matrix(matrix, translation):
        unit = None
        if any([hasattr(translation, 'unit'), hasattr(matrix, 'unit')]):
            if not all([hasattr(translation, 'unit'), hasattr(matrix, 'unit')]):
                raise ValueError("To use AffineTransformation with quantities, "
                                 "both matrix and unit need to be quantities.")
            unit = translation.unit
            # matrix should have the same units as translation
            if not (matrix.unit / translation.unit) == u.dimensionless_unscaled:
                raise ValueError("matrix and translation must have the same units.")

        augmented_matrix = np.empty((3, 3), dtype=float)
        augmented_matrix[0:2, 0:2] = matrix
        augmented_matrix[0:2, 2:].flat = translation
        augmented_matrix[2] = [0, 0, 1]
        if unit is not None:
            return augmented_matrix * unit
        else:
            return augmented_matrix 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:projections.py


注:本文中的astropy.units.dimensionless_unscaled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。