Commit 73bec68a96196ffb8ad8892f97fbdb8eeb3d1e2b
Merge branch '1867-csresmap-significance-map' into integration
Showing
4 changed files
with
80 additions
and
5 deletions
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|SIGNIFICANCE,, "Residual map computation algorithm" |
| 47 | 47 | ||
| 48 | # | 48 | # |
| 49 | # Standard parameters | 49 | # Standard parameters |
cscripts/csresmap.py
| @@ -239,6 +239,26 @@ class csresmap(ctools.cscript): | @@ -239,6 +239,26 @@ class csresmap(ctools.cscript): | ||
| 239 | self._resmap -= modelmap | 239 | self._resmap -= modelmap |
| 240 | self._resmap /= modelmap.sqrt() | 240 | self._resmap /= modelmap.sqrt() |
| 241 | 241 | ||
| 242 | + # Calculate significance from Li&Ma derivation | ||
| 243 | + elif algorithm == 'SIGNIFICANCE': | ||
| 244 | + signmap = (self._resmap - modelmap).sign() | ||
| 245 | + logmap = self._resmap/modelmap | ||
| 246 | + # Masking pixels with zero counts. Put a small value >0 for log | ||
| 247 | + # calculation and restore the zero value afterwards | ||
| 248 | + mask = [] | ||
| 249 | + for i in range(logmap.npix()): | ||
| 250 | + # Testing pixel i and map 0 (there is one map only after stacking) | ||
| 251 | + if logmap[i,0] == 0: | ||
| 252 | + mask.append(i) | ||
| 253 | + logmap[i,0] = 1e-10 | ||
| 254 | + logmap = logmap.log() | ||
| 255 | + for i in mask: | ||
| 256 | + logmap[i,0] = 0. | ||
| 257 | + signif_squared_map = (self._resmap*logmap) + modelmap - self._resmap | ||
| 258 | + signif_squared_map *= 2. | ||
| 259 | + unsigned_resmap = signif_squared_map.sqrt() | ||
| 260 | + self._resmap = unsigned_resmap * signmap | ||
| 261 | + | ||
| 242 | # Raise exception if algorithm is unknown | 262 | # Raise exception if algorithm is unknown |
| 243 | else: | 263 | else: |
| 244 | raise TypeError('Algorithm "'+algorithm+'" not known') | 264 | raise TypeError('Algorithm "'+algorithm+'" not known') |
doc/source/users/reference_manual/csresmap.rst
| @@ -94,9 +94,17 @@ General parameters | @@ -94,9 +94,17 @@ General parameters | ||
| 94 | ``binsz [real]`` | 94 | ``binsz [real]`` |
| 95 | Cube bin size (in degrees/pixel). | 95 | Cube bin size (in degrees/pixel). |
| 96 | 96 | ||
| 97 | -``(algorithm = SUBDIV) <SUB|SUBDIV|SUBDIVSQRT> [string]`` | 97 | +``(algorithm = SUBDIV) <SUB|SUBDIV|SUBDIVSQRT|SIGNIF> [string]`` |
| 98 | Algorithm used to generate the residual map. | 98 | Algorithm used to generate the residual map. |
| 99 | - | 99 | + |
| 100 | + SUB: DATA - MODEL | ||
| 101 | + | ||
| 102 | + SUBDIV: (DATA - MODEL)/MODEL | ||
| 103 | + | ||
| 104 | + SUBDIVSQRT: (DATA - MODEL)/sqrt(MODEL) | ||
| 105 | + | ||
| 106 | + SIGNIF: sign(DATA-MODEL) * sqrt( 2*( DATA*log(DATA/MODEL) + MODEL - DATA ) ) | ||
| 107 | + | ||
| 100 | 108 | ||
| 101 | Standard parameters | 109 | Standard parameters |
| 102 | ------------------- | 110 | ------------------- |
test/test_csresmap.py
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | # This scripts performs unit tests for the csresmap script. | 3 | # This scripts performs unit tests for the csresmap script. |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2016 Juergen Knoedlseder | 5 | +# Copyright (C) 2016-2017 Juergen Knoedlseder |
| 6 | # | 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -33,7 +33,7 @@ class Test(test): | @@ -33,7 +33,7 @@ class Test(test): | ||
| 33 | This test class makes unit tests for the csresmap script by using it | 33 | This test class makes unit tests for the csresmap script by using it |
| 34 | from the command line and from Python. | 34 | from the command line and from Python. |
| 35 | """ | 35 | """ |
| 36 | - | 36 | + |
| 37 | # Constructor | 37 | # Constructor |
| 38 | def __init__(self): | 38 | def __init__(self): |
| 39 | """ | 39 | """ |
| @@ -165,6 +165,53 @@ class Test(test): | @@ -165,6 +165,53 @@ 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 | + # Run csresmap with SUBDIVSQRT algorithm | ||
| 169 | + resmap = cscripts.csresmap() | ||
| 170 | + resmap['inobs'] = self._cntcube | ||
| 171 | + resmap['modcube'] = 'NONE' | ||
| 172 | + resmap['expcube'] = 'NONE' | ||
| 173 | + resmap['psfcube'] = 'NONE' | ||
| 174 | + resmap['edispcube'] = 'NONE' | ||
| 175 | + resmap['bkgcube'] = 'NONE' | ||
| 176 | + resmap['caldb'] = self._caldb | ||
| 177 | + resmap['irf'] = self._irf | ||
| 178 | + resmap['inmodel'] = self._model | ||
| 179 | + resmap['outmap'] = 'csresmap_py3.fits' | ||
| 180 | + resmap['algorithm'] = 'SUBDIVSQRT' | ||
| 181 | + resmap['logfile'] = 'csresmap_py3.log' | ||
| 182 | + resmap['chatter'] = 3 | ||
| 183 | + resmap['publish'] = True | ||
| 184 | + | ||
| 185 | + # Run csresmap script | ||
| 186 | + resmap.execute() | ||
| 187 | + | ||
| 188 | + # Check pull distribution file | ||
| 189 | + self._check_result_file('csresmap_py3.fits', nx=200, ny=200) | ||
| 190 | + | ||
| 191 | + # Run csresmap with SIGNIFICANCE algorithm | ||
| 192 | + resmap = cscripts.csresmap() | ||
| 193 | + resmap['inobs'] = self._cntcube | ||
| 194 | + resmap['modcube'] = 'NONE' | ||
| 195 | + resmap['expcube'] = 'NONE' | ||
| 196 | + resmap['psfcube'] = 'NONE' | ||
| 197 | + resmap['edispcube'] = 'NONE' | ||
| 198 | + resmap['bkgcube'] = 'NONE' | ||
| 199 | + resmap['caldb'] = self._caldb | ||
| 200 | + resmap['irf'] = self._irf | ||
| 201 | + resmap['inmodel'] = self._model | ||
| 202 | + resmap['outmap'] = 'csresmap_py4.fits' | ||
| 203 | + resmap['algorithm'] = 'SIGNIFICANCE' | ||
| 204 | + resmap['logfile'] = 'csresmap_py4.log' | ||
| 205 | + resmap['chatter'] = 3 | ||
| 206 | + resmap['publish'] = True | ||
| 207 | + | ||
| 208 | + # Run csresmap script | ||
| 209 | + resmap.execute() | ||
| 210 | + | ||
| 211 | + # Check pull distribution file | ||
| 212 | + self._check_result_file('csresmap_py4.fits', nx=200, ny=200) | ||
| 213 | + | ||
| 214 | + | ||
| 168 | # Return | 215 | # Return |
| 169 | return | 216 | return |
| 170 | 217 |