get_pixel_mapping#
- mufasa.utils.fits_utils.get_pixel_mapping(header1, header2)[source]#
Compute the pixel mapping between two FITS headers or WCS objects.
This function determines how pixel coordinates in one FITS header or WCS (header1) map to pixel coordinates in another (header2). It returns a grid that describes the transformation in terms of world coordinates.
- Parameters:
header1 (~astropy.io.fits.Header or ~astropy.wcs.WCS) – The header or WCS corresponding to the input image whose pixel coordinates are being transformed.
header2 (~astropy.io.fits.Header or ~astropy.wcs.WCS) – The header or WCS corresponding to the output image onto which the input image will be interpolated.
- Returns:
grid – A 2D array of shape (2, n, m) where n and m are the dimensions of header2. The array contains the mapped pixel coordinates from header1 in the following order: - grid[0, :, :]: The y-coordinates in header1. - grid[1, :, :]: The x-coordinates in header1.
- Return type:
~numpy.ndarray
- Raises:
TypeError – If either header1 or header2 is not an instance of astropy.io.fits.Header or astropy.wcs.WCS.
NotImplementedError – If the coordinate system type (CTYPE) in the headers is not recognized or if unit conversions between coordinate systems are not implemented.
Notes
The function supports transformations between images that share compatible celestial coordinate systems, such as GLON/GLAT and RA/DEC.
If the coordinate systems differ, they will be transformed to align before computing the pixel mapping.
The code here is borrowed from FITS_tools.downsample.
Examples
>>> from astropy.io import fits >>> from astropy.wcs import WCS >>> header1 = fits.Header() # Define input header or WCS >>> header2 = fits.Header() # Define output header or WCS >>> grid = get_pixel_mapping(header1, header2) >>> print(grid.shape) (2, n, m) # Example output shape corresponding to header2 dimensions