Metadata-Version: 2.4
Name: gammapy_plugin
Version: 0.0.2
Summary: The gammapy plugin for 3ML
Author-email: Tobias Preis <tobias.preis@uibk.ac.at>, "J. Michael Burgess" <jburgess@mpe.mpg.de>
Maintainer-email: Tobias Preis <tobias.preis@uibk.ac.at>
License-Expression: GPL-3.0
Project-URL: Homepage, https://github.com/threeML/gammapy-plugin
Project-URL: Issues, https://github.com/threeML/gammapy-plugin/issues
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Physics
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: matplotlib
Requires-Dist: astromodels>=2.6.0
Requires-Dist: threeml>=2.6.0
Requires-Dist: gammapy>=2.0
Requires-Dist: regions<0.12
Provides-Extra: tests
Requires-Dist: coverage; extra == "tests"
Requires-Dist: pytest; extra == "tests"
Requires-Dist: pytest-cov; extra == "tests"
Requires-Dist: pytest-xdist; extra == "tests"
Requires-Dist: filelock; extra == "tests"
Provides-Extra: all
Requires-Dist: gammapy_plugin[tests]; extra == "all"
Dynamic: license-file

[![CI](https://github.com/threeML/gammapy-plugin/actions/workflows/build_test_pip.yml/badge.svg?branch=main)](https://github.com/threeML/gammapy-plugin/actions/workflows/build_test_pip.yml)
[![codecov](https://codecov.io/github/threeML/gammapy-plugin/graph/badge.svg?token=EGG9OUMT9J)](https://codecov.io/github/threeML/gammapy-plugin)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/threeML/gammapy-plugin/main.svg)](https://results.pre-commit.ci/latest/github/threeML/gammapy-plugin/main)
[![Docs](https://img.shields.io/readthedocs/gammapy-plugin/latest)](https://gammapy-plugin.readthedocs.io/en/latest/)

# Gammapy Plugin
![A gammapy plugin for threeML](docs/_static/banner-dark.svg)

`threeML` plugin to use `gammapy` datasets in your `threeML` analysis.


## Docs

You can find the docs containg also example notebooks 
either on [readthedocs](https://gammapy-plugin.readthedocs.io/en/latest/) or on the 
[github pages](https://threeml.github.io/gammapy-plugin/).

## Installation

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

```bash
pip install gammapy-plugin
```

You can test the installation using `pytest`. To get all the dependencies it is
recommeneded to run 
```bash
# install test dependenices
pip install gammapy-plugin[tests]

# 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 -n auto --dist worksteal gammapy_plugin
```

The first part is equivalent to running `gammapy download datasets` [(see the `gammapy` installation
instructions)](https://docs.gammapy.org/1.3/getting-started/index.html#getting-started).

These data are required by the `pytest` tests.

### Requirements

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

## Usage and Examples

The basic procedure after creating a `gammapy` dataset is

```python
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/sampling.

This might then look like this for example:

```python
datasets = Datasets()
gls = []
for o in observations:
    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)
```

# Notes
This current version is based on previous work by [J. Michael Burgess](https://github.com/grburgess), [Sajan
Kumar](https://github.com/skumarudel) and [AnjanaTel](https://github.com/AnjanaTel).

