SpectrumDatasetOnOffStacker

class gammapy.spectrum.SpectrumDatasetOnOffStacker(obs_list)[source]

Bases: object

Stack a list of homogeneous datasets.

The stacking of \(j\) datasets is implemented as follows. \(k\) and \(l\) denote a bin in reconstructed and true energy, respectively.

\[ \begin{align}\begin{aligned}\begin{split}\epsilon_{jk} =\left\{\begin{array}{cl} 1, & \mbox{if bin k is inside the energy thresholds}\\ 0, & \mbox{otherwise} \end{array}\right.\end{split}\\\overline{\mathrm{n_{on}}}_k = \sum_{j} \mathrm{n_{on}}_{jk} \cdot \epsilon_{jk}\\\overline{\mathrm{n_{off}}}_k = \sum_{j} \mathrm{n_{off}}_{jk} \cdot \epsilon_{jk}\\\overline{\alpha}_k = \frac{\overline{{b_{on}}}_k}{\overline{{b_{off}}}_k}\\\overline{{b}_{on}}_k = 1\\\overline{{b}_{off}}_k = \frac{1}{\sum_{j}\alpha_{jk} \cdot \mathrm{n_{off}}_{jk} \cdot \epsilon_{jk}} \cdot \overline{\mathrm {n_{off}}}\end{aligned}\end{align} \]

Please refer to the IRFStacker for the description of how the IRFs are stacked.

Parameters:
obs_list : list of SpectrumDatasetOnOff

Observations to stack

Examples

>>> from gammapy.spectrum import SpectrumDatasetOnOff, SpectrumDatasetOnOffStacker
>>> obs_ids = [23523, 23526, 23559, 23592]
>>> datasets = []
>>> for obs in obs_ids:
>>>     filename = "$GAMMAPY_DATA/joint-crab/spectra/hess/pha_obs{}.fits"
>>>     ds = SpectrumDatasetOnOff.from_ogip_files(filename.format(obs))
>>>     datasets.append(ds)
>>> obs_stacker = SpectrumDatasetOnOffStacker(datasets)
>>> stacked = obs_stacker.run()
>>> print(stacked.livetime)
6313.8116406202325 s

Methods Summary

run(self) Run all steps in the correct order.
setup_counts_vectors(self) Add correct attributes to stacked counts vectors.
stack_aeff(self) Stack effective areas (weighted by livetime).
stack_backscal(self) Stack backscal for on and off vector.
stack_counts_spectrum(counts_spectrum_list) Stack PHACountsSpectrum.
stack_counts_vectors(self) Stack on and off vectors.
stack_edisp(self) Stack energy dispersion (weighted by exposure).
stack_obs(self) Create stacked SpectrumDatasetOnOff
stack_off_vector(self) Stack the off count vector.
stack_on_vector(self) Stack the on count vector.

Methods Documentation

run(self)[source]

Run all steps in the correct order.

setup_counts_vectors(self)[source]

Add correct attributes to stacked counts vectors.

stack_aeff(self)[source]

Stack effective areas (weighted by livetime).

Calls gammapy.irf.IRFStacker.stack_aeff.

stack_backscal(self)[source]

Stack backscal for on and off vector.

static stack_counts_spectrum(counts_spectrum_list)[source]

Stack PHACountsSpectrum.

  • Bins outside the safe energy range are set to 0
  • Attributes are set to None.
  • The quality vector of the observations are combined with a logical or, such that the low (high) threshold of the stacked obs is the minimum low (maximum high) threshold of the observation list to be stacked.
stack_counts_vectors(self)[source]

Stack on and off vectors.

stack_edisp(self)[source]

Stack energy dispersion (weighted by exposure).

Calls stack_edisp

stack_obs(self)[source]

Create stacked SpectrumDatasetOnOff

stack_off_vector(self)[source]

Stack the off count vector.

stack_on_vector(self)[source]

Stack the on count vector.