How to use the gwcs.coordinate_frames.CelestialFrame 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 / wcs.py View on Github external
------
        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
github astropy / photutils / photutils / datasets / make.py View on Github external
tan = models.Pix2Sky_TAN()
    celestial_rotation = models.RotateNative2Celestial(197.8925, -1.36555556,
                                                       180.0)

    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)
github spacetelescope / gwcs / gwcs / coordinate_frames.py View on Github external
if 'distance' in _axes_names:
                        _axes_names.remove('distance')
                    if axes_names is None:
                        axes_names = _axes_names
                    naxes = len(_axes_names)
                    _unit = list(reference_frame.representation_component_units.values())
                    if unit is None and _unit:
                        unit = _unit

        if axes_order is None:
            axes_order = tuple(range(naxes))
        if unit is None:
            unit = tuple([u.degree] * naxes)
        axes_type = ['SPATIAL'] * naxes

        super(CelestialFrame, self).__init__(naxes=naxes, axes_type=axes_type,
                                             axes_order=axes_order,
                                             reference_frame=reference_frame,
                                             unit=unit,
                                             axes_names=axes_names,
                                             name=name, axis_physical_types=axis_physical_types)
github spacetelescope / gwcs / gwcs / tags / wcs.py View on Github external
def from_tree(cls, node, ctx):
        node = cls._from_tree(node, ctx)
        return CelestialFrame(**node)
github spacetelescope / gwcs / gwcs / tags / wcs.py View on Github external
return cls._to_tree(frame, ctx)


class Frame2DType(FrameType):
    name = "frame2d"
    types = [Frame2D]

    @classmethod
    def from_tree(cls, node, ctx):
        node = cls._from_tree(node, ctx)
        return Frame2D(**node)


class CelestialFrameType(FrameType):
    name = "celestial_frame"
    types = [CelestialFrame]

    @classmethod
    def from_tree(cls, node, ctx):
        node = cls._from_tree(node, ctx)
        return CelestialFrame(**node)

    @classmethod
    def to_tree(cls, frame, ctx):
        return cls._to_tree(frame, ctx)

    @classmethod
    def assert_equal(cls, old, new):
        cls._assert_equal(old, new)

        assert old.reference_position == new.reference_position  # nosec
github astropy / photutils / photutils / datasets / make.py View on Github external
rotation = models.AffineTransformation2D(cd_matrix, translation=[0, 0])
    rotation.inverse = models.AffineTransformation2D(
        np.linalg.inv(cd_matrix), translation=[0, 0])

    tan = models.Pix2Sky_TAN()
    celestial_rotation = models.RotateNative2Celestial(197.8925, -1.36555556,
                                                       180.0)

    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)
github spacetelescope / gwcs / gwcs / coordinate_frames.py View on Github external
"""
        if pht is not None:
            if isinstance(pht, str):
                pht = (pht,)
            elif not isiterable(pht):
                raise TypeError("axis_physical_types must be of type string or iterable of strings")
            if len(pht) != self.naxes:
                raise ValueError('"axis_physical_types" must be of length {}'.format(self.naxes))
            ph_type = []
            for axt in pht:
                if axt not in VALID_UCDS and not axt.startswith("custom:"):
                    ph_type.append("custom:{}".format(axt))
                else:
                    ph_type.append(axt)

        elif isinstance(self, CelestialFrame):
            if isinstance(self.reference_frame, coord.Galactic):
                ph_type = "pos.galactic.lon", "pos.galactic.lat"
            elif isinstance(self.reference_frame, (coord.GeocentricTrueEcliptic,
                                                   coord.GCRS,
                                                   coord.PrecessedGeocentric)):
                ph_type = "pos.bodyrc.lon", "pos.bodyrc.lat"
            elif isinstance(self.reference_frame, coord.builtin_frames.BaseRADecFrame):
                ph_type = "pos.eq.ra", "pos.eq.dec"
            elif isinstance(self.reference_frame, coord.builtin_frames.BaseEclipticFrame):
                ph_type = "pos.ecliptic.lon", "pos.ecliptic.lat"
            else:
                ph_type = tuple("custom:{}".format(t) for t in self.axes_names)

        elif isinstance(self, SpectralFrame):
            if self.unit[0].physical_type == "frequency":
                ph_type = ("em.freq",)