Commit a0c2cfae64191e7761d2f1a66a65f389dad374b6

Authored by Michael Mayer
1 parent 48524efb

Finished the tips section and expanded section about expcube

doc/source/user_manual/iact_analysis/analysis.rst
... ... @@ -301,8 +301,15 @@ After binning the events into a three-dimensional cube, an exposure cube has to
301 301 The exposure is defined as the effective area times the dead-time corrected observation time.
302 302 Each observation from the input container gets stacked in the resulting cube. The exposure is stored
303 303 in units of cm^2 s. The exposure cube does not have to contain the same binning as the event cube
304   -but for simplicity, the event cube can be passed to adopt the binning parameters. This task is performed by
305   -:ref:`ctexpcube`.
  304 +but for simplicity, the event cube can be passed to adopt the binning parameters. Note, however, that the
  305 +exposure cube is defined in true sky coordinates and energy while the counts cube is defined in reconstructed
  306 +sky coordinates and energy. Consequently, the sky area and energy range covered by the exposure cube should be
  307 +slightly larger than that of the counts cube to accommodate for spill over of events due to the point spread function
  308 +and energy dispersion. By computing the exposure cube on the same grid as the counts cube, the spill over of events
  309 +from sources at the edge of cube will not be handled correctly. In the example below, however, no source at the edge of the
  310 +field of view is present. Therefore, for simplicity, the count cube is used as input cube to extract the binning.
  311 +
  312 +This task of computing the exposure cube is is performed by:ref:`ctexpcube`.
306 313  
307 314 .. code-block:: bash
308 315  
... ...
doc/source/user_manual/iact_analysis/tips.rst
... ... @@ -2,7 +2,7 @@
2 2  
3 3 Tips, Tricks and FAQs
4 4 =====================
5   -This section shows some of the wrinkles that could fascilitate the users' life when running analyses.
  5 +This section shows some of the wrinkles that could fascilitate the users' life when running IACT analyses.
6 6  
7 7 Visualise observations
8 8 ----------------------
... ... @@ -12,7 +12,7 @@ Create a skymap of counts
12 12 ^^^^^^^^^^^^^^^^^^^^^^^^^
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   -Since :ref:`ctbin` is indended for binned/stacked analysis, it respects energy thresholds, RoI selections etc.
  15 +Since :ref:`ctbin` is intended for binned/stacked analysis, it respects energy thresholds, RoI selections etc.
16 16 Accordingly, :ref:`ctskymap` should be used for a simple visualisation of the counts.
17 17  
18 18  
... ... @@ -39,8 +39,7 @@ contains these information:
39 39  
40 40 .. code-block:: bash
41 41  
42   - $ csobsinfo ds9file=pointings.reg
43   - Parfile "csobsinfo.par" not found. Create default parfile.
  42 + $ csobsinfo ds9file=pointings.reg debug=yes
44 43 Event list, counts cube, or observation definition file [obs.xml]
45 44  
46 45 Together with the previously produced skymap, one can plot the pointings using e.g. ds9:
... ... @@ -51,7 +50,7 @@ Together with the previously produced skymap, one can plot the pointings using e
51 50  
52 51 Plot zenith angle distribution of observations
53 52 ----------------------------------------------
54   -The tool :ref:`csobsinfo` dumps more information into the log file that might be of interest to catch in a script.
  53 +The tool :ref:`csobsinfo` dumps more information into the log file. Some of them might be of interest to catch in a script.
55 54 Therefore, one could simply use this tool via python and plot some distributions:
56 55  
57 56 .. code-block:: python
... ... @@ -86,7 +85,7 @@ position and sizes of the model on top of a skymap, this tool has the hidden par
86 85  
87 86 .. code-block:: bash
88 87  
89   - csmodelinfo ds9file=models.reg
  88 + csmodelinfo ds9file=models.reg debug=yes
90 89 Input model XML file [$CTOOLS/share/models/crab.xml]
91 90  
92 91 There are several options regarding the color, text and other attributes of the region file. To see a full list,
... ... @@ -118,7 +117,7 @@ This step will give some guidance how to work with model XML files in python and
118 117  
119 118 # Print the spectral parameter "Prefactor"
120 119 prefactor = src.spectral()["Prefactor"]
121   - print("Prefactor:",prefactor.value(),"+-",prefactor.error())
  120 + print("Prefactor: "+str(prefactor.value())+" +- "+str(prefactor.error()))
122 121  
123 122 # Set the prefactor value
124 123 prefactor.value(3.5e-17)
... ... @@ -140,7 +139,7 @@ This step will give some guidance how to work with model XML files in python and
140 139 models["Crab"]["Prefactor"].max(1e-16)
141 140  
142 141 # ... or in one step:
143   - models["Crab"]["Prefactor].range(1e-18, 1e-16)
  142 + models["Crab"]["Prefactor"].range(1e-18, 1e-16)
144 143  
145 144 # Remove model from container
146 145 models.remove("Crab")
... ... @@ -231,16 +230,16 @@ should consist of a spectral component using a PowerLaw2 model:
231 230 .. code-block:: xml
232 231  
233 232 <source name="TestSource" type="PointSource">
234   - <spectrum type="PowerLaw2">
235   - <parameter scale="1e-07" name="Integral" min="1e-07" max="1000.0" value="1.0" free="1"/>
236   - <parameter scale="1.0" name="Index" min="-5.0" max="+5.0" value="-2.0" free="1"/>
237   - <parameter scale="1.0" name="LowerLimit" min="10.0" max="1000000.0" value="100.0" free="0"/>
238   - <parameter scale="1.0" name="UpperLimit" min="10.0" max="1000000.0" value="500000.0" free="0"/>
239   - </spectrum>
240   - <spatialModel type="SkyDirFunction">
241   - <parameter free="0" max="360" min="-360" name="RA" scale="1" value="83.6331" />
242   - <parameter free="0" max="90" min="-90" name="DEC" scale="1" value="22.0145" />
243   - </spatialModel>
  233 + <spectrum type="PowerLaw2">
  234 + <parameter scale="1e-07" name="Integral" min="1e-07" max="1000.0" value="1.0" free="1"/>
  235 + <parameter scale="1.0" name="Index" min="-5.0" max="+5.0" value="-2.0" free="1"/>
  236 + <parameter scale="1.0" name="LowerLimit" min="10.0" max="1000000.0" value="100.0" free="0"/>
  237 + <parameter scale="1.0" name="UpperLimit" min="10.0" max="1000000.0" value="500000.0" free="0"/>
  238 + </spectrum>
  239 + <spatialModel type="SkyDirFunction">
  240 + <parameter free="0" max="360" min="-360" name="RA" scale="1" value="83.6331" />
  241 + <parameter free="0" max="90" min="-90" name="DEC" scale="1" value="22.0145" />
  242 + </spatialModel>
244 243 </source>
245 244  
246 245 The further content of the rest of the XML model file depends on the user requirements:
... ... @@ -260,23 +259,23 @@ is supported. This might be of particular interest if the user has access to a b
260 259 Split TS map computation
261 260 ^^^^^^^^^^^^^^^^^^^^^^^^
262 261 For the purpose of job splitting, the hidden parameter ``binmin`` and ``binmax`` were included in the tool. These are integer parameter
263   -that specify which bins should be computed. For instance, if the map should consist of 30x30 =90 pixels, the use could e.g. execute
  262 +that specify which bins should be computed. For instance, if the map should consist of 30x30(=900) pixels, the user could e.g. execute
264 263  
265 264 .. code-block:: bash
266 265  
267   - $ cttsmap binmin=0 binmax=299
  266 + $ cttsmap binmin=0 binmax=299 outmap=tsmap_0_299.fits
268 267 ...
269   - $ cttsmap binmin=300 binmax=599
  268 + $ cttsmap binmin=300 binmax=599 outmap=tsmap_300_599.fits
270 269 ...
271   - $ cttsmap binmin=600 binmax=899
  270 + $ cttsmap binmin=600 binmax=899 outmap=tsmap_600_899.fits
272 271 ...
273 272  
274   -on different machines.
  273 +Each command could run on a different machine.
275 274  
276 275 .. note::
277 276  
278   - The output file name of individual jobs can be the same. If the parameters are specified, the output file name will be appended by the suffix
279   - "_<binmin>_<binmax>" to distinguish between the sliced TS maps.
  277 + The output file name of individual jobs should be different. Otherwise files could overwrite each other. The naming of the individual slices
  278 + is up to the user.
280 279  
281 280 Merge sliced TS maps
282 281 ^^^^^^^^^^^^^^^^^^^^
... ... @@ -302,4 +301,122 @@ In this example the ASCII file method is presented:
302 301  
303 302  
304 303 Creating a python analysis pipeline
305   ------------------------------------
306 304 \ No newline at end of file
  305 +-----------------------------------
  306 +It is easily possible to build an own analysis workflow with a simple python script. The following source code example shows a python script
  307 +running from gathering observations until fitting spectral points without storing intermediate data products on disk. It assumes that the
  308 +environment variable ``$VHEFITS`` is set to the path where IACT FITS data is located.
  309 +
  310 +.. code-block:: python
  311 +
  312 + import gammalib
  313 + import ctools
  314 + import cscripts
  315 +
  316 + # Set debug flag
  317 + debug = True
  318 +
  319 + # Set flag to use energy dispersion
  320 + edisp = False
  321 +
  322 + # Set inmodel file name
  323 + inmodel = "$GAMMALIB/test/data/model_point_plaw.xml"
  324 +
  325 + # Expand environment variable
  326 + inmodel = gammalib.expand_env(inmodel)
  327 +
  328 + # Extract coordinates and model properties
  329 + models = gammalib.GModels(inmodel)
  330 + srcname = models[0].name()
  331 + ra = models[0]["RA"].value()
  332 + dec = models[0]["DEC"].value()
  333 +
  334 + # Find FITS production name
  335 + iactdata = cscripts.csiactdata()
  336 + iactdata["debug"] = debug
  337 + iactdata.run()
  338 +
  339 + # Use first available production
  340 + prodname = iactdata.names()[0]
  341 +
  342 + # Run csfindobs
  343 + findobs = cscripts.csfindobs()
  344 + findobs["ra"] = ra
  345 + findobs["dec"] = dec
  346 + findobs["rad"] = 2.5
  347 + findobs["prodname"] = prodname
  348 + findobs["debug"] = debug
  349 + findobs["outfile"] = "NONE"
  350 + findobs.run()
  351 +
  352 + # Retrieve obervation IDs (runlist)
  353 + obs_ids = findobs.obs_ids()
  354 +
  355 + # Build observation container
  356 + iactobs = cscripts.csiactobs()
  357 + iactobs["prodname"] = prodname
  358 + iactobs["inmodel"] = inmodel
  359 + iactobs["bkgpars"] = 1
  360 + iactobs["outobs"] = "NONE"
  361 + iactobs["outmodel"] = "NONE"
  362 + iactobs["debug"] = debug
  363 + iactobs.runlist(obs_ids)
  364 + iactobs.run()
  365 +
  366 + # Retrieve observation container and energy boundaries
  367 + obs = iactobs.obs()
  368 + ebounds = iactobs.ebounds()
  369 +
  370 + # Run ctselect
  371 + select = ctools.ctselect(obs)
  372 + select["usepnt"] = True
  373 + select["rad"] = 2.5
  374 + select["usethres"] = "DEFAULT"
  375 + select["tmin"] = 0.0
  376 + select["tmax"] = 0.0
  377 + select["emin"] = 0.1
  378 + select["emax"] = 100.0
  379 + select["debug"] = debug
  380 + select.run()
  381 +
  382 + # Pass selected observations to ctlike
  383 + like = ctools.ctlike(select.obs())
  384 + like["debug"] = debug
  385 + like["edisp"] = edisp
  386 + like.run()
  387 +
  388 + # Compute a spectrum and save
  389 + spec = cscripts.csspec(like.obs())
  390 + spec["srcname"] = srcname
  391 + spec["emin"] = ebounds.emin().TeV()
  392 + spec["emax"] = ebounds.emax().TeV()
  393 + spec["enumbins"] = 10
  394 + spec["edisp"] = edisp
  395 + spec["ebinalg"] = "LOG"
  396 + spec["debug"] = debug
  397 + spec["outfile"] = "spectrum.fits"
  398 + spec.execute()
  399 +
  400 + # Remove model for excess map computation
  401 + like.obs().models().remove(srcname)
  402 +
  403 + # Compute an excess map
  404 + resmap = cscripts.csresmap(like.obs())
  405 + resmap["xref"] = ra
  406 + resmap["yref"] = dec
  407 + resmap["proj"] = "CAR"
  408 + resmap["coordsys"] = "CEL"
  409 + resmap["emin"] = ebounds.emin().TeV()
  410 + resmap["emax"] = ebounds.emax().TeV()
  411 + resmap["nxpix"] = 100
  412 + resmap["nypix"] = 100
  413 + resmap["binsz"] = 0.02
  414 + resmap["outmap"] = "excessmap.fits"
  415 + resmap.execute()
  416 +
  417 +The results of this analysis workflow can be inspected using an example python script and e.g. ds9:
  418 +
  419 +.. code-block:: bash
  420 +
  421 + $ python $CTOOLS/examples/show_spectrum.py spectrum.fits
  422 + $ ds9 excessmap.fits
  423 +
307 424 \ No newline at end of file
... ...