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


Python units.km方法代码示例

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


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

示例1: test_orbit

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def test_orbit(self):
        """
        Test orbit method to ensure proper output
        """

        t_ref = Time(2000.0, format='jyear')
        for mod in self.allmods:
            with RedirectStreams(stdout=self.dev_null):
                if 'SotoStarshade' in mod.__name__:
                    obj = mod(f_nStars=4, **copy.deepcopy(self.spec))
                else:
                    obj = mod(**copy.deepcopy(self.spec))
            r_sc = obj.orbit(t_ref)
            # the r_sc attribute is set and is a 3-tuple of astropy Quantity's
            self.assertEqual(type(r_sc), type(1.0 * u.km))
            self.assertEqual(r_sc.shape, (1, 3)) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:18,代码来源:test_Observatory.py

示例2: test_gen_sma

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [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

示例3: test_gen_radius

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [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

示例4: test_moon_earth

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

        Approach: Reference to pre-computed result from Matlab.
        """

        print('moon_earth()')
        obs = self.fixture
        # TODO: add other times besides this one
        # century = 0
        t_ref_string = '2000-01-01T12:00:00.0'
        t_ref = Time(t_ref_string, format='isot', scale='utc')
        moon = obs.moon_earth(t_ref).flatten().to(u.km)
        # print moon
        r_earth = 6378.137 # earth radius [km], as used in Vallado's code
        moon_ref = [-45.74169421, -41.80825511, -11.88954996] # pre-computed from Matlab
        for coord in range(3):
            self.assertAlmostEqual(moon[coord].value, moon_ref[coord] * r_earth, places=1) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:20,代码来源:test_Observatory.py

示例5: __init__

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def __init__(self, a, e, I, O, w, lM):
            
            # store list of semimajor axis values (convert from AU to km)
            self.a = (a*u.AU).to('km').value
            if not isinstance(self.a, float):
                self.a = self.a.tolist()
            # store list of dimensionless eccentricity values
            self.e = e
            # store list of inclination values (degrees)
            self.I = I
            # store list of right ascension of ascending node values (degrees)
            self.O = O 
            # store list of longitude of periapsis values (degrees)
            self.w = w 
            # store list of mean longitude values (degrees)
            self.lM = lM 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:18,代码来源:Observatory.py

示例6: s_a

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def s_a(self, lat, lon):
        """ Standard deviation of terrain heights (m) within a 110 km × 110 km
        area with a 30 s resolution (e.g. the Globe “gtopo30” data).
        The value for the mid-path may be obtained from an area roughness
        with 0.5 × 0.5 degree resolution of geographical coordinates
        using bi-linear interpolation.
        """
        if not self._s_a:
            vals = load_data(os.path.join(dataset_dir, '530/v16_gtopo_30.txt'))
            lats = load_data(os.path.join(dataset_dir, '530/v16_lat.txt'))
            lons = load_data(os.path.join(dataset_dir, '530/v16_lon.txt'))
            self._Pr6 = bilinear_2D_interpolator(lats, lons, vals)

        return self._Pr6(
            np.array([lat.ravel(), lon.ravel()]).T).reshape(lat.shape)

    ###########################################################################
    #                               Section 2.2                               #
    ########################################################################### 
开发者ID:iportillo,项目名称:ITU-Rpy,代码行数:21,代码来源:itu530.py

示例7: test_all_to_value

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def test_all_to_value():
    """test all_to_value"""
    x_m = np.arange(5) * u.m
    y_mm = np.arange(5) * 1000 * u.mm
    z_km = np.arange(5) * 1e-3 * u.km
    nono_deg = np.arange(5) * 1000 * u.deg

    # one argument
    x = all_to_value(x_m, unit=u.m)
    assert (x == np.arange(5)).all()

    # two arguments
    x, y = all_to_value(x_m, y_mm, unit=u.m)
    assert (x == np.arange(5)).all()
    assert (y == np.arange(5)).all()

    # three
    x, y, z = all_to_value(x_m, y_mm, z_km, unit=u.m)
    assert (x == np.arange(5)).all()
    assert (y == np.arange(5)).all()
    assert (z == np.arange(5)).all()

    # cannot be converted
    with pytest.raises(u.UnitConversionError):
        all_to_value(x_m, nono_deg, unit=x_m.unit) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:27,代码来源:test_quantities.py

示例8: plot_spectrum

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def plot_spectrum(self):
        ''' Plot the HI spectrum '''

        if self._specfile:
            if not self._specdata:
                self._specdata = self._get_data(self._specfile)

            vel = self._specdata['VHI'][0]
            flux = self._specdata['FHI'][0]
            spec = Spectrum(flux, unit=u.Jy, wavelength=vel,
                            wavelength_unit=u.km / u.s)
            ax = spec.plot(
                ylabel='HI\ Flux', xlabel='Velocity', title=self.targetid, ytrim='minmax'
            )
            return ax
        return None

#
# Functions to become available on your VAC in marvin.tools.vacs.VACs 
开发者ID:sdss,项目名称:marvin,代码行数:21,代码来源:hi.py

示例9: test_nddata_init_data_nddata_subclass

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def test_nddata_init_data_nddata_subclass():
    uncert = StdDevUncertainty(3)
    # There might be some incompatible subclasses of NDData around.
    bnd = BadNDDataSubclass(False, True, 3, 2, 'gollum', 100)
    # Before changing the NDData init this would not have raised an error but
    # would have lead to a compromised nddata instance
    with pytest.raises(TypeError):
        NDData(bnd)

    # but if it has no actual incompatible attributes it passes
    bnd_good = BadNDDataSubclass(np.array([1, 2]), uncert, 3, HighLevelWCSWrapper(WCS(naxis=1)),
                                 {'enemy': 'black knight'}, u.km)
    nd = NDData(bnd_good)
    assert nd.unit == bnd_good.unit
    assert nd.meta == bnd_good.meta
    assert nd.uncertainty == bnd_good.uncertainty
    assert nd.mask == bnd_good.mask
    assert nd.wcs is bnd_good.wcs
    assert nd.data is bnd_good.data 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_nddata.py

示例10: test_param_unit

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def test_param_unit():
    with pytest.raises(ValueError):
        NDData(np.ones((5, 5)), unit="NotAValidUnit")
    NDData([1, 2, 3], unit='meter')
    # Test conflicting units (quantity as data)
    q = np.array([1, 2, 3]) * u.m
    nd = NDData(q, unit='cm')
    assert nd.unit != q.unit
    assert nd.unit == u.cm
    # (masked quantity)
    mq = np.ma.array(np.array([2, 3])*u.m, mask=False)
    nd2 = NDData(mq, unit=u.s)
    assert nd2.unit == u.s
    # (another NDData as data)
    nd3 = NDData(nd, unit='km')
    assert nd3.unit == u.km 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_nddata.py

示例11: test_ecliptic_heliobary

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def test_ecliptic_heliobary():
    """
    Check that the ecliptic transformations for heliocentric and barycentric
    at least more or less make sense
    """
    icrs = ICRS(1*u.deg, 2*u.deg, distance=1.5*R_sun)

    bary = icrs.transform_to(BarycentricMeanEcliptic)
    helio = icrs.transform_to(HeliocentricMeanEcliptic)

    # make sure there's a sizable distance shift - in 3d hundreds of km, but
    # this is 1D so we allow it to be somewhat smaller
    assert np.abs(bary.distance - helio.distance) > 1*u.km

    # now make something that's got the location of helio but in bary's frame.
    # this is a convenience to allow `separation` to work as expected
    helio_in_bary_frame = bary.realize_frame(helio.cartesian)
    assert bary.separation(helio_in_bary_frame) > 1*u.arcmin 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_ecliptic.py

示例12: test_against_jpl_horizons

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def test_against_jpl_horizons():
    """Check that Astropy gives consistent results with the JPL Horizons example.

    The input parameters and reference results are taken from this page:
    (from the first row of the Results table at the bottom of that page)
    http://ssd.jpl.nasa.gov/?horizons_tutorial
    """
    obstime = Time('1998-07-28 03:00')
    location = EarthLocation(lon=Angle('248.405300d'),
                             lat=Angle('31.9585d'),
                             height=2.06 * u.km)
    # No atmosphere
    altaz_frame = AltAz(obstime=obstime, location=location)

    altaz = SkyCoord('143.2970d 2.6223d', frame=altaz_frame)
    radec_actual = altaz.transform_to('icrs')
    radec_expected = SkyCoord('19h24m55.01s -40d56m28.9s', frame='icrs')
    distance = radec_actual.separation(radec_expected).to('arcsec')
    # Current value: 0.238111 arcsec
    assert distance < 1 * u.arcsec 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_altaz_icrs.py

示例13: test_gen_radius

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [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 that, for this power law, there
        are more small than large masses (for n large).
        """

        plan_pop = self.fixture
        n = 10000
        # call the routine
        radii = plan_pop.gen_radius(n)
        # check the type
        self.assertEqual(type(radii), type(1.0 * u.km))
        # ensure the units are length
        self.assertEqual((radii/u.km).decompose().unit, u.dimensionless_unscaled)
        # radius > 0
        self.assertTrue(np.all(radii.value >= 0))
        # crude check on the shape (masses are a power law, so radii will also be,
        # so we require more small than large radii)
        midpoint = (np.min(radii) + np.max(radii)) * 0.5
        self.assertGreater(np.count_nonzero(radii < midpoint),
                           np.count_nonzero(radii > midpoint))
        # test some illegal "n" values
        # Note: as long as we're checking this, -1 should be illegal, but is passed thru
        n_list_bad = [-1, '100', 22.5]
        for n in n_list_bad:
            with self.assertRaises(AssertionError):
                radii = plan_pop.gen_radius(n) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:31,代码来源:test_KnownRVPlanets.py

示例14: __init__

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [as 别名]
def __init__(self, ntargs=1000, star_dist=5, **specs):
        
        StarCatalog.__init__(self,**specs)
        
        # ntargs must be an integer >= 1
        self.ntargs = max(int(ntargs), 1)
        
        # list of astropy attributes
        self.coords = self.inverse_method(self.ntargs,star_dist)     # ICRS coordinates
        self.ntargs = int(len(self.coords.ra))
        self.dist = star_dist*np.ones(self.ntargs)*u.pc               # distance
        self.parx = self.dist.to('mas', equivalencies=u.parallax())   # parallax
        self.pmra = np.zeros(self.ntargs)*u.mas/u.yr                 # proper motion in RA
        self.pmdec = np.zeros(self.ntargs)*u.mas/u.yr                # proper motion in DEC
        self.rv = np.zeros(self.ntargs)*u.km/u.s                     # radial velocity
        
        # list of non-astropy attributes to pass target list filters
        self.Name = np.array([str(x) for x in range(self.ntargs)])   # star names
        self.Spec = np.array(['G']*self.ntargs)                      # spectral types
        self.Umag = np.zeros(self.ntargs)                            # U magnitude
        self.Bmag = np.zeros(self.ntargs)                            # B magnitude
        self.Vmag = 5*np.ones(self.ntargs)                           # V magnitude
        self.Rmag = np.zeros(self.ntargs)                            # R magnitude
        self.Imag = np.zeros(self.ntargs)                            # I magnitude
        self.Jmag = np.zeros(self.ntargs)                            # J magnitude
        self.Hmag = np.zeros(self.ntargs)                            # H magnitude
        self.Kmag = np.zeros(self.ntargs)                            # K magnitude
        self.BV = np.zeros(self.ntargs)                              # B-V Johnson magnitude
        self.MV   = self.Vmag - 5*( np.log10(star_dist) - 1 )   # absolute V magnitude 
        self.BC   = -0.10*np.ones(self.ntargs)                       # bolometric correction
        
        BM        = self.MV + self.BC
        L0        = 3.0128e28
        BMsun     = 4.74
        self.L    = L0*10**(0.4*(BMsun-BM))                     # stellar luminosity in ln(SolLum)
        self.Binary_Cut = np.zeros(self.ntargs, dtype=bool)          # binary closer than 10 arcsec
        
        # populate outspecs
        self._outspec['ntargs'] = self.ntargs 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:41,代码来源:FakeCatalog.py

示例15: mass_dec_sk

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import km [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


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