.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/data/ctao.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_ctao.py: CTAO with Gammapy ================= Access and inspect CTAO data and instrument response functions (IRFs) using Gammapy. Introduction ------------ The `Cherenkov Telescope Array Observatory (CTAO) `__ is the next generation ground-based observatory for gamma-ray astronomy. Gammapy is the core library for the Cherenkov Telescope Array Observatory (CTAO) science tools (`CTAO Press Release `__). CTAO will start taking data in the coming years. To prepare the community, a full simulation of 7 years of observations has been produced for open access as part of the CTAO Science Data Challenge. You can learn how to analyse CTAO data and to use Gammapy using these data. You can also use Gammapy to simulate CTAO data and evaluate CTAO performance using the CTAO response files. The latest ones, for the Beta array configuration (prod 6, 2026), are available on Zenodo: https://zenodo.org/records/22871179. Additionally, two sets of responses are available for older array layouts: the `Omega (prod3b, 2016) `__, and `Alpha (prod5, 2021) `__ array configurations. They are all fully supported by Gammapy. Tutorial overview ----------------- This notebook shows how to access CTAO data and instrument response functions (IRFs) using Gammapy, and gives some examples how to quickly look the content of CTAO files, especially to see the shape of CTAO IRFs. At the end of the notebooks, we give several links to other tutorial notebooks that show how to simulate CTAO data and how to evaluate CTAO observability and sensitivity, or how to analyse CTAO data. Note that the FITS data and IRF format currently used by CTAO is the one documented at https://gamma-astro-data-formats.readthedocs.io/, and is also used by H.E.S.S. and other Imaging Atmospheric Cherenkov Telescopes (IACTs). So if you see other Gammapy tutorials using e.g. H.E.S.S. example data, know that they also apply to CTAO, all you have to do is to change the loaded data or IRFs to CTAO. Setup ----- .. GENERATED FROM PYTHON SOURCE LINES 54-66 .. code-block:: Python import os from pathlib import Path from astropy import units as u # %matplotlib inline import matplotlib.pyplot as plt from IPython.display import display from gammapy.data import DataStore from gammapy.irf import load_irf_dict_from_file .. GENERATED FROM PYTHON SOURCE LINES 67-82 CTAO open science data challenge (SDC) -------------------------------------- **For convenience**, since the SDC data files are large, we have taken a small subset of the data, and **included them at** `$GAMMAPY_DATA/cta-sdc`. Data are distributed for different sites (North or South) and night sky conditions (Dark or Moon). In the following, we will show a quick overview of the files and how to load them, and some quick look plots showing the shape of the CTAO IRFs. How to do CTAO simulations and analyses is shown in other tutorials, see links at the end of this notebook. .. GENERATED FROM PYTHON SOURCE LINES 85-95 Datastore ~~~~~~~~~ Gammapy provides the `~gammapy.data.DataStore` interface to access the data. It can be created via the index files when they are provided. Index files consist in two tables: - the HDU index table which connects every observation element to its location on disk - the observation table which provides a summary of observation metadata .. GENERATED FROM PYTHON SOURCE LINES 95-99 .. code-block:: Python data_store_south = DataStore.from_dir("$GAMMAPY_DATA/cta-sdc/South/Dark") print(data_store_south) .. 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.2/cta-sdc/South/Dark Rows: 12 OBS_ID: 5000000013 -- 5000000014 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_3gauss')] Observation table: Observatory name: 'N/A' Number of observations: 2 .. GENERATED FROM PYTHON SOURCE LINES 100-102 The tables can be directly explored .. GENERATED FROM PYTHON SOURCE LINES 102-105 .. code-block:: Python display(data_store_south.obs_table) .. rst-class:: sphx-glr-script-out .. code-block:: none OBS_ID TSTART TSTOP ... TIMEUNIT TIMESYS TIMEREF s s ... ---------- ----------- ------------------ ... -------- ------- ------- 5000000013 315727020.3 315730620.29999995 ... s utc LOCAL 5000000014 315730620.3 315734220.3 ... s utc LOCAL .. GENERATED FROM PYTHON SOURCE LINES 106-109 In the absence of index files, it is possible to generate the `~gammapy.data.DataStore` directly from the SDC event files. .. GENERATED FROM PYTHON SOURCE LINES 109-117 .. code-block:: Python path = Path(os.environ["GAMMAPY_DATA"]) / "cta-sdc/North/Dark/" paths = list(path.rglob("dl3-event-obs*.fits.gz")) data_store_north = DataStore.from_events_files(paths) print(data_store_north) display(data_store_north.obs_table) .. rst-class:: sphx-glr-script-out .. code-block:: none Data store: HDU index table: BASE_DIR: . Rows: 12 OBS_ID: 5000000001 -- 5000000002 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_3gauss')] Observation table: Observatory name: 'N/A' Number of observations: 2 OBS_ID TSTART TSTOP ... TIMEUNIT TIMESYS TIMEREF s s ... ---------- ----------- ----------- ... -------- ------- ------- 5000000001 315703860.0 315704760.0 ... s utc LOCAL 5000000002 315704760.0 315705660.0 ... s utc LOCAL .. GENERATED FROM PYTHON SOURCE LINES 118-130 Accessing an observation can then be done directly using its ``OBS_ID``. Here we consider an observation from the Southern CTAO array. A `~gammapy.data.Observation` bundles the event list and the IRFs as well as Good Time Intervals (GTI) and metadata. SDC IRFs are full-enclosure response functions which are split in: - effective area - energy dispersion - point spread function - background .. GENERATED FROM PYTHON SOURCE LINES 130-136 .. code-block:: Python observation = data_store_south.obs(5000000013) print(observation) observation.peek() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_001.png :alt: Effective area, Background rate, Energy dispersion, Point spread function, Events :srcset: /tutorials/data/images/sphx_glr_ctao_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Observation obs id : 5000000013 tstart : 61773.25 tstop : 61773.29 duration : 3600.00 s pointing (icrs) : 193.6 deg, -24.2 deg deadtime fraction : 0.0% .. GENERATED FROM PYTHON SOURCE LINES 137-145 Events ~~~~~~ Events data are directly accessible via the ``events`` attribute of the `~gammapy.data.Observation`. Events can be accessed from the observation object like: .. GENERATED FROM PYTHON SOURCE LINES 145-148 .. code-block:: Python events = observation.events .. GENERATED FROM PYTHON SOURCE LINES 149-151 Here we print the data from the first 5 events listed in the table: .. GENERATED FROM PYTHON SOURCE LINES 151-154 .. code-block:: Python display(events.table[:5]) .. rst-class:: sphx-glr-script-out .. code-block:: none TIME ENERGY RA ... EVENT_ID DETX DETY TeV deg ... deg deg ------------------ ---------- --------- ... -------- ----------- ---------- 61773.24792015697 0.05941907 192.35968 ... 88802 -1.1016397 0.82475513 61773.24792026059 0.95400846 194.75739 ... 145384 1.1102488 2.0430682 61773.24792032727 0.301907 194.5587 ... 165778 0.91427135 0.39009765 61773.247920455564 0.88798153 192.81873 ... 79241 -0.67988724 0.773133 61773.24792118332 0.13895014 191.99638 ... 23055 -1.4371771 1.0002052 .. GENERATED FROM PYTHON SOURCE LINES 155-157 And show a summary plot: .. GENERATED FROM PYTHON SOURCE LINES 157-162 .. code-block:: Python events.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_002.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 163-165 We can access the observation metadata: .. GENERATED FROM PYTHON SOURCE LINES 165-172 .. code-block:: Python # array used print(observation.meta.obs_info.instrument) # target name print(observation.meta.target.name) .. rst-class:: sphx-glr-script-out .. code-block:: none CTAO-South EGAL Survey .. GENERATED FROM PYTHON SOURCE LINES 173-176 Effective area ~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 176-183 .. code-block:: Python aeff = observation.aeff print(aeff) aeff.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_003.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none EffectiveAreaTable2D -------------------- axes : ['energy_true', 'offset'] shape : (42, 6) ndim : 2 unit : m2 dtype : >f4 .. GENERATED FROM PYTHON SOURCE LINES 184-187 Energy dispersion ~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 187-192 .. code-block:: Python observation.edisp.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_004.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 193-196 Point spread function ~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 196-200 .. code-block:: Python observation.psf.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_005.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 201-206 Background ~~~~~~~~~~ The background is given as a rate in units ``MeV-1 s-1 sr-1``. .. GENERATED FROM PYTHON SOURCE LINES 206-211 .. code-block:: Python observation.bkg.peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_006.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_006.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 212-235 Working with CTAO IRFs ---------------------- To study expected performances of a given CTAO observation, it can be useful to build a synthetic `~gammapy.data.Observation`. For this, you need to retrieve the CTAO instrument response functions. They are distributed for the north and south arrays, for different observing conditions, i.e. different zenith angles and night sky brightnesses. The following IRFs are available: - effective area - energy dispersion - point spread function - background The Beta array configuration (prod 6, 2026) IRFs are available on Zenodo: https://zenodo.org/records/22871179. We ship a small subset of these IRFs in `$GAMMAPY_DATA/cta-caldb`. Gammapy provides an helper function to read in those files and return a dictionary of `~gammapy.irf.IRF` objects. .. GENERATED FROM PYTHON SOURCE LINES 235-240 .. code-block:: Python irf_filename = "$GAMMAPY_DATA/cta-caldb/Prod6-CTAO-North-20deg-AverageAz-4LSTs09MSTs-dark-180000s-v1.0.fits.gz" irfs = load_irf_dict_from_file(irf_filename) print(irfs) .. rst-class:: sphx-glr-script-out .. code-block:: none {'aeff': , 'psf': , 'edisp': , 'bkg': } .. GENERATED FROM PYTHON SOURCE LINES 241-243 To visualise the background at particular energies: .. GENERATED FROM PYTHON SOURCE LINES 243-247 .. code-block:: Python irfs["bkg"].plot_at_energy(["50 GeV", "100 GeV", "500 GeV", "1 TeV", "3 TeV", "10 TeV"]) plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_007.png :alt: 50 GeV, 100 GeV, 500 GeV, 1 TeV, 3 TeV, 10 TeV :srcset: /tutorials/data/images/sphx_glr_ctao_007.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 248-251 Point spread function ~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 251-256 .. code-block:: Python irfs["psf"].peek() plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_008.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_008.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 257-259 This is how for analysis you could slice out the PSF at a given field of view offset .. GENERATED FROM PYTHON SOURCE LINES 259-266 .. code-block:: Python plt.figure(figsize=(8, 5)) irfs["psf"].plot_containment_radius_vs_energy( offset=[1] * u.deg, fraction=[0.68, 0.8, 0.95] ) plt.show() .. image-sg:: /tutorials/data/images/sphx_glr_ctao_009.png :alt: ctao :srcset: /tutorials/data/images/sphx_glr_ctao_009.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 267-273 Further CTAO IRFs ~~~~~~~~~~~~~~~~~ If you want to use other response files, the following code cells (remove the # to uncomment) explain how to proceed. This example is made with the Beta configuration (Prod6). .. GENERATED FROM PYTHON SOURCE LINES 273-290 .. code-block:: Python # import os # !curl -o ctao-prod6-zenodo-v1.0-fits-only.zip https://zenodo.org/records/22871179/files/ctao-prod6-zenodo-v1.0-fits-only.zip # !unzip ctao-prod6-zenodo-v1.0-fits-only.zip # os.chdir("ctao-prod6-zenodo-v1.0-fits-only") # !ls fits/ # !tar xf fits/CTAO-Performance-Prod6-CTAO-North-52deg-halfmoon-v1.0.FITS.tar.gz -C fits/. # !ls fits/*.fits.gz # irfs1 = load_irf_dict_from_file("fits/Prod6-CTAO-North-52deg-NorthAz-4LSTs09MSTs-halfmoon-180000s-v1.0.fits.gz") # irfs1["aeff"].plot_energy_dependence() # irfs2 = load_irf_dict_from_file("fits/Prod6-CTAO-North-52deg-SouthAz-4LSTs09MSTs-halfmoon-180000s-v1.0.fits.gz") # irfs2["aeff"].plot_energy_dependence() .. GENERATED FROM PYTHON SOURCE LINES 291-303 Next steps ---------- - Learn how to analyse data with :doc:`/tutorials/starting/analysis_1` and :doc:`/tutorials/starting/analysis_2` or any other Gammapy analysis tutorial. - Learn how to evaluate CTAO observability and sensitivity with :doc:`/tutorials/analysis-3d/simulate_3d`, :doc:`/tutorials/analysis-1d/spectrum_simulation` or :doc:`/tutorials/analysis-1d/cta_sensitivity`. .. _sphx_glr_download_tutorials_data_ctao.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.2?urlpath=lab/tree/notebooks/2.2/tutorials/data/ctao.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ctao.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ctao.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ctao.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_