From ff06df5480722716f5d7101aa98adbf1c1fdc680 Mon Sep 17 00:00:00 2001 From: Josh Cardenzana Date: Tue, 7 Aug 2018 14:03:32 +0200 Subject: [PATCH] Add new parameters to cssrcdetect for smoothing. Implement smoothing methods in cssrcdetect. --- cscripts/cssrcdetect.par | 2 ++ cscripts/cssrcdetect.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cscripts/cssrcdetect.par b/cscripts/cssrcdetect.par index d3caa9f..2101b33 100755 --- a/cscripts/cssrcdetect.par +++ b/cscripts/cssrcdetect.par @@ -30,6 +30,8 @@ maxsrcs, i, h, 20,1,1000, "Maximum number of sources" exclrad, r, h, 0.2,,, "Exclusion radius (deg)" fit_pos, b, h, yes,,, "Fit source positions?" fit_shape, b, h, yes,,, "Fit source shapes?" +smoothkernel, s, a, NONE,NONE|DISK|GAUSSIAN,,"Smoothing kernel to use for smoothing the input sky map" +smoothparam, r, a, 0.05,,,"Smoothing kernel parameters (sigma for GAUS, radius for DISK)" # # Standard parameters diff --git a/cscripts/cssrcdetect.py b/cscripts/cssrcdetect.py index a5dbc9d..58781b6 100755 --- a/cscripts/cssrcdetect.py +++ b/cscripts/cssrcdetect.py @@ -72,6 +72,8 @@ class cssrcdetect(ctools.cscript): self['exclrad'].real() self['fit_pos'].boolean() self['fit_shape'].boolean() + self['smoothkernel'].string() + self['smoothparam'].real() # Query ahead output model filename if self._read_ahead(): @@ -338,6 +340,26 @@ class cssrcdetect(ctools.cscript): return model + def _smooth_skymap(self, skymap): + """ + Smooth the input sky map if a valid kernel was supplied + + Parameters + ---------- + skymap : `~gammalib.GSkyMap()` + Sky map + """ + # Make sure the smoothing kernel is not 'NONE' + if self['smoothkernel'].string().upper() != 'NONE': + skymap.smooth(self['smoothkernel'].string(), + self['smoothparam'].real()) + else: + self._log_string(gammalib.NORMAL, + "Smoothing kernel is NONE, smoothing will be ignored.") + + return + + def _load_skymap(self): """ Load sky map @@ -378,13 +400,16 @@ class cssrcdetect(ctools.cscript): # Get parameters self._get_parameters() - # Write header - self._log_header1(gammalib.NORMAL, 'Source detection') - # If sky map is empty then load it from input parameter if self._map.is_empty(): self._map = self._load_skymap() + # Smooth the map + self._smooth_skymap(self._map) + + # Write header + self._log_header1(gammalib.NORMAL, 'Source detection') + # Detect sources self._detect_sources(self._map) -- libgit2 0.21.4