Commit d5cd93bc76ac30c324f9d28b30fab60151d7e45c
1 parent
35b73225
first complete version
Showing
1 changed file
with
70 additions
and
21 deletions
test/test_csphagen.py
| @@ -41,11 +41,14 @@ class Test(test): | @@ -41,11 +41,14 @@ class Test(test): | ||
| 41 | """ | 41 | """ |
| 42 | # Call base class constructor | 42 | # Call base class constructor |
| 43 | test.__init__(self) | 43 | test.__init__(self) |
| 44 | - self._myevents = self._datadir + '/crab_offaxis1.fits' | 44 | + self._myevents1 = self._datadir + '/crab_offaxis1.fits' |
| 45 | + self._myevents2 = self._datadir + '/crab_offaxis2.fits' | ||
| 45 | self._exclusion = self._datadir + '/crab_exclusion.fits' | 46 | self._exclusion = self._datadir + '/crab_exclusion.fits' |
| 46 | self._nreg_with_excl = 5 | 47 | self._nreg_with_excl = 5 |
| 47 | self._nreg_wo_excl = 8 | 48 | self._nreg_wo_excl = 8 |
| 48 | - # number of expected background regions with/wo exclusion | 49 | + self._nreg_mul = [self._nreg_with_excl, 6] |
| 50 | + # number of expected background regions with/wo exclusion, | ||
| 51 | + # and for two different runs | ||
| 49 | 52 | ||
| 50 | # Return | 53 | # Return |
| 51 | return | 54 | return |
| @@ -74,7 +77,7 @@ class Test(test): | @@ -74,7 +77,7 @@ class Test(test): | ||
| 74 | csphagen = self._script('csphagen') | 77 | csphagen = self._script('csphagen') |
| 75 | nbins = 120 | 78 | nbins = 120 |
| 76 | 79 | ||
| 77 | - cmd = csphagen + 'inobs="' + self._myevents + \ | 80 | + cmd = csphagen + 'inobs="' + self._myevents1 + \ |
| 78 | '" caldb="' + self._caldb + '" irf="' + self._irf + \ | 81 | '" caldb="' + self._caldb + '" irf="' + self._irf + \ |
| 79 | '" ebinalg=LOG emin=0.1 emax=100. enumbins="' + nbins + \ | 82 | '" ebinalg=LOG emin=0.1 emax=100. enumbins="' + nbins + \ |
| 80 | '" coordsys=CEL' + ' ra=83.633 dec=22.0145 rad=0.2 stack=no exclusion="' + \ | 83 | '" coordsys=CEL' + ' ra=83.633 dec=22.0145 rad=0.2 stack=no exclusion="' + \ |
| @@ -90,7 +93,8 @@ class Test(test): | @@ -90,7 +93,8 @@ class Test(test): | ||
| 90 | 'Check successful execution from command line') | 93 | 'Check successful execution from command line') |
| 91 | 94 | ||
| 92 | # Check output files | 95 | # Check output files |
| 93 | - self._check_output('genpha_cmd1', nbins, self._nreg_with_excl) | 96 | + self._check_output('genpha_cmd1_', nbins, self._nreg_with_excl) |
| 97 | + self._check_outobs('genpha_cmd1', 1) | ||
| 94 | 98 | ||
| 95 | cmd = csphagen + 'inobs="events_that_do_not_exist.fits"' + \ | 99 | cmd = csphagen + 'inobs="events_that_do_not_exist.fits"' + \ |
| 96 | '" caldb="' + self._caldb + '" irf="' + self._irf + \ | 100 | '" caldb="' + self._caldb + '" irf="' + self._irf + \ |
| @@ -104,7 +108,7 @@ class Test(test): | @@ -104,7 +108,7 @@ class Test(test): | ||
| 104 | 'Check invalid input file when executed from command line') | 108 | 'Check invalid input file when executed from command line') |
| 105 | 109 | ||
| 106 | # Check cslightcrv --help | 110 | # Check cslightcrv --help |
| 107 | - self._check_help(cslightcrv) | 111 | + self._check_help(csphagen) |
| 108 | 112 | ||
| 109 | # Return | 113 | # Return |
| 110 | return | 114 | return |
| @@ -117,12 +121,12 @@ class Test(test): | @@ -117,12 +121,12 @@ class Test(test): | ||
| 117 | 121 | ||
| 118 | # Same test as from command line | 122 | # Same test as from command line |
| 119 | phagen = cscripts.csphagen() | 123 | phagen = cscripts.csphagen() |
| 120 | - phagen['inobs'] = self._myevents | 124 | + phagen['inobs'] = self._myevents1 |
| 121 | phagen['caldb'] = self._caldb | 125 | phagen['caldb'] = self._caldb |
| 122 | phagen['irf'] = self._irf | 126 | phagen['irf'] = self._irf |
| 123 | phagen['ebinalg'] = 'LOG' | 127 | phagen['ebinalg'] = 'LOG' |
| 124 | phagen['emin'] = 0.1 | 128 | phagen['emin'] = 0.1 |
| 125 | - phagen['emax']= 100. | 129 | + phagen['emax'] = 100. |
| 126 | phagen['enumbins'] = nbins | 130 | phagen['enumbins'] = nbins |
| 127 | phagen['coordsys'] = 'CEL' | 131 | phagen['coordsys'] = 'CEL' |
| 128 | phagen['ra'] = 83.633 | 132 | phagen['ra'] = 83.633 |
| @@ -138,11 +142,12 @@ class Test(test): | @@ -138,11 +142,12 @@ class Test(test): | ||
| 138 | phagen.execute() | 142 | phagen.execute() |
| 139 | 143 | ||
| 140 | # Check outout | 144 | # Check outout |
| 141 | - self._check_output('genpha_py1', nbins, self._nreg_with_excl) | 145 | + self._check_output('genpha_py1_', nbins, self._nreg_with_excl) |
| 146 | + self._check_outobs('genpha_py1', 1) | ||
| 142 | 147 | ||
| 143 | - # Second test, now without exclusion region | 148 | + # Now test without exclusion region |
| 144 | phagen = cscripts.csphagen() | 149 | phagen = cscripts.csphagen() |
| 145 | - phagen['inobs'] = self._myevents | 150 | + phagen['inobs'] = self._myevents1 |
| 146 | phagen['caldb'] = self._caldb | 151 | phagen['caldb'] = self._caldb |
| 147 | phagen['irf'] = self._irf | 152 | phagen['irf'] = self._irf |
| 148 | phagen['ebinalg'] = 'LOG' | 153 | phagen['ebinalg'] = 'LOG' |
| @@ -162,8 +167,44 @@ class Test(test): | @@ -162,8 +167,44 @@ class Test(test): | ||
| 162 | phagen.execute() | 167 | phagen.execute() |
| 163 | 168 | ||
| 164 | # Check outout | 169 | # Check outout |
| 165 | - self._check_output('genpha_py2', nbins, self._nreg_wo_excl) | 170 | + self._check_output('genpha_py2_', nbins, self._nreg_wo_excl) |
| 171 | + self._check_outobs('genpha_py2', 1) | ||
| 172 | + | ||
| 173 | + # Test with multiple input observations, no stacking | ||
| 174 | + # Create observation container | ||
| 175 | + obs = gammalib.GObservations() | ||
| 176 | + for s, events in enumerate([self._myevents1, self._myevents2]): | ||
| 177 | + run = gammalib.GCTAObservation(events) | ||
| 178 | + run.id(str(s + 1)) | ||
| 179 | + run.response(self.irf, self.caldb) | ||
| 180 | + obs.append(run) | ||
| 181 | + | ||
| 182 | + # Setup csphagen | ||
| 183 | + phagen = cscripts.csphagen(obs) | ||
| 184 | + phagen['ebinalg'] = 'LOG' | ||
| 185 | + phagen['emin'] = 0.1 | ||
| 186 | + phagen['emax'] = 100. | ||
| 187 | + phagen['enumbins'] = nbins | ||
| 188 | + phagen['coordsys'] = 'CEL' | ||
| 189 | + phagen['ra'] = 83.633 | ||
| 190 | + phagen['dec'] = 22.0145 | ||
| 191 | + phagen['rad'] = 0.2 | ||
| 192 | + phagen['stack'] = False | ||
| 193 | + phagen['exclusion'] = self._exclusion | ||
| 194 | + phagen['outroot'] = 'genpha_py3' | ||
| 195 | + phagen['logfile'] = 'csphagen_py3.log' | ||
| 196 | + phagen['chatter'] = 1 | ||
| 197 | + | ||
| 198 | + # Run script | ||
| 199 | + phagen.execute() | ||
| 200 | + | ||
| 201 | + # Check outout | ||
| 202 | + for s in range(2): | ||
| 203 | + self._check_output('genpha_py3_' + str(s + 1), nbins, | ||
| 204 | + self._nreg_mul[s]) | ||
| 205 | + self._check_outobs('genpha_py3', 2) | ||
| 166 | 206 | ||
| 207 | + return | ||
| 167 | 208 | ||
| 168 | def _check_ebounds(self, table, bins): | 209 | def _check_ebounds(self, table, bins): |
| 169 | """ | 210 | """ |
| @@ -300,28 +341,36 @@ class Test(test): | @@ -300,28 +341,36 @@ class Test(test): | ||
| 300 | # Return | 341 | # Return |
| 301 | return | 342 | return |
| 302 | 343 | ||
| 303 | - def _check_output(self, filenameroot, bins, nreg): | 344 | + def _check_output(self, filenameroot, bins, nreg, nout): |
| 304 | """ | 345 | """ |
| 305 | Check the output from a csphagen run | 346 | Check the output from a csphagen run |
| 306 | """ | 347 | """ |
| 307 | 348 | ||
| 308 | # OGIP files | 349 | # OGIP files |
| 309 | - self._check_pha(filenameroot + '__pha_on.fits', bins) | ||
| 310 | - self._check_pha(filenameroot + '__pha_off.fits', bins) | ||
| 311 | - self._check_arf(filenameroot + '__arf.fits', bins) | ||
| 312 | - self._check_rmf(filenameroot + '__rmf.fits', bins) | 350 | + self._check_pha(filenameroot + '_pha_on.fits', bins) |
| 351 | + self._check_pha(filenameroot + '_pha_off.fits', bins) | ||
| 352 | + self._check_arf(filenameroot + '_arf.fits', bins) | ||
| 353 | + self._check_rmf(filenameroot + '_rmf.fits', bins) | ||
| 313 | 354 | ||
| 314 | # Observations | 355 | # Observations |
| 315 | - obs = gammalib.GObservations(filenameroot + '.xml') | ||
| 316 | - self.test_value(obs.size(), 1, 'Check for ' + str( | ||
| 317 | - number) + ' observations in XML file') | 356 | + |
| 318 | 357 | ||
| 319 | # Regions | 358 | # Regions |
| 320 | - reg = gammalib.GSkyRegions(filenameroot + "__on.reg") | 359 | + reg = gammalib.GSkyRegions(filenameroot + "_on.reg") |
| 321 | self.test_value(reg.size(), 1, 'Check for ' + str( | 360 | self.test_value(reg.size(), 1, 'Check for ' + str( |
| 322 | number) + ' region in source region file') | 361 | number) + ' region in source region file') |
| 323 | - reg = gammalib.GSkyRegions(filenameroot + "__off.reg") | 362 | + reg = gammalib.GSkyRegions(filenameroot + "_off.reg") |
| 324 | self.test_value(reg.size(), nreg, 'Check for ' + str( | 363 | self.test_value(reg.size(), nreg, 'Check for ' + str( |
| 325 | number) + ' region in background region file') | 364 | number) + ' region in background region file') |
| 326 | 365 | ||
| 327 | return | 366 | return |
| 367 | + | ||
| 368 | + def _check_outobs(self, filenameroot, nout): | ||
| 369 | + """ | ||
| 370 | + Check the output XML file containing ON/OFF observations | ||
| 371 | + """ | ||
| 372 | + obs = gammalib.GObservations(filenameroot + '.xml') | ||
| 373 | + self.test_value(obs.size(), nout, 'Check for ' + str( | ||
| 374 | + number) + ' observations in XML file') | ||
| 375 | + | ||
| 376 | + return |