Commit 8c6691f42bf5b81fc36f24647bbad841077046a4

Authored by Jürgen Knödlseder
1 parent c057d371

Add csadd2caldb script

.gitignore
... ... @@ -83,6 +83,7 @@ src/template/ctool_obs
83 83 test/pfiles/
84 84 test/caldb/
85 85 test/prod3
  86 +test/csadd2caldb_*
86 87 test/csroot2caldb_*
87 88 test/csiactcopy_*
88 89 test/comobsbin_*
... ...
ChangeLog
1   -2021-06-25
  1 +2021-09-30
2 2  
3 3 * Version 2.0.0 released
4 4 ========================
5 5  
  6 + Add csadd2caldb script
6 7 Add restart of bisection in case of bad convergence in ctulimit
7 8 Add COMPTEL analysis scripts (#3738)
8 9 Add source counts constraints to cssens (#3668)
... ...
1 1 New Features and Important Changes in ctools 2.0.0
2 2  
3   -25 June 2021
  3 +30 September 2021
4 4  
5 5  
6 6 Introduction
... ... @@ -167,6 +167,12 @@ support - Support classes
167 167 Add stamping to ctool::save_event_list() method (#3662).
168 168  
169 169  
  170 +csadd2caldb - Adds CTA response function to calibration database
  171 +----------------------------------------------------------------
  172 +New script that was added to support the installation of prod5-v0.1 CTA response
  173 +functions into the calibration database.
  174 +
  175 +
170 176 csbkgmodel - Generate background model for 3D analysis
171 177 ------------------------------------------------------
172 178 None
... ...
README.md
1 1 ctools information
2 2 ==================
3   -* Version: 2.0.0.dev (25 June 2021)
  3 +* Version: 2.0.0.dev (30 September 2021)
4 4 * GammaLib dependency: 2.0.0.dev
5 5  
6 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/)
... ...
cscripts/Makefile.am
... ... @@ -21,6 +21,7 @@
21 21  
22 22 # Scripts to be distributed in $(pyexecdir)/cscripts
23 23 pythonscripts = $(top_builddir)/cscripts/__init__.py \
  24 + $(srcdir)/csadd2caldb.py \
24 25 $(srcdir)/csbkgmodel.py \
25 26 $(srcdir)/cscaldb.py \
26 27 $(srcdir)/csebins.py \
... ... @@ -60,7 +61,8 @@ pythonscripts = $(top_builddir)/cscripts/__init__.py \
60 61 $(srcdir)/mputils.py
61 62  
62 63 # Parfiles to be distributed in $(prefix)/syspfiles
63   -parfiles = $(srcdir)/csbkgmodel.par \
  64 +parfiles = $(srcdir)/csadd2caldb.par \
  65 + $(srcdir)/csbkgmodel.par \
64 66 $(srcdir)/cscaldb.par \
65 67 $(srcdir)/csebins.par \
66 68 $(srcdir)/cslightcrv.par \
... ... @@ -93,7 +95,8 @@ parfiles = $(srcdir)/csbkgmodel.par \
93 95 $(srcdir)/csiactobs.par
94 96  
95 97 # Scripts for which symbolic links will be created in bindir
96   -linkscripts = csbkgmodel \
  98 +linkscripts = csadd2caldb \
  99 + csbkgmodel \
97 100 cscaldb \
98 101 csebins \
99 102 csinfo \
... ... @@ -132,6 +135,7 @@ testscripts = $(srcdir)/tests/__init__.py \
132 135 $(top_srcdir)/test/test_python_cscripts.py \
133 136 $(top_srcdir)/test/test_cscript.py \
134 137 $(top_srcdir)/test/test_cscaldb.py \
  138 + $(top_srcdir)/test/test_csadd2caldb.py \
135 139 $(top_srcdir)/test/test_csbkgmodel.py \
136 140 $(top_srcdir)/test/test_csebins.py \
137 141 $(top_srcdir)/test/test_csfindobs.py \
... ... @@ -266,6 +270,9 @@ testiactevents = $(top_srcdir)/test/data/iactdata/events/irf_file.fits.gz \
266 270 $(top_srcdir)/test/data/iactdata/events/events_7.fits.gz \
267 271 $(top_srcdir)/test/data/iactdata/events/events_8.fits.gz
268 272  
  273 +# Test data to be distributed in $(pyexecdir)/cscripts/tests/data/prod5-v0.1
  274 +testprod501data = $(top_srcdir)/test/data/prod5-v0.1/CTA-Performance-prod5-v0.1-South-20deg.FITS.tar.gz
  275 +
269 276 # Install scripts, parfiles, test scripts and test data. Note that we don't
270 277 # need to prepend $(DESTDIR) here (not fully clear why, but that's the way
271 278 # it is)
... ... @@ -283,11 +290,13 @@ testiactdatadir = $(pyexecdir)/cscripts/tests/data/iactdata
283 290 testiactdata_DATA = $(testiactdata)
284 291 testiacteventsdir = $(pyexecdir)/cscripts/tests/data/iactdata/events
285 292 testiactevents_DATA = $(testiactevents)
  293 +testprod501dir = $(pyexecdir)/cscripts/tests/data/prod5-v0.1
  294 +testprod501_DATA = $(testprod501data)
286 295  
287 296 # Files to be distributed in the tar file
288 297 EXTRA_DIST = $(binscripts) $(pythonscripts) $(parfiles) \
289 298 $(testscripts) $(testdata) $(testiactdata) \
290   - $(testiactevents)
  299 + $(testiactevents) $(testprod501data)
291 300  
292 301 # Add install hook rule to create symbolic links to cscripts without .py in the bindir
293 302 install-data-hook:
... ...
cscripts/__init__.py.in
1 1 # ==========================================================================
2 2 # cscripts Python module
3 3 #
4   -# Copyright (C) 2015-2020 Juergen Knoedlseder
  4 +# Copyright (C) 2015-2021 Juergen Knoedlseder
5 5 #
6 6 # This program is free software: you can redistribute it and/or modify
7 7 # it under the terms of the GNU General Public License as published by
... ... @@ -24,6 +24,7 @@ cur_version = sys.version_info
24 24  
25 25 # List all scripts in this module
26 26 __all__ = [
  27 + "csadd2caldb",
27 28 "csbkgmodel",
28 29 "cscaldb",
29 30 "csebins",
... ... @@ -65,6 +66,7 @@ if cur_version > req_version:
65 66 "csiactobs"])
66 67  
67 68 # Import
  69 +from cscripts.csadd2caldb import csadd2caldb
68 70 from cscripts.csbkgmodel import csbkgmodel
69 71 from cscripts.cscaldb import cscaldb
70 72 from cscripts.csebins import csebins
... ...
cscripts/csadd2caldb.par 0 → 100755
  1 +#############################################################################
  2 +# #
  3 +# CTA Science Analysis Tools #
  4 +# #
  5 +# ------------------------------------------------------------------------- #
  6 +# #
  7 +# File: csadd2caldb.par #
  8 +# #
  9 +# Author: Juergen Knoedlseder #
  10 +# Jurgen.Knodlseder@irap.omp.eu #
  11 +# IRAP #
  12 +# #
  13 +# Purpose: Parameter file for the csadd2caldb script #
  14 +# #
  15 +#############################################################################
  16 +#
  17 +# Input and output parameters
  18 +#============================
  19 +indir, f, a, fits,,, "Input IRF folder"
  20 +outdir, f, a, $CALDB,,, "Output caldb folder"
  21 +
  22 +#
  23 +# Standard parameters
  24 +#====================
  25 +chatter, i, h, 2,0,4, "Chattiness of output"
  26 +clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
  27 +debug, b, h, no,,, "Activate debugging mode?"
  28 +mode, s, h, ql,,, "Mode of automatic parameters"
  29 +logfile, f, h, csadd2caldb.log,,, "Log filename"
... ...
doc/source/users/user_manual/csadd2caldb.py renamed to cscripts/csadd2caldb.py
... ... @@ -39,9 +39,6 @@ class csadd2caldb(ctools.cscript):
39 39 """
40 40 Constructor
41 41 """
42   - # Make sure that parfile exists
43   - self._parfile()
44   -
45 42 # Initialise application by calling the base class constructor
46 43 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
47 44  
... ... @@ -50,31 +47,6 @@ class csadd2caldb(ctools.cscript):
50 47  
51 48  
52 49 # Private methods
53   - def _parfile(self):
54   - """
55   - Check if parfile exists. If parfile does not exist then create a
56   - default parfile. This kluge avoids shipping the cscript with a parfile.
57   - """
58   - # Set parfile name
59   - parfile = self.__class__.__name__+'.par'
60   -
61   - # Load parfile or create
62   - try:
63   - pars = gammalib.GApplicationPars(parfile)
64   - except:
65   - # Signal that parfile was not found
66   - print('Parfile '+parfile+' not found. Create default parfile.')
67   -
68   - # Create default parfile
69   - pars = gammalib.GApplicationPars()
70   - pars.append(gammalib.GApplicationPar('indir','f','a','fits','','','Input IRF folder'))
71   - pars.append(gammalib.GApplicationPar('outdir','f','a','$CALDB','','','Output caldb folder'))
72   - pars.append_standard()
73   - pars.save(parfile)
74   -
75   - # Return
76   - return
77   -
78 50 def _get_parameters(self):
79 51 """
80 52 Get parameters from parfile
... ... @@ -358,6 +330,12 @@ class csadd2caldb(ctools.cscript):
358 330 # Collect tarfiles
359 331 tarfiles = self._collect_tarfiles(self['indir'].filename())
360 332  
  333 + # Raise an exception if no tarfiles were found
  334 + if len(tarfiles) == 0:
  335 + msg = ('No tarfiles found in folder "'+self['indir'].filename().url()+'. '
  336 + 'Please specify a folder that contains IRF tarfiles.')
  337 + raise RuntimeError(msg)
  338 +
361 339 # Add IRFs in tarfiles
362 340 for file in tarfiles:
363 341  
... ...
cscripts/mputils.py 100644 → 100755
doc/source/admin/release_history/2.0.rst
1 1 .. _2.0:
2 2  
3   -ctools 2.0 release (25 June 2021)
4   -=================================
  3 +ctools 2.0 release (30 September 2021)
  4 +======================================
5 5  
6 6 Overview
7 7 --------
... ... @@ -58,6 +58,7 @@ New features
58 58  
59 59 * [`3738 <https://cta-redmine.irap.omp.eu/issues/3738>`_] -
60 60 Add COMPTEL analysis scripts
  61 +* Add :ref:`csadd2caldb` script
61 62  
62 63  
63 64 Clean up
... ...
doc/source/users/reference_manual/csadd2caldb.rst 0 → 100755
  1 +.. _csadd2caldb:
  2 +
  3 +csadd2caldb
  4 +===========
  5 +
  6 +Adds CTA response function to calibration database.
  7 +
  8 +
  9 +Synopsis
  10 +--------
  11 +
  12 +This script adds a CTA response function to the calibration database. The
  13 +CTA response functions can be downloaded from CTAO Zenodo directory.
  14 +
  15 +
  16 +General parameters
  17 +------------------
  18 +
  19 +``indir [file]``
  20 + Input IRF folder.
  21 +
  22 +``outdir [file]``
  23 + Output caldb folder.
  24 +
  25 +
  26 +Standard parameters
  27 +-------------------
  28 +
  29 +``(chatter = 2) [integer]``
  30 + Verbosity of the executable:
  31 + ``chatter = 0``: no information will be logged
  32 +
  33 + ``chatter = 1``: only errors will be logged
  34 +
  35 + ``chatter = 2``: errors and actions will be logged
  36 +
  37 + ``chatter = 3``: report about the task execution
  38 +
  39 + ``chatter = 4``: detailed report about the task execution
  40 +
  41 +``(clobber = yes) [boolean]``
  42 + Specifies whether an existing energy boundaries output file should be overwritten.
  43 +
  44 +``(debug = no) [boolean]``
  45 + Enables debug mode. In debug mode the executable will dump any log file output to the console.
  46 +
  47 +``(mode = ql) [string]``
  48 + Mode of automatic parameters (default is ``ql``, i.e. "query and learn").
  49 +
  50 +``(logfile = csadd2caldb.log) [filename]``
  51 + Log filename.
  52 +
  53 +
  54 +Related tools or scripts
  55 +------------------------
... ...
doc/source/users/reference_manual/index.rst
... ... @@ -64,6 +64,7 @@ CTA and IACT analysis tools and scripts
64 64 cspull --- Generates pull distribution <cspull>
65 65 csresmap --- Generates residual map <csresmap>
66 66 csresspec --- Generates residual spectrum <csresspec>
  67 + csadd2caldb --- Adds CTA response function to calibration database <csadd2caldb>
67 68 csroot2caldb --- Creates a caldb entry from a ROOT file <csroot2caldb>
68 69 csscs --- Performs spectral component separation <csscs>
69 70 cssens --- Computes CTA sensitivity <cssens>
... ...
doc/source/users/user_manual/irf_cta.rst
... ... @@ -83,10 +83,6 @@ In total, the following six instrument response functions are available:
83 83 The latest CTA reponse functions (``prod5-v0.1``) can be downloaded from
84 84 `this link <https://zenodo.org/record/5499840#.YVV1di0itZo>`_.
85 85  
86   -Addition of CTA response functions to the calibration database can be done
87   -using the script :download:`csadd2caldb.py <csadd2caldb.py>` that is available
88   -for download.
89   -
90 86 To download and install the ``prod5-v0.1`` response functions you should execute
91 87 the following commands in a terminal:
92 88  
... ... @@ -96,8 +92,7 @@ the following commands in a terminal:
96 92 $ cd temp
97 93 $ wget https://zenodo.org/record/5499840/files/cta-prod5-zenodo-fitsonly-v0.1.zip
98 94 $ unzip cta-prod5-zenodo-fitsonly-v0.1.zip
99   - $ ./csadd2caldb.py
100   - Parfile csadd2caldb.par not found. Create default parfile.
  95 + $ csadd2caldb
101 96 Input IRF folder [fits]
102 97 Output caldb folder [$CALDB]
103 98  
... ...
test/data/prod5-v0.1/CTA-Performance-prod5-v0.1-South-20deg.FITS.tar.gz 0 → 100644
No preview for this file type
test/test_csadd2caldb.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for the csadd2caldb script.
  4 +#
  5 +# Copyright (C) 2021 Juergen Knoedlseder
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +import os
  22 +import gammalib
  23 +import cscripts
  24 +from testing import test
  25 +
  26 +
  27 +# ================================= #
  28 +# Test class for csadd2caldb script #
  29 +# ================================= #
  30 +class Test(test):
  31 + """
  32 + Test class for csadd2caldb script
  33 +
  34 + This test class makes unit tests for the csadd2caldb script by using it
  35 + from the command line and from Python.
  36 + """
  37 +
  38 + # Constructor
  39 + def __init__(self):
  40 + """
  41 + Constructor
  42 + """
  43 + # Call base class constructor
  44 + test.__init__(self)
  45 +
  46 + # Set test datasets and parameters
  47 + self._prod501 = self._datadir + '/prod5-v0.1'
  48 +
  49 + # Clear results
  50 + os.system('rm -rf csadd2caldb_cmd1')
  51 + os.system('rm -rf csadd2caldb_py1')
  52 + os.system('rm -rf csadd2caldb_py1_pickle')
  53 +
  54 + # Return
  55 + return
  56 +
  57 + # Set test functions
  58 + def set(self):
  59 + """
  60 + Set all test functions.
  61 + """
  62 + # Set test name
  63 + self.name('csadd2caldb')
  64 +
  65 + # Append tests
  66 + self.append(self._test_cmd, 'Test csadd2caldb on command line')
  67 + self.append(self._test_python, 'Test csadd2caldb from Python')
  68 + self.append(self._test_pickeling, 'Test csadd2caldb pickeling')
  69 +
  70 + # Return
  71 + return
  72 +
  73 + # Test csadd2caldb on command line
  74 + def _test_cmd(self):
  75 + """
  76 + Test csadd2caldb on the command line.
  77 + """
  78 + # Set script name
  79 + csadd2caldb = self._script('csadd2caldb')
  80 +
  81 + # Setup csadd2caldb command
  82 + cmd = csadd2caldb+' indir="'+self._prod501+'"'+ \
  83 + ' outdir="csadd2caldb_cmd1"'+ \
  84 + ' logfile="csadd2caldb_cmd1.log" chatter=4'
  85 +
  86 + # Check if execution was successful
  87 + self.test_assert(self._execute(cmd) == 0,
  88 + 'Check successful execution from command line')
  89 +
  90 + # Check IRF
  91 + self._check_irf('csadd2caldb_cmd1')
  92 +
  93 + # Setup csadd2caldb command
  94 + cmd = csadd2caldb+' indir="folder_that_does_not_exist"'+ \
  95 + ' outdir="csadd2caldb_cmd2"'+ \
  96 + ' logfile="csadd2caldb_cmd2.log" chatter=1'
  97 +
  98 + # Check if execution failed
  99 + self.test_assert(self._execute(cmd, success=False) != 0,
  100 + 'Check invalid input file when executed from command line')
  101 +
  102 + # Check csadd2caldb --help
  103 + self._check_help(csadd2caldb)
  104 +
  105 + # Return
  106 + return
  107 +
  108 + # Test csadd2caldb from Python
  109 + def _test_python(self):
  110 + """
  111 + Test csadd2caldb from Python
  112 + """
  113 + # Set-up csadd2caldb
  114 + addirf = cscripts.csadd2caldb()
  115 + addirf['indir'] = self._prod501
  116 + addirf['outdir'] = 'csadd2caldb_py1'
  117 + addirf['logfile'] = 'csadd2caldb_py1.log'
  118 +
  119 + # Run csadd2caldb script and save background model
  120 + addirf.logFileOpen() # Make sure we get a log file
  121 + addirf.run()
  122 + addirf.save()
  123 +
  124 + # Check IRF
  125 + self._check_irf('csadd2caldb_py1')
  126 +
  127 + # Return
  128 + return
  129 +
  130 + # Test csadd2caldb pickeling
  131 + def _test_pickeling(self):
  132 + """
  133 + Test csadd2caldb pickeling
  134 + """
  135 + # Perform pickeling tests of empty class
  136 + self._pickeling(cscripts.csadd2caldb())
  137 +
  138 + # Set-up csadd2caldb
  139 + addirf = cscripts.csadd2caldb()
  140 + addirf['indir'] = self._prod501
  141 + addirf['outdir'] = 'csadd2caldb_py1_pickle'
  142 + addirf['logfile'] = 'csadd2caldb_py1_pickle.log'
  143 +
  144 + # Perform pickeling tests of filled class
  145 + obj = self._pickeling(addirf)
  146 +
  147 + # Run csadd2caldb script and save background model
  148 + obj.logFileOpen() # Make sure we get a log file
  149 + obj.run()
  150 + obj.save()
  151 +
  152 + # Check IRF
  153 + self._check_irf('csadd2caldb_py1_pickle')
  154 +
  155 + # Return
  156 + return
  157 +
  158 + # Check IRF
  159 + def _check_irf(self, filename, prod='prod5-v0.1', nirfs=8):
  160 + """
  161 + Check IRF
  162 + """
  163 + # Open CALDB
  164 + caldb = gammalib.GCaldb(filename)
  165 + caldb.open('CTA', prod)
  166 +
  167 + # Check CALDB
  168 + self.test_value(caldb.size(), nirfs, 'Check for %d entries in CALDB' % nirfs)
  169 +
  170 + # Return
  171 + return
... ...
test/test_python_cscripts.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This scripts performs unit tests for cscripts
4 4 #
5   -# Copyright (C) 2016-2020 Juergen Knoedlseder
  5 +# Copyright (C) 2016-2021 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -25,6 +25,7 @@ import sys
25 25 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
26 26 import test_cscript
27 27 import test_cscaldb
  28 +import test_csadd2caldb
28 29 import test_csbkgmodel
29 30 import test_csebins
30 31 import test_csfindobs
... ... @@ -117,6 +118,7 @@ def test(installed=False, debug=False):
117 118  
118 119 # Define list of test suites
119 120 tests = [test_cscript.Test(),
  121 + test_csadd2caldb.Test(),
120 122 test_csbkgmodel.Test(),
121 123 test_cscaldb.Test(),
122 124 test_csebins.Test(),
... ...