Commit d32a48de686a3005245dc19948c2eed8c6ff2289

Authored by Jürgen Knödlseder
1 parent 10e2ae51

Add coordsys, proj and binsz parameters to comobsres script

doc/source/users/reference_manual/comobsres.rst
@@ -36,10 +36,19 @@ General parameters @@ -36,10 +36,19 @@ General parameters
36 ``(armmax = 3.0) [real]`` 36 ``(armmax = 3.0) [real]``
37 Maximum ARM (deg). 37 Maximum ARM (deg).
38 38
  39 +``coordsys <CEL|GAL> [string]``
  40 + Coordinate system (CEL - celestial, GAL - galactic).
  41 +
  42 +``proj <AIT|AZP|CAR|GLS|MOL|SFL|SIN|STG|TAN> [string]``
  43 + Projection method.
  44 +
39 ``(margin = 30.0) [real]`` 45 ``(margin = 30.0) [real]``
40 Sky map margin (deg). This margin is added to the data cube size so that 46 Sky map margin (deg). This margin is added to the data cube size so that
41 also source positions outside the range spanned by the data cube are considered. 47 also source positions outside the range spanned by the data cube are considered.
42 48
  49 +``(binsz = 1.0) [real]``
  50 + Sky map bin size (deg).
  51 +
43 ``(grouping = 1) [integer]`` 52 ``(grouping = 1) [integer]``
44 Number of Chi/Psi bins to group for residual computation. 53 Number of Chi/Psi bins to group for residual computation.
45 54
modules/comscripts/comobsres.par
@@ -27,7 +27,10 @@ outmap, f, a, resmap.fits,,,&quot;Output residual map&quot; @@ -27,7 +27,10 @@ outmap, f, a, resmap.fits,,,&quot;Output residual map&quot;
27 algorithm, s, a, SIGNIFICANCE,SUB|SUBDIV|SUBDIVSQRT|SIGNIFICANCE,, "Residual map computation algorithm" 27 algorithm, s, a, SIGNIFICANCE,SUB|SUBDIV|SUBDIVSQRT|SIGNIFICANCE,, "Residual map computation algorithm"
28 armmin, r, h, -3.0,,, "Minimum ARM (deg)" 28 armmin, r, h, -3.0,,, "Minimum ARM (deg)"
29 armmax, r, h, 3.0,,, "Maximum ARM (deg)" 29 armmax, r, h, 3.0,,, "Maximum ARM (deg)"
  30 +coordsys, s, a, GAL,CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)"
  31 +proj, s, a, TAN,AIT|AZP|CAR|GLS|MOL|SFL|SIN|STG|TAN,, "Projection method"
30 margin, r, h, 30.0,,, "Sky map margin (deg)" 32 margin, r, h, 30.0,,, "Sky map margin (deg)"
  33 +binsz, r, h, 1.0,0.1,10.0, "Bin size (deg)"
31 grouping, i, h, 1,1,80, "Number of Chi/Psi bins to group for residual computation" 34 grouping, i, h, 1,1,80, "Number of Chi/Psi bins to group for residual computation"
32 dri, b, h, no,,, "Compute DRI residuals?" 35 dri, b, h, no,,, "Compute DRI residuals?"
33 png, b, h, no,,, "Generate residual histogram png files?" 36 png, b, h, no,,, "Generate residual histogram png files?"
modules/comscripts/comobsres.py
@@ -145,7 +145,10 @@ class comobsres(ctools.csobservation): @@ -145,7 +145,10 @@ class comobsres(ctools.csobservation):
145 self['algorithm'].string() 145 self['algorithm'].string()
146 self['armmin'].real() 146 self['armmin'].real()
147 self['armmax'].real() 147 self['armmax'].real()
  148 + self['coordsys'].string()
  149 + self['proj'].string()
148 self['margin'].real() 150 self['margin'].real()
  151 + self['binsz'].real()
149 152
150 # Query PNG parameters 153 # Query PNG parameters
151 if self['png'].boolean(): 154 if self['png'].boolean():
@@ -187,6 +190,11 @@ class comobsres(ctools.csobservation): @@ -187,6 +190,11 @@ class comobsres(ctools.csobservation):
187 glat_min = None 190 glat_min = None
188 glat_max = None 191 glat_max = None
189 192
  193 + # Get parameters
  194 + proj = self['proj'].string()
  195 + coordsys = self['coordsys'].string()
  196 + binsz = self['binsz'].real()
  197 +
190 # Loop over all input observations 198 # Loop over all input observations
191 for obs in inobs: 199 for obs in inobs:
192 200
@@ -243,15 +251,22 @@ class comobsres(ctools.csobservation): @@ -243,15 +251,22 @@ class comobsres(ctools.csobservation):
243 # Compute width and number of pixels 251 # Compute width and number of pixels
244 glon_width = glon_max - glon_min 252 glon_width = glon_max - glon_min
245 glat_width = glat_max - glat_min 253 glat_width = glat_max - glat_min
246 - nx = int(glon_width+0.5)  
247 - ny = int(glat_width+0.5) 254 + nx = int(glon_width/binsz+0.5)
  255 + ny = int(glat_width/binsz+0.5)
248 if nx > 360: 256 if nx > 360:
249 nx = 360 257 nx = 360
250 if ny > 180: 258 if ny > 180:
251 ny = 180 259 ny = 180
252 260
  261 + # Translate to celestial coordinates if requested
  262 + if coordsys == 'CEL':
  263 + centre = gammalib.GSkyDir()
  264 + centre.lb_deg(glon, glat)
  265 + glon = centre.ra_deg()
  266 + glat = centre.dec_deg()
  267 +
253 # Allocate map 268 # Allocate map
254 - map = gammalib.GSkyMap('TAN', 'GAL', glon, glat, -1.0, 1.0, nx, ny) 269 + map = gammalib.GSkyMap(proj, coordsys, glon, glat, -binsz, binsz, nx, ny)
255 270
256 # Return map 271 # Return map
257 return map 272 return map
test/test_comobsres.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # This scripts performs unit tests for the comobsres script. 3 # This scripts performs unit tests for the comobsres script.
4 # 4 #
5 -# Copyright (C) 2021 Juergen Knoedlseder 5 +# Copyright (C) 2021-2022 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
@@ -75,7 +75,8 @@ class Test(test): @@ -75,7 +75,8 @@ class Test(test):
75 75
76 # Setup command 76 # Setup command
77 cmd = comobsres+' inobs="'+self._obs+'" inmodel="'+self._model+'" '+ \ 77 cmd = comobsres+' inobs="'+self._obs+'" inmodel="'+self._model+'" '+ \
78 - 'algorithm="SIGNIFICANCE" margin="0.0" '+ \ 78 + 'algorithm="SIGNIFICANCE" margin="0.0" binsz="5.0" '+ \
  79 + 'coordsys="GAL" proj="TAN" '+ \
79 'outfolder="comobsres_cmd1" outmap="comobsres_cmd1.fits" '+ \ 80 'outfolder="comobsres_cmd1" outmap="comobsres_cmd1.fits" '+ \
80 'logfile="comobsres_cmd1.log" chatter=1' 81 'logfile="comobsres_cmd1.log" chatter=1'
81 82
@@ -88,7 +89,8 @@ class Test(test): @@ -88,7 +89,8 @@ class Test(test):
88 89
89 # Setup command 90 # Setup command
90 cmd = comobsres+' inobs="file_that_does_not_exist.xml" inmodel="'+self._model+'" '+ \ 91 cmd = comobsres+' inobs="file_that_does_not_exist.xml" inmodel="'+self._model+'" '+ \
91 - 'algorithm="SIGNIFICANCE" margin="0.0" '+ \ 92 + 'algorithm="SIGNIFICANCE" margin="0.0" binsz="5.0" '+ \
  93 + 'coordsys="GAL" proj="TAN" '+ \
92 'outfolder="comobsres_cmd2" outmap="comobsres_cmd2.fits" '+ \ 94 'outfolder="comobsres_cmd2" outmap="comobsres_cmd2.fits" '+ \
93 'logfile="comobsres_cmd2.log" chatter=1' 95 'logfile="comobsres_cmd2.log" chatter=1'
94 96
@@ -112,7 +114,10 @@ class Test(test): @@ -112,7 +114,10 @@ class Test(test):
112 add['inobs'] = self._obs 114 add['inobs'] = self._obs
113 add['inmodel'] = self._model 115 add['inmodel'] = self._model
114 add['algorithm'] = 'SIGNIFICANCE' 116 add['algorithm'] = 'SIGNIFICANCE'
  117 + add['coordsys'] = 'GAL'
  118 + add['proj'] = 'TAN'
115 add['margin'] = 0.0 119 add['margin'] = 0.0
  120 + add['binsz'] = 5.0
116 add['outfolder'] = 'comobsres_py1' 121 add['outfolder'] = 'comobsres_py1'
117 add['outmap'] = 'comobsres_py1.fits' 122 add['outmap'] = 'comobsres_py1.fits'
118 add['logfile'] = 'comobsres_py1.log' 123 add['logfile'] = 'comobsres_py1.log'
@@ -138,7 +143,7 @@ class Test(test): @@ -138,7 +143,7 @@ class Test(test):
138 map = gammalib.GSkyMap(filename) 143 map = gammalib.GSkyMap(filename)
139 144
140 # Check that there is one observation 145 # Check that there is one observation
141 - self.test_value(map.npix(), 3025, 'Check for number of pixels in sky map') 146 + self.test_value(map.npix(), 121, 'Check for number of pixels in sky map')
142 147
143 # Return 148 # Return
144 return 149 return