diff --git a/.gitignore b/.gitignore index be454c1..09b0d28 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ src/ctbutterfly/ctbutterfly src/ctulimit/ctulimit src/cterror/cterror test/pfiles/ +test/caldb/ test/*.fits test/*.dat test/*.xml diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am index be46fe5..7fa4e3d 100644 --- a/cscripts/Makefile.am +++ b/cscripts/Makefile.am @@ -12,8 +12,8 @@ pythonscripts = __init__.py \ # Scripts for which symbolic links will be created in bindir linkscripts = cspull cssens cstsdist cscaldb csresmap \ - cshessobs csobsdef csspec cslightcrv csobs2caldb \ - csinfo + cshessobs csobsdef csspec cslightcrv \ + csinfo csobs2caldb # Distribute scripts EXTRA_DIST = $(binscripts) $(pythonscripts) diff --git a/cscripts/csobs2caldb.py b/cscripts/csobs2caldb.py index 2c4df80..13b43cc 100755 --- a/cscripts/csobs2caldb.py +++ b/cscripts/csobs2caldb.py @@ -25,15 +25,16 @@ import os import datetime -# =============== # -# cshessobs class # -# =============== # +# ================= # +# csobs2caldb class # +# ================= # class csobs2caldb(ctools.cscript): """ - This class implements the creation of a caldb entry for a particular observation, - which might be helpful for running simulations for current IACTs. - It takes an observation definition file as input and uses the first observation - to create a caldb entry which can be used for simulations and sensitivity studies later on + This class implements the creation of a caldb entry for a particular + observation, which might be helpful for running simulations for current + IACTs. It takes an observation definition file as input and uses the + first observation to create a caldb entry which can be used for + simulations and sensitivity studies later on. """ def __init__(self, *argv): """ @@ -41,7 +42,7 @@ class csobs2caldb(ctools.cscript): """ # Set name self.name = "csobs2caldb" - self.version = "0.1.0" + self.version = "1.1.0" # Make sure that parfile exists file = self.parfile() @@ -71,7 +72,8 @@ class csobs2caldb(ctools.cscript): def parfile(self): """ Check if parfile exists. If parfile does not exist then create a - default parfile. This kluge avoids shipping the cscript with a parfile. + default parfile. This kluge avoids shipping the cscript with a + parfile. """ # Set parfile name @@ -102,7 +104,7 @@ class csobs2caldb(ctools.cscript): """ # Get parameters self.inobs = self["inobs"].filename() - self.obs = gammalib.GObservations(self.inobs) + self.obs = gammalib.GObservations(self.inobs) # Get index of observation to be used (0=default) inx = self["index"].integer() @@ -135,7 +137,6 @@ class csobs2caldb(ctools.cscript): # Return return - def make_irf_file(self): # retrieve response component @@ -145,10 +146,10 @@ class csobs2caldb(ctools.cscript): fits = gammalib.GFits() # Open FITS files of response components - fits_aeff = gammalib.GFits(rsp.aeff().filename()) - fits_psf = gammalib.GFits(rsp.psf().filename()) + fits_aeff = gammalib.GFits(rsp.aeff().filename()) + fits_psf = gammalib.GFits(rsp.psf().filename()) fits_edisp = gammalib.GFits(rsp.edisp().filename()) - fits_bkg = gammalib.GFits(rsp.background().filename()) + fits_bkg = gammalib.GFits(rsp.background().filename()) # Bundle IRFs into one file fits.append(fits_aeff["EFFECTIVE AREA"]) @@ -159,7 +160,6 @@ class csobs2caldb(ctools.cscript): # Return fits file return fits - def make_caldb_index(self): # Open calibration database index @@ -227,6 +227,7 @@ class csobs2caldb(ctools.cscript): # Set row number row = i + row_index-4 + # Set date now = str(datetime.datetime.now()) today, time = now.split() @@ -242,10 +243,10 @@ class csobs2caldb(ctools.cscript): table["CAL_VST"][row] = time.split(".")[0] table["REF_TIME"][row] = 51544.0 table["CAL_QUAL"][row] = 0 - table["CAL_CBD"][row] = "NAME("+self.m_rspname+")" + table["CAL_CBD"][row] = "NAME("+self.m_rspname+")" table["CAL_DATE"][row] = today.replace("-","/")[2:] - table["CAL_DIR"][row] = self.cal_dir - table["CAL_FILE"][row] = self.m_outfile + table["CAL_DIR"][row] = self.cal_dir + table["CAL_FILE"][row] = self.m_outfile # Add effective area information row = row_index-4 @@ -269,7 +270,6 @@ class csobs2caldb(ctools.cscript): # Return CIF FITS file return cif - def make_dirs(self): @@ -293,17 +293,19 @@ class csobs2caldb(ctools.cscript): # Create directories and log information if not os.path.isdir(self.rsp_dir): if self.logExplicit(): - self.header3("Creating directory \""+self.rsp_dir+"\"") + self.log(gammalib.parformat("Directory")) + self.log(self.rsp_dir) + self.log("\n") os.makedirs(self.rsp_dir) else: if self.logExplicit(): - self.log("Directory \""+self.rsp_dir+"\" already exists\n") + self.log(gammalib.parformat("Directory (existing)")) + self.log(self.rsp_dir) self.log("\n") # Return return - - + def run(self): """ Run the script. @@ -318,25 +320,24 @@ class csobs2caldb(ctools.cscript): # Write input parameters into logger if self.logTerse(): self.log_parameters() - self.log("\n") + self.log("\n\n") self.log.header1("Creating directory structure") - self.log("\n") # Create directory structure self.make_dirs() # Logging if self.logTerse(): - self.log.header1("Updating calibration database") self.log("\n") + self.log.header1("Updating calibration database") # Create/update calibration database self.caldb_inx = self.make_caldb_index() # Logging if self.logTerse(): - self.log.header1("Creating response file") self.log("\n") + self.log.header1("Creating response file") # Create IRF file self.irf_fits = self.make_irf_file() @@ -368,6 +369,7 @@ class csobs2caldb(ctools.cscript): # Return return + # ======================== # # Main routine entry point # # ======================== # diff --git a/doc/source/reference_manual/csob2caldb.rst b/doc/source/reference_manual/csob2caldb.rst deleted file mode 100644 index a129285..0000000 --- a/doc/source/reference_manual/csob2caldb.rst +++ /dev/null @@ -1 +0,0 @@ -.. _csobs2caldb: csobs2caldb ======= Creates an calibration database entry from an input observation definition file. Synopsis -------- This scripts creates a calibration database entry from an input observation container. The caldb entry can be used for simulations later on. The script further takes the name of the respone as input, which allows the user to specify a generic name for this kind of observation. An example could be 'zenith50_azimuth0' referring to the parameter characterising the IRFs. In order to check the available caldb entries, the use of the cscaldb script is recommended afterwards General parameters ------------------ ``inobs [file]`` Input observation definition XML file. ``rspname [string]`` Response output name (e.g. Zenith50) ``(outfile = irf_file.fits) [file]`` Output IRF file name ``(index = 0) [integer]`` Index of observation to be used from XML file 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 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"). Related tools ------------- cscaldb \ No newline at end of file diff --git a/doc/source/reference_manual/csobs2caldb.rst b/doc/source/reference_manual/csobs2caldb.rst index 0dfa3e7..d97e572 100644 --- a/doc/source/reference_manual/csobs2caldb.rst +++ b/doc/source/reference_manual/csobs2caldb.rst @@ -1,9 +1,9 @@ .. _csobs2caldb: csobs2caldb -========== +=========== -Creates a caldb entry from an input observation +Creates a caldb entry from an input observation. Synopsis @@ -13,7 +13,7 @@ This script creates an entry in the local calibration database from an input observation container. The caldb entry can be used for simulations with :doc:`ctobssim` later on. On default csobs2caldb uses the first observation in the given container. This can be modified using the hidden parameter "index" -(e.g. index=3) instructs the tool to use the third observation in the container. +(e.g. index=3 instructs the tool to use the third observation in the container). Note that for the moment, the script only works for unbinned observations which use the latest CTA IRF format (i.e. 2D/3D FITS binary tables). diff --git a/doc/source/reference_manual/index.rst b/doc/source/reference_manual/index.rst index 2515750..0202ca9 100644 --- a/doc/source/reference_manual/index.rst +++ b/doc/source/reference_manual/index.rst @@ -45,4 +45,4 @@ cscripts csspec --- Computes spectral points csresmap --- Generates residual map cstsdist --- Generates TS distribution - csobs2caldb --- Creates a entry from an input observation + csobs2caldb --- Creates a caldb entry from an input observation diff --git a/test/data/obs_unbinned.xml b/test/data/obs_unbinned.xml index 79fb549..4adfdbb 100644 --- a/test/data/obs_unbinned.xml +++ b/test/data/obs_unbinned.xml @@ -1,10 +1,10 @@ - - - - - + + + + + diff --git a/test/irf/irf_file.fits.gz b/test/irf/irf_file.fits.gz new file mode 100644 index 0000000..e9e0aa4 --- /dev/null +++ b/test/irf/irf_file.fits.gz diff --git a/test/test_cscripts.sh.in b/test/test_cscripts.sh.in index 234166b..5efb2f4 100755 --- a/test/test_cscripts.sh.in +++ b/test/test_cscripts.sh.in @@ -42,11 +42,13 @@ rm -rf *.fits *.xml *.dat # # Creates pfiles directory # ======================== -rm -rf pfiles -mkdir -p pfiles -cp -r ../src/*/*.par pfiles/ export PFILES=pfiles -export CALDB=$PWD +export CALDB=$PWD/caldb +rm -rf $PFILES +mkdir -p $PFILES +cp -r ../src/*/*.par pfiles/ +rm -rf $CALDB +mkdir -p $CALDB # # Test csobsdef @@ -80,7 +82,7 @@ chmod +x @abs_top_srcdir@/cscripts/csobs2caldb.py @abs_top_srcdir@/cscripts/csobs2caldb.py \ inobs="data/obs_unbinned.xml" \ rspname="test_irfs" \ - chatter=4 > csobs2caldb.log + chatter=4 #> csobs2caldb.log $ECHO -n "." if [ -s "$CALDB/data/cta/cta/bcf/test_irfs/irf_file.fits" ] then