magwarp: Remap Image WCS via Warping

View source: R/magwarp.R

magwarpR Documentation

Remap Image WCS via Warping

Description

Remaps an input Tan Gnomonic or Sine Orthographic projection system to a different target WCS.

Usage

magwarp(image_in, header_out = NULL, header_in = NULL, dim_out, direction = "auto",
boundary = "dirichlet", interpolation = "cubic", doscale = TRUE, CRVAL1_in = 0,
CRVAL2_in = 0, CRPIX1_in = 0, CRPIX2_in = 0, CD1_1_in = 1, CD1_2_in = 0, CD2_1_in = 0,
CD2_2_in = 1, CRVAL1_out = 0, CRVAL2_out = 0, CRPIX1_out = 0, CRPIX2_out = 0,
CD1_1_out = 1, CD1_2_out = 0, CD2_1_out = 0, CD2_2_out = 1, plot = FALSE, ...)

Arguments

image_in

Numeric matrix; required, the image we want to remap. If image_in is a list as created by readFITS, read.fits of magcutoutWCS then the image part of the list is parsed to image_in and the correct header part is parsed to header_in.

header_out

Full FITS header in table or vector format. This is the target WCS projection that image_in will be mapped onto. Legal table format headers are provided by the read.fitshdr function or the hdr list output of read.fits in the astro package; the hdr output of readFITS in the FITSio package or the header output of magcutoutWCS. If header_out is provided then key words will be taken from here as a priority. Missing header keywords are printed out and other header option arguments are used in these cases.

header_in

Full FITS header in table or vector format. This should be the header WCS that matches image_in. Legal table format headers are provided by the read.fitshdr function or the hdr list output of read.fits in the astro package; the hdr output of readFITS in the FITSio package or the header output of magcutoutWCS. If header_in is provided then key words will be taken from here as a priority. Missing header keywords are printed out and other header option arguments are used in these cases.

dim_out

Integer vector; this defines the desired dimensions of the output image. If this is not provided then the output image is made to be the same size as the NAXIS1 and NAXIS2 arguments taken from header_out (which is usually what you will want TBH).

direction

"auto" (default), "forward" or "backward", see imwarp. Since it is usally better to go from the higher resolution image and map this onto the lower resolution grid, "auto" selects the better direction given the pixel scales recovered from the header information.

boundary

boundary conditions: "dirichlet", "neumann", "periodic" (default "dirichlet"), see imwarp

interpolation

"nearest", "linear", "cubic" (default "linear"), see imwarp

doscale

Logical; if TRUE (default) then the image is scaled by the relative change in the pixel scale. This is usually what you want when converting images between different WCS (since we really want to make sure we conserve overall flux). If FALSE then nothing is done to rescale the image. This is useful when the input image_in is something like a segmentation map, where the actual values matter.

CRVAL1_in

FITS header CRVAL1 for the Tan Gnomonic projection system of the input WCS. This is the RA in degrees at the location of CRPIX1.

CRVAL2_in

FITS header CRVAL2 for the Tan Gnomonic projection system of the input WCS. This is the Dec in degrees at the location of CRPIX2.

CRPIX1_in

FITS header CRPIX1 for the Tan Gnomonic projection system of the input WCS. This is the x pixel value at the location of CRVAL1.

CRPIX2_in

FITS header CRPIX2 for the Tan Gnomonic projection system of the input WCS. This is the y pixel value at the location of CRVAL2.

CD1_1_in

FITS header CD1_1 for the Tan Gnomonic projection system of the input WCS. Change in RA-Tan in degrees along x-Axis.

CD1_2_in

FITS header CD1_2 for the Tan Gnomonic projection system of the input WCS. Change in RA-Tan in degrees along y-Axis.

CD2_1_in

FITS header CD2_1 for the Tan Gnomonic projection system of the input WCS. Change in Dec-Tan in degrees along x-Axis.

CD2_2_in

FITS header CD2_2 for the Tan Gnomonic projection system of the input WCS. Change in Dec-Tan in degrees along y-Axis.

CRVAL1_out

FITS header CRVAL1 for the Tan Gnomonic projection system of the output WCS. This is the RA in degrees at the location of CRPIX1.

CRVAL2_out

FITS header CRVAL2 for the Tan Gnomonic projection system of the output WCS. This is the Dec in degrees at the location of CRPIX2.

CRPIX1_out

FITS header CRPIX1 for the Tan Gnomonic projection system of the output WCS. This is the x pixel value at the location of CRVAL1.

CRPIX2_out

FITS header CRPIX2 for the Tan Gnomonic projection system of the output WCS. This is the y pixel value at the location of CRVAL2.

CD1_1_out

FITS header CD1_1 for the Tan Gnomonic projection system of the output WCS. Change in RA-Tan in degrees along x-Axis.

CD1_2_out

FITS header CD1_2 for the Tan Gnomonic projection system of the output WCS. Change in RA-Tan in degrees along y-Axis.

CD2_1_out

FITS header CD2_1 for the Tan Gnomonic projection system of the output WCS. Change in Dec-Tan in degrees along x-Axis.

CD2_2_out

FITS header CD2_2 for the Tan Gnomonic projection system of the output WCS. Change in Dec-Tan in degrees along y-Axis.

plot

Logical; should a magimageWCS plot of the output be generated?

...

Dots are parsed to either magimageWCS (only relevant if plot=TRUE).

Details

The function allows for arbitrary WCS remapping, as long as the input and output WCS both use the Tan Gnomonic projection system (which is by far the most common with modern survey imaging data). The process internally does the following:

  • xy2radec; maps the input image to RA and Dec per pixel using the input header

  • radec2xy; maps the pixel RA and Dec coordinates onto the desired output pixel grid using the output header

There are a few different ways to consider doing pixel remapping (or warping). The main question is usually whether to operate on a forward or backwards manner (see imwarp). Backwards mapping (the default) finds the best interpolation of every output pixel in the input image, whereas forward mapping finds the best interpolation of every input pixel on the output image. Backwards mapping usually provides the fewest artefacts (hence it is the default), but in general if the input image is higher resolution then you might prefer forward mapping and vica-versa.

The actual warping is done using the imwarp function in the imager package, so this will need to be installed prior to use (it is available on CRAN).

Value

A list containing:

image

Numeric matrix; the remapped image using the target WCS.

header

The target header_out.

Note

This function uses a bi-cubic interpolation scheme by default. It should approximately conserve the flux in image_in, but this is not guaranteed. The 'linear' interpolation scheme may be closer to conserving flux in images with sharp features. The conservation is usually good to about 0.1% (i.e. 0.01 mag). If you require better conservation than this then alternative schemes (e.g. SWarp) will be required.

Author(s)

Aaron Robotham

See Also

magimageWCSRGB

Examples

## Not run: 
VISTA_K=readFITS(system.file("extdata", 'VISTA_K.fits', package="magicaxis"))
VST_r=readFITS(system.file("extdata", 'VST_r.fits', package="magicaxis"))
GALEX_NUV=readFITS(system.file("extdata", 'GALEX_NUV.fits', package="magicaxis"))

magwarp(VST_r, GALEX_NUV$hdr, plot=TRUE)
magwarp(VISTA_K, GALEX_NUV$hdr, plot=TRUE)

magwarp(GALEX_NUV, VST_r$hdr, plot=TRUE)
magwarp(VISTA_K, VST_r$hdr, plot=TRUE)

magwarp(GALEX_NUV, VISTA_K$hdr, plot=TRUE)
magwarp(VST_r, VISTA_K$hdr, plot=TRUE)

#Check we can warp forwards and backwards correctly:

magimageWCS(GALEX_NUV)
magwarp(GALEX_NUV, GALEX_NUV$hdr, plot=TRUE)
magwarp(magwarp(GALEX_NUV, VST_r$hdr, interpolation='nearest'),
        GALEX_NUV$hdr, interpolation='nearest', plot=TRUE)

## End(Not run)

magicaxis documentation built on March 18, 2022, 6:27 p.m.