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() 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 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()

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')[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.