CountsSpectrum

class gammapy.spectrum.CountsSpectrum(energy_lo, energy_hi, data=None, unit='', region=None, wcs=None)[source]

Bases: object

Generic counts spectrum.

Parameters
energy_loQuantity

Lower bin edges of energy axis

energy_hiQuantity

Upper bin edges of energy axis

datandarray

Spectrum data.

unitstr or Unit

Data unit

regionSkyRegion

Region the spectrum is defined for.

wcsWCS

the wcs system used to perform region based event selection

Examples

from gammapy.spectrum import CountsSpectrum
import numpy as np
import astropy.units as u

ebounds = np.logspace(0,1,11) * u.TeV
data = np.arange(10)
spec = CountsSpectrum(
    energy_lo=ebounds[:-1],
    energy_hi=ebounds[1:],
    data=data,
)
spec.plot(show_poisson_errors=True)

(png, hires.png, pdf)

../_images/gammapy-spectrum-CountsSpectrum-1.png

Attributes Summary

quantity

total_counts

Total number of counts.

Methods Summary

copy(self)

A deep copy of self.

downsample(self, factor)

Downsample spectrum.

energy_mask(self[, emin, emax])

Create a mask for a given energy range.

fill_energy(self, energy)

Fill energy values (Quantity)

fill_events(self, events)

Fill events (gammapy.data.EventList).

from_hdulist(hdulist[, hdu1, hdu2, hdu3])

Read from HDU list in OGIP format.

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.

plot_region(self[, ax])

Plot region

read(filename[, hdu1, hdu2, hdu3])

Read from file.

read_region_table(hdu)

Read region table and convert it to region list.

to_hdulist(self[, use_sherpa])

Convert to HDUList.

to_table(self)

Convert to Table.

write(self, filename[, use_sherpa])

Write to file.

Attributes Documentation

quantity
total_counts

Total number of counts.

Methods Documentation

copy(self)[source]

A deep copy of self.

downsample(self, factor)[source]

Downsample spectrum.

Parameters
factorint

Downsampling factor.

Returns
spectrumCountsSpectrum

Downsampled spectrum.

energy_mask(self, emin=None, emax=None)[source]

Create a mask for a given energy range.

Parameters
emin, emaxQuantity

Energy range

fill_energy(self, energy)[source]

Fill energy values (Quantity)

fill_events(self, events)[source]

Fill events (gammapy.data.EventList).

classmethod from_hdulist(hdulist, hdu1='COUNTS', hdu2='EBOUNDS', hdu3='REGION')[source]

Read from HDU list in OGIP format.

peek(self, figsize=(5, 10))[source]

Quick-look summary plots.

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

Plot as data points.

kwargs are forwarded to errorbar

Parameters
axaxis (optional)

Axis instance to be used for the plot

energy_unitstr, Unit, optional

Unit of the energy axis

show_poisson_errorsbool, optional

Show poisson errors on the plot

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

Plot as histogram.

kwargs are forwarded to hist

Parameters
axaxis (optional)

Axis instance to be used for the plot

energy_unitstr, Unit, optional

Unit of the energy axis

show_energyQuantity, optional

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

plot_region(self, ax=None, **kwargs)[source]

Plot region

Parameters
axWCSAxes

Axes to plot on.

**kwargsdict

Keyword arguments forwarded to as_artist

classmethod read(filename, hdu1='COUNTS', hdu2='EBOUNDS', hdu3='REGION')[source]

Read from file.

static read_region_table(hdu)[source]

Read region table and convert it to region list.

to_hdulist(self, use_sherpa=False)[source]

Convert to HDUList.

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

to_table(self)[source]

Convert to Table.

Data format specification: PHA

write(self, filename, use_sherpa=False, **kwargs)[source]

Write to file.