EnergyOffset ArrayΒΆ

The EnergyOffsetArray class represents a 2D array (energy,offset) that is filled with an eventlist. For a set of observations, by giving an energy binning and an offset binning, you fill the events in this histogram.

Four Crab observations are located at $GAMMAPY_EXTRA/datasets/hess-crab4-hd-hap-prod2

An example script of how to fill this array from these four observations and plots the result is given in the examples directory: example_energy_offset_array.py

"""Example how to use `gammapy.background.EnergyOffsetArray`.
"""
import numpy as np
import matplotlib.pyplot as plt
from astropy.coordinates import Angle
from gammapy.data import DataStore
from gammapy.background import EnergyOffsetArray
from gammapy.utils.energy import EnergyBounds


def make_counts_array():
    """Make an example counts array with energy and offset axes."""
    data_store = DataStore.from_dir('$GAMMAPY_EXTRA/datasets/hess-crab4-hd-hap-prod2')

    event_lists = data_store.load_all('events')
    ebounds = EnergyBounds.equal_log_spacing(0.1, 100, 100, 'TeV')
    offset = Angle(np.linspace(0, 2.5, 100), "deg")
    array = EnergyOffsetArray(ebounds, offset)
    array.fill_events(event_lists)

    return array


if __name__ == '__main__':
    array = make_counts_array()
    array.plot()
    plt.show()

(png, hires.png, pdf)

../_images/example_energy_offset_array.png