From e04fd4500a030450eadb92d066ae9fe056814b5c Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 17 Mar 2016 23:42:48 +0100 Subject: [PATCH] Try solving some Sonar code quality issues. --- cscripts/csfindobs.py | 1 + cscripts/csobs2caldb.py | 3 +++ cscripts/csobsdef.py | 20 ++++++++++---------- cscripts/cspull.py | 36 +++++++++++++++++++----------------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/cscripts/csfindobs.py b/cscripts/csfindobs.py index 8b02761..9881acf 100755 --- a/cscripts/csfindobs.py +++ b/cscripts/csfindobs.py @@ -48,6 +48,7 @@ class csfindobs(ctools.cscript): self._ra = 0.0 self._dec = 0.0 self._obs_index = "" + self._runs = [] # Initialise application by calling the appropriate class # constructor. diff --git a/cscripts/csobs2caldb.py b/cscripts/csobs2caldb.py index 7da6b32..4270ce3 100755 --- a/cscripts/csobs2caldb.py +++ b/cscripts/csobs2caldb.py @@ -56,6 +56,9 @@ class csobs2caldb(ctools.cscript): self._outfile = gammalib.GFilename("irf_file.fits") self._base_dir = "" self._cal_dir = "" + self._rsp_dir = "" + self._caldb_inx = gammalib.GFits() + self._irf_fits = gammalib.GFits() # Initialise observation container from constructor arguments. self._obs, argv = self._set_input_obs(argv) diff --git a/cscripts/csobsdef.py b/cscripts/csobsdef.py index 7697128..4af97cc 100755 --- a/cscripts/csobsdef.py +++ b/cscripts/csobsdef.py @@ -177,7 +177,7 @@ class csobsdef(ctools.cscript): # Clear observation container self._obs.clear() - self._id = 1 + identifier = 1 # Extract header from pointing definition file header = [] @@ -202,11 +202,11 @@ class csobsdef(ctools.cscript): # Set identifier if "id" in header: - id = pntdef[row, header.index("id")] + id_ = pntdef[row, header.index("id")] else: - id = "%6.6d" % self._id - self._id += 1 - obs.id(id) + id_ = "%6.6d" % identifier + identifier += 1 + obs.id(id_) # Set pointing if "ra" in header and "dec" in header: @@ -293,17 +293,17 @@ class csobsdef(ctools.cscript): roi = gammalib.GCTARoi(gammalib.GCTAInstDir(pntdir), rad) # Create an empty event list - list = gammalib.GCTAEventList() - list.gti(gti) + list_ = gammalib.GCTAEventList() + list_.gti(gti) # Set optional information if has_ebounds: - list.ebounds(ebounds) + list_.ebounds(ebounds) if has_roi: - list.roi(roi) + list_.roi(roi) # Attach event list to CTA observation - obs.events(list) + obs.events(list_) # Write observation into logger if self._logExplicit(): diff --git a/cscripts/cspull.py b/cscripts/cspull.py index 02e677e..9dbb4a7 100755 --- a/cscripts/cspull.py +++ b/cscripts/cspull.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # # ========================================================================== -#import gammalib +import gammalib import ctools from cscripts import obsutils import sys @@ -48,10 +48,7 @@ class cspull(ctools.cscript): self._version = "1.1.0" # Initialise some members - self._model = None - self._inmodel = None self._edisp = False - self._profile = False self._exposure = None self._psfcube = None self._bckcube = None @@ -60,6 +57,14 @@ class cspull(ctools.cscript): self._coordsys = "CEL" self._proj = "TAN" self._log_clients = False + self._offset = 0.0 + self._ntrials = 0 + self._outfile = gammalib.GFilename() + self._npix = 0 + self._binsz = 0.0 + self._pattern = "single" + self._enumbins = 0 + self._chatter = 2 # Initialise observation container from constructor arguments. self._obs, argv = self._set_input_obs(argv) @@ -93,15 +98,11 @@ class cspull(ctools.cscript): self._enumbins = self["enumbins"].integer() # Read parameters for binned if requested - if not self._enumbins == 0: + if self._enumbins != 0: self._npix = self["npix"].integer() self._binsz = self["binsz"].real() self._coordsys = self["coordsys"].string() self._proj = self["proj"].string() - else: - # Set dummy values (required by obsutils) - self._npix = 0 - self._binsz = 0.0 # Set models if we have none if self._obs.models().size() == 0: @@ -109,12 +110,13 @@ class cspull(ctools.cscript): # Read other parameters self._outfile = self["outfile"].filename() - self._ntrials = self["ntrials"].integer() + self._ntrials = self["ntrials"].integer() self._edisp = self["edisp"].boolean() - self._offset = self["offset"].real() - self._profile = self["profile"].boolean() + self._offset = self["offset"].real() self._chatter = self["chatter"].integer() - self._debug = self["debug"].boolean() + + # Query some parameters + self["profile"].boolean() # Write input parameters into logger if self._logTerse(): @@ -270,7 +272,7 @@ class cspull(ctools.cscript): coord=self._coordsys, edisp=self._edisp, log=self._log_clients, - debug=self._debug, + debug=self._logDebug(), chatter=self._chatter) # Set response for a stacked observation @@ -296,18 +298,18 @@ class cspull(ctools.cscript): self._log("\n") # Fit model - if self._profile: + if self["profile"].boolean(): models = self._obs.models() for i in range(models.size()): model_name = models[i].name() like = obsutils.cterror(self._obs, model_name, log=self._log_clients, - debug=self._debug, + debug=self._logDebug(), chatter=self._chatter) else: like = obsutils.fit(obs, edisp=self._edisp, log=self._log_clients, - debug=self._debug, + debug=self._logDebug(), chatter=self._chatter) # Store results -- libgit2 0.21.4