Commit b9dead70d2d71bc94d8574f1bcb4f1a23ac8d7ad

Authored by ldivenere
1 parent 4b7d6042

add SIGNIF option in csresmap. added tests for DIFFSQRT and SIGNIF algorithms

cscripts/csresmap.par
@@ -43,7 +43,7 @@ yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DE @@ -43,7 +43,7 @@ yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DE
43 nxpix, i, a, 200,,, "Size of the X axis in pixels" 43 nxpix, i, a, 200,,, "Size of the X axis in pixels"
44 nypix, i, a, 200,,, "Size of the Y axis in pixels" 44 nypix, i, a, 200,,, "Size of the Y axis in pixels"
45 binsz, r, a, 0.02,,, "Pixel size (deg/pixel)" 45 binsz, r, a, 0.02,,, "Pixel size (deg/pixel)"
46 -algorithm, s, a, SUBDIV,SUB|SUBDIV|SUBDIVSQRT,, "Residual map computation algorithm" 46 +algorithm, s, a, SUBDIV,SUB|SUBDIV|SUBDIVSQRT|SIGNIF,, "Residual map computation algorithm"
47 47
48 # 48 #
49 # Standard parameters 49 # Standard parameters
cscripts/csresmap.py
@@ -241,6 +241,27 @@ class csresmap(ctools.cscript): @@ -241,6 +241,27 @@ class csresmap(ctools.cscript):
241 self._resmap -= modelmap 241 self._resmap -= modelmap
242 self._resmap /= modelmap.sqrt() 242 self._resmap /= modelmap.sqrt()
243 243
  244 + # Calculate significance from Li&Ma derivation
  245 + elif algorithm == 'SIGNIF':
  246 + signmap = (self._resmap - modelmap).sign()
  247 + logmap = self._resmap/modelmap
  248 + # Masking pixels with 0 counts. Put a small value >0 for log calculation
  249 + # and restore the 0. value afterwards
  250 + mask = []
  251 + for i in range(logmap.npix()):
  252 + # Testing pixel i and map 0 (there is one map only after stacking)
  253 + if logmap[i,0] == 0:
  254 + mask.append(i)
  255 + logmap[i,0] = 1e-10
  256 + logmap = logmap.log()
  257 + for i in mask:
  258 + logmap[i,0] = 0.
  259 +
  260 + signif_squared_map = (self._resmap*logmap) + modelmap - self._resmap
  261 + signif_squared_map *= 2.
  262 + unsigned_resmap = signif_squared_map.sqrt()
  263 + self._resmap = unsigned_resmap * signmap
  264 +
244 # Raise exception if algorithm is unknown 265 # Raise exception if algorithm is unknown
245 else: 266 else:
246 raise TypeError('Algorithm "'+algorithm+'" not known') 267 raise TypeError('Algorithm "'+algorithm+'" not known')
test/test_csresmap.py
@@ -165,6 +165,54 @@ class Test(test): @@ -165,6 +165,54 @@ class Test(test):
165 # Check pull distribution file 165 # Check pull distribution file
166 self._check_result_file('csresmap_py2.fits', nx=200, ny=200) 166 self._check_result_file('csresmap_py2.fits', nx=200, ny=200)
167 167
  168 +
  169 + # Run csresmap with SUBDIVSQRT algorithm
  170 + resmap = cscripts.csresmap()
  171 + resmap['inobs'] = self._cntcube
  172 + resmap['modcube'] = 'NONE'
  173 + resmap['expcube'] = 'NONE'
  174 + resmap['psfcube'] = 'NONE'
  175 + resmap['edispcube'] = 'NONE'
  176 + resmap['bkgcube'] = 'NONE'
  177 + resmap['caldb'] = self._caldb
  178 + resmap['irf'] = self._irf
  179 + resmap['inmodel'] = self._model
  180 + resmap['outmap'] = 'csresmap_py3.fits'
  181 + resmap['algorithm'] = 'SUBDIVSQRT'
  182 + resmap['logfile'] = 'csresmap_py3.log'
  183 + resmap['chatter'] = 3
  184 + resmap['publish'] = True
  185 +
  186 + # Run csresmap script
  187 + resmap.execute()
  188 +
  189 + # Check pull distribution file
  190 + self._check_result_file('csresmap_py3.fits', nx=200, ny=200)
  191 +
  192 + # Run csresmap with SIGNIF algorithm
  193 + resmap = cscripts.csresmap()
  194 + resmap['inobs'] = self._cntcube
  195 + resmap['modcube'] = 'NONE'
  196 + resmap['expcube'] = 'NONE'
  197 + resmap['psfcube'] = 'NONE'
  198 + resmap['edispcube'] = 'NONE'
  199 + resmap['bkgcube'] = 'NONE'
  200 + resmap['caldb'] = self._caldb
  201 + resmap['irf'] = self._irf
  202 + resmap['inmodel'] = self._model
  203 + resmap['outmap'] = 'csresmap_py4.fits'
  204 + resmap['algorithm'] = 'SIGNIF'
  205 + resmap['logfile'] = 'csresmap_py4.log'
  206 + resmap['chatter'] = 3
  207 + resmap['publish'] = True
  208 +
  209 + # Run csresmap script
  210 + resmap.execute()
  211 +
  212 + # Check pull distribution file
  213 + self._check_result_file('csresmap_py4.fits', nx=200, ny=200)
  214 +
  215 +
168 # Return 216 # Return
169 return 217 return
170 218
test/test_python_ctools.py
@@ -117,7 +117,7 @@ def test(installed=False): @@ -117,7 +117,7 @@ def test(installed=False):
117 test_ctulimit.Test(), 117 test_ctulimit.Test(),
118 test_cterror.Test(), 118 test_cterror.Test(),
119 test_pipelines.Test()] 119 test_pipelines.Test()]
120 - 120 +
121 # Allocate test suite container 121 # Allocate test suite container
122 suites = gammalib.GTestSuites('ctools unit testing') 122 suites = gammalib.GTestSuites('ctools unit testing')
123 123