Commit e04fd4500a030450eadb92d066ae9fe056814b5c
1 parent
920b233b
Try solving some Sonar code quality issues.
Showing
4 changed files
with
33 additions
and
27 deletions
cscripts/csfindobs.py
| @@ -48,6 +48,7 @@ class csfindobs(ctools.cscript): | @@ -48,6 +48,7 @@ class csfindobs(ctools.cscript): | ||
| 48 | self._ra = 0.0 | 48 | self._ra = 0.0 |
| 49 | self._dec = 0.0 | 49 | self._dec = 0.0 |
| 50 | self._obs_index = "" | 50 | self._obs_index = "" |
| 51 | + self._runs = [] | ||
| 51 | 52 | ||
| 52 | # Initialise application by calling the appropriate class | 53 | # Initialise application by calling the appropriate class |
| 53 | # constructor. | 54 | # constructor. |
cscripts/csobs2caldb.py
| @@ -56,6 +56,9 @@ class csobs2caldb(ctools.cscript): | @@ -56,6 +56,9 @@ class csobs2caldb(ctools.cscript): | ||
| 56 | self._outfile = gammalib.GFilename("irf_file.fits") | 56 | self._outfile = gammalib.GFilename("irf_file.fits") |
| 57 | self._base_dir = "" | 57 | self._base_dir = "" |
| 58 | self._cal_dir = "" | 58 | self._cal_dir = "" |
| 59 | + self._rsp_dir = "" | ||
| 60 | + self._caldb_inx = gammalib.GFits() | ||
| 61 | + self._irf_fits = gammalib.GFits() | ||
| 59 | 62 | ||
| 60 | # Initialise observation container from constructor arguments. | 63 | # Initialise observation container from constructor arguments. |
| 61 | self._obs, argv = self._set_input_obs(argv) | 64 | self._obs, argv = self._set_input_obs(argv) |
cscripts/csobsdef.py
| @@ -177,7 +177,7 @@ class csobsdef(ctools.cscript): | @@ -177,7 +177,7 @@ class csobsdef(ctools.cscript): | ||
| 177 | 177 | ||
| 178 | # Clear observation container | 178 | # Clear observation container |
| 179 | self._obs.clear() | 179 | self._obs.clear() |
| 180 | - self._id = 1 | 180 | + identifier = 1 |
| 181 | 181 | ||
| 182 | # Extract header from pointing definition file | 182 | # Extract header from pointing definition file |
| 183 | header = [] | 183 | header = [] |
| @@ -202,11 +202,11 @@ class csobsdef(ctools.cscript): | @@ -202,11 +202,11 @@ class csobsdef(ctools.cscript): | ||
| 202 | 202 | ||
| 203 | # Set identifier | 203 | # Set identifier |
| 204 | if "id" in header: | 204 | if "id" in header: |
| 205 | - id = pntdef[row, header.index("id")] | 205 | + id_ = pntdef[row, header.index("id")] |
| 206 | else: | 206 | else: |
| 207 | - id = "%6.6d" % self._id | ||
| 208 | - self._id += 1 | ||
| 209 | - obs.id(id) | 207 | + id_ = "%6.6d" % identifier |
| 208 | + identifier += 1 | ||
| 209 | + obs.id(id_) | ||
| 210 | 210 | ||
| 211 | # Set pointing | 211 | # Set pointing |
| 212 | if "ra" in header and "dec" in header: | 212 | if "ra" in header and "dec" in header: |
| @@ -293,17 +293,17 @@ class csobsdef(ctools.cscript): | @@ -293,17 +293,17 @@ class csobsdef(ctools.cscript): | ||
| 293 | roi = gammalib.GCTARoi(gammalib.GCTAInstDir(pntdir), rad) | 293 | roi = gammalib.GCTARoi(gammalib.GCTAInstDir(pntdir), rad) |
| 294 | 294 | ||
| 295 | # Create an empty event list | 295 | # Create an empty event list |
| 296 | - list = gammalib.GCTAEventList() | ||
| 297 | - list.gti(gti) | 296 | + list_ = gammalib.GCTAEventList() |
| 297 | + list_.gti(gti) | ||
| 298 | 298 | ||
| 299 | # Set optional information | 299 | # Set optional information |
| 300 | if has_ebounds: | 300 | if has_ebounds: |
| 301 | - list.ebounds(ebounds) | 301 | + list_.ebounds(ebounds) |
| 302 | if has_roi: | 302 | if has_roi: |
| 303 | - list.roi(roi) | 303 | + list_.roi(roi) |
| 304 | 304 | ||
| 305 | # Attach event list to CTA observation | 305 | # Attach event list to CTA observation |
| 306 | - obs.events(list) | 306 | + obs.events(list_) |
| 307 | 307 | ||
| 308 | # Write observation into logger | 308 | # Write observation into logger |
| 309 | if self._logExplicit(): | 309 | if self._logExplicit(): |
cscripts/cspull.py
| @@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -#import gammalib | 21 | +import gammalib |
| 22 | import ctools | 22 | import ctools |
| 23 | from cscripts import obsutils | 23 | from cscripts import obsutils |
| 24 | import sys | 24 | import sys |
| @@ -48,10 +48,7 @@ class cspull(ctools.cscript): | @@ -48,10 +48,7 @@ class cspull(ctools.cscript): | ||
| 48 | self._version = "1.1.0" | 48 | self._version = "1.1.0" |
| 49 | 49 | ||
| 50 | # Initialise some members | 50 | # Initialise some members |
| 51 | - self._model = None | ||
| 52 | - self._inmodel = None | ||
| 53 | self._edisp = False | 51 | self._edisp = False |
| 54 | - self._profile = False | ||
| 55 | self._exposure = None | 52 | self._exposure = None |
| 56 | self._psfcube = None | 53 | self._psfcube = None |
| 57 | self._bckcube = None | 54 | self._bckcube = None |
| @@ -60,6 +57,14 @@ class cspull(ctools.cscript): | @@ -60,6 +57,14 @@ class cspull(ctools.cscript): | ||
| 60 | self._coordsys = "CEL" | 57 | self._coordsys = "CEL" |
| 61 | self._proj = "TAN" | 58 | self._proj = "TAN" |
| 62 | self._log_clients = False | 59 | self._log_clients = False |
| 60 | + self._offset = 0.0 | ||
| 61 | + self._ntrials = 0 | ||
| 62 | + self._outfile = gammalib.GFilename() | ||
| 63 | + self._npix = 0 | ||
| 64 | + self._binsz = 0.0 | ||
| 65 | + self._pattern = "single" | ||
| 66 | + self._enumbins = 0 | ||
| 67 | + self._chatter = 2 | ||
| 63 | 68 | ||
| 64 | # Initialise observation container from constructor arguments. | 69 | # Initialise observation container from constructor arguments. |
| 65 | self._obs, argv = self._set_input_obs(argv) | 70 | self._obs, argv = self._set_input_obs(argv) |
| @@ -93,15 +98,11 @@ class cspull(ctools.cscript): | @@ -93,15 +98,11 @@ class cspull(ctools.cscript): | ||
| 93 | self._enumbins = self["enumbins"].integer() | 98 | self._enumbins = self["enumbins"].integer() |
| 94 | 99 | ||
| 95 | # Read parameters for binned if requested | 100 | # Read parameters for binned if requested |
| 96 | - if not self._enumbins == 0: | 101 | + if self._enumbins != 0: |
| 97 | self._npix = self["npix"].integer() | 102 | self._npix = self["npix"].integer() |
| 98 | self._binsz = self["binsz"].real() | 103 | self._binsz = self["binsz"].real() |
| 99 | self._coordsys = self["coordsys"].string() | 104 | self._coordsys = self["coordsys"].string() |
| 100 | self._proj = self["proj"].string() | 105 | self._proj = self["proj"].string() |
| 101 | - else: | ||
| 102 | - # Set dummy values (required by obsutils) | ||
| 103 | - self._npix = 0 | ||
| 104 | - self._binsz = 0.0 | ||
| 105 | 106 | ||
| 106 | # Set models if we have none | 107 | # Set models if we have none |
| 107 | if self._obs.models().size() == 0: | 108 | if self._obs.models().size() == 0: |
| @@ -109,12 +110,13 @@ class cspull(ctools.cscript): | @@ -109,12 +110,13 @@ class cspull(ctools.cscript): | ||
| 109 | 110 | ||
| 110 | # Read other parameters | 111 | # Read other parameters |
| 111 | self._outfile = self["outfile"].filename() | 112 | self._outfile = self["outfile"].filename() |
| 112 | - self._ntrials = self["ntrials"].integer() | 113 | + self._ntrials = self["ntrials"].integer() |
| 113 | self._edisp = self["edisp"].boolean() | 114 | self._edisp = self["edisp"].boolean() |
| 114 | - self._offset = self["offset"].real() | ||
| 115 | - self._profile = self["profile"].boolean() | 115 | + self._offset = self["offset"].real() |
| 116 | self._chatter = self["chatter"].integer() | 116 | self._chatter = self["chatter"].integer() |
| 117 | - self._debug = self["debug"].boolean() | 117 | + |
| 118 | + # Query some parameters | ||
| 119 | + self["profile"].boolean() | ||
| 118 | 120 | ||
| 119 | # Write input parameters into logger | 121 | # Write input parameters into logger |
| 120 | if self._logTerse(): | 122 | if self._logTerse(): |
| @@ -270,7 +272,7 @@ class cspull(ctools.cscript): | @@ -270,7 +272,7 @@ class cspull(ctools.cscript): | ||
| 270 | coord=self._coordsys, | 272 | coord=self._coordsys, |
| 271 | edisp=self._edisp, | 273 | edisp=self._edisp, |
| 272 | log=self._log_clients, | 274 | log=self._log_clients, |
| 273 | - debug=self._debug, | 275 | + debug=self._logDebug(), |
| 274 | chatter=self._chatter) | 276 | chatter=self._chatter) |
| 275 | 277 | ||
| 276 | # Set response for a stacked observation | 278 | # Set response for a stacked observation |
| @@ -296,18 +298,18 @@ class cspull(ctools.cscript): | @@ -296,18 +298,18 @@ class cspull(ctools.cscript): | ||
| 296 | self._log("\n") | 298 | self._log("\n") |
| 297 | 299 | ||
| 298 | # Fit model | 300 | # Fit model |
| 299 | - if self._profile: | 301 | + if self["profile"].boolean(): |
| 300 | models = self._obs.models() | 302 | models = self._obs.models() |
| 301 | for i in range(models.size()): | 303 | for i in range(models.size()): |
| 302 | model_name = models[i].name() | 304 | model_name = models[i].name() |
| 303 | like = obsutils.cterror(self._obs, model_name, | 305 | like = obsutils.cterror(self._obs, model_name, |
| 304 | log=self._log_clients, | 306 | log=self._log_clients, |
| 305 | - debug=self._debug, | 307 | + debug=self._logDebug(), |
| 306 | chatter=self._chatter) | 308 | chatter=self._chatter) |
| 307 | else: | 309 | else: |
| 308 | like = obsutils.fit(obs, edisp=self._edisp, | 310 | like = obsutils.fit(obs, edisp=self._edisp, |
| 309 | log=self._log_clients, | 311 | log=self._log_clients, |
| 310 | - debug=self._debug, | 312 | + debug=self._logDebug(), |
| 311 | chatter=self._chatter) | 313 | chatter=self._chatter) |
| 312 | 314 | ||
| 313 | # Store results | 315 | # Store results |