Commit d403041f143ee6f064ee11aedaaa10c7cb173553
1 parent
eb9b3f22
Allow setting exclusion map via 'csphagen.exclusion_map()'
This allows setting the exclusion map without having to save the map first
Showing
2 changed files
with
40 additions
and
1 deletions
cscripts/csphagen.py
| @@ -282,7 +282,10 @@ class csphagen(ctools.csobservation): | @@ -282,7 +282,10 @@ class csphagen(ctools.csobservation): | ||
| 282 | self._src_reg = gammalib.GSkyRegions() | 282 | self._src_reg = gammalib.GSkyRegions() |
| 283 | 283 | ||
| 284 | # Exclusion map | 284 | # Exclusion map |
| 285 | - if self['inexclusion'].is_valid(): | 285 | + if (self._excl_reg is not None) and (self._excl_reg.map().npix() > 0): |
| 286 | + # Exclusion map set and is not empty | ||
| 287 | + self._has_exclusion = True | ||
| 288 | + elif self['inexclusion'].is_valid(): | ||
| 286 | inexclusion = self['inexclusion'].filename() | 289 | inexclusion = self['inexclusion'].filename() |
| 287 | self._excl_reg = gammalib.GSkyRegionMap(inexclusion) | 290 | self._excl_reg = gammalib.GSkyRegionMap(inexclusion) |
| 288 | self._has_exclusion = True | 291 | self._has_exclusion = True |
test/test_csphagen.py
| @@ -335,6 +335,42 @@ class Test(test): | @@ -335,6 +335,42 @@ class Test(test): | ||
| 335 | 0, check_regions=False) | 335 | 0, check_regions=False) |
| 336 | self._check_outobs('csphagen_py6_obs.xml', 1) | 336 | self._check_outobs('csphagen_py6_obs.xml', 1) |
| 337 | 337 | ||
| 338 | + # Same test as from command line, but set exclusion with csphagen.exclusion_map | ||
| 339 | + phagen = cscripts.csphagen() | ||
| 340 | + phagen['inobs'] = self._myevents1 | ||
| 341 | + phagen['inmodel'] = 'NONE' | ||
| 342 | + phagen['caldb'] = self._caldb | ||
| 343 | + phagen['irf'] = self._irf | ||
| 344 | + phagen['ebinalg'] = 'LOG' | ||
| 345 | + phagen['emin'] = 0.1 | ||
| 346 | + phagen['emax'] = 100.0 | ||
| 347 | + phagen['enumbins'] = self._nbins | ||
| 348 | + phagen['coordsys'] = 'CEL' | ||
| 349 | + phagen['ra'] = 83.633 | ||
| 350 | + phagen['dec'] = 22.0145 | ||
| 351 | + phagen['rad'] = 0.2 | ||
| 352 | + phagen['stack'] = False | ||
| 353 | + phagen['bkgmethod'] = 'REFLECTED' | ||
| 354 | + phagen['etruemin'] = 0.05 | ||
| 355 | + phagen['etruemax'] = 150.0 | ||
| 356 | + phagen['etruebins'] = 5 | ||
| 357 | + phagen['outobs'] = 'csphagen_py7_obs.xml' | ||
| 358 | + phagen['outmodel'] = 'csphagen_py7_model.xml' | ||
| 359 | + phagen['prefix'] = 'csphagen_py7' | ||
| 360 | + phagen['logfile'] = 'csphagen_py7.log' | ||
| 361 | + phagen['chatter'] = 1 | ||
| 362 | + | ||
| 363 | + # Set exclusion map | ||
| 364 | + exclmap = gammalib.GSkyRegionMap(self._exclusion) | ||
| 365 | + phagen.exclusion_map(exclmap) | ||
| 366 | + | ||
| 367 | + # Execute script | ||
| 368 | + phagen.execute() | ||
| 369 | + | ||
| 370 | + # Check output | ||
| 371 | + self._check_output('csphagen_py7', self._nbins, self._nreg_with_excl) | ||
| 372 | + self._check_outobs('csphagen_py7_obs.xml', 1) | ||
| 373 | + | ||
| 338 | # Return | 374 | # Return |
| 339 | return | 375 | return |
| 340 | 376 |