Survey map

Here’s an example of a Gammapy analysis as a Python script:

"""Make a survey counts map.

We create an all-sky map in AIT projection
for the HESS DL3 DR1 dataset.
"""
import logging
from gammapy.data import DataStore
from gammapy.maps import Map

log = logging.getLogger(__name__)


def main():
    data_store = DataStore.from_dir("$GAMMAPY_DATA/hess-dl3-dr1")
    obs_id = data_store.obs_table["OBS_ID"]
    observations = data_store.get_observations(obs_id)

    m = Map.create()
    for obs in observations:
        log.info(f"Processing obs_id: {obs.obs_id}")
        m.fill_events(obs.events)

    m.write("survey_map.fits.gz")


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    main()

To execute it run:

$ python survey_example.py

For interactive use, IPython and Jupyter are great, and most Gammapy examples use those. However, for long-running, non-interactive tasks like data reduction or survey maps, you might prefer a Python script.