gammapy_plugin package

Subpackages

Submodules

gammapy_plugin.converter module

class gammapy_plugin.converter.AstromodelConverter(model, frame=None, convert_ps=True)[source]

Bases: object

Class for analyizing an astromodel model and converting all the individual sources such that it can be used with gammapy.

Every Source in the Model will get its own Gammapy skymodel. The evaluation happens via the astromodel definition.

Parameters:
  • model (Model)

  • frame (str | None)

  • convert_ps (bool)

property converted_sources: dict

Returns dictionary with all the converted sources.

Returns:

the converted sources dict

Return type:

dict

property gammapy_models: list[SkyModel]

Returns all the gammapy skymodels for that model.

Returns:

list with all the SkyModels

Return type:

list[SkyModel]

property model: Model

Return the corresponding astromodels model

Returns:

the astromodels model

Return type:

astromodels.core.model.Model

update()[source]

Update all parameters of all SkyModels witht the current values from the astromodels model. Public method for _update_parameters

Return type:

None

class gammapy_plugin.converter.SourceConverter(source, converter, **kwargs)[source]

Bases: object

Takes a astromodels source and converts it to a SkyModel

Parameters:
property astromodels_source: Source

Returns the original astromodel source.

Returns:

the converted astromodels Source

Return type:

astromodels.sources.Source

property skymodel: SkyModel

Returns the Gammapy skymodel for this source.

Returns:

the created gammapy SkyModel

Return type:

gammapy.modeling.models.SkyModel

update()[source]

This invokes the updating of all parameters of the converted model in the gammapy SkyModels

Return type:

None

gammapy_plugin.gammapy_like module

class gammapy_plugin.gammapy_like.GammapyLike(*args, **kwargs)[source]

Bases: PluginPrototype

A plugin for including Gammapy datasets.

Return type:

PluginPrototype

property astromodel_converter: AstromodelConverter

AstromodelConverter object used for this plugin.

property datasets: Datasets

Gammapy datasets of the plugin.

distribute_covariance(result)[source]

Function to pass the (estimated) Covariance Matrix to the gammapy parameters so that the gammapy plotting functions can display the correct uncertainty.

Parameters:

result (BayesianResults or MLEResults) – the analysis result

Return type:

None

property frame: str

Coordinate Frame of the plugin.

property gammapy_model

List of all the Gammapy SkyModels.

get_log_like()[source]

Return the value of the log-likelihood with the current values for the parameters stored in the model instance.

Return type:

float

get_number_of_data_points()[source]

This returns the number of data points that are used to evaluate the likelihood.

For binned measurements, this is the number of active bins used in the fit. For unbinned measurements, this would be the number of photons/particles that are evaluated on the likelihood

Return type:

int64

inner_fit()[source]

This is used for the profile likelihood.

Keeping fixed all parameters in the LikelihoodModel, this method minimize the logLike over the remaining nuisance parameters, i.e., the parameters belonging only to the model for this particular detector. If there are no nuisance parameters, simply return the logLike value.

property model: Model

Astromodels model of the plugin.

set_background_models(bkg_model)[source]

Set the gammapy background models (e.g. FoVBackgroundModel) :param bkg_model: Background model(s) :type bkg_model: ModelBase or list of ModelBase or Models or DatasetModels.

Parameters:

bkg_model (ModelBase | list | Models | DatasetModels)

Return type:

None

set_datasets(datasets, mode='individual', stacked_name='stacked')[source]

Set the Gammapy Dataset.

Parameters:
  • datasets (Dataset | Datasets | list[Dataset]) – list of Gammapy datasets or a single Dataset object

  • mode (str) – individual or stacked - defaults to individual, stacked stacks the passed datasets

  • stacked_name (str) – name of the stacked datasset if mode is stacked

Return type:

None

set_model(likelihood_model, converted_model=None)[source]

Set the model to be used in the joint minimization.

Parameters:
  • likelihood_model (Model) – astromodels model

  • converted_model (AstromodelConverter) – converted astromodels

Return type:

None

set_sources(sources=None)[source]

Set the sources to be used by this plugin - No need to specify bkg models

Parameters:

sources (list of str or str) – Source(s) to be used in the analysis defaults to all

Return type:

None

gammapy_plugin.models module

class gammapy_plugin.models.PointSourceModelConverted(sky_position, frame)[source]

Bases: PointSpatialModel

Parameters:
  • sky_position (SkyDirection)

  • frame (str)

default_parameters = <gammapy.modeling.parameter.Parameters object>
property mapping
property mapping_free
tag = ['PointSourceModelConverted', 'ps_conv']
class gammapy_plugin.models.SpatialModelConverted(function, frame=None)[source]

Bases: SpatialModel

Class for converting a spatial astromodels function into an gammapy SpatialModel.

Parameters:
  • function (Function)

  • frame (str)

default_parameters = <gammapy.modeling.parameter.Parameters object>
evaluate(*args, **kwargs)[source]

Evaluates astromodels function instead of gammapy one.

property mapping
property mapping_free
tag = ['SpatialModelConverted', 'spat_conv']
class gammapy_plugin.models.SpectralModelConverted(function, **kwargs)[source]

Bases: SpectralModel

Class for converting a spectral astromodel function into an gammapy SpectralModel.

Parameters:

function (Function | list)

default_parameters = <gammapy.modeling.parameter.Parameters object>
evaluate(energy, **kwargs)[source]

Evaluates the astromodels function instead of a gammapy one.

property mapping
property mapping_free
tag = ['SpectralModelConverted', 'spec_conv']

Module contents

Top-level package for Gammapy Plugin.

class gammapy_plugin.GammapyLike(*args, **kwargs)[source]

Bases: PluginPrototype

A plugin for including Gammapy datasets.

Return type:

PluginPrototype

property astromodel_converter: AstromodelConverter

AstromodelConverter object used for this plugin.

property datasets: Datasets

Gammapy datasets of the plugin.

distribute_covariance(result)[source]

Function to pass the (estimated) Covariance Matrix to the gammapy parameters so that the gammapy plotting functions can display the correct uncertainty.

Parameters:

result (BayesianResults or MLEResults) – the analysis result

Return type:

None

property frame: str

Coordinate Frame of the plugin.

property gammapy_model

List of all the Gammapy SkyModels.

get_log_like()[source]

Return the value of the log-likelihood with the current values for the parameters stored in the model instance.

Return type:

float

get_number_of_data_points()[source]

This returns the number of data points that are used to evaluate the likelihood.

For binned measurements, this is the number of active bins used in the fit. For unbinned measurements, this would be the number of photons/particles that are evaluated on the likelihood

Return type:

int64

inner_fit()[source]

This is used for the profile likelihood.

Keeping fixed all parameters in the LikelihoodModel, this method minimize the logLike over the remaining nuisance parameters, i.e., the parameters belonging only to the model for this particular detector. If there are no nuisance parameters, simply return the logLike value.

property model: Model

Astromodels model of the plugin.

set_background_models(bkg_model)[source]

Set the gammapy background models (e.g. FoVBackgroundModel) :param bkg_model: Background model(s) :type bkg_model: ModelBase or list of ModelBase or Models or DatasetModels.

Parameters:

bkg_model (ModelBase | list | Models | DatasetModels)

Return type:

None

set_datasets(datasets, mode='individual', stacked_name='stacked')[source]

Set the Gammapy Dataset.

Parameters:
  • datasets (Dataset | Datasets | list[Dataset]) – list of Gammapy datasets or a single Dataset object

  • mode (str) – individual or stacked - defaults to individual, stacked stacks the passed datasets

  • stacked_name (str) – name of the stacked datasset if mode is stacked

Return type:

None

set_model(likelihood_model, converted_model=None)[source]

Set the model to be used in the joint minimization.

Parameters:
  • likelihood_model (Model) – astromodels model

  • converted_model (AstromodelConverter) – converted astromodels

Return type:

None

set_sources(sources=None)[source]

Set the sources to be used by this plugin - No need to specify bkg models

Parameters:

sources (list of str or str) – Source(s) to be used in the analysis defaults to all

Return type:

None