vip_hci.fits package

Submodules

vip_hci.fits.fits module

Module with various fits handling functions.

vip_hci.fits.fits.byteswap_array(array)[source]

FITS files are stored in big-endian byte order. All modern CPUs are little-endian byte order, so at some point you have to byteswap the data. Some FITS readers (cfitsio, the fitsio python module) do the byteswap when reading the data from disk to memory, so we get numpy arrays in native (little-endian) byte order. Unfortunately, astropy.io.fits does not byteswap for us, and we get numpy arrays in non-native byte order. However, most of the time we never notice this because when you do any numpy operations on such arrays, numpy uses an intermediate buffer to byteswap the array behind the scenes and returns the result as a native byte order array. Some operations require the data to be byteswaped before and will complain about it. This function will help in those cases.

Parameters:

array (numpy ndarray) – 2d input array.

Returns:

array_out – 2d resulting array after the byteswap operation.

Return type:

numpy ndarray

vip_hci.fits.fits.info_fits(fitsfilename, **kwargs)[source]

Print the information about a fits file.

Parameters:
  • fitsfilename (str) – Path to the fits file.

  • **kwargs (optional) – Optional arguments to the astropy.io.fits.open() function. E.g. “output_verify” can be set to ignore, in case of non-standard header.

vip_hci.fits.fits.open_fits(fitsfilename, n=0, header=False, ignore_missing_end=False, precision=<class 'numpy.float32'>, return_memmap=False, verbose=True, **kwargs)[source]

Load a fits file into memory as numpy array.

Parameters:
  • fitsfilename (string or pathlib.Path) – Name of the fits file or pathlib.Path object

  • n (int, optional) – It chooses which HDU to open. Default is the first one. If n is equal to -2, opens and returns all extensions.

  • header (bool, optional) – Whether to return the header along with the data or not.

  • precision (numpy dtype, optional) – Float precision, by default np.float32 or single precision float.

  • ignore_missing_end (bool optional) – Allows to open fits files with a header missing END card.

  • return_memmap (bool, optional) – If True, the function returns the handle to the FITS file opened by mmap. With the hdulist, array data of each HDU to be accessed with mmap, rather than being read into memory all at once. This is particularly useful for working with very large arrays that cannot fit entirely into physical memory.

  • verbose (bool, optional) – If True prints message of completion.

  • **kwargs (optional) – Optional arguments to the astropy.io.fits.open() function. E.g. “output_verify” can be set to ignore, in case of non-standard header.

Returns:

  • hdulist (HDU or HDUList) – [memmap=True] FITS file n hdulist. If n equals -2, returns the whole hdulist.

  • data (numpy ndarray or list of numpy ndarrays) – [memmap=False] Array containing the frames of the fits-cube. If n equals -2, returns a list of all arrays.

  • header (dict or list of dict) – [memmap=False, header=True] Dictionary containing the fits header. If n equals -2, returns a list of all dictionaries.

vip_hci.fits.fits.verify_fits(fitsfilename)[source]

Verify “the FITS standard” of a fits file or list of fits.

Parameters:

fitsfilename (string or list) – Path to the fits file or list with fits filename paths.

vip_hci.fits.fits.write_fits(fitsfilename, array, header=None, output_verify='exception', precision=<class 'numpy.float32'>, verbose=True)[source]

Write array and header into FITS file.

If there is a previous file with the same filename then it’s replaced.

Parameters:
  • fitsfilename (string) – Full path of the fits file to be written.

  • array (numpy ndarray or tuple of numpy ndarray) – Array(s) to be written into a fits file. If a tuple of several arrays, the fits file will be written as a multiple extension fits file

  • header (numpy ndarray, or tuple of headers, optional) – Header dictionary, or tuple of headers for a multiple extension fits file.

  • output_verify (str, optional) – {“fix”, “silentfix”, “ignore”, “warn”, “exception”} Verification options: https://docs.astropy.org/en/stable/io/fits/api/verification.html

  • precision (numpy dtype, optional) – Float precision, by default np.float32 or single precision float.

  • verbose (bool, optional) – If True prints message.

vip_hci.fits.headers module

Module with conversion utilities from dictionaries to headers, and reversely.

vip_hci.fits.headers.dict_to_fitsheader(initial_dict: dict) Header[source]

Convert a dictionnary into a fits Header object.

Parameters:

initial_dict (dict) – Dictionnary of parameters to convert to a Header object.

Returns:

fits_header – Converted set of parameters.

Return type:

Header

vip_hci.fits.headers.fitsheader_to_dict(initial_header: Header, sort_by_prefix: str = '') Tuple[dict, str][source]

Extract a dictionary of parameters and a string from a FITS Header.

The string is supposedly the name of the algorithm that was used to obtain the results that go with the Header.

Parameters:
  • initial_header (Header) – HDU Header that contains parameters used for the run of an algorithm through PostProc, and some unwanted parameters as well.

  • sort_by_prefix (str) – String that will help filter keys of the header that don’t start with that same string. By default, it doesn’t filter out anything.

Returns:

  • parameters (dict) – The set of parameters saved in PPResult that was used for a run of an algorithm.

  • algo_name (str) – The name of the algorithm that was saved alongside its parameters.

vip_hci.fits.headers.open_header(fitsfilename: str, n: int = 0, extname: str | None = None, verbose: bool = False) Header[source]

Load a FITS header into memory to avoid loading the data.

This function is a simple wrapper of astropy.io.fits.convenience.getheader designed to substitute open_fits when only a FITS header is needed. This is ~ 40 times faster than using open_fits with header=True on an average sized VLT/SPHERE data set.

Parameters:
  • fitsfilename (string) – Name of the FITS file.

  • n (int, optional) – Which HDU ext to open. Default is the first ext (zero based indexing).

  • extname (str, optional) – Opens the HDU ext by name, rather than by HDU number. Overrides n and is not case-sensitive.

  • verbose (bool, optional) – If True prints message of completion.

Returns:

header – Astropy Header class with both a dict-like and list-like interface.

Return type:

Header dictionary

Module contents

Subpackage fits includes fits handling functions:
  • fits opening

  • fits info

  • fits writing

  • appending extensions to a fit file

  • ADI cube opening (cube with PA attached as HDU extension)