Commit 95b202bf09ec53ab886f2b4ac3bf285fd4d9c454

Authored by Michael Mayer
1 parent 3ba575b2

Added unit test and docs for csobsinfo

cscripts/csobsinfo.py 100644 → 100755
... ... @@ -21,8 +21,6 @@
21 21 import gammalib
22 22 import ctools
23 23 import sys
24   -import os
25   -import datetime
26 24  
27 25  
28 26 # =============== #
... ... @@ -103,7 +101,7 @@ class csobsinfo(ctools.cscript):
103 101 # Get parameters
104 102 #self.inobs = self["inobs"].filename()
105 103 self.require_inobs("csobsinfo::get_parameters")
106   - self.obs = self.get_observations(False)#gammalib.GObservations(self.inobs)
  104 + self.obs = self.get_observations(False)
107 105  
108 106 self.obj_dir = gammalib.GSkyDir()
109 107  
... ... @@ -145,8 +143,8 @@ class csobsinfo(ctools.cscript):
145 143 obs_names = []
146 144  
147 145 # Initialise output to be filled
148   - ebounds = gammalib.GEbounds()
149   - gti = gammalib.GGti()
  146 + self.ebounds = gammalib.GEbounds()
  147 + self.gti = gammalib.GGti()
150 148 ontime = 0.0
151 149 livetime = 0.0
152 150 n_events = 0
... ... @@ -197,10 +195,10 @@ class csobsinfo(ctools.cscript):
197 195  
198 196 # If avaliable append energy boundaries
199 197 if obs_bounds.size() > 0 :
200   - ebounds.merge(obs_bounds.emin(),obs_bounds.emax())
  198 + self.ebounds.merge(obs_bounds.emin(),obs_bounds.emax())
201 199  
202 200 # Append time interval
203   - gti.merge(obs_gti.tstart(), obs_gti.tstop())
  201 + self.gti.merge(obs_gti.tstart(), obs_gti.tstop())
204 202  
205 203 # increment global livetime and ontime
206 204 ontime += obs.ontime()
... ... @@ -340,25 +338,25 @@ class csobsinfo(ctools.cscript):
340 338 # Log energy range
341 339 self.log.header3("Energy range")
342 340 self.log.parformat("Emin")
343   - if ebounds.size() == 0:
  341 + if self.ebounds.size() == 0:
344 342 self.log("undefined")
345 343 else:
346   - self.log(str(ebounds.emin()))
  344 + self.log(str(self.ebounds.emin()))
347 345 self.log("\n")
348 346 self.log.parformat("Emax")
349   - if ebounds.size() == 0:
  347 + if self.ebounds.size() == 0:
350 348 self.log("undefined")
351 349 else:
352   - self.log(str(ebounds.emax()))
  350 + self.log(str(self.ebounds.emax()))
353 351 self.log("\n\n")
354 352  
355 353 # Log time range
356 354 self.log.header3("Time range")
357 355 self.log.parformat("Start [MJD]")
358   - self.log(str(gti.tstart().mjd()))
  356 + self.log(str(self.gti.tstart().mjd()))
359 357 self.log("\n")
360 358 self.log.parformat("Stop [MJD]")
361   - self.log(str(gti.tstop().mjd()))
  359 + self.log(str(self.gti.tstop().mjd()))
362 360 self.log("\n")
363 361  
364 362 # Log ontime and livetime in different units
... ... @@ -422,7 +420,18 @@ class csobsinfo(ctools.cscript):
422 420 Return offset angles
423 421 """
424 422 return self.offsets
425   -
  423 +
  424 + def ebounds(self):
  425 + """
  426 + Return energy boundaries
  427 + """
  428 + return self.ebounds
  429 +
  430 + def gti(self):
  431 + """
  432 + Return good time intervals
  433 + """
  434 + return self.gti
426 435  
427 436 def execute(self):
428 437 """
... ...
doc/source/reference_manual/csobsinfo.rst 0 → 100644
  1 +.. _csobsinfo:
  2 +
  3 +csobsinfo
  4 +======
  5 +
  6 +Dumps information about an observation container into log file or on screen
  7 +
  8 +
  9 +Synopsis
  10 +--------
  11 +
  12 +This script provides detailled information about a given observation container.
  13 +For IACT observations usually several observations with different
  14 +configurations are combined. The script computes e.g. the overall energy
  15 +range which could be an important input for :doc:`ctbin` to create a suitable
  16 +energy range. In addition the script prints the pointing attributes like the average
  17 +zenith/azimuth angle. If the hidden boolean parameter "offset" is specified to "yes",
  18 +the script queries for the target position and computes the run-by-run offset as well
  19 +as its average. In the observation summary, the time range of the observations including
  20 +total ontime and (dead-time corrected) livetime is shown.
  21 +
  22 +The script further contains the hidden parameter "ds9file". If specified with a file
  23 +name, the tool writes out a ds9 region file including a cross for each pointing position
  24 +in the sky.
  25 +
  26 +When executed from within python, the script provides methods to return arrays containing
  27 +observation-wise parameters. This might be useful for graphical display within a script. The
  28 +following methods are implemented:
  29 +- zeniths (returning all zenith angles)
  30 +- azimuths (returning all azimuth angles)
  31 +- offsets (returning all offset angles, provided the hidden parameter offset=yes)
  32 +- ebounds (returning energy boundaries)
  33 +- gtis (returning good time intervals)
  34 +
  35 +
  36 +General parameters
  37 +------------------
  38 +
  39 +``inobs [file]``
  40 + Event list, counts cube, or observation definition file
  41 +
  42 +``(offset = no) [file]``
  43 + Compute offset from target to pointing positions
  44 +
  45 +``ra [real]``
  46 + Target right ascension for offset computation (only queried if offset=yes)
  47 +
  48 +``dec [real]``
  49 + Target declination for offset computation (only queried if offset=yes)
  50 +
  51 +``(ds9file = NONE) [file]``
  52 + DS9 region file containing pointings
  53 +
  54 +
  55 +Standard parameters
  56 +-------------------
  57 +
  58 +``(chatter = 2) [integer]``
  59 + Verbosity of the executable:
  60 + chatter = 0: no information will be logged
  61 +
  62 + chatter = 1: only errors will be logged
  63 +
  64 + chatter = 2: errors and actions will be logged
  65 +
  66 + chatter = 3: report about the task execution
  67 +
  68 + chatter = 4: detailed report about the task execution
  69 +
  70 +``(clobber = yes) [boolean]``
  71 + Specifies whether an existing output counts cube should be overwritten.
  72 +
  73 +``(debug = no) [boolean]``
  74 + Enables debug mode. In debug mode the executable will dump any log file output to the console.
  75 +
  76 +``(mode = ql) [string]``
  77 + Mode of automatic parameters (default is "ql", i.e. "query and learn").
  78 +
  79 +``(logfile = cssens.log) [filename]``
  80 + Log filename.
  81 +
  82 +
  83 +Related tools or scripts
  84 +------------------------
  85 +
... ...
test/test_cscripts.sh.in
... ... @@ -36,7 +36,7 @@ $ECHO "*****************"
36 36 #
37 37 # Remove any existing result files
38 38 # ================================
39   -rm -rf *.fits *.xml *.dat
  39 +rm -rf *.fits *.xml *.dat *.reg
40 40  
41 41  
42 42 #
... ... @@ -74,6 +74,28 @@ $ECHO " ok"
74 74  
75 75  
76 76 #
  77 +# Test csobsinfo
  78 +# ==============
  79 +$ECHO -n "Test csobsinfo: "
  80 +chmod +x @abs_top_srcdir@/cscripts/csobsinfo.py
  81 +@abs_top_srcdir@/cscripts/csobsinfo.py \
  82 + inobs="obs.xml" \
  83 + ds9file="ds9.reg" \
  84 + offset=yes \
  85 + ra="83.6331" \
  86 + dec="22.01" > csobsinfo.log
  87 +$ECHO -n "."
  88 +if [ -s "ds9.reg" ]
  89 +then
  90 + $ECHO -n "."
  91 +else
  92 + $ECHO " ds9.reg file is not valid"
  93 + exit 1
  94 +fi
  95 +$ECHO " ok"
  96 +
  97 +
  98 +#
77 99 # Test cspull
78 100 # ===========
79 101 $ECHO -n "Test cspull: "
... ...