Exemplo n.º 1
0
def fitswcs_transform_from_model(wcsinfo, wavetable=None):
    """
    Create a WCS object using from datamodel.meta.wcsinfo.
    Transforms assume 0-based coordinates.

    Parameters
    ----------
    wcsinfo : dict-like
        ``~jwst.meta.wcsinfo`` structure.

    Return
    ------
    transform : `~astropy.modeling.core.Model`
        WCS forward transform - from pixel to world coordinates.

    """
    spatial_axes, spectral_axes, unknown = gwutils.get_axes(wcsinfo)

    transform = gwutils.make_fitswcs_transform(wcsinfo)
    if spectral_axes:
        sp_axis = spectral_axes[0]
        if wavetable is None:
            # Subtract one from CRPIX which is 1-based.
            spectral_transform = astmodels.Shift(-(wcsinfo['CRPIX'][sp_axis] - 1)) | \
                astmodels.Scale(wcsinfo['CDELT'][sp_axis]) | \
                astmodels.Shift(wcsinfo['CRVAL'][sp_axis])
        else:
            # Wave dimension is an array that needs to be converted to a table
            waves = wavetable['wavelength'].flatten()
            spectral_transform = astmodels.Tabular1D(lookup_table=waves)

        transform = transform & spectral_transform

    return transform
Exemplo n.º 2
0
def fitswcs_transform_from_model(wcsinfo):
    """
    Create a WCS object using from datamodel.meta.wcsinfo.
    Transforms assume 0-based coordinates.

    Parameters
    ----------
    wcsinfo : dict-like
        ``~jwst.meta.wcsinfo`` structure.

    Return
    ------
    transform : `~astropy.modeling.core.Model`
        WCS forward transform - from pixel to world coordinates.

    """
    spatial_axes, spectral_axes, unknown = gwutils.get_axes(wcsinfo)
    #sp_axis = spectral_axes[0]

    transform = gwutils.make_fitswcs_transform(wcsinfo)
    #if wcsinfo['WCSAXES'] == 3:
    if spectral_axes:
        sp_axis = spectral_axes[0]
        # Subtract one from CRPIX which is 1-based.
        spectral_transform = astmodels.Shift(-(wcsinfo['CRPIX'][sp_axis] - 1)) | \
                           astmodels.Scale(wcsinfo['CDELT'][sp_axis]) | \
                           astmodels.Shift(wcsinfo['CRVAL'][sp_axis])
        transform = transform & spectral_transform

    return transform
Exemplo n.º 3
0
def fitswcs_transform_from_model(wcsinfo, wavetable=None):
    """
    Create a WCS object using from datamodel.meta.wcsinfo.
    Transforms assume 0-based coordinates.

    Parameters
    ----------
    wcsinfo : dict-like
        ``~jwst.meta.wcsinfo`` structure.

    Return
    ------
    transform : `~astropy.modeling.core.Model`
        WCS forward transform - from pixel to world coordinates.

    """
    spatial_axes, spectral_axes, unknown = gwutils.get_axes(wcsinfo)
    #sp_axis = spectral_axes[0]

    transform = gwutils.make_fitswcs_transform(wcsinfo)
    if spectral_axes:
        sp_axis = spectral_axes[0]
        if wavetable is None :
            # Subtract one from CRPIX which is 1-based.
            spectral_transform = astmodels.Shift(-(wcsinfo['CRPIX'][sp_axis] - 1)) | \
                astmodels.Scale(wcsinfo['CDELT'][sp_axis]) | \
                astmodels.Shift(wcsinfo['CRVAL'][sp_axis])
        else :
            # Wave dimension is an array that needs to be converted to a table
            waves = wavetable['wavelength'].flatten()
            spectral_transform = astmodels.Tabular1D(lookup_table=waves) 

        transform = transform & spectral_transform

    return transform
Exemplo n.º 4
0
def fitswcs_transform_from_model(input_model):
    """
    Create a fits wcs from a datamodel.meta.wcsinfo.
    """
    wcsinfo = {}
    wcsaxes = input_model._instance['meta']['wcsinfo']['wcsaxes']
    wcsinfo['WCSAXES'] = wcsaxes
    for key in ['CTYPE', 'CRPIX', 'CRVAL', 'CDELT', 'CUNIT']:
        val = []
        for ax in range(1, wcsaxes + 1):
            try:
                val.append(input_model._instance['meta']['wcsinfo'][(
                    key + "{0}".format(ax)).lower()])
            except KeyError:
                pass
        wcsinfo[key.upper()] = val

    pc = np.zeros((wcsaxes, 2))

    for i in range(1, wcsaxes + 1):
        for j in range(1, 3):
            pc[i - 1, j - 1] = input_model._instance['meta']['wcsinfo'][
                'pc{0}_{1}'.format(i, j)]
    wcsinfo['PC'] = pc
    # getting "coordinates" from the schema is currently broken.
    wcsinfo[
        'RADESYS'] = 'ICRS'  #input_model._instance['meta']['coordinates']['reference_frame']
    wcsinfo['has_cd'] = False
    transform = gwutils.make_fitswcs_transform(wcsinfo)
    return transform
Exemplo n.º 5
0
def test_reproject():
    hdr1 = fits.Header.fromfile(get_pkg_data_filename('data/simple_wcs.hdr'))
    hdr2 = fits.Header.fromfile(get_pkg_data_filename('data/simple_wcs2.hdr'))
    w1 = fitswcs.WCS(hdr1)
    w2 = fitswcs.WCS(hdr2)
    gw2 = wcs.WCS(output_frame='icrs',
                  forward_transform=gwutil.make_fitswcs_transform(hdr2))
    func1 = reproject(w1, w2)
    func2 = reproject(w1, gw2)
    x1, y1 = func1(1, 2)
    x2, y2 = func2(1, 2)
    utils.assert_allclose(x1, x2, atol=10**-7)
    utils.assert_allclose(y1, y2, atol=10**-7)
Exemplo n.º 6
0
def test_reproject():
    hdr1 = fits.Header.fromfile(get_pkg_data_filename('data/simple_wcs.hdr'))
    hdr2 = fits.Header.fromfile(get_pkg_data_filename('data/simple_wcs2.hdr'))
    w1 = fitswcs.WCS(hdr1)
    w2 = fitswcs.WCS(hdr2)
    gw2 = wcs.WCS(output_frame='icrs',
                  forward_transform=gwutil.make_fitswcs_transform(hdr2))
    func1 = reproject(w1, w2)
    func2 = reproject(w1, gw2)
    x1, y1 = func1(1, 2)
    x2, y2 = func2(1, 2)
    utils.assert_allclose(x1, x2, atol=10**-7)
    utils.assert_allclose(y1, y2, atol=10**-7)
Exemplo n.º 7
0
def fitswcs_transform_from_model(wcsinfo):
    """
    Create a fits wcs from a datamodel.meta.wcsinfo.
    """
    spatial_axes, spectral_axes = gwutils.get_axes(wcsinfo)

    transform = gwutils.make_fitswcs_transform(wcsinfo)
    if wcsinfo['WCSAXES'] == 3:
        spectral_transform = astmodels.Shift(-wcsinfo['CRPIX'][spectral_axes]) | \
                           astmodels.Scale(wcsinfo['CDELT'][spectral_axes]) | \
                           astmodels.Shift(wcsinfo['CRVAL'][spectral_axes])
        transform = transform & spectral_transform

    return transform
Exemplo n.º 8
0
def create_fitswcs_transform(input_model):
    ff = fits_support.to_fits(input_model._instance, input_model._schema)
    hdu = fits_support.get_hdu(ff._hdulist, "PRIMARY")
    header = hdu.header
    transform = gwutils.make_fitswcs_transform(header)
    return transform
Exemplo n.º 9
0
def create_fitswcs_transform(input_model):
    ff = fits_support.to_fits(input_model._instance, input_model._schema)
    hdu = fits_support.get_hdu(ff._hdulist, "PRIMARY")
    header = hdu.header
    transform = gwutils.make_fitswcs_transform(header)
    return transform