Pha

class gdt.core.pha.Pha[source]

Bases: FitsFileContextManager

PHA class for count spectra.

Attributes Summary

channel_mask

A Boolean array representing the valid channels

data

The PHA data

ebounds

The energy bounds

energy_range

The energy range of the spectrum

exposure

The exposure of the PHA data

filename

The filename

gti

The good time intervals

hdulist

The list of Header Data Units

headers

The headers

num_chans

The number of energy channels

num_hdus

The number of HDUs

tcent

The center time of the data

time_range

The time range of the spectrum

trigtime

The trigger time of the data, if available

valid_channels

The channel indices that are valid

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.

from_data(data[, gti, trigger_time, ...])

Create a PHA object from an EnergyBins object.

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, **kwargs)

Open a PHA FITS file and return the PHA object

rebin_energy(method, *args[, energy_range])

Rebin the PHA in energy given a rebinning method.

slice_energy(energy_ranges, **kwargs)

Slice the PHA by one or more energy ranges.

write(directory[, filename, rates, poisson_errs])

Write the file to disk.

Attributes Documentation

channel_mask

A Boolean array representing the valid channels

Type:

(np.array)

data

The PHA data

Type:

(EnergyBins)

ebounds

The energy bounds

Type:

(Ebounds)

energy_range

The energy range of the spectrum

Type:

(float, float)

exposure

The exposure of the PHA data

Type:

(float)

filename

The filename

Type:

(str)

gti

The good time intervals

Type:

(Gti)

hdulist

The list of Header Data Units

Type:

(astropy.io.fits.hdu.HDUList)

headers

The headers

Type:

(FileHeaders)

num_chans

The number of energy channels

Type:

(int)

num_hdus

The number of HDUs

Type:

(int)

tcent

The center time of the data

Type:

(float)

time_range

The time range of the spectrum

Type:

(float, float)

trigtime

The trigger time of the data, if available

Type:

(float)

valid_channels

The channel indices that are valid

Type:

(np.array)

Methods Documentation

close()

Close the file

column(hdu_num: int, col_name: str) array

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

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)

classmethod from_data(data, gti=None, trigger_time=None, filename=None, headers=None, channel_mask=None, header_type=<class 'gdt.core.pha.PhaHeaders'>, valid_channels=None, **kwargs)[source]

Create a PHA object from an EnergyBins object.

Parameters:
  • data (EnergyBins) – The PHA count spectrum data

  • gti (Gti), optional) – The good time intervals of the pectrum data. If omitted, then assumes the range (0, exposure).

  • trigger_time (float, optional) – The trigger time, if applicable. If provided, the data times will be shifted relative to the trigger time. Default is zero.

  • headers (FileHeaders) – The file headers

  • channel_mask (np.array(dtype=bool)) – A boolean array representing the valid channels. If omitted, assumes all non-zero count channels are valid.

  • header_type (FileHeaders) – Default file header class. Only used if headers is not defined

  • valid_channels (np.array(dtype=int)) – An integer array indicating which channels are valid. This is overriden if channel_mask is set.

Returns:

(Pha)

get_column_names(hdu_num: int)

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)

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, **kwargs)[source]

Open a PHA FITS file and return the PHA object

If this class is inherited, this method may be over-written if a non-standard file is being parsed, or if there is extra header information/data that needs to be stored.

Parameters:

file_path (str) – The file path of the FITS file

Returns:

(Pha)

rebin_energy(method, *args, energy_range=(None, None), **kwargs)[source]

Rebin the PHA in energy given a rebinning method.

Parameters:
  • method (<function>) – The rebinning function

  • *args – Arguments to be passed to the rebinning function

  • energy_range ((float, float), optional) – The starting and ending energy to rebin. If omitted, uses the full range of data. Setting start or end to None will use the data from the beginning or end of the data, respectively.

Returns

(Pha)

slice_energy(energy_ranges, **kwargs)[source]

Slice the PHA by one or more energy ranges. Produces a new PHA object.

Parameters:

energy_ranges ([(float, float), ...]) – The energy ranges to slice the data to.

Returns:

(Pha)

write(directory, filename=None, rates=False, poisson_errs=False, **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.