SpectrumExtraction

class gammapy.spectrum.SpectrumExtraction(observations, bkg_estimate, e_reco=None, e_true=None, containment_correction=False, max_alpha=1, use_recommended_erange=True)[source]

Bases: object

Creating input data to 1D spectrum fitting.

This class is responsible for extracting a SpectrumObservation from a DataStoreObservation. The background estimation is done beforehand, using e.g. the ReflectedRegionsBackgroundEstimator. For point sources analyzed with ‘full containment’ IRFs, a correction for PSF leakage out of the circular ON region can be applied.

For more info see Spectral Fitting.

For a usage example see spectrum_analysis.html

Parameters:
observations : Observations

Observations to process

bkg_estimate : BackgroundEstimate

Background estimate, e.g. of ReflectedRegionsBackgroundEstimator

e_reco : Quantity, optional

Reconstructed energy binning

e_true : Quantity, optional

True energy binning

containment_correction : bool

Apply containment correction for point sources and circular on regions.

max_alpha : float

Maximum alpha value to accept, if the background was estimated using reflected regions this is 1 / minimum number of regions.

use_recommended_erange : bool

Extract spectrum only within the recommended valid energy range of the effective area table (default is True).

Attributes Summary

DEFAULT_RECO_ENERGY Reconstruced energy axis to be used if not specified otherwise
DEFAULT_TRUE_ENERGY True energy axis to be used if not specified otherwise

Methods Summary

apply_containment_correction(self, …) Apply PSF containment correction.
compute_energy_threshold(self[, reset]) Compute and set the safe energy threshold for all observations.
extract_counts(self, bkg) Fill on and off vector for one observation.
extract_irfs(self, observation) Extract IRFs.
make_empty_vectors(self, observation, bkg) Create empty vectors.
process(self, observation, bkg) Process one observation.
run(self) Run all steps.
write(self, outdir[, ogipdir, use_sherpa, …]) Write results to disk as OGIP format.

Attributes Documentation

DEFAULT_RECO_ENERGY = <Quantity [1.00000000e-02, 1.13646367e-02, 1.29154967e-02, 1.46779927e-02, 1.66810054e-02, 1.89573565e-02, 2.15443469e-02, 2.44843675e-02, 2.78255940e-02, 3.16227766e-02, 3.59381366e-02, 4.08423865e-02, 4.64158883e-02, 5.27499706e-02, 5.99484250e-02, 6.81292069e-02, 7.74263683e-02, 8.79922544e-02, 1.00000000e-01, 1.13646367e-01, 1.29154967e-01, 1.46779927e-01, 1.66810054e-01, 1.89573565e-01, 2.15443469e-01, 2.44843675e-01, 2.78255940e-01, 3.16227766e-01, 3.59381366e-01, 4.08423865e-01, 4.64158883e-01, 5.27499706e-01, 5.99484250e-01, 6.81292069e-01, 7.74263683e-01, 8.79922544e-01, 1.00000000e+00, 1.13646367e+00, 1.29154967e+00, 1.46779927e+00, 1.66810054e+00, 1.89573565e+00, 2.15443469e+00, 2.44843675e+00, 2.78255940e+00, 3.16227766e+00, 3.59381366e+00, 4.08423865e+00, 4.64158883e+00, 5.27499706e+00, 5.99484250e+00, 6.81292069e+00, 7.74263683e+00, 8.79922544e+00, 1.00000000e+01, 1.13646367e+01, 1.29154967e+01, 1.46779927e+01, 1.66810054e+01, 1.89573565e+01, 2.15443469e+01, 2.44843675e+01, 2.78255940e+01, 3.16227766e+01, 3.59381366e+01, 4.08423865e+01, 4.64158883e+01, 5.27499706e+01, 5.99484250e+01, 6.81292069e+01, 7.74263683e+01, 8.79922544e+01, 1.00000000e+02] TeV>

Reconstruced energy axis to be used if not specified otherwise

DEFAULT_TRUE_ENERGY = <Quantity [1.00000000e-02, 1.10069417e-02, 1.21152766e-02, 1.33352143e-02, 1.46779927e-02, 1.61559810e-02, 1.77827941e-02, 1.95734178e-02, 2.15443469e-02, 2.37137371e-02, 2.61015722e-02, 2.87298483e-02, 3.16227766e-02, 3.48070059e-02, 3.83118685e-02, 4.21696503e-02, 4.64158883e-02, 5.10896977e-02, 5.62341325e-02, 6.18965819e-02, 6.81292069e-02, 7.49894209e-02, 8.25404185e-02, 9.08517576e-02, 1.00000000e-01, 1.10069417e-01, 1.21152766e-01, 1.33352143e-01, 1.46779927e-01, 1.61559810e-01, 1.77827941e-01, 1.95734178e-01, 2.15443469e-01, 2.37137371e-01, 2.61015722e-01, 2.87298483e-01, 3.16227766e-01, 3.48070059e-01, 3.83118685e-01, 4.21696503e-01, 4.64158883e-01, 5.10896977e-01, 5.62341325e-01, 6.18965819e-01, 6.81292069e-01, 7.49894209e-01, 8.25404185e-01, 9.08517576e-01, 1.00000000e+00, 1.10069417e+00, 1.21152766e+00, 1.33352143e+00, 1.46779927e+00, 1.61559810e+00, 1.77827941e+00, 1.95734178e+00, 2.15443469e+00, 2.37137371e+00, 2.61015722e+00, 2.87298483e+00, 3.16227766e+00, 3.48070059e+00, 3.83118685e+00, 4.21696503e+00, 4.64158883e+00, 5.10896977e+00, 5.62341325e+00, 6.18965819e+00, 6.81292069e+00, 7.49894209e+00, 8.25404185e+00, 9.08517576e+00, 1.00000000e+01, 1.10069417e+01, 1.21152766e+01, 1.33352143e+01, 1.46779927e+01, 1.61559810e+01, 1.77827941e+01, 1.95734178e+01, 2.15443469e+01, 2.37137371e+01, 2.61015722e+01, 2.87298483e+01, 3.16227766e+01, 3.48070059e+01, 3.83118685e+01, 4.21696503e+01, 4.64158883e+01, 5.10896977e+01, 5.62341325e+01, 6.18965819e+01, 6.81292069e+01, 7.49894209e+01, 8.25404185e+01, 9.08517576e+01, 1.00000000e+02, 1.10069417e+02, 1.21152766e+02, 1.33352143e+02, 1.46779927e+02, 1.61559810e+02, 1.77827941e+02, 1.95734178e+02, 2.15443469e+02, 2.37137371e+02, 2.61015722e+02, 2.87298483e+02, 3.16227766e+02] TeV>

True energy axis to be used if not specified otherwise

Methods Documentation

apply_containment_correction(self, observation, bkg)[source]

Apply PSF containment correction.

Parameters:
observation : DataStoreObservation

observation

bkg : BackgroundEstimate

background esimate

compute_energy_threshold(self, reset=False, **kwargs)[source]

Compute and set the safe energy threshold for all observations.

See compute_energy_thresholds for full documentation about the options.

extract_counts(self, bkg)[source]

Fill on and off vector for one observation.

Parameters:
bkg : BackgroundEstimate

Background estimate

extract_irfs(self, observation)[source]

Extract IRFs.

Parameters:
observation : DataStoreObservation

Observation

make_empty_vectors(self, observation, bkg)[source]

Create empty vectors.

This method copies over all meta info and sets up the energy binning.

Parameters:
observation : DataStoreObservation

Observation

bkg : BackgroundEstimate

Background estimate

process(self, observation, bkg)[source]

Process one observation.

Parameters:
observation : DataStoreObservation

Observation

bkg : BackgroundEstimate

Background estimate

Returns:
spectrum_observation : SpectrumObservation

Spectrum observation

run(self)[source]

Run all steps.

write(self, outdir, ogipdir='ogip_data', use_sherpa=False, overwrite=False)[source]

Write results to disk as OGIP format.

Parameters:
outdir : pathlib.Path

Output folder

ogipdir : str, optional

Folder name for OGIP data, default: ‘ogip_data’

use_sherpa : bool, optional

Write Sherpa compliant files?

overwrite : bool

Overwrite existing files?