ParameterEstimator#

class gammapy.estimators.ParameterEstimator(n_sigma=1, n_sigma_ul=2, n_sigma_sensitivity=5, null_value=1e-150, selection_optional=None, fit=None, reoptimize=True)[source]#

Bases: Estimator

Model parameter estimator.

Estimates a model parameter for a group of datasets. Compute best fit value, symmetric and delta(TS) for a given null value. Additionally asymmetric errors as well as parameter upper limit and fit statistic profile can be estimated.

Parameters:
n_sigmaint, optional

Sigma to use for asymmetric error computation. Default is 1.

n_sigma_ulint, optional

Sigma to use for upper limit computation. Default is 2.

n_sigma_sensitivityint, optional

Sigma to use for sensitivity computation. Default is 5.

null_valuefloat, optional

Which null value to use for the parameter. Default is 1e-150.

selection_optionallist of str, optional

Which additional quantities to estimate. Available options are:

  • “all”: all the optional steps are executed.

  • “errn-errp”: estimate asymmetric errors on parameter best fit value.

  • “ul”: estimate upper limits.

  • “scan”: estimate fit statistic profiles.

Default is None, so the optional steps are not executed.

fitFit, optional

Fit instance specifying the backend and fit options. If None, the Fit instance is created internally. Default is None.

reoptimizebool, optional

Re-optimize other free model parameters. Default is True.

Examples

>>> from gammapy.datasets import SpectrumDatasetOnOff, Datasets
>>> from gammapy.modeling.models import SkyModel, PowerLawSpectralModel
>>> from gammapy.estimators import ParameterEstimator
>>>
>>> filename = "$GAMMAPY_DATA/joint-crab/spectra/hess/pha_obs23523.fits"
>>> dataset = SpectrumDatasetOnOff.read(filename)
>>> datasets = Datasets([dataset])
>>> spectral_model = PowerLawSpectralModel(amplitude="3e-11 cm-2s-1TeV-1", index=2.7)
>>>
>>> model = SkyModel(spectral_model=spectral_model, name="Crab")
>>> model.spectral_model.amplitude.scan_n_values = 10
>>>
>>> for dataset in datasets:
...     dataset.models = model
>>>
>>> estimator = ParameterEstimator(selection_optional="all")
>>> result = estimator.run(datasets, parameter="amplitude")

Attributes Summary

config_parameters

Configuration parameters.

selection_optional

tag

Methods Summary

copy()

Copy estimator.

estimate_best_fit(datasets, parameter)

Estimate parameter asymmetric errors.

estimate_counts(datasets)

Estimate counts for the flux point.

estimate_errn_errp(datasets, parameter)

Estimate parameter asymmetric errors.

estimate_npred(datasets)

Estimate npred for the flux point.

estimate_scan(datasets, parameter)

Estimate parameter statistic scan.

estimate_sensitivity(datasets, parameter)

Estimate norm sensitivity for the flux point.

estimate_ts(datasets, parameter)

Estimate parameter ts.

estimate_ul(datasets, parameter)

Estimate parameter ul.

run(datasets, parameter)

Run the parameter estimator.

Attributes Documentation

config_parameters#

Configuration parameters.

selection_optional#
tag = 'ParameterEstimator'#

Methods Documentation

copy()#

Copy estimator.

estimate_best_fit(datasets, parameter)[source]#

Estimate parameter asymmetric errors.

Parameters:
datasetsDatasets

Datasets.

parameterParameter

For which parameter to get the value.

Returns:
resultdict

Dictionary with the various parameter estimation values. Entries are:

  • parameter.name: best fit parameter value.

  • “stat”: best fit total stat.

  • “success”: boolean flag for fit success.

  • parameter.name_err: covariance-based error estimate on parameter value.

static estimate_counts(datasets)[source]#

Estimate counts for the flux point.

Parameters:
datasetsDatasets

Datasets.

Returns:
resultdict

Dictionary with an array with one entry per dataset with the sum of the masked counts.

estimate_errn_errp(datasets, parameter)[source]#

Estimate parameter asymmetric errors.

Parameters:
datasetsDatasets

Datasets.

parameterParameter

For which parameter to get the value.

Returns:
resultdict

Dictionary with the parameter asymmetric errors. Entries are:

  • {parameter.name}_errp : positive error on parameter value.

  • {parameter.name}_errn : negative error on parameter value.

static estimate_npred(datasets)[source]#

Estimate npred for the flux point.

Parameters:
datasetsDatasets

Datasets.

Returns:
resultdict

Dictionary with an array with one entry per dataset with the sum of the masked npred.

estimate_scan(datasets, parameter)[source]#

Estimate parameter statistic scan.

Parameters:
datasetsDatasets

The datasets used to estimate the model parameter.

parameterParameter

For which parameter to get the value.

Returns:
resultdict

Dictionary with the parameter fit scan values. Entries are:

  • parameter.name_scan : parameter values scan.

  • “stat_scan” : fit statistic values scan.

estimate_sensitivity(datasets, parameter)[source]#

Estimate norm sensitivity for the flux point.

Parameters:
datasetsDatasets

Datasets.

Returns:
resultdict

Dictionary with an array with one entry per dataset with the sum of the masked npred.

estimate_ts(datasets, parameter)[source]#

Estimate parameter ts.

Parameters:
datasetsDatasets

Datasets.

parameterParameter

For which parameter to get the value.

Returns:
resultdict

Dictionary with the test statistic of the best fit value compared to the null hypothesis. Entries are:

  • “ts” : fit statistic difference with null hypothesis.

  • “npred” : predicted number of counts per dataset.

  • “stat_null” : total stat corresponding to the null hypothesis

estimate_ul(datasets, parameter)[source]#

Estimate parameter ul.

Parameters:
datasetsDatasets

The datasets used to estimate the model parameter.

parameterParameter

For which parameter to get the value.

Returns:
resultdict

Dictionary with the parameter upper limits. Entries are:

  • parameter.name_ul : upper limit on parameter value.

run(datasets, parameter)[source]#

Run the parameter estimator.

Parameters:
datasetsDatasets

The datasets used to estimate the model parameter.

parameterstr or Parameter

For which parameter to run the estimator.

Returns:
resultdict

Dictionary with the various parameter estimation values.