本文整理汇总了Python中astropy.units.spectral方法的典型用法代码示例。如果您正苦于以下问题:Python units.spectral方法的具体用法?Python units.spectral怎么用?Python units.spectral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.units
的用法示例。
在下文中一共展示了units.spectral方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _calculate_conversion
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def _calculate_conversion(self):
# convert the model to the right units so that we can
# convert back later for speed
tmp = self._model_converter[self._flux_type](self._test_value)
if (
tmp.unit == u.dimensionless_unscaled
or tmp.unit == self._test_value.unit
or tmp.unit == (self._test_value.unit) ** 2
):
# this is a multiplicative model
self._conversion = 1.0
self._is_dimensionless = True
else:
self._conversion = tmp.unit.to(self._flux_unit, equivalencies=u.spectral())
self._is_dimensionless = False
示例2: test_evaluate_with_quantities_and_equivalencies
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_evaluate_with_quantities_and_equivalencies():
"""
We now make sure that equivalencies are correctly taken into account
"""
g = Gaussian1D(1 * u.Jy, 10 * u.nm, 2 * u.nm)
# We aren't setting the equivalencies, so this won't work
with pytest.raises(UnitsError) as exc:
g(30 * u.PHz)
assert exc.value.args[0] == ("Gaussian1D: Units of input 'x', PHz (frequency), could "
"not be converted to required input units of "
"nm (length)")
# But it should now work if we pass equivalencies when evaluating
assert_quantity_allclose(g(30 * u.PHz, equivalencies={'x': u.spectral()}),
g(9.993081933333332 * u.nm))
示例3: test_quantity_conversion_with_equiv
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_quantity_conversion_with_equiv():
q1 = u.Quantity(0.1, unit=u.meter)
v2 = q1.to_value(u.Hz, equivalencies=u.spectral())
assert_allclose(v2, 2997924580.0)
q2 = q1.to(u.Hz, equivalencies=u.spectral())
assert_allclose(q2.value, v2)
q1 = u.Quantity(0.4, unit=u.arcsecond)
v2 = q1.to_value(u.au, equivalencies=u.parallax())
q2 = q1.to(u.au, equivalencies=u.parallax())
v3 = q2.to_value(u.arcminute, equivalencies=u.parallax())
q3 = q2.to(u.arcminute, equivalencies=u.parallax())
assert_allclose(v2, 515662.015)
assert_allclose(q2.value, v2)
assert q2.unit == u.au
assert_allclose(v3, 0.0066666667)
assert_allclose(q3.value, v3)
assert q3.unit == u.arcminute
示例4: test_quantity_conversion_equivalency_passed_on
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_quantity_conversion_equivalency_passed_on():
class MySpectral(u.Quantity):
_equivalencies = u.spectral()
def __quantity_view__(self, obj, unit):
return obj.view(MySpectral)
def __quantity_instance__(self, *args, **kwargs):
return MySpectral(*args, **kwargs)
q1 = MySpectral([1000, 2000], unit=u.Hz)
q2 = q1.to(u.nm)
assert q2.unit == u.nm
q3 = q2.to(u.Hz)
assert q3.unit == u.Hz
assert_allclose(q3.value, q1.value)
q4 = MySpectral([1000, 2000], unit=u.nm)
q5 = q4.to(u.Hz).to(u.nm)
assert q5.unit == u.nm
assert_allclose(q4.value, q5.value)
# Regression test for issue #2315, divide-by-zero error when examining 0*unit
示例5: test_equivalent_units2
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [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
示例6: _call_with_units
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def _call_with_units(self, x):
# Gather the current parameters' values with units
values = list(map(attrgetter("as_quantity"), self._get_children()))
try:
results = self.evaluate(
x.to(self.x_unit, equivalencies=u.spectral()), *values)
except u.UnitsError: # pragma: no cover
# see if this is a dimensionless function
if self.has_fixed_units():
try:
results = self.evaluate(x.to(self.x_unit), *values)
except u.UnitsError:
raise u.UnitsError("Looks like you didn't provide all the units, or you provided the wrong ones, when "
"calling function %s" % self.name)
else:
raise u.UnitsError("Looks like you didn't provide all the units, or you provided the wrong ones, when "
"calling function %s" % self.name)
else:
return results
示例7: integrated_luminosities
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def integrated_luminosities(self,out ,all_nus_rest, nuLnus4plotting):
"""
Calculates the integrated luminosities for
all model templates chosen by the user in out['intlum_models'],
within the integration ranges given by out['intlum_freqranges'].
##input:
- settings dictionary out[]
- all_nus_rest
- nuLnus4plotting: nu*luminosities for the four models corresponding
to each element of the total chain
"""
SBnuLnu, BBnuLnu, GAnuLnu, TOnuLnu, TOTALnuLnu, BBnuLnu_deredd =nuLnus4plotting
out['intlum_freqranges'] = (out['intlum_freqranges']*out['intlum_freqranges_unit']).to(u.Hz, equivalencies=u.spectral())
int_lums = []
for m in range(len(out['intlum_models'])):
if out['intlum_models'][m] == 'sb':
nuLnu= SBnuLnu
elif out['intlum_models'][m] == 'bbb':
nuLnu= BBnuLnu
elif out['intlum_models'][m] == 'bbbdered':
nuLnu=BBnuLnu_deredd
elif out['intlum_models'][m] == 'gal':
nuLnu=GAnuLnu
elif out['intlum_models'][m] == 'tor':
nuLnu=TOnuLnu
index = ((all_nus_rest >= np.log10(out['intlum_freqranges'][m][1].value)) & (all_nus_rest<= np.log10(out['intlum_freqranges'][m][0].value)))
all_nus_rest_int = 10**(all_nus_rest[index])
Lnu = nuLnu[:,index] / all_nus_rest_int
Lnu_int = scipy.integrate.trapz(Lnu, x=all_nus_rest_int)
int_lums.append(Lnu_int)
return np.array(int_lums)
示例8: test_input_units_equivalencies
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_input_units_equivalencies(self):
self.model._input_units = {'x': u.micron}
with pytest.raises(UnitsError) as exc:
self.model(3 * u.PHz, 3)
assert exc.value.args[0] == ("MyTestModel: Units of input 'x', PHz (frequency), could "
"not be converted to required input units of "
"micron (length)")
self.model.input_units_equivalencies = {'x': u.spectral()}
assert_quantity_allclose(self.model(3 * u.PHz, 3),
3 * (3 * u.PHz).to(u.micron, equivalencies=u.spectral()))
示例9: test_equiv_compose
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_equiv_compose():
composed = u.m.compose(equivalencies=u.spectral())
assert any([u.Hz] == x.bases for x in composed)
示例10: test_spectral
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_spectral():
a = u.AA.to(u.Hz, 1, u.spectral())
assert_allclose(a, 2.9979245799999995e+18)
b = u.Hz.to(u.AA, a, u.spectral())
assert_allclose(b, 1)
a = u.AA.to(u.MHz, 1, u.spectral())
assert_allclose(a, 2.9979245799999995e+12)
b = u.MHz.to(u.AA, a, u.spectral())
assert_allclose(b, 1)
a = u.m.to(u.Hz, 1, u.spectral())
assert_allclose(a, 2.9979245799999995e+8)
b = u.Hz.to(u.m, a, u.spectral())
assert_allclose(b, 1)
示例11: test_spectral2
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_spectral2():
a = u.nm.to(u.J, 500, u.spectral())
assert_allclose(a, 3.972891366538605e-19)
b = u.J.to(u.nm, a, u.spectral())
assert_allclose(b, 500)
a = u.AA.to(u.Hz, 1, u.spectral())
b = u.Hz.to(u.J, a, u.spectral())
c = u.AA.to(u.J, 1, u.spectral())
assert_allclose(b, c)
c = u.J.to(u.Hz, b, u.spectral())
assert_allclose(a, c)
示例12: test_spectral3
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_spectral3():
a = u.nm.to(u.Hz, [1000, 2000], u.spectral())
assert_allclose(a, [2.99792458e+14, 1.49896229e+14])
示例13: test_spectral4
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_spectral4(in_val, in_unit):
"""Wave number conversion w.r.t. wavelength, freq, and energy."""
# Spectroscopic and angular
out_units = [u.micron ** -1, u.radian / u.micron]
answers = [[1e+5, 2.0, 1.0], [6.28318531e+05, 12.5663706, 6.28318531]]
for out_unit, ans in zip(out_units, answers):
# Forward
a = in_unit.to(out_unit, in_val, u.spectral())
assert_allclose(a, ans)
# Backward
b = out_unit.to(in_unit, ans, u.spectral())
assert_allclose(b, in_val)
示例14: test_equivalency_context_manager
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import spectral [as 别名]
def test_equivalency_context_manager():
base_registry = u.get_current_unit_registry()
def just_to_from_units(equivalencies):
return [(equiv[0], equiv[1]) for equiv in equivalencies]
tf_dimensionless_angles = just_to_from_units(u.dimensionless_angles())
tf_spectral = just_to_from_units(u.spectral())
assert base_registry.equivalencies == []
with u.set_enabled_equivalencies(u.dimensionless_angles()):
new_registry = u.get_current_unit_registry()
assert (set(just_to_from_units(new_registry.equivalencies)) ==
set(tf_dimensionless_angles))
assert set(new_registry.all_units) == set(base_registry.all_units)
with u.set_enabled_equivalencies(u.spectral()):
newer_registry = u.get_current_unit_registry()
assert (set(just_to_from_units(newer_registry.equivalencies)) ==
set(tf_spectral))
assert (set(newer_registry.all_units) ==
set(base_registry.all_units))
assert (set(just_to_from_units(new_registry.equivalencies)) ==
set(tf_dimensionless_angles))
assert set(new_registry.all_units) == set(base_registry.all_units)
with u.add_enabled_equivalencies(u.spectral()):
newer_registry = u.get_current_unit_registry()
assert (set(just_to_from_units(newer_registry.equivalencies)) ==
set(tf_dimensionless_angles) | set(tf_spectral))
assert (set(newer_registry.all_units) ==
set(base_registry.all_units))
assert base_registry is u.get_current_unit_registry()