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


Python units.kg方法代码示例

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


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

示例1: test_gen_mass

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

        Approach: Ensures the output is set, of the correct type, length, and units.
        Check the range of the returned values.  Check that, for this power law, there
        are more small than large masses (for n large).
        """

        plan_pop = self.fixture
        n = 10000
        # call the routine
        masses = plan_pop.gen_mass(n)
        # check the type
        self.assertEqual(type(masses), type(1.0 * u.kg))
        # crude check on the shape (more small than large for this power law)
        midpoint = np.mean(plan_pop.Mprange)
        self.assertGreater(np.count_nonzero(masses < midpoint),
                           np.count_nonzero(masses > midpoint))
        # test some illegal "n" values
        n_list_bad = [-1, '100', 22.5]
        for n in n_list_bad:
            with self.assertRaises(AssertionError):
                masses = plan_pop.gen_mass(n) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:25,代码来源:test_KnownRVPlanets.py

示例2: calc_radius_from_mass

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def calc_radius_from_mass(self, Mp):
        """Helper function for calculating radius given the mass.
        
        Prototype provides only a dummy function that assumes a density of water.
        
        Args:
            Mp (astropy Quantity array):
                Planet mass in units of Earth mass
        
        Returns:
            Rp (astropy Quantity array):
                Planet radius in units of Earth radius
        
        """
        
        rho = 1000*u.kg/u.m**3.
        Rp = ((3.*Mp/rho/np.pi/4.)**(1./3.)).to('earthRad')
        
        return Rp 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:21,代码来源:PlanetPhysicalModel.py

示例3: test_unit_mismatch

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

        q_len = u.Quantity([1], u.km)
        q_nonlen = u.Quantity([1], u.kg)

        with pytest.raises(u.UnitsError) as exc:
            s1 = CartesianRepresentation(x=q_nonlen, y=q_len, z=q_len)
        assert exc.value.args[0] == "x, y, and z should have matching physical types"

        with pytest.raises(u.UnitsError) as exc:
            s1 = CartesianRepresentation(x=q_len, y=q_nonlen, z=q_len)
        assert exc.value.args[0] == "x, y, and z should have matching physical types"

        with pytest.raises(u.UnitsError) as exc:
            s1 = CartesianRepresentation(x=q_len, y=q_len, z=q_nonlen)
        assert exc.value.args[0] == "x, y, and z should have matching physical types" 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_representation.py

示例4: test_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_units():
    plt.figure()

    with quantity_support():
        buff = io.BytesIO()

        plt.plot([1, 2, 3] * u.m, [3, 4, 5] * u.kg, label='label')
        plt.plot([105, 210, 315] * u.cm, [3050, 3025, 3010] * u.g)
        plt.legend()
        # Also test fill_between, which requires actual conversion to ndarray
        # with numpy >=1.10 (#4654).
        plt.fill_between([1, 3] * u.m, [3, 5] * u.kg, [3050, 3010] * u.g)
        plt.savefig(buff, format='svg')

        assert plt.gca().xaxis.get_units() == u.m
        assert plt.gca().yaxis.get_units() == u.kg 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_units.py

示例5: test_quantity_subclass

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_quantity_subclass():
    """Check that subclasses are recognized.

    This sadly is not done by matplotlib.units itself, though
    there is a PR to change it:
    https://github.com/matplotlib/matplotlib/pull/13536
    """
    plt.figure()

    with quantity_support():
        plt.scatter(Angle([1, 2, 3], u.deg), [3, 4, 5] * u.kg)
        plt.scatter([105, 210, 315] * u.arcsec, [3050, 3025, 3010] * u.g)
        plt.plot(Angle([105, 210, 315], u.arcsec), [3050, 3025, 3010] * u.g)

        assert plt.gca().xaxis.get_units() == u.deg
        assert plt.gca().yaxis.get_units() == u.kg 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_units.py

示例6: test_nested

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

    with quantity_support():

        with quantity_support():

            fig = plt.figure()
            ax = fig.add_subplot(1, 1, 1)
            ax.scatter(Angle([1, 2, 3], u.deg), [3, 4, 5] * u.kg)

            assert ax.xaxis.get_units() == u.deg
            assert ax.yaxis.get_units() == u.kg

        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)
        ax.scatter(Angle([1, 2, 3], u.arcsec), [3, 4, 5] * u.pc)

        assert ax.xaxis.get_units() == u.arcsec
        assert ax.yaxis.get_units() == u.pc 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_units.py

示例7: test_complicated_operation

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_complicated_operation(self):
        """ Perform a more complicated test """
        from astropy.units import imperial

        # Multiple units
        distance = u.Quantity(15., u.meter)
        time = u.Quantity(11., u.second)

        velocity = (distance / time).to(imperial.mile / u.hour)
        assert_array_almost_equal(
            velocity.value, 3.05037, decimal=5)

        G = u.Quantity(6.673E-11, u.m ** 3 / u.kg / u.s ** 2)
        new_q = ((1. / (4. * np.pi * G)).to(u.pc ** -3 / u.s ** -2 * u.kg))

        # Area
        side1 = u.Quantity(11., u.centimeter)
        side2 = u.Quantity(7., u.centimeter)
        area = side1 * side2
        assert_array_almost_equal(area.value, 77., decimal=15)
        assert area.unit == u.cm * u.cm 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_quantity.py

示例8: test_compose_fractional_powers

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_compose_fractional_powers():
    # Warning: with a complicated unit, this test becomes very slow;
    # e.g., x = (u.kg / u.s ** 3 * u.au ** 2.5 / u.yr ** 0.5 / u.sr ** 2)
    # takes 3 s
    x = u.m ** 0.5 / u.yr ** 1.5

    factored = x.compose()

    for unit in factored:
        assert x.decompose() == unit.decompose()

    factored = x.compose(units=u.cgs)

    for unit in factored:
        assert x.decompose() == unit.decompose()

    factored = x.compose(units=u.si)

    for unit in factored:
        assert x.decompose() == unit.decompose() 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_units.py

示例9: test_comparison_valid_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_comparison_valid_units(self, ufunc):
        q_i1 = np.array([-3.3, 2.1, 10.2]) * u.kg / u.s
        q_i2 = np.array([10., -5., 1.e6]) * u.g / u.Ms
        q_o = ufunc(q_i1, q_i2)
        assert not isinstance(q_o, u.Quantity)
        assert q_o.dtype == bool
        assert np.all(q_o == ufunc(q_i1.value, q_i2.to_value(q_i1.unit)))
        q_o2 = ufunc(q_i1 / q_i2, 2.)
        assert not isinstance(q_o2, u.Quantity)
        assert q_o2.dtype == bool
        assert np.all(q_o2 == ufunc((q_i1 / q_i2)
                                    .to_value(u.dimensionless_unscaled), 2.))
        # comparison with 0., inf, nan is OK even for dimensional quantities
        # (though ignore numpy runtime warnings for comparisons with nan).
        with catch_warnings(RuntimeWarning):
            for arbitrary_unit_value in (0., np.inf, np.nan):
                ufunc(q_i1, arbitrary_unit_value)
                ufunc(q_i1, arbitrary_unit_value*np.ones(len(q_i1)))
            # and just for completeness
            ufunc(q_i1, np.array([0., np.inf, np.nan])) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_quantity_ufuncs.py

示例10: test_radian

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_radian(self, function):
            q1 = function(180. * u.degree, 0. * u.arcmin, 0. * u.arcsec)
            assert_allclose(q1.value, np.pi)
            assert q1.unit == u.radian

            q2 = function(0. * u.degree, 30. * u.arcmin, 0. * u.arcsec)
            assert_allclose(q2.value, (30. * u.arcmin).to(u.radian).value)
            assert q2.unit == u.radian

            q3 = function(0. * u.degree, 0. * u.arcmin, 30. * u.arcsec)
            assert_allclose(q3.value, (30. * u.arcsec).to(u.radian).value)

            # the following doesn't make much sense in terms of the name of the
            # routine, but we check it gives the correct result.
            q4 = function(3. * u.radian, 0. * u.arcmin, 0. * u.arcsec)
            assert_allclose(q4.value, 3.)
            assert q4.unit == u.radian

            with pytest.raises(TypeError):
                function(3. * u.m, 2. * u.s, 1. * u.kg) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_quantity_ufuncs.py

示例11: test_is_equivalent

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def test_is_equivalent():
    assert u.m.is_equivalent(u.pc)
    assert u.cycle.is_equivalent(u.mas)
    assert not u.cycle.is_equivalent(u.dimensionless_unscaled)
    assert u.cycle.is_equivalent(u.dimensionless_unscaled,
                                 u.dimensionless_angles())
    assert not (u.Hz.is_equivalent(u.J))
    assert u.Hz.is_equivalent(u.J, u.spectral())
    assert u.J.is_equivalent(u.Hz, u.spectral())
    assert u.pc.is_equivalent(u.arcsecond, u.parallax())
    assert u.arcminute.is_equivalent(u.au, u.parallax())

    # Pass a tuple for multiple possibilities
    assert u.cm.is_equivalent((u.m, u.s, u.kg))
    assert u.ms.is_equivalent((u.m, u.s, u.kg))
    assert u.g.is_equivalent((u.m, u.s, u.kg))
    assert not u.L.is_equivalent((u.m, u.s, u.kg))
    assert not (u.km / u.s).is_equivalent((u.m, u.s, u.kg)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_equivalencies.py

示例12: mass_dec

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def mass_dec(self, dF_lateral, t_int):
        """Returns mass_used and deltaV 
        
        The values returned by this method are used to decrement spacecraft 
        mass for station-keeping.
        
        Args:
            dF_lateral (astropy Quantity):
                Lateral disturbance force in units of N
            t_int (astropy Quantity):
                Integration time in units of day
                
        Returns:
            tuple:
            intMdot (astropy Quantity):
                Mass flow rate in units of kg/s
            mass_used (astropy Quantity):
                Mass used in station-keeping units of kg
            deltaV (astropy Quantity):
                Change in velocity required for station-keeping in units of km/s
        
        """
        
        intMdot = (1./np.cos(np.radians(45))*np.cos(np.radians(5))*
                dF_lateral/const.g0/self.skIsp).to('kg/s')
        mass_used = (intMdot*t_int).to('kg')
        deltaV = (dF_lateral/self.scMass*t_int).to('km/s')
        
        return intMdot, mass_used, deltaV 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:31,代码来源:Observatory.py

示例13: mass_dec_sk

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def mass_dec_sk(self, TL, sInd, currentTime, t_int):
        """Returns mass_used, deltaV and disturbance forces
        
        This method calculates all values needed to decrement spacecraft mass
        for station-keeping.
        
        Args:
            TL (TargetList module):
                TargetList class object
            sInd (integer):
                Integer index of the star of interest
            currentTime (astropy Time):
                Current absolute mission time in MJD
            t_int (astropy Quantity):
                Integration time in units of day
                
        Returns:
            tuple:
            dF_lateral (astropy Quantity):
                Lateral disturbance force in units of N
            dF_axial (astropy Quantity):
                Axial disturbance force in units of N
            intMdot (astropy Quantity):
                Mass flow rate in units of kg/s
            mass_used (astropy Quantity):
                Mass used in station-keeping units of kg
            deltaV (astropy Quantity):
                Change in velocity required for station-keeping in units of km/s
        
        """
        
        dF_lateral, dF_axial = self.distForces(TL, sInd, currentTime)
        intMdot, mass_used, deltaV = self.mass_dec(dF_lateral, t_int)
        
        return dF_lateral, dF_axial, intMdot, mass_used, deltaV 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:37,代码来源:Observatory.py

示例14: log_occulterResults

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def log_occulterResults(self,DRM,slewTimes,sInd,sd,dV):
        """Updates the given DRM to include occulter values and results
        
        Args:
            DRM (dict):
                Design Reference Mission, contains the results of one complete
                observation (detection and characterization)
            slewTimes (astropy Quantity):
                Time to transfer to new star line of sight in units of days
            sInd (integer):
                Integer index of the star of interest
            sd (astropy Quantity):
                Angular separation between stars in rad
            dV (astropy Quantity):
                Delta-V used to transfer to new star line of sight in units of m/s
                
        Returns:
            dict:
                Design Reference Mission dictionary, contains the results of one complete
                observation (detection and characterization)
        
        """
        
        DRM['slew_time'] = slewTimes.to('day')
        DRM['slew_angle'] = sd.to('deg')
        
        slew_mass_used = slewTimes*self.defburnPortion*self.flowRate
        DRM['slew_dV'] = (slewTimes*self.ao*self.defburnPortion).to('m/s')
        DRM['slew_mass_used'] = slew_mass_used.to('kg')
        self.scMass = self.scMass - slew_mass_used
        DRM['scMass'] = self.scMass.to('kg')
        
        return DRM 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:35,代码来源:Observatory.py

示例15: columnar_content_reduced_liquid

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import kg [as 别名]
def columnar_content_reduced_liquid(lat, lon, p):
    """
    A method to compute the total columnar content of reduced cloud liquid
    water, Lred (kg/m2), exceeded for p% of the average year


    Parameters
    ----------
    lat : number, sequence, or numpy.ndarray
        Latitudes of the receiver points
    lon : number, sequence, or numpy.ndarray
        Longitudes of the receiver points
    p : number
        Percentage of time exceeded for p% of the average year


    Returns
    -------
    Lred: numpy.ndarray
        Total columnar content of reduced cloud liquid water, Lred (kg/m2),
        exceeded for p% of the average year



    References
    ----------
    [1] Attenuation due to clouds and fog:
    https://www.itu.int/rec/R-REC-P.840/en
    """
    global __model
    type_output = type(lat)
    lat = prepare_input_array(lat)
    lon = prepare_input_array(lon)
    lon = np.mod(lon, 360)
    val = __model.columnar_content_reduced_liquid(lat, lon, p)
    return prepare_output_array(val, type_output) * u.kg / u.m**2 
开发者ID:iportillo,项目名称:ITU-Rpy,代码行数:38,代码来源:itu840.py


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