Commit 00a109e49192d0454097e14c615d9356e899bcd8
1 parent
b39b19cb
Add pickling unit tests (#2421)
Showing
7 changed files
with
258 additions
and
6 deletions
test/test_cslightcrv.py
test/test_csphagen.py
| @@ -68,6 +68,7 @@ class Test(test): | @@ -68,6 +68,7 @@ class Test(test): | ||
| 68 | # Append tests | 68 | # Append tests |
| 69 | self.append(self._test_cmd, 'Test csphagen on command line') | 69 | self.append(self._test_cmd, 'Test csphagen on command line') |
| 70 | self.append(self._test_python, 'Test csphagen from Python') | 70 | self.append(self._test_python, 'Test csphagen from Python') |
| 71 | + self.append(self._test_pickeling, 'Test csphagen pickeling') | ||
| 71 | 72 | ||
| 72 | # Return | 73 | # Return |
| 73 | return | 74 | return |
| @@ -329,6 +330,54 @@ class Test(test): | @@ -329,6 +330,54 @@ class Test(test): | ||
| 329 | # Return | 330 | # Return |
| 330 | return | 331 | return |
| 331 | 332 | ||
| 333 | + # Test csphagen pickeling | ||
| 334 | + def _test_pickeling(self): | ||
| 335 | + """ | ||
| 336 | + Test csphagen pickeling | ||
| 337 | + """ | ||
| 338 | + # Perform pickeling tests of empty class | ||
| 339 | + self._pickeling(cscripts.csphagen()) | ||
| 340 | + | ||
| 341 | + # Set-up csphagen | ||
| 342 | + phagen = cscripts.csphagen() | ||
| 343 | + phagen['inobs'] = self._myevents1 | ||
| 344 | + phagen['inmodel'] = 'NONE' | ||
| 345 | + phagen['caldb'] = self._caldb | ||
| 346 | + phagen['irf'] = self._irf | ||
| 347 | + phagen['ebinalg'] = 'LOG' | ||
| 348 | + phagen['emin'] = 0.1 | ||
| 349 | + phagen['emax'] = 100.0 | ||
| 350 | + phagen['enumbins'] = self._nbins | ||
| 351 | + phagen['coordsys'] = 'CEL' | ||
| 352 | + phagen['ra'] = 83.633 | ||
| 353 | + phagen['dec'] = 22.0145 | ||
| 354 | + phagen['rad'] = 0.2 | ||
| 355 | + phagen['stack'] = False | ||
| 356 | + phagen['inexclusion'] = self._exclusion | ||
| 357 | + phagen['bkgmethod'] = 'REFLECTED' | ||
| 358 | + phagen['etruemin'] = 0.05 | ||
| 359 | + phagen['etruemax'] = 150.0 | ||
| 360 | + phagen['etruebins'] = 5 | ||
| 361 | + phagen['outobs'] = 'csphagen_py1_pickle.xml' | ||
| 362 | + phagen['prefix'] = 'csphagen_py1_pickle' | ||
| 363 | + phagen['logfile'] = 'csphagen_py1_pickle.log' | ||
| 364 | + phagen['chatter'] = 1 | ||
| 365 | + | ||
| 366 | + # Perform pickeling tests of filled class | ||
| 367 | + obj = self._pickeling(phagen) | ||
| 368 | + | ||
| 369 | + # Run csspec script and save light curve | ||
| 370 | + obj.logFileOpen() # Make sure we get a log file | ||
| 371 | + obj.run() | ||
| 372 | + obj.save() | ||
| 373 | + | ||
| 374 | + # Check result files | ||
| 375 | + self._check_output('csphagen_py1_pickle', self._nbins, self._nreg_with_excl) | ||
| 376 | + self._check_outobs('csphagen_py1_pickle', 1) | ||
| 377 | + | ||
| 378 | + # Return | ||
| 379 | + return | ||
| 380 | + | ||
| 332 | def _check_ebounds(self, table, bins): | 381 | def _check_ebounds(self, table, bins): |
| 333 | """ | 382 | """ |
| 334 | Check EBOUNDS table | 383 | Check EBOUNDS table |
test/test_csphasecrv.py
| @@ -61,6 +61,7 @@ class Test(test): | @@ -61,6 +61,7 @@ class Test(test): | ||
| 61 | # Append tests | 61 | # Append tests |
| 62 | self.append(self._test_cmd, 'Test csphasecrv on command line') | 62 | self.append(self._test_cmd, 'Test csphasecrv on command line') |
| 63 | self.append(self._test_python, 'Test csphasecrv from Python') | 63 | self.append(self._test_python, 'Test csphasecrv from Python') |
| 64 | + self.append(self._test_pickeling, 'Test csphasecrv pickeling') | ||
| 64 | 65 | ||
| 65 | # Return | 66 | # Return |
| 66 | return | 67 | return |
| @@ -298,6 +299,46 @@ class Test(test): | @@ -298,6 +299,46 @@ class Test(test): | ||
| 298 | # Return | 299 | # Return |
| 299 | return | 300 | return |
| 300 | 301 | ||
| 302 | + # Test csphasecrv pickeling | ||
| 303 | + def _test_pickeling(self): | ||
| 304 | + """ | ||
| 305 | + Test csphasecrv pickeling | ||
| 306 | + """ | ||
| 307 | + # Perform pickeling tests of empty class | ||
| 308 | + self._pickeling(cscripts.csphasecrv()) | ||
| 309 | + | ||
| 310 | + # Set-up unbinned csphasecrv | ||
| 311 | + pcrv = cscripts.csphasecrv() | ||
| 312 | + pcrv['inobs'] = self._phased_events | ||
| 313 | + pcrv['inmodel'] = self._model | ||
| 314 | + pcrv['srcname'] = 'Crab' | ||
| 315 | + pcrv['caldb'] = self._caldb | ||
| 316 | + pcrv['irf'] = self._irf | ||
| 317 | + pcrv['phbinalg'] = 'LIN' | ||
| 318 | + pcrv['phbins'] = 5 | ||
| 319 | + pcrv['method'] = '3D' | ||
| 320 | + pcrv['enumbins'] = 0 | ||
| 321 | + pcrv['emin'] = 0.1 | ||
| 322 | + pcrv['emax'] = 100.0 | ||
| 323 | + pcrv['outfile'] = 'csphasecrv_py1_pickle.fits' | ||
| 324 | + pcrv['logfile'] = 'csphasecrv_py1_pickle.log' | ||
| 325 | + pcrv['chatter'] = 2 | ||
| 326 | + pcrv['publish'] = True | ||
| 327 | + | ||
| 328 | + # Perform pickeling tests of filled class | ||
| 329 | + obj = self._pickeling(pcrv) | ||
| 330 | + | ||
| 331 | + # Run csphasecrv script and save light curve | ||
| 332 | + obj.logFileOpen() # Make sure we get a log file | ||
| 333 | + obj.run() | ||
| 334 | + obj.save() | ||
| 335 | + | ||
| 336 | + # Check phase curve | ||
| 337 | + self._check_phase_curve('csphasecrv_py1_pickle.fits', 5) | ||
| 338 | + | ||
| 339 | + # Return | ||
| 340 | + return | ||
| 341 | + | ||
| 301 | # Check phase curve result file | 342 | # Check phase curve result file |
| 302 | def _check_phase_curve(self, filename, bins): | 343 | def _check_phase_curve(self, filename, bins): |
| 303 | """ | 344 | """ |
test/test_cspull.py
| @@ -62,6 +62,7 @@ class Test(test): | @@ -62,6 +62,7 @@ class Test(test): | ||
| 62 | # Append tests | 62 | # Append tests |
| 63 | self.append(self._test_cmd, 'Test cspull on command line') | 63 | self.append(self._test_cmd, 'Test cspull on command line') |
| 64 | self.append(self._test_python, 'Test cspull from Python') | 64 | self.append(self._test_python, 'Test cspull from Python') |
| 65 | + self.append(self._test_pickeling, 'Test cspull pickeling') | ||
| 65 | 66 | ||
| 66 | # Return | 67 | # Return |
| 67 | return | 68 | return |
| @@ -291,6 +292,48 @@ class Test(test): | @@ -291,6 +292,48 @@ class Test(test): | ||
| 291 | # Return | 292 | # Return |
| 292 | return | 293 | return |
| 293 | 294 | ||
| 295 | + # Test cspull pickeling | ||
| 296 | + def _test_pickeling(self): | ||
| 297 | + """ | ||
| 298 | + Test cspull pickeling | ||
| 299 | + """ | ||
| 300 | + # Perform pickeling tests of empty class | ||
| 301 | + self._pickeling(cscripts.cspull()) | ||
| 302 | + | ||
| 303 | + # Set-up unbinned cspull | ||
| 304 | + pull = cscripts.cspull() | ||
| 305 | + pull['inmodel'] = self._model | ||
| 306 | + pull['onsrc'] = 'NONE' | ||
| 307 | + pull['ntrials'] = 2 | ||
| 308 | + pull['caldb'] = self._caldb | ||
| 309 | + pull['irf'] = self._irf | ||
| 310 | + pull['ra'] = 83.6331 | ||
| 311 | + pull['dec'] = 22.0145 | ||
| 312 | + pull['emin'] = 0.1 | ||
| 313 | + pull['emax'] = 100.0 | ||
| 314 | + pull['enumbins'] = 0 | ||
| 315 | + pull['tmin'] = 0.0 | ||
| 316 | + pull['tmax'] = 100.0 | ||
| 317 | + pull['deadc'] = 0.98 | ||
| 318 | + pull['rad'] = 5.0 | ||
| 319 | + pull['logfile'] = 'cspull_py1_pickle.log' | ||
| 320 | + pull['outfile'] = 'cspull_py1_pickle.dat' | ||
| 321 | + pull['chatter'] = 2 | ||
| 322 | + | ||
| 323 | + # Perform pickeling tests of filled class | ||
| 324 | + obj = self._pickeling(pull) | ||
| 325 | + | ||
| 326 | + # Run csphasecrv script and save light curve | ||
| 327 | + obj.logFileOpen() # Make sure we get a log file | ||
| 328 | + obj.run() | ||
| 329 | + #obj.save() | ||
| 330 | + | ||
| 331 | + # Check pull distribution file | ||
| 332 | + self._check_pull_file('cspull_py1_pickle.dat') | ||
| 333 | + | ||
| 334 | + # Return | ||
| 335 | + return | ||
| 336 | + | ||
| 294 | # Check pull file | 337 | # Check pull file |
| 295 | def _check_pull_file(self, filename, rows=3): | 338 | def _check_pull_file(self, filename, rows=3): |
| 296 | """ | 339 | """ |
test/test_cssens.py
| @@ -59,6 +59,7 @@ class Test(test): | @@ -59,6 +59,7 @@ class Test(test): | ||
| 59 | # Append tests | 59 | # Append tests |
| 60 | self.append(self._test_cmd, 'Test cssens on command line') | 60 | self.append(self._test_cmd, 'Test cssens on command line') |
| 61 | self.append(self._test_python, 'Test cssens from Python') | 61 | self.append(self._test_python, 'Test cssens from Python') |
| 62 | + self.append(self._test_pickeling, 'Test cssens pickeling') | ||
| 62 | 63 | ||
| 63 | # Return | 64 | # Return |
| 64 | return | 65 | return |
| @@ -109,7 +110,8 @@ class Test(test): | @@ -109,7 +110,8 @@ class Test(test): | ||
| 109 | """ | 110 | """ |
| 110 | Test cssens from Python | 111 | Test cssens from Python |
| 111 | """ | 112 | """ |
| 112 | - # Set-up cssens for differential sensitivity computation with multiprocessing | 113 | + # Set-up cssens for differential sensitivity computation with |
| 114 | + # multiprocessing | ||
| 113 | sens = cscripts.cssens() | 115 | sens = cscripts.cssens() |
| 114 | sens['inobs'] = 'NONE' | 116 | sens['inobs'] = 'NONE' |
| 115 | sens['inmodel'] = self._model | 117 | sens['inmodel'] = self._model |
| @@ -133,7 +135,8 @@ class Test(test): | @@ -133,7 +135,8 @@ class Test(test): | ||
| 133 | # Check pull distribution file | 135 | # Check pull distribution file |
| 134 | self._check_result_file('cssens_py1.dat',nrows=3) | 136 | self._check_result_file('cssens_py1.dat',nrows=3) |
| 135 | 137 | ||
| 136 | - # Set-up cssens for integral sensitivity computation without multiprocessing | 138 | + # Set-up cssens for integral sensitivity computation without |
| 139 | + # multiprocessing | ||
| 137 | sens = cscripts.cssens() | 140 | sens = cscripts.cssens() |
| 138 | sens['inobs'] = 'NONE' | 141 | sens['inobs'] = 'NONE' |
| 139 | sens['inmodel'] = self._model | 142 | sens['inmodel'] = self._model |
| @@ -160,6 +163,44 @@ class Test(test): | @@ -160,6 +163,44 @@ class Test(test): | ||
| 160 | # Return | 163 | # Return |
| 161 | return | 164 | return |
| 162 | 165 | ||
| 166 | + # Test cssens pickeling | ||
| 167 | + def _test_pickeling(self): | ||
| 168 | + """ | ||
| 169 | + Test cssens pickeling | ||
| 170 | + """ | ||
| 171 | + # Perform pickeling tests of empty class | ||
| 172 | + self._pickeling(cscripts.cssens()) | ||
| 173 | + | ||
| 174 | + # Set-up unbinned cssens | ||
| 175 | + sens = cscripts.cssens() | ||
| 176 | + sens['inobs'] = 'NONE' | ||
| 177 | + sens['inmodel'] = self._model | ||
| 178 | + sens['srcname'] = 'Crab' | ||
| 179 | + sens['caldb'] = self._caldb | ||
| 180 | + sens['irf'] = self._irf | ||
| 181 | + sens['outfile'] = 'cssens_py1_pickle.dat' | ||
| 182 | + sens['duration'] = 180.0 | ||
| 183 | + sens['rad'] = 3.0 | ||
| 184 | + sens['emin'] = 1.0 | ||
| 185 | + sens['emax'] = 10.0 | ||
| 186 | + sens['bins'] = 2 | ||
| 187 | + sens['logfile'] = 'cssens_py1_pickle.log' | ||
| 188 | + sens['chatter'] = 4 | ||
| 189 | + | ||
| 190 | + # Perform pickeling tests of filled class | ||
| 191 | + obj = self._pickeling(sens) | ||
| 192 | + | ||
| 193 | + # Run csspec script and save light curve | ||
| 194 | + obj.logFileOpen() # Make sure we get a log file | ||
| 195 | + obj.run() | ||
| 196 | + obj.save() | ||
| 197 | + | ||
| 198 | + # Check result file | ||
| 199 | + self._check_result_file('cssens_py1_pickle.dat',nrows=3) | ||
| 200 | + | ||
| 201 | + # Return | ||
| 202 | + return | ||
| 203 | + | ||
| 163 | # Check result file | 204 | # Check result file |
| 164 | def _check_result_file(self, filename, nrows=2): | 205 | def _check_result_file(self, filename, nrows=2): |
| 165 | """ | 206 | """ |
test/test_csspec.py
| @@ -66,6 +66,7 @@ class Test(test): | @@ -66,6 +66,7 @@ class Test(test): | ||
| 66 | # Append tests | 66 | # Append tests |
| 67 | self.append(self._test_cmd, 'Test csspec on command line') | 67 | self.append(self._test_cmd, 'Test csspec on command line') |
| 68 | self.append(self._test_python, 'Test csspec from Python') | 68 | self.append(self._test_python, 'Test csspec from Python') |
| 69 | + self.append(self._test_pickeling, 'Test csspec pickeling') | ||
| 69 | 70 | ||
| 70 | # Return | 71 | # Return |
| 71 | return | 72 | return |
| @@ -260,6 +261,45 @@ class Test(test): | @@ -260,6 +261,45 @@ class Test(test): | ||
| 260 | # Return | 261 | # Return |
| 261 | return | 262 | return |
| 262 | 263 | ||
| 264 | + # Test csspec pickeling | ||
| 265 | + def _test_pickeling(self): | ||
| 266 | + """ | ||
| 267 | + Test csspec pickeling | ||
| 268 | + """ | ||
| 269 | + # Perform pickeling tests of empty class | ||
| 270 | + self._pickeling(cscripts.csspec()) | ||
| 271 | + | ||
| 272 | + # Set-up unbinned csspec | ||
| 273 | + spec = cscripts.csspec() | ||
| 274 | + spec['inobs'] = self._events | ||
| 275 | + spec['inmodel'] = self._model | ||
| 276 | + spec['srcname'] = 'Crab' | ||
| 277 | + spec['caldb'] = self._caldb | ||
| 278 | + spec['irf'] = self._irf | ||
| 279 | + spec['method'] = 'AUTO' | ||
| 280 | + spec['ebinalg'] = 'LOG' | ||
| 281 | + spec['enumbins'] = 5 | ||
| 282 | + spec['emin'] = 0.1 | ||
| 283 | + spec['emax'] = 100.0 | ||
| 284 | + spec['outfile'] = 'csspec_py1_pickle.fits' | ||
| 285 | + spec['logfile'] = 'csspec_py1_pickle.log' | ||
| 286 | + spec['chatter'] = 2 | ||
| 287 | + spec['publish'] = True | ||
| 288 | + | ||
| 289 | + # Perform pickeling tests of filled class | ||
| 290 | + obj = self._pickeling(spec) | ||
| 291 | + | ||
| 292 | + # Run csspec script and save light curve | ||
| 293 | + obj.logFileOpen() # Make sure we get a log file | ||
| 294 | + obj.run() | ||
| 295 | + obj.save() | ||
| 296 | + | ||
| 297 | + # Check result file | ||
| 298 | + self._check_result_file('csspec_py1_pickle.fits', 5) | ||
| 299 | + | ||
| 300 | + # Return | ||
| 301 | + return | ||
| 302 | + | ||
| 263 | # Check result file | 303 | # Check result file |
| 264 | def _check_result_file(self, filename, bins): | 304 | def _check_result_file(self, filename, bins): |
| 265 | """ | 305 | """ |
test/test_cstsdist.py
| @@ -65,6 +65,7 @@ class Test(test): | @@ -65,6 +65,7 @@ class Test(test): | ||
| 65 | 'Test cstsdist from Python in binned mode') | 65 | 'Test cstsdist from Python in binned mode') |
| 66 | self.append(self._test_python_stacked, | 66 | self.append(self._test_python_stacked, |
| 67 | 'Test cstsdist from Python in stacked mode') | 67 | 'Test cstsdist from Python in stacked mode') |
| 68 | + self.append(self._test_pickeling, 'Test cstsdist pickeling') | ||
| 68 | 69 | ||
| 69 | # Return | 70 | # Return |
| 70 | return | 71 | return |
| @@ -132,7 +133,7 @@ class Test(test): | @@ -132,7 +133,7 @@ class Test(test): | ||
| 132 | tsdist.run() | 133 | tsdist.run() |
| 133 | tsdist.save() | 134 | tsdist.save() |
| 134 | 135 | ||
| 135 | - # Check pull distribution file | 136 | + # Check TS distribution file |
| 136 | self._check_result_file('cstsdist_py1.dat') | 137 | self._check_result_file('cstsdist_py1.dat') |
| 137 | 138 | ||
| 138 | # Set-up cstsdist without multiprocessing | 139 | # Set-up cstsdist without multiprocessing |
| @@ -153,7 +154,7 @@ class Test(test): | @@ -153,7 +154,7 @@ class Test(test): | ||
| 153 | tsdist.run() | 154 | tsdist.run() |
| 154 | tsdist.save() | 155 | tsdist.save() |
| 155 | 156 | ||
| 156 | - # Check pull distribution file | 157 | + # Check TS distribution file |
| 157 | self._check_result_file('cstsdist_py2.dat') | 158 | self._check_result_file('cstsdist_py2.dat') |
| 158 | 159 | ||
| 159 | # Return | 160 | # Return |
| @@ -182,7 +183,7 @@ class Test(test): | @@ -182,7 +183,7 @@ class Test(test): | ||
| 182 | tsdist.logFileOpen() # Make sure we get a log file | 183 | tsdist.logFileOpen() # Make sure we get a log file |
| 183 | tsdist.execute() | 184 | tsdist.execute() |
| 184 | 185 | ||
| 185 | - # Check pull distribution file | 186 | + # Check TS distribution file |
| 186 | self._check_result_file('cstsdist_py2.dat') | 187 | self._check_result_file('cstsdist_py2.dat') |
| 187 | 188 | ||
| 188 | # Return | 189 | # Return |
| @@ -206,12 +207,46 @@ class Test(test): | @@ -206,12 +207,46 @@ class Test(test): | ||
| 206 | tsdist.logFileOpen() # Make sure we get a log file | 207 | tsdist.logFileOpen() # Make sure we get a log file |
| 207 | tsdist.execute() | 208 | tsdist.execute() |
| 208 | 209 | ||
| 209 | - # Check pull distribution file | 210 | + # Check TS distribution file |
| 210 | self._check_result_file('cstsdist_py3.dat') | 211 | self._check_result_file('cstsdist_py3.dat') |
| 211 | 212 | ||
| 212 | # Return | 213 | # Return |
| 213 | return | 214 | return |
| 214 | 215 | ||
| 216 | + # Test cstsdist pickeling | ||
| 217 | + def _test_pickeling(self): | ||
| 218 | + """ | ||
| 219 | + Test cstsdist pickeling | ||
| 220 | + """ | ||
| 221 | + # Perform pickeling tests of empty class | ||
| 222 | + self._pickeling(cscripts.cstsdist()) | ||
| 223 | + | ||
| 224 | + # Set-up cstsdist for event list | ||
| 225 | + tsdist = cscripts.cstsdist() | ||
| 226 | + tsdist['inobs'] = self._events | ||
| 227 | + tsdist['inmodel'] = self._model | ||
| 228 | + tsdist['srcname'] = 'Crab' | ||
| 229 | + tsdist['caldb'] = self._caldb | ||
| 230 | + tsdist['irf'] = self._irf | ||
| 231 | + tsdist['ntrials'] = 2 | ||
| 232 | + tsdist['outfile'] = 'cstsdist_py1_pickle.dat' | ||
| 233 | + tsdist['logfile'] = 'cstsdist_py1_pickle.log' | ||
| 234 | + tsdist['chatter'] = 3 | ||
| 235 | + | ||
| 236 | + # Perform pickeling tests of filled class | ||
| 237 | + obj = self._pickeling(tsdist) | ||
| 238 | + | ||
| 239 | + # Run csphasecrv script and save light curve | ||
| 240 | + obj.logFileOpen() # Make sure we get a log file | ||
| 241 | + obj.run() | ||
| 242 | + obj.save() | ||
| 243 | + | ||
| 244 | + # Check TS distribution file | ||
| 245 | + self._check_result_file('cstsdist_py1_pickle.dat') | ||
| 246 | + | ||
| 247 | + # Return | ||
| 248 | + return | ||
| 249 | + | ||
| 215 | # Check result file | 250 | # Check result file |
| 216 | def _check_result_file(self, filename, nrows=3, ncols=9): | 251 | def _check_result_file(self, filename, nrows=3, ncols=9): |
| 217 | """ | 252 | """ |