SpectrumFit¶
-
class
gammapy.spectrum.SpectrumFit(obs_list, model, stat='wstat', forward_folded=True, fit_range=None, background_model=None, method='sherpa', err_method='sherpa')[source]¶ Bases:
objectOrchestrate a 1D counts spectrum fit.
For usage examples see Spectral Fitting
Parameters: obs_list :
SpectrumObservationList,SpectrumObservationObservation(s) to fit
model :
SpectralModelSource model. Should return counts if
forward_foldedis False and a flux otherwisestat : {‘wstat’, ‘cash’}
Fit statistic
forward_folded : bool, default: True
Fold
modelwith the IRFs given inobs_listfit_range : tuple of
QuantityFit range, will be convolved with observation thresholds. If you want to control which bins are taken into account in the fit for each observations, use
qualitiy()background_model :
SpectralModel, optionalBackground model to be used in cash fits
method : {‘sherpa’}
Optimization backend for the fit
err_method : {‘sherpa’}
Optimization backend for error estimation
Attributes Summary
bins_in_fit_rangeBins participating in the fit for each observation. fit_rangeFit range. predicted_countsCurrent value of predicted counts. statvalCurrent value of statval. total_statStatistic summed over all bins and all observations. true_fit_rangeTrue fit range for each observation. Methods Summary
calc_statval()Calc statistic for all observations. est_errors()Estimate parameter errors. fit()Run the fit. likelihood_1d(model, parname, parvals)Compute likelihood profile. plot_likelihood_1d([ax])Plot 1-dim likelihood profile. predict_counts()Predict counts for all observations. run([outdir])Run all steps and write result to disk. Attributes Documentation
-
bins_in_fit_range¶ Bins participating in the fit for each observation.
-
fit_range¶ Fit range.
-
predicted_counts¶ Current value of predicted counts.
For each observation a tuple to counts for the on and off region is returned.
-
statval¶ Current value of statval.
For each observation the statval per bin is returned.
-
total_stat¶ Statistic summed over all bins and all observations.
This is what is used for the fit.
-
true_fit_range¶ True fit range for each observation.
True fit range is the fit range set in the
SpectrumFitwith observation threshold taken into account.
Methods Documentation
-
calc_statval()[source]¶ Calc statistic for all observations.
The result is stored as attribute
statval, bin outside the fit range are set to 0.
-
likelihood_1d(model, parname, parvals)[source]¶ Compute likelihood profile.
Parameters: model :
SpectralModelModel to draw likelihood profile for
parname : str
Parameter to calculate profile for
parvals :
QuantityParameter values
-
plot_likelihood_1d(ax=None, **kwargs)[source]¶ Plot 1-dim likelihood profile.
See
likelihood_1d()
-