SpectrumObservation¶
-
class
gammapy.spectrum.SpectrumObservation(on_vector, aeff=None, off_vector=None, edisp=None)[source]¶ Bases:
object1D 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_vectorattribute. This reflects the OGIP convention.Parameters: on_vector :
PHACountsSpectrumOn vector
aeff :
EffectiveAreaTableEffective 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
alphaExposure ratio between signal and background regions background_vectorBackground CountsSpectrume_recoReconstruced energy bounds array. e_trueTrue energy bounds array. hi_thresholdHigh energy threshold livetimeDead-time corrected observation time lo_thresholdLow energy threshold nbinsNumber of reconstruced energy bins obs_idUnique identifier total_statsReturn total SpectrumStatstotal_stats_safe_rangeReturn total SpectrumStatswithin the tresholdsMethods Summary
copy()A deep copy of self. peek([figsize])Quick-look summary plots. predicted_counts(model)Calculated npred given a model read(filename)Read SpectrumObservationfrom 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 DataPHAwrite([outdir, use_sherpa, overwrite])Write OGIP files Attributes Documentation
-
alpha¶ Exposure ratio between signal and background regions
-
background_vector¶ Background
CountsSpectrumbkg = 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
SpectrumStatswithin the tresholds
Methods Documentation
-
predicted_counts(model)[source]¶ Calculated npred given a model
Parameters: model :
SpectralModelSpectral model
Returns: npred :
CountsSpectrumPredicted counts
-
classmethod
read(filename)[source]¶ Read
SpectrumObservationfrom 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 :
SpectrumStatsStats
-
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 :
SpectrumStatsStacked stats
-
stats_table()[source]¶ Per-bin stats as a table.
Returns: table :
TableTable with stats for one energy bin in one row.
-
to_sherpa()[source]¶ Create a
DataPHAassociated 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_sherpaflag. Then all files will be written in units ‘keV’ and ‘cm2’.Parameters: outdir :
Pathoutput directory, default: pwd
use_sherpa : bool, optional
Write Sherpa compliant files, default: False
overwrite : bool, optional
Overwrite, default: True