From 00a109e49192d0454097e14c615d9356e899bcd8 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 20 Jul 2018 17:12:43 +0200 Subject: [PATCH] Add pickling unit tests (#2421) --- test/test_cslightcrv.py | 3 +++ test/test_csphagen.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ test/test_csphasecrv.py | 41 +++++++++++++++++++++++++++++++++++++++++ test/test_cspull.py | 43 +++++++++++++++++++++++++++++++++++++++++++ test/test_cssens.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- test/test_csspec.py | 40 ++++++++++++++++++++++++++++++++++++++++ test/test_cstsdist.py | 43 +++++++++++++++++++++++++++++++++++++++---- 7 files changed, 258 insertions(+), 6 deletions(-) diff --git a/test/test_cslightcrv.py b/test/test_cslightcrv.py index b0251a7..8723e32 100755 --- a/test/test_cslightcrv.py +++ b/test/test_cslightcrv.py @@ -340,6 +340,9 @@ class Test(test): obj.run() obj.save() + # Check light curve + self._check_light_curve('cslightcrv_py1_pickle.fits', 3) + # Return return diff --git a/test/test_csphagen.py b/test/test_csphagen.py index a2e044c..3e7b5d5 100644 --- a/test/test_csphagen.py +++ b/test/test_csphagen.py @@ -68,6 +68,7 @@ class Test(test): # Append tests self.append(self._test_cmd, 'Test csphagen on command line') self.append(self._test_python, 'Test csphagen from Python') + self.append(self._test_pickeling, 'Test csphagen pickeling') # Return return @@ -329,6 +330,54 @@ class Test(test): # Return return + # Test csphagen pickeling + def _test_pickeling(self): + """ + Test csphagen pickeling + """ + # Perform pickeling tests of empty class + self._pickeling(cscripts.csphagen()) + + # Set-up csphagen + phagen = cscripts.csphagen() + phagen['inobs'] = self._myevents1 + phagen['inmodel'] = 'NONE' + phagen['caldb'] = self._caldb + phagen['irf'] = self._irf + phagen['ebinalg'] = 'LOG' + phagen['emin'] = 0.1 + phagen['emax'] = 100.0 + phagen['enumbins'] = self._nbins + phagen['coordsys'] = 'CEL' + phagen['ra'] = 83.633 + phagen['dec'] = 22.0145 + phagen['rad'] = 0.2 + phagen['stack'] = False + phagen['inexclusion'] = self._exclusion + phagen['bkgmethod'] = 'REFLECTED' + phagen['etruemin'] = 0.05 + phagen['etruemax'] = 150.0 + phagen['etruebins'] = 5 + phagen['outobs'] = 'csphagen_py1_pickle.xml' + phagen['prefix'] = 'csphagen_py1_pickle' + phagen['logfile'] = 'csphagen_py1_pickle.log' + phagen['chatter'] = 1 + + # Perform pickeling tests of filled class + obj = self._pickeling(phagen) + + # Run csspec script and save light curve + obj.logFileOpen() # Make sure we get a log file + obj.run() + obj.save() + + # Check result files + self._check_output('csphagen_py1_pickle', self._nbins, self._nreg_with_excl) + self._check_outobs('csphagen_py1_pickle', 1) + + # Return + return + def _check_ebounds(self, table, bins): """ Check EBOUNDS table diff --git a/test/test_csphasecrv.py b/test/test_csphasecrv.py index 0afa539..d437ec5 100755 --- a/test/test_csphasecrv.py +++ b/test/test_csphasecrv.py @@ -61,6 +61,7 @@ class Test(test): # Append tests self.append(self._test_cmd, 'Test csphasecrv on command line') self.append(self._test_python, 'Test csphasecrv from Python') + self.append(self._test_pickeling, 'Test csphasecrv pickeling') # Return return @@ -298,6 +299,46 @@ class Test(test): # Return return + # Test csphasecrv pickeling + def _test_pickeling(self): + """ + Test csphasecrv pickeling + """ + # Perform pickeling tests of empty class + self._pickeling(cscripts.csphasecrv()) + + # Set-up unbinned csphasecrv + pcrv = cscripts.csphasecrv() + pcrv['inobs'] = self._phased_events + pcrv['inmodel'] = self._model + pcrv['srcname'] = 'Crab' + pcrv['caldb'] = self._caldb + pcrv['irf'] = self._irf + pcrv['phbinalg'] = 'LIN' + pcrv['phbins'] = 5 + pcrv['method'] = '3D' + pcrv['enumbins'] = 0 + pcrv['emin'] = 0.1 + pcrv['emax'] = 100.0 + pcrv['outfile'] = 'csphasecrv_py1_pickle.fits' + pcrv['logfile'] = 'csphasecrv_py1_pickle.log' + pcrv['chatter'] = 2 + pcrv['publish'] = True + + # Perform pickeling tests of filled class + obj = self._pickeling(pcrv) + + # Run csphasecrv script and save light curve + obj.logFileOpen() # Make sure we get a log file + obj.run() + obj.save() + + # Check phase curve + self._check_phase_curve('csphasecrv_py1_pickle.fits', 5) + + # Return + return + # Check phase curve result file def _check_phase_curve(self, filename, bins): """ diff --git a/test/test_cspull.py b/test/test_cspull.py index f0dbced..e2c8f7a 100755 --- a/test/test_cspull.py +++ b/test/test_cspull.py @@ -62,6 +62,7 @@ class Test(test): # Append tests self.append(self._test_cmd, 'Test cspull on command line') self.append(self._test_python, 'Test cspull from Python') + self.append(self._test_pickeling, 'Test cspull pickeling') # Return return @@ -291,6 +292,48 @@ class Test(test): # Return return + # Test cspull pickeling + def _test_pickeling(self): + """ + Test cspull pickeling + """ + # Perform pickeling tests of empty class + self._pickeling(cscripts.cspull()) + + # Set-up unbinned cspull + pull = cscripts.cspull() + pull['inmodel'] = self._model + pull['onsrc'] = 'NONE' + pull['ntrials'] = 2 + pull['caldb'] = self._caldb + pull['irf'] = self._irf + pull['ra'] = 83.6331 + pull['dec'] = 22.0145 + pull['emin'] = 0.1 + pull['emax'] = 100.0 + pull['enumbins'] = 0 + pull['tmin'] = 0.0 + pull['tmax'] = 100.0 + pull['deadc'] = 0.98 + pull['rad'] = 5.0 + pull['logfile'] = 'cspull_py1_pickle.log' + pull['outfile'] = 'cspull_py1_pickle.dat' + pull['chatter'] = 2 + + # Perform pickeling tests of filled class + obj = self._pickeling(pull) + + # Run csphasecrv script and save light curve + obj.logFileOpen() # Make sure we get a log file + obj.run() + #obj.save() + + # Check pull distribution file + self._check_pull_file('cspull_py1_pickle.dat') + + # Return + return + # Check pull file def _check_pull_file(self, filename, rows=3): """ diff --git a/test/test_cssens.py b/test/test_cssens.py index 97efc06..61fa1d6 100755 --- a/test/test_cssens.py +++ b/test/test_cssens.py @@ -59,6 +59,7 @@ class Test(test): # Append tests self.append(self._test_cmd, 'Test cssens on command line') self.append(self._test_python, 'Test cssens from Python') + self.append(self._test_pickeling, 'Test cssens pickeling') # Return return @@ -109,7 +110,8 @@ class Test(test): """ Test cssens from Python """ - # Set-up cssens for differential sensitivity computation with multiprocessing + # Set-up cssens for differential sensitivity computation with + # multiprocessing sens = cscripts.cssens() sens['inobs'] = 'NONE' sens['inmodel'] = self._model @@ -133,7 +135,8 @@ class Test(test): # Check pull distribution file self._check_result_file('cssens_py1.dat',nrows=3) - # Set-up cssens for integral sensitivity computation without multiprocessing + # Set-up cssens for integral sensitivity computation without + # multiprocessing sens = cscripts.cssens() sens['inobs'] = 'NONE' sens['inmodel'] = self._model @@ -160,6 +163,44 @@ class Test(test): # Return return + # Test cssens pickeling + def _test_pickeling(self): + """ + Test cssens pickeling + """ + # Perform pickeling tests of empty class + self._pickeling(cscripts.cssens()) + + # Set-up unbinned cssens + sens = cscripts.cssens() + sens['inobs'] = 'NONE' + sens['inmodel'] = self._model + sens['srcname'] = 'Crab' + sens['caldb'] = self._caldb + sens['irf'] = self._irf + sens['outfile'] = 'cssens_py1_pickle.dat' + sens['duration'] = 180.0 + sens['rad'] = 3.0 + sens['emin'] = 1.0 + sens['emax'] = 10.0 + sens['bins'] = 2 + sens['logfile'] = 'cssens_py1_pickle.log' + sens['chatter'] = 4 + + # Perform pickeling tests of filled class + obj = self._pickeling(sens) + + # Run csspec script and save light curve + obj.logFileOpen() # Make sure we get a log file + obj.run() + obj.save() + + # Check result file + self._check_result_file('cssens_py1_pickle.dat',nrows=3) + + # Return + return + # Check result file def _check_result_file(self, filename, nrows=2): """ diff --git a/test/test_csspec.py b/test/test_csspec.py index b73a75b..7b46b86 100755 --- a/test/test_csspec.py +++ b/test/test_csspec.py @@ -66,6 +66,7 @@ class Test(test): # Append tests self.append(self._test_cmd, 'Test csspec on command line') self.append(self._test_python, 'Test csspec from Python') + self.append(self._test_pickeling, 'Test csspec pickeling') # Return return @@ -260,6 +261,45 @@ class Test(test): # Return return + # Test csspec pickeling + def _test_pickeling(self): + """ + Test csspec pickeling + """ + # Perform pickeling tests of empty class + self._pickeling(cscripts.csspec()) + + # Set-up unbinned csspec + spec = cscripts.csspec() + spec['inobs'] = self._events + spec['inmodel'] = self._model + spec['srcname'] = 'Crab' + spec['caldb'] = self._caldb + spec['irf'] = self._irf + spec['method'] = 'AUTO' + spec['ebinalg'] = 'LOG' + spec['enumbins'] = 5 + spec['emin'] = 0.1 + spec['emax'] = 100.0 + spec['outfile'] = 'csspec_py1_pickle.fits' + spec['logfile'] = 'csspec_py1_pickle.log' + spec['chatter'] = 2 + spec['publish'] = True + + # Perform pickeling tests of filled class + obj = self._pickeling(spec) + + # Run csspec script and save light curve + obj.logFileOpen() # Make sure we get a log file + obj.run() + obj.save() + + # Check result file + self._check_result_file('csspec_py1_pickle.fits', 5) + + # Return + return + # Check result file def _check_result_file(self, filename, bins): """ diff --git a/test/test_cstsdist.py b/test/test_cstsdist.py index 9b2e6f9..0324f41 100755 --- a/test/test_cstsdist.py +++ b/test/test_cstsdist.py @@ -65,6 +65,7 @@ class Test(test): 'Test cstsdist from Python in binned mode') self.append(self._test_python_stacked, 'Test cstsdist from Python in stacked mode') + self.append(self._test_pickeling, 'Test cstsdist pickeling') # Return return @@ -132,7 +133,7 @@ class Test(test): tsdist.run() tsdist.save() - # Check pull distribution file + # Check TS distribution file self._check_result_file('cstsdist_py1.dat') # Set-up cstsdist without multiprocessing @@ -153,7 +154,7 @@ class Test(test): tsdist.run() tsdist.save() - # Check pull distribution file + # Check TS distribution file self._check_result_file('cstsdist_py2.dat') # Return @@ -182,7 +183,7 @@ class Test(test): tsdist.logFileOpen() # Make sure we get a log file tsdist.execute() - # Check pull distribution file + # Check TS distribution file self._check_result_file('cstsdist_py2.dat') # Return @@ -206,12 +207,46 @@ class Test(test): tsdist.logFileOpen() # Make sure we get a log file tsdist.execute() - # Check pull distribution file + # Check TS distribution file self._check_result_file('cstsdist_py3.dat') # Return return + # Test cstsdist pickeling + def _test_pickeling(self): + """ + Test cstsdist pickeling + """ + # Perform pickeling tests of empty class + self._pickeling(cscripts.cstsdist()) + + # Set-up cstsdist for event list + tsdist = cscripts.cstsdist() + tsdist['inobs'] = self._events + tsdist['inmodel'] = self._model + tsdist['srcname'] = 'Crab' + tsdist['caldb'] = self._caldb + tsdist['irf'] = self._irf + tsdist['ntrials'] = 2 + tsdist['outfile'] = 'cstsdist_py1_pickle.dat' + tsdist['logfile'] = 'cstsdist_py1_pickle.log' + tsdist['chatter'] = 3 + + # Perform pickeling tests of filled class + obj = self._pickeling(tsdist) + + # Run csphasecrv script and save light curve + obj.logFileOpen() # Make sure we get a log file + obj.run() + obj.save() + + # Check TS distribution file + self._check_result_file('cstsdist_py1_pickle.dat') + + # Return + return + # Check result file def _check_result_file(self, filename, nrows=3, ncols=9): """ -- libgit2 0.21.4