Commit 7cdc1b2e51ed610daaef1ef9eba271380ba8d94e
1 parent
2c013235
Added unit test, reference manual entry for csobs2caldb
Showing
4 changed files
with
108 additions
and
6 deletions
cscripts/csobs2caldb.py
| @@ -87,7 +87,7 @@ class csobs2caldb(ctools.cscript): | @@ -87,7 +87,7 @@ class csobs2caldb(ctools.cscript): | ||
| 87 | pars = gammalib.GApplicationPars() | 87 | pars = gammalib.GApplicationPars() |
| 88 | pars.append(gammalib.GApplicationPar("inobs","f","a","obs.xml","","","Input observation definition file")) | 88 | pars.append(gammalib.GApplicationPar("inobs","f","a","obs.xml","","","Input observation definition file")) |
| 89 | pars.append(gammalib.GApplicationPar("rspname","s","a","NONE","","","Response output name (e.g. Zenith50)")) | 89 | pars.append(gammalib.GApplicationPar("rspname","s","a","NONE","","","Response output name (e.g. Zenith50)")) |
| 90 | - pars.append(gammalib.GApplicationPar("outfile","f","h","irf_file.fits","","","Output IRF file name")) | 90 | + pars.append(gammalib.GApplicationPar("outirfs","f","h","irf_file.fits","","","Output IRF file name")) |
| 91 | pars.append(gammalib.GApplicationPar("index","i","h","0","","","Index of observation to be used from XML file")) | 91 | pars.append(gammalib.GApplicationPar("index","i","h","0","","","Index of observation to be used from XML file")) |
| 92 | pars.append_standard() | 92 | pars.append_standard() |
| 93 | pars.append(gammalib.GApplicationPar("logfile","f","h","csobs2caldb.log","","","Log filename")) | 93 | pars.append(gammalib.GApplicationPar("logfile","f","h","csobs2caldb.log","","","Log filename")) |
| @@ -119,7 +119,7 @@ class csobs2caldb(ctools.cscript): | @@ -119,7 +119,7 @@ class csobs2caldb(ctools.cscript): | ||
| 119 | 119 | ||
| 120 | # Get config and file name | 120 | # Get config and file name |
| 121 | self.m_rspname = self["rspname"].string() | 121 | self.m_rspname = self["rspname"].string() |
| 122 | - self.m_outfile = self["outfile"].filename() | 122 | + self.m_outfile = self["outirfs"].filename() |
| 123 | 123 | ||
| 124 | # Make sure we have a cta observation | 124 | # Make sure we have a cta observation |
| 125 | if not self.observation.classname() == "GCTAObservation": | 125 | if not self.observation.classname() == "GCTAObservation": |
| @@ -141,6 +141,9 @@ class csobs2caldb(ctools.cscript): | @@ -141,6 +141,9 @@ class csobs2caldb(ctools.cscript): | ||
| 141 | # retrieve response component | 141 | # retrieve response component |
| 142 | rsp = self.observation.response() | 142 | rsp = self.observation.response() |
| 143 | 143 | ||
| 144 | + # Initialise FITS file | ||
| 145 | + fits = gammalib.GFits() | ||
| 146 | + | ||
| 144 | # Open FITS files of response components | 147 | # Open FITS files of response components |
| 145 | fits_aeff = gammalib.GFits(rsp.aeff().filename()) | 148 | fits_aeff = gammalib.GFits(rsp.aeff().filename()) |
| 146 | fits_psf = gammalib.GFits(rsp.psf().filename()) | 149 | fits_psf = gammalib.GFits(rsp.psf().filename()) |
| @@ -148,7 +151,6 @@ class csobs2caldb(ctools.cscript): | @@ -148,7 +151,6 @@ class csobs2caldb(ctools.cscript): | ||
| 148 | fits_bkg = gammalib.GFits(rsp.background().filename()) | 151 | fits_bkg = gammalib.GFits(rsp.background().filename()) |
| 149 | 152 | ||
| 150 | # Bundle IRFs into one file | 153 | # Bundle IRFs into one file |
| 151 | - fits = gammalib.GFits() | ||
| 152 | fits.append(fits_aeff["EFFECTIVE AREA"]) | 154 | fits.append(fits_aeff["EFFECTIVE AREA"]) |
| 153 | fits.append(fits_psf["POINT SPREAD FUNCTION"]) | 155 | fits.append(fits_psf["POINT SPREAD FUNCTION"]) |
| 154 | fits.append(fits_edisp["ENERGY DISPERSION"]) | 156 | fits.append(fits_edisp["ENERGY DISPERSION"]) |
doc/source/reference_manual/csobs2caldb.rst
0 → 100644
| 1 | +.. _csobs2caldb: | ||
| 2 | + | ||
| 3 | +csobs2caldb | ||
| 4 | +========== | ||
| 5 | + | ||
| 6 | +Creates a caldb entry from an input observation | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +Synopsis | ||
| 10 | +-------- | ||
| 11 | + | ||
| 12 | +This script creates an entry in the local calibration database from an | ||
| 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 | ||
| 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. | ||
| 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). | ||
| 19 | + | ||
| 20 | +In particular this script might be useful for simulations of current IACT data. | ||
| 21 | +Provided a specific observation with IRFs e.g. at certain zenith/azimuth angle, | ||
| 22 | +the user can create a caldb entry using this tool and subsequently simulate e.g. | ||
| 23 | +50 hours using this configuration. | ||
| 24 | + | ||
| 25 | +General parameters | ||
| 26 | +------------------ | ||
| 27 | + | ||
| 28 | +``inobs [file]`` | ||
| 29 | + Input event list, counts cube or observation definition XML file. | ||
| 30 | + | ||
| 31 | +``rspname [string]`` | ||
| 32 | + Response output name (e.g. Zenith50). | ||
| 33 | + | ||
| 34 | +``(outirfs = irf_file.fits) [file]`` | ||
| 35 | + Output IRF file name. | ||
| 36 | + | ||
| 37 | +``(index = 0) [integer]`` | ||
| 38 | + Index of observation to be used from XML file. | ||
| 39 | + | ||
| 40 | + | ||
| 41 | +Standard parameters | ||
| 42 | +------------------- | ||
| 43 | + | ||
| 44 | +``(chatter = 2) [integer]`` | ||
| 45 | + Verbosity of the executable: | ||
| 46 | + chatter = 0: no information will be logged | ||
| 47 | + | ||
| 48 | + chatter = 1: only errors will be logged | ||
| 49 | + | ||
| 50 | + chatter = 2: errors and actions will be logged | ||
| 51 | + | ||
| 52 | + chatter = 3: report about the task execution | ||
| 53 | + | ||
| 54 | + chatter = 4: detailed report about the task execution | ||
| 55 | + | ||
| 56 | +``(clobber = yes) [boolean]`` | ||
| 57 | + Specifies whether an existing output counts cube should be overwritten. | ||
| 58 | + | ||
| 59 | +``(debug = no) [boolean]`` | ||
| 60 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | ||
| 61 | + | ||
| 62 | +``(mode = ql) [string]`` | ||
| 63 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | ||
| 64 | + | ||
| 65 | +``(logfile = csobs2caldb.log) [filename]`` | ||
| 66 | + Log filename. | ||
| 67 | + | ||
| 68 | + | ||
| 69 | +Related tools or scripts | ||
| 70 | +------------------------ | ||
| 71 | + | ||
| 72 | +:doc:`cscaldb` |
test/data/obs_unbinned.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| 2 | +<observation_list title="observation list"> | ||
| 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" /> | ||
| 9 | + </observation> | ||
| 10 | +</observation_list> |
test/test_cscripts.sh.in
| @@ -46,7 +46,7 @@ rm -rf pfiles | @@ -46,7 +46,7 @@ rm -rf pfiles | ||
| 46 | mkdir -p pfiles | 46 | mkdir -p pfiles |
| 47 | cp -r ../src/*/*.par pfiles/ | 47 | cp -r ../src/*/*.par pfiles/ |
| 48 | export PFILES=pfiles | 48 | export PFILES=pfiles |
| 49 | - | 49 | +export CALDB=$PWD |
| 50 | 50 | ||
| 51 | # | 51 | # |
| 52 | # Test csobsdef | 52 | # Test csobsdef |
| @@ -72,6 +72,24 @@ else | @@ -72,6 +72,24 @@ else | ||
| 72 | fi | 72 | fi |
| 73 | $ECHO " ok" | 73 | $ECHO " ok" |
| 74 | 74 | ||
| 75 | +# | ||
| 76 | +# Test csobs2caldb | ||
| 77 | +# ================ | ||
| 78 | +$ECHO -n "Test csobs2caldb: " | ||
| 79 | +chmod +x @abs_top_srcdir@/cscripts/csobs2caldb.py | ||
| 80 | +@abs_top_srcdir@/cscripts/csobs2caldb.py \ | ||
| 81 | + inobs="data/obs_unbinned.xml" \ | ||
| 82 | + rspname="test_irfs" \ | ||
| 83 | + chatter=4 > csobs2caldb.log | ||
| 84 | +$ECHO -n "." | ||
| 85 | +if [ -s "$CALDB/data/cta/cta/bcf/test_irfs/irf_file.fits" ] | ||
| 86 | +then | ||
| 87 | + $ECHO -n "." | ||
| 88 | +else | ||
| 89 | + $ECHO " $CALDB/data/cta/cta/bcf/test_irfs/irf_file.fits file is not valid" | ||
| 90 | + exit 1 | ||
| 91 | +fi | ||
| 92 | +$ECHO " ok" | ||
| 75 | 93 | ||
| 76 | # | 94 | # |
| 77 | # Test cspull | 95 | # Test cspull |
| @@ -82,8 +100,8 @@ chmod +x @abs_top_srcdir@/cscripts/cspull.py | @@ -82,8 +100,8 @@ chmod +x @abs_top_srcdir@/cscripts/cspull.py | ||
| 82 | inmodel="data/crab.xml" \ | 100 | inmodel="data/crab.xml" \ |
| 83 | outfile="pull.dat" \ | 101 | outfile="pull.dat" \ |
| 84 | ntrials="3" \ | 102 | ntrials="3" \ |
| 85 | - caldb="irf" \ | ||
| 86 | - irf="cta_dummy_irf" \ | 103 | + caldb="cta" \ |
| 104 | + irf="test_irfs" \ | ||
| 87 | ra=83.6331 \ | 105 | ra=83.6331 \ |
| 88 | dec=22.0145 \ | 106 | dec=22.0145 \ |
| 89 | emin=0.1 \ | 107 | emin=0.1 \ |