Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
------
ValueError
If the WCS is not 2D, an exception will be raised. If the specified accuracy
(both forward and inverse, both rms and maximum) is not achieved an exception
will be raised.
Notes
-----
Use of this requires a judicious choice of required accuracies. Attempts to use
higher degrees (~7 or higher) will typically fail due floating point problems
that arise with high powers.
"""
if not isinstance(self.output_frame, cf.CelestialFrame):
raise ValueError(
"The to_fits_sip method only works with celestial frame transforms")
transform = self.forward_transform
# Determine reference points.
if bounding_box is None and self.bounding_box is None:
raise ValueError("A bounding_box is needed to proceed.")
if bounding_box is None:
bounding_box = self.bounding_box
(xmin, xmax), (ymin, ymax) = bounding_box
crpix1 = (xmax - xmin) // 2
crpix2 = (ymax - ymin) // 2
crval1, crval2 = transform(crpix1, crpix2)
hdr = fits.Header()
hdr['naxis'] = 2
def _tpcorr_init(v2_ref, v3_ref, roll_ref):
s2c = SphericalToCartesian(name='s2c', wrap_lon_at=180)
c2s = CartesianToSpherical(name='c2s', wrap_lon_at=180)
unit_conv = Scale(1.0 / 3600.0, name='arcsec_to_deg_1D')
unit_conv = unit_conv & unit_conv
unit_conv.name = 'arcsec_to_deg_2D'
unit_conv_inv = Scale(3600.0, name='deg_to_arcsec_1D')
unit_conv_inv = unit_conv_inv & unit_conv_inv
unit_conv_inv.name = 'deg_to_arcsec_2D'
affine = AffineTransformation2D(name='tp_affine')
affine_inv = AffineTransformation2D(name='tp_affine_inv')
rot = RotationSequence3D(
[v2_ref, -v3_ref, roll_ref],
'zyx',
name='det_to_optic_axis'
def _tpcorr_init(v2_ref, v3_ref, roll_ref):
s2c = SphericalToCartesian(name='s2c', wrap_lon_at=180)
c2s = CartesianToSpherical(name='c2s', wrap_lon_at=180)
unit_conv = Scale(1.0 / 3600.0, name='arcsec_to_deg_1D')
unit_conv = unit_conv & unit_conv
unit_conv.name = 'arcsec_to_deg_2D'
unit_conv_inv = Scale(3600.0, name='deg_to_arcsec_1D')
unit_conv_inv = unit_conv_inv & unit_conv_inv
unit_conv_inv.name = 'deg_to_arcsec_2D'
affine = AffineTransformation2D(name='tp_affine')
affine_inv = AffineTransformation2D(name='tp_affine_inv')
rot = RotationSequence3D(
[v2_ref, -v3_ref, roll_ref],
'zyx',
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)
if isinstance(coords[0], time.Time):
ref_value = self.reference_frame.value
if not isinstance(ref_value, np.ndarray):
return (coords[0] - self.reference_frame).to(self.unit[0])
else:
# If we can't convert to a quantity just drop the object out
# and hope the transform can cope.
return coords[0]
# Is already a quantity
elif hasattr(coords[0], 'unit'):
return coords[0]
else:
raise ValueError("Can not convert {} to Quantity".format(coords[0]))
class CompositeFrame(CoordinateFrame):
"""
Represents one or more frames.
Parameters
----------
frames : list
List of frames (TemporalFrame, CelestialFrame, SpectralFrame, CoordinateFrame).
name : str
Name for this frame.
"""
def __init__(self, frames, name=None):
self._frames = frames[:]
naxes = sum([frame._naxes for frame in self._frames])
axes_type = list(range(naxes))
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)
return StokesProfile(out.item())
elif nans.all():
return np.array(out, dtype=float)
return out
def __new__(cls, content):
content = str(content)
if content not in cls.profiles.keys():
raise ValueError(f"The profile name must be one of {cls.profiles.keys()} not {content}")
return str.__new__(cls, content)
def value(self):
return self.profiles[self]
class StokesFrame(CoordinateFrame):
"""
A coordinate frame for representing stokes polarisation states
Parameters
----------
name : str
Name of this frame.
"""
def __init__(self, axes_order=(0,), name=None):
super(StokesFrame, self).__init__(1, ["STOKES"], axes_order, name=name,
axes_names=("stokes",), unit=u.one,
axis_physical_types="phys.polarization.stokes")
@property
def _world_axis_object_classes(self):
def from_tree(cls, node, ctx):
node = cls._from_tree(node, ctx)
return CoordinateFrame(**node)
return coords
@property
def axis_physical_types(self):
return self._axis_physical_types
@property
def _world_axis_object_components(self):
raise NotImplementedError(f"This method is not implemented for {type(self)}")
@property
def _world_axis_object_classes(self):
raise NotImplementedError(f"This method is not implemented for {type(self)}")
class CelestialFrame(CoordinateFrame):
"""
Celestial Frame Representation
Parameters
----------
axes_order : tuple of int
A dimension in the input data that corresponds to this axis.
reference_frame : astropy.coordinates.builtin_frames
A reference frame.
unit : str or units.Unit instance or iterable of those
Units on axes.
axes_names : list
Names of the axes in this frame.
name : str
Name of this frame.
"""