SpectrumObservation

class gammapy.spectrum.SpectrumObservation(on_vector, aeff=None, off_vector=None, edisp=None)[source]

Bases: object

1D spectral analysis storage class

This container holds the ingredients for 1D region based spectral analysis TODO: describe PHA, ARF, etc.

Meta data is stored in the on_vector attribute. This reflects the OGIP convention.

Parameters:

on_vector : PHACountsSpectrum

On vector

aeff : EffectiveAreaTable

Effective Area

off_vector : PHACountsSpectrum, optional

Off vector

edisp : EnergyDispersion, optional

Energy dispersion matrix

Examples

::
from gammapy.spectrum import SpectrumObservation filename = ‘$GAMMAPY_EXTRA/datasets/hess-crab4_pha/pha_obs23523.fits’ obs = SpectrumObservation.read(filename) print(obs)

Attributes Summary

alpha Exposure ratio between signal and background regions
background_vector Background CountsSpectrum
e_reco Reconstruced energy bounds array.
e_true True energy bounds array.
hi_threshold High energy threshold
livetime Dead-time corrected observation time
lo_threshold Low energy threshold
nbins Number of reconstruced energy bins
obs_id Unique identifier
total_stats Return total SpectrumStats
total_stats_safe_range Return total SpectrumStats within the tresholds

Methods Summary

copy() A deep copy of self.
peek([figsize]) Quick-look summary plots.
predicted_counts(model) Calculated npred given a model
read(filename) Read SpectrumObservation from OGIP files.
stats(idx) Compute stats for one energy bin.
stats_in_range(bin_min, bin_max) Compute stats for a range of energy bins
stats_table() Per-bin stats as a table.
to_sherpa() Create a DataPHA
write([outdir, use_sherpa, overwrite]) Write OGIP files

Attributes Documentation

alpha

Exposure ratio between signal and background regions

background_vector

Background CountsSpectrum

bkg = alpha * n_off

If alpha is a function of energy this will differ from self.on_vector * self.total_stats.alpha because the latter returns an average value for alpha.

e_reco

Reconstruced energy bounds array.

e_true

True energy bounds array.

hi_threshold

High energy threshold

livetime

Dead-time corrected observation time

lo_threshold

Low energy threshold

nbins

Number of reconstruced energy bins

obs_id

Unique identifier

total_stats

Return total SpectrumStats

total_stats_safe_range

Return total SpectrumStats within the tresholds

Methods Documentation

copy()[source]

A deep copy of self.

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

Quick-look summary plots.

predicted_counts(model)[source]

Calculated npred given a model

Parameters:

model : SpectralModel

Spectral model

Returns:

npred : CountsSpectrum

Predicted counts

classmethod read(filename)[source]

Read SpectrumObservation from OGIP files.

BKG file, ARF, and RMF must be set in the PHA header and be present in the same folder.

Parameters:

filename : str

OGIP PHA file to read

stats(idx)[source]

Compute stats for one energy bin.

Parameters:

idx : int

Energy bin index

Returns:

stats : SpectrumStats

Stats

stats_in_range(bin_min, bin_max)[source]

Compute stats for a range of energy bins

Parameters:

bin_min, bin_max: int

Bins to include

Returns:

stats : SpectrumStats

Stacked stats

stats_table()[source]

Per-bin stats as a table.

Returns:

table : Table

Table with stats for one energy bin in one row.

to_sherpa()[source]

Create a DataPHA

associated background vectors and IRFs are also translated to sherpa objects and appended to the PHA instance

write(outdir=None, use_sherpa=False, overwrite=True)[source]

Write OGIP files

If you want to use the written files with Sherpa you have to set the use_sherpa flag. Then all files will be written in units ‘keV’ and ‘cm2’.

Parameters:

outdir : Path

output directory, default: pwd

use_sherpa : bool, optional

Write Sherpa compliant files, default: False

overwrite : bool, optional

Overwrite, default: True