fitsmgmt.wcs.wcsremove

fitsmgmt.wcs.wcsremove(
    path_or_header=None,
    additional_keys=None,
    ccddata=True,
    extension=None,
    output=None,
    output_verify='fix',
    overwrite=False,
    checksum=False,
    verbose=True,
)

Remove most ~astropy.wcs.WCS related keywords from the header.

Parameters

path_or_header : str, ~astropy.io.fits.Header, optional. = None

The path to the FITS file, or the header to be modified. If it is header, ccddata, extension, output, output_verify, overwrite, and checksum will be ignored. Default: None.

additional_keys : list of regex str = None

Additional keys given by the user to be ‘reset’. It must be in regex expression. Of course regex accepts just string, like ‘NAXIS1’. Default: None.

ccddata : bool, optional. = True

Whether to return ~astropy.nddata.CCDData. Default is True. If False, it will return ~astropy.io.fits.PrimaryHDU of the extension.

Note

If there is no need to use the returned astropy.nddata.CCDData, it is better to set ccddata=False to improve the performance.

Warning

The returned astropy.nddata.CCDData will have ccd.wcs as None, while if the saved output is read by ~astropy.nddata.CCDData.read(filename), it will have the proper ccd.wcs.

extension : int, str, (str, int), optional. = None

The extension of FITS to be used. It can be given as integer (0-indexing) of the extension, EXTNAME (single str), or a tuple of str and int: (EXTNAME, EXTVER). If None (default), the first extension with data will be used. Default: None.

output : str or ~pathlib.Path, optional. = None

The output file path. Default: None.

output_verify : str, optional. = 'fix'

Output verification option. Must be one of "fix", "silentfix", "ignore", "warn", or "exception". May also be any combination of "fix" or "silentfix" with "+ignore", +warn, or +exception" (e.g.“fix+warn”). See :ref:`astropy:verify` for more info. Default:‘fix’``.

overwrite : bool = False

If True, overwrite the output file if it exists. Raises an OSError if False and the output file exists. Default is False.

checksum : bool = False

If True, adds both DATASUM and CHECKSUM cards to the headers of all HDU’s written to the file. Default: False.

Notes

For air.wcsremove("test.fit") with a simple 33.6MB FITS file (71 keywords, 20 ~astropy.wcs.WCS-related keywords, 5 COMMENTs) on MBP 14” [2021, macOS 13.1, M1Pro(6P+2E/G16c/N16c/32G)]:

V A C
O X O = 10.6 ± 0.2 ms (DEFAULT)
X X O = 10.8 ± 0.3 ms (almost no benefit)  - effect of verbose

Here::

* A : additional_keys=["COMMEnT"]
* V : verbose=True
* C : ccddata=True

With additional_keys (the payoff is not that big):

V A C
O O O = 11.2 ± 0.4 ms
X O O = 10.6 ± 0.2 ms

Return ~astropy.io.fits.PrimaryHDU without converting to ~astropy.nddata.CCDData (almost 5x faster):

V A C
X X X =  1.9 ± 0.0 ms
X O X =  2.1 ± 0.0 ms

The time it takes to parse the header and open the file is 0.4 ms, so the key removal part is changed from ~ 10 ms to ~ 1.5 ms (6-7 times faster)

Same benchmark on MBP 14” [2024, macOS 26.4.1, M4Pro(8P+4E/G20c/N16c/48G)], 2026-05-27, using a 33.6 MB FITS file:

V A C
O X O = 2.88 ± 0.05 ms
X X O = 2.93 ± 0.16 ms
O O O = 2.88 ± 0.04 ms
X O O = 2.92 ± 0.26 ms
X X X = 2.89 ± 0.06 ms
X O X = 2.89 ± 0.15 ms

Reproduction:

whdr = fits.Header()
whdr["BUNIT"] = "adu"
whdr["CTYPE1"] = "RA---TAN"
whdr["CTYPE2"] = "DEC--TAN"
whdr["CRPIX1"] = 1024.0
whdr["CRPIX2"] = 1024.0
whdr["CRVAL1"] = 10.0
whdr["CRVAL2"] = 20.0
whdr["CD1_1"] = -1e-4
whdr["CD1_2"] = 0.0
whdr["CD2_1"] = 0.0
whdr["CD2_2"] = 1e-4
whdr["EQUINOX"] = 2000.0
fits.writeto(
    "wcs_33mb.fits",
    np.zeros((2048, 2048), dtype="float64"),
    whdr,
    overwrite=True,
)
%timeit air.wcsremove("wcs_33mb.fits", verbose=True, ccddata=True)
%timeit air.wcsremove("wcs_33mb.fits", verbose=False, ccddata=True)
%timeit air.wcsremove("wcs_33mb.fits", additional_keys=["COMMEnT"], verbose=True, ccddata=True)
%timeit air.wcsremove("wcs_33mb.fits", additional_keys=["COMMEnT"], verbose=False, ccddata=True)
%timeit air.wcsremove("wcs_33mb.fits", verbose=False, ccddata=False)
%timeit air.wcsremove("wcs_33mb.fits", additional_keys=["COMMEnT"], verbose=False, ccddata=False)