From 95b202bf09ec53ab886f2b4ac3bf285fd4d9c454 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 20 Nov 2015 15:04:13 +0100 Subject: [PATCH] Added unit test and docs for csobsinfo --- cscripts/csobsinfo.py | 37 +++++++++++++++++++++++-------------- doc/source/reference_manual/csobsinfo.rst | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_cscripts.sh.in | 24 +++++++++++++++++++++++- 3 files changed, 131 insertions(+), 15 deletions(-) mode change 100644 => 100755 cscripts/csobsinfo.py create mode 100644 doc/source/reference_manual/csobsinfo.rst diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py old mode 100644 new mode 100755 index 663ab2e..f8deef8 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -21,8 +21,6 @@ import gammalib import ctools import sys -import os -import datetime # =============== # @@ -103,7 +101,7 @@ class csobsinfo(ctools.cscript): # Get parameters #self.inobs = self["inobs"].filename() self.require_inobs("csobsinfo::get_parameters") - self.obs = self.get_observations(False)#gammalib.GObservations(self.inobs) + self.obs = self.get_observations(False) self.obj_dir = gammalib.GSkyDir() @@ -145,8 +143,8 @@ class csobsinfo(ctools.cscript): obs_names = [] # Initialise output to be filled - ebounds = gammalib.GEbounds() - gti = gammalib.GGti() + self.ebounds = gammalib.GEbounds() + self.gti = gammalib.GGti() ontime = 0.0 livetime = 0.0 n_events = 0 @@ -197,10 +195,10 @@ class csobsinfo(ctools.cscript): # If avaliable append energy boundaries if obs_bounds.size() > 0 : - ebounds.merge(obs_bounds.emin(),obs_bounds.emax()) + self.ebounds.merge(obs_bounds.emin(),obs_bounds.emax()) # Append time interval - gti.merge(obs_gti.tstart(), obs_gti.tstop()) + self.gti.merge(obs_gti.tstart(), obs_gti.tstop()) # increment global livetime and ontime ontime += obs.ontime() @@ -340,25 +338,25 @@ class csobsinfo(ctools.cscript): # Log energy range self.log.header3("Energy range") self.log.parformat("Emin") - if ebounds.size() == 0: + if self.ebounds.size() == 0: self.log("undefined") else: - self.log(str(ebounds.emin())) + self.log(str(self.ebounds.emin())) self.log("\n") self.log.parformat("Emax") - if ebounds.size() == 0: + if self.ebounds.size() == 0: self.log("undefined") else: - self.log(str(ebounds.emax())) + self.log(str(self.ebounds.emax())) self.log("\n\n") # Log time range self.log.header3("Time range") self.log.parformat("Start [MJD]") - self.log(str(gti.tstart().mjd())) + self.log(str(self.gti.tstart().mjd())) self.log("\n") self.log.parformat("Stop [MJD]") - self.log(str(gti.tstop().mjd())) + self.log(str(self.gti.tstop().mjd())) self.log("\n") # Log ontime and livetime in different units @@ -422,7 +420,18 @@ class csobsinfo(ctools.cscript): Return offset angles """ return self.offsets - + + def ebounds(self): + """ + Return energy boundaries + """ + return self.ebounds + + def gti(self): + """ + Return good time intervals + """ + return self.gti def execute(self): """ diff --git a/doc/source/reference_manual/csobsinfo.rst b/doc/source/reference_manual/csobsinfo.rst new file mode 100644 index 0000000..df9399a --- /dev/null +++ b/doc/source/reference_manual/csobsinfo.rst @@ -0,0 +1,85 @@ +.. _csobsinfo: + +csobsinfo +====== + +Dumps information about an observation container into log file or on screen + + +Synopsis +-------- + +This script provides detailled information about a given observation container. +For IACT observations usually several observations with different +configurations are combined. The script computes e.g. the overall energy +range which could be an important input for :doc:`ctbin` to create a suitable +energy range. In addition the script prints the pointing attributes like the average +zenith/azimuth angle. If the hidden boolean parameter "offset" is specified to "yes", +the script queries for the target position and computes the run-by-run offset as well +as its average. In the observation summary, the time range of the observations including +total ontime and (dead-time corrected) livetime is shown. + +The script further contains the hidden parameter "ds9file". If specified with a file +name, the tool writes out a ds9 region file including a cross for each pointing position +in the sky. + +When executed from within python, the script provides methods to return arrays containing +observation-wise parameters. This might be useful for graphical display within a script. The +following methods are implemented: +- zeniths (returning all zenith angles) +- azimuths (returning all azimuth angles) +- offsets (returning all offset angles, provided the hidden parameter offset=yes) +- ebounds (returning energy boundaries) +- gtis (returning good time intervals) + + +General parameters +------------------ + +``inobs [file]`` + Event list, counts cube, or observation definition file + +``(offset = no) [file]`` + Compute offset from target to pointing positions + +``ra [real]`` + Target right ascension for offset computation (only queried if offset=yes) + +``dec [real]`` + Target declination for offset computation (only queried if offset=yes) + +``(ds9file = NONE) [file]`` + DS9 region file containing pointings + + +Standard parameters +------------------- + +``(chatter = 2) [integer]`` + Verbosity of the executable: + chatter = 0: no information will be logged + + chatter = 1: only errors will be logged + + chatter = 2: errors and actions will be logged + + chatter = 3: report about the task execution + + chatter = 4: detailed report about the task execution + +``(clobber = yes) [boolean]`` + Specifies whether an existing output counts cube should be overwritten. + +``(debug = no) [boolean]`` + Enables debug mode. In debug mode the executable will dump any log file output to the console. + +``(mode = ql) [string]`` + Mode of automatic parameters (default is "ql", i.e. "query and learn"). + +``(logfile = cssens.log) [filename]`` + Log filename. + + +Related tools or scripts +------------------------ + diff --git a/test/test_cscripts.sh.in b/test/test_cscripts.sh.in index 628c16e..ab5c68c 100755 --- a/test/test_cscripts.sh.in +++ b/test/test_cscripts.sh.in @@ -36,7 +36,7 @@ $ECHO "*****************" # # Remove any existing result files # ================================ -rm -rf *.fits *.xml *.dat +rm -rf *.fits *.xml *.dat *.reg # @@ -74,6 +74,28 @@ $ECHO " ok" # +# Test csobsinfo +# ============== +$ECHO -n "Test csobsinfo: " +chmod +x @abs_top_srcdir@/cscripts/csobsinfo.py +@abs_top_srcdir@/cscripts/csobsinfo.py \ + inobs="obs.xml" \ + ds9file="ds9.reg" \ + offset=yes \ + ra="83.6331" \ + dec="22.01" > csobsinfo.log +$ECHO -n "." +if [ -s "ds9.reg" ] +then + $ECHO -n "." +else + $ECHO " ds9.reg file is not valid" + exit 1 +fi +$ECHO " ok" + + +# # Test cspull # =========== $ECHO -n "Test cspull: " -- libgit2 0.21.4