Commit ff06df5480722716f5d7101aa98adbf1c1fdc680

Authored by Josh Cardenzana
1 parent ec917f94

Add new parameters to cssrcdetect for smoothing. Implement smoothing methods in cssrcdetect.

cscripts/cssrcdetect.par
@@ -30,6 +30,8 @@ maxsrcs, i, h, 20,1,1000, "Maximum number of sources" @@ -30,6 +30,8 @@ maxsrcs, i, h, 20,1,1000, "Maximum number of sources"
30 exclrad, r, h, 0.2,,, "Exclusion radius (deg)" 30 exclrad, r, h, 0.2,,, "Exclusion radius (deg)"
31 fit_pos, b, h, yes,,, "Fit source positions?" 31 fit_pos, b, h, yes,,, "Fit source positions?"
32 fit_shape, b, h, yes,,, "Fit source shapes?" 32 fit_shape, b, h, yes,,, "Fit source shapes?"
  33 +smoothkernel, s, a, NONE,NONE|DISK|GAUSSIAN,,"Smoothing kernel to use for smoothing the input sky map"
  34 +smoothparam, r, a, 0.05,,,"Smoothing kernel parameters (sigma for GAUS, radius for DISK)"
33 35
34 # 36 #
35 # Standard parameters 37 # Standard parameters
cscripts/cssrcdetect.py
@@ -72,6 +72,8 @@ class cssrcdetect(ctools.cscript): @@ -72,6 +72,8 @@ class cssrcdetect(ctools.cscript):
72 self['exclrad'].real() 72 self['exclrad'].real()
73 self['fit_pos'].boolean() 73 self['fit_pos'].boolean()
74 self['fit_shape'].boolean() 74 self['fit_shape'].boolean()
  75 + self['smoothkernel'].string()
  76 + self['smoothparam'].real()
75 77
76 # Query ahead output model filename 78 # Query ahead output model filename
77 if self._read_ahead(): 79 if self._read_ahead():
@@ -338,6 +340,26 @@ class cssrcdetect(ctools.cscript): @@ -338,6 +340,26 @@ class cssrcdetect(ctools.cscript):
338 return model 340 return model
339 341
340 342
  343 + def _smooth_skymap(self, skymap):
  344 + """
  345 + Smooth the input sky map if a valid kernel was supplied
  346 +
  347 + Parameters
  348 + ----------
  349 + skymap : `~gammalib.GSkyMap()`
  350 + Sky map
  351 + """
  352 + # Make sure the smoothing kernel is not 'NONE'
  353 + if self['smoothkernel'].string().upper() != 'NONE':
  354 + skymap.smooth(self['smoothkernel'].string(),
  355 + self['smoothparam'].real())
  356 + else:
  357 + self._log_string(gammalib.NORMAL,
  358 + "Smoothing kernel is NONE, smoothing will be ignored.")
  359 +
  360 + return
  361 +
  362 +
341 def _load_skymap(self): 363 def _load_skymap(self):
342 """ 364 """
343 Load sky map 365 Load sky map
@@ -378,13 +400,16 @@ class cssrcdetect(ctools.cscript): @@ -378,13 +400,16 @@ class cssrcdetect(ctools.cscript):
378 # Get parameters 400 # Get parameters
379 self._get_parameters() 401 self._get_parameters()
380 402
381 - # Write header  
382 - self._log_header1(gammalib.NORMAL, 'Source detection')  
383 -  
384 # If sky map is empty then load it from input parameter 403 # If sky map is empty then load it from input parameter
385 if self._map.is_empty(): 404 if self._map.is_empty():
386 self._map = self._load_skymap() 405 self._map = self._load_skymap()
387 406
  407 + # Smooth the map
  408 + self._smooth_skymap(self._map)
  409 +
  410 + # Write header
  411 + self._log_header1(gammalib.NORMAL, 'Source detection')
  412 +
388 # Detect sources 413 # Detect sources
389 self._detect_sources(self._map) 414 self._detect_sources(self._map)
390 415