PHACountsSpectrum

class gammapy.spectrum.PHACountsSpectrum(energy_lo, energy_hi, data=None, quality=None, backscal=None, areascal=None, is_bkg=False, 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

meta : dict, optional

Meta information, TODO: add link where possible meta info is listed

Attributes Summary

arffile ARF associated with the observations
bins_in_safe_range Indices of bins within the energy thresholds
bkgfile Background PHA files associated with the observations
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)
livetime
lo_threshold Low energy threshold of the observation (lower bin edge)
obs_id
offset
phafile PHA file associated with the observations
rmffile RMF associated with the observations
total_counts Total number of counts

Methods Summary

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

Attributes Documentation

arffile

ARF associated with the observations

bins_in_safe_range

Indices of bins within the energy thresholds

bkgfile

Background PHA files associated with the observations

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)

livetime
lo_threshold

Low energy threshold of the observation (lower bin edge)

obs_id
offset
phafile

PHA file associated with the observations

rmffile

RMF associated with the observations

total_counts

Total number of counts

Methods Documentation

copy()

A deep copy of self.

fill(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(figsize=(5, 10))

Quick-look summary plots.

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

Read from file.

rebin(parameter)[source]

Rebin.

See CountsSpectrum. This function treats the quality vector correctly

reset_thresholds()[source]

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

to_hdulist()

Convert to HDUList.

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

to_sherpa(name)[source]

Convert to sherpa.astro.data.DataPHA.

Parameters:

name : str

Instance name

to_table()[source]

Convert to Table.

write(filename, **kwargs)

Write to file.