fits

This module’s scope covers operations related to the FITS file format.

As much as possible, operations are deferred to astropy.io.fits.

class tuna.io.fits.fits(array=None, file_name=None, metadata={}, photons=None)[source]

This class’ responsibility is to operate on FITS files.

Its constructors signature is:

Parameters:

  • array : numpy.ndarray : defaults to None

    Contains the data to be written to a file.

  • file_name : string : defaults to None

    Contains the full location of a file to be read, or to be written to.

  • metadata : dictionary : defaults to { }

    Contains metadata to be written as a FITS header, or the metadata read from a FITS header.

  • photons : dictionary : defaults to None

    Contains the table of photon counts and positions. It is either supplied to be saved to a file, or generated from the data on a file.

Example:

import tuna
import numpy

zeros_array = numpy.zeros ( shape = ( 3, 3, 3 ) )
zeros_file = tuna.io.fits ( array = zeros_array )
zeros_file.write ( file_name = "test_file.fits" )
fits_file = tuna.io.fits ( file_name = "test_file.fits" )
fits_file.read ( )
fits_file.get_array ( )
fits_file.get_metadata ( )
get_array()[source]

This method’s goal is to access the current array in this object.

Returns:

  • self.__array : numpy.ndarray

    Contains the current data stored in this object’s array.

get_metadata()[source]

This method’s goal is to access the current metadata in this object.

Returns:

  • self.__metadata : dictionary

    Contains the current metadata stored in this object.

read()[source]

This method’s goal is to read the file specified in the constructor’s file_name as a FITS file.

It will inspect the FITS header and try to do the “best thing” according to how many image HDU lists it finds; if there is only one list, that will be the data. If there are multiple lists, and these lists can be arranged as a mosaic (i.e., there are a “quadratic” number of images - 4, 9, 25, etc) they will. This is done in a counter-clockwise order, if we assume the 0th row and column is the top left of the image.

write(file_name=None)[source]

This method’s goal is to write the object’s current array and metadata as a FITS file named file_name.

Parameters:

  • file_name: string

    Contains a valid path for an yet non-existing file.

write_metadata_table()[source]

This method’s goal is to write the object’s metadata as a FITS table file.

It will write the file at the path “metadata_” + self.__file_name.

write_photons_table()[source]

This method’s goal is to write the object’s photons dictionary as a FITS table file.

It will write the file at the path “photons_” + self.__file_name.