Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __call__(self, pixel_indices):
transformed = pixel_indices + self.pmin
return super(Spectrum1DIRAFLegendreWCS, self).__call__(transformed)
def get_fits_spec(self):
# if abs(self.indexer.step) != 1:
# raise Spectrum1DWCSFITSError("WCS with indexer step greater than 1"
# "cannot be written")
func_type = 2
order = self.degree + 1
coefficients = [self.__getattr__('c{0}'.format(i)).value
for i in range(order)]
return [func_type, order, self.pmin, self.pmax] + coefficients
class Spectrum1DIRAFChebyshevWCS(BaseSpectrum1DWCS, polynomial.Chebyshev1D):
"""
WCS for polynomial dispersion using Chebyshev polynomials with
transformation required for processing IRAF specification described at
http://iraf.net/irafdocs/specwcs.php
See Also
--------
astropy.modeling.polynomial.Chebyshev1D
astropy.modeling.polynomial.Polynomial1D
"""
def __init__(self, order, pmin, pmax, **coefficients):
super(Spectrum1DIRAFChebyshevWCS, self).__init__(
order-1, domain=[pmin, pmax], **coefficients)
self.pmin = pmin
self.pmax = pmax
Add a new equivalency
Parameters
----------
new_equiv: list
A list of equivalency mappings
Examples
--------
>>> wcs.add_equivalency(u.doppler_optical(5*u.AA))
"""
u.core._normalize_equivalencies(new_equiv)
self._equivalencies += new_equiv
class Spectrum1DLookupWCS(BaseSpectrum1DWCS):
"""
A simple lookup table wcs
Parameters
----------
lookup_table : ~np.ndarray or ~astropy.units.Quantity
lookup table for the array
"""
n_inputs = 1
n_outputs = 1
lookup_table_parameter = Parameter('lookup_table_parameter')
def __init__(self, lookup_table, unit=None,
lookup_table_interpolation_kind='linear'):
def __call__(self, pixel_indices):
transformed = pixel_indices + self.pmin
return super(Spectrum1DIRAFChebyshevWCS, self).__call__(transformed)
def get_fits_spec(self):
# if abs(self.indexer.step) != 1:
# raise Spectrum1DWCSFITSError("WCS with indexer step greater than 1"
# "cannot be written")
func_type = 1
order = self.degree + 1
coefficients = [self.__getattr__('c{0}'.format(i)).value
for i in range(order)]
return [func_type, order, self.pmin, self.pmax] + coefficients
class Spectrum1DIRAFBSplineWCS(BaseSpectrum1DWCS, BSplineModel):
"""
WCS for polynomial dispersion using BSpline functions with transformation
required for processing IRAF specification described at
http://iraf.net/irafdocs/specwcs.php
"""
def __init__(self, degree, npieces, y, pmin, pmax):
from scipy.interpolate import splrep
self.npieces = npieces
self.y = y
x = np.arange(npieces + degree)
knots, coefficients, _ = splrep(x, y, k=degree)
super(Spectrum1DIRAFBSplineWCS, self).__init__(degree, knots,
coefficients)
self.pmin = pmin
raise NotImplementedError(
'Interpolation type {0} is not implemented'.format(
self.lookup_table_interpolation_kindkind))
def invert(self, dispersion_values):
if self.lookup_table_interpolation_kind == 'linear':
return np.interp(dispersion_values,
self.lookup_table_parameter.value,
self.pixel_index, left=np.nan,
right=np.nan)
else:
raise NotImplementedError(
'Interpolation type %s is not implemented' % self.lookup_table_interpolation_kind)
class Spectrum1DPolynomialWCS(BaseSpectrum1DWCS, polynomial.Polynomial1D):
"""
WCS for polynomial dispersion. The only added parameter is a unit,
otherwise the same as 'astropy.modeling.polynomial.Polynomial1D'
"""
def __init__(self, degree, unit=None, domain=None, window=[-1, 1],
**params):
super(Spectrum1DPolynomialWCS, self).__init__(degree, domain=domain,
window=window, **params)
self.unit = unit
self.fits_header_writers = {'linear': self._write_fits_header_linear,
'matrix': self._write_fits_header_matrix}
def evaluate(self, pixel_indices, *coeffs):
return super(Spectrum1DPolynomialWCS, self).evaluate(pixel_indices,
return DopplerShift(-self.velocity)
@property
def beta(self):
return self.velocity / constants.c
@property
def doppler_factor(self):
return math.sqrt((1 + self.beta)/(1 - self.beta))
@property
def redshift(self):
return self.doppler_factor - 1
class MultispecIRAFCompositeWCS(BaseSpectrum1DWCS, CompositeWCS):
"""
A specialized composite WCS model for IRAF FITS multispec specification.
This model adds applies doppler adjustment and log (if applicable) to the
dispersion WCS. The dispersion WCS may be a linear WCS or a weighted
combination WCS. This model stores FITS metadata and also provides a method
to generate the multispec string for the FITS header.
Parameters
-----------
dispersion_wcs : Model
the wcs that returns the raw dispersion when passed the pixel
coordinates. There is no doppler shift applied to this dispersion
num_pixels : int
the number of valid pixels
z : float, optional
the redshift, used to determine the doppler shift needed to correct the
def __init__(self, *args, **kwargs):
super(BaseSpectrum1DWCS, self).__init__(*args, **kwargs)
def _write_fits_header_matrix(self, header, spectral_axis=1):
header['cd{0}_{1}'.format(spectral_axis, spectral_axis)] = self.c1.value
header['crval{0}'.format(spectral_axis)] = self.c0.value
if self._unit is not None:
unit_string = self.unit
if isinstance(self.unit, u.UnitBase):
if self.unit == u.AA:
unit_string = 'angstroms'
else:
unit_string = self.unit.to_string()
header['cunit{0}'.format(spectral_axis)] = unit_string
class Spectrum1DIRAFLegendreWCS(BaseSpectrum1DWCS, polynomial.Legendre1D):
"""
WCS for polynomial dispersion using Legendre polynomials with
transformation required for processing IRAF specification described at
http://iraf.net/irafdocs/specwcs.php
"""
def __init__(self, order, pmin, pmax, **coefficients):
super(Spectrum1DIRAFLegendreWCS, self).__init__(
order-1, domain=[pmin, pmax], **coefficients)
self.pmin = pmin
self.pmax = pmax
def __call__(self, pixel_indices):
transformed = pixel_indices + self.pmin
return super(Spectrum1DIRAFLegendreWCS, self).__call__(transformed)
def get_fits_spec(self):