Commit ea93452178e06e8c9f37cd53cf0598b7e02ca53f
1 parent
a93fe3b6
Improve code coverage
Showing
3 changed files
with
384 additions
and
23 deletions
test/test_cscript.py
| @@ -76,6 +76,35 @@ class cscript_test(ctools.cscript): | @@ -76,6 +76,35 @@ class cscript_test(ctools.cscript): | ||
| 76 | pnt = gammalib.GCTAPointing() | 76 | pnt = gammalib.GCTAPointing() |
| 77 | return self._get_roi(pnt) | 77 | return self._get_roi(pnt) |
| 78 | 78 | ||
| 79 | + # Check get_ebounds() method | ||
| 80 | + def check_get_ebounds(self): | ||
| 81 | + return self._get_ebounds() | ||
| 82 | + | ||
| 83 | + # Check get_gti() method | ||
| 84 | + def check_get_gti(self): | ||
| 85 | + ref = gammalib.GTimeReference() | ||
| 86 | + return self._get_gti(ref) | ||
| 87 | + | ||
| 88 | + # Check get_pointing() method | ||
| 89 | + def check_get_pointing(self): | ||
| 90 | + return self._get_pointing() | ||
| 91 | + | ||
| 92 | + # Check get_skydir() method | ||
| 93 | + def check_get_skydir(self): | ||
| 94 | + return self._get_skydir() | ||
| 95 | + | ||
| 96 | + # Check set_outfile_name() method | ||
| 97 | + def check_set_outfile_name(self, filename): | ||
| 98 | + return self._set_outfile_name(filename) | ||
| 99 | + | ||
| 100 | + # Check is_stacked() method | ||
| 101 | + def check_is_stacked(self): | ||
| 102 | + return self._is_stacked() | ||
| 103 | + | ||
| 104 | + # Check is_onoff() method | ||
| 105 | + def check_is_onoff(self): | ||
| 106 | + return self._is_onoff() | ||
| 107 | + | ||
| 79 | # Check restore_edisp() method | 108 | # Check restore_edisp() method |
| 80 | def check_restore_edisp(self): | 109 | def check_restore_edisp(self): |
| 81 | obs = gammalib.GObservations() | 110 | obs = gammalib.GObservations() |
| @@ -223,9 +252,9 @@ class ctlikelihood_test(ctools.cslikelihood): | @@ -223,9 +252,9 @@ class ctlikelihood_test(ctools.cslikelihood): | ||
| 223 | return self._evaluate(par, value) | 252 | return self._evaluate(par, value) |
| 224 | 253 | ||
| 225 | 254 | ||
| 226 | -# ============================ # | ||
| 227 | -# Test class for base classes # | ||
| 228 | -# ============================ # | 255 | +# =========================== # |
| 256 | +# Test class for base classes # | ||
| 257 | +# =========================== # | ||
| 229 | class Test(test): | 258 | class Test(test): |
| 230 | """ | 259 | """ |
| 231 | Test class for base classes | 260 | Test class for base classes |
| @@ -303,6 +332,27 @@ class Test(test): | @@ -303,6 +332,27 @@ class Test(test): | ||
| 303 | # Return | 332 | # Return |
| 304 | return | 333 | return |
| 305 | 334 | ||
| 335 | + # Setup cscript class | ||
| 336 | + def _setup_cscript(self): | ||
| 337 | + """ | ||
| 338 | + Setup cscript test class | ||
| 339 | + """ | ||
| 340 | + # Get text class | ||
| 341 | + test = cscript_test() | ||
| 342 | + | ||
| 343 | + # Recover User parameters | ||
| 344 | + pars = test.pars() | ||
| 345 | + | ||
| 346 | + # Create a copy of the User parameters | ||
| 347 | + cpy_pars = pars.copy() | ||
| 348 | + | ||
| 349 | + # Clear User parameters | ||
| 350 | + pars.clear() | ||
| 351 | + | ||
| 352 | + # Return | ||
| 353 | + return (test, pars, cpy_pars) | ||
| 354 | + | ||
| 355 | + | ||
| 306 | # Test cscript base class | 356 | # Test cscript base class |
| 307 | def _test_cscript(self): | 357 | def _test_cscript(self): |
| 308 | """ | 358 | """ |
| @@ -406,6 +456,14 @@ class Test(test): | @@ -406,6 +456,14 @@ class Test(test): | ||
| 406 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') | 456 | self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') |
| 407 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') | 457 | self.test_value(ebounds.emax().TeV(), 10.0, 'Check maximum energy') |
| 408 | 458 | ||
| 459 | + # Test create_ebounds() method for invalid extension name | ||
| 460 | + self.test_try('Check create_ebounds() method for invalid extension name') | ||
| 461 | + try: | ||
| 462 | + empty.check_create_ebounds('test_ebinfile_bins.fits') | ||
| 463 | + self.test_try_failure('Exception not thrown') | ||
| 464 | + except ValueError: | ||
| 465 | + self.test_try_success() | ||
| 466 | + | ||
| 409 | # Test create_map() method | 467 | # Test create_map() method |
| 410 | # TODO: implement | 468 | # TODO: implement |
| 411 | 469 | ||
| @@ -439,30 +497,297 @@ class Test(test): | @@ -439,30 +497,297 @@ class Test(test): | ||
| 439 | except ValueError: | 497 | except ValueError: |
| 440 | self.test_try_success() | 498 | self.test_try_success() |
| 441 | 499 | ||
| 442 | - # Test get_roi() method | ||
| 443 | - roi = empty.check_get_roi() | ||
| 444 | - self.test_assert(not roi.is_valid(), 'Check get_roi() method') | ||
| 445 | - | ||
| 446 | - # Test get_ebounds() method | ||
| 447 | - # TODO: implement | ||
| 448 | - | ||
| 449 | - # Test get_gti() method | ||
| 450 | - # TODO: implement | 500 | + # Test get_roi() method for the case that there is no "usepnt" |
| 501 | + # parameter and that there are no valid "ra" and "dec" parameters. | ||
| 502 | + # In that case an empty ROI should be returned. | ||
| 503 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 504 | + pars.append(gammalib.GApplicationPar('ra','r','h','NONE','','','')) | ||
| 505 | + pars.append(gammalib.GApplicationPar('dec','r','h','NONE','','','')) | ||
| 506 | + roi = test.check_get_roi() | ||
| 507 | + self.test_assert(not roi.is_valid(), 'Check that get_roi() for absent ' | ||
| 508 | + '"usepnt" and invalid "ra" and "dec" parameters returns ' | ||
| 509 | + 'an invalid ROI') | ||
| 510 | + test.pars(cpy_pars) | ||
| 511 | + | ||
| 512 | + # Test get_roi() method for the case that there is no "usepnt" | ||
| 513 | + # parameter and that there is no valid "ra" parameter. | ||
| 514 | + # In that case an empty ROI should be returned. | ||
| 515 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 516 | + pars.append(gammalib.GApplicationPar('ra','r','h','NONE','','','')) | ||
| 517 | + pars.append(gammalib.GApplicationPar('dec','r','h','10.0','','','')) | ||
| 518 | + roi = test.check_get_roi() | ||
| 519 | + self.test_assert(not roi.is_valid(), 'Check that get_roi() for absent ' | ||
| 520 | + '"usepnt" and an invalid "ra" parameter returns ' | ||
| 521 | + 'an invalid ROI') | ||
| 522 | + test.pars(cpy_pars) | ||
| 523 | + | ||
| 524 | + # Test get_roi() method for the case that there is no "usepnt" | ||
| 525 | + # parameter and that there is no valid "dec" parameter. | ||
| 526 | + # In that case an empty ROI should be returned. | ||
| 527 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 528 | + pars.append(gammalib.GApplicationPar('ra','r','h','10.0','','','')) | ||
| 529 | + pars.append(gammalib.GApplicationPar('dec','r','h','NONE','','','')) | ||
| 530 | + roi = test.check_get_roi() | ||
| 531 | + self.test_assert(not roi.is_valid(), 'Check that get_roi() for absent ' | ||
| 532 | + '"usepnt" and an invalid "dec" parameter returns ' | ||
| 533 | + 'an invalid ROI') | ||
| 534 | + test.pars(cpy_pars) | ||
| 535 | + | ||
| 536 | + # Test get_roi() method for the case that there is no "usepnt" | ||
| 537 | + # parameter and that there are valid "ra", "dec" and "rad" parameters. | ||
| 538 | + # In that case a valid ROI should be returned. | ||
| 539 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 540 | + pars.append(gammalib.GApplicationPar('ra','r','h','10.0','','','')) | ||
| 541 | + pars.append(gammalib.GApplicationPar('dec','r','h','20.0','','','')) | ||
| 542 | + pars.append(gammalib.GApplicationPar('rad','r','h','1.0','','','')) | ||
| 543 | + roi = test.check_get_roi() | ||
| 544 | + self.test_assert(roi.is_valid(), 'Check that get_roi() for absent ' | ||
| 545 | + '"usepnt" and valid "ra", "dec" and "rad" parameters ' | ||
| 546 | + 'returns a valid ROI') | ||
| 547 | + self.test_value(roi.centre().dir().ra_deg(), 10.0, 'Check Right Ascension') | ||
| 548 | + self.test_value(roi.centre().dir().dec_deg(), 20.0, 'Check Declination') | ||
| 549 | + self.test_value(roi.radius(), 1.0, 'Check radius') | ||
| 550 | + test.pars(cpy_pars) | ||
| 551 | + | ||
| 552 | + # Test get_roi() method for the case that there is a "usepnt" | ||
| 553 | + # parameter and that there is a valid "rad" parameter. | ||
| 554 | + # In that case a valid ROI should be returned. | ||
| 555 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 556 | + pars.append(gammalib.GApplicationPar('usepnt','b','h','yes','','','')) | ||
| 557 | + pars.append(gammalib.GApplicationPar('rad','r','h','1.0','','','')) | ||
| 558 | + roi = test.check_get_roi() | ||
| 559 | + self.test_assert(roi.is_valid(), 'Check that get_roi() for present ' | ||
| 560 | + '"usepnt" and valid "rad" parameter returns a valid ROI') | ||
| 561 | + self.test_value(roi.centre().dir().ra_deg(), 0.0, 'Check Right Ascension') | ||
| 562 | + self.test_value(roi.centre().dir().dec_deg(), 0.0, 'Check Declination') | ||
| 563 | + self.test_value(roi.radius(), 1.0, 'Check radius') | ||
| 564 | + test.pars(cpy_pars) | ||
| 565 | + | ||
| 566 | + # Test get_ebounds() method for the case that both "emin" and "emax" | ||
| 567 | + # parameters are invalid. In that case an empty energy boundary should | ||
| 568 | + # be returned. | ||
| 569 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 570 | + pars.append(gammalib.GApplicationPar('emin','r','h','NONE','','','')) | ||
| 571 | + pars.append(gammalib.GApplicationPar('emax','r','h','NONE','','','')) | ||
| 572 | + ebounds = test.check_get_ebounds() | ||
| 573 | + self.test_value(ebounds.size(), 0, 'Check that get_ebounds() for ' | ||
| 574 | + 'invalid "emin" and "emax" parameters returns empty ' | ||
| 575 | + 'energy boundaries') | ||
| 576 | + test.pars(cpy_pars) | ||
| 577 | + | ||
| 578 | + # Test get_ebounds() method for the case that the "emin" parameter is | ||
| 579 | + # invalid. In that case an empty energy boundary should be returned. | ||
| 580 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 581 | + pars.append(gammalib.GApplicationPar('emin','r','h','NONE','','','')) | ||
| 582 | + pars.append(gammalib.GApplicationPar('emax','r','h','100.0','','','')) | ||
| 583 | + ebounds = test.check_get_ebounds() | ||
| 584 | + self.test_value(ebounds.size(), 0, 'Check that get_ebounds() for ' | ||
| 585 | + 'invalid "emin" parameter returns empty energy ' | ||
| 586 | + 'boundaries') | ||
| 587 | + test.pars(cpy_pars) | ||
| 588 | + | ||
| 589 | + # Test get_ebounds() method for the case that the "emax" parameter is | ||
| 590 | + # invalid. In that case an empty energy boundary should be returned. | ||
| 591 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 592 | + pars.append(gammalib.GApplicationPar('emin','r','h','1.0','','','')) | ||
| 593 | + pars.append(gammalib.GApplicationPar('emax','r','h','NONE','','','')) | ||
| 594 | + ebounds = test.check_get_ebounds() | ||
| 595 | + self.test_value(ebounds.size(), 0, 'Check that get_ebounds() for ' | ||
| 596 | + 'invalid "emax" parameter returns empty energy ' | ||
| 597 | + 'boundaries') | ||
| 598 | + test.pars(cpy_pars) | ||
| 599 | + | ||
| 600 | + # Test get_ebounds() method for the case of valid "emin" and "emax" | ||
| 601 | + # parameters. In that case a single energy boundary should be returned. | ||
| 602 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 603 | + pars.append(gammalib.GApplicationPar('emin','r','h','1.0','','','')) | ||
| 604 | + pars.append(gammalib.GApplicationPar('emax','r','h','100.0','','','')) | ||
| 605 | + ebounds = test.check_get_ebounds() | ||
| 606 | + self.test_value(ebounds.size(), 1, 'Check that get_ebounds() for ' | ||
| 607 | + 'valid "emin" and "emax" parameters returns empty one ' | ||
| 608 | + 'energy boundary') | ||
| 609 | + self.test_value(ebounds.emin().TeV(), 1.0, 'Check minimum energy') | ||
| 610 | + self.test_value(ebounds.emax().TeV(), 100.0, 'Check maximum energy') | ||
| 611 | + test.pars(cpy_pars) | ||
| 612 | + | ||
| 613 | + # Test get_gti() method for the case that both "tmin" and "tmax" | ||
| 614 | + # parameters are invalid. In that case an empty Good Time Interval | ||
| 615 | + # should be returned. | ||
| 616 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 617 | + pars.append(gammalib.GApplicationPar('tmin','t','h','NONE','','','')) | ||
| 618 | + pars.append(gammalib.GApplicationPar('tmax','t','h','NONE','','','')) | ||
| 619 | + gti = test.check_get_gti() | ||
| 620 | + self.test_value(gti.size(), 0, 'Check that get_gti() for invalid "tmin" ' | ||
| 621 | + 'and "tmax" parameters returns empty GTI') | ||
| 622 | + test.pars(cpy_pars) | ||
| 623 | + | ||
| 624 | + # Test get_gti() method for the case that the "tmin" parameter is | ||
| 625 | + # invalid. In that case an empty Good Time Interval should be returned. | ||
| 626 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 627 | + pars.append(gammalib.GApplicationPar('tmin','t','h','NONE','','','')) | ||
| 628 | + pars.append(gammalib.GApplicationPar('tmax','t','h','2005-10-08T14:58:26','','','')) | ||
| 629 | + gti = test.check_get_gti() | ||
| 630 | + self.test_value(gti.size(), 0, 'Check that get_gti() for an invalid ' | ||
| 631 | + '"tmin" parameter returns empty GTI') | ||
| 632 | + test.pars(cpy_pars) | ||
| 633 | + | ||
| 634 | + # Test get_gti() method for the case that the "tmax" parameter is | ||
| 635 | + # invalid. In that case an empty Good Time Interval should be returned. | ||
| 636 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 637 | + pars.append(gammalib.GApplicationPar('tmin','t','h','2005-10-08T14:30:25','','','')) | ||
| 638 | + pars.append(gammalib.GApplicationPar('tmax','t','h','NONE','','','')) | ||
| 639 | + gti = test.check_get_gti() | ||
| 640 | + self.test_value(gti.size(), 0, 'Check that get_gti() for an invalid ' | ||
| 641 | + '"tmax" parameter returns empty GTI') | ||
| 642 | + test.pars(cpy_pars) | ||
| 643 | + | ||
| 644 | + # Test get_gti() method for the case that both "tmin" and "tmax" | ||
| 645 | + # parameters are valid. In that case a valid Good Time Interval should | ||
| 646 | + # be returned. | ||
| 647 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 648 | + pars.append(gammalib.GApplicationPar('tmin','t','h','2005-10-08T14:30:25','','','')) | ||
| 649 | + pars.append(gammalib.GApplicationPar('tmax','t','h','2005-10-08T14:58:26','','','')) | ||
| 650 | + gti = test.check_get_gti() | ||
| 651 | + self.test_value(gti.size(), 1, 'Check that get_gti() for valid "tmin" ' | ||
| 652 | + 'and "tmax" parameters returns one GTI') | ||
| 653 | + self.test_value(gti.tstart().utc(), '2005-10-08T14:30:25', 'Check "tmin"') | ||
| 654 | + self.test_value(gti.tstop().utc(), '2005-10-08T14:58:26', 'Check "tmax"') | ||
| 655 | + test.pars(cpy_pars) | ||
| 451 | 656 | ||
| 452 | # Test get_pointing() method | 657 | # Test get_pointing() method |
| 453 | - # TODO: implement | 658 | + test, pars, cpy_pars = self._setup_cscript() |
| 659 | + pars.append(gammalib.GApplicationPar('ra','r','h','10.0','','','')) | ||
| 660 | + pars.append(gammalib.GApplicationPar('dec','r','h','20.0','','','')) | ||
| 661 | + pnt = test.check_get_pointing() | ||
| 662 | + self.test_value(pnt.dir().ra_deg(), 10.0, 'Check Right Ascension') | ||
| 663 | + self.test_value(pnt.dir().dec_deg(), 20.0, 'Check Declination') | ||
| 664 | + test.pars(cpy_pars) | ||
| 454 | 665 | ||
| 455 | # Test get_skydir() method | 666 | # Test get_skydir() method |
| 456 | - # TODO: implement | ||
| 457 | - | ||
| 458 | - # Test set_outfile_name() method | ||
| 459 | - # TODO: implement | ||
| 460 | - | ||
| 461 | - # Test is_stacked() method | ||
| 462 | - # TODO: implement | ||
| 463 | - | ||
| 464 | - # Test is_onoff() method | ||
| 465 | - # TODO: implement | 667 | + test, pars, cpy_pars = self._setup_cscript() |
| 668 | + pars.append(gammalib.GApplicationPar('ra','r','h','10.0','','','')) | ||
| 669 | + pars.append(gammalib.GApplicationPar('dec','r','h','20.0','','','')) | ||
| 670 | + dir = test.check_get_skydir() | ||
| 671 | + self.test_value(dir.ra_deg(), 10.0, 'Check Right Ascension') | ||
| 672 | + self.test_value(dir.dec_deg(), 20.0, 'Check Declination') | ||
| 673 | + test.pars(cpy_pars) | ||
| 674 | + | ||
| 675 | + # Test set_outfile_name() method for "fix" filename, which should | ||
| 676 | + # return the prefixed basename. | ||
| 677 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 678 | + pars.append(gammalib.GApplicationPar('prefix','s','h','pre_','','','')) | ||
| 679 | + filename = test.check_set_outfile_name('fix') | ||
| 680 | + self.test_value(filename, 'pre_fix', 'Check "pre_fix"') | ||
| 681 | + test.pars(cpy_pars) | ||
| 682 | + | ||
| 683 | + # Test set_outfile_name() method for "/path/to/fix" filename, which | ||
| 684 | + # should return the prefixed basename. | ||
| 685 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 686 | + pars.append(gammalib.GApplicationPar('prefix','s','h','pre_','','','')) | ||
| 687 | + filename = test.check_set_outfile_name('/path/to/fix') | ||
| 688 | + self.test_value(filename, 'pre_fix', 'Check "pre_fix"') | ||
| 689 | + test.pars(cpy_pars) | ||
| 690 | + | ||
| 691 | + # Test set_outfile_name() method for "/path/to/fix.gz" filename, which | ||
| 692 | + # should return the prefixed basename without the ".gz" | ||
| 693 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 694 | + pars.append(gammalib.GApplicationPar('prefix','s','h','pre_','','','')) | ||
| 695 | + filename = test.check_set_outfile_name('/path/to/fix.gz') | ||
| 696 | + self.test_value(filename, 'pre_fix', 'Check "pre_fix"') | ||
| 697 | + test.pars(cpy_pars) | ||
| 698 | + | ||
| 699 | + # Test set_outfile_name() method for empty filename, which should | ||
| 700 | + # return an empty filename. | ||
| 701 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 702 | + pars.append(gammalib.GApplicationPar('prefix','s','h','pre_','','','')) | ||
| 703 | + filename = test.check_set_outfile_name('') | ||
| 704 | + self.test_value(filename, '', 'Check on empty string') | ||
| 705 | + test.pars(cpy_pars) | ||
| 706 | + | ||
| 707 | + # Test is_stacked() method for the case that "enumbins" is zero. In | ||
| 708 | + # that case the is_stacked() method should return False. | ||
| 709 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 710 | + pars.append(gammalib.GApplicationPar('emin','r','h','1.0','','','')) | ||
| 711 | + pars.append(gammalib.GApplicationPar('emax','r','h','100.0','','','')) | ||
| 712 | + pars.append(gammalib.GApplicationPar('enumbins','i','h','0','','','')) | ||
| 713 | + self.test_assert(not test.check_is_stacked(), 'Check if is_stacked() ' | ||
| 714 | + 'returns False if there are no energy bins') | ||
| 715 | + test.pars(cpy_pars) | ||
| 716 | + | ||
| 717 | + # Test is_stacked() method for the case that "enumbins" is larger | ||
| 718 | + # than zero. In that case the is_stacked() method should return True | ||
| 719 | + # and query a bunch of parameters. | ||
| 720 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 721 | + pars.append(gammalib.GApplicationPar('emin','r','h','1.0','','','')) | ||
| 722 | + pars.append(gammalib.GApplicationPar('emax','r','h','100.0','','','')) | ||
| 723 | + pars.append(gammalib.GApplicationPar('enumbins','i','h','10','','','')) | ||
| 724 | + pars.append(gammalib.GApplicationPar('coordsys','s','h','CEL','','','')) | ||
| 725 | + pars.append(gammalib.GApplicationPar('proj','s','h','TAN','','','')) | ||
| 726 | + pars.append(gammalib.GApplicationPar('xref','r','h','11.1','','','')) | ||
| 727 | + pars.append(gammalib.GApplicationPar('yref','r','h','12.1','','','')) | ||
| 728 | + pars.append(gammalib.GApplicationPar('nxpix','i','h','100','','','')) | ||
| 729 | + pars.append(gammalib.GApplicationPar('nypix','i','h','100','','','')) | ||
| 730 | + pars.append(gammalib.GApplicationPar('binsz','r','h','0.02','','','')) | ||
| 731 | + self.test_assert(test.check_is_stacked(), 'Check if is_stacked() ' | ||
| 732 | + 'returns True if there are energy bins') | ||
| 733 | + test.pars(cpy_pars) | ||
| 734 | + | ||
| 735 | + # Test is_onoff() method for the case that method='NONE', i.e. the | ||
| 736 | + # method is not 'ONOFF'. In that case the is_onoff() method should | ||
| 737 | + # return False. | ||
| 738 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 739 | + pars.append(gammalib.GApplicationPar('method','s','h','NONE','','','')) | ||
| 740 | + self.test_assert(not test.check_is_onoff(), | ||
| 741 | + 'Check if is_onoff() returns False if method is not "ONOFF"') | ||
| 742 | + test.pars(cpy_pars) | ||
| 743 | + | ||
| 744 | + # Test is_onoff() method for the case that method='ONOFF', | ||
| 745 | + # srcshape='CIRCLE' and bkgmethod='REFLECTED'. In that case the | ||
| 746 | + # is_onoff() method should return True and a bunch of application | ||
| 747 | + # parameters are queried. | ||
| 748 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 749 | + pars.append(gammalib.GApplicationPar('method','s','h','ONOFF','','','')) | ||
| 750 | + pars.append(gammalib.GApplicationPar('inexclusion','f','h','NONE','','','')) | ||
| 751 | + pars.append(gammalib.GApplicationPar('emin','r','h','0.1','','','')) | ||
| 752 | + pars.append(gammalib.GApplicationPar('emax','r','h','100.0','','','')) | ||
| 753 | + pars.append(gammalib.GApplicationPar('enumbins','i','h','10','','','')) | ||
| 754 | + pars.append(gammalib.GApplicationPar('coordsys','s','h','CEL','','','')) | ||
| 755 | + pars.append(gammalib.GApplicationPar('xref','r','h','11.1','','','')) | ||
| 756 | + pars.append(gammalib.GApplicationPar('yref','r','h','12.1','','','')) | ||
| 757 | + pars.append(gammalib.GApplicationPar('srcshape','s','h','CIRCLE','','','')) | ||
| 758 | + pars.append(gammalib.GApplicationPar('rad','r','h','1.1','','','')) | ||
| 759 | + pars.append(gammalib.GApplicationPar('bkgmethod','s','h','REFLECTED','','','')) | ||
| 760 | + pars.append(gammalib.GApplicationPar('bkgregmin','i','h','3','','','')) | ||
| 761 | + pars.append(gammalib.GApplicationPar('maxoffset','r','h','0.1','','','')) | ||
| 762 | + pars.append(gammalib.GApplicationPar('etruemin','r','h','0.1','','','')) | ||
| 763 | + pars.append(gammalib.GApplicationPar('etruemax','r','h','100.0','','','')) | ||
| 764 | + pars.append(gammalib.GApplicationPar('etruebins','i','h','10','','','')) | ||
| 765 | + self.test_assert(test.check_is_onoff(), | ||
| 766 | + 'Check if is_onoff() returns True if method is "ONOFF"') | ||
| 767 | + test.pars(cpy_pars) | ||
| 768 | + | ||
| 769 | + # Test is_onoff() method for the case that method='ONOFF', | ||
| 770 | + # srcshape='CIRCLE' and bkgmethod='REFLECTED'. In that case the | ||
| 771 | + # is_onoff() method should return True and a bunch of application | ||
| 772 | + # parameters are queried, except of rad and bkgregmin. | ||
| 773 | + test, pars, cpy_pars = self._setup_cscript() | ||
| 774 | + pars.append(gammalib.GApplicationPar('method','s','h','ONOFF','','','')) | ||
| 775 | + pars.append(gammalib.GApplicationPar('inexclusion','f','h','NONE','','','')) | ||
| 776 | + pars.append(gammalib.GApplicationPar('emin','r','h','0.1','','','')) | ||
| 777 | + pars.append(gammalib.GApplicationPar('emax','r','h','100.0','','','')) | ||
| 778 | + pars.append(gammalib.GApplicationPar('enumbins','i','h','10','','','')) | ||
| 779 | + pars.append(gammalib.GApplicationPar('coordsys','s','h','CEL','','','')) | ||
| 780 | + pars.append(gammalib.GApplicationPar('xref','r','h','11.1','','','')) | ||
| 781 | + pars.append(gammalib.GApplicationPar('yref','r','h','12.1','','','')) | ||
| 782 | + pars.append(gammalib.GApplicationPar('srcshape','s','h','NONE','','','')) | ||
| 783 | + pars.append(gammalib.GApplicationPar('bkgmethod','s','h','NONE','','','')) | ||
| 784 | + pars.append(gammalib.GApplicationPar('maxoffset','r','h','0.1','','','')) | ||
| 785 | + pars.append(gammalib.GApplicationPar('etruemin','r','h','0.1','','','')) | ||
| 786 | + pars.append(gammalib.GApplicationPar('etruemax','r','h','100.0','','','')) | ||
| 787 | + pars.append(gammalib.GApplicationPar('etruebins','i','h','10','','','')) | ||
| 788 | + self.test_assert(test.check_is_onoff(), | ||
| 789 | + 'Check if is_onoff() returns True if method is "ONOFF"') | ||
| 790 | + test.pars(cpy_pars) | ||
| 466 | 791 | ||
| 467 | # Test set_response() method | 792 | # Test set_response() method |
| 468 | # TODO: implement | 793 | # TODO: implement |
test/test_ctedispcube.py
| @@ -217,6 +217,25 @@ class Test(test): | @@ -217,6 +217,25 @@ class Test(test): | ||
| 217 | # Check result file | 217 | # Check result file |
| 218 | self._check_result_file('ctedispcube_py3.fits') | 218 | self._check_result_file('ctedispcube_py3.fits') |
| 219 | 219 | ||
| 220 | + # Set-up ctexpcube from event list and counts cube | ||
| 221 | + edispcube = ctools.ctedispcube() | ||
| 222 | + edispcube['inobs'] = self._events | ||
| 223 | + edispcube['incube'] = self._cntcube | ||
| 224 | + edispcube['caldb'] = self._caldb | ||
| 225 | + edispcube['irf'] = self._irf | ||
| 226 | + edispcube['migramax'] = 2.0 | ||
| 227 | + edispcube['migrabins'] = 10 | ||
| 228 | + edispcube['outcube'] = 'ctedispcube_py4.fits' | ||
| 229 | + edispcube['logfile'] = 'ctedispcube_py4.log' | ||
| 230 | + edispcube['chatter'] = 2 | ||
| 231 | + | ||
| 232 | + # Run ctedispcube tool | ||
| 233 | + edispcube.logFileOpen() # Make sure we get a log file | ||
| 234 | + edispcube.execute() | ||
| 235 | + | ||
| 236 | + # Check result file | ||
| 237 | + self._check_result_file('ctedispcube_py4.fits') | ||
| 238 | + | ||
| 220 | # Return | 239 | # Return |
| 221 | return | 240 | return |
| 222 | 241 |
test/test_ctexpcube.py
| @@ -210,6 +210,23 @@ class Test(test): | @@ -210,6 +210,23 @@ class Test(test): | ||
| 210 | # Check result file | 210 | # Check result file |
| 211 | self._check_result_file('ctexpcube_py3.fits') | 211 | self._check_result_file('ctexpcube_py3.fits') |
| 212 | 212 | ||
| 213 | + # Set-up ctexpcube from event list and counts cube | ||
| 214 | + expcube = ctools.ctexpcube() | ||
| 215 | + expcube['inobs'] = self._events | ||
| 216 | + expcube['incube'] = self._cntcube | ||
| 217 | + expcube['caldb'] = self._caldb | ||
| 218 | + expcube['irf'] = self._irf | ||
| 219 | + expcube['logfile'] = 'ctexpcube_py4.log' | ||
| 220 | + expcube['outcube'] = 'ctexpcube_py4.fits' | ||
| 221 | + expcube['chatter'] = 2 | ||
| 222 | + | ||
| 223 | + # Execute ctexpcube tool | ||
| 224 | + expcube.logFileOpen() # Needed to get a new log file | ||
| 225 | + expcube.execute() | ||
| 226 | + | ||
| 227 | + # Check result file | ||
| 228 | + self._check_result_file('ctexpcube_py4.fits') | ||
| 229 | + | ||
| 213 | # Return | 230 | # Return |
| 214 | return | 231 | return |
| 215 | 232 |