Remove make_counts_map and improve fill_map_counts docstring
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import absolute_import, division, print_function, unicode_literals
-from ..maps import Map
__all__ = [
'fill_map_counts',
- 'make_map_counts',
]
-def fill_map_counts(count_map, events):
+def fill_map_counts(counts_map, events):
"""Fill events into a counts map.
The energy of the events is used for a non-spatial axis homogeneous to energy.
- The other non-spatial axis names should have an entry in the column names of the ``EventList``
+ The other non-spatial axis names should have an entry in the column names of the event list.
Parameters
----------
- count_map : `~gammapy.maps.Map`
+ counts_map : `~gammapy.maps.Map`
Map object, will be filled by this function.
events : `~gammapy.data.EventList`
Event list
- """
- geom = count_map.geom
+ 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_EXTRA/datasets/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_EXTRA/datasets/fermi_2fhl/2fhl_events.fits.gz')
+ reference_map = Map.read('$GAMMAPY_EXTRA/datasets/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.
+ """
# Make a coordinate dictionary; skycoord is always added
coord_dict = dict(skycoord=events.radec)
# Now add one coordinate for each extra map axis
- for axis in geom.axes:
+ for axis in counts_map.geom.axes:
if axis.type == 'energy':
# This axis is the energy. We treat it differently because axis.name could be e.g. 'energy_reco'
coord_dict[axis.name] = events.energy.to(axis.unit)
@@ -41,24 +65,4 @@ def fill_map_counts(count_map, events):
else:
raise ValueError("Cannot find MapGeom axis {!r} in EventList".format(axis.name))
- count_map.fill_by_coord(coord_dict)
-
-
-def make_map_counts(events, geom):
- """Make a counts map for a given geometry.
-
- Parameters
- ----------
- events : `~gammapy.data.EventList`
- Event list
- geom : `~gammapy.maps.Geom`
- Map geometry
-
- Returns
- -------
- counts_map : `~gammapy.maps.Map`
- Counts map
- """
- counts_map = Map.from_geom(geom)
- fill_map_counts(counts_map, events)
- return counts_map
+ counts_map.fill_by_coord(coord_dict)
