Commit 8649d5bcafd0a2e6c696e6c766ea4dfa9927a84b
1 parent
902c40cc
Integrate code
Showing
7 changed files
with
81 additions
and
65 deletions
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 | 3 | * Version 1.1.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add cstsmapsplit script (#1797) | |
| 6 | 7 | Add unit tests for all example scripts |
| 7 | 8 | Handle zero parameter errors in ctulimit (#1795) |
| 8 | 9 | Compute counts cube weights in ctbin (#1789) | ... | ... |
NEWS
| 1 | 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 | 6 | Introduction |
| ... | ... | @@ -219,6 +219,9 @@ sampling than the spatial sampling in the ROOT file. |
| 219 | 219 | Add csobsdef.pntdef() method to set directly a pointing definition from a |
| 220 | 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 | 225 | Unit tests have been added for all cscripts. |
| 223 | 226 | |
| 224 | 227 | ... | ... |
README.md
cscripts/Makefile.am
| ... | ... | @@ -16,8 +16,8 @@ pythonscripts = __init__.py \ |
| 16 | 16 | cssens.py \ |
| 17 | 17 | csspec.py \ |
| 18 | 18 | cstsdist.py \ |
| 19 | - cstsmapsplit.py \ | |
| 20 | 19 | cstsmapmerge.py \ |
| 20 | + cstsmapsplit.py \ | |
| 21 | 21 | csworkflow.py \ |
| 22 | 22 | csfindobs.py \ |
| 23 | 23 | csiactcopy.py \ |
| ... | ... | @@ -39,8 +39,8 @@ parfiles = cscaldb.par \ |
| 39 | 39 | cssens.par \ |
| 40 | 40 | csspec.par \ |
| 41 | 41 | cstsdist.par \ |
| 42 | - cstsmapsplit.par \ | |
| 43 | 42 | cstsmapmerge.par \ |
| 43 | + cstsmapsplit.par \ | |
| 44 | 44 | csworkflow.par \ |
| 45 | 45 | csfindobs.par \ |
| 46 | 46 | csiactcopy.par \ |
| ... | ... | @@ -62,8 +62,8 @@ linkscripts = cscaldb \ |
| 62 | 62 | cssens \ |
| 63 | 63 | csspec \ |
| 64 | 64 | cstsdist \ |
| 65 | - cstsmapsplit \ | |
| 66 | 65 | cstsmapmerge \ |
| 66 | + cstsmapsplit \ | |
| 67 | 67 | csworkflow \ |
| 68 | 68 | csfindobs \ |
| 69 | 69 | csiactcopy \ |
| ... | ... | @@ -87,8 +87,8 @@ testscripts = tests/__init__.py \ |
| 87 | 87 | ../test/test_cssens.py \ |
| 88 | 88 | ../test/test_csspec.py \ |
| 89 | 89 | ../test/test_cstsdist.py \ |
| 90 | - ../test/test_cstsmapsplit.py \ | |
| 91 | 90 | ../test/test_cstsmapmerge.py \ |
| 91 | + ../test/test_cstsmapsplit.py \ | |
| 92 | 92 | ../test/test_csworkflow.py \ |
| 93 | 93 | ../test/test_csfindobs.py \ |
| 94 | 94 | ../test/test_csiactcopy.py \ | ... | ... |
cscripts/__init__.py.in
| ... | ... | @@ -38,8 +38,8 @@ __all__ = [ |
| 38 | 38 | "cssens", |
| 39 | 39 | "csspec", |
| 40 | 40 | "cstsdist", |
| 41 | - "cstsmapsplit", | |
| 42 | 41 | "cstsmapmerge", |
| 42 | + "cstsmapsplit", | |
| 43 | 43 | "csworkflow", |
| 44 | 44 | "obsutils" |
| 45 | 45 | ] |
| ... | ... | @@ -64,8 +64,8 @@ from cscripts.csroot2caldb import csroot2caldb |
| 64 | 64 | from cscripts.cssens import cssens |
| 65 | 65 | from cscripts.csspec import csspec |
| 66 | 66 | from cscripts.cstsdist import cstsdist |
| 67 | -from cscripts.cstsmapsplit import cstsmapsplit | |
| 68 | 67 | from cscripts.cstsmapmerge import cstsmapmerge |
| 68 | +from cscripts.cstsmapsplit import cstsmapsplit | |
| 69 | 69 | from cscripts.csworkflow import csworkflow |
| 70 | 70 | from cscripts import obsutils |
| 71 | 71 | if cur_version > req_version: | ... | ... |
test/test_cstsmapsplit.py
| ... | ... | @@ -18,19 +18,19 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | -import os | |
| 22 | 21 | import gammalib |
| 23 | 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 | 34 | from the command line and from Python. |
| 35 | 35 | """ |
| 36 | 36 | |
| ... | ... | @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): |
| 40 | 40 | Constructor |
| 41 | 41 | """ |
| 42 | 42 | # Call base class constructor |
| 43 | - gammalib.GPythonTestSuite.__init__(self) | |
| 43 | + test.__init__(self) | |
| 44 | 44 | |
| 45 | 45 | # Return |
| 46 | 46 | return |
| ... | ... | @@ -55,7 +55,7 @@ class Test(gammalib.GPythonTestSuite): |
| 55 | 55 | |
| 56 | 56 | # Append tests |
| 57 | 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 | 60 | # Return |
| 61 | 61 | return |
| ... | ... | @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): |
| 63 | 63 | # Test cstsmapsplit on command line |
| 64 | 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 | 71 | # Setup cstsmapsplit command |
| 75 | 72 | cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ |
| ... | ... | @@ -87,21 +84,19 @@ class Test(gammalib.GPythonTestSuite): |
| 87 | 84 | ' proj="CAR"'+ \ |
| 88 | 85 | ' compute_null=yes'+ \ |
| 89 | 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 | 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 | 101 | # Setup cstsmapsplit command |
| 107 | 102 | cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ |
| ... | ... | @@ -119,18 +114,12 @@ class Test(gammalib.GPythonTestSuite): |
| 119 | 114 | ' proj="CAR"'+ \ |
| 120 | 115 | ' compute_null=yes'+ \ |
| 121 | 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 | 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 | 124 | # Return |
| 136 | 125 | return |
| ... | ... | @@ -138,40 +127,63 @@ class Test(gammalib.GPythonTestSuite): |
| 138 | 127 | # Test cstsmapsplit from Python |
| 139 | 128 | def _test_python(self): |
| 140 | 129 | """ |
| 141 | - Test cstsmapsplit from Python. | |
| 130 | + Test cstsmapsplit from Python | |
| 142 | 131 | """ |
| 143 | 132 | # Set-up cstsmapsplit |
| 144 | 133 | tsmapsplit = cscripts.cstsmapsplit() |
| 145 | - tsmapsplit['inobs'] = 'obs_selected.xml' | |
| 134 | + tsmapsplit['inobs'] = 'selected_events.fits' | |
| 146 | 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 | 147 | tsmapsplit['xref'] = 83.6331 |
| 148 | 148 | tsmapsplit['yref'] = 22.01 |
| 149 | - tsmapsplit['coordsys'] = 'CEL' | |
| 150 | 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 | 154 | tsmapsplit.logFileOpen() # Make sure we get a log file |
| 160 | 155 | tsmapsplit.run() |
| 161 | 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 | 179 | # Return |
| 167 | 180 | return |
| 168 | 181 | |
| 169 | 182 | # Check observation definition XML file |
| 170 | 183 | def _check_cmdfile(self, filename): |
| 171 | 184 | """ |
| 172 | - Check ascii files containing commands | |
| 185 | + Check ASCII files containing commands | |
| 173 | 186 | """ |
| 174 | - | |
| 175 | 187 | # Create file name instance |
| 176 | 188 | fname = gammalib.GFilename(filename) |
| 177 | 189 | ... | ... |
test/test_python_cscripts.py
| ... | ... | @@ -37,8 +37,8 @@ import test_csroot2caldb |
| 37 | 37 | import test_cssens |
| 38 | 38 | import test_csspec |
| 39 | 39 | import test_cstsdist |
| 40 | -import test_cstsmapsplit | |
| 41 | 40 | import test_cstsmapmerge |
| 41 | +import test_cstsmapsplit | |
| 42 | 42 | import test_csworkflow |
| 43 | 43 | import test_csiactcopy |
| 44 | 44 | import test_csiactdata |
| ... | ... | @@ -112,8 +112,8 @@ def test(installed=False, debug=False): |
| 112 | 112 | suite_cssens = test_cssens.Test() |
| 113 | 113 | suite_csspec = test_csspec.Test() |
| 114 | 114 | suite_cstsdist = test_cstsdist.Test() |
| 115 | - suite_cstsmapsplit = test_cstsmapsplit.Test() | |
| 116 | 115 | suite_cstsmapmerge = test_cstsmapmerge.Test() |
| 116 | + suite_cstsmapsplit = test_cstsmapsplit.Test() | |
| 117 | 117 | suite_csworkflow = test_csworkflow.Test() |
| 118 | 118 | |
| 119 | 119 | # Setup unit tests |
| ... | ... | @@ -130,8 +130,8 @@ def test(installed=False, debug=False): |
| 130 | 130 | suite_cssens.set() |
| 131 | 131 | suite_csspec.set() |
| 132 | 132 | suite_cstsdist.set() |
| 133 | - suite_cstsmapsplit.set() | |
| 134 | 133 | suite_cstsmapmerge.set() |
| 134 | + suite_cstsmapsplit.set() | |
| 135 | 135 | suite_csworkflow.set() |
| 136 | 136 | |
| 137 | 137 | # Append tests to container |
| ... | ... | @@ -148,8 +148,8 @@ def test(installed=False, debug=False): |
| 148 | 148 | suites.append(suite_cssens) |
| 149 | 149 | suites.append(suite_csspec) |
| 150 | 150 | suites.append(suite_cstsdist) |
| 151 | - suites.append(suite_cstsmapsplit) | |
| 152 | 151 | suites.append(suite_cstsmapmerge) |
| 152 | + suites.append(suite_cstsmapsplit) | |
| 153 | 153 | suites.append(suite_csworkflow) |
| 154 | 154 | |
| 155 | 155 | # Append tests for Python 2.6+ (the IACT cscripts depend on the json | ... | ... |