utils module¶
- ariastrotools.utils.create_fits(datadict, header_dict, filename='Avg_neid_data.fits')[source]¶
Create a multi-extension FITS file from a dictionary of data arrays and headers.
- Parameters:
datadict (dict) –
Dictionary mapping extension names to their corresponding data.
The first entry is written as the primary HDU. Remaining entries are written as
ImageHDUobjects, except those listed intablehdu, which are written asBinTableHDUobjects.header_dict (dict) – Dictionary mapping extension names to FITS header information. Each value must be compatible with
astropy.io.fits.Header.filename (str, optional) – Name of the output FITS file. Default is
"Avg_neid_data.fits".
Notes
The function automatically selects
BinTableHDUfor extensions listed intablehdu(currently onlyACTIVITY). All other extensions are written asImageHDUobjects. Existing files with the same name are overwritten.Examples
>>> datadict = { ... "PRIMARY": np.zeros((100, 100)), ... "SCIENCE": np.random.random((50, 50)), ... "ACTIVITY": structured_array, ... } >>> header_dict = { ... "PRIMARY": {"OBSERVER": "Varghese"}, ... "SCIENCE": {"EXTNAME": "SCIENCE"}, ... "ACTIVITY": {"COMMENT": "Activity indices"}, ... } >>> create_fits(datadict, header_dict, filename="output.fits")
- ariastrotools.utils.extract_allexts(fname)[source]¶
Extract all extensions from a FITS file.
- Parameters:
fname (str) – Path to the FITS file.
- Returns:
datadict (dict) – Dictionary mapping extension keywords to numpy arrays containing the data.
headerdict (dict) – Dictionary mapping extension keywords to FITS headers.
- ariastrotools.utils.extract_data_header(hdu, ext=0)[source]¶
Function to open the fits file and extract the data and header.
- ariastrotools.utils.shrink_fits(filename, extensions, replace=False, strict=True)[source]¶
Shrink a FITS file by retaining data only in selected extensions.
Extensions not listed in
extensionsare replaced with empty HDUs, preserving their headers and extension names.- Parameters:
filename (str or pathlib.Path) – Input FITS file.
extensions (list of str or int) – Extension names and/or extension numbers to retain. The primary HDU (extension 0) is always preserved.
replace (bool, optional) – If True, overwrite the original file. Otherwise create a new file with suffix
.shrink.fits. Default is False.strict (bool, optional) – If True (default), raise an exception if any requested extension does not exist. Otherwise, issue a warning and continue.
- Returns:
Name of the output FITS file.
- Return type:
str