:orphan:
.. include:: ../references.txt
.. _tutorials:
=========
Tutorials
=========
.. important::
* It is **strongly** advised to first read :ref:`package_structure` of the User Guide before using the
tutorials.
* In general, all methods and classes are defined with default values that permit a good execution per default.
In the tutorials, we frequently use extra values to just illustrate their usage.
* The Gammapy library is used by many instruments and as consequence can not describe the specificities of each
data release of each observatory. Get in touch with the observatory experts to get the best usage of a given
data release.
This page lists the Gammapy tutorials that are available as `Jupyter`_ notebooks.
You can read them here, or execute them using a temporary cloud server in Binder.
To execute them locally, you have to first install Gammapy locally (see
:ref:`installation`) and download the tutorial notebooks and example datasets (see
:ref:`getting-started`). Once Gammapy is installed, remember that you can always
use ``gammapy tutorial setup`` to check your tutorial setup, or in your script with
.. code-block:: python
from gammapy.utils.check import check_tutorials_setup
check_tutorials_setup()
Gammapy is a Python package built on `Numpy`_ and `Astropy`_, so to use it
effectively, you have to learn the basics. Many good free resources are
available, e.g. `A Whirlwind tour of Python`_, the `Python data science
handbook`_ and the `Astropy Hands-On Tutorial`_.
.. raw:: html
.. thumbnail-parent-div-open
.. thumbnail-parent-div-close
.. raw:: html
Introduction
============
The following three tutorials show different ways of how to use Gammapy to perform a complete data analysis,
from data selection to data reduction and finally modeling and fitting.
The first tutorial is an overview on how to perform a standard analysis workflow using the high level interface
in a configuration-driven approach, whilst the second deals with the same use-case using the low level API
and showing what is happening *under-the-hood*. The third tutorial shows a glimpse of how to handle different
basic data structures like event lists, source catalogs, sky maps, spectral models and flux points tables.
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/starting/images/thumb/sphx_glr_overview_thumb.png
:alt:
:ref:`sphx_glr_tutorials_starting_overview.py`
.. raw:: html
Data structures
.. raw:: html
.. only:: html
.. image:: /tutorials/starting/images/thumb/sphx_glr_analysis_1_thumb.png
:alt:
:ref:`sphx_glr_tutorials_starting_analysis_1.py`
.. raw:: html
High level interface
.. raw:: html
.. only:: html
.. image:: /tutorials/starting/images/thumb/sphx_glr_analysis_2_thumb.png
:alt:
:ref:`sphx_glr_tutorials_starting_analysis_2.py`
.. raw:: html
Low level API
.. thumbnail-parent-div-close
.. raw:: html
Data exploration
================
These tutorials show how to perform data exploration with Gammapy, providing an introduction to H.E.S.S., MAGIC, VERITAS, CTAO, HAWC and Fermi-LAT data and their instrument response functions (IRFs). You will learn to explore and filter event lists according to different criteria, view multidimensional IRF files and perform instrument-specific analysis.
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/data/images/thumb/sphx_glr_hess_thumb.png
:alt:
:ref:`sphx_glr_tutorials_data_hess.py`
.. raw:: html
H.E.S.S. with Gammapy
.. raw:: html
.. only:: html
.. image:: /tutorials/data/images/thumb/sphx_glr_cta_thumb.png
:alt:
:ref:`sphx_glr_tutorials_data_cta.py`
.. raw:: html
CTAO with Gammapy
.. raw:: html
.. only:: html
.. image:: /tutorials/data/images/thumb/sphx_glr_magic_thumb.png
:alt:
:ref:`sphx_glr_tutorials_data_magic.py`
.. raw:: html
MAGIC with Gammapy
.. raw:: html
.. only:: html
.. image:: /tutorials/data/images/thumb/sphx_glr_fermi_lat_thumb.png
:alt:
:ref:`sphx_glr_tutorials_data_fermi_lat.py`
.. raw:: html
Fermi-LAT with Gammapy
.. raw:: html
.. only:: html
.. image:: /tutorials/data/images/thumb/sphx_glr_hawc_thumb.png
:alt:
:ref:`sphx_glr_tutorials_data_hawc.py`
.. raw:: html
HAWC with Gammapy
.. raw:: html
.. only:: html
.. image:: /tutorials/data/images/thumb/sphx_glr_veritas_thumb.png
:alt:
:ref:`sphx_glr_tutorials_data_veritas.py`
.. raw:: html
VERITAS with Gammapy
.. thumbnail-parent-div-close
.. raw:: html
Model Gallery
=============
A gallery of all possible spectral, spatial and temporal models can be found in this page:
:ref:`model-gallery`.
.. raw:: html
.. thumbnail-parent-div-open
.. thumbnail-parent-div-close
.. raw:: html
Detailed explanation
====================
The following tutorials demonstrate different how to use Gammapy tools
across the full analysis chain, from data loading to model comparison.
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_irfs_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_irfs.py`
.. raw:: html
Using Gammapy IRFs
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_observation_clustering_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_observation_clustering.py`
.. raw:: html
Observational clustering
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_theta_square_plot_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_theta_square_plot.py`
.. raw:: html
Make a theta-square plot
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_makers_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_makers.py`
.. raw:: html
Makers - Data reduction
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_datasets_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_datasets.py`
.. raw:: html
Datasets - Reduced data, IRFs, models
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_maps_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_maps.py`
.. raw:: html
Maps
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_mask_maps_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_mask_maps.py`
.. raw:: html
Mask maps
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_catalog_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_catalog.py`
.. raw:: html
Source catalogs
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_models_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_models.py`
.. raw:: html
Models
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_priors_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_priors.py`
.. raw:: html
Priors
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_model_management_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_model_management.py`
.. raw:: html
Modelling
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_fitting_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_fitting.py`
.. raw:: html
Fitting
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_nested_sampling_Crab_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_nested_sampling_Crab.py`
.. raw:: html
Bayesian analysis with nested sampling
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_estimators_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_estimators.py`
.. raw:: html
Estimators
.. raw:: html
.. only:: html
.. image:: /tutorials/details/images/thumb/sphx_glr_parameter_ul_thumb.png
:alt:
:ref:`sphx_glr_tutorials_details_parameter_ul.py`
.. raw:: html
Constraining parameter limits
.. thumbnail-parent-div-close
.. raw:: html
Data analysis
=============
The following set of tutorials are devoted to data analysis, and grouped according to the specific covered use
cases in spectral analysis and flux fitting, image and cube analysis modelling and fitting, as well as
time-dependent analysis with light-curves.
1D Spectral
-----------
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-1d/images/thumb/sphx_glr_cta_sensitivity_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-1d_cta_sensitivity.py`
.. raw:: html
Point source sensitivity
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-1d/images/thumb/sphx_glr_spectral_analysis_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-1d_spectral_analysis.py`
.. raw:: html
Spectral analysis
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-1d/images/thumb/sphx_glr_spectral_analysis_hli_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-1d_spectral_analysis_hli.py`
.. raw:: html
Spectral analysis with the HLI
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-1d/images/thumb/sphx_glr_extended_source_spectral_analysis_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-1d_extended_source_spectral_analysis.py`
.. raw:: html
Spectral analysis of extended sources
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-1d/images/thumb/sphx_glr_spectrum_simulation_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-1d_spectrum_simulation.py`
.. raw:: html
1D spectrum simulation
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-1d/images/thumb/sphx_glr_sed_fitting_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-1d_sed_fitting.py`
.. raw:: html
Flux point fitting
.. thumbnail-parent-div-close
.. raw:: html
2D Image
--------
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-2d/images/thumb/sphx_glr_detect_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-2d_detect.py`
.. raw:: html
Source detection and significance maps
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-2d/images/thumb/sphx_glr_ring_background_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-2d_ring_background.py`
.. raw:: html
Ring background map
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-2d/images/thumb/sphx_glr_modeling_2D_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-2d_modeling_2D.py`
.. raw:: html
2D map fitting
.. thumbnail-parent-div-close
.. raw:: html
3D Cube
-------
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_analysis_3d_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_analysis_3d.py`
.. raw:: html
3D detailed analysis
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_cta_data_analysis_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_cta_data_analysis.py`
.. raw:: html
Basic image exploration and fitting
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_analysis_mwl_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_analysis_mwl.py`
.. raw:: html
Multi instrument joint 3D and 1D analysis
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_simulate_3d_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_simulate_3d.py`
.. raw:: html
3D map simulation
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_event_sampling_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_event_sampling.py`
.. raw:: html
Event sampling
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_event_sampling_nrg_depend_models_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_event_sampling_nrg_depend_models.py`
.. raw:: html
Sample a source with energy-dependent temporal evolution
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_flux_profiles_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_flux_profiles.py`
.. raw:: html
Flux Profile Estimation
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-3d/images/thumb/sphx_glr_non_detected_source_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-3d_non_detected_source.py`
.. raw:: html
Computing flux upper limits
.. thumbnail-parent-div-close
.. raw:: html
Time series
-----------
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-time/images/thumb/sphx_glr_light_curve_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-time_light_curve.py`
.. raw:: html
Light curves
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-time/images/thumb/sphx_glr_light_curve_flare_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-time_light_curve_flare.py`
.. raw:: html
Light curves for flares
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-time/images/thumb/sphx_glr_variability_estimation_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-time_variability_estimation.py`
.. raw:: html
Estimation of time variability in a lightcurve
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-time/images/thumb/sphx_glr_time_resolved_spectroscopy_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-time_time_resolved_spectroscopy.py`
.. raw:: html
Time resolved spectroscopy estimator
.. raw:: html
.. only:: html
.. image:: /tutorials/analysis-time/images/thumb/sphx_glr_light_curve_simulation_thumb.png
:alt:
:ref:`sphx_glr_tutorials_analysis-time_light_curve_simulation.py`
.. raw:: html
Simulating and fitting a time varying source
.. thumbnail-parent-div-close
.. raw:: html
Astrophysics use cases
======================
This section outlines some source specific use cases.
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/astrophysics/images/thumb/sphx_glr_ebl_thumb.png
:alt:
:ref:`sphx_glr_tutorials_astrophysics_ebl.py`
.. raw:: html
Account for spectral absorption due to the EBL
.. raw:: html
.. only:: html
.. image:: /tutorials/astrophysics/images/thumb/sphx_glr_energy_dependent_estimation_thumb.png
:alt:
:ref:`sphx_glr_tutorials_astrophysics_energy_dependent_estimation.py`
.. raw:: html
Morphological energy dependence estimation
.. raw:: html
.. only:: html
.. image:: /tutorials/astrophysics/images/thumb/sphx_glr_pulsar_analysis_thumb.png
:alt:
:ref:`sphx_glr_tutorials_astrophysics_pulsar_analysis.py`
.. raw:: html
Pulsar analysis
.. raw:: html
.. only:: html
.. image:: /tutorials/astrophysics/images/thumb/sphx_glr_astro_dark_matter_thumb.png
:alt:
:ref:`sphx_glr_tutorials_astrophysics_astro_dark_matter.py`
.. raw:: html
Dark matter spatial and spectral models
.. thumbnail-parent-div-close
.. raw:: html
Scripts
=======
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.
The following example shows how to run Gammapy within a Python script.
.. raw:: html
.. thumbnail-parent-div-open
.. raw:: html
.. only:: html
.. image:: /tutorials/scripts/images/thumb/sphx_glr_survey_map_thumb.png
:alt:
:ref:`sphx_glr_tutorials_scripts_survey_map.py`
.. raw:: html
Survey Map Script
.. thumbnail-parent-div-close
.. raw:: html
.. toctree::
:hidden:
:includehidden:
/tutorials/starting/index.rst
/tutorials/data/index.rst
/tutorials/model-gallery/index.rst
/tutorials/details/index.rst
/tutorials/analysis-1d/index.rst
/tutorials/analysis-2d/index.rst
/tutorials/analysis-3d/index.rst
/tutorials/analysis-time/index.rst
/tutorials/astrophysics/index.rst
/tutorials/scripts/index.rst
.. only:: html
.. container:: sphx-glr-footer sphx-glr-footer-gallery
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download all examples in Python source code: tutorials_python.zip `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download all examples in Jupyter notebooks: tutorials_jupyter.zip `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_