Commit 0328ad4ea41b7c13658bbb05151ba7efca9dbadf
1 parent
fb79542b
Adapt unit tests to new interface
Showing
4 changed files
with
25 additions
and
22 deletions
cscripts/csspec.py
| ... | ... | @@ -451,14 +451,17 @@ class csspec(ctools.csobservation): |
| 451 | 451 | pha_off.areascal(idst, obs.off_spec().areascal(isrc)) |
| 452 | 452 | pha_off.backscal(idst, obs.off_spec().backscal(isrc)) |
| 453 | 453 | |
| 454 | - # Extract ARF | |
| 455 | - arf = gammalib.GArf(etrue) | |
| 456 | - arf_backresp = obs.arf()['BACKRESP'] | |
| 454 | + # Extract BACKRESP | |
| 455 | + pha_backresp = obs.off_spec()['BACKRESP'] | |
| 457 | 456 | backresp = [] |
| 457 | + for idst, isrc in enumerate(ireco): | |
| 458 | + backresp.append(pha_backresp[isrc]) | |
| 459 | + pha_off.append('BACKRESP', backresp) | |
| 460 | + | |
| 461 | + # Extract ARF | |
| 462 | + arf = gammalib.GArf(etrue) | |
| 458 | 463 | for idst, isrc in enumerate(itrue): |
| 459 | 464 | arf[idst] = obs.arf()[isrc] |
| 460 | - backresp.append(arf_backresp[isrc]) | |
| 461 | - arf.append('BACKRESP', backresp) | |
| 462 | 465 | |
| 463 | 466 | # Extract RMF |
| 464 | 467 | rmf = gammalib.GRmf(etrue, ereco) | ... | ... |
test/test_csphagen.py
| ... | ... | @@ -343,12 +343,12 @@ class Test(test): |
| 343 | 343 | 'Check for %d rows in energy bounds table' % bins) |
| 344 | 344 | for col in cols: |
| 345 | 345 | self.test_assert(table.contains(col), |
| 346 | - 'FITS file contains "' + col + '" column') | |
| 346 | + 'Test if EBOUNDS contains "' + col + '" column') | |
| 347 | 347 | |
| 348 | 348 | # Return |
| 349 | 349 | return |
| 350 | 350 | |
| 351 | - def _check_pha(self, filename, bins): | |
| 351 | + def _check_pha(self, filename, bins, ncols=8): | |
| 352 | 352 | """ |
| 353 | 353 | Check PHA file |
| 354 | 354 | """ |
| ... | ... | @@ -363,21 +363,21 @@ class Test(test): |
| 363 | 363 | self.test_value(fits.size(), 3, |
| 364 | 364 | 'Check for 3 extensions in PHA file') |
| 365 | 365 | self.test_assert(fits.contains('SPECTRUM'), |
| 366 | - 'FITS file contains "SPECTRUM" extension') | |
| 366 | + 'Test if PHA file contains "SPECTRUM" extension') | |
| 367 | 367 | self.test_assert(fits.contains('EBOUNDS'), |
| 368 | - 'FITS file contains "EBOUNDS" extension') | |
| 368 | + 'Test if PHA file contains "EBOUNDS" extension') | |
| 369 | 369 | |
| 370 | 370 | # Get SPECTRUM table |
| 371 | 371 | table = fits['SPECTRUM'] |
| 372 | 372 | |
| 373 | 373 | # Check FITS table structure |
| 374 | - self.test_value(table.ncols(), len(cols), | |
| 374 | + self.test_value(table.ncols(), ncols, | |
| 375 | 375 | 'Check for %d columns in PHA table' % len(cols)) |
| 376 | 376 | self.test_value(table.nrows(), bins, |
| 377 | 377 | 'Check for %d rows in PHA table' % bins) |
| 378 | 378 | for col in cols: |
| 379 | 379 | self.test_assert(table.contains(col), |
| 380 | - 'FITS file contains "' + col + '" column') | |
| 380 | + 'Test if PHA file contains "' + col + '" column') | |
| 381 | 381 | |
| 382 | 382 | # Check EBOUNDS table |
| 383 | 383 | table = fits['EBOUNDS'] |
| ... | ... | @@ -394,7 +394,7 @@ class Test(test): |
| 394 | 394 | Check ARF file |
| 395 | 395 | """ |
| 396 | 396 | # Expected column names |
| 397 | - cols = ['ENERG_LO', 'ENERG_HI', 'SPECRESP', 'BACKRESP'] | |
| 397 | + cols = ['ENERG_LO', 'ENERG_HI', 'SPECRESP'] | |
| 398 | 398 | |
| 399 | 399 | # Open FITS file |
| 400 | 400 | fits = gammalib.GFits(filename) |
| ... | ... | @@ -403,7 +403,7 @@ class Test(test): |
| 403 | 403 | self.test_value(fits.size(), 2, |
| 404 | 404 | 'Check for 2 extensions in ARF file') |
| 405 | 405 | self.test_assert(fits.contains('SPECRESP'), |
| 406 | - 'FITS file contains "SPECRESP" extension') | |
| 406 | + 'Test if ARF file contains "SPECRESP" extension') | |
| 407 | 407 | |
| 408 | 408 | # Get SPECRESP table |
| 409 | 409 | table = fits['SPECRESP'] |
| ... | ... | @@ -415,7 +415,7 @@ class Test(test): |
| 415 | 415 | 'Check for %d rows in ARF table' % bins) |
| 416 | 416 | for col in cols: |
| 417 | 417 | self.test_assert(table.contains(col), |
| 418 | - 'FITS file contains "' + col + '" column') | |
| 418 | + 'Test if ARF file contains "' + col + '" column') | |
| 419 | 419 | |
| 420 | 420 | # Close FITS file |
| 421 | 421 | fits.close() |
| ... | ... | @@ -437,9 +437,9 @@ class Test(test): |
| 437 | 437 | self.test_value(fits.size(), 3, |
| 438 | 438 | 'Check for 3 extensions in RMF file') |
| 439 | 439 | self.test_assert(fits.contains('MATRIX'), |
| 440 | - 'FITS file contains "MATRIX" extension') | |
| 440 | + 'Test if RMF file contains "MATRIX" extension') | |
| 441 | 441 | self.test_assert(fits.contains('EBOUNDS'), |
| 442 | - 'FITS file contains "EBOUNDS" extension') | |
| 442 | + 'Test if RMF file contains "EBOUNDS" extension') | |
| 443 | 443 | |
| 444 | 444 | # Get MATRIX table |
| 445 | 445 | table = fits['MATRIX'] |
| ... | ... | @@ -451,7 +451,7 @@ class Test(test): |
| 451 | 451 | 'Check for %d rows in RMF table' % etruebins) |
| 452 | 452 | for col in cols: |
| 453 | 453 | self.test_assert(table.contains(col), |
| 454 | - 'FITS file contains "' + col + '" column') | |
| 454 | + 'Test if RMF file contains "' + col + '" column') | |
| 455 | 455 | |
| 456 | 456 | # Check EBOUNDS table |
| 457 | 457 | table = fits['EBOUNDS'] |
| ... | ... | @@ -469,7 +469,7 @@ class Test(test): |
| 469 | 469 | """ |
| 470 | 470 | # OGIP files |
| 471 | 471 | self._check_pha(filenameroot + '_pha_on.fits', bins) |
| 472 | - self._check_pha(filenameroot + '_pha_off.fits', bins) | |
| 472 | + self._check_pha(filenameroot + '_pha_off.fits', bins, ncols=9) | |
| 473 | 473 | self._check_arf(filenameroot + '_arf.fits', 17) |
| 474 | 474 | self._check_rmf(filenameroot + '_rmf.fits', bins) |
| 475 | 475 | ... | ... |
test/test_csresspec.py
| ... | ... | @@ -224,7 +224,7 @@ class Test(test): |
| 224 | 224 | resspec.execute() |
| 225 | 225 | |
| 226 | 226 | # Check result file |
| 227 | - self._check_result_file('csresspec_py5.fits', 20, 8, nobs=2) | |
| 227 | + self._check_result_file('csresspec_py5.fits', 30, 8, nobs=2) | |
| 228 | 228 | |
| 229 | 229 | # Set-up csresspec for On/Off observations |
| 230 | 230 | # in stacked mode and with WSTAT background |
| ... | ... | @@ -242,7 +242,7 @@ class Test(test): |
| 242 | 242 | resspec.execute() |
| 243 | 243 | |
| 244 | 244 | # Check result file |
| 245 | - self._check_result_file('csresspec_py6.fits', 20, 8) | |
| 245 | + self._check_result_file('csresspec_py6.fits', 30, 8) | |
| 246 | 246 | |
| 247 | 247 | # Return |
| 248 | 248 | return | ... | ... |
test/test_obsutils.py
| ... | ... | @@ -280,13 +280,13 @@ class Test(test): |
| 280 | 280 | 'Check minimum energy of ARF') |
| 281 | 281 | self.test_value(res[0].arf().ebounds().emax().TeV(), 12.0, |
| 282 | 282 | 'Check minimum energy of ARF') |
| 283 | - self.test_value(res[0].arf().ebounds().size(), 42, | |
| 283 | + self.test_value(res[0].arf().ebounds().size(), 41, | |
| 284 | 284 | 'Check number of energy bins of ARF') |
| 285 | 285 | self.test_value(res[0].rmf().etrue().emin().TeV(), 0.5, |
| 286 | 286 | 'Check minimum true energy of RMF') |
| 287 | 287 | self.test_value(res[0].rmf().etrue().emax().TeV(), 12.0, |
| 288 | 288 | 'Check minimum true energy of RMF') |
| 289 | - self.test_value(res[0].rmf().etrue().size(), 42, | |
| 289 | + self.test_value(res[0].rmf().etrue().size(), 41, | |
| 290 | 290 | 'Check number of true energy bins of RMF') |
| 291 | 291 | self.test_value(res[0].rmf().emeasured().emin().TeV(), 1.0, |
| 292 | 292 | 'Check minimum reconstructed energy of RMF') | ... | ... |