Commit 3a4b7a912b2c72ea760a443441b80ee687aa0ac7

Authored by Jürgen Knödlseder
2 parents 8649d5bc 5a7f34d5

Merge branch '1646-add-doc-for-iact-edisp' into integration

doc/source/users/reference_manual/csmodelmerge.rst
... ... @@ -13,10 +13,10 @@ This script merges several model XML file into a single model XML file. The
13 13 files are passed via the ``inmodels`` parameter. There are 4 options to specify
14 14 a list of files that should be merged:
15 15  
16   -* a space-separated list of file names (e.g. model1.xml model2.xml)
17   -* a comma-separated list of file names (e.g. model1.xml,model2.xml)
18   -* a wildcard string (e.g. mymodel*.xml)
19   -* an ASCII file containing the file names, one file per line (e.g. @mymodels.txt)
  16 +* a space-separated list of file names (e.g. ``model1.xml model2.xml``)
  17 +* a semi-colon separated list of file names (e.g. ``model1.xml;model2.xml``)
  18 +* a wildcard string (e.g. ``mymodel*.xml``)
  19 +* an ASCII file containing the file names, one file per line (e.g. ``@mymodels.txt``)
20 20  
21 21 Note that the "@" needs to be specified in case of an ASCII file name. It is
22 22 also important to note that models with the same name cannot be appended. The
... ...
doc/source/users/user_manual/iact_analysis/analysis.rst
... ... @@ -3,83 +3,97 @@
3 3 Analysing IACT data
4 4 ===================
5 5  
6   -In order to analyse data from current IACTs, the data have to be retrieved. Information how
7   -to copy IACT data to a local machine can be found here: :ref:`sec_copy`
  6 +In order to analyse data from current IACTs, you first have to retrieve the
  7 +data. Information on how to do that can be found in the section :ref:`sec_copy`.
8 8  
9 9 Check available FITS production
10 10 -------------------------------
11   -Before starting an analysis, it is important to know what kind of data need to be analysed.
12   -In the current scheme of `storing IACT data <http://gamma-astro-data-formats.readthedocs.org/en/latest/data_storage/index.html>`_,
13   -every FITS data set is represented with a unique name, e.g. ``"hess-fits-pa-release-1.0-Prod26-MppStd"``. This string
14   -has to be passed to some set of ctools to find and use the data for analysis.
  11 +Before you start an analysis, it is important that you know what kind of data
  12 +need to be analysed. In the current scheme of
  13 +`storing IACT data <http://gamma-astro-data-formats.readthedocs.org/en/latest/data_storage/index.html>`_,
  14 +every FITS data set is represented by a unique name, e.g.
  15 +``"hess-fits-pa-release-1.0-Prod26-MppStd"``.
  16 +You have to pass this string to some set of scripts to find and use the data
  17 +for analysis.
15 18  
16   -To check the available names of FITS data sets, it is recommended to run :ref:`csiactdata`.
  19 +To check the available names of FITS data sets, you should run the
  20 +:ref:`csiactdata` script:
17 21  
18 22 .. code-block:: bash
19 23  
20 24 $ csiactdata
21 25 Path were data is located [] /path/to/fits/data/
22 26  
23   -This will list names of available FITS data sets on the screen. In the
24   -following it is assumed the user has selected a data set called ``fits-data-name``.
25   -The query for the path where the data is located can be
26   -omitted by setting the environment variable ``VHEFITS`` to this locations. This might be convenient
27   -since some other tools also query for the same parameter and can use ``VHEFITS`` instead.
  27 +This script will list the names of available FITS data sets into the console.
  28 +In the following it is assumed that you have selected a data set named
  29 +``fits-data-name``.
  30 +You can omit the query for the path where the data is located by setting the
  31 +environment variable ``VHEFITS`` to this location. Also other scripts will
  32 +benefit from having this environment variable set, and this avoids that you
  33 +have to type in the path name every time you use one of these scripts.
  34 +
28 35  
29 36 Find observations
30 37 -----------------
31   -To start an analysis, it is required to assemble a list of observations that should be used. For this purpose,
32   -:ref:`csfindobs` searches for observations according to user criteria.
33 38  
34   -Search for sky pointings
35   -^^^^^^^^^^^^^^^^^^^^^^^^
36   -The most common search for observations is by pointing position in the sky.
  39 +Now that you know which data are available you have to assemble a list of
  40 +observations (a.k.a. runs) that you want to use in an analysis. You will
  41 +use the :ref:`csfindobs` for that task, which allows you to select the
  42 +observations according to a number of user criteria.
  43 +
  44 +
  45 +Select observations according to pointing direction
  46 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  47 +
  48 +The most common search for observations is by pointing direction on the sky,
  49 +and you do this by simply invoking the :ref:`csfindobs` script:
37 50  
38 51 .. code-block:: bash
39 52  
40 53 $ csfindobs
41 54 Name of FITS production (Run csiactdata to view your options) [fits-data-name]
42   - Right ascension [83.6331]
43   - Declination [22.01]
44   - Search radius [2.5]
45   - Runlist outfile [runlist.lis]
46   -
47   -
48   -Specifying additional search criteria
49   -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50   -The search for observations can be further constrained arbitrarily. For this purpose,
51   -:ref:`csfindobs` contains a hidden parameter ``expression``. It is possible to use any
52   -FITS selection expression that is `supported by cfitsio <http://www.isdc.unige.ch/integral/download/osa/doc/10.1/osa_um_intro/node38.html>`_.
53   -Available properties (i.e. column names) for selection, can be found
54   -`here <http://gamma-astro-data-formats.readthedocs.org/en/latest/data_storage/obs_index/index.html>`_
55   -or by simply browsing the observation index file with a FITS viewer.
  55 + Right ascension of selection region centre (deg) [83.63]
  56 + Declination of selection region centre (deg) [22.01]
  57 + Search radius of selection region (deg) [2.5]
  58 + Output runlist file [runlist.lis]
56 59  
57   -Example:
  60 +The script will create an ASCII file named ``runlist.lis`` that contains the
  61 +identifiers for all observations with pointing directions located within 2.5°
  62 +around the position of the Crab nebula.
  63 +
  64 +
  65 +Select observations using additional criteria
  66 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  67 +
  68 +You may add further selection criteria using the hidden ``expression`` parameter.
  69 +You may use any FITS selection expression that is
  70 +`supported by the cfitsio row filtering specification <https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node97.html>`_.
  71 +Column names that can be used in the expression can be found
  72 +`here <http://gamma-astro-data-formats.readthedocs.org/en/latest/data_storage/obs_index/index.html>`_
  73 +or by simply browsing the observation index file with a FITS viewer. For example
58 74  
59 75 .. code-block:: bash
60 76  
61 77 $ csfindobs expression="ZEN_PNT<30&&LIVETIME>1800"
62   - ...
63   -
64   -This command selects all observations that have a zenith angle less than
65   -30 degrees and a livetime larger than 1800 seconds (i.e. 30 minutes).
  78 +
  79 +will select all observations that have a zenith angle less than 30° and a
  80 +livetime larger than 1800 seconds.
66 81  
67 82  
68   -Omitting the pointing selection
69   -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70   -You can also omit the pointing selection, for example in case where you
71   -don't know the sky coordinates of your object of interest. In that case, you
72   -may directly use the object name in the expression and pass ``NONE`` as
73   -coordinate to :ref:`csfindobs`:
  83 +Select observations independent of pointing direction
  84 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  85 +
  86 +You can also omit the pointing selection, for example in case that you do not
  87 +know the sky coordinates of your object of interest. In that case, you may
  88 +directly use the object name in the expression and pass ``NONE`` as coordinate
  89 +to :ref:`csfindobs`:
74 90  
75 91 .. code-block:: bash
76 92  
77 93 $ csfindobs expression="OBJECT=='Crab Nebula'"
78 94 Name of FITS production (Run csiactdata to view your options) [fits-data-name]
79   - Right ascension [NONE]
80   - Runlist outfile [runlist.lis]
81   -
82   -This will omit the selection of pointing positions.
  95 + Right ascension of selection region centre [NONE]
  96 + Output runlist file [runlist.lis]
83 97  
84 98 .. note::
85 99  
... ... @@ -88,50 +102,79 @@ This will omit the selection of pointing positions.
88 102 ``min_qual``. For example, ``min_qual=1`` selects all data with a
89 103 looser quality criteria.
90 104  
  105 +
91 106 Create an observation list
92 107 --------------------------
93   -The runlist ASCII file containing a list of selected observation IDs must now be converted to an
94   -observation definition XML file. This file contains information about the location of the files that are required
95   -for the analysis. The purpose of the tool :ref:`csiactobs` is to do this conversion.
  108 +
  109 +As next step, you must convert the runlist ASCII file into an observation
  110 +definition XML file. The observation definition XML file will contain the
  111 +file names of all files that are needed for the analysis. You do this
  112 +conversion with the :ref:`csiactobs` script:
96 113  
97 114 .. code-block:: bash
98 115  
99 116 $ csiactobs
100   - Data storage name (Run csiactdata to view your options) [] fits-data-name
101   - Runlist file [runlist.lis]
  117 + Data storage name [] fits-data-name
  118 + Input runlist file [runlist.lis]
102 119 Number of free parameters per background model [1]
103   - Output model XML file [bgmodels.xml]
104   - Observation XML outfile [obs.xml]
105   -
106   -This tools has now performed various tasks:
107   -
108   -* Use the IACT data storage to convert the observation list ``runlist.lis`` into an observation definition XML file ``obs.xml``.
109   -* Create a model XML file that contains the background models. In ctools, each observation has its own independent background model. The number of free parameters per model was set to 1, i.e. the normalisation of the background is left free for each observation. The models were saved in ``bgmodels.xml``.
110   -* The tool uses an internal hierarchy for assigning the background models. The hidden parameter ``bkg_mod_hiera`` (default=irf|aeff|gauss) steers the order how background models should be created. In case the IRF background model is not available, the script automatically falls back to the background model from effective area (GCTAModelAeffBackground).
111   -* There are some further hidden parameters to steer the start parameters for the Aeff and Gaussian background model. Have a look at :ref:`csiactobs` to view a full list of parameters.
112   -* In ``csiactobs.log`` (or on screen if ``debug=yes``), the script logs the complete energy range of the observation container. These values might be important for later usage (e.g. in binned analysis).
113   -
114   -In case a sky model is already prepared, it is possible to also provide the hidden parameter ``inmodel``. The output
115   -model XML file will then contain both, the background model and the input sky model:
  120 + Output model definition XML file [bgmodels.xml]
  121 + Output observation definition XML file [obs.xml]
  122 +
  123 +The :ref:`csiactobs` script will create two output files: the observations
  124 +definition XML file ``obs.xml`` and an output model definition XML file
  125 +``bgmodels.xml``. To generate ``obs.xml``, :ref:`csiactobs` has used the
  126 +IACT data storage and extracted the relevant file names. ``bgmodels.xml`` is
  127 +a file that is used for background modeling, where each observation will have
  128 +its own independent background model. In the example above, you have set the
  129 +number of free parameters per background model to one, hence the normalisation
  130 +of the background model for each observation will be a free parameter that is
  131 +later adjusted by the maximum likelihood fit.
  132 +
  133 +There are some further hidden parameters to steer the start parameters for the
  134 +effective area and the Gaussian background models. You may have a look at
  135 +:ref:`csiactobs` to see the full list of available parameters.
  136 +
  137 +You may also note that the :ref:`csiactobs` script has created a ``csiactobs.log``
  138 +file that logs the complete energy range of the observations that have been
  139 +selected. These values may be important for later, in particular if you
  140 +intend to do a binned or stacked analysis.
  141 +
  142 +In case that you have already a model definition XML file that describes a model
  143 +of the celestial source distribution (a.k.a. a sky model), you may provide this
  144 +sky model to :ref:`csiactobs` using the hidden ``inmodel`` parameter. The
  145 +output model definition XML file will then contain the sky model and the
  146 +background model, and you can use the model directly in a maximum likelihood
  147 +fit.
116 148  
117 149 .. code-block:: bash
118 150  
119 151 $ csiactobs inmodel="mymodel.xml"
120 152  
121   -Alternatively, models can be merged at any times using the simple tool :ref:`csmodelmerge`:
  153 +Alternatively, you can merged models using the :ref:`csmodelmerge` script:
122 154  
123 155 .. code-block:: bash
124 156  
125 157 $ csmodelmerge
126   - Input model XML files [bgmodels.xml crab.xml]
127   - Output model file [crab_models.xml]
128   -
129   -Note that the number of files to merge is not limited to two. Detailled options how the input model XML file can
130   -be passed is given on the reference page of :ref:`csmodelmerge`. It is also important to know that each model in the container
131   -must have a unique name. This implies, for instance, merging the same XML model twice will result in an exception.
  158 + Input model definition XML files [mymodel.xml bgmodels.xml]
  159 + Output model definition XML file [combined_model.xml]
  160 +
  161 +.. note::
  162 +
  163 + The number of files that can be merged with :ref:`csmodelmerge` is not
  164 + limited to two. The list of input file names may be either separated by
  165 + whitespace or semi-colons, can be specified using wildcards, or can be given
  166 + in an ASCII file (see :ref:`csmodelmerge`).
  167 +
  168 +.. warning::
132 169  
133   -A list of available sky models can be found `here <http://gammalib.sourceforge.net/user_manual/modules/model.html>`_.
134   -Of particular help to create sky models for your dataset is the section about :ref:`modelling CTA data <models>`.
  170 + Each model component in the input model definition XML files that are provided
  171 + to :ref:`csmodelmerge` must have a different and unique name. Merging for
  172 + example the same XML model twice will raise an exception.
  173 +
  174 +A list of available sky models can be found
  175 +`here <http://gammalib.sourceforge.net/user_manual/modules/model.html>`_.
  176 +If you are not familiar with creating sky models you should read the section
  177 +about :ref:`modelling CTA data <models>`.
135 178  
136 179  
137 180 Example XML files
... ... @@ -381,6 +424,33 @@ Depending on the required PSF precision, one could reduce the number of offset b
381 424  
382 425 $ ctpsfcube anumbins=100
383 426  
  427 +Create energy dispersion cube (optional)
  428 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  429 +In case energy dispersion wants to be used in the analysis, the tool :ref:`ctedispcube` computes the energy
  430 +migration response for the given observations. Analogous to the PSF cube, the Edisp cube is stored in
  431 +a four-dimensional map. In each bin of the cube, the migration value ``E_reco/E_true`` is stored. The granularity
  432 +of the migration histogram can be steered via the hidden parameter ``migrabins`` (default: 100). In addition, the
  433 +maximum migration value can be set via the hidden parameter ``migramax`` (default: 2.0). Similar to the PSF cube,
  434 +the edispcube FITS file can become quite large. Therefore, since the energy dispersion shouldn't vary too much across
  435 +the sky region, one could reduce the spatial binning:
  436 +
  437 +.. code-block:: bash
  438 +
  439 + $ ctedispcube
  440 + Input event list or observation definition XML file [NONE] selected_obs.xml
  441 + Input counts cube file to extract energy dispersion cube definition [NONE]
  442 + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]
  443 + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01]
  444 + Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR]
  445 + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL]
  446 + Image scale (in degrees/pixel) [1.0] 0.2
  447 + Size of the X axis in pixels [10] 20
  448 + Size of the Y axis in pixels [10] 20
  449 + Lower energy limit (TeV) [0.1] 0.5
  450 + Upper energy limit (TeV) [100.0] 50
  451 + Number of energy bins [20]
  452 + Output energy dispersion cube file [edispcube.fits]
  453 +
384 454 Create background cube
385 455 ^^^^^^^^^^^^^^^^^^^^^^
386 456 Last but not least, for a binned IACT analysis a cube containing the background rate in sky coordinates and
... ... @@ -451,6 +521,19 @@ Note that when passing an event cube to :ref:`ctlike`, the tool behaves differen
451 521 It queries directly for the additional ingredients for the binned analysis. It is important to pass the background model
452 522 generated by :ref:`ctbkgcube` here to ensure the proper modelling of the background in the fit.
453 523  
  524 +Running :ref:`ctlike` with energy dispersion, the hidden parameter ``edisp=yes`` needs to be specified. The tool
  525 +will then additionally query for the energy dispersion cube described above:
  526 +
  527 +.. code-block:: bash
  528 +
  529 + $ ctlike debug=yes
  530 + Input event list, counts cube or observation definition XML file [events.fits] cntcube.fits
  531 + Input exposure cube file (only needed for stacked analysis) [NONE] expcube.fits
  532 + Input PSF cube file (only needed for stacked analysis) [NONE] psfcube.fits
  533 + Input energy dispersion cube file (only needed for stacked analysis) [NONE] edispcube.fits
  534 + Input background cube file (only needed for stacked analysis) [NONE] bkgcube.fits
  535 + Input model XML file [binned_models.xml]
  536 + Output model XML file [binned_results.xml]
454 537  
455 538  
456 539  
... ...
doc/source/users/user_manual/iact_analysis/high_level.rst
... ... @@ -56,7 +56,8 @@ For a direct output on the screen, pass the hidden parameter ``debug=yes`` on th
56 56 2016-02-19T15:43:08: Total livetime ............: 6427.52 s = 107.13 min = 1.79 h
57 57 ...
58 58  
59   -Further options are described on the reference page :ref:`csobsinfo`.
  59 +Further options are described on the reference page :ref:`csobsinfo`. For instance, is possible to
  60 +generate a ds9 region file including all the pointing position by specifying the hidden parameter ``ds9file``.
60 61  
61 62 Inspecting model XML files
62 63 --------------------------
... ... @@ -90,6 +91,8 @@ parameters that are at their limits might be of interest.
90 91 2016-02-19T15:50:40: Free spectral parameters ..: 2
91 92 2016-02-19T15:50:40: Parameters at limit .......: 0
92 93  
  94 +Similar to :ref:`csobsinfo`, a ds9 region file including all the sky model components
  95 +can be generated by specifying the hidden parameter ``ds9file``.
93 96  
94 97 Compute upper limit
95 98 -------------------
... ... @@ -120,13 +123,18 @@ source of interest. For this purpose, the tool :ref:`cterror` can be used:
120 123 Output model XML file [cterror_results.xml]
121 124  
122 125 The output model does not contain asymmetric errors yet. The positive and negative uncertainties can be read from the
123   -logfile (or from screen) if ``debug=yes`` was specified.
  126 +logfile (or from screen if ``debug=yes`` was specified).
124 127  
125 128 Compute spectral points
126 129 -----------------------
127 130 A very common task in astronomy is to compute spectral data points. To determine a spectral data point, a small energy
128 131 range is considered and the model prefactor and its uncertainty is evaluated. The tool :ref:`csspec` works on both, binned
129   -and unbinned data.
  132 +and unbinned data. The hidden parameter ``edisp=yes`` can be specified in both cases to consider the energy migration
  133 +matrix in the fit.
  134 +
  135 +.. note::
  136 +
  137 + The resulting spectral points are provided as a function of reconstructed energy.
130 138  
131 139 Unbinned
132 140 ^^^^^^^^
... ... @@ -158,8 +166,7 @@ Binned
158 166 Number of spectral points (1-10000) [10]
159 167 Lower energy limit for spectral points (TeV) [0.5]
160 168 Upper energy limit for spectral points (TeV) [50.0]
161   - Output spectrum file [spectrum.fits]
162   -
  169 + Output spectrum file [spectrum.fits]
163 170  
164 171 Plot spectral points
165 172 ^^^^^^^^^^^^^^^^^^^^
... ...
doc/source/users/user_manual/iact_analysis/tips.rst
... ... @@ -13,7 +13,7 @@ Create a skymap of counts
13 13 The tool :ref:`ctskymap` allows to create a single map of counts contained inside an observation container.
14 14 In contrast to :ref:`ctbin`, ctskymap takes into account all events that fall into the skymap energy range and spatial range.
15 15 Since :ref:`ctbin` is intended for binned/stacked analysis, it respects energy thresholds, RoI selections etc.
16   -Accordingly, :ref:`ctskymap` should be used for a simple visualisation of the counts.
  16 +Accordingly, :ref:`ctskymap` could be used for a simple visualisation of the counts.
17 17  
18 18  
19 19 .. code-block:: bash
... ... @@ -31,6 +31,15 @@ Accordingly, :ref:`ctskymap` should be used for a simple visualisation of the co
31 31 Size of the Y axis in pixels [200]
32 32 Output skymap file [skymap.fits]
33 33  
  34 +Alternatively, one could use count cube and collapse the maps into one single image via Python:
  35 +
  36 +.. code-block:: python
  37 +
  38 + import gammalib
  39 + map = gammalib.GSkyMap("myCountCube.fits") # Loads the count cube
  40 + map.stack_maps() # Stack energy slices
  41 + map.save("myCountMap.fits") # Save to file
  42 +
34 43 Create region file of pointings
35 44 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36 45 In particular, one might want to know how the pointings of the observation container distribute across the sky.
... ... @@ -77,6 +86,12 @@ to access information in python:
77 86 info.ebounds() # gammalib.GEbounds object of energy ranges
78 87 info.gti() # gammalib.GGti object containing good time intervals
79 88  
  89 +There is also an example script to plot several information about an observation container which might be useful
  90 +for a quick visualisation of the observations inside a container:
  91 +
  92 +.. code-block:: bash
  93 +
  94 + $ python $CTOOLS/examples/show_obs.py selected_obs.xml
80 95  
81 96 Visualise models
82 97 ----------------
... ... @@ -185,7 +200,7 @@ Not all issues can be tackled. Nevertheless, here is a list of actions that have
185 200  
186 201 * Consider switching to binned analysis if the observation time exceeds 50-100 hours.
187 202 * Diffuse and extended sources in the RoI are computational expensive. However, in unbinned analysis they impact the speed much more.
188   -* Usage of energy dispersion in unbinned analysis could also cause a long fit. Try switching it off if speed is important.
  203 +* Usage of energy dispersion could also cause a long fit. Try switching it off if speed is important. Keep in mind this will have an effect on the results.
189 204 * Switch to a machine that supports OpenMP. This allows to parallelise the fit onto several cores.
190 205  
191 206 Compute excess maps
... ...