How to use the gwcs.coordinate_frames.CoordinateFrame function in gwcs

To help you get started, we’ve selected a few gwcs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spacetelescope / gwcs / gwcs / coordinate_frames.py View on Github external
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))
github astropy / specutils / specutils / wcs / wcs_wrapper.py View on Github external
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)
github spacetelescope / gwcs / gwcs / coordinate_frames.py View on Github external
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):
github spacetelescope / gwcs / gwcs / tags / wcs.py View on Github external
def from_tree(cls, node, ctx):
        node = cls._from_tree(node, ctx)
        return CoordinateFrame(**node)
github spacetelescope / gwcs / gwcs / coordinate_frames.py View on Github external
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.
    """
github spacetelescope / gwcs / gwcs / coordinate_frames.py View on Github external
if isinstance(args[0], u.Quantity):
            arg = args[0].value
        else:
            arg = args[0]

        return StokesProfile.from_index(arg)

    def coordinate_to_quantity(self, *coords):
        if isinstance(coords[0], str):
            if coords[0] in StokesProfile.profiles.keys():
                return StokesProfile.profiles[coords[0]] * u.one
        else:
            return coords[0]


class Frame2D(CoordinateFrame):
    """
    A 2D coordinate frame.

    Parameters
    ----------
    axes_order : tuple of int
        A dimension in the input data that corresponds to this axis.
    unit : list of astropy.units.Unit
        Unit for each axis.
    axes_names : list
        Names of the axes in this frame.
    name : str
        Name of this frame.
    """

    def __init__(self, axes_order=(0, 1), unit=(u.pix, u.pix), axes_names=('x', 'y'),