Commit 22bfe352f87f68ab6c7be3858a2bf1968db45379

Authored by Jürgen Knödlseder
1 parent bfbc70b3

Integrate code.

.gitignore
@@ -63,6 +63,7 @@ src/ctbutterfly/ctbutterfly @@ -63,6 +63,7 @@ src/ctbutterfly/ctbutterfly
63 src/ctulimit/ctulimit 63 src/ctulimit/ctulimit
64 src/cterror/cterror 64 src/cterror/cterror
65 test/pfiles/ 65 test/pfiles/
  66 +test/caldb/
66 test/*.fits 67 test/*.fits
67 test/*.dat 68 test/*.dat
68 test/*.xml 69 test/*.xml
cscripts/Makefile.am
@@ -12,8 +12,8 @@ pythonscripts = __init__.py \ @@ -12,8 +12,8 @@ pythonscripts = __init__.py \
12 12
13 # Scripts for which symbolic links will be created in bindir 13 # Scripts for which symbolic links will be created in bindir
14 linkscripts = cspull cssens cstsdist cscaldb csresmap \ 14 linkscripts = cspull cssens cstsdist cscaldb csresmap \
15 - cshessobs csobsdef csspec cslightcrv csobs2caldb \  
16 - csinfo 15 + cshessobs csobsdef csspec cslightcrv \
  16 + csinfo csobs2caldb
17 17
18 # Distribute scripts 18 # Distribute scripts
19 EXTRA_DIST = $(binscripts) $(pythonscripts) 19 EXTRA_DIST = $(binscripts) $(pythonscripts)
cscripts/csobs2caldb.py
@@ -25,15 +25,16 @@ import os @@ -25,15 +25,16 @@ import os
25 import datetime 25 import datetime
26 26
27 27
28 -# =============== #  
29 -# cshessobs class #  
30 -# =============== # 28 +# ================= #
  29 +# csobs2caldb class #
  30 +# ================= #
31 class csobs2caldb(ctools.cscript): 31 class csobs2caldb(ctools.cscript):
32 """ 32 """
33 - This class implements the creation of a caldb entry for a particular observation,  
34 - which might be helpful for running simulations for current IACTs.  
35 - It takes an observation definition file as input and uses the first observation  
36 - to create a caldb entry which can be used for simulations and sensitivity studies later on 33 + This class implements the creation of a caldb entry for a particular
  34 + observation, which might be helpful for running simulations for current
  35 + IACTs. It takes an observation definition file as input and uses the
  36 + first observation to create a caldb entry which can be used for
  37 + simulations and sensitivity studies later on.
37 """ 38 """
38 def __init__(self, *argv): 39 def __init__(self, *argv):
39 """ 40 """
@@ -41,7 +42,7 @@ class csobs2caldb(ctools.cscript): @@ -41,7 +42,7 @@ class csobs2caldb(ctools.cscript):
41 """ 42 """
42 # Set name 43 # Set name
43 self.name = "csobs2caldb" 44 self.name = "csobs2caldb"
44 - self.version = "0.1.0" 45 + self.version = "1.1.0"
45 46
46 # Make sure that parfile exists 47 # Make sure that parfile exists
47 file = self.parfile() 48 file = self.parfile()
@@ -71,7 +72,8 @@ class csobs2caldb(ctools.cscript): @@ -71,7 +72,8 @@ class csobs2caldb(ctools.cscript):
71 def parfile(self): 72 def parfile(self):
72 """ 73 """
73 Check if parfile exists. If parfile does not exist then create a 74 Check if parfile exists. If parfile does not exist then create a
74 - default parfile. This kluge avoids shipping the cscript with a parfile. 75 + default parfile. This kluge avoids shipping the cscript with a
  76 + parfile.
75 """ 77 """
76 78
77 # Set parfile name 79 # Set parfile name
@@ -102,7 +104,7 @@ class csobs2caldb(ctools.cscript): @@ -102,7 +104,7 @@ class csobs2caldb(ctools.cscript):
102 """ 104 """
103 # Get parameters 105 # Get parameters
104 self.inobs = self["inobs"].filename() 106 self.inobs = self["inobs"].filename()
105 - self.obs = gammalib.GObservations(self.inobs) 107 + self.obs = gammalib.GObservations(self.inobs)
106 108
107 # Get index of observation to be used (0=default) 109 # Get index of observation to be used (0=default)
108 inx = self["index"].integer() 110 inx = self["index"].integer()
@@ -135,7 +137,6 @@ class csobs2caldb(ctools.cscript): @@ -135,7 +137,6 @@ class csobs2caldb(ctools.cscript):
135 # Return 137 # Return
136 return 138 return
137 139
138 -  
139 def make_irf_file(self): 140 def make_irf_file(self):
140 141
141 # retrieve response component 142 # retrieve response component
@@ -145,10 +146,10 @@ class csobs2caldb(ctools.cscript): @@ -145,10 +146,10 @@ class csobs2caldb(ctools.cscript):
145 fits = gammalib.GFits() 146 fits = gammalib.GFits()
146 147
147 # Open FITS files of response components 148 # Open FITS files of response components
148 - fits_aeff = gammalib.GFits(rsp.aeff().filename())  
149 - fits_psf = gammalib.GFits(rsp.psf().filename()) 149 + fits_aeff = gammalib.GFits(rsp.aeff().filename())
  150 + fits_psf = gammalib.GFits(rsp.psf().filename())
150 fits_edisp = gammalib.GFits(rsp.edisp().filename()) 151 fits_edisp = gammalib.GFits(rsp.edisp().filename())
151 - fits_bkg = gammalib.GFits(rsp.background().filename()) 152 + fits_bkg = gammalib.GFits(rsp.background().filename())
152 153
153 # Bundle IRFs into one file 154 # Bundle IRFs into one file
154 fits.append(fits_aeff["EFFECTIVE AREA"]) 155 fits.append(fits_aeff["EFFECTIVE AREA"])
@@ -159,7 +160,6 @@ class csobs2caldb(ctools.cscript): @@ -159,7 +160,6 @@ class csobs2caldb(ctools.cscript):
159 # Return fits file 160 # Return fits file
160 return fits 161 return fits
161 162
162 -  
163 def make_caldb_index(self): 163 def make_caldb_index(self):
164 164
165 # Open calibration database index 165 # Open calibration database index
@@ -227,6 +227,7 @@ class csobs2caldb(ctools.cscript): @@ -227,6 +227,7 @@ class csobs2caldb(ctools.cscript):
227 # Set row number 227 # Set row number
228 row = i + row_index-4 228 row = i + row_index-4
229 229
  230 + # Set date
230 now = str(datetime.datetime.now()) 231 now = str(datetime.datetime.now())
231 today, time = now.split() 232 today, time = now.split()
232 233
@@ -242,10 +243,10 @@ class csobs2caldb(ctools.cscript): @@ -242,10 +243,10 @@ class csobs2caldb(ctools.cscript):
242 table["CAL_VST"][row] = time.split(".")[0] 243 table["CAL_VST"][row] = time.split(".")[0]
243 table["REF_TIME"][row] = 51544.0 244 table["REF_TIME"][row] = 51544.0
244 table["CAL_QUAL"][row] = 0 245 table["CAL_QUAL"][row] = 0
245 - table["CAL_CBD"][row] = "NAME("+self.m_rspname+")" 246 + table["CAL_CBD"][row] = "NAME("+self.m_rspname+")"
246 table["CAL_DATE"][row] = today.replace("-","/")[2:] 247 table["CAL_DATE"][row] = today.replace("-","/")[2:]
247 - table["CAL_DIR"][row] = self.cal_dir  
248 - table["CAL_FILE"][row] = self.m_outfile 248 + table["CAL_DIR"][row] = self.cal_dir
  249 + table["CAL_FILE"][row] = self.m_outfile
249 250
250 # Add effective area information 251 # Add effective area information
251 row = row_index-4 252 row = row_index-4
@@ -269,7 +270,6 @@ class csobs2caldb(ctools.cscript): @@ -269,7 +270,6 @@ class csobs2caldb(ctools.cscript):
269 270
270 # Return CIF FITS file 271 # Return CIF FITS file
271 return cif 272 return cif
272 -  
273 273
274 def make_dirs(self): 274 def make_dirs(self):
275 275
@@ -293,17 +293,19 @@ class csobs2caldb(ctools.cscript): @@ -293,17 +293,19 @@ class csobs2caldb(ctools.cscript):
293 # Create directories and log information 293 # Create directories and log information
294 if not os.path.isdir(self.rsp_dir): 294 if not os.path.isdir(self.rsp_dir):
295 if self.logExplicit(): 295 if self.logExplicit():
296 - self.header3("Creating directory \""+self.rsp_dir+"\"") 296 + self.log(gammalib.parformat("Directory"))
  297 + self.log(self.rsp_dir)
  298 + self.log("\n")
297 os.makedirs(self.rsp_dir) 299 os.makedirs(self.rsp_dir)
298 else: 300 else:
299 if self.logExplicit(): 301 if self.logExplicit():
300 - self.log("Directory \""+self.rsp_dir+"\" already exists\n") 302 + self.log(gammalib.parformat("Directory (existing)"))
  303 + self.log(self.rsp_dir)
301 self.log("\n") 304 self.log("\n")
302 305
303 # Return 306 # Return
304 return 307 return
305 -  
306 - 308 +
307 def run(self): 309 def run(self):
308 """ 310 """
309 Run the script. 311 Run the script.
@@ -318,25 +320,24 @@ class csobs2caldb(ctools.cscript): @@ -318,25 +320,24 @@ class csobs2caldb(ctools.cscript):
318 # Write input parameters into logger 320 # Write input parameters into logger
319 if self.logTerse(): 321 if self.logTerse():
320 self.log_parameters() 322 self.log_parameters()
321 - self.log("\n") 323 + self.log("\n\n")
322 self.log.header1("Creating directory structure") 324 self.log.header1("Creating directory structure")
323 - self.log("\n")  
324 325
325 # Create directory structure 326 # Create directory structure
326 self.make_dirs() 327 self.make_dirs()
327 328
328 # Logging 329 # Logging
329 if self.logTerse(): 330 if self.logTerse():
330 - self.log.header1("Updating calibration database")  
331 self.log("\n") 331 self.log("\n")
  332 + self.log.header1("Updating calibration database")
332 333
333 # Create/update calibration database 334 # Create/update calibration database
334 self.caldb_inx = self.make_caldb_index() 335 self.caldb_inx = self.make_caldb_index()
335 336
336 # Logging 337 # Logging
337 if self.logTerse(): 338 if self.logTerse():
338 - self.log.header1("Creating response file")  
339 self.log("\n") 339 self.log("\n")
  340 + self.log.header1("Creating response file")
340 341
341 # Create IRF file 342 # Create IRF file
342 self.irf_fits = self.make_irf_file() 343 self.irf_fits = self.make_irf_file()
@@ -368,6 +369,7 @@ class csobs2caldb(ctools.cscript): @@ -368,6 +369,7 @@ class csobs2caldb(ctools.cscript):
368 # Return 369 # Return
369 return 370 return
370 371
  372 +
371 # ======================== # 373 # ======================== #
372 # Main routine entry point # 374 # Main routine entry point #
373 # ======================== # 375 # ======================== #
doc/source/reference_manual/csob2caldb.rst deleted
1 -.. _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  
2 \ No newline at end of file 0 \ No newline at end of file
doc/source/reference_manual/csobs2caldb.rst
1 .. _csobs2caldb: 1 .. _csobs2caldb:
2 2
3 csobs2caldb 3 csobs2caldb
4 -========== 4 +===========
5 5
6 -Creates a caldb entry from an input observation 6 +Creates a caldb entry from an input observation.
7 7
8 8
9 Synopsis 9 Synopsis
@@ -13,7 +13,7 @@ This script creates an entry in the local calibration database from an @@ -13,7 +13,7 @@ This script creates an entry in the local calibration database from an
13 input observation container. The caldb entry can be used for simulations 13 input observation container. The caldb entry can be used for simulations
14 with :doc:`ctobssim` later on. On default csobs2caldb uses the first observation 14 with :doc:`ctobssim` later on. On default csobs2caldb uses the first observation
15 in the given container. This can be modified using the hidden parameter "index" 15 in the given container. This can be modified using the hidden parameter "index"
16 -(e.g. index=3) instructs the tool to use the third observation in the container. 16 +(e.g. index=3 instructs the tool to use the third observation in the container).
17 Note that for the moment, the script only works for unbinned observations which 17 Note that for the moment, the script only works for unbinned observations which
18 use the latest CTA IRF format (i.e. 2D/3D FITS binary tables). 18 use the latest CTA IRF format (i.e. 2D/3D FITS binary tables).
19 19
doc/source/reference_manual/index.rst
@@ -45,4 +45,4 @@ cscripts @@ -45,4 +45,4 @@ cscripts
45 csspec --- Computes spectral points <csspec> 45 csspec --- Computes spectral points <csspec>
46 csresmap --- Generates residual map <csresmap> 46 csresmap --- Generates residual map <csresmap>
47 cstsdist --- Generates TS distribution <cstsdist> 47 cstsdist --- Generates TS distribution <cstsdist>
48 - csobs2caldb --- Creates a <caldb> entry from an input observation 48 + csobs2caldb --- Creates a caldb entry from an input observation <csobs2caldb>
test/data/obs_unbinned.xml
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <observation_list title="observation list"> 2 <observation_list title="observation list">
3 <observation name="" id="00001" instrument="CTA"> 3 <observation name="" id="00001" instrument="CTA">
4 - <parameter name="EventList" file="${CTOOLS}/test/data/crab_events.fits.gz" />  
5 - <parameter name="EffectiveArea" file="${CTOOLS}/share/caldb/data/cta/prod2/bcf/South_50h/irf_file.fits.gz" />  
6 - <parameter name="PointSpreadFunction" file="${CTOOLS}/share/caldb/data/cta/prod2/bcf/South_50h/irf_file.fits.gz" />  
7 - <parameter name="EnergyDispersion" file="${CTOOLS}/share/caldb/data/cta/prod2/bcf/South_50h/irf_file.fits.gz" />  
8 - <parameter name="Background" file="${CTOOLS}/share/caldb/data/cta/prod2/bcf/South_50h/irf_file.fits.gz" /> 4 + <parameter name="EventList" file="data/crab_events.fits" />
  5 + <parameter name="EffectiveArea" file="irf/irf_file.fits" />
  6 + <parameter name="PointSpreadFunction" file="irf/irf_file.fits" />
  7 + <parameter name="EnergyDispersion" file="irf/irf_file.fits" />
  8 + <parameter name="Background" file="irf/irf_file.fits" />
9 </observation> 9 </observation>
10 </observation_list> 10 </observation_list>
test/irf/irf_file.fits.gz 0 → 100644
No preview for this file type
test/test_cscripts.sh.in
@@ -42,11 +42,13 @@ rm -rf *.fits *.xml *.dat @@ -42,11 +42,13 @@ rm -rf *.fits *.xml *.dat
42 # 42 #
43 # Creates pfiles directory 43 # Creates pfiles directory
44 # ======================== 44 # ========================
45 -rm -rf pfiles  
46 -mkdir -p pfiles  
47 -cp -r ../src/*/*.par pfiles/  
48 export PFILES=pfiles 45 export PFILES=pfiles
49 -export CALDB=$PWD 46 +export CALDB=$PWD/caldb
  47 +rm -rf $PFILES
  48 +mkdir -p $PFILES
  49 +cp -r ../src/*/*.par pfiles/
  50 +rm -rf $CALDB
  51 +mkdir -p $CALDB
50 52
51 # 53 #
52 # Test csobsdef 54 # Test csobsdef
@@ -80,7 +82,7 @@ chmod +x @abs_top_srcdir@/cscripts/csobs2caldb.py @@ -80,7 +82,7 @@ chmod +x @abs_top_srcdir@/cscripts/csobs2caldb.py
80 @abs_top_srcdir@/cscripts/csobs2caldb.py \ 82 @abs_top_srcdir@/cscripts/csobs2caldb.py \
81 inobs="data/obs_unbinned.xml" \ 83 inobs="data/obs_unbinned.xml" \
82 rspname="test_irfs" \ 84 rspname="test_irfs" \
83 - chatter=4 > csobs2caldb.log 85 + chatter=4 #> csobs2caldb.log
84 $ECHO -n "." 86 $ECHO -n "."
85 if [ -s "$CALDB/data/cta/cta/bcf/test_irfs/irf_file.fits" ] 87 if [ -s "$CALDB/data/cta/cta/bcf/test_irfs/irf_file.fits" ]
86 then 88 then