Commit 8649d5bcafd0a2e6c696e6c766ea4dfa9927a84b

Authored by Jürgen Knödlseder
1 parent 902c40cc

Integrate code

ChangeLog
1 -2016-06-25 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> 1 +2016-07-01 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2
3 * Version 1.1.0 released 3 * Version 1.1.0 released
4 ======================== 4 ========================
5 5
  6 + Add cstsmapsplit script (#1797)
6 Add unit tests for all example scripts 7 Add unit tests for all example scripts
7 Handle zero parameter errors in ctulimit (#1795) 8 Handle zero parameter errors in ctulimit (#1795)
8 Compute counts cube weights in ctbin (#1789) 9 Compute counts cube weights in ctbin (#1789)
1 New Features and Important Changes in ctools 1.1.0 1 New Features and Important Changes in ctools 1.1.0
2 2
3 -25 June 2016 3 +1 July 2016
4 4
5 5
6 Introduction 6 Introduction
@@ -219,6 +219,9 @@ sampling than the spatial sampling in the ROOT file. @@ -219,6 +219,9 @@ sampling than the spatial sampling in the ROOT file.
219 Add csobsdef.pntdef() method to set directly a pointing definition from a 219 Add csobsdef.pntdef() method to set directly a pointing definition from a
220 gammalib.GCsv object (#1771). 220 gammalib.GCsv object (#1771).
221 221
  222 +Add cstsmapsplit script that generates the command sequence for splitting the
  223 +computation of a Test Statistic map into computations of sub maps (#1797).
  224 +
222 Unit tests have been added for all cscripts. 225 Unit tests have been added for all cscripts.
223 226
224 227
README.md
1 ctools information 1 ctools information
2 ================== 2 ==================
3 -* Version: 1.1.0.dev1 (25 June 2016) 3 +* Version: 1.1.0.dev1 (1 July 2016)
4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) 4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu)
5 * GammaLib dependency: 1.1.0.dev1 5 * GammaLib dependency: 1.1.0.dev1
6 6
cscripts/Makefile.am
@@ -16,8 +16,8 @@ pythonscripts = __init__.py \ @@ -16,8 +16,8 @@ pythonscripts = __init__.py \
16 cssens.py \ 16 cssens.py \
17 csspec.py \ 17 csspec.py \
18 cstsdist.py \ 18 cstsdist.py \
19 - cstsmapsplit.py \  
20 cstsmapmerge.py \ 19 cstsmapmerge.py \
  20 + cstsmapsplit.py \
21 csworkflow.py \ 21 csworkflow.py \
22 csfindobs.py \ 22 csfindobs.py \
23 csiactcopy.py \ 23 csiactcopy.py \
@@ -39,8 +39,8 @@ parfiles = cscaldb.par \ @@ -39,8 +39,8 @@ parfiles = cscaldb.par \
39 cssens.par \ 39 cssens.par \
40 csspec.par \ 40 csspec.par \
41 cstsdist.par \ 41 cstsdist.par \
42 - cstsmapsplit.par \  
43 cstsmapmerge.par \ 42 cstsmapmerge.par \
  43 + cstsmapsplit.par \
44 csworkflow.par \ 44 csworkflow.par \
45 csfindobs.par \ 45 csfindobs.par \
46 csiactcopy.par \ 46 csiactcopy.par \
@@ -62,8 +62,8 @@ linkscripts = cscaldb \ @@ -62,8 +62,8 @@ linkscripts = cscaldb \
62 cssens \ 62 cssens \
63 csspec \ 63 csspec \
64 cstsdist \ 64 cstsdist \
65 - cstsmapsplit \  
66 cstsmapmerge \ 65 cstsmapmerge \
  66 + cstsmapsplit \
67 csworkflow \ 67 csworkflow \
68 csfindobs \ 68 csfindobs \
69 csiactcopy \ 69 csiactcopy \
@@ -87,8 +87,8 @@ testscripts = tests/__init__.py \ @@ -87,8 +87,8 @@ testscripts = tests/__init__.py \
87 ../test/test_cssens.py \ 87 ../test/test_cssens.py \
88 ../test/test_csspec.py \ 88 ../test/test_csspec.py \
89 ../test/test_cstsdist.py \ 89 ../test/test_cstsdist.py \
90 - ../test/test_cstsmapsplit.py \  
91 ../test/test_cstsmapmerge.py \ 90 ../test/test_cstsmapmerge.py \
  91 + ../test/test_cstsmapsplit.py \
92 ../test/test_csworkflow.py \ 92 ../test/test_csworkflow.py \
93 ../test/test_csfindobs.py \ 93 ../test/test_csfindobs.py \
94 ../test/test_csiactcopy.py \ 94 ../test/test_csiactcopy.py \
cscripts/__init__.py.in
@@ -38,8 +38,8 @@ __all__ = [ @@ -38,8 +38,8 @@ __all__ = [
38 "cssens", 38 "cssens",
39 "csspec", 39 "csspec",
40 "cstsdist", 40 "cstsdist",
41 - "cstsmapsplit",  
42 "cstsmapmerge", 41 "cstsmapmerge",
  42 + "cstsmapsplit",
43 "csworkflow", 43 "csworkflow",
44 "obsutils" 44 "obsutils"
45 ] 45 ]
@@ -64,8 +64,8 @@ from cscripts.csroot2caldb import csroot2caldb @@ -64,8 +64,8 @@ from cscripts.csroot2caldb import csroot2caldb
64 from cscripts.cssens import cssens 64 from cscripts.cssens import cssens
65 from cscripts.csspec import csspec 65 from cscripts.csspec import csspec
66 from cscripts.cstsdist import cstsdist 66 from cscripts.cstsdist import cstsdist
67 -from cscripts.cstsmapsplit import cstsmapsplit  
68 from cscripts.cstsmapmerge import cstsmapmerge 67 from cscripts.cstsmapmerge import cstsmapmerge
  68 +from cscripts.cstsmapsplit import cstsmapsplit
69 from cscripts.csworkflow import csworkflow 69 from cscripts.csworkflow import csworkflow
70 from cscripts import obsutils 70 from cscripts import obsutils
71 if cur_version > req_version: 71 if cur_version > req_version:
test/test_cstsmapsplit.py
@@ -18,19 +18,19 @@ @@ -18,19 +18,19 @@
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # 19 #
20 # ========================================================================== 20 # ==========================================================================
21 -import os  
22 import gammalib 21 import gammalib
23 import cscripts 22 import cscripts
  23 +from testing import test
24 24
25 25
26 -# =============================== #  
27 -# Test class for cstssplit script #  
28 -# =============================== #  
29 -class Test(gammalib.GPythonTestSuite): 26 +# ================================== #
  27 +# Test class for cstsmapsplit script #
  28 +# ================================== #
  29 +class Test(test):
30 """ 30 """
31 - Test class for cstssplit script 31 + Test class for cstsmapsplit script
32 32
33 - This test class makes unit tests for the csstsplit script by using it 33 + This test class makes unit tests for the cstsmapsplit script by using it
34 from the command line and from Python. 34 from the command line and from Python.
35 """ 35 """
36 36
@@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite):
40 Constructor 40 Constructor
41 """ 41 """
42 # Call base class constructor 42 # Call base class constructor
43 - gammalib.GPythonTestSuite.__init__(self) 43 + test.__init__(self)
44 44
45 # Return 45 # Return
46 return 46 return
@@ -55,7 +55,7 @@ class Test(gammalib.GPythonTestSuite): @@ -55,7 +55,7 @@ class Test(gammalib.GPythonTestSuite):
55 55
56 # Append tests 56 # Append tests
57 self.append(self._test_cmd, 'Test cstsmapsplit on command line') 57 self.append(self._test_cmd, 'Test cstsmapsplit on command line')
58 - #self.append(self._test_python, 'Test cstsmapsplit from Python') 58 + self.append(self._test_python, 'Test cstsmapsplit from Python')
59 59
60 # Return 60 # Return
61 return 61 return
@@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite):
63 # Test cstsmapsplit on command line 63 # Test cstsmapsplit on command line
64 def _test_cmd(self): 64 def _test_cmd(self):
65 """ 65 """
66 - Test cstsmapsplit on the command line. 66 + Test cstsmapsplit on the command line
67 """ 67 """
68 - # Kluge to set the command (installed version has no README file)  
69 - if os.path.isfile("README.md"):  
70 - cstsmapsplit = "../cscripts/cstsmapsplit.py"  
71 - else:  
72 - cstsmapsplit = "cstsmapsplit" 68 + # Set script name
  69 + cstsmapsplit = self._script('cstsmapsplit')
73 70
74 # Setup cstsmapsplit command 71 # Setup cstsmapsplit command
75 cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ 72 cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \
@@ -87,21 +84,19 @@ class Test(gammalib.GPythonTestSuite): @@ -87,21 +84,19 @@ class Test(gammalib.GPythonTestSuite):
87 ' proj="CAR"'+ \ 84 ' proj="CAR"'+ \
88 ' compute_null=yes'+ \ 85 ' compute_null=yes'+ \
89 ' bins_per_job=5'+ \ 86 ' bins_per_job=5'+ \
90 - ' outfile="tsmap_cmds1.txt"' 87 + ' outfile="cstsmapsplit_cmd1.dat"'+ \
  88 + ' logfile="cstsmapsplit_cmd1.log" chatter=1'
91 89
92 -  
93 - # Execute cstssplit, make sure we catch any exception  
94 - try:  
95 - rc = os.system(cmd+" >/dev/null 2>&1")  
96 - except:  
97 - pass 90 + # Check if execution of wrong command fails
  91 + self.test_assert(self._execute('command_that_does_not_exist') != 0,
  92 + 'Self test of test script')
98 93
99 # Check if execution was successful 94 # Check if execution was successful
100 - self.test_assert(rc == 0,  
101 - "Successful cstsssplit execution on command line") 95 + self.test_assert(self._execute(cmd) == 0,
  96 + 'Check successful execution from command line')
102 97
103 - # Check observation definition XML file  
104 - self._check_cmdfile('tsmap_cmds1.txt') 98 + # Check command file
  99 + self._check_cmdfile('cstsmapsplit_cmd1.dat')
105 100
106 # Setup cstsmapsplit command 101 # Setup cstsmapsplit command
107 cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ 102 cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \
@@ -119,18 +114,12 @@ class Test(gammalib.GPythonTestSuite): @@ -119,18 +114,12 @@ class Test(gammalib.GPythonTestSuite):
119 ' proj="CAR"'+ \ 114 ' proj="CAR"'+ \
120 ' compute_null=yes'+ \ 115 ' compute_null=yes'+ \
121 ' bins_per_job=5'+ \ 116 ' bins_per_job=5'+ \
122 - ' outfile="tsmap_cmds2.txt"'  
123 -  
124 -  
125 - # Execute cstssplit, make sure we catch any exception  
126 - try:  
127 - rc = os.system(cmd+" >/dev/null 2>&1")  
128 - except:  
129 - pass  
130 - 117 + ' outfile="cstsmapsplit_cmd2.dat"'+ \
  118 + ' logfile="cstsmapsplit_cmd2.log" chatter=2'
  119 +
131 # Check if execution failed 120 # Check if execution failed
132 - self.test_assert(rc != 0,  
133 - "Failure of cstssplit execution on command line") 121 + self.test_assert(self._execute(cmd) != 0,
  122 + 'Check invalid input file when executed from command line')
134 123
135 # Return 124 # Return
136 return 125 return
@@ -138,40 +127,63 @@ class Test(gammalib.GPythonTestSuite): @@ -138,40 +127,63 @@ class Test(gammalib.GPythonTestSuite):
138 # Test cstsmapsplit from Python 127 # Test cstsmapsplit from Python
139 def _test_python(self): 128 def _test_python(self):
140 """ 129 """
141 - Test cstsmapsplit from Python. 130 + Test cstsmapsplit from Python
142 """ 131 """
143 # Set-up cstsmapsplit 132 # Set-up cstsmapsplit
144 tsmapsplit = cscripts.cstsmapsplit() 133 tsmapsplit = cscripts.cstsmapsplit()
145 - tsmapsplit['inobs'] = 'obs_selected.xml' 134 + tsmapsplit['inobs'] = 'selected_events.fits'
146 tsmapsplit['inmodel'] = 'data/crab.xml' 135 tsmapsplit['inmodel'] = 'data/crab.xml'
  136 + tsmapsplit['srcname'] = 'Crab'
  137 + tsmapsplit['caldb'] = 'prod2'
  138 + tsmapsplit['irf'] = 'South_0.5h'
  139 + tsmapsplit['outmap'] = 'tsmap.fits'
  140 + tsmapsplit['bins_per_job'] = 5
  141 + tsmapsplit['compute_null'] = False
  142 + tsmapsplit['outfile'] = 'cstsmapsplit_py1.dat'
  143 + tsmapsplit['nxpix'] = 5
  144 + tsmapsplit['nypix'] = 5
  145 + tsmapsplit['binsz'] = 0.05
  146 + tsmapsplit['coordsys'] = 'CEL'
147 tsmapsplit['xref'] = 83.6331 147 tsmapsplit['xref'] = 83.6331
148 tsmapsplit['yref'] = 22.01 148 tsmapsplit['yref'] = 22.01
149 - tsmapsplit['coordsys'] = 'CEL'  
150 tsmapsplit['proj'] = 'CAR' 149 tsmapsplit['proj'] = 'CAR'
151 - tsmapsplit['binsz'] = 0.05  
152 - tsmapsplit['nxpix'] = 5  
153 - tsmapsplit['nypix'] = 5  
154 - tsmapsplit['compute_null'] = False  
155 - tsmapsplit['bins_per_job'] = 5  
156 - tsmapsplit['outfile'] = 'tsmap_cmd_py1.txt' 150 + tsmapsplit['logfile'] = 'cstsmapsplit_py1.log'
  151 + tsmapsplit['chatter'] = 2
157 152
158 - # Run cstssplit script and save run list 153 + # Run cstsmapsplit script and save the commands
159 tsmapsplit.logFileOpen() # Make sure we get a log file 154 tsmapsplit.logFileOpen() # Make sure we get a log file
160 tsmapsplit.run() 155 tsmapsplit.run()
161 tsmapsplit.save() 156 tsmapsplit.save()
162 157
163 - # Check observation definition XML file  
164 - self._check_cmdfile('tsmap_cmd_py1.txt')  
165 - 158 + # Check command file
  159 + self._check_cmdfile('cstsmapsplit_py1.dat')
  160 +
  161 + # Test with higher chatter level 3
  162 + tsmapsplit['outfile'] = 'cstsmapsplit_py2.dat'
  163 + tsmapsplit['logfile'] = 'cstsmapsplit_py2.log'
  164 + tsmapsplit['chatter'] = 3
  165 + tsmapsplit.execute()
  166 +
  167 + # Check command file
  168 + self._check_cmdfile('cstsmapsplit_py2.dat')
  169 +
  170 + # Test with higher chatter level 4
  171 + tsmapsplit['outfile'] = 'cstsmapsplit_py3.dat'
  172 + tsmapsplit['logfile'] = 'cstsmapsplit_py3.log'
  173 + tsmapsplit['chatter'] = 4
  174 + tsmapsplit.execute()
  175 +
  176 + # Check command file
  177 + self._check_cmdfile('cstsmapsplit_py3.dat')
  178 +
166 # Return 179 # Return
167 return 180 return
168 181
169 # Check observation definition XML file 182 # Check observation definition XML file
170 def _check_cmdfile(self, filename): 183 def _check_cmdfile(self, filename):
171 """ 184 """
172 - Check ascii files containing commands 185 + Check ASCII files containing commands
173 """ 186 """
174 -  
175 # Create file name instance 187 # Create file name instance
176 fname = gammalib.GFilename(filename) 188 fname = gammalib.GFilename(filename)
177 189
test/test_python_cscripts.py
@@ -37,8 +37,8 @@ import test_csroot2caldb @@ -37,8 +37,8 @@ import test_csroot2caldb
37 import test_cssens 37 import test_cssens
38 import test_csspec 38 import test_csspec
39 import test_cstsdist 39 import test_cstsdist
40 -import test_cstsmapsplit  
41 import test_cstsmapmerge 40 import test_cstsmapmerge
  41 +import test_cstsmapsplit
42 import test_csworkflow 42 import test_csworkflow
43 import test_csiactcopy 43 import test_csiactcopy
44 import test_csiactdata 44 import test_csiactdata
@@ -112,8 +112,8 @@ def test(installed=False, debug=False): @@ -112,8 +112,8 @@ def test(installed=False, debug=False):
112 suite_cssens = test_cssens.Test() 112 suite_cssens = test_cssens.Test()
113 suite_csspec = test_csspec.Test() 113 suite_csspec = test_csspec.Test()
114 suite_cstsdist = test_cstsdist.Test() 114 suite_cstsdist = test_cstsdist.Test()
115 - suite_cstsmapsplit = test_cstsmapsplit.Test()  
116 suite_cstsmapmerge = test_cstsmapmerge.Test() 115 suite_cstsmapmerge = test_cstsmapmerge.Test()
  116 + suite_cstsmapsplit = test_cstsmapsplit.Test()
117 suite_csworkflow = test_csworkflow.Test() 117 suite_csworkflow = test_csworkflow.Test()
118 118
119 # Setup unit tests 119 # Setup unit tests
@@ -130,8 +130,8 @@ def test(installed=False, debug=False): @@ -130,8 +130,8 @@ def test(installed=False, debug=False):
130 suite_cssens.set() 130 suite_cssens.set()
131 suite_csspec.set() 131 suite_csspec.set()
132 suite_cstsdist.set() 132 suite_cstsdist.set()
133 - suite_cstsmapsplit.set()  
134 suite_cstsmapmerge.set() 133 suite_cstsmapmerge.set()
  134 + suite_cstsmapsplit.set()
135 suite_csworkflow.set() 135 suite_csworkflow.set()
136 136
137 # Append tests to container 137 # Append tests to container
@@ -148,8 +148,8 @@ def test(installed=False, debug=False): @@ -148,8 +148,8 @@ def test(installed=False, debug=False):
148 suites.append(suite_cssens) 148 suites.append(suite_cssens)
149 suites.append(suite_csspec) 149 suites.append(suite_csspec)
150 suites.append(suite_cstsdist) 150 suites.append(suite_cstsdist)
151 - suites.append(suite_cstsmapsplit)  
152 suites.append(suite_cstsmapmerge) 151 suites.append(suite_cstsmapmerge)
  152 + suites.append(suite_cstsmapsplit)
153 suites.append(suite_csworkflow) 153 suites.append(suite_csworkflow)
154 154
155 # Append tests for Python 2.6+ (the IACT cscripts depend on the json 155 # Append tests for Python 2.6+ (the IACT cscripts depend on the json