Commit 25495305941ec1fefb934597d7ab203fc72d8d52
1 parent
40d2e152
working on stacking, broken by gammalib update
Showing
2 changed files
with
64 additions
and
19 deletions
cscripts/csphagen.py
| ... | ... | @@ -195,8 +195,7 @@ class csphagen(ctools.cscript): |
| 195 | 195 | bkg_reg.append(region) |
| 196 | 196 | if bkg_reg.size() >= 1 or ( |
| 197 | 197 | self._bkgmethod == "REFLECTED" and bkg_reg.size() >= self._bkgregmin): |
| 198 | - onoff = gammalib.GCTAOnOffObservation(obs, etrue, ereco, | |
| 199 | - self._src_reg, bkg_reg) | |
| 198 | + onoff = gammalib.GCTAOnOffObservation(obs, self._src_dir, etrue, ereco,self._src_reg, bkg_reg) | |
| 200 | 199 | onoff.id(obs.id()) |
| 201 | 200 | outobs.append(onoff) |
| 202 | 201 | else: |
| ... | ... | @@ -207,20 +206,38 @@ class csphagen(ctools.cscript): |
| 207 | 206 | |
| 208 | 207 | # Save PHA, ARF and RMFs |
| 209 | 208 | for obs in outobs: |
| 210 | - obs.on_spec().save( | |
| 211 | - self._outroot + '_{}_pha_on.fits'.format(obs.id()), | |
| 212 | - True) | |
| 213 | - obs.off_spec().save( | |
| 214 | - self._outroot + '_{}_pha_off.fits'.format(obs.id()), | |
| 215 | - True) | |
| 216 | - obs.arf().save(self._outroot + '_{}_arf.fits'.format(obs.id()), | |
| 217 | - True) | |
| 218 | - obs.rmf().save(self._outroot + '_{}_rmf.fits'.format(obs.id()), | |
| 219 | - True) | |
| 209 | + if outobs.size() < 2 or self._stack == False: | |
| 210 | + obs.on_spec().save( | |
| 211 | + self._outroot + '_{}_pha_on.fits'.format(obs.id()), | |
| 212 | + True) | |
| 213 | + obs.off_spec().save( | |
| 214 | + self._outroot + '_{}_pha_off.fits'.format(obs.id()), | |
| 215 | + True) | |
| 216 | + obs.arf().save(self._outroot + '_{}_arf.fits'.format(obs.id()), | |
| 217 | + True) | |
| 218 | + obs.rmf().save(self._outroot + '_{}_rmf.fits'.format(obs.id()), | |
| 219 | + True) | |
| 220 | 220 | obs.on_regions().save(self._outroot + '_{}_on.reg'.format(obs.id())) |
| 221 | 221 | obs.off_regions().save( |
| 222 | 222 | self._outroot + '_{}_off.reg'.format(obs.id())) |
| 223 | 223 | |
| 224 | + if outobs.size() > 1 and self._stack == True: | |
| 225 | + if self._logVerbose(): | |
| 226 | + msg = 'Stacking {} observations\n'.format( | |
| 227 | + outobs.size()) | |
| 228 | + self._log(msg) | |
| 229 | + outobs = gammalib.GCTAOnOffObservation(outobs) | |
| 230 | + outobs.on_spec().save( | |
| 231 | + self._outroot + '_stacked_pha_on.fits', | |
| 232 | + True) | |
| 233 | + outobs.off_spec().save( | |
| 234 | + self._outroot + '_stacked_pha_off.fits', | |
| 235 | + True) | |
| 236 | + outobs.arf().save(self._outroot + '_stacked_arf.fits', | |
| 237 | + True) | |
| 238 | + outobs.rmf().save(self._outroot + '_stacked_rmf.fits', | |
| 239 | + True) | |
| 240 | + | |
| 224 | 241 | # Save On/Off observations |
| 225 | 242 | outname = self._outroot + '.xml' |
| 226 | 243 | outobs.save(outname) | ... | ... |
test/test_csphagen.py
| ... | ... | @@ -204,6 +204,33 @@ class Test(test): |
| 204 | 204 | self._nreg_mul[s]) |
| 205 | 205 | self._check_outobs('phagen_py3', 2) |
| 206 | 206 | |
| 207 | + # Test with multiple input observations and stacking | |
| 208 | + | |
| 209 | + # Setup csphagen | |
| 210 | + phagen = cscripts.csphagen(obs) | |
| 211 | + phagen['ebinalg'] = 'LOG' | |
| 212 | + phagen['emin'] = 0.1 | |
| 213 | + phagen['emax'] = 100. | |
| 214 | + phagen['enumbins'] = nbins | |
| 215 | + phagen['coordsys'] = 'CEL' | |
| 216 | + phagen['ra'] = 83.633 | |
| 217 | + phagen['dec'] = 22.0145 | |
| 218 | + phagen['rad'] = 0.2 | |
| 219 | + phagen['stack'] = True | |
| 220 | + phagen['exclusion'] = self._exclusion | |
| 221 | + phagen['outroot'] = 'phagen_py4' | |
| 222 | + phagen['logfile'] = 'csphagen_py4.log' | |
| 223 | + phagen['chatter'] = 1 | |
| 224 | + | |
| 225 | + # Run script | |
| 226 | + phagen.execute() | |
| 227 | + | |
| 228 | + # Check outout | |
| 229 | + for s in range(2): | |
| 230 | + self._check_output('phagen_py4_stacked', nbins, | |
| 231 | + 0,check_regions=False) | |
| 232 | + self._check_outobs('phagen_py4', 1) | |
| 233 | + | |
| 207 | 234 | return |
| 208 | 235 | |
| 209 | 236 | def _check_ebounds(self, table, bins): |
| ... | ... | @@ -341,7 +368,7 @@ class Test(test): |
| 341 | 368 | # Return |
| 342 | 369 | return |
| 343 | 370 | |
| 344 | - def _check_output(self, filenameroot, bins, nreg): | |
| 371 | + def _check_output(self, filenameroot, bins, nreg, check_regions = True): | |
| 345 | 372 | """ |
| 346 | 373 | Check the output from a csphagen run |
| 347 | 374 | """ |
| ... | ... | @@ -356,12 +383,13 @@ class Test(test): |
| 356 | 383 | |
| 357 | 384 | |
| 358 | 385 | # Regions |
| 359 | - reg = gammalib.GSkyRegions(filenameroot + "_on.reg") | |
| 360 | - self.test_value(reg.size(), 1, 'Check for ' + str( | |
| 361 | - 1) + ' region in source region file') | |
| 362 | - reg = gammalib.GSkyRegions(filenameroot + "_off.reg") | |
| 363 | - self.test_value(reg.size(), nreg, 'Check for ' + str( | |
| 364 | - nreg) + ' region in background region file') | |
| 386 | + if check_regions: | |
| 387 | + reg = gammalib.GSkyRegions(filenameroot + "_on.reg") | |
| 388 | + self.test_value(reg.size(), 1, 'Check for ' + str( | |
| 389 | + 1) + ' region in source region file') | |
| 390 | + reg = gammalib.GSkyRegions(filenameroot + "_off.reg") | |
| 391 | + self.test_value(reg.size(), nreg, 'Check for ' + str( | |
| 392 | + nreg) + ' region in background region file') | |
| 365 | 393 | |
| 366 | 394 | return |
| 367 | 395 | ... | ... |