Commit c0ec604c0cf4b98fea9d803bca4f4ec8c2fb2736

Authored by Jürgen Knödlseder
2 parents 3064f16a 3d4fd4b7

Merge branch '1646-add-cstssplit-to-docs' into integration

doc/source/users/user_manual/iact_analysis/tips.rst
@@ -2,245 +2,269 @@ @@ -2,245 +2,269 @@
2 2
3 Tips, Tricks and FAQs 3 Tips, Tricks and FAQs
4 ===================== 4 =====================
5 -This section shows some of the wrinkles that could fascilitate the users' life when running IACT analyses. 5 +This section shows some of the wrinkles that could ease your life when
  6 +running IACT analyses.
  7 +
6 8
7 Visualise observations 9 Visualise observations
8 ---------------------- 10 ----------------------
9 -A very common task is to inspect the observation container and visualise several quantities. 11 +A very common task is to inspect the observation container and visualise several
  12 +quantities.
10 13
11 Create a skymap of counts 14 Create a skymap of counts
12 ^^^^^^^^^^^^^^^^^^^^^^^^^ 15 ^^^^^^^^^^^^^^^^^^^^^^^^^
13 -The tool :ref:`ctskymap` allows to create a single map of counts contained inside an observation container.  
14 -In contrast to :ref:`ctbin`, ctskymap takes into account all events that fall into the skymap energy range and spatial range.  
15 -Since :ref:`ctbin` is intended for binned/stacked analysis, it respects energy thresholds, RoI selections etc.  
16 -Accordingly, :ref:`ctskymap` could be used for a simple visualisation of the counts.  
17 - 16 +The tool :ref:`ctskymap` allows to create a single map of counts contained
  17 +inside an observation container. In contrast to :ref:`ctbin`, ctskymap takes
  18 +into account all events that fall into the skymap energy range and spatial
  19 +range. Since :ref:`ctbin` is intended for stacked analysis, it respects energy
  20 +thresholds, RoI selections, etc. In contrast, :ref:`ctskymap` may be used for
  21 +a simple visualisation of the counts.
18 22
19 .. code-block:: bash 23 .. code-block:: bash
20 24
21 - $ ctskymap debug=yes  
22 - Input event list or observation definition XML file [events.fits] obs.xml  
23 - Lower energy limit (TeV) [0.1]  
24 - Upper energy limit (TeV) [100.0]  
25 - First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]  
26 - Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01]  
27 - Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR]  
28 - Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL]  
29 - Image scale (in degrees/pixel) [0.02]  
30 - Size of the X axis in pixels [200]  
31 - Size of the Y axis in pixels [200]  
32 - Output skymap file [skymap.fits]  
33 -  
34 -Alternatively, one could use count cube and collapse the maps into one single image via Python: 25 + $ ctskymap debug=yes
  26 + Input event list or observation definition XML file [events.fits] obs.xml
  27 + Lower energy limit (TeV) [0.1]
  28 + Upper energy limit (TeV) [100.0]
  29 + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]
  30 + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01]
  31 + Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR]
  32 + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL]
  33 + Image scale (in degrees/pixel) [0.02]
  34 + Size of the X axis in pixels [200]
  35 + Size of the Y axis in pixels [200]
  36 + Output skymap file [skymap.fits]
  37 +
  38 +Alternatively, you may start from a counts cube and collapse the maps into one
  39 +single map via Python:
35 40
36 .. code-block:: python 41 .. code-block:: python
37 42
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 43 + >>> import gammalib
  44 + >>> map = gammalib.GSkyMap("myCountCube.fits") # Load counts cube
  45 + >>> map.stack_maps() # Stack all cube maps into a single map
  46 + >>> map.save("myCountMap.fits") # Save map to file
42 47
43 Create region file of pointings 48 Create region file of pointings
44 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 49 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45 -In particular, one might want to know how the pointings of the observation container distribute across the sky.  
46 -For this purpose, :ref:`csobsinfo` provides the hidden parameter ``ds9file`` which signals to produce a region file that  
47 -contains these information: 50 +You may want to know how the pointings of the observation container distribute
  51 +across the sky. For this purpose, :ref:`csobsinfo` provides the hidden parameter
  52 +``ds9file`` which instructs the script produce a region file that contains the
  53 +pointing information:
48 54
49 .. code-block:: bash 55 .. code-block:: bash
50 56
51 - $ csobsinfo ds9file=pointings.reg debug=yes  
52 - Event list, counts cube, or observation definition file [obs.xml] 57 + $ csobsinfo ds9file=pointings.reg debug=yes
  58 + Event list, counts cube, or observation definition file [obs.xml]
53 59
54 -Together with the previously produced skymap, one can plot the pointings using e.g. ds9: 60 +Together with the previously produced skymap, you can plot the pointings using
  61 +for example ds9:
55 62
56 .. code-block:: bash 63 .. code-block:: bash
57 64
58 - $ ds9 skymap.fits -regions pointings.reg 65 + $ ds9 skymap.fits -regions pointings.reg
  66 +
59 67
60 Plot zenith angle distribution of observations 68 Plot zenith angle distribution of observations
61 ---------------------------------------------- 69 ----------------------------------------------
62 -The tool :ref:`csobsinfo` dumps more information into the log file. Some of them might be of interest to catch in a script.  
63 -Therefore, one could simply use this tool via python and plot some distributions: 70 +The script :ref:`csobsinfo` logs information about an observation container
  71 +into a log file. You may access the information through dedicated class methods
  72 +and plot the information using for example matplotlib:
64 73
65 .. code-block:: python 74 .. code-block:: python
66 75
67 - # Run script  
68 - import cscripts  
69 - info = cscripts.csobsinfo()  
70 - info["inobs"] = "selected_obs.xml"  
71 - info.run()  
72 -  
73 - # Plot data  
74 - import matplotlib.pyplot as plt  
75 - plt.hist(info.zeniths(), bins=10, range=[0,90])  
76 - plt.show() 76 + >>> # Run script
  77 + >>> import cscripts
  78 + >>> info = cscripts.csobsinfo()
  79 + >>> info["inobs"] = "selected_obs.xml"
  80 + >>> info.run()
  81 +
  82 + >>> # Plot data
  83 + >>> import matplotlib.pyplot as plt
  84 + >>> plt.hist(info.zeniths(), bins=10, range=[0,90])
  85 + >>> plt.show()
77 86
78 -This will plot a histogram showing the zenith angle distribution of the observation container. In addition there are more methods  
79 -to access information in python: 87 +This example will plot a histogram showing the zenith angle distribution of the
  88 +observation container. In addition there are more methods to access information
  89 +in Python:
80 90
81 .. code-block:: python 91 .. code-block:: python
82 92
83 - # csobsinfo can also return:  
84 - info.azimuths() # list of azimuth values  
85 - info.offsets() # list of offset values (only computed if hidden parameter offset=yes was specified)  
86 - info.ebounds() # gammalib.GEbounds object of energy ranges  
87 - info.gti() # gammalib.GGti object containing good time intervals 93 + >>> info.azimuths() # list of azimuth values
  94 + >>> info.offsets() # list of offset values (only computed if hidden parameter offset=yes was specified)
  95 + >>> info.ebounds() # gammalib.GEbounds object of energy ranges
  96 + >>> info.gti() # gammalib.GGti object containing good time intervals
88 97
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: 98 +There is also an example script to plot information about an observation
  99 +container which might be useful for a quick visualisation:
91 100
92 .. code-block:: bash 101 .. code-block:: bash
93 102
94 - $ python $CTOOLS/examples/show_obs.py selected_obs.xml 103 + $ python $CTOOLS/examples/show_obs.py selected_obs.xml
  104 +
95 105
96 Visualise models 106 Visualise models
97 ---------------- 107 ----------------
98 -Similar to :ref:`csobsinfo`, there is :ref:`csmodelinfo` to find out more about the content of a model XML file. In order to show the  
99 -position and sizes of the model on top of a skymap, this tool has the hidden parameter ``ds9file``, too. 108 +Similar to :ref:`csobsinfo`, there is the :ref:`csmodelinfo` script to find out
  109 +more about the content of a model XML file. In order to show the position and
  110 +sizes of the model on top of a skymap, this tool has the hidden parameter
  111 +``ds9file``, too.
100 112
101 .. code-block:: bash 113 .. code-block:: bash
102 114
103 - csmodelinfo ds9file=models.reg debug=yes  
104 - Input model XML file [$CTOOLS/share/models/crab.xml] 115 + $ csmodelinfo ds9file=models.reg debug=yes
  116 + Input model XML file [$CTOOLS/share/models/crab.xml]
105 117
106 -There are several options regarding the color, text and other attributes of the region file. To see a full list,  
107 -:ref:`visit the reference page <csmodelinfo>`.  
108 -Analogous to the pointings of the observation container, the models can be visualised using e.g. ds9: 118 +There are several options regarding the color, text and other attributes of the
  119 +region file. To see a full list, :ref:`visit the reference page <csmodelinfo>`.
  120 +Analogous to the pointings of the observation container, the models can be
  121 +visualised using for example ds9:
109 122
110 .. code-block:: bash 123 .. code-block:: bash
111 124
112 - $ ds9 skymap.fits -regions models.reg 125 + $ ds9 skymap.fits -regions models.reg
  126 +
113 127
114 Manipulating models in python 128 Manipulating models in python
115 ----------------------------- 129 -----------------------------
116 -This step will give some guidance how to work with model XML files in python and how to manipulate their content 130 +This example will give you some guidance on how to work with model XML files in
  131 +Python and how to manipulate their content:
117 132
118 .. code-block:: python 133 .. code-block:: python
119 134
120 - import gammalib  
121 -  
122 - # Open model file  
123 - models = gammalib.GModels("$CTOOLS/share/models/crab.xml")  
124 -  
125 - # Access a model component  
126 - src = models["Crab"]  
127 - print(src)  
128 -  
129 - # Retrieve the spectral or spatial component  
130 - print(src.spectral())  
131 - print(src.spatial())  
132 -  
133 - # Print the spectral parameter "Prefactor"  
134 - prefactor = src.spectral()["Prefactor"]  
135 - print("Prefactor: "+str(prefactor.value())+" +- "+str(prefactor.error()))  
136 -  
137 - # Set the prefactor value  
138 - prefactor.value(3.5e-17)  
139 -  
140 - # Loop over models and fix all parameters  
141 - for model in models:  
142 -  
143 - # Loop over model parameters  
144 - for par in model:  
145 -  
146 - # Fix parameter  
147 - par.fix()  
148 -  
149 - # Release one specific parameter  
150 - models["Crab"]["Prefactor"].free()  
151 -  
152 - # Set the parameter range  
153 - models["Crab"]["Prefactor"].min(1e-18)  
154 - models["Crab"]["Prefactor"].max(1e-16)  
155 -  
156 - # ... or in one step:  
157 - models["Crab"]["Prefactor"].range(1e-18, 1e-16)  
158 -  
159 - # Remove model from container  
160 - models.remove("Crab")  
161 -  
162 - # Save model to another XML file  
163 - models.save("mymodels.xml") 135 + >>> import gammalib
  136 +
  137 + >>> # Open model file
  138 + >>> models = gammalib.GModels("$CTOOLS/share/models/crab.xml")
  139 +
  140 + >>> # Access a model component
  141 + >>> src = models["Crab"]
  142 + >>> print(src)
  143 +
  144 + >>> # Retrieve the spectral or spatial component
  145 + >>> print(src.spectral())
  146 + >>> print(src.spatial())
  147 +
  148 + >>> # Print the spectral parameter "Prefactor"
  149 + >>> prefactor = src.spectral()["Prefactor"]
  150 + >>> print("Prefactor: "+str(prefactor.value())+" +- "+str(prefactor.error()))
  151 +
  152 + >>> # Set the prefactor value
  153 + >>> prefactor.value(3.5e-17)
  154 +
  155 + >>> # Loop over models and fix all parameters
  156 + >>> for model in models:
  157 + >>> for par in model: # Loop over model parameters
  158 + >>> par.fix() # Fix parameter
  159 +
  160 + >>> # Release one specific parameter
  161 + >>> models["Crab"]["Prefactor"].free()
  162 +
  163 + >>> # Set the parameter range
  164 + >>> models["Crab"]["Prefactor"].min(1e-18)
  165 + >>> models["Crab"]["Prefactor"].max(1e-16)
  166 +
  167 + >>> # ... or in one step:
  168 + >>> models["Crab"]["Prefactor"].range(1e-18, 1e-16)
  169 +
  170 + >>> # Remove model from container
  171 + >>> models.remove("Crab")
  172 +
  173 + >>> # Save model to another XML file
  174 + >>> models.save("mymodels.xml")
164 175
165 176
166 -Retrieve likelihood values from :ref:`ctlike`  
167 ----------------------------------------------  
168 -For some purposes, it might be useful to retrieve the fitted likelihood value and other results of the fit with :ref:`ctlike`. 177 +Retrieve likelihood values from ctlike
  178 +--------------------------------------
  179 +For some purposes, it might be useful to retrieve the fitted likelihood value
  180 +and other results of the fit with :ref:`ctlike`.
169 181
170 .. code-block:: python 182 .. code-block:: python
171 183
172 - import gammalib  
173 - import ctools  
174 -  
175 - # Create ctlike  
176 - like = ctools.ctlike()  
177 - like["inobs"] = "selected_obs.xml"  
178 - like["inmodel"] = "mymodels.xml"  
179 - like.run()  
180 -  
181 - # Get optimizer from ctlike  
182 - opt = like.opt()  
183 - print(opt)  
184 -  
185 - # Get likelihood value from optimizer  
186 - print(opt.value())  
187 -  
188 - # Get fit status:  
189 - print(opt.status())  
190 - # 0: converged  
191 - # 1: stalled  
192 - # 2: singular curvature matrix encountered  
193 - # 3: curvature matrix not positive definite  
194 - # 4: errors are inaccurate 184 + >>> import gammalib
  185 + >>> import ctools
  186 +
  187 + >>> # Create and run ctlike
  188 + >>> like = ctools.ctlike()
  189 + >>> like["inobs"] = "selected_obs.xml"
  190 + >>> like["inmodel"] = "mymodels.xml"
  191 + >>> like.run()
  192 +
  193 + >>> # Get optimizer from ctlike
  194 + >>> opt = like.opt()
  195 + >>> print(opt)
  196 +
  197 + >>> # Get likelihood value from optimizer
  198 + >>> print(opt.value())
  199 +
  200 + >>> # Get fit status:
  201 + >>> print(opt.status())
  202 + >>> # 0: converged
  203 + >>> # 1: stalled
  204 + >>> # 2: singular curvature matrix encountered
  205 + >>> # 3: curvature matrix not positive definite
  206 + >>> # 4: errors are inaccurate
  207 +
195 208
196 Speed up analysis 209 Speed up analysis
197 ----------------- 210 -----------------
198 -In some cases it may occur that the analysis takes very long. There are several reasons that can slow down the analysis quite severly.  
199 -Not all issues can be tackled. Nevertheless, here is a list of actions that have proven to speed up the fit. 211 +In some cases it may occur that the analysis takes very long. There are several
  212 +reasons that can slow down the analysis quite severly. Not all issues can be
  213 +tackled. Nevertheless, here is a list of actions that have proven to speed up
  214 +the fit.
  215 +
  216 +* Consider switching to stacked analysis if the observation time exceeds 50-100
  217 + hours.
  218 +* Diffuse and extended sources in the RoI are computational expensive. However,
  219 + in unbinned analysis they impact the speed much more.
  220 +* Usage of energy dispersion could also cause a long fit. Try switching it off
  221 + if speed is important. Keep in mind this will have an effect on the results.
  222 +* Switch to a machine that supports OpenMP. This allows to parallelise the fit
  223 + onto several cores.
200 224
201 -* Consider switching to binned analysis if the observation time exceeds 50-100 hours.  
202 -* Diffuse and extended sources in the RoI are computational expensive. However, in unbinned analysis they impact the speed much more.  
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.  
204 -* Switch to a machine that supports OpenMP. This allows to parallelise the fit onto several cores.  
205 225
206 Compute excess maps 226 Compute excess maps
207 ------------------- 227 -------------------
208 -A very important means to visualise images of sources are excess maps. The tool :ref:`csresmap` can also be used to create such a map.  
209 -The user, however, has to manually remove the source(s) of interest from the input model XML file. 228 +A very important means to visualise images of sources are excess maps. The script
  229 +:ref:`csresmap` can also be used to create such a map. The user, however, has to
  230 +manually remove the source(s) of interest from the input model XML file.
210 231
211 .. code-block:: python 232 .. code-block:: python
212 233
213 - import gammalib  
214 - models = gammalib.GModels("crab_models.xml")  
215 - models.remove("Crab")  
216 - models.save("models_without_crab.xml") 234 + >>> import gammalib
  235 + >>> models = gammalib.GModels("crab_models.xml")
  236 + >>> models.remove("Crab")
  237 + >>> models.save("models_without_crab.xml")
217 238
218 Of course, this can also be done by editing the XML file with an editor. 239 Of course, this can also be done by editing the XML file with an editor.
219 240
220 -Subsequently, :ref:`csresmap` can be executed using the ``algorithm=SUB`` parameter: 241 +Subsequently, :ref:`csresmap` can be executed using the ``algorithm=SUB``
  242 +parameter:
221 243
222 .. code-block:: bash 244 .. code-block:: bash
223 245
224 - $ csresmap  
225 - Input event list, counts cube, or observation definition XML file [selected_obs.xml]  
226 - Input model XML file [models_without_crab.xml]  
227 - First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]  
228 - Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01]  
229 - Coordinate System (CEL|GAL) [CEL]  
230 - Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR]  
231 - Size of the X axis in pixels [100]  
232 - Size of the Y axis in pixels [100]  
233 - Pixel size (deg/pixel) [0.02]  
234 - Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT) [SUB]  
235 - Output residual map file [excessmap.fits] 246 + $ csresmap
  247 + Input event list, counts cube, or observation definition XML file [selected_obs.xml]
  248 + Input model XML file [models_without_crab.xml]
  249 + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]
  250 + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01]
  251 + Coordinate System (CEL|GAL) [CEL]
  252 + Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR]
  253 + Size of the X axis in pixels [100]
  254 + Size of the Y axis in pixels [100]
  255 + Pixel size (deg/pixel) [0.02]
  256 + Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT) [SUB]
  257 + Output residual map file [excessmap.fits]
236 258
237 259
238 Compute flux maps 260 Compute flux maps
239 ----------------- 261 -----------------
240 -The creation of a flux map is much more expensive in terms of computing than an excess map. In the section about  
241 -:ref:`high level analysis tools <sec_high_level>`, the usage of :ref:`cttsmap` was demonstrated. This tool can also  
242 -be used to generate flux maps. For this, the user has to incoorporate a test source in the XML model file. This source  
243 -should consist of a spectral component using a PowerLaw2 model: 262 +The creation of a flux map is much more expensive in terms of computing than an
  263 +excess map. In the section about :ref:`high level analysis tools <sec_high_level>`,
  264 +the usage of :ref:`cttsmap` was demonstrated. This tool can also be used to
  265 +generate flux maps. For this, the user has to incorporate a test source in the
  266 +XML model file. This source should consist of a spectral component using a
  267 +PowerLaw2 model:
244 268
245 .. code-block:: xml 269 .. code-block:: xml
246 270
@@ -257,24 +281,30 @@ should consist of a spectral component using a PowerLaw2 model: @@ -257,24 +281,30 @@ should consist of a spectral component using a PowerLaw2 model:
257 </spatialModel> 281 </spatialModel>
258 </source> 282 </source>
259 283
260 -The further content of the rest of the XML model file depends on the user requirements: 284 +The further content of the rest of the XML model file depends on the user
  285 +requirements:
261 286
262 * For an absolute flux map, all other sky models should be removed 287 * For an absolute flux map, all other sky models should be removed
263 * For a residual flux map, all other sky models should be kept 288 * For a residual flux map, all other sky models should be kept
264 289
265 -The tool :ref:`cttsmap` will create one skymap per free spectral parameter in the model. In the result FITS file,  
266 -there will be an extension called "Integral" that contains the flux map. For the above XML example, the source name  
267 -"TestSource" should be specified to :ref:`cttsmap`. 290 +The tool :ref:`cttsmap` will create one skymap per free spectral parameter in
  291 +the model. In the result FITS file, there will be an extension called ``Integral``
  292 +that contains the flux map. For the above XML example, the source name
  293 +``TestSource`` should be specified to :ref:`cttsmap`.
  294 +
268 295
269 Speed up TS map computation 296 Speed up TS map computation
270 --------------------------- 297 ---------------------------
271 -Since the computation of a TS map can be extremely time consuming, the option of splitting the computation into several jobs  
272 -is supported. This might be of particular interest if the user has access to a batch farm. 298 +Since the computation of a TS map can be extremely time consuming, the option of
  299 +splitting the computation into several jobs is supported. This might be of
  300 +particular interest if the user has access to a batch farm.
273 301
274 Split TS map computation 302 Split TS map computation
275 ^^^^^^^^^^^^^^^^^^^^^^^^ 303 ^^^^^^^^^^^^^^^^^^^^^^^^
276 -For the purpose of job splitting, the hidden parameter ``binmin`` and ``binmax`` were included in the tool. These are integer parameter  
277 -that specify which bins should be computed. For instance, if the map should consist of 30x30(=900) pixels, the user could e.g. execute 304 +For the purpose of job splitting, the hidden parameter ``binmin`` and ``binmax``
  305 +were included in the tool. These are integer parameter that specify which bins
  306 +should be computed. For instance, if the map should consist of 30x30(=900) pixels,
  307 +the user could for example execute
278 308
279 .. code-block:: bash 309 .. code-block:: bash
280 310
@@ -289,13 +319,46 @@ Each command could run on a different machine. @@ -289,13 +319,46 @@ Each command could run on a different machine.
289 319
290 .. note:: 320 .. note::
291 321
292 - The output file name of individual jobs should be different. Otherwise files could overwrite each other. The naming of the individual slices  
293 - is up to the user. 322 + The output file name of individual jobs should be different. Otherwise files
  323 + could overwrite each other. The naming of the individual slices is up to the
  324 + user.
294 325
295 -Merge sliced TS maps  
296 -^^^^^^^^^^^^^^^^^^^^  
297 -The tool :ref:`cstsmapmerge` is intended to take care of merging the files that were produced while splitting the TS map computation.  
298 -There are several options to pass the files to be merged as arguments: 326 +The script :ref:`cstsmapsplit` will take care of this bookkeeping. It creates an
  327 +ASCII file containing all the commands according to the user input. The following
  328 +example will create split the computation of a TS map into 2000 separate task.
  329 +Each task will only compute 5 bins on its own. This is very useful if the
  330 +observation container is large or the fit simply takes a long time.
  331 +
  332 +.. code-block:: bash
  333 +
  334 + $ cstsmapsplit
  335 + Input event list, counts cube or observation definition XML file [selected_obs.xml]
  336 + Input model definition XML file [$CTOOLS/share/models/crab.xml]
  337 + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]
  338 + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01]
  339 + Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR]
  340 + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL]
  341 + Image scale (in degrees/pixel) [0.02]
  342 + Size of the X axis in pixels [100]
  343 + Size of the Y axis in pixels [100]
  344 + Test source name [Crab]
  345 + Output Test Statistic map file [tsmap.fits]
  346 + Number of TS map bins per task [5]
  347 + Compute null hypothesis first? [yes]
  348 + ASCII file containing all commands [commands.dat]
  349 +
  350 +.. note::
  351 +
  352 + One can decide if we want to compute the null hypothesis first. This way, a
  353 + parameter optimisation will be performed without the test source. The obtained
  354 + likelihood value will then be passed to each individual task of :ref:`cttsmap`.
  355 + If ``compute_null=no``, each task has to compute the null hypothesis itself.
  356 +
  357 +Merge splitted TS maps
  358 +^^^^^^^^^^^^^^^^^^^^^^
  359 +The script :ref:`cstsmapmerge` is intended to take care of merging the files
  360 +that were produced while splitting the TS map computation. There are several
  361 +options to pass the files to be merged as arguments:
299 362
300 * a space-separated list of file names (e.g. tsmap1.fits tsmap2.fits) 363 * a space-separated list of file names (e.g. tsmap1.fits tsmap2.fits)
301 * a comma-separated list of file names (e.g. tsmap1.fits,tsmap2.fits) 364 * a comma-separated list of file names (e.g. tsmap1.fits,tsmap2.fits)
@@ -306,132 +369,135 @@ In this example the ASCII file method is presented: @@ -306,132 +369,135 @@ In this example the ASCII file method is presented:
306 369
307 .. code-block:: bash 370 .. code-block:: bash
308 371
309 - # Put slice files into an ascii file  
310 - $ ls tsmap_*.fits > tsmapfiles.txt  
311 -  
312 - # Run cstsmapmerge  
313 - $ cstsmapmerge  
314 - Input TS map FITS files [@tsmapfiles.txt]  
315 - Output TS map FITS file [mytsmap.fits] 372 + # Put slice files into an ascii file
  373 + $ ls tsmap_*.fits > tsmapfiles.txt
  374 +
  375 + # Run cstsmapmerge
  376 + $ cstsmapmerge
  377 + Input TS map FITS files [@tsmapfiles.txt]
  378 + Output TS map FITS file [mytsmap.fits]
316 379
317 380
318 Creating a python analysis pipeline 381 Creating a python analysis pipeline
319 ----------------------------------- 382 -----------------------------------
320 -It is easily possible to build an own analysis workflow with a simple python script. The following source code example shows a python script  
321 -running from gathering observations until fitting spectral points without storing intermediate data products on disk. It assumes that the  
322 -environment variable ``$VHEFITS`` is set to the path where IACT FITS data is located. 383 +It is easily possible to build an own analysis workflow with a simple python
  384 +script. The following source code example shows a python script running from
  385 +gathering observations until fitting spectral points without storing intermediate
  386 +data products on disk. It assumes that the environment variable ``$VHEFITS`` is
  387 +set to the path where IACT FITS data is located.
323 388
324 .. code-block:: python 389 .. code-block:: python
325 390
326 - import gammalib  
327 - import ctools  
328 - import cscripts  
329 -  
330 - # Set debug flag  
331 - debug = True  
332 -  
333 - # Set flag to use energy dispersion  
334 - edisp = False  
335 -  
336 - # Set inmodel file name  
337 - inmodel = "$GAMMALIB/test/data/model_point_plaw.xml"  
338 -  
339 - # Expand environment variable  
340 - inmodel = gammalib.expand_env(inmodel)  
341 -  
342 - # Extract coordinates and model properties  
343 - models = gammalib.GModels(inmodel)  
344 - srcname = models[0].name()  
345 - ra = models[0]["RA"].value()  
346 - dec = models[0]["DEC"].value()  
347 -  
348 - # Find FITS production name  
349 - iactdata = cscripts.csiactdata()  
350 - iactdata["debug"] = debug  
351 - iactdata.run()  
352 -  
353 - # Use first available production  
354 - prodname = iactdata.names()[0]  
355 -  
356 - # Run csfindobs  
357 - findobs = cscripts.csfindobs()  
358 - findobs["ra"] = ra  
359 - findobs["dec"] = dec  
360 - findobs["rad"] = 2.5  
361 - findobs["prodname"] = prodname  
362 - findobs["debug"] = debug  
363 - findobs["outfile"] = "NONE"  
364 - findobs.run()  
365 -  
366 - # Retrieve obervation IDs (runlist)  
367 - obs_ids = findobs.obs_ids()  
368 -  
369 - # Build observation container  
370 - iactobs = cscripts.csiactobs()  
371 - iactobs["prodname"] = prodname  
372 - iactobs["inmodel"] = inmodel  
373 - iactobs["bkgpars"] = 1  
374 - iactobs["outobs"] = "NONE"  
375 - iactobs["outmodel"] = "NONE"  
376 - iactobs["debug"] = debug  
377 - iactobs.runlist(obs_ids)  
378 - iactobs.run()  
379 -  
380 - # Retrieve observation container and energy boundaries  
381 - obs = iactobs.obs()  
382 - ebounds = iactobs.ebounds()  
383 -  
384 - # Run ctselect  
385 - select = ctools.ctselect(obs)  
386 - select["usepnt"] = True  
387 - select["rad"] = 2.5  
388 - select["usethres"] = "DEFAULT"  
389 - select["tmin"] = 0.0  
390 - select["tmax"] = 0.0  
391 - select["emin"] = 0.1  
392 - select["emax"] = 100.0  
393 - select["debug"] = debug  
394 - select.run()  
395 -  
396 - # Pass selected observations to ctlike  
397 - like = ctools.ctlike(select.obs())  
398 - like["debug"] = debug  
399 - like["edisp"] = edisp  
400 - like.run()  
401 -  
402 - # Compute a spectrum and save  
403 - spec = cscripts.csspec(like.obs())  
404 - spec["srcname"] = srcname  
405 - spec["emin"] = ebounds.emin().TeV()  
406 - spec["emax"] = ebounds.emax().TeV()  
407 - spec["enumbins"] = 10  
408 - spec["edisp"] = edisp  
409 - spec["ebinalg"] = "LOG"  
410 - spec["debug"] = debug  
411 - spec["outfile"] = "spectrum.fits"  
412 - spec.execute()  
413 -  
414 - # Remove model for excess map computation  
415 - like.obs().models().remove(srcname)  
416 -  
417 - # Compute an excess map  
418 - resmap = cscripts.csresmap(like.obs())  
419 - resmap["xref"] = ra  
420 - resmap["yref"] = dec  
421 - resmap["proj"] = "CAR"  
422 - resmap["coordsys"] = "CEL"  
423 - resmap["emin"] = ebounds.emin().TeV()  
424 - resmap["emax"] = ebounds.emax().TeV()  
425 - resmap["nxpix"] = 100  
426 - resmap["nypix"] = 100  
427 - resmap["binsz"] = 0.02  
428 - resmap["outmap"] = "excessmap.fits"  
429 - resmap.execute()  
430 -  
431 -The results of this analysis workflow can be inspected using an example python script and e.g. ds9: 391 + >>> import gammalib
  392 + >>> import ctools
  393 + >>> import cscripts
  394 +
  395 + >>> # Set debug flag
  396 + >>> debug = True
  397 +
  398 + >>> # Set flag to use energy dispersion
  399 + >>> edisp = False
  400 +
  401 + >>> # Set inmodel file name
  402 + >>> inmodel = "$GAMMALIB/test/data/model_point_plaw.xml"
  403 +
  404 + >>> # Expand environment variable
  405 + >>> inmodel = gammalib.expand_env(inmodel)
  406 +
  407 + >>> # Extract coordinates and model properties
  408 + >>> models = gammalib.GModels(inmodel)
  409 + >>> srcname = models[0].name()
  410 + >>> ra = models[0]["RA"].value()
  411 + >>> dec = models[0]["DEC"].value()
  412 +
  413 + >>> # Find FITS production name
  414 + >>> iactdata = cscripts.csiactdata()
  415 + >>> iactdata["debug"] = debug
  416 + >>> iactdata.run()
  417 +
  418 + >>> # Use first available production
  419 + >>> prodname = iactdata.names()[0]
  420 +
  421 + >>> # Run csfindobs
  422 + >>> findobs = cscripts.csfindobs()
  423 + >>> findobs["ra"] = ra
  424 + >>> findobs["dec"] = dec
  425 + >>> findobs["rad"] = 2.5
  426 + >>> findobs["prodname"] = prodname
  427 + >>> findobs["debug"] = debug
  428 + >>> findobs["outfile"] = "NONE"
  429 + >>> findobs.run()
  430 +
  431 + >>> # Retrieve obervation IDs (runlist)
  432 + >>> obs_ids = findobs.obs_ids()
  433 +
  434 + >>> # Build observation container
  435 + >>> iactobs = cscripts.csiactobs()
  436 + >>> iactobs["prodname"] = prodname
  437 + >>> iactobs["inmodel"] = inmodel
  438 + >>> iactobs["bkgpars"] = 1
  439 + >>> iactobs["outobs"] = "NONE"
  440 + >>> iactobs["outmodel"] = "NONE"
  441 + >>> iactobs["debug"] = debug
  442 + >>> iactobs.runlist(obs_ids)
  443 + >>> iactobs.run()
  444 +
  445 + >>> # Retrieve observation container and energy boundaries
  446 + >>> obs = iactobs.obs()
  447 + >>> ebounds = iactobs.ebounds()
  448 +
  449 + >>> # Run ctselect
  450 + >>> select = ctools.ctselect(obs)
  451 + >>> select["usepnt"] = True
  452 + >>> select["rad"] = 2.5
  453 + >>> select["usethres"] = "DEFAULT"
  454 + >>> select["tmin"] = 0.0
  455 + >>> select["tmax"] = 0.0
  456 + >>> select["emin"] = 0.1
  457 + >>> select["emax"] = 100.0
  458 + >>> select["debug"] = debug
  459 + >>> select.run()
  460 +
  461 + >>> # Pass selected observations to ctlike
  462 + >>> like = ctools.ctlike(select.obs())
  463 + >>> like["debug"] = debug
  464 + >>> like["edisp"] = edisp
  465 + >>> like.run()
  466 +
  467 + >>> # Compute a spectrum and save
  468 + >>> spec = cscripts.csspec(like.obs())
  469 + >>> spec["srcname"] = srcname
  470 + >>> spec["emin"] = ebounds.emin().TeV()
  471 + >>> spec["emax"] = ebounds.emax().TeV()
  472 + >>> spec["enumbins"] = 10
  473 + >>> spec["edisp"] = edisp
  474 + >>> spec["ebinalg"] = "LOG"
  475 + >>> spec["debug"] = debug
  476 + >>> spec["outfile"] = "spectrum.fits"
  477 + >>> spec.execute()
  478 +
  479 + >>> # Remove model for excess map computation
  480 + >>> like.obs().models().remove(srcname)
  481 +
  482 + >>> # Compute an excess map
  483 + >>> resmap = cscripts.csresmap(like.obs())
  484 + >>> resmap["xref"] = ra
  485 + >>> resmap["yref"] = dec
  486 + >>> resmap["proj"] = "CAR"
  487 + >>> resmap["coordsys"] = "CEL"
  488 + >>> resmap["emin"] = ebounds.emin().TeV()
  489 + >>> resmap["emax"] = ebounds.emax().TeV()
  490 + >>> resmap["nxpix"] = 100
  491 + >>> resmap["nypix"] = 100
  492 + >>> resmap["binsz"] = 0.02
  493 + >>> resmap["outmap"] = "excessmap.fits"
  494 + >>> resmap.execute()
  495 +
  496 +The results of this analysis workflow can be inspected using an example Python
  497 +script and for example ds9:
432 498
433 .. code-block:: bash 499 .. code-block:: bash
434 500
435 - $ python $CTOOLS/examples/show_spectrum.py spectrum.fits  
436 - $ ds9 excessmap.fits 501 + $ python $CTOOLS/examples/show_spectrum.py spectrum.fits
  502 + $ ds9 excessmap.fits
437 503
438 \ No newline at end of file 504 \ No newline at end of file