Phaii¶
- class gdt.core.phaii.Phaii[source]¶
Bases:
FitsFileContextManagerPHAII class for time series of spectra.
Attributes Summary
The PHAII data
The energy-channel mapping.
The energy range of the data.
The filename
The good time intervals
The list of Header Data Units
The headers
The number of energy channels
The number of HDUs
The time range of the data
The trigger time of the data, if available.
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 PHAII object from a
TimeEnergyBinsdata object.get_column_names(hdu_num)Get the column names in a HDU.
get_exposure([time_ranges])Calculate the total exposure of a time range or time ranges of data.
hdu_index_from_name(ext_name)Returns the index into the HDU list based on the extension name.
merge(phaii_list)Merge a list of Phaii objects into a new Phaii object.
open(file_path[, mode, memmap])Open a FITS file.
rebin_energy(method, *args[, energy_range])Rebin the PHAII in energy given a rebinning method.
rebin_time(method, *args[, time_range])Rebin the PHAII in time given a rebinning method.
set_ebounds(ebounds)Set the energy calibration (ebounds) of the data.
slice_energy(energy_ranges, **kwargs)Slice the PHAII by one or more energy range.
slice_time(time_ranges, **kwargs)Slice the PHAII by one or more time range.
to_lightcurve([time_range, energy_range, ...])Integrate the PHAII data over energy to produce a lightcurve.
to_pha([time_ranges, energy_range, ...])Integrate the PHAII data over time to produce a PHA object.
to_spectrum([time_range, energy_range, ...])Integrate the PHAII data over time to produce a count spectrum
write(directory[, filename])Write the file to disk.
Attributes Documentation
- data¶
The PHAII data
- Type:
- ebounds¶
The energy-channel mapping. If data does not have an ebounds, returns None.
- Type:
(
Ebounds)
- energy_range¶
The energy range of the data. If data does not have an ebounds, returns None.
- Type:
(float, float)
- filename¶
The filename
- Type:
(str)
- hdulist¶
The list of Header Data Units
- Type:
(astropy.io.fits.hdu.HDUList)
- headers¶
The headers
- Type:
- num_chans¶
The number of energy channels
- Type:
(int)
- num_hdus¶
The number of HDUs
- Type:
(int)
- time_range¶
The time range of the data
- Type:
(float, float)
- trigtime¶
The trigger time of the data, if available.
- Type:
(float)
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, **kwargs)[source]¶
Create a PHAII object from a
TimeEnergyBinsdata object.- Parameters:
data (
TimeEnergyBins) – The PHAII datagti (
Gti, optional) – The Good Time Intervals object. If omitted, the GTI spans (tstart, tstop)trigger_time (float, optional) – The trigger time, if applicable. If provided, the data times will be shifted relative to the trigger time.
filename (str, optional) – The name of the file
headers (
FileHeaders) – The file headers
- Returns:
(
Phaii)
- 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)
- get_exposure(time_ranges=None)[source]¶
Calculate the total exposure of a time range or time ranges of data.
- Parameters:
time_ranges ([(float, float), ...], optional) – The time range or time ranges over which to calculate the exposure. If omitted, calculates the total exposure of the data.
- Returns:
(float)
- 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 merge(phaii_list)[source]¶
Merge a list of Phaii objects into a new Phaii object. The header from the first Phaii in the list is used in the new Phaii and appropriately updated.
- Parameters:
phaii_list (list) – The list of Phaii objects to merge
- Returns:
(
Phaii)
- classmethod open(file_path: Union[str, Path], mode: str = 'readonly', memmap: bool = None)¶
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)
- rebin_energy(method, *args, energy_range=(None, None), **kwargs)[source]¶
Rebin the PHAII in energy given a rebinning method. Produces a new PHAII object.
- Note::
If the data does not have an energy calibration (ebounds), then this function will bin by energy channels, and therefore the
energy_rangeargument should be a range of energy channels instead of energies.
- 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 (or channel) to rebin. If omitted, uses the full range of data. Setting start or end to
Nonewill use the data from the beginning or end of the data, respectively.
- Returns
(
Phaii)
- rebin_time(method, *args, time_range=(None, None), **kwargs)[source]¶
Rebin the PHAII in time given a rebinning method. Produces a new PHAII object.
- Parameters:
method (<function>) – The rebinning function
*args – Arguments to be passed to the rebinning function
time_range ((float, float), optional) – The starting and ending time to rebin. If omitted, uses the full range of data. Setting start or end to
Nonewill use the data from the beginning or end of the data, respectively.
- Returns
(
Phaii)
- set_ebounds(ebounds)[source]¶
Set the energy calibration (ebounds) of the data. If the data are not yet energy calibrated, this will convert the data object from
TimeChannelBinstoTimeEnergyBins`. If the data already has an energy calibration, this method will update the calibration to with the new ebounds. The number of channels ineboundsmust equal the number of channels of the data.- Parameters:
ebounds (
Ebounds) – The ebounds
- slice_energy(energy_ranges, **kwargs)[source]¶
Slice the PHAII by one or more energy range. Produces a new PHAII object.
- Note::
If the data does not have an energy calibration (ebounds), then this function will slice by energy channels, and therefore the
energy_rangesargument should be a range(s) of energy channels instead of energies.
- Parameters:
energy_ranges ([(float, float), ...]) – The energy ranges to slice the data to.
- Returns:
(
Phaii)
- slice_time(time_ranges, **kwargs)[source]¶
Slice the PHAII by one or more time range. Produces a new PHAII object. The GTI will be automatically update to match the new time range(s).
- Parameters:
time_ranges ([(float, float), ...]) – The time ranges to slice the data to.
- Returns:
(
Phaii)
- to_lightcurve(time_range=None, energy_range=None, channel_range=None)[source]¶
Integrate the PHAII data over energy to produce a lightcurve.
- Note::
If the data has not energy calibration, then
energy_rangeis ignored, and onlychannel_rangeis used.
- Parameters:
time_range ((float, float), optional) – The time range of the lightcurve. If omitted, uses the entire time range of the data.
energy_range ((float, float), optional) – The energy range of the lightcurve. If omitted, uses the entire energy range of the data.
channel_range ((int, int), optional) – The channel range of the lightcurve. If omitted, uses the entire energy range of the data.
- Returns:
(
TimeBins)
- to_pha(time_ranges=None, energy_range=None, channel_range=None, **kwargs)[source]¶
Integrate the PHAII data over time to produce a PHA object.
- Note::
If the data does not have an energy calibration (ebounds), then a PHA object cannot be created and calling this method will raise an exception.
- Parameters:
time_ranges ([(float, float), ...], optional) – The time range of the spectrum. If omitted, uses the entire time range of the data.
energy_range ((float, float), optional) – The energy range of the spectrum. If omitted, uses the entire energy range of the data.
channel_range ((int, int), optional) – The channel range of the spectrum. If omitted, uses the entire energy range of the data.
**kwargs – Options passed to
pha.Pha.from_data()
- Returns:
(
Pha)
- to_spectrum(time_range=None, energy_range=None, channel_range=None)[source]¶
Integrate the PHAII data over time to produce a count spectrum
- Note::
If the data has not energy calibration, then
energy_rangeis ignored, and onlychannel_rangeis used.
- Parameters:
time_range ((float, float), optional) – The time range of the spectrum. If omitted, uses the entire time range of the data.
energy_range ((float, float), optional) – The energy range of the spectrum. If omitted, uses the entire energy range of the data.
channel_range ((int, int), optional) – The channel range of the spectrum. If omitted, uses the entire energy range of the data.
- Returns:
- write(directory: Union[str, Path], filename: str = None, **kwargs)¶
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
filenameif set.