Commit 35b732256d1c4b2c80a200fcb4e300d473c2dd55

Authored by Luigi Tibaldo
1 parent 63e7f3f8

development of test unit

cscripts/csphagen.py
... ... @@ -92,6 +92,8 @@ class csphagen(ctools.cscript):
92 92 self._excl_reg = gammalib.GSkyRegionMap(
93 93 self["exclusion"].filename())
94 94 self._has_exclusion = True
  95 + else:
  96 + self._has_exclusion = False
95 97  
96 98 # Stacking
97 99 self._stack = self['stack'].boolean()
... ... @@ -240,9 +242,6 @@ class csphagen(ctools.cscript):
240 242 # Run the script
241 243 self.run()
242 244  
243   - # Save residual map
244   - self.save()
245   -
246 245 # Return
247 246 return
248 247  
... ...
test/data/crab_offaxis.fits renamed to test/data/crab_offaxis1.fits
No preview for this file type
test/data/crab_offaxis2.fits 0 → 100644
No preview for this file type
test/test_csphagen.py
... ... @@ -41,10 +41,11 @@ class Test(test):
41 41 """
42 42 # Call base class constructor
43 43 test.__init__(self)
44   - self._myevents = self._datadir + '/crab_offaxis.fits'
  44 + self._myevents = self._datadir + '/crab_offaxis1.fits'
45 45 self._exclusion = self._datadir + '/crab_exclusion.fits'
46 46 self._nreg_with_excl = 5
47   - # number of expected background regions with exclusion
  47 + self._nreg_wo_excl = 8
  48 + # number of expected background regions with/wo exclusion
48 49  
49 50 # Return
50 51 return
... ... @@ -108,6 +109,62 @@ class Test(test):
108 109 # Return
109 110 return
110 111  
  112 + def _test_python(self):
  113 + """
  114 + Test csphagen from Python
  115 + """
  116 + nbins = 120
  117 +
  118 + # Same test as from command line
  119 + phagen = cscripts.csphagen()
  120 + phagen['inobs'] = self._myevents
  121 + phagen['caldb'] = self._caldb
  122 + phagen['irf'] = self._irf
  123 + phagen['ebinalg'] = 'LOG'
  124 + phagen['emin'] = 0.1
  125 + phagen['emax']= 100.
  126 + phagen['enumbins'] = nbins
  127 + phagen['coordsys'] = 'CEL'
  128 + phagen['ra'] = 83.633
  129 + phagen['dec'] = 22.0145
  130 + phagen['rad'] = 0.2
  131 + phagen['stack'] = False
  132 + phagen['exclusion'] = self._exclusion
  133 + phagen['outroot'] = 'genpha_py1'
  134 + phagen['logfile'] = 'csphagen_py1.log'
  135 + phagen['chatter'] = 1
  136 +
  137 + # Run script
  138 + phagen.execute()
  139 +
  140 + # Check outout
  141 + self._check_output('genpha_py1', nbins, self._nreg_with_excl)
  142 +
  143 + # Second test, now without exclusion region
  144 + phagen = cscripts.csphagen()
  145 + phagen['inobs'] = self._myevents
  146 + phagen['caldb'] = self._caldb
  147 + phagen['irf'] = self._irf
  148 + phagen['ebinalg'] = 'LOG'
  149 + phagen['emin'] = 0.1
  150 + phagen['emax'] = 100.
  151 + phagen['enumbins'] = nbins
  152 + phagen['coordsys'] = 'CEL'
  153 + phagen['ra'] = 83.633
  154 + phagen['dec'] = 22.0145
  155 + phagen['rad'] = 0.2
  156 + phagen['stack'] = False
  157 + phagen['outroot'] = 'genpha_py2'
  158 + phagen['logfile'] = 'csphagen_py2.log'
  159 + phagen['chatter'] = 1
  160 +
  161 + # Run script
  162 + phagen.execute()
  163 +
  164 + # Check outout
  165 + self._check_output('genpha_py2', nbins, self._nreg_wo_excl)
  166 +
  167 +
111 168 def _check_ebounds(self, table, bins):
112 169 """
113 170 Check EBOUNDS table
... ...