lezargus.library.fits module#

FITS file reading, writing, and other manipulations.

lezargus.library.fits.create_fits_header(input_dict: dict | Header | None = None) Header[source]#

Create a FITS header provided dictionary input.

This function creates a FITS header from provided input cards in the form of a dictionary. This function mostly exists to properly sanitize input data to better conform to the FITS standard.

Parameter#

input_dictdict, default = None

The input dictionary to create a FITS header from. If it is None, the input is considered blank.

returns:

output_header – The header made from the input.

rtype:

Astropy Header

lezargus.library.fits.create_lezargus_fits_header(header: Header, entries: dict | None = None) Header[source]#

Create a Lezargus header.

This function creates an ordered Lezargus header from a header containing both Lezargus keywords and non-Lezargus keywords. We only include the relevant headers. WCS header information is also extracted and added as we consider it within our domain even though it does not follow the keyword naming convention (as WCS keywords must follow WCS convention).

Additional header entries may be provided as a last-minute overwrite. We also operate on a copy of the header to prevent conflicts.

Parameters:
  • header (Astropy Header) – The header which the entries will be added to.

  • entries (dict, default = None) – The new entries to the header. By default, None means nothing is to be overwritten at the last minute.

Returns:

lezargus_header – The header which Lezargus entries have been be added to. The order of the entries are specified.

Return type:

Astropy Header

lezargus.library.fits.create_wcs_header_from_lezargus_header(header: Header) Header[source]#

Create WCS header keywords from Lezargus header.

See the FITS standard for more information.

Parameters:

header (Header) – The Lezargus header from which we will derive a WCS header from.

Returns:

wcs_header – The WCS header.

Return type:

Header

lezargus.library.fits.read_fits_header(filename: str, extension: int | str = 0) Header[source]#

Read a FITS file header.

This reads the header of fits files only. This should be used only if there is no data. Really, this is just a wrapper around Astropy, but it is made for consistency and to avoid the usage of the convince functions.

Parameters:
  • filename (str) – The filename that the fits image file is at.

  • extension (int or str, default = 0) – The fits extension that is desired to be opened.

Returns:

header – The header of the fits file.

Return type:

Astropy Header

lezargus.library.fits.read_lezargus_fits_file(filename: str) tuple[Header, ndarray, ndarray, ndarray, Unit, Unit, ndarray, ndarray][source]#

Read in a Lezargus fits file.

This function reads in a Lezargus FITS file and parses it based on the convention of Lezargus. See TODO for the specification. However, we do not construct the actual classes here and instead leave that to the class reader and writers of the container themselves so we can reuse error reporting code there.

In general, it is advisable to use the reading and writing class functions of the container instance you want.

Parameters:

filename (str) – The filename of the FITS file to read.

Returns:

  • header (Header) – The header of the Lezargus FITS file.

  • wavelength (ndarray) – The wavelength information of the file.

  • data (ndarray) – The data array of the Lezargus FITS file.

  • uncertainty (ndarray) – The uncertainty in the data.

  • wavelength_unit (Unit) – The unit of the wavelength array.

  • data_unit (Unit) – The unit of the data.

  • mask (ndarray) – The mask of the data.

  • flags (ndarray) – The noted flags for each of the data points.

lezargus.library.fits.write_lezargus_fits_file(filename: str, header: Header, wavelength: ndarray, data: ndarray, uncertainty: ndarray, wavelength_unit: Unit, data_unit: Unit, uncertainty_unit: Unit, mask: ndarray, flags: ndarray, overwrite: bool = False) None[source]#

Write to a Lezargus fits file.

This function reads in a Lezargus FITS file and parses it based on the convention of Lezargus. See TODO for the specification. However, we do not construct the actual classes here and instead leave that to the class reader and writers of the container themselves so we can reuse error reporting code there.

In general, it is advisable to use the reading and writing class functions of the container instance you want.

Parameters:
  • filename (str) – The filename of the FITS file to write to.

  • header (Header) – The header of the Lezargus FITS file.

  • wavelength (ndarray) – The wavelength information of the file.

  • data (ndarray) – The data array of the Lezargus FITS file.

  • uncertainty (ndarray) – The uncertainty in the data.

  • wavelength_unit (Unit) – The unit of the wavelength array.

  • data_unit (Unit) – The unit of the data.

  • uncertainty_unit (Unit) – The unit of the uncertainty of the data.

  • mask (ndarray) – The mask of the data.

  • flags (ndarray) – The noted flags for each of the data points.

  • overwrite (bool, default = False) – If True, overwrite the file upon conflicts.

Return type:

None