How to use the tweakwcs.wcsimage.RefCatalog 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 / imalign.py View on Github external
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')
            )

            refcat = RefCatalog(rcat, name=refcat_name)

        elif isinstance(refcat, astropy.table.Table):
            if 'RA' not in refcat.colnames or 'DEC' not in refcat.colnames:
                raise KeyError("Reference catalogs *must* contain *both* 'RA' "
                               "and 'DEC' columns.")
            refcat = RefCatalog(
                refcat, name=refcat.meta.get('name', 'Unnamed')
            )

        else:
            raise TypeError("Unsupported 'refcat' type. Supported 'refcat' "
                            "types are 'tweakwcs.tpwcs.TPWCS' and "
                            "'astropy.table.Table'")

    # find group ID and assign images to groups:
    grouped_images = collections.defaultdict(list)
github spacetelescope / tweakwcs / tweakwcs / imalign.py View on Github external
try:
        # Attempt to set initial status to FAILED.
        tpwcs.meta['fit_info'] = {'status': 'FAILED: Unknown error'}
    except Exception:
        raise AttributeError("Unable to set/modify tpwcs.meta attribute.")

    # check fitgeom:
    fitgeom = fitgeom.lower()
    if fitgeom not in ['shift', 'rscale', 'general']:
        raise ValueError("Unsupported 'fitgeom'. Valid values are: "
                         "'shift', 'rscale', or 'general'")

    wimcat = WCSImageCatalog(imcat, tpwcs,
                             name=imcat.meta.get('name', 'Unnamed'))
    wgcat = WCSGroupCatalog(wimcat, name=imcat.meta.get('name', 'Unnamed'))
    wrefcat = RefCatalog(refcat, name=imcat.meta.get('name', 'Unnamed'))

    succes = wgcat.align_to_ref(refcat=wrefcat, match=None, minobj=None,
                                fitgeom=fitgeom, nclip=nclip, sigma=sigma)

    tpwcs.meta['fit_info'] = wimcat.fit_info
    if not succes:
        log.warning("Failed to align catalog '{}'.".format(wgcat.name))

    # log running time:
    runtime_end = datetime.now()
    log.info(" ")
    log.info("***** {:s}.{:s}() ended on {}"
             .format(__name__, function_name, runtime_end))
    log.info("***** {:s}.{:s}() TOTAL RUN TIME: {}"
             .format(__name__, function_name, runtime_end - runtime_begin))
    log.info(" ")
github spacetelescope / tweakwcs / tweakwcs / imalign.py View on Github external
# 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')
            )

            refcat = RefCatalog(rcat, name=refcat_name)

        elif isinstance(refcat, astropy.table.Table):
            if 'RA' not in refcat.colnames or 'DEC' not in refcat.colnames:
                raise KeyError("Reference catalogs *must* contain *both* 'RA' "
                               "and 'DEC' columns.")
            refcat = RefCatalog(
                refcat, name=refcat.meta.get('name', 'Unnamed')
            )

        else:
            raise TypeError("Unsupported 'refcat' type. Supported 'refcat' "
                            "types are 'tweakwcs.tpwcs.TPWCS' and "
                            "'astropy.table.Table'")

    # find group ID and assign images to groups:
    grouped_images = collections.defaultdict(list)
    for wcat in wcs_im_cats:
        grouped_images[wcat.group_id].append(wcat)

    # create WCSImageCatalog and WCSGroupCatalog:
    wcs_gcat = []
    for group_id, wcatalogs in grouped_images.items():
github spacetelescope / tweakwcs / tweakwcs / imalign.py View on Github external
if (refcat is None and len(wcs_gcat) < 2) or len(wcs_gcat) == 0:
        raise ValueError("Too few input images (or groups of images) with "
                         "non-empty catalogs.")

    # get the first image to be aligned and
    # create reference catalog if needed:
    if refcat is None:
        # create reference catalog:
        ref_imcat, current_wcat = max_overlap_pair(
            images=wcs_gcat,
            enforce_user_order=enforce_user_order or not expand_refcat
        )
        log.info("Selected image '{}' as reference image"
                 .format(ref_imcat.name))

        refcat = RefCatalog(ref_imcat.catalog, name=ref_imcat[0].name)

        for wcat in ref_imcat:
            wcat.tpwcs.meta['fit_info'] = {'status': 'REFERENCE'}

    else:
        # find the first image to be aligned:
        current_wcat = max_overlap_image(
            refimage=refcat,
            images=wcs_gcat,
            enforce_user_order=enforce_user_order or not expand_refcat
        )

    while current_wcat is not None:
        log.info("Aligning image catalog '{}' to the reference catalog."
                 .format(current_wcat.name))