From d403041f143ee6f064ee11aedaaa10c7cb173553 Mon Sep 17 00:00:00 2001 From: Josh Cardenzana Date: Tue, 2 Jul 2019 20:47:54 +0200 Subject: [PATCH] Allow setting exclusion map via 'csphagen.exclusion_map()' This allows setting the exclusion map without having to save the map first --- cscripts/csphagen.py | 5 ++++- test/test_csphagen.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/cscripts/csphagen.py b/cscripts/csphagen.py index 1f9967d..ac36f80 100755 --- a/cscripts/csphagen.py +++ b/cscripts/csphagen.py @@ -282,7 +282,10 @@ class csphagen(ctools.csobservation): self._src_reg = gammalib.GSkyRegions() # Exclusion map - if self['inexclusion'].is_valid(): + if (self._excl_reg is not None) and (self._excl_reg.map().npix() > 0): + # Exclusion map set and is not empty + self._has_exclusion = True + elif self['inexclusion'].is_valid(): inexclusion = self['inexclusion'].filename() self._excl_reg = gammalib.GSkyRegionMap(inexclusion) self._has_exclusion = True diff --git a/test/test_csphagen.py b/test/test_csphagen.py index 5200853..b0ad772 100644 --- a/test/test_csphagen.py +++ b/test/test_csphagen.py @@ -335,6 +335,42 @@ class Test(test): 0, check_regions=False) self._check_outobs('csphagen_py6_obs.xml', 1) + # Same test as from command line, but set exclusion with csphagen.exclusion_map + 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['bkgmethod'] = 'REFLECTED' + phagen['etruemin'] = 0.05 + phagen['etruemax'] = 150.0 + phagen['etruebins'] = 5 + phagen['outobs'] = 'csphagen_py7_obs.xml' + phagen['outmodel'] = 'csphagen_py7_model.xml' + phagen['prefix'] = 'csphagen_py7' + phagen['logfile'] = 'csphagen_py7.log' + phagen['chatter'] = 1 + + # Set exclusion map + exclmap = gammalib.GSkyRegionMap(self._exclusion) + phagen.exclusion_map(exclmap) + + # Execute script + phagen.execute() + + # Check output + self._check_output('csphagen_py7', self._nbins, self._nreg_with_excl) + self._check_outobs('csphagen_py7_obs.xml', 1) + # Return return -- libgit2 0.21.4