本文整理汇总了Python中astropy.constants.c方法的典型用法代码示例。如果您正苦于以下问题:Python constants.c方法的具体用法?Python constants.c怎么用?Python constants.c使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.constants
的用法示例。
在下文中一共展示了constants.c方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_Sij
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def get_Sij(T, wavenums, lower_wavenums, Sij_ref, molecule_id=1, iso_id=1, T_ref=296.0):
T = float(T)
filename = "QTpy/{}_{}.QTpy".format(molecule_id, iso_id)
partition_sums = pickle.load(open(filename))
Q_T = float(partition_sums[str(int(round(T)))])
Q_ref = float(partition_sums[str(int(T_ref))])
c2 = (h * c / k_B).cgs.value
#print Q_T, Q_ref
#print -c2*lower_wavenums/T_ref #np.exp(-c2*lower_wavenums/T_ref), lower_wavenums, wavenums, c2
ratios = Q_ref/Q_T * np.exp(-c2 * lower_wavenums * (1/T - 1/T_ref)) * (1 - np.exp(-c2*wavenums/T)) / (1 - np.exp(-c2*wavenums/T_ref))
Sij = Sij_ref * ratios
#print Sij
print ratios
print np.min(ratios), np.max(ratios)
return Sij
示例2: get_cross_sections
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def get_cross_sections(all_wavenums, wavenum_ref, integral, P, T, gamma_ref, n_air, delta_ref, T_ref=296.0):
P_atm = P/1e5 #Pascals to atm
wavenum = wavenum_ref + delta_ref * P_atm
gamma = (T_ref/T)**n_air * gamma_ref * P_atm
#print wavenum_ref, delta_ref * P_atm, (T_ref/T)**n_air * P_atm, n_air
#print gamma_ref, gamma
fwhm_gaussian = 2*wavenum/c * np.sqrt(2*k_B*T*np.log(2)/u)
fwhm_gaussian = fwhm_gaussian.cgs.value
fwhm_lorentzian = 2 * gamma
d_ln_wavenum = np.log(all_wavenums[1]/all_wavenums[0])
if fwhm_gaussian/wavenum < 2 * d_ln_wavenum and fwhm_lorentzian/wavenum < 2 * d_ln_wavenum:
#print(d_ln_wavenum, fwhm_gaussian/wavenum, fwhm_lorentzian/wavenum)
index = np.searchsorted(all_wavenums, wavenum)
cross_sections = np.zeros(len(all_wavenums))
cross_sections[index] = integral
return cross_sections
voigt_func = Voigt1D(wavenum, amplitude_L=integral/(np.pi * gamma), fwhm_L=fwhm_lorentzian, fwhm_G = fwhm_gaussian)
return voigt_func(all_wavenums)
示例3: set_model
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def set_model(self, differential_flux):
"""
set the model of that will be used during the convolution. Not that speclite
considers a differential flux to be in units of erg/s/cm2/lambda so we must convert
astromodels into the proper units (using astropy units!)
"""
conversion_factor = (constants.c ** 2 * constants.h ** 2).to("keV2 * cm2")
def wrapped_model(x):
return old_div(differential_flux(x) * conversion_factor, x ** 3)
self._wrapped_model = wrapped_model
self._model_set = True
示例4: test_altaz_diffs
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_altaz_diffs():
time = Time('J2015') + np.linspace(-1, 1, 1000)*u.day
loc = get_builtin_sites()['greenwich']
aa = AltAz(obstime=time, location=loc)
icoo = ICRS(np.zeros_like(time)*u.deg, 10*u.deg, 100*u.au,
pm_ra_cosdec=np.zeros_like(time)*u.marcsec/u.yr,
pm_dec=0*u.marcsec/u.yr,
radial_velocity=0*u.km/u.s)
acoo = icoo.transform_to(aa)
# Make sure the change in radial velocity over ~2 days isn't too much
# more than the rotation speed of the Earth - some excess is expected
# because the orbit also shifts the RV, but it should be pretty small
# over this short a time.
assert np.ptp(acoo.radial_velocity)/2 < (2*np.pi*constants.R_earth/u.day)*1.2 # MAGIC NUMBER
cdiff = acoo.data.differentials['s'].represent_as(CartesianDifferential,
acoo.data)
# The "total" velocity should be > c, because the *tangential* velocity
# isn't a True velocity, but rather an induced velocity due to the Earth's
# rotation at a distance of 100 AU
assert np.all(np.sum(cdiff.d_xyz**2, axis=0)**0.5 > constants.c)
示例5: test_erfa_planet
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_erfa_planet(self, body, sep_tol, dist_tol):
"""Test predictions using erfa/plan94.
Accuracies are maximum deviations listed in erfa/plan94.c, for Jupiter and
Mercury, and that quoted in Meeus "Astronomical Algorithms" (1998) for the Moon.
"""
astropy = get_body(body, self.t, ephemeris='builtin')
horizons = self.horizons[body]
# convert to true equator and equinox
astropy = _apparent_position_in_true_coordinates(astropy)
# Assert sky coordinates are close.
assert astropy.separation(horizons) < sep_tol
# Assert distances are close.
assert_quantity_allclose(astropy.distance, horizons.distance,
atol=dist_tol)
示例6: setup
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def setup(self):
kitt_peak = EarthLocation.from_geodetic(lon=-111.6*u.deg,
lat=31.963333333333342*u.deg,
height=2120*u.m)
self.t = Time('2014-09-25T00:00', location=kitt_peak)
obsgeoloc, obsgeovel = kitt_peak.get_gcrs_posvel(self.t)
self.frame = GCRS(obstime=self.t,
obsgeoloc=obsgeoloc, obsgeovel=obsgeovel)
# Results returned by JPL Horizons web interface
self.horizons = {
'mercury': SkyCoord(ra='13h38m58.50s', dec='-13d34m42.6s',
distance=c*7.699020*u.min, frame=self.frame),
'moon': SkyCoord(ra='12h33m12.85s', dec='-05d17m54.4s',
distance=c*0.022054*u.min, frame=self.frame),
'jupiter': SkyCoord(ra='09h09m55.55s', dec='+16d51m57.8s',
distance=c*49.244937*u.min, frame=self.frame)}
示例7: w
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def w(self, z):
""" The dark energy equation of state.
Parameters
----------
z : array_like
Input redshifts.
Returns
-------
w : ndarray, or float if input scalar
The dark energy equation of state
Notes
-----
The dark energy equation of state is defined as
:math:`w(z) = P(z)/\\rho(z)`, where :math:`P(z)` is the
pressure at redshift z and :math:`\\rho(z)` is the density
at redshift z, both in units where c=1.
This must be overridden by subclasses.
"""
raise NotImplementedError("w(z) is not implemented")
示例8: lookback_distance
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def lookback_distance(self, z):
"""
The lookback distance is the light travel time distance to a given
redshift. It is simply c * lookback_time. It may be used to calculate
the proper distance between two redshifts, e.g. for the mean free path
to ionizing radiation.
Parameters
----------
z : array_like
Input redshifts. Must be 1D or scalar
Returns
-------
d : `~astropy.units.Quantity`
Lookback distance in Mpc
"""
return (self.lookback_time(z) * const.c).to(u.Mpc)
示例9: test_complex_fractional_rounding_errors
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_complex_fractional_rounding_errors():
# See #3788
kappa = 0.34 * u.cm**2 / u.g
r_0 = 886221439924.7849 * u.cm
q = 1.75
rho_0 = 5e-10 * u.solMass / u.solRad**3
y = 0.5
beta = 0.19047619047619049
a = 0.47619047619047628
m_h = 1e6*u.solMass
t1 = 2 * c.c / (kappa * np.sqrt(np.pi))
t2 = (r_0**-q) / (rho_0 * y * beta * (a * c.G * m_h)**0.5)
result = ((t1 * t2)**-0.8)
assert result.unit.physical_type == 'length'
result.to(u.solRad)
示例10: get_cross_sections
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def get_cross_sections(all_wavenums, wavenum_ref, integral, P, T, gamma_ref, n_air, delta_ref, T_ref=296.0):
P_atm = P/1e5 #Pascals to atm
wavenum = wavenum_ref + delta_ref * P_atm
gamma = (T_ref/T)**n_air * gamma_ref * P_atm
#print wavenum_ref, delta_ref * P_atm, (T_ref/T)**n_air * P_atm, n_air
#print gamma_ref, gamma
fwhm_gaussian = 2*wavenum/c * np.sqrt(2*k_B*T*np.log(2)/u)
fwhm_gaussian = fwhm_gaussian.cgs.value
fwhm_lorentzian = 2 * gamma
# From Wikipedia
fwhm_voigt = 0.5346*fwhm_lorentzian + np.sqrt(0.2166*fwhm_lorentzian**2 + fwhm_gaussian**2)
d_ln_wavenum = np.log(all_wavenums[1]/all_wavenums[0])
if fwhm_gaussian/wavenum < 2 * d_ln_wavenum and fwhm_lorentzian/wavenum < 2 * d_ln_wavenum:
#print(d_ln_wavenum, fwhm_gaussian/wavenum, fwhm_lorentzian/wavenum)
index = np.searchsorted(all_wavenums, wavenum)
cross_sections = np.zeros(len(all_wavenums))
cross_sections[index] = integral
return cross_sections
# Num widths follows Hedges & Madhusudhan 2016
if P_atm > 1:
num_widths = 500
else:
num_widths = 250
cond = np.logical_and(all_wavenums > wavenum - num_widths * fwhm_voigt, all_wavenums < wavenum + num_widths * fwhm_voigt)
voigt_func = Voigt1D(wavenum, amplitude_L=integral/(np.pi * gamma), fwhm_L=fwhm_lorentzian, fwhm_G = fwhm_gaussian)
cross_sections = np.zeros(len(all_wavenums))
cross_sections[cond] = voigt_func(all_wavenums[cond])
return cross_sections
示例11: get_Sij
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def get_Sij(T, wavenums, lower_wavenums, Sij_ref, molecule_id=1, iso_id=1, T_ref=296.0):
T = float(T)
filename = "QTpy/{}_{}.QTpy".format(molecule_id, iso_id)
partition_sums = pickle.load(open(filename))
Q_T = float(partition_sums[str(int(round(T)))])
Q_ref = float(partition_sums[str(int(T_ref))])
c2 = (h * c / k_B).cgs.value
ratios = Q_ref/Q_T * np.exp(-c2 * lower_wavenums * (1/T - 1/T_ref)) * (1 - np.exp(-c2*wavenums/T)) / (1 - np.exp(-c2*wavenums/T_ref))
Sij = Sij_ref * ratios
print np.min(ratios), np.max(ratios)
return Sij
示例12: test_c
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_c():
from astropy.constants import c
# c is an exactly defined constant, so it shouldn't be changing
assert c.value == 2.99792458e8 # default is S.I.
assert c.si.value == 2.99792458e8
assert c.cgs.value == 2.99792458e10
# make sure it has the necessary attributes and they're not blank
assert c.uncertainty == 0 # c is a *defined* quantity
assert c.name
assert c.reference
assert c.unit
示例13: test_copy
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_copy():
from astropy import constants as const
cc = copy.deepcopy(const.c)
assert cc == const.c
cc = copy.copy(const.c)
assert cc == const.c
示例14: test_view
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_view():
"""Check that Constant and Quantity views can be taken (#3537, #3538)."""
from astropy.constants import c
c2 = c.view(Constant)
assert c2 == c
assert c2.value == c.value
# make sure it has the necessary attributes and they're not blank
assert c2.uncertainty == 0 # c is a *defined* quantity
assert c2.name == c.name
assert c2.reference == c.reference
assert c2.unit == c.unit
q1 = c.view(Q)
assert q1 == c
assert q1.value == c.value
assert type(q1) is Q
assert not hasattr(q1, 'reference')
q2 = Q(c)
assert q2 == c
assert q2.value == c.value
assert type(q2) is Q
assert not hasattr(q2, 'reference')
c3 = Q(c, subok=True)
assert c3 == c
assert c3.value == c.value
# make sure it has the necessary attributes and they're not blank
assert c3.uncertainty == 0 # c is a *defined* quantity
assert c3.name == c.name
assert c3.reference == c.reference
assert c3.unit == c.unit
c4 = Q(c, subok=True, copy=False)
assert c4 is c
示例15: test_c
# 需要导入模块: from astropy import constants [as 别名]
# 或者: from astropy.constants import c [as 别名]
def test_c():
from astropy.constants.codata2010 import c
# c is an exactly defined constant, so it shouldn't be changing
assert c.value == 2.99792458e8 # default is S.I.
assert c.si.value == 2.99792458e8
assert c.cgs.value == 2.99792458e10
# make sure it has the necessary attributes and they're not blank
assert c.uncertainty == 0 # c is a *defined* quantity
assert c.name
assert c.reference
assert c.unit