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 from_array(array):
"""
Create a new WCS from provided tabular data. This defaults to being
a GWCS object.
"""
array = u.Quantity(array)
coord_frame = cf.CoordinateFrame(naxes=1,
axes_type=('SPECTRAL',),
axes_order=(0,))
spec_frame = cf.SpectralFrame(unit=array.unit, axes_order=(0,))
forward_transform = Tabular1D(np.arange(len(array)), array.value)
forward_transform.inverse = Tabular1D(array.value, np.arange(len(array)))
tabular_gwcs = gwcs.wcs.WCS(forward_transform=forward_transform,
input_frame=coord_frame,
output_frame=spec_frame)
return WCSWrapper(wcs=tabular_gwcs)
det2sky = shift_by_crpix | rotation | tan | celestial_rotation
det2sky.name = 'linear_transform'
detector_frame = cf.Frame2D(name='detector', axes_names=('x', 'y'),
unit=(u.pix, u.pix))
if galactic:
sky_frame = cf.CelestialFrame(reference_frame=coord.Galactic(),
name='galactic', unit=(u.deg, u.deg))
else:
sky_frame = cf.CelestialFrame(reference_frame=coord.ICRS(),
name='icrs', unit=(u.deg, u.deg))
pipeline = [(detector_frame, det2sky), (sky_frame, None)]
return gwcs_wcs.WCS(pipeline)
def from_tree(cls, node, ctx):
steps = [(x['frame'], x.get('transform')) for x in node['steps']]
name = node['name']
return WCS(steps, name=name)
trans = (skyrot | projection)
projection_x, projection_y = trans(lon, lat)
poly = supported_poly_types[polynomial_type](degree)
fitter = fitting.LevMarLSQFitter()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
poly_x = fitter(poly, x, y, projection_x)
poly_y = fitter(poly, x, y, projection_y)
transform = models.Mapping((0, 1, 0, 1)) | poly_x & poly_y | projection.inverse | skyrot.inverse
skyframe = CelestialFrame(reference_frame=fiducial.frame)
detector = Frame2D(name="detector")
pipeline = [(detector, transform),
(skyframe, None)
]
return WCS(pipeline)
SpectralFrame, TemporalFrame, CompositeFrame,
StokesFrame)
from ..wcs import WCS
_REQUIRES = ['astropy']
__all__ = ["WCSType", "CelestialFrameType", "CompositeFrameType", "FrameType",
"SpectralFrameType", "StepType", "TemporalFrameType", "StokesFrameType"]
class WCSType(GWCSType):
name = "wcs"
requires = _REQUIRES
types = [WCS]
version = '1.1.0'
@classmethod
def from_tree(cls, node, ctx):
steps = [(x['frame'], x.get('transform')) for x in node['steps']]
name = node['name']
return WCS(steps, name=name)
@classmethod
def to_tree(cls, gwcsobj, ctx):
def get_frame(frame_name):
frame = getattr(gwcsobj, frame_name)
if frame is None:
return frame_name
if isinstance(forward_transform, Model):
if output_frame is None:
raise CoordinateFrameError("An output_frame must be specified"
"if forward_transform is a model.")
_input_frame, inp_frame_obj = self._get_frame_name(input_frame)
_output_frame, outp_frame_obj = self._get_frame_name(output_frame)
super(WCS, self).__setattr__(_input_frame, inp_frame_obj)
super(WCS, self).__setattr__(_output_frame, outp_frame_obj)
self._pipeline = [(input_frame, forward_transform.copy()),
(output_frame, None)]
elif isinstance(forward_transform, list):
for item in forward_transform:
name, frame_obj = self._get_frame_name(item[0])
super(WCS, self).__setattr__(name, frame_obj)
#self._pipeline.append((name, item[1]))
self._pipeline = forward_transform
else:
raise TypeError("Expected forward_transform to be a model or a "
"(frame, transform) list, got {0}".format(
type(forward_transform)))
else:
# Initialize a WCS without a forward_transform - allows building a WCS programmatically.
if output_frame is None:
raise CoordinateFrameError("An output_frame must be specified"
"if forward_transform is None.")
_input_frame, inp_frame_obj = self._get_frame_name(input_frame)
_output_frame, outp_frame_obj = self._get_frame_name(output_frame)
super(WCS, self).__setattr__(_input_frame, inp_frame_obj)
super(WCS, self).__setattr__(_output_frame, outp_frame_obj)
self._pipeline = [(_input_frame, None),