Skip to content

threeML/gammapy-plugin

Repository files navigation

CI CI dev Code style: black codecov

Gammapy Plugin

A gammapy plugin for threeML

threeML plugin to use gammapy datasets in your threeML analysis.

This version is based on previous work by J. Michael Burgess, Sajan Kumar and AnjanaTel.

Installation

The following should be sufficient and install all the relevant dependencies.

git clone https://github.com/threeML/gammapy-plugin.git
cd gammapy-plugin
pip install .

You can test your installation by installing pytest and running the tests after downloading some test datasets:

# install pytest
pip install pytest

# equivalent to gammapy download datasets
export GAMMAPY_DATA=/path/to/gammapy_datasets/
git clone https://github.com/gammapy/gammapy-data.git $GAMMAPY_DATA

# run pytests
python -m pytest

The first part is equivalent to running gammapy download datasets (see the gammapy installation instructions).

These data are used by the examples as well as by pytest.

Requirements

Python 3.11, 3.12 or 3.13 together with gammapy>=v2.0.0

Usage and Examples

For an example check out e.g. the example notebook for an extended source.

The basic procedure after creating a gammapy dataset is

gl = GammapyLike(name = "name_of_the_plugin")   # initializing the plugin
gl.set_datasets(datasets,mode="individual")     # adding the gammapy dataset
gl.set_sources("name_of_the_source")            # setting the source
gl.set_model(model)                             # setting the astromodels model

When using MapDataset with FoVBackgroundModel you can also include them in a fit. The parameters of the background models are currently treated as nuisance parameters during the fitting.

This might then look like this for example:

datasets = Datasets()
gls = []
for o in obs:
    dataset = MapDataset.create(
        geom=geom, energy_axis_true=energy_axis_true, name=f"HESS_{o.obs_id}"
    )
    dataset = maker.run(dataset, o)
    dataset = safe_mask_maker.run(dataset, o)
    bkg_model = FoVBackgroundModel(name = f"{o.obs_id}_bkg",dataset_name= dataset.name)
    dataset.models = [bkg_model]
    dataset = fov_bkg_maker.run(dataset)
    datasets.append(dataset)
    gl = GammapyLike(dataset.name, frame="galactic")
    gl.set_datasets(dataset)
    gl.set_background_models(bkg_model)
    gls.append(gl)

About

This repository contains the code of the gammapy plugin for threeML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages