.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/data/hess.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_data_hess.py: H.E.S.S. with Gammapy ===================== Explore H.E.S.S. event lists and IRFs. Introduction ------------ `H.E.S.S. `__ is an array of gamma-ray telescopes located in Namibia. Gammapy is regularly used and fully supports H.E.S.S. high level data analysis, after export to the current `open data level 3 format `__. The H.E.S.S. data is private, and H.E.S.S. analysis is mostly documented and discussed in the internal Wiki pages and in H.E.S.S.-internal communication channels. However, in 2018, a small sub-set of archival H.E.S.S. data was publicly released, called the `H.E.S.S. DL3 DR1 `__, the data level 3, data release number 1. This dataset is 50 MB in size and is used in many Gammapy analysis tutorials, and can be downloaded via `gammapy download `__. This notebook is a quick introduction to this specific DR1 release. It briefly describes H.E.S.S. data and instrument responses and show a simple exploration of the data with the creation of theta-squared plot. H.E.S.S. members can find details on the DL3 FITS production on this `Confluence page `__ and access more detailed tutorials in the BitBucket `hess-open-tools` repository. DL3 DR1 ------- This is how to access data and IRFs from the H.E.S.S. data level 3, data release 1. .. GENERATED FROM PYTHON SOURCE LINES 44-53 .. code-block:: Python import astropy.units as u # %matplotlib inline import matplotlib.pyplot as plt from IPython.display import display from gammapy.data import DataStore .. GENERATED FROM PYTHON SOURCE LINES 54-62 A useful way to organize the relevant files are the index tables. The observation index table contains information on each particular run, such as the pointing, or the run ID. The HDU index table has a row per relevant file (i.e., events, effective area, psf…) and contains the path to said file. Together they can be loaded into a Datastore by indicating the directory in which they can be found, in this case `$GAMMAPY_DATA/hess-dl3-dr1`: .. GENERATED FROM PYTHON SOURCE LINES 64-65 Create and get info on the data store .. GENERATED FROM PYTHON SOURCE LINES 65-70 .. code-block:: Python data_store = DataStore.from_dir("$GAMMAPY_DATA/hess-dl3-dr1") data_store.info() .. rst-class:: sphx-glr-script-out .. code-block:: none Data store: HDU index table: BASE_DIR: /home/runner/work/gammapy-docs/gammapy-docs/gammapy-datasets/2.0/hess-dl3-dr1 Rows: 630 OBS_ID: 20136 -- 47829 HDU_TYPE: [np.str_('aeff'), np.str_('bkg'), np.str_('edisp'), np.str_('events'), np.str_('gti'), np.str_('psf')] HDU_CLASS: [np.str_('aeff_2d'), np.str_('bkg_3d'), np.str_('edisp_2d'), np.str_('events'), np.str_('gti'), np.str_('psf_table')] Observation table: Observatory name: 'N/A' Number of observations: 105 .. GENERATED FROM PYTHON SOURCE LINES 71-72 Preview an excerpt from the observation table .. GENERATED FROM PYTHON SOURCE LINES 72-75 .. code-block:: Python display(data_store.obs_table[:2][["OBS_ID", "DATE-OBS", "RA_PNT", "DEC_PNT", "OBJECT"]]) .. rst-class:: sphx-glr-script-out .. code-block:: none OBS_ID DATE-OBS RA_PNT DEC_PNT OBJECT deg deg ------ ---------- -------- ---------- -------- 20136 2004-03-26 228.6125 -58.771667 MSH15-52 20137 2004-03-26 228.6125 -59.771667 MSH15-52 .. GENERATED FROM PYTHON SOURCE LINES 76-77 Get a single observation .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. code-block:: Python obs = data_store.obs(23523) .. GENERATED FROM PYTHON SOURCE LINES 81-82 Select and peek events .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: Python obs.events.select_offset([0, 2.5] * u.deg).peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_hess_001.png :alt: hess :srcset: /tutorials/data/images/sphx_glr_hess_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 87-88 Peek the effective area .. GENERATED FROM PYTHON SOURCE LINES 88-92 .. code-block:: Python obs.aeff.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_hess_002.png :alt: hess :srcset: /tutorials/data/images/sphx_glr_hess_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/gammapy-docs/gammapy-docs/gammapy/.tox/build_docs/lib/python3.11/site-packages/astropy/units/quantity.py:659: RuntimeWarning: invalid value encountered in divide result = super().__array_ufunc__(function, method, *arrays, **kwargs) .. GENERATED FROM PYTHON SOURCE LINES 93-94 Peek the energy dispersion .. GENERATED FROM PYTHON SOURCE LINES 94-98 .. code-block:: Python obs.edisp.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_hess_003.png :alt: hess :srcset: /tutorials/data/images/sphx_glr_hess_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 99-100 Peek the psf .. GENERATED FROM PYTHON SOURCE LINES 100-103 .. code-block:: Python obs.psf.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_hess_004.png :alt: hess :srcset: /tutorials/data/images/sphx_glr_hess_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 104-105 Peek the background rate .. GENERATED FROM PYTHON SOURCE LINES 105-109 .. code-block:: Python obs.bkg.to_2d().plot() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_hess_005.png :alt: hess :srcset: /tutorials/data/images/sphx_glr_hess_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 110-118 Exercises --------- - Find the `OBS_ID` for the runs of the Crab nebula - Compute the expected number of background events in the whole RoI for `OBS_ID=23523` in the 1 TeV to 3 TeV energy band, from the background IRF. .. GENERATED FROM PYTHON SOURCE LINES 121-136 Next steps ---------- Now you know how to access and work with H.E.S.S. data. All other tutorials and documentation apply to H.E.S.S. and CTAO or any other IACT that provides DL3 data and IRFs in the standard format. You can see the following tutorials for more detailed analysis using H.E.S.S. data - :doc:`/tutorials/starting/analysis_1` - :doc:`/tutorials/starting/analysis_2` - :doc:`/tutorials/analysis-1d/spectral_analysis` - :doc:`/tutorials/analysis-1d/extended_source_spectral_analysis` - :doc:`/tutorials/analysis-2d/ring_background` .. _sphx_glr_download_tutorials_data_hess.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/gammapy/gammapy-webpage/v2.0?urlpath=lab/tree/notebooks/2.0/tutorials/data/hess.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hess.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hess.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: hess.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_