diff --git a/ChangeLog b/ChangeLog index a161fc6..f543d26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-06-25 Juergen Knoedlseder +2016-07-01 Juergen Knoedlseder * Version 1.1.0 released ======================== + Add cstsmapsplit script (#1797) Add unit tests for all example scripts Handle zero parameter errors in ctulimit (#1795) Compute counts cube weights in ctbin (#1789) diff --git a/NEWS b/NEWS index db7bb1f..698a0b2 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.1.0 -25 June 2016 +1 July 2016 Introduction @@ -219,6 +219,9 @@ sampling than the spatial sampling in the ROOT file. Add csobsdef.pntdef() method to set directly a pointing definition from a gammalib.GCsv object (#1771). +Add cstsmapsplit script that generates the command sequence for splitting the +computation of a Test Statistic map into computations of sub maps (#1797). + Unit tests have been added for all cscripts. diff --git a/README.md b/README.md index dee57cc..48b2e2b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ctools information ================== -* Version: 1.1.0.dev1 (25 June 2016) +* Version: 1.1.0.dev1 (1 July 2016) * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) * GammaLib dependency: 1.1.0.dev1 diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am index 6712daf..1072771 100644 --- a/cscripts/Makefile.am +++ b/cscripts/Makefile.am @@ -16,8 +16,8 @@ pythonscripts = __init__.py \ cssens.py \ csspec.py \ cstsdist.py \ - cstsmapsplit.py \ cstsmapmerge.py \ + cstsmapsplit.py \ csworkflow.py \ csfindobs.py \ csiactcopy.py \ @@ -39,8 +39,8 @@ parfiles = cscaldb.par \ cssens.par \ csspec.par \ cstsdist.par \ - cstsmapsplit.par \ cstsmapmerge.par \ + cstsmapsplit.par \ csworkflow.par \ csfindobs.par \ csiactcopy.par \ @@ -62,8 +62,8 @@ linkscripts = cscaldb \ cssens \ csspec \ cstsdist \ - cstsmapsplit \ cstsmapmerge \ + cstsmapsplit \ csworkflow \ csfindobs \ csiactcopy \ @@ -87,8 +87,8 @@ testscripts = tests/__init__.py \ ../test/test_cssens.py \ ../test/test_csspec.py \ ../test/test_cstsdist.py \ - ../test/test_cstsmapsplit.py \ ../test/test_cstsmapmerge.py \ + ../test/test_cstsmapsplit.py \ ../test/test_csworkflow.py \ ../test/test_csfindobs.py \ ../test/test_csiactcopy.py \ diff --git a/cscripts/__init__.py.in b/cscripts/__init__.py.in index 36ced7a..98b6666 100644 --- a/cscripts/__init__.py.in +++ b/cscripts/__init__.py.in @@ -38,8 +38,8 @@ __all__ = [ "cssens", "csspec", "cstsdist", - "cstsmapsplit", "cstsmapmerge", + "cstsmapsplit", "csworkflow", "obsutils" ] @@ -64,8 +64,8 @@ from cscripts.csroot2caldb import csroot2caldb from cscripts.cssens import cssens from cscripts.csspec import csspec from cscripts.cstsdist import cstsdist -from cscripts.cstsmapsplit import cstsmapsplit from cscripts.cstsmapmerge import cstsmapmerge +from cscripts.cstsmapsplit import cstsmapsplit from cscripts.csworkflow import csworkflow from cscripts import obsutils if cur_version > req_version: diff --git a/test/test_cstsmapsplit.py b/test/test_cstsmapsplit.py index d41fcb6..21686d8 100755 --- a/test/test_cstsmapsplit.py +++ b/test/test_cstsmapsplit.py @@ -18,19 +18,19 @@ # along with this program. If not, see . # # ========================================================================== -import os import gammalib import cscripts +from testing import test -# =============================== # -# Test class for cstssplit script # -# =============================== # -class Test(gammalib.GPythonTestSuite): +# ================================== # +# Test class for cstsmapsplit script # +# ================================== # +class Test(test): """ - Test class for cstssplit script + Test class for cstsmapsplit script - This test class makes unit tests for the csstsplit script by using it + This test class makes unit tests for the cstsmapsplit script by using it from the command line and from Python. """ @@ -40,7 +40,7 @@ class Test(gammalib.GPythonTestSuite): Constructor """ # Call base class constructor - gammalib.GPythonTestSuite.__init__(self) + test.__init__(self) # Return return @@ -55,7 +55,7 @@ class Test(gammalib.GPythonTestSuite): # Append tests self.append(self._test_cmd, 'Test cstsmapsplit on command line') - #self.append(self._test_python, 'Test cstsmapsplit from Python') + self.append(self._test_python, 'Test cstsmapsplit from Python') # Return return @@ -63,13 +63,10 @@ class Test(gammalib.GPythonTestSuite): # Test cstsmapsplit on command line def _test_cmd(self): """ - Test cstsmapsplit on the command line. + Test cstsmapsplit on the command line """ - # Kluge to set the command (installed version has no README file) - if os.path.isfile("README.md"): - cstsmapsplit = "../cscripts/cstsmapsplit.py" - else: - cstsmapsplit = "cstsmapsplit" + # Set script name + cstsmapsplit = self._script('cstsmapsplit') # Setup cstsmapsplit command cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ @@ -87,21 +84,19 @@ class Test(gammalib.GPythonTestSuite): ' proj="CAR"'+ \ ' compute_null=yes'+ \ ' bins_per_job=5'+ \ - ' outfile="tsmap_cmds1.txt"' + ' outfile="cstsmapsplit_cmd1.dat"'+ \ + ' logfile="cstsmapsplit_cmd1.log" chatter=1' - - # Execute cstssplit, make sure we catch any exception - try: - rc = os.system(cmd+" >/dev/null 2>&1") - except: - pass + # Check if execution of wrong command fails + self.test_assert(self._execute('command_that_does_not_exist') != 0, + 'Self test of test script') # Check if execution was successful - self.test_assert(rc == 0, - "Successful cstsssplit execution on command line") + self.test_assert(self._execute(cmd) == 0, + 'Check successful execution from command line') - # Check observation definition XML file - self._check_cmdfile('tsmap_cmds1.txt') + # Check command file + self._check_cmdfile('cstsmapsplit_cmd1.dat') # Setup cstsmapsplit command cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ @@ -119,18 +114,12 @@ class Test(gammalib.GPythonTestSuite): ' proj="CAR"'+ \ ' compute_null=yes'+ \ ' bins_per_job=5'+ \ - ' outfile="tsmap_cmds2.txt"' - - - # Execute cstssplit, make sure we catch any exception - try: - rc = os.system(cmd+" >/dev/null 2>&1") - except: - pass - + ' outfile="cstsmapsplit_cmd2.dat"'+ \ + ' logfile="cstsmapsplit_cmd2.log" chatter=2' + # Check if execution failed - self.test_assert(rc != 0, - "Failure of cstssplit execution on command line") + self.test_assert(self._execute(cmd) != 0, + 'Check invalid input file when executed from command line') # Return return @@ -138,40 +127,63 @@ class Test(gammalib.GPythonTestSuite): # Test cstsmapsplit from Python def _test_python(self): """ - Test cstsmapsplit from Python. + Test cstsmapsplit from Python """ # Set-up cstsmapsplit tsmapsplit = cscripts.cstsmapsplit() - tsmapsplit['inobs'] = 'obs_selected.xml' + tsmapsplit['inobs'] = 'selected_events.fits' tsmapsplit['inmodel'] = 'data/crab.xml' + tsmapsplit['srcname'] = 'Crab' + tsmapsplit['caldb'] = 'prod2' + tsmapsplit['irf'] = 'South_0.5h' + tsmapsplit['outmap'] = 'tsmap.fits' + tsmapsplit['bins_per_job'] = 5 + tsmapsplit['compute_null'] = False + tsmapsplit['outfile'] = 'cstsmapsplit_py1.dat' + tsmapsplit['nxpix'] = 5 + tsmapsplit['nypix'] = 5 + tsmapsplit['binsz'] = 0.05 + tsmapsplit['coordsys'] = 'CEL' tsmapsplit['xref'] = 83.6331 tsmapsplit['yref'] = 22.01 - tsmapsplit['coordsys'] = 'CEL' tsmapsplit['proj'] = 'CAR' - tsmapsplit['binsz'] = 0.05 - tsmapsplit['nxpix'] = 5 - tsmapsplit['nypix'] = 5 - tsmapsplit['compute_null'] = False - tsmapsplit['bins_per_job'] = 5 - tsmapsplit['outfile'] = 'tsmap_cmd_py1.txt' + tsmapsplit['logfile'] = 'cstsmapsplit_py1.log' + tsmapsplit['chatter'] = 2 - # Run cstssplit script and save run list + # Run cstsmapsplit script and save the commands tsmapsplit.logFileOpen() # Make sure we get a log file tsmapsplit.run() tsmapsplit.save() - # Check observation definition XML file - self._check_cmdfile('tsmap_cmd_py1.txt') - + # Check command file + self._check_cmdfile('cstsmapsplit_py1.dat') + + # Test with higher chatter level 3 + tsmapsplit['outfile'] = 'cstsmapsplit_py2.dat' + tsmapsplit['logfile'] = 'cstsmapsplit_py2.log' + tsmapsplit['chatter'] = 3 + tsmapsplit.execute() + + # Check command file + self._check_cmdfile('cstsmapsplit_py2.dat') + + # Test with higher chatter level 4 + tsmapsplit['outfile'] = 'cstsmapsplit_py3.dat' + tsmapsplit['logfile'] = 'cstsmapsplit_py3.log' + tsmapsplit['chatter'] = 4 + tsmapsplit.execute() + + # Check command file + self._check_cmdfile('cstsmapsplit_py3.dat') + # Return return # Check observation definition XML file def _check_cmdfile(self, filename): """ - Check ascii files containing commands + Check ASCII files containing commands """ - # Create file name instance fname = gammalib.GFilename(filename) diff --git a/test/test_python_cscripts.py b/test/test_python_cscripts.py index 63c6150..1a95303 100755 --- a/test/test_python_cscripts.py +++ b/test/test_python_cscripts.py @@ -37,8 +37,8 @@ import test_csroot2caldb import test_cssens import test_csspec import test_cstsdist -import test_cstsmapsplit import test_cstsmapmerge +import test_cstsmapsplit import test_csworkflow import test_csiactcopy import test_csiactdata @@ -112,8 +112,8 @@ def test(installed=False, debug=False): suite_cssens = test_cssens.Test() suite_csspec = test_csspec.Test() suite_cstsdist = test_cstsdist.Test() - suite_cstsmapsplit = test_cstsmapsplit.Test() suite_cstsmapmerge = test_cstsmapmerge.Test() + suite_cstsmapsplit = test_cstsmapsplit.Test() suite_csworkflow = test_csworkflow.Test() # Setup unit tests @@ -130,8 +130,8 @@ def test(installed=False, debug=False): suite_cssens.set() suite_csspec.set() suite_cstsdist.set() - suite_cstsmapsplit.set() suite_cstsmapmerge.set() + suite_cstsmapsplit.set() suite_csworkflow.set() # Append tests to container @@ -148,8 +148,8 @@ def test(installed=False, debug=False): suites.append(suite_cssens) suites.append(suite_csspec) suites.append(suite_cstsdist) - suites.append(suite_cstsmapsplit) suites.append(suite_cstsmapmerge) + suites.append(suite_cstsmapsplit) suites.append(suite_csworkflow) # Append tests for Python 2.6+ (the IACT cscripts depend on the json