How to use the tweakwcs.tpwcs.TPWCS function in tweakwcs

To help you get started, we’ve selected a few tweakwcs 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 / tweakwcs / tweakwcs / tpwcs.py View on Github external
def _get_submodel(model, name):
    """ Return the first occurence of a sub-model. Search is performed by
        model name.
    """
    if not isinstance(model, CompoundModel):
        return model if model.name == name else None

    for m in model.traverse_postorder():
        if m.name == name:
            return m

    return None


class JWSTgWCS(TPWCS):
    """ A class for holding ``JWST`` ``gWCS`` information and for managing
    tangent-plane corrections.

    """
    def __init__(self, wcs, wcsinfo, meta=None):
        """
        Parameters
        ----------
        wcs: GWCS
            A `GWCS` object.

        wcsinfo: dict
            A dictionary containing reference angles of ``JWST`` instrument
            provided in the ``wcsinfo`` property of ``JWST`` meta data.

            This dictionary **must contain** the following keys and values:
github spacetelescope / tweakwcs / tweakwcs / wcsimage.py View on Github external
def tpwcs(self, tpwcs):
        """ Get/Set catalog's WCS (a :py:class:`TPWCS`-derived object).

        .. note::
            Setting the WCS triggers automatic bounding polygon recalculation.

        Parameters
        ----------
        tpwcs: TPWCS
            ``TPWCS``-derived tangent-plane WCS corrector object associated
            with the image from which the catalog was extracted.

        """
        if not isinstance(tpwcs, TPWCS):
            raise TypeError("Unsupported 'tpwcs' type. "
                            "'tpwcs' must be a subtype of TPWCS.")
        self._tpwcs = tpwcs

        # create spherical polygon bounding the image
        self.calc_bounding_polygon()
github spacetelescope / tweakwcs / tweakwcs / imalign.py View on Github external
different tangent plane.

    """
    function_name = align_wcs.__name__

    # Time it
    runtime_begin = datetime.now()

    log.info(" ")
    log.info("***** {:s}.{:s}() started on {}"
             .format(__name__, function_name, runtime_begin))
    log.info("      Version {}".format(__version__))
    log.info(" ")

    # Check that type of `wcscat` is correct and set initial status to FAILED:
    if isinstance(wcscat, TPWCS):
        wcscat = [wcscat]
        start = 1
    else:
        start = 0

    if not (hasattr(wcscat, '__iter__') and all(isinstance(wcat, TPWCS)
                                                for wcat in wcscat[start:])):
        raise TypeError("Input 'wcscat' must be either a single TPWCS-derived "
                        " object or a list of TPWCS-derived objects.")

    wcs_im_cats = []
    for wcat in wcscat:
        if wcat.meta.get('catalog', None) is None:
            raise ValueError("Each object in 'wcscat' must have a valid "
                             "catalog.")
github spacetelescope / tweakwcs / tweakwcs / tpwcs.py View on Github external
    @property
    def meta(self):
        return self._meta

    @property
    def bounding_box(self):
        """
        Get the bounding box (if any) of the underlying image for which
        the original WCS is defined.

        """
        return None


class FITSWCS(TPWCS):
    """ A class for holding ``FITS`` ``WCS`` information and for managing
    tangent-plane corrections.

    .. note::
        Currently only WCS objects that have ``CPDIS``, ``DET2IM``, and ``SIP``
        distortions *before* the application of the ``CD`` or ``PC`` matrix are
        supported.

    """
    def __init__(self, wcs, meta=None):
        """
        Parameters
        ----------

        wcs: astropy.wcs.WCS
            An `astropy.wcs.WCS` object.
github spacetelescope / tweakwcs / tweakwcs / imalign.py View on Github external
fitgeom = fitgeom.lower()
    if fitgeom not in ['shift', 'rscale', 'general']:
        raise ValueError("Unsupported 'fitgeom'. Valid values are: "
                         "'shift', 'rscale', or 'general'")

    if minobj is None:  # pragma: no branch
        if fitgeom == 'general':
            minobj = 3
        elif fitgeom == 'rscale':
            minobj = 2
        else:
            minobj = 1

    # process reference catalog or image if provided:
    if refcat is not None:
        if isinstance(refcat, TPWCS):
            if 'catalog' not in refcat.meta:
                raise ValueError("Reference 'TPWCS' must contain a "
                                 "catalog.")

            rcat = refcat.meta['catalog'].copy()

            if not ('RA' in rcat.colnames and 'DEC' in rcat.colnames):  # pragma: no branch
                # convert image x & y to world coordinates:
                ra, dec = refcat.det_to_world(rcat['x'], rcat['y'])
                rcat['RA'] = ra
                rcat['DEC'] = dec

            refcat_name = refcat.meta.get(
                'name', rcat.meta.get('name', 'Unnamed')
            )