WCS & FITS#

Headers, coordinates, cropping, and reprojection helpers.

Headers#

McfHeader

A stateful wrapper around an astropy.io.fits.Header.

as_mcfheader

Return header as an McfHeader (pass-through if it already is).

save_header

Write a header to a portable plain-text .hdr file.

load_header

Load an McfHeader from a plain-text header file written by save_header() / McfHeader.totextfile().

force_header_2d

A simple function to take in a header and remove items related to 3D or 4D structure -- such as NAXIS3...

force_header_3d

Return copy of header with all 4th-axis cards removed (NAXIS=3).

force_header_floats

Helper function to force various header values to floats.

make_simple_header

Function to make a new 'simple header' from the WCS information in the input header.

squeeze_image

Squeeze a FITS image to 2D, cleaning up the header to match.

annotate_provenance_header

Add HISTORY / COMMENT cards noting that a FITS file was created with multicolorfits (version, timestamp, optional per-layer settings).

Coordinates#

sex2dec

Converts sexagesimal coordinates to decimal.

dec2sex

Converts decimal coordinates to sexagesimal.

deg2dms

Convert decimal degrees to DMS components.

dms2deg

Convert DMS string ('dd:mm:ss.s') or [d, m, s] list to decimal degrees.

deg2hour

Convert decimal degrees to [hours, minutes, seconds] list.

hour2deg

Convert HMS string ('hh:mm:ss.s') or [h, m, s] list to decimal degrees.

angular_distance

Angular distance between two sky positions using the Vincenty formula.

sky_to_pixel

Helper function to convert sky coordinates to pixel coordinates.

pixel_to_sky

Helper function to convert pixel coordinates to sky coordinates.

header_coord_grids

Per-pixel world (lon/lat) coordinates for an image grid.

get_cdelts

Function to calculate CDELT1 and CDELT2 from the input header PCx_x cards.

get_cd_matrix

Calculate the CDn_m matrix from CDELTS and CROTA/CROTA2

deg_per_pixel

Calculates degrees per pixel side.

arcsec_per_pixel

Calculates arcseconds per pixel side.

sterad_per_pixel

Calculates steradians per pixel.

beam_params_arcsec

Returns beam parameters [BMAJ (arcsec), BMIN (arcsec), BPA (deg)] from input header

pixels_per_beam

Calculates the number of pixels per beam from the beam parameters (BMAJ,BMIN) in the header.

Crop & reproject#

crop_image

Function to crop a 2D fits image to the specified pixel bounds.

crop_image_sky

Function to crop a 2D fits image based on sky coordinates and specified width.

crop_cube

Function to crop a 3D fits cube to the specified pixel bounds.

crop_cube_sky

Function to crop a 3D fits cube based on sky coordinates and specified width.

reproject_image

Function that reprojects a 2D map from the parameters in one header to the parameters in another header.

reproject_cube

Reproject a 3D cube from one WCS header onto another, plane by plane.

header_frame_name

Determine the celestial frame of a FITS header, as an astropy frame name.

convert_header_frame

Build a new 2D header in a different celestial frame, covering the same sky area as the input header with the same pixel scale, with the new frame's north axis up (no rotation).

reproject_to_frame

Reproject a 2D image into a different celestial frame (e.g. Galactic), with the new frame's north up.

reproject_to_galactic

Convenience alias for reproject_to_frame(..., frame='galactic').

optimal_common_header

Compute an optimal common header covering a set of images, using reproject.mosaicking.find_optimal_celestial_wcs.

For long spectral cubes, reproject_cube() accepts print_progress=True (drives draw_progress_bar()). See that helper’s docstring for a tqdm alternative if you prefer wrapping the per-plane loop yourself.