PHACountsSpectrum

class gammapy.spectrum.PHACountsSpectrum(energy_lo, energy_hi, data=None, quality=None, backscal=None, areascal=None, is_bkg=False, obs_id=None, livetime=None, offset=None, meta=None)[source]

Bases: gammapy.spectrum.CountsSpectrum

Counts spectrum corresponding to OGIP PHA format.

The bkg flag controls whether the PHA counts spectrum represents a background estimate or not (this slightly affects the FITS header information when writing to disk).

Parameters:
energy_lo : Quantity

Lower bin edges of energy axis

energy_hi : Quantity

Upper bin edges of energy axis

data : array-like, optional

Counts

quality : int, array-like, optional

Mask bins in safe energy range (1 = bad, 0 = good)

backscal : float, array-like, optional

Background scaling factor

areascal : float, array-like, optional

Area scaling factor

is_bkg : bool, optional

Background or soure spectrum, default: False

obs_id : int

Observation identifier, optional

livetime : Quantity, optional

Observation livetime

offset : Quantity, optional

Field of view offset

meta : dict, optional

Meta information

Attributes Summary

arffile ARF associated with the observation
bins_in_safe_range Indices of bins within the energy thresholds
bkgfile Background PHA files associated with the observation
counts_in_safe_range Counts with bins outside safe range set to 0
default_interp_kwargs
energy
hi_threshold High energy threshold of the observation (upper bin edge)
lo_threshold Low energy threshold of the observation (lower bin edge)
phafile PHA file associated with the observation
quality Bins in safe energy range (1 = bad, 0 = good)
rmffile RMF associated with the observation
total_counts Total number of counts

Methods Summary

copy(self) A deep copy of self.
energy_mask(self[, emin, emax]) Create a mask for a given energy range.
fill(self, events) Fill with list of events.
from_hdulist(hdulist[, hdu1, hdu2]) Create from HDUList.
peek(self[, figsize]) Quick-look summary plots.
plot(self[, ax, energy_unit, …]) Plot as data points.
plot_hist(self[, ax, energy_unit, show_energy]) Plot as histogram.
read(filename[, hdu1, hdu2]) Read from file.
rebin(self, parameter) Rebin.
reset_thresholds(self) Reset energy thresholds (i.e.
to_hdulist(self[, use_sherpa]) Convert to HDUList.
to_sherpa(self, name) Convert to sherpa.astro.data.DataPHA.
to_table(self) Convert to Table.
write(self, filename[, use_sherpa]) Write to file.

Attributes Documentation

arffile

ARF associated with the observation

bins_in_safe_range

Indices of bins within the energy thresholds

bkgfile

Background PHA files associated with the observation

counts_in_safe_range

Counts with bins outside safe range set to 0

default_interp_kwargs = {'bounds_error': False, 'method': 'nearest'}
energy
hi_threshold

High energy threshold of the observation (upper bin edge)

lo_threshold

Low energy threshold of the observation (lower bin edge)

phafile

PHA file associated with the observation

quality

Bins in safe energy range (1 = bad, 0 = good)

rmffile

RMF associated with the observation

total_counts

Total number of counts

Methods Documentation

copy(self)

A deep copy of self.

energy_mask(self, emin=None, emax=None)

Create a mask for a given energy range.

Parameters:
emin, emax : Quantity

Energy range

fill(self, events)

Fill with list of events.

TODO: Move to NDDataArray

Parameters:
events : Quantity, gammapy.data.EventList,

List of event energies

classmethod from_hdulist(hdulist, hdu1='SPECTRUM', hdu2='EBOUNDS')[source]

Create from HDUList.

peek(self, figsize=(5, 10))

Quick-look summary plots.

plot(self, ax=None, energy_unit='TeV', show_poisson_errors=False, show_energy=None, **kwargs)

Plot as data points.

kwargs are forwarded to errorbar

Parameters:
ax : axis (optional)

Axis instance to be used for the plot

energy_unit : str, Unit, optional

Unit of the energy axis

show_poisson_errors : bool, optional

Show poisson errors on the plot

show_energy : Quantity, optional

Show energy, e.g. threshold, as vertical line

Returns:
ax: axis

Axis instance used for the plot

plot_hist(self, ax=None, energy_unit='TeV', show_energy=None, **kwargs)

Plot as histogram.

kwargs are forwarded to hist

Parameters:
ax : axis (optional)

Axis instance to be used for the plot

energy_unit : str, Unit, optional

Unit of the energy axis

show_energy : Quantity, optional

Show energy, e.g. threshold, as vertical line

classmethod read(filename, hdu1='SPECTRUM', hdu2='EBOUNDS')[source]

Read from file.

rebin(self, parameter)[source]

Rebin.

See CountsSpectrum. This function treats the quality vector correctly

reset_thresholds(self)[source]

Reset energy thresholds (i.e. declare all energy bins valid)

to_hdulist(self, use_sherpa=False)

Convert to HDUList.

This adds an EBOUNDS extension to the BinTableHDU produced by to_table, in order to store the energy axis

to_sherpa(self, name)[source]

Convert to sherpa.astro.data.DataPHA.

Parameters:
name : str

Instance name

to_table(self)[source]

Convert to Table.

write(self, filename, use_sherpa=False, **kwargs)

Write to file.