本文整理汇总了Python中astropy.units.K属性的典型用法代码示例。如果您正苦于以下问题:Python units.K属性的具体用法?Python units.K怎么用?Python units.K使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类astropy.units
的用法示例。
在下文中一共展示了units.K属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stellarTeff
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def stellarTeff(self, sInds):
"""Calculate the effective stellar temperature based on B-V color.
This method uses the empirical fit from Ballesteros (2012) doi:10.1209/0295-5075/97/34008
Args:
sInds (integer ndarray):
Indices of the stars of interest
Returns:
Quantity array:
Stellar effective temperatures in degrees K
"""
# cast sInds to array
sInds = np.array(sInds, ndmin=1, copy=False)
Teff = 4600.0*u.K * (1.0/(0.92*self.BV[sInds] + 1.7) + 1.0/(0.92*self.BV[sInds] + 0.62))
return Teff
示例2: prepare_quantity
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def prepare_quantity(value, units=None, name_val=None):
""" The function verifys that a
"""
if value is None:
return None
if isinstance(value, u.Quantity):
if units in [u.K, u.deg_C, u.Kelvin, u.Celsius, u.imperial.deg_F]:
return value.to(units, equivalencies=u.temperature()).value
else:
return value.to(units).value
elif isinstance(value, numbers.Number) and units is not None:
return value
elif isinstance(value, np.ndarray) and units is not None:
return value
elif isinstance(value, list) and units is not None:
return np.array([prepare_quantity(v, units, name_val) for v in value])
elif isinstance(value, tuple) and units is not None:
return np.array([prepare_quantity(v, units, name_val) for v in value])
else:
raise ValueError('%s has not the correct format. It must be a value,'
'sequence, array, or a Quantity with %s units' %
(name_val, str(units)))
示例3: calc_brightness_ratio_from_Teff
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def calc_brightness_ratio_from_Teff(Teff_1, Teff_2, plot=False):
bandpass = np.genfromtxt('tess-response-function-v1.0.csv', delimiter=',', names=['wavelength','transmission'])
wavelength_grid = np.arange(500,2000,1)
if plot:
fig, ax = plt.subplots()
ax.plot(list(bandpass['wavelength'])+[2000], list(bandpass['transmission'])+[0], lw=2)
ax.set(ylabel='TESS Transmission')
ax2 = ax.twinx()
ax2.plot(wavelength_grid, blackbody_lambda(wavelength_grid*u.nm, Teff_1*u.K), 'r-', lw=2, color='darkorange')
ax2.plot(wavelength_grid, blackbody_lambda(wavelength_grid*u.nm, Teff_2*u.K), 'r-', lw=2, color='brown')
ax2.set(ylabel='Blackbody Flux\n'+r'($erg \, cm^{-2} \, s^{-1} \, A^{-1} \, sr^{-1}$)')
int1 = np.trapz(bandpass['transmission']*u.nm*blackbody_lambda(bandpass['wavelength']*u.nm, Teff_1*u.K), x=bandpass['wavelength']*u.nm, dx=np.diff(bandpass['wavelength']*u.nm))
int2 = np.trapz(bandpass['transmission']*u.nm*blackbody_lambda(bandpass['wavelength']*u.nm, Teff_2*u.K), x=bandpass['wavelength']*u.nm, dx=np.diff(bandpass['wavelength']*u.nm))
sbratio = int2/int1
return sbratio
示例4: Tcmb
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def Tcmb(self, z):
""" Return the CMB temperature at redshift ``z``.
Parameters
----------
z : array_like
Input redshifts.
Returns
-------
Tcmb : `~astropy.units.Quantity`
The temperature of the CMB in K.
"""
if isiterable(z):
z = np.asarray(z)
return self._Tcmb0 * (1. + z)
示例5: Tnu
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def Tnu(self, z):
""" Return the neutrino temperature at redshift ``z``.
Parameters
----------
z : array_like
Input redshifts.
Returns
-------
Tnu : `~astropy.units.Quantity`
The temperature of the cosmic neutrino background in K.
"""
if isiterable(z):
z = np.asarray(z)
return self._Tnu0 * (1. + z)
示例6: test_ocurv
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def test_ocurv():
# Test Ok evolution
# Flat, boring case
tcos = core.FlatLambdaCDM(70.0, 0.3)
assert allclose(tcos.Ok0, 0.0)
assert allclose(tcos.Ok(0), 0.0)
z = np.array([0.0, 0.5, 1.0, 2.0])
assert allclose(tcos.Ok(z), [0.0, 0.0, 0.0, 0.0],
rtol=1e-6)
# Not flat
tcos = core.LambdaCDM(70.0, 0.3, 0.5, Tcmb0=u.Quantity(0.0, u.K))
assert allclose(tcos.Ok0, 0.2)
assert allclose(tcos.Ok(0), 0.2)
assert allclose(tcos.Ok(z), [0.2, 0.22929936, 0.21621622, 0.17307692],
rtol=1e-4)
# Test the sum; note that Ogamma/Onu are 0
assert allclose(tcos.Ok(z) + tcos.Om(z) + tcos.Ode(z),
[1.0, 1.0, 1.0, 1.0], rtol=1e-5)
示例7: test_blackbody_scipy
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def test_blackbody_scipy():
"""Test Planck function.
.. note:: Needs ``scipy`` to work.
"""
flux_unit = u.Watt / (u.m ** 2 * u.um)
wave = np.logspace(0, 8, 100000) * u.AA
temp = 100. * u.K
with np.errstate(all='ignore'):
bb_nu = blackbody_nu(wave, temp) * u.sr
flux = bb_nu.to(flux_unit, u.spectral_density(wave)) / u.sr
lum = wave.to(u.um)
intflux = integrate.trapz(flux.value, x=lum.value)
ans = const.sigma_sb * temp ** 4 / np.pi
np.testing.assert_allclose(intflux, ans.value, rtol=0.01) # 1% accuracy
示例8: test_blackbody_exceptions_and_warnings
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def test_blackbody_exceptions_and_warnings():
"""Test exceptions."""
# Negative temperature
with pytest.raises(ValueError) as exc:
blackbody_nu(1000 * u.AA, -100)
assert exc.value.args[0] == 'Temperature should be positive: -100.0 K'
# Zero wavelength given for conversion to Hz
with catch_warnings(AstropyUserWarning) as w:
blackbody_nu(0 * u.AA, 5000)
assert len(w) == 1
assert 'invalid' in w[0].message.args[0]
# Negative wavelength given for conversion to Hz
with catch_warnings(AstropyUserWarning) as w:
blackbody_nu(-1. * u.AA, 5000)
assert len(w) == 1
assert 'invalid' in w[0].message.args[0]
示例9: test_blackbody_overflow
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def test_blackbody_overflow():
"""Test Planck function with overflow."""
photlam = u.photon / (u.cm ** 2 * u.s * u.AA)
wave = [0.0, 1000.0, 100000.0, 1e55] # Angstrom
temp = 10000.0 # Kelvin
bb = BlackBody(temperature=temp * u.K, scale=1.0)
with pytest.warns(
AstropyUserWarning,
match=r'Input contains invalid wavelength/frequency value\(s\)'):
with np.errstate(all="ignore"):
bb_lam = bb(wave) * u.sr
flux = bb_lam.to(photlam, u.spectral_density(wave * u.AA)) / u.sr
# First element is NaN, last element is very small, others normal
assert np.isnan(flux[0])
with np.errstate(all="ignore"):
assert np.log10(flux[-1].value) < -134
np.testing.assert_allclose(
flux.value[1:-1], [0.00046368, 0.04636773], rtol=1e-3
) # 0.1% accuracy in PHOTLAM/sr
with np.errstate(all="ignore"):
flux = bb(1.0 * u.AA)
assert flux.value == 0
示例10: test_swapped_args_brightness_temperature
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def test_swapped_args_brightness_temperature():
"""
#5173 changes the order of arguments but accepts the old (deprecated) args
"""
omega_B = np.pi * (50 * u.arcsec) ** 2
nu = u.GHz * 5
tb = 7.052587837212582 * u.K
with catch_warnings(AstropyDeprecationWarning) as w:
result = (1*u.Jy).to(
u.K, equivalencies=u.brightness_temperature(omega_B, nu))
roundtrip = result.to(
u.Jy, equivalencies=u.brightness_temperature(omega_B, nu))
assert len(w) == 2
np.testing.assert_almost_equal(tb.value, result.value)
np.testing.assert_almost_equal(roundtrip.value, 1)
示例11: main
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def main():
w,h = (2056,1024)
l_0 = 0.
# Create a grid of coordinates
print('Creating grid of coordinates...')
l = np.linspace(-180.+l_0, 180.+l_0, 2*w)
b = np.linspace(-90., 90., 2*h+2)
b = b[1:-1]
l,b = np.meshgrid(l, b)
l += (np.random.random(l.shape) - 0.5) * 360./(2.*w)
b += (np.random.random(l.shape) - 0.5) * 180./(2.*h)
coords = SkyCoord(l*u.deg, b*u.deg, frame='galactic')
planck_components = [
('ebv', 0., 1.5),
('radiance', 0., 1.5),
('tau', 0., 1.5),
('temp', 15.*u.K, 25.*u.K),
('err_temp', 0.*u.K, 4.*u.K),
('beta', 1., 3.),
('err_beta', 0., 0.2)]
for component,vmin,vmax in planck_components:
# Set up Planck query object
print('Loading Planck map...')
planck = PlanckQuery(component=component)
print('Querying map...')
res = planck.query(coords)
# Convert the output array to a PIL image and save
print('Saving image...')
img = numpy2pil(res[::-1,::-1], vmin, vmax)
img = img.resize((w,h), resample=PIL.Image.LANCZOS)
fname = 'planck_{}.png'.format(component)
img.save(fname)
return 0
示例12: fgk_filter
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def fgk_filter(self):
"""Includes only F, G, K spectral type stars in Target List
"""
spec = np.array(list(map(str, self.Spec)))
iF = np.where(np.core.defchararray.startswith(spec, 'F'))[0]
iG = np.where(np.core.defchararray.startswith(spec, 'G'))[0]
iK = np.where(np.core.defchararray.startswith(spec, 'K'))[0]
i = np.append(np.append(iF, iG), iK)
i = np.unique(i)
self.revise_lists(i)
示例13: swoops_ions
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def swoops_ions(starttime, endtime):
"""
Import SWOOPS ion data.
Parameters
----------
starttime : datetime
Start of interval
endtime : datetime
End of interval
Returns
-------
data : :class:`~sunpy.timeseries.TimeSeries`
Requested data
"""
units = OrderedDict([('T_p_large', u.K), ('T_p_small', u.K),
('v_t', u.km / u.s), ('v_r', u.km / u.s),
('v_n', u.km / u.s), ('r', u.au),
('n_a', u.cm**-3), ('n_p', u.cm**-3),
('hlat', u.deg),
('hlon', u.deg),
('iqual', u.dimensionless_unscaled)])
downloader = _swoopsionDownloader(units)
return downloader.load(starttime, endtime)
示例14: __init__
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def __init__(self, probe):
_check_probe(probe, ['8'])
self.probe = probe
self.units = OrderedDict(
[('sw_flag', u.dimensionless_unscaled),
('x_gse', u.R_earth), ('y_gse', u.R_earth),
('z_gse', u.R_earth), ('y_gsm', u.R_earth),
('z_gsm', u.R_earth), ('Nm', u.dimensionless_unscaled),
('<|B|>', u.nT), ('|<B>|', u.nT), ('<B_lat>', u.nT),
('<B_long>', u.nT), ('Bx_gse', u.nT), ('By_gse', u.nT),
('Bz_gse', u.nT), ('By_gsm', u.nT), ('Bz_gsm', u.nT),
('sigma|B|', u.nT), ('sigma B', u.nT),
('sigma B_x', u.nT), ('sigma B_y', u.nT),
('sigma B_z', u.nT),
('plas_reg', u.dimensionless_unscaled),
('Npp', u.dimensionless_unscaled),
('v_fit', u.km / u.s), ('vx_fit_gse', u.km / u.s),
('vy_fit_gse', u.km / u.s), ('vz_fit_gse', u.km / u.s),
('vlong_fit', u.deg), ('vlat_fit', u.deg),
('np_fit', u.cm**-3), ('Tp_fit', u.K),
('v_mom', u.km / u.s), ('vx_mom_gse', u.km / u.s),
('vy_mom_gse', u.km / u.s), ('vz_mom_gse', u.km / u.s),
('vlong_mom', u.deg), ('vlat_mom', u.deg),
('np_mom', u.cm**-3), ('Tp_mom', u.K),
('FCp', u.dimensionless_unscaled),
('DWp', u.dimensionless_unscaled)])
示例15: __init__
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import K [as 别名]
def __init__(self, probe):
self.probe = _check_probe(probe)
self.units = OrderedDict([
('B instrument', u.dimensionless_unscaled),
('Bx', u.nT), ('By', u.nT), ('Bz', u.nT),
('sigma B', u.nT),
('Ion instrument', u.dimensionless_unscaled),
('Status', u.dimensionless_unscaled),
('Tp_par', u.K), ('Tp_perp', u.K),
('carrot', u.dimensionless_unscaled),
('r_sun', u.AU), ('clat', u.deg),
('clong', u.deg), ('earth_he_angle', u.deg),
('n_p', u.cm**-3), ('vp_x', u.km / u.s),
('vp_y', u.km / u.s), ('vp_z', u.km / u.s),
('vth_p_par', u.km / u.s), ('vth_p_perp', u.km / u.s)])