本文整理汇总了Python中astropy.units.AU属性的典型用法代码示例。如果您正苦于以下问题:Python units.AU属性的具体用法?Python units.AU怎么用?Python units.AU使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类astropy.units
的用法示例。
在下文中一共展示了units.AU属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fEZ
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def test_fEZ(self):
"""
Test that fEZ returns correct shape and units.
"""
exclude_mods=[]
for mod in self.allmods:
if mod.__name__ in exclude_mods:
continue
if 'fEZ' in mod.__dict__:
obj = mod()
# use 3 planets
d = 10.*np.random.rand(3)*u.AU
I = np.random.uniform(0.0, 180.0, 3)*u.deg
fEZs = obj.fEZ(self.TL.MV[0], I, d)
self.assertEqual(len(fEZs), 3, 'fEZ does not return same number of values as planets tested for {}'.format(mod.__name__))
self.assertEqual(fEZs.unit, self.unit, 'fEZ does not return 1/arcsec**2 for {}'.format(mod.__name__))
示例2: test_calc_Teff
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def test_calc_Teff(self):
"""
Tests that calc_Teff returns values within appropriate ranges.
"""
for mod in self.allmods:
if 'calc_Teff' in mod.__dict__:
with RedirectStreams(stdout=self.dev_null):
obj = mod()
starL = np.random.uniform(0.7,1.3,100)
p = np.random.uniform(0.0, 1.0, 100)
d = np.random.uniform(0.2, 10.0, 100)*u.AU
Teff = obj.calc_Teff(starL,d,p)
self.assertTrue(len(Teff) == len(starL),'length of Teff returned does not match inputs for %s'%mod.__name__)
self.assertTrue(np.all(np.isfinite(Teff)),'calc_Teff returned infinite value for %s'%mod.__name__)
self.assertTrue(np.all(Teff >= 0.0),'calc_Teff returned negative value for %s'%mod.__name__)
示例3: hist
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def hist(self, nplan, xedges, yedges):
"""Returns completeness histogram for Monte Carlo simulation
This function uses the inherited Planet Population module.
Args:
nplan (float):
number of planets used
xedges (float ndarray):
x edge of 2d histogram (separation)
yedges (float ndarray):
y edge of 2d histogram (dMag)
Returns:
h (ndarray):
2D numpy ndarray containing completeness histogram
"""
s, dMag = self.genplans(nplan)
# get histogram
h, yedges, xedges = np.histogram2d(dMag, s.to('AU').value, bins=1000,
range=[[yedges.min(), yedges.max()], [xedges.min(), xedges.max()]])
return h, xedges, yedges
示例4: gen_sma
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def gen_sma(self, n):
"""Generate semi-major axis values in AU
Samples a power law distribution with exponential turn-off
determined by class attribute smaknee
Args:
n (integer):
Number of samples to generate
Returns:
astropy Quantity array:
Semi-major axis values in units of AU
"""
n = self.gen_input_check(n)
ar = self.arange.to('AU').value
a = statsFun.simpSample(self.dist_sma, n, ar[0], ar[1])*u.AU
return a
示例5: gen_sma
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def gen_sma(self, n):
"""Generate semi-major axis values in AU
The Earth-twin population assumes a uniform distribution between the minimum and
maximum values.
Args:
n (integer):
Number of samples to generate
Returns:
a (astropy Quantity array):
Semi-major axis values in units of AU
"""
n = self.gen_input_check(n)
ar = self.arange.to('AU').value
a = np.random.uniform(low=ar[0], high=ar[1], size=n)*u.AU
return a
示例6: gen_sma
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def gen_sma(self, n):
"""Generate semi-major axis values in AU
Samples a power law distribution with exponential turn-off
determined by class attribute smaknee
Args:
n (integer):
Number of samples to generate
Returns:
a (astropy Quantity array):
Semi-major axis in units of AU
"""
n = self.gen_input_check(n)
a = self.sma_sampler(n)*u.AU
return a
示例7: hist
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def hist(self, nplan, xedges, yedges):
"""Returns completeness histogram for Monte Carlo simulation
This function uses the inherited Planet Population module.
Args:
nplan (float):
number of planets used
xedges (float ndarray):
x edge of 2d histogram (separation)
yedges (float ndarray):
y edge of 2d histogram (dMag)
Returns:
float ndarray:
2D numpy ndarray containing completeness frequencies
"""
s, dMag = self.genplans(nplan)
# get histogram
h, yedges, xedges = np.histogram2d(dMag, s.to('AU').value, bins=1000,
range=[[yedges.min(), yedges.max()], [xedges.min(), xedges.max()]])
return h, xedges, yedges
示例8: calc_fdmag
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def calc_fdmag(self, dMag, smin, smax):
"""Calculates probability density of dMag by integrating over projected
separation
Args:
dMag (float ndarray):
Planet delta magnitude(s)
smin (float ndarray):
Value of minimum projected separation (AU) from instrument
smax (float ndarray):
Value of maximum projected separation (AU) from instrument
Returns:
float:
Value of probability density
"""
f = np.zeros(len(smin))
for k, dm in enumerate(dMag):
f[k] = interpolate.InterpolatedUnivariateSpline(self.xnew,self.EVPOCpdf(self.xnew,dm),ext=1).integral(smin[k],smax[k])
return f
示例9: dist_sma
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def dist_sma(self, a):
"""Probability density function for semi-major axis in AU
The prototype provides a log-uniform distribution between the minimum
and maximum values.
Args:
a (float ndarray):
Semi-major axis value(s) in AU. Not an astropy quantity.
Returns:
float ndarray:
Semi-major axis probability density
"""
return self.logunif(a, self.arange.to('AU').value)
示例10: eclip2equat
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def eclip2equat(self, r_eclip, currentTime):
"""Rotates heliocentric coordinates from ecliptic to equatorial frame.
Args:
r_eclip (astropy Quantity nx3 array):
Positions vector in heliocentric ecliptic frame in units of AU
currentTime (astropy Time array):
Current absolute mission time in MJD
Returns:
r_equat (astropy Quantity nx3 array):
Positions vector in heliocentric equatorial frame in units of AU
"""
r_equat = self.equat2eclip(r_eclip, currentTime, rotsign=-1)
return r_equat
示例11: __init__
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [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
示例12: test_period_semi
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def test_period_semi():
# Check that an error is raised if neither a nor porb is given
with pytest.raises(ValueError) as e:
body = starry.Secondary(starry.Map())
assert "Must provide a value for either `porb` or `a`" in str(e.value)
# Check that the semi --> period conversion works
pri = starry.Primary(starry.Map(), m=1.0, mass_unit=u.Msun)
sec = starry.Secondary(
starry.Map(), a=10.0, m=1.0, length_unit=u.AU, mass_unit=u.Mearth
)
sys = starry.System(pri, sec)
period = sys._get_periods()[0]
true_period = (
(
(2 * np.pi)
* (sec.a * sec.length_unit) ** (3 / 2)
/ (np.sqrt(G * (pri.m * pri.mass_unit + sec.m * sec.mass_unit)))
)
.to(u.day)
.value
)
assert np.allclose(period, true_period)
示例13: test_component_names_repr
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def test_component_names_repr():
from astropy.coordinates.baseframe import BaseCoordinateFrame, RepresentationMapping
# Frame class with new component names that includes a name swap
class NameChangeFrame(BaseCoordinateFrame):
default_representation = r.PhysicsSphericalRepresentation
frame_specific_representation_info = {
r.PhysicsSphericalRepresentation: [
RepresentationMapping('phi', 'theta', u.deg),
RepresentationMapping('theta', 'phi', u.arcsec),
RepresentationMapping('r', 'JUSTONCE', u.AU)]
}
frame = NameChangeFrame(0*u.deg, 0*u.arcsec, 0*u.AU)
# Check for the new names in the Frame repr
assert "(theta, phi, JUSTONCE)" in repr(frame)
# Check that the letter "r" has not been replaced more than once in the Frame repr
assert repr(frame).count("JUSTONCE") == 1
示例14: test_regression_4210
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def test_regression_4210():
"""
Issue: https://github.com/astropy/astropy/issues/4210
Related PR with actual change: https://github.com/astropy/astropy/pull/4211
"""
crd = SkyCoord(0*u.deg, 0*u.deg, distance=1*u.AU)
ecl = crd.geocentricmeanecliptic
# bug was that "lambda", which at the time was the name of the geocentric
# ecliptic longitude, is a reserved keyword. So this just makes sure the
# new name is are all valid
ecl.lon
# and for good measure, check the other ecliptic systems are all the same
# names for their attributes
from astropy.coordinates.builtin_frames import ecliptic
for frame_name in ecliptic.__all__:
eclcls = getattr(ecliptic, frame_name)
eclobj = eclcls(1*u.deg, 2*u.deg, 3*u.AU)
eclobj.lat
eclobj.lon
eclobj.distance
示例15: test_equivalent_units2
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import AU [as 别名]
def test_equivalent_units2():
units = set(u.Hz.find_equivalent_units(u.spectral()))
match = set(
[u.AU, u.Angstrom, u.Hz, u.J, u.Ry, u.cm, u.eV, u.erg, u.lyr,
u.m, u.micron, u.pc, u.solRad, u.Bq, u.Ci, u.k, u.earthRad,
u.jupiterRad])
assert units == match
from astropy.units import imperial
with u.add_enabled_units(imperial):
units = set(u.Hz.find_equivalent_units(u.spectral()))
match = set(
[u.AU, u.Angstrom, imperial.BTU, u.Hz, u.J, u.Ry,
imperial.cal, u.cm, u.eV, u.erg, imperial.ft, imperial.fur,
imperial.inch, imperial.kcal, u.lyr, u.m, imperial.mi,
imperial.mil, u.micron, u.pc, u.solRad, imperial.yd, u.Bq, u.Ci,
imperial.nmi, u.k, u.earthRad, u.jupiterRad])
assert units == match
units = set(u.Hz.find_equivalent_units(u.spectral()))
match = set(
[u.AU, u.Angstrom, u.Hz, u.J, u.Ry, u.cm, u.eV, u.erg, u.lyr,
u.m, u.micron, u.pc, u.solRad, u.Bq, u.Ci, u.k, u.earthRad,
u.jupiterRad])
assert units == match