Commit e0ba2a94009e75b998e12979d8faf924d427edd7
1 parent
35b1bdd3
Enhance code quality (#1828)
Showing
2 changed files
with
48 additions
and
40 deletions
test/test_cscript.py
| @@ -49,56 +49,56 @@ class cscript_test(ctools.cscript): | @@ -49,56 +49,56 @@ class cscript_test(ctools.cscript): | ||
| 49 | return | 49 | return |
| 50 | 50 | ||
| 51 | # Check is_valid_filename() method | 51 | # Check is_valid_filename() method |
| 52 | - def _check_is_valid_filename(self, filename): | 52 | + def check_is_valid_filename(self, filename): |
| 53 | return self._is_valid_filename(gammalib.GFilename(filename)) | 53 | return self._is_valid_filename(gammalib.GFilename(filename)) |
| 54 | 54 | ||
| 55 | # Check setup_observations() method | 55 | # Check setup_observations() method |
| 56 | - def _check_setup_observations(self, filename, list=True, cube=True): | 56 | + def check_setup_observations(self, filename, events=True, cube=True): |
| 57 | self.pars()['inobs'].value(filename) | 57 | self.pars()['inobs'].value(filename) |
| 58 | obs = gammalib.GObservations() | 58 | obs = gammalib.GObservations() |
| 59 | - self._setup_observations(obs, True, list, cube) | 59 | + self._setup_observations(obs, True, events, cube) |
| 60 | return | 60 | return |
| 61 | 61 | ||
| 62 | # Check setup_models() method | 62 | # Check setup_models() method |
| 63 | - def _check_setup_models(self): | 63 | + def check_setup_models(self): |
| 64 | obs = gammalib.GObservations() | 64 | obs = gammalib.GObservations() |
| 65 | self._setup_models(obs) | 65 | self._setup_models(obs) |
| 66 | return | 66 | return |
| 67 | 67 | ||
| 68 | # Check create_ebounds() method | 68 | # Check create_ebounds() method |
| 69 | - def _check_create_ebounds(self, filename): | 69 | + def check_create_ebounds(self, filename): |
| 70 | self.pars()['ebinfile'].value(filename) | 70 | self.pars()['ebinfile'].value(filename) |
| 71 | return self._create_ebounds() | 71 | return self._create_ebounds() |
| 72 | 72 | ||
| 73 | # Check require_inobs() method | 73 | # Check require_inobs() method |
| 74 | - def _check_require_inobs(self, filename): | 74 | + def check_require_inobs(self, filename): |
| 75 | self.pars()['inobs'].value(filename) | 75 | self.pars()['inobs'].value(filename) |
| 76 | - self._require_inobs('_check_require_inobs') | 76 | + self._require_inobs('check_require_inobs') |
| 77 | return | 77 | return |
| 78 | 78 | ||
| 79 | # Check get_roi() method | 79 | # Check get_roi() method |
| 80 | - def _check_get_roi(self): | 80 | + def check_get_roi(self): |
| 81 | return self._get_roi() | 81 | return self._get_roi() |
| 82 | 82 | ||
| 83 | # Check restore_edisp() method | 83 | # Check restore_edisp() method |
| 84 | - def _check_restore_edisp(self): | 84 | + def check_restore_edisp(self): |
| 85 | obs = gammalib.GObservations() | 85 | obs = gammalib.GObservations() |
| 86 | edisp = [True, True] | 86 | edisp = [True, True] |
| 87 | self._restore_edisp(obs, edisp) | 87 | self._restore_edisp(obs, edisp) |
| 88 | return | 88 | return |
| 89 | 89 | ||
| 90 | # Check set_obs_bounds() method | 90 | # Check set_obs_bounds() method |
| 91 | - def _check_set_obs_bounds(self): | ||
| 92 | - obs = gammalib.GObservations() | ||
| 93 | - list = gammalib.GCTAEventList() | ||
| 94 | - cta = gammalib.GCTAObservation() | ||
| 95 | - cta.events(list) | 91 | + def check_set_obs_bounds(self): |
| 92 | + obs = gammalib.GObservations() | ||
| 93 | + events = gammalib.GCTAEventList() | ||
| 94 | + cta = gammalib.GCTAObservation() | ||
| 95 | + cta.events(events) | ||
| 96 | obs.append(cta) | 96 | obs.append(cta) |
| 97 | self._set_obs_bounds(obs) | 97 | self._set_obs_bounds(obs) |
| 98 | return obs.copy() | 98 | return obs.copy() |
| 99 | 99 | ||
| 100 | # Check get_mean_pointing() method | 100 | # Check get_mean_pointing() method |
| 101 | - def _check_get_mean_pointing(self): | 101 | + def check_get_mean_pointing(self): |
| 102 | obs = gammalib.GObservations() | 102 | obs = gammalib.GObservations() |
| 103 | return self._get_mean_pointing(obs) | 103 | return self._get_mean_pointing(obs) |
| 104 | 104 | ||
| @@ -149,7 +149,7 @@ class ctlikelihood_test(ctools.cslikelihood): | @@ -149,7 +149,7 @@ class ctlikelihood_test(ctools.cslikelihood): | ||
| 149 | return | 149 | return |
| 150 | 150 | ||
| 151 | # Check evaluate() method | 151 | # Check evaluate() method |
| 152 | - def _check_evaluate(self, value): | 152 | + def check_evaluate(self, value): |
| 153 | par = gammalib.GModelPar() | 153 | par = gammalib.GModelPar() |
| 154 | par.value(2.0) | 154 | par.value(2.0) |
| 155 | par.range(1.0, 3.0) | 155 | par.range(1.0, 3.0) |
| @@ -230,17 +230,17 @@ class Test(test): | @@ -230,17 +230,17 @@ class Test(test): | ||
| 230 | empty = cscript_test() | 230 | empty = cscript_test() |
| 231 | 231 | ||
| 232 | # Test is_valid_filename() method | 232 | # Test is_valid_filename() method |
| 233 | - self.test_assert(empty._check_is_valid_filename(self._model), | 233 | + self.test_assert(empty.check_is_valid_filename(self._model), |
| 234 | 'Check model definiton XML file') | 234 | 'Check model definiton XML file') |
| 235 | - self.test_assert(not empty._check_is_valid_filename(''), | 235 | + self.test_assert(not empty.check_is_valid_filename(''), |
| 236 | 'Check empty filename') | 236 | 'Check empty filename') |
| 237 | - self.test_assert(not empty._check_is_valid_filename('NONE'), | 237 | + self.test_assert(not empty.check_is_valid_filename('NONE'), |
| 238 | 'Check "NONE" filename') | 238 | 'Check "NONE" filename') |
| 239 | 239 | ||
| 240 | # Test setup_observations() for invalid file name | 240 | # Test setup_observations() for invalid file name |
| 241 | self.test_try('Check setup_observations() for "NONE"') | 241 | self.test_try('Check setup_observations() for "NONE"') |
| 242 | try: | 242 | try: |
| 243 | - empty._check_setup_observations('NONE') | 243 | + empty.check_setup_observations('NONE') |
| 244 | self.test_try_failure('Exception not thrown') | 244 | self.test_try_failure('Exception not thrown') |
| 245 | except ValueError: | 245 | except ValueError: |
| 246 | self.test_try_success() | 246 | self.test_try_success() |
| @@ -248,7 +248,7 @@ class Test(test): | @@ -248,7 +248,7 @@ class Test(test): | ||
| 248 | # Test setup_observations() for unacceptable event list | 248 | # Test setup_observations() for unacceptable event list |
| 249 | self.test_try('Check setup_observations() for unacceptable event list') | 249 | self.test_try('Check setup_observations() for unacceptable event list') |
| 250 | try: | 250 | try: |
| 251 | - empty._check_setup_observations(self._events, list=False) | 251 | + empty.check_setup_observations(self._events, events=False) |
| 252 | self.test_try_failure('Exception not thrown') | 252 | self.test_try_failure('Exception not thrown') |
| 253 | except ValueError: | 253 | except ValueError: |
| 254 | self.test_try_success() | 254 | self.test_try_success() |
| @@ -256,7 +256,7 @@ class Test(test): | @@ -256,7 +256,7 @@ class Test(test): | ||
| 256 | # Test setup_observations() for unacceptable counts cube | 256 | # Test setup_observations() for unacceptable counts cube |
| 257 | self.test_try('Check setup_observations() for unacceptable counts cube') | 257 | self.test_try('Check setup_observations() for unacceptable counts cube') |
| 258 | try: | 258 | try: |
| 259 | - empty._check_setup_observations(self._cntcube, cube=False) | 259 | + empty.check_setup_observations(self._cntcube, cube=False) |
| 260 | self.test_try_failure('Exception not thrown') | 260 | self.test_try_failure('Exception not thrown') |
| 261 | except ValueError: | 261 | except ValueError: |
| 262 | self.test_try_success() | 262 | self.test_try_success() |
| @@ -264,19 +264,19 @@ class Test(test): | @@ -264,19 +264,19 @@ class Test(test): | ||
| 264 | # Test setup_models() for invalid model definition file name | 264 | # Test setup_models() for invalid model definition file name |
| 265 | self.test_try('Check setup_models() for invalid model definition file name') | 265 | self.test_try('Check setup_models() for invalid model definition file name') |
| 266 | try: | 266 | try: |
| 267 | - empty._check_setup_models() | 267 | + empty.check_setup_models() |
| 268 | self.test_try_failure('Exception not thrown') | 268 | self.test_try_failure('Exception not thrown') |
| 269 | except ValueError: | 269 | except ValueError: |
| 270 | self.test_try_success() | 270 | self.test_try_success() |
| 271 | 271 | ||
| 272 | # Test create_ebounds() method for "EBOUNDS" extension | 272 | # Test create_ebounds() method for "EBOUNDS" extension |
| 273 | - ebounds = empty._check_create_ebounds('test_ebinfile_ebounds.fits') | 273 | + ebounds = empty.check_create_ebounds('test_ebinfile_ebounds.fits') |
| 274 | self.test_value(ebounds.size(), 1, 'Check number of energy boundaries') | 274 | self.test_value(ebounds.size(), 1, 'Check number of energy boundaries') |
| 275 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') | 275 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') |
| 276 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') | 276 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') |
| 277 | 277 | ||
| 278 | # Test create_ebounds() method for "ENERGYBINS" extension | 278 | # Test create_ebounds() method for "ENERGYBINS" extension |
| 279 | - ebounds = empty._check_create_ebounds('test_ebinfile_energybins.fits') | 279 | + ebounds = empty.check_create_ebounds('test_ebinfile_energybins.fits') |
| 280 | self.test_value(ebounds.size(), 1, 'Check number of energy boundaries') | 280 | self.test_value(ebounds.size(), 1, 'Check number of energy boundaries') |
| 281 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') | 281 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') |
| 282 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') | 282 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') |
| @@ -284,27 +284,33 @@ class Test(test): | @@ -284,27 +284,33 @@ class Test(test): | ||
| 284 | # Test create_ebounds() method for invalid extension | 284 | # Test create_ebounds() method for invalid extension |
| 285 | self.test_try('Check create_ebounds() method for invalid extension') | 285 | self.test_try('Check create_ebounds() method for invalid extension') |
| 286 | try: | 286 | try: |
| 287 | - empty._check_create_ebounds('test_ebinfile_energies.fits') | 287 | + empty.check_create_ebounds('test_ebinfile_energies.fits') |
| 288 | self.test_try_failure('Exception not thrown') | 288 | self.test_try_failure('Exception not thrown') |
| 289 | except ValueError: | 289 | except ValueError: |
| 290 | self.test_try_success() | 290 | self.test_try_success() |
| 291 | 291 | ||
| 292 | + # Test create_ebounds() method for "ENERGIES" extension | ||
| 293 | + ebounds = empty.check_create_ebounds('test_ebinfile_energies.fits[ENERGIES]') | ||
| 294 | + self.test_value(ebounds.size(), 1, 'Check number of energy boundaries') | ||
| 295 | + self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') | ||
| 296 | + self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') | ||
| 297 | + | ||
| 292 | # Test require_inobs() method for invalid file name | 298 | # Test require_inobs() method for invalid file name |
| 293 | self.test_try('Check require_inobs() method for invalid file name') | 299 | self.test_try('Check require_inobs() method for invalid file name') |
| 294 | try: | 300 | try: |
| 295 | - empty._check_require_inobs('NONE') | 301 | + empty.check_require_inobs('NONE') |
| 296 | self.test_try_failure('Exception not thrown') | 302 | self.test_try_failure('Exception not thrown') |
| 297 | except ValueError: | 303 | except ValueError: |
| 298 | self.test_try_success() | 304 | self.test_try_success() |
| 299 | 305 | ||
| 300 | # Test get_roi() method | 306 | # Test get_roi() method |
| 301 | - roi = empty._check_get_roi() | 307 | + roi = empty.check_get_roi() |
| 302 | self.test_assert(not roi.is_valid(), 'Check get_roi() method') | 308 | self.test_assert(not roi.is_valid(), 'Check get_roi() method') |
| 303 | 309 | ||
| 304 | # Test restore_edisp() method for invalid vector size | 310 | # Test restore_edisp() method for invalid vector size |
| 305 | #self.test_try('Check restore_edisp() method for invalid vector size') | 311 | #self.test_try('Check restore_edisp() method for invalid vector size') |
| 306 | #try: | 312 | #try: |
| 307 | - # empty._check_restore_edisp() | 313 | + # empty.check_restore_edisp() |
| 308 | # self.test_try_failure('Exception not thrown') | 314 | # self.test_try_failure('Exception not thrown') |
| 309 | #except ValueError: | 315 | #except ValueError: |
| 310 | # self.test_try_success() | 316 | # self.test_try_success() |
| @@ -313,7 +319,7 @@ class Test(test): | @@ -313,7 +319,7 @@ class Test(test): | ||
| 313 | # integer vector conversion. | 319 | # integer vector conversion. |
| 314 | 320 | ||
| 315 | # Test set_obs_bounds() method | 321 | # Test set_obs_bounds() method |
| 316 | - obs = empty._check_set_obs_bounds() | 322 | + obs = empty.check_set_obs_bounds() |
| 317 | self.test_value(obs.size(), 1, 'Check number of observations') | 323 | self.test_value(obs.size(), 1, 'Check number of observations') |
| 318 | self.test_value(obs[0].events().ebounds().size(), 1, | 324 | self.test_value(obs[0].events().ebounds().size(), 1, |
| 319 | 'Check number of energy boundaries') | 325 | 'Check number of energy boundaries') |
| @@ -328,7 +334,7 @@ class Test(test): | @@ -328,7 +334,7 @@ class Test(test): | ||
| 328 | self.test_try('Check get_mean_pointing() method for empty observation ' | 334 | self.test_try('Check get_mean_pointing() method for empty observation ' |
| 329 | 'container') | 335 | 'container') |
| 330 | try: | 336 | try: |
| 331 | - empty._check_get_mean_pointing() | 337 | + empty.check_get_mean_pointing() |
| 332 | self.test_try_failure('Exception not thrown') | 338 | self.test_try_failure('Exception not thrown') |
| 333 | except ValueError: | 339 | except ValueError: |
| 334 | self.test_try_success() | 340 | self.test_try_success() |
| @@ -366,7 +372,7 @@ class Test(test): | @@ -366,7 +372,7 @@ class Test(test): | ||
| 366 | # Test evaluate() method for minimum value violation | 372 | # Test evaluate() method for minimum value violation |
| 367 | self.test_try('Check evaluate() for minimum value violation') | 373 | self.test_try('Check evaluate() for minimum value violation') |
| 368 | try: | 374 | try: |
| 369 | - empty._check_evaluate(0.0) | 375 | + empty.check_evaluate(0.0) |
| 370 | self.test_try_failure('Exception not thrown') | 376 | self.test_try_failure('Exception not thrown') |
| 371 | except ValueError: | 377 | except ValueError: |
| 372 | self.test_try_success() | 378 | self.test_try_success() |
| @@ -374,7 +380,7 @@ class Test(test): | @@ -374,7 +380,7 @@ class Test(test): | ||
| 374 | # Test evaluate() method for maximum value violation | 380 | # Test evaluate() method for maximum value violation |
| 375 | self.test_try('Check evaluate() for maximum value violation') | 381 | self.test_try('Check evaluate() for maximum value violation') |
| 376 | try: | 382 | try: |
| 377 | - empty._check_evaluate(4.0) | 383 | + empty.check_evaluate(4.0) |
| 378 | self.test_try_failure('Exception not thrown') | 384 | self.test_try_failure('Exception not thrown') |
| 379 | except ValueError: | 385 | except ValueError: |
| 380 | self.test_try_success() | 386 | self.test_try_success() |
test/test_ctskymap.py
| @@ -152,13 +152,15 @@ class Test(test): | @@ -152,13 +152,15 @@ class Test(test): | ||
| 152 | 152 | ||
| 153 | # Execute copy of ctskymap tool again, now with a higher chatter | 153 | # Execute copy of ctskymap tool again, now with a higher chatter |
| 154 | # level than before | 154 | # level than before |
| 155 | - cpy_skymap['usepnt'] = True | ||
| 156 | - cpy_skymap['emin'] = 0.2 | ||
| 157 | - cpy_skymap['emax'] = 150.0 | ||
| 158 | - cpy_skymap['outmap'] = 'ctskymap_py2.fits' | ||
| 159 | - cpy_skymap['logfile'] = 'ctskymap_py2.log' | ||
| 160 | - cpy_skymap['publish'] = True | ||
| 161 | - cpy_skymap['chatter'] = 3 | 155 | + cpy_skymap['usepnt'] = True |
| 156 | + cpy_skymap['emin'] = 0.2 | ||
| 157 | + cpy_skymap['emax'] = 150.0 | ||
| 158 | + cpy_skymap['coordsys'] = 'GAL' | ||
| 159 | + cpy_skymap['proj'] = 'CAR' | ||
| 160 | + cpy_skymap['outmap'] = 'ctskymap_py2.fits' | ||
| 161 | + cpy_skymap['logfile'] = 'ctskymap_py2.log' | ||
| 162 | + cpy_skymap['publish'] = True | ||
| 163 | + cpy_skymap['chatter'] = 3 | ||
| 162 | cpy_skymap.logFileOpen() # Needed to get a new log file | 164 | cpy_skymap.logFileOpen() # Needed to get a new log file |
| 163 | cpy_skymap.execute() | 165 | cpy_skymap.execute() |
| 164 | 166 |