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
, optionalOff vector
edisp :
EnergyDispersion
, optionalEnergy 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. excess_vector
Excess CountsSpectrum
.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 tresholdsMethods Summary
compute_energy_threshold
([method_lo, …])Compute and set the safe energy threshold. copy
()A deep copy. peek
([figsize])Quick-look summary plots. predicted_counts
(model)Calculated number of predicted counts given a model. read
(filename)Read SpectrumObservation
from OGIP files.reset_thresholds
()Reset energy thresholds (i.e. 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
()Convert to 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.
-
excess_vector
¶ Excess
CountsSpectrum
.excess = n_on = alpha * n_off
-
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
-
compute_energy_threshold
(method_lo='none', method_hi='none', reset=False, **kwargs)[source]¶ Compute and set the safe energy threshold.
Set the high and low energy threshold for each observation based on a chosen method.
Available methods for setting the low energy threshold:
- area_max : Set energy threshold at x percent of the maximum effective area (x given as kwargs[‘area_percent_lo’])
- energy_bias : Set energy threshold at energy where the energy bias exceeds a value of x percent (given as kwargs[‘bias_percent_lo’])
- none : Do not apply a lower threshold
Available methods for setting the high energy threshold:
- area_max : Set energy threshold at x percent of the maximum effective area (x given as kwargs[‘area_percent_hi’])
- energy_bias : Set energy threshold at energy where the energy bias exceeds a value of x percent (given as kwargs[‘bias_percent_hi’])
- none : Do not apply a higher energy threshold
Parameters: method_lo : {‘area_max’, ‘energy_bias’, ‘none’}
Method for defining the low energy threshold
method_hi : {‘area_max’, ‘energy_bias’, ‘none’}
Method for defining the high energy threshold
reset : bool
Reset existing energy thresholds before setting the new ones (default is
False
)
-
predicted_counts
(model)[source]¶ Calculated number of predicted counts 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]¶ Convert to
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