本文整理汇总了Python中astropy.units.Angstrom方法的典型用法代码示例。如果您正苦于以下问题:Python units.Angstrom方法的具体用法?Python units.Angstrom怎么用?Python units.Angstrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.units
的用法示例。
在下文中一共展示了units.Angstrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trace_table
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def trace_table(self):
"""
Table of trace parameters. Trace is unit-indexed.
"""
dtype = np.float32
tab = utils.GTable()
tab.meta['CONFFILE'] = os.path.basename(self.beam.conf.conf_file)
tab['wavelength'] = np.cast[dtype](self.beam.lam*u.Angstrom)
tab['trace'] = np.cast[dtype](self.beam.ytrace + self.beam.sh_beam[0]/2 - self.beam.ycenter)
sens_units = u.erg/u.second/u.cm**2/u.Angstrom/(u.electron/u.second)
tab['sensitivity'] = np.cast[dtype](self.beam.sensitivity*sens_units)
return tab
示例2: datacube
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def datacube():
"""Produces a simple 3D array for datacube testing."""
flux = numpy.tile([numpy.arange(1, 1001, dtype=numpy.float32)],
(100, 1)).T.reshape(1000, 10, 10)
ivar = (1. / (flux / 100))**2
mask = numpy.zeros(flux.shape, dtype=numpy.int)
wave = numpy.arange(1, 1001)
redcorr = numpy.ones(1000) * 1.5
mask[50:100, 5, 5] = 2**10
mask[500:600, 3, 3] = 2**4
scale = 1e-3
datacube = DataCube(flux, wave, ivar=ivar, mask=mask, redcorr=redcorr, scale=scale,
unit=u.erg / u.s / (u.cm ** 2) / u.Angstrom / spaxel_unit,
pixmask_flag='MANGA_DRP3PIXMASK')
yield datacube
示例3: spectrum
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def spectrum():
"""Produces a simple 1D array for datacube testing."""
flux = numpy.arange(1, 1001, dtype=numpy.float32)
ivar = (1. / (flux / 100))**2
mask = numpy.zeros(flux.shape, dtype=numpy.int)
wave = numpy.arange(1, 1001)
mask[50:100] = 2**10
mask[500:600] = 2**4
scale = 1e-3
datacube = Spectrum(flux, wave, ivar=ivar, mask=mask, scale=scale,
unit=u.erg / u.s / (u.cm ** 2) / u.Angstrom / spaxel_unit,
pixmask_flag='MANGA_DRP3PIXMASK')
yield datacube
示例4: test_compound_without_units
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_compound_without_units(model):
x = np.linspace(-5, 5, 10) * u.Angstrom
with NumpyRNGContext(12345):
y = np.random.sample(10)
fitter = fitting.LevMarLSQFitter()
res_fit = fitter(model, x, y * u.Hz)
for param_name in res_fit.param_names:
print(getattr(res_fit, param_name))
assert all([res_fit[i]._has_units for i in range(3)])
z = res_fit(x)
assert isinstance(z, u.Quantity)
res_fit = fitter(model, np.arange(10) * u.Unit('Angstrom'), y)
assert all([res_fit[i]._has_units for i in range(3)])
z = res_fit(x)
assert isinstance(z, np.ndarray)
示例5: test_compound_fitting_with_units
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_compound_fitting_with_units():
x = np.linspace(-5, 5, 15) * u.Angstrom
y = np.linspace(-5, 5, 15) * u.Angstrom
fitter = fitting.LevMarLSQFitter()
m = models.Gaussian2D(10*u.Hz,
3*u.Angstrom, 4*u.Angstrom,
1*u.Angstrom, 2*u.Angstrom)
p = models.Planar2D(3*u.Hz/u.Angstrom, 4*u.Hz/u.Angstrom, 1*u.Hz)
model = m + p
z = model(x, y)
res = fitter(model, x, y, z)
assert isinstance(res(x, y), np.ndarray)
assert all([res[i]._has_units for i in range(2)])
model = models.Gaussian2D() + models.Planar2D()
res = fitter(model, x, y, z)
assert isinstance(res(x, y), np.ndarray)
assert all([res[i]._has_units for i in range(2)])
示例6: test_deprecated_did_you_mean_units
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_deprecated_did_you_mean_units():
with pytest.raises(ValueError) as exc_info:
u.Unit('ANGSTROM', format='fits')
assert 'Did you mean Angstrom or angstrom?' in str(exc_info.value)
with pytest.raises(ValueError) as exc_info:
u.Unit('crab', format='ogip')
assert 'Crab (deprecated)' in str(exc_info.value)
assert 'mCrab (deprecated)' in str(exc_info.value)
with catch_warnings() as w:
u.Unit('ANGSTROM', format='vounit')
assert len(w) == 1
assert 'angstrom (deprecated)' in str(w[0].message)
assert '0.1nm' in str(w[0].message)
assert str(w[0].message).count('0.1nm') == 1
with catch_warnings() as w:
u.Unit('angstrom', format='vounit')
assert len(w) == 1
assert '0.1nm' in str(w[0].message)
示例7: test_equivalent_units2
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [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
示例8: test_serialize_spectrum
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_serialize_spectrum(self):
flux = np.arange(1, 200) * units.Jy
wavelength = np.arange(1, 200) * units.Angstrom
spectrum = Spectrum1D(spectral_axis=wavelength, flux=flux)
serialized = self.serializer.serialize(spectrum)
self.assertTrue(type(serialized) is str)
serialized = json.loads(serialized)
self.assertTrue(serialized['photon_flux'])
self.assertTrue(serialized['photon_flux_units'])
self.assertTrue(serialized['wavelength'])
self.assertTrue(serialized['wavelength_units'])
示例9: test_deserialize_spectrum
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_deserialize_spectrum(self):
serialized_spectrum = json.dumps({
'photon_flux': [1, 2],
'photon_flux_units': 'ph / (Angstrom cm2 s)',
'wavelength': [1, 2],
'wavelength_units': 'Angstrom'
})
deserialized = self.serializer.deserialize(serialized_spectrum)
self.assertTrue(type(deserialized) is Spectrum1D)
self.assertEqual(deserialized.flux.mean().value, 1.5)
self.assertEqual(deserialized.wavelength.mean().value, 1.5)
示例10: __new__
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def __new__(cls, flux, wavelength, scale=None, unit=Angstrom,
wavelength_unit=Angstrom, ivar=None, std=None,
mask=None, dtype=None, copy=True, pixmask_flag=None, **kwargs):
flux = np.array(flux)
# If the scale is defined, creates a new composite unit with the input scale.
if scale is not None:
unit = CompositeUnit(unit.scale * scale, unit.bases, unit.powers)
obj = Quantity(flux, unit=unit, dtype=dtype, copy=copy)
obj = obj.view(cls)
obj._set_unit(unit)
obj.ivar = np.array(ivar) if ivar is not None else None
obj.mask = np.array(mask) if mask is not None else None
if std is not None:
assert ivar is None, 'std and ivar cannot be used at the same time.'
obj._std = np.array(std)
assert wavelength is not None, 'invalid wavelength'
if isinstance(wavelength, Quantity):
obj.wavelength = wavelength
else:
obj.wavelength = np.array(wavelength) * wavelength_unit
obj.pixmask_flag = pixmask_flag
return obj
示例11: test_units_with_bounding_box
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_units_with_bounding_box():
points = np.arange(10, 20)
table = np.arange(10) * u.Angstrom
t = models.Tabular1D(points, lookup_table=table)
assert isinstance(t(10), u.Quantity)
assert isinstance(t(10, with_bounding_box=True), u.Quantity)
assert_quantity_allclose(t(10), t(10, with_bounding_box=True))
示例12: test_bad_compound_without_units
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_bad_compound_without_units(model):
with pytest.raises(ValueError):
x = np.linspace(-5, 5, 10) * u.Angstrom
with NumpyRNGContext(12345):
y = np.random.sample(10)
fitter = fitting.LevMarLSQFitter()
res_fit = fitter(model, x, y * u.Hz)
示例13: test_fits_scale_factor_errors
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def test_fits_scale_factor_errors():
with pytest.raises(ValueError):
x = u.Unit('1000 erg/(s cm**2 Angstrom)', format='fits')
with pytest.raises(ValueError):
x = u.Unit('12 erg/(s cm**2 Angstrom)', format='fits')
x = u.Unit(1.2 * u.erg)
with pytest.raises(ValueError):
x.to_string(format='fits')
x = u.Unit(100.0 * u.erg)
assert x.to_string(format='fits') == '10**2 erg'
示例14: get_2d_wcs
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def get_2d_wcs(self, data=None, key=None):
"""Get simplified WCS of the 2D spectrum
Parameters
----------
data : array-like
Put this data in the output HDU rather than empty zeros
key : None
Key for WCS extension, passed to `~astropy.wcs.WCS.to_header`.
Returns
-------
hdu : `~astropy.io.fits.ImageHDU`
Image HDU with header and data properties.
wcs : `~astropy.wcs.WCS`
WCS appropriate for the 2D spectrum with spatial (y) and spectral
(x) axes.
.. note::
Assumes linear dispersion and trace functions!
"""
h = pyfits.Header()
h['WCSNAME'] = 'BeamLinear2D'
h['CRPIX1'] = self.beam.sh_beam[0]/2 - self.beam.xcenter
h['CRPIX2'] = self.beam.sh_beam[0]/2 - self.beam.ycenter
# Wavelength, A
h['CNAME1'] = 'Wave-Angstrom'
h['CTYPE1'] = 'WAVE'
#h['CUNIT1'] = 'Angstrom'
h['CRVAL1'] = self.beam.lam_beam[0]
h['CD1_1'] = self.beam.lam_beam[1] - self.beam.lam_beam[0]
h['CD1_2'] = 0.
# Linear trace
h['CNAME2'] = 'Trace'
h['CTYPE2'] = 'LINEAR'
h['CRVAL2'] = -1*self.beam.ytrace_beam[0]
h['CD2_2'] = 1.
h['CD2_1'] = -(self.beam.ytrace_beam[1] - self.beam.ytrace_beam[0])
if data is None:
data = np.zeros(self.beam.sh_beam, dtype=np.float32)
hdu = pyfits.ImageHDU(data=data, header=h)
wcs = pywcs.WCS(hdu.header)
#wcs.pscale = np.sqrt(wcs.wcs.cd[0,0]**2 + wcs.wcs.cd[1,0]**2)*3600.
wcs.pscale = utils.get_wcs_pscale(wcs)
return hdu, wcs
示例15: __new__
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Angstrom [as 别名]
def __new__(cls, value, wavelength, scale=None, unit=units.dimensionless_unscaled,
wavelength_unit=units.Angstrom, redcorr=None, ivar=None, mask=None,
binid=None, pixmask_flag=None, dtype=None, copy=True, **kwargs):
# If the scale is defined, creates a new composite unit with the input scale.
if scale is not None:
unit = units.CompositeUnit(unit.scale * scale, unit.bases, unit.powers)
assert wavelength is not None, 'a valid wavelength array is required'
assert isinstance(value, np.ndarray) and value.ndim == 3, 'value must be a 3D array.'
assert isinstance(wavelength, np.ndarray) and wavelength.ndim == 1, \
'wavelength must be a 1D array.'
assert len(wavelength) == value.shape[0], \
'wavelength and value spectral dimensions do not match'
if ivar is not None:
assert isinstance(ivar, np.ndarray) and ivar.shape == value.shape, 'invalid ivar shape'
if mask is not None:
assert isinstance(mask, np.ndarray) and mask.shape == value.shape, 'invalid mask shape'
if binid is not None:
assert (isinstance(binid, np.ndarray) and
binid.shape == value.shape[1:]), 'invalid binid shape'
obj = units.Quantity(value, unit=unit, **kwargs)
obj = obj.view(cls)
obj._set_unit(unit)
assert wavelength is not None, 'invalid wavelength'
if isinstance(wavelength, units.Quantity):
obj.wavelength = wavelength
else:
obj.wavelength = np.array(wavelength) * wavelength_unit
obj.ivar = np.array(ivar) if ivar is not None else None
obj.mask = np.array(mask) if mask is not None else None
obj.binid = np.array(binid) if binid is not None else None
obj.pixmask_flag = pixmask_flag
if redcorr is not None:
assert len(redcorr) == len(obj.wavelength), 'invalid length for redcorr.'
obj.redcorr = np.array(redcorr)
return obj