diff --git a/csst_common/io.py b/csst_common/io.py index edb2369f12127d0c9eadb715ea4af0a033b56900..5379d0a9173cb6cd6dcb82573674810b86625955 100644 --- a/csst_common/io.py +++ b/csst_common/io.py @@ -6,10 +6,12 @@ Author: Bo Zhang Created: 2023-12-13 Modified-History: 2023-12-10, Bo Zhang, created - 2023-12-15, Bo Zhang, add verify_checksum and append_header, add module header + 2023-12-15, Bo Zhang, added verify_checksum and append_header, add module header + 2023-12-16, Bo Zhang, fixed a bug in finding the first key when reformatting """ import warnings from copy import deepcopy +from typing import Optional from astropy.io import fits @@ -86,7 +88,34 @@ def append_header( return original_h -def reformat_header(h: fits.Header, strip=True, comment=None): +def reformat_header( + h: fits.Header, + strip: bool = True, + comment: Optional[str] = None, +): + """ + Reformat fits Header. + + Remove blanks, comments, and history, and add a new comment at the beginning. + + Parameters + ---------- + h : fits.Header + The original header. + strip: bool = True + If `True`, strip cards like SIMPLE, BITPIX, etc. + so the rest of the header can be used to reconstruct another kind of header. + comment: Optional[str] = None + The new comment at the beginning. + + See Also + -------- + astropy.io.fits.Header.strip() + + References + ---------- + https://docs.astropy.org/en/stable/io/fits/api/headers.html#astropy.io.fits.Header.strip + """ h_copy = deepcopy(h) # strip if strip: