fill_map_counts

gammapy.cube.fill_map_counts(counts_map, events)[source]

Fill events into a counts map.

This method handles sky coordinates automatically. For all other map axes, an event list table column with the same name has to be present (case-insensitive compare), or a KeyError will be raised.

Note that this function is just a thin wrapper around the sky map fill_by_coord method. For more complex scenarios, use that directly.

Parameters:

counts_map : Map

Map object, will be filled by this function.

events : EventList

Event list

Examples

To make a counts map, create an empty map with a geometry of your choice and then fill it using this function:

from gammapy.maps import Map
from gammapy.data import EventList
from gammapy.cube import fill_map_counts
events = EventList.read('$GAMMAPY_DATA/cta-1dc/data/baseline/gps/gps_baseline_110380.fits')
counts = Map.create(coordsys='GAL', skydir=(0, 0), binsz=0.1, npix=(120, 100))
fill_map_counts(counts, events)
counts.plot()

If you have a given map already, and want to make a counts image with the same geometry (not using the pixel data from the original map), do this:

from gammapy.maps import Map from gammapy.data import EventList from gammapy.cube import fill_map_counts events = EventList.read(‘$GAMMAPY_DATA/fermi_2fhl/2fhl_events.fits.gz’) reference_map = Map.read(‘$GAMMAPY_DATA/fermi_2fhl/fermi_2fhl_gc.fits.gz’) counts = Map.from_geom(reference_map.geom) fill_map_counts(counts, events) counts.smooth(3).plot()

It works for IACT and Fermi-LAT events, for WCS or HEALPix map geometries, and also for extra axes. Especially energy axes are automatically handled correctly.