Commit 1bfa71e6ec9569fa49986adb3a1a66ca0f10b393

Authored by Josh Cardenzana
Committed by Jürgen Knödlseder
1 parent 30fe50a9

Add comments to csresmap fix (#2136)

Removed a couple of unnecessary computations and added comments to the code.
Showing 1 changed file with 13 additions and 5 deletions
cscripts/csresmap.py
@@ -246,19 +246,27 @@ class csresmap(ctools.cscript): @@ -246,19 +246,27 @@ class csresmap(ctools.cscript):
246 # Compute sign map 246 # Compute sign map
247 signmap = (self._resmap - modelmap).sign() 247 signmap = (self._resmap - modelmap).sign()
248 248
249 - # Compute logarithm of map. For that we mask pixels  
250 - #logmap = self._resmap/modelmap  
251 - logmap = self._resmap.copy() # Python 3.x kluge  
252 - logmap /= modelmap  
253 - for i in range(logmap.npix()): 249 + # Loop over every bin in the map
  250 + for i in range(self._resmap.npix()):
  251 +
  252 + # If the model value > 0.0 do the computation as normal
254 model_val = modelmap[i] 253 model_val = modelmap[i]
255 if model_val > 0.0: 254 if model_val > 0.0:
  255 +
  256 + # If the data value is also > 0 then proceed as normal
256 data_val = self._resmap[i] 257 data_val = self._resmap[i]
257 if data_val > 0.0: 258 if data_val > 0.0:
  259 + # Compute the significance^2 and save it to the map
258 log_val = math.log(data_val/model_val) 260 log_val = math.log(data_val/model_val)
259 self._resmap[i] = (data_val*log_val) + model_val - data_val 261 self._resmap[i] = (data_val*log_val) + model_val - data_val
  262 +
  263 + # If the data value is less than zero, then compute the
  264 + # reduced value of the above expression. This is necessary
  265 + # to avoid computing log(0).
260 else: 266 else:
261 self._resmap[i] = model_val 267 self._resmap[i] = model_val
  268 +
  269 + # If the model value is zero, hard-code the significance to 0
262 else: 270 else:
263 self._resmap[i] = 0.0 271 self._resmap[i] = 0.0
264 272