spectrum - 1D spectrum analysis

Introduction

gammapy.spectrum holds functions and classes related to 1D region based spectral analysis. This includes also simulation tools.

The basic of 1D spectral analysis are explained in this talk. A good reference for the forward-folding on-off likelihood fitting methods is Section 7.5 “Spectra and Light Curves” in [Naurois2012], in publications usually the reference [Piron2001] is used. A standard reference for the unfolding method is [Albert2007].

Getting Started

The following code snippet demonstrates how to load an observation stored in OGIP format and fit a spectral model.

from gammapy.spectrum import SpectrumObservation, SpectrumFit
from gammapy.spectrum.models import PowerLaw

filename = '$GAMMAPY_DATA/joint-crab/spectra/hess/pha_obs23523.fits'
obs = SpectrumObservation.read(filename)

model = PowerLaw(
    index=2,
    amplitude='1e-12 cm-2 s-1 TeV-1',
    reference='1 TeV',
)
fit = SpectrumFit(obs_list=[obs], model=model)
fit.run()
print(fit.result[0])

It will print the following output to the console:

Fit result info
---------------
Model: PowerLaw

Parameters:

       name     value     error         unit         min    max
    --------- --------- --------- --------------- --------- ---
        index 2.791e+00 1.456e-01                       nan nan
    amplitude 5.030e-11 6.251e-12 1 / (cm2 s TeV)       nan nan
    reference 1.000e+00 0.000e+00             TeV 0.000e+00 nan

Covariance:

       name           index               amplitude        reference
    --------- --------------------- ---------------------- ---------
        index  0.021213640646334082  5.788340722422449e-13       0.0
    amplitude 5.788340722422449e-13 3.9079614123597625e-23       0.0
    reference                   0.0                    0.0       0.0

Statistic: 41.756 (wstat)
Fit Range: [8.79922544e+08 1.00000000e+11] keV

Using gammapy.spectrum

For more advanced use cases please go to the tutorial notebooks:

The following pages describe gammapy.spectrum in more detail:

Reference/API

gammapy.spectrum Package

Spectrum estimation and modeling methods (1-dimensional, with an energy axis).

Functions

cosmic_ray_flux(energy[, particle]) Cosmic ray flux at Earth.
integrate_spectrum(func, xmin, xmax[, …]) Integrate 1d function using the log-log trapezoidal rule.

Classes

CountsPredictor(model[, aeff, edisp, …]) Calculate number of predicted counts (npred).
CountsSpectrum(energy_lo, energy_hi[, data, …]) Generic counts spectrum.
CrabSpectrum([reference]) Crab nebula spectral model.
FluxPointEstimator(obs, groups, model) Flux point estimator.
FluxPointFit(model, data[, stat]) Fit a set of flux points with a parametric model.
FluxPoints(table) Flux points container.
PHACountsSpectrum(energy_lo, energy_hi[, …]) Counts spectrum corresponding to OGIP PHA format.
PHACountsSpectrumList List of PHACountsSpectrum objects.
SensitivityEstimator(irf, livetime[, slope, …]) Estimate differential sensitivity.
SpectrumEnergyGroup(energy_group_idx, …) Spectrum energy group.
SpectrumEnergyGroupMaker(obs) Energy bin groups for spectral analysis.
SpectrumEnergyGroups([initlist]) List of SpectrumEnergyGroup objects.
SpectrumExtraction(obs_list, bkg_estimate[, …]) Creating input data to 1D spectrum fitting.
SpectrumFit(obs_list, model[, stat, …]) Orchestrate a 1D counts spectrum fit.
SpectrumFitResult(model[, fit_range, …]) Result of a SpectrumFit.
SpectrumObservation(on_vector[, aeff, …]) 1D spectral analysis storage class.
SpectrumObservationList([initlist]) List of SpectrumObservation objects.
SpectrumObservationStacker(obs_list) Stack observations in a SpectrumObservationList.
SpectrumResult(model, points) Spectrum analysis results.
SpectrumSimulation(livetime, source_model[, …]) Simulate SpectrumObservation.
SpectrumStats(**kwargs) Spectrum stats.

gammapy.spectrum.models Module

Spectral models for Gammapy.

Classes

SpectralModel Spectral model base class.
ConstantModel(const) Constant model
CompoundSpectralModel(model1, model2, operator) Represents the algebraic combination of two SpectralModel
PowerLaw([index, amplitude, reference]) Spectral power-law model.
PowerLaw2([amplitude, index, emin, emax]) Spectral power-law model with integral as amplitude parameter.
ExponentialCutoffPowerLaw([index, …]) Spectral exponential cutoff power-law model.
ExponentialCutoffPowerLaw3FGL([index, …]) Spectral exponential cutoff power-law model used for 3FGL.
PLSuperExpCutoff3FGL([index_1, index_2, …]) Spectral super exponential cutoff power-law model used for 3FGL.
LogParabola([amplitude, reference, alpha, beta]) Spectral log parabola model.
TableModel(energy, values[, norm, …]) A model generated from a table of energy and value arrays.
AbsorbedSpectralModel(spectral_model, …[, …]) Spectral model with EBL absorption.
Absorption(energy_lo, energy_hi, param_lo, …) Gamma-ray absorption models.