FitsFileContextManager

class gdt.core.file.FitsFileContextManager[source]

Bases: AbstractContextManager

A context manager for FITS files. Includes some convenience functions.

Attributes Summary

filename

The filename

hdulist

The list of Header Data Units

headers

The headers

num_hdus

The number of HDUs

Methods Summary

close()

Close the file

column(hdu_num, col_name)

Return a column from an HDU as an array.

columns_as_array(hdu_num, col_names[, dtype])

Return a list of columns from an HDU as an array.

get_column_names(hdu_num)

Get the column names in a HDU.

hdu_index_from_name(ext_name)

Returns the index into the HDU list based on the extension name.

open(file_path[, mode, memmap])

Open a FITS file.

write(directory[, filename])

Write the file to disk.

Attributes Documentation

filename

The filename

Type:

(str)

hdulist

The list of Header Data Units

Type:

(astropy.io.fits.hdu.HDUList)

headers

The headers

Type:

(FileHeaders)

num_hdus

The number of HDUs

Type:

(int)

Methods Documentation

close()[source]

Close the file

column(hdu_num: int, col_name: str) array[source]

Return a column from an HDU as an array.

Parameters:
  • hdu_num (int) – The HDU number

  • col_name (str) – The name of the column

Returns:

(np.array)

columns_as_array(hdu_num: int, col_names: List[str], dtype: dtype = None) array[source]

Return a list of columns from an HDU as an array.

Parameters:
  • hdu_num (int) – The HDU number

  • col_names (list of str) – The names of the columns

  • dtype (np.dtype, optional) – The custom dtype of the output array

Returns:

(np.array)

get_column_names(hdu_num: int)[source]

Get the column names in a HDU. Returns empty if there is no data extension in the HDU.

Parameters:

hdu_num (int) – The HDU number

Returns:

(tuple)

hdu_index_from_name(ext_name)[source]

Returns the index into the HDU list based on the extension name. If there is no match, returns None.

Parameters:

ext_name (str) – The extension name

Returns:

(int)

classmethod open(file_path: Union[str, Path], mode: str = 'readonly', memmap: bool = None)[source]

Open a FITS file.

Parameters:
  • file_path (str) – The file path

  • mode (str) – The file access mode

  • memmap (bool) – If True, memory map when reading the file

Returns:

(FitsFileContextManager)

write(directory: Union[str, Path], filename: str = None, **kwargs)[source]

Write the file to disk.

Parameters:
  • directory (str) – The directory to write the file.

  • filename (str, optional) – The filename. If omitted, attempts to use the filename if set.