Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tabular_wcs(xarray):
coordinateframe = cf.CoordinateFrame(naxes=1, axes_type=('SPECTRAL',),
axes_order=(0,))
specframe = cf.SpectralFrame(unit=xarray.unit, axes_order=(0,))
transform = Tabular1D(np.arange(len(xarray)), xarray.value)
tabular_gwcs = gwcs.wcs.WCS([(coordinateframe, transform), (specframe, None)])
return tabular_gwcs
def _get_frame_index(self, frame):
"""
Return the index in the pipeline where this frame is locate.
"""
if isinstance(frame, coordinate_frames.CoordinateFrame):
frame = frame.name
frame_names = [getattr(item[0], "name", item[0]) for item in self._pipeline]
return frame_names.index(frame)
def gwcs_from_array(array):
"""
Create a new WCS from provided tabular data. This defaults to being
a GWCS object.
"""
orig_array = u.Quantity(array)
# TODO: Input arrays must be strictly ascending. This is not always the
# case for a spectral axis (e.g. when in frequency space). Thus, we
# convert to wavelength to create the wcs.
if orig_array.unit.physical_type != 'length' and \
orig_array.unit.is_equivalent(u.AA, equivalencies=u.spectral()):
array = orig_array.to(u.AA, equivalencies=u.spectral())
coord_frame = cf.CoordinateFrame(naxes=1,
axes_type=('SPECTRAL',),
axes_order=(0,))
spec_frame = cf.SpectralFrame(unit=array.unit, axes_order=(0,))
# In order for the world_to_pixel transformation to automatically convert
# input units, the equivalencies in the look up table have to be extended
# with spectral unit information.
SpectralTabular1D = type("SpectralTabular1D", (Tabular1D,),
{'input_units_equivalencies': {'x0': u.spectral()}})
forward_transform = SpectralTabular1D(np.arange(len(array)),
lookup_table=array)
forward_transform.inverse = SpectralTabular1D(
array, lookup_table=np.arange(len(array)))
class SpectralGWCS(GWCS):