Commit 3d26c9cef82c94d366e31af090a6a59661eceece

Authored by Jürgen Knödlseder
1 parent 333841e5

Accept models with Galactic coordinates in comlixmap

Showing 1 changed file with 30 additions and 8 deletions
modules/comscripts/comlixmap.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Create SRCLIX TS map
4 4 #
5   -# Copyright (C) 2021 Juergen Knoedlseder
  5 +# Copyright (C) 2021-2022 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -176,11 +176,13 @@ class comlixmap(ctools.cslikelihood):
176 176 nfree = 0
177 177  
178 178 # Compute number of free model parameters for all test sources,
179   - # exclusing 'RA' and 'DEC'
  179 + # excluding 'RA', 'DEC', 'GLON' and 'GLAT'
180 180 for srcname in self._srcnames:
181 181 source = self.obs().models()[srcname]
182 182 for par in source:
183   - if par.name() != 'RA' and par.name() != 'DEC' and par.is_free():
  183 + if par.name() != 'RA' and par.name() != 'DEC' and \
  184 + par.name() != 'GLON' and par.name() != 'GLAT' and \
  185 + par.is_free():
184 186 self._map_names.append(par.name())
185 187 nfree += 1
186 188  
... ... @@ -213,10 +215,21 @@ class comlixmap(ctools.cslikelihood):
213 215  
214 216 # Set and fix position of test source
215 217 source = self.obs().models()[srcname]
216   - source['RA'].value(dir.ra_deg())
217   - source['DEC'].value(dir.dec_deg())
218   - source['RA'].fix()
219   - source['DEC'].fix()
  218 + if source.has_par('RA') and source.has_par('DEC'):
  219 + source['RA'].value(dir.ra_deg())
  220 + source['DEC'].value(dir.dec_deg())
  221 + source['RA'].fix()
  222 + source['DEC'].fix()
  223 + elif source.has_par('GLON') and source.has_par('GLAT'):
  224 + source['GLON'].value(dir.l_deg())
  225 + source['GLAT'].value(dir.b_deg())
  226 + source['GLON'].fix()
  227 + source['GLAT'].fix()
  228 + else:
  229 + msg = ('Source "'+srcname+'" has neither RA/DEC nor GLON/GLAT '
  230 + 'parameters. Please specify a source than can be '
  231 + 'positioned.')
  232 + raise RuntimeError(msg)
220 233  
221 234 # Remove response cache for test source
222 235 self.obs().remove_response_cache(srcname)
... ... @@ -341,9 +354,16 @@ class comlixmap(ctools.cslikelihood):
341 354 # Log header
342 355 self._log_header1(gammalib.NORMAL, 'Generate TS map')
343 356  
  357 + # Get a copy of the initial models
  358 + models = self.obs().models().copy()
  359 +
344 360 # Loop over grid positions
345 361 for ipix in range(self._maps[0].npix()):
346 362  
  363 + # Set initial models so that each pixel starts from the same
  364 + # initial model
  365 + self.obs().models(models)
  366 +
347 367 # Get sky direction of sky map pixel
348 368 dir = self._maps[0].inx2dir(ipix)
349 369  
... ... @@ -364,7 +384,9 @@ class comlixmap(ctools.cslikelihood):
364 384 for srcname in self._srcnames:
365 385 source = self.obs().models()[srcname]
366 386 for par in source:
367   - if par.name() != 'RA' and par.name() != 'DEC' and par.is_free():
  387 + if par.name() != 'RA' and par.name() != 'DEC' and \
  388 + par.name() != 'GLON' and par.name() != 'GLAT' and \
  389 + par.is_free():
368 390 self._maps[ipar][ipix] = par.value()
369 391 ipar += 1
370 392  
... ...