Commit 27c6936b9623269523683a195c226744d9d208fb
1 parent
d74d5a2c
Add basic functionality test for each tool (just runs the tools without any check out the result)
Showing
10 changed files
with
273 additions
and
5 deletions
test/test_ctbin.py
| ... | ... | @@ -38,6 +38,7 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 41 | 42 | |
| 42 | 43 | # Return |
| 43 | 44 | return |
| ... | ... | @@ -61,5 +62,37 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 62 | """ |
| 62 | 63 | Test ctbin functionnality. |
| 63 | 64 | """ |
| 65 | + # Set-up ctbin | |
| 66 | + bin = ctools.ctbin() | |
| 67 | + bin["evfile"].filename(self.events_name) | |
| 68 | + bin["outfile"].filename("cntmap.fits") | |
| 69 | + bin["ebinalg"].string("LOG") | |
| 70 | + bin["emin"].real(0.1) | |
| 71 | + bin["emax"].real(100.0) | |
| 72 | + bin["enumbins"].integer(20) | |
| 73 | + bin["nxpix"].integer(200) | |
| 74 | + bin["nypix"].integer(200) | |
| 75 | + bin["binsz"].real(0.02) | |
| 76 | + bin["coordsys"].string("CEL") | |
| 77 | + bin["proj"].string("CAR") | |
| 78 | + bin["xref"].real(83.63) | |
| 79 | + bin["yref"].real(22.01) | |
| 80 | + | |
| 81 | + # Run tool | |
| 82 | + self.test_try("Run ctbin") | |
| 83 | + try: | |
| 84 | + bin.run() | |
| 85 | + self.test_try_success() | |
| 86 | + except: | |
| 87 | + self.test_try_failure("Exception occured in ctbin.") | |
| 88 | + | |
| 89 | + # Save counts cube | |
| 90 | + self.test_try("Save counts cube") | |
| 91 | + try: | |
| 92 | + bin.save() | |
| 93 | + self.test_try_success() | |
| 94 | + except: | |
| 95 | + self.test_try_failure("Exception occured in saving counts cube.") | |
| 96 | + | |
| 64 | 97 | # Return |
| 65 | 98 | return | ... | ... |
test/test_ctcubemask.py
| ... | ... | @@ -38,6 +38,8 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.cntmap_name = "data/crab_cntmap.fits" | |
| 42 | + self.regfile = "data/exclusion.reg" | |
| 41 | 43 | |
| 42 | 44 | # Return |
| 43 | 45 | return |
| ... | ... | @@ -61,5 +63,32 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 63 | """ |
| 62 | 64 | Test ctcubemask functionnality. |
| 63 | 65 | """ |
| 66 | + # Set-up ctcubemask | |
| 67 | + mask = ctools.ctcubemask() | |
| 68 | + mask["infile"].filename(self.cntmap_name) | |
| 69 | + mask["regfile"].filename(self.regfile) | |
| 70 | + mask["outfile"].filename("filtered_cntmap.fits") | |
| 71 | + mask["ra"].real(83.63) | |
| 72 | + mask["dec"].real(22.01) | |
| 73 | + mask["rad"].real(2.0) | |
| 74 | + mask["emin"].real(0.1) | |
| 75 | + mask["emax"].real(100.0) | |
| 76 | + | |
| 77 | + # Run tool | |
| 78 | + self.test_try("Run ctcubemask") | |
| 79 | + try: | |
| 80 | + mask.run() | |
| 81 | + self.test_try_success() | |
| 82 | + except: | |
| 83 | + self.test_try_failure("Exception occured in ctcubemask.") | |
| 84 | + | |
| 85 | + # Save counts cube | |
| 86 | + self.test_try("Save counts cube") | |
| 87 | + try: | |
| 88 | + mask.save() | |
| 89 | + self.test_try_success() | |
| 90 | + except: | |
| 91 | + self.test_try_failure("Exception occured in saving counts cube.") | |
| 92 | + | |
| 64 | 93 | # Return |
| 65 | 94 | return | ... | ... |
test/test_ctexpcube.py
| ... | ... | @@ -38,6 +38,9 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 42 | + self.caldb = "irf" | |
| 43 | + self.irf = "cta_dummy_irf" | |
| 41 | 44 | |
| 42 | 45 | # Return |
| 43 | 46 | return |
| ... | ... | @@ -61,5 +64,40 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 64 | """ |
| 62 | 65 | Test ctexpcube functionnality. |
| 63 | 66 | """ |
| 67 | + # Set-up ctexpcube | |
| 68 | + expcube = ctools.ctexpcube() | |
| 69 | + expcube["infile"].filename(self.events_name) | |
| 70 | + expcube["cntmap"].filename("NONE") | |
| 71 | + expcube["outfile"].filename("expcube.fits") | |
| 72 | + expcube["caldb"].string(self.caldb) | |
| 73 | + expcube["irf"].string(self.irf) | |
| 74 | + expcube["ebinalg"].string("LOG") | |
| 75 | + expcube["emin"].real(0.1) | |
| 76 | + expcube["emax"].real(100.0) | |
| 77 | + expcube["enumbins"].integer(20) | |
| 78 | + expcube["nxpix"].integer(200) | |
| 79 | + expcube["nypix"].integer(200) | |
| 80 | + expcube["binsz"].real(0.02) | |
| 81 | + expcube["coordsys"].string("CEL") | |
| 82 | + expcube["proj"].string("CAR") | |
| 83 | + expcube["xref"].real(83.63) | |
| 84 | + expcube["yref"].real(22.01) | |
| 85 | + | |
| 86 | + # Run tool | |
| 87 | + self.test_try("Run ctexpcube") | |
| 88 | + try: | |
| 89 | + expcube.run() | |
| 90 | + self.test_try_success() | |
| 91 | + except: | |
| 92 | + self.test_try_failure("Exception occured in ctexpcube.") | |
| 93 | + | |
| 94 | + # Save exposure cube | |
| 95 | + self.test_try("Save exposure cube") | |
| 96 | + try: | |
| 97 | + expcube.save() | |
| 98 | + self.test_try_success() | |
| 99 | + except: | |
| 100 | + self.test_try_failure("Exception occured in saving exposure cube.") | |
| 101 | + | |
| 64 | 102 | # Return |
| 65 | 103 | return | ... | ... |
test/test_ctlike.py
| ... | ... | @@ -38,6 +38,10 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 42 | + self.model_name = "data/crab.xml" | |
| 43 | + self.caldb = "irf" | |
| 44 | + self.irf = "cta_dummy_irf" | |
| 41 | 45 | |
| 42 | 46 | # Return |
| 43 | 47 | return |
| ... | ... | @@ -61,5 +65,29 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 65 | """ |
| 62 | 66 | Test ctlike functionnality. |
| 63 | 67 | """ |
| 68 | + # Set-up ctlike | |
| 69 | + like = ctools.ctlike() | |
| 70 | + like["infile"].filename(self.events_name) | |
| 71 | + like["srcmdl"].filename(self.model_name) | |
| 72 | + like["caldb"].string(self.caldb) | |
| 73 | + like["irf"].string(self.irf) | |
| 74 | + like["outmdl"].filename("result.xml") | |
| 75 | + | |
| 76 | + # Run tool | |
| 77 | + self.test_try("Run ctlike") | |
| 78 | + try: | |
| 79 | + like.run() | |
| 80 | + self.test_try_success() | |
| 81 | + except: | |
| 82 | + self.test_try_failure("Exception occured in ctlike.") | |
| 83 | + | |
| 84 | + # Save results | |
| 85 | + self.test_try("Save results") | |
| 86 | + try: | |
| 87 | + like.save() | |
| 88 | + self.test_try_success() | |
| 89 | + except: | |
| 90 | + self.test_try_failure("Exception occured in saving results.") | |
| 91 | + | |
| 64 | 92 | # Return |
| 65 | 93 | return | ... | ... |
test/test_ctmodel.py
| ... | ... | @@ -38,6 +38,9 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.model_name = "data/crab.xml" | |
| 42 | + self.caldb = "irf" | |
| 43 | + self.irf = "cta_dummy_irf" | |
| 41 | 44 | |
| 42 | 45 | # Return |
| 43 | 46 | return |
| ... | ... | @@ -61,5 +64,43 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 64 | """ |
| 62 | 65 | Test ctmodel functionnality. |
| 63 | 66 | """ |
| 67 | + # Set-up ctmodel from scratch | |
| 68 | + model = ctools.ctmodel() | |
| 69 | + model["infile"].filename("NONE") | |
| 70 | + model["outfile"].filename("modmap.fits") | |
| 71 | + model["caldb"].string(self.caldb) | |
| 72 | + model["irf"].string(self.irf) | |
| 73 | + model["srcmdl"].filename(self.model_name) | |
| 74 | + model["ra"].real(83.63) | |
| 75 | + model["dec"].real(22.01) | |
| 76 | + model["tmin"].real(0.0) | |
| 77 | + model["tmax"].real(1800.0) | |
| 78 | + model["emin"].real(0.1) | |
| 79 | + model["emax"].real(100.0) | |
| 80 | + model["enumbins"].integer(20) | |
| 81 | + model["nxpix"].integer(200) | |
| 82 | + model["nypix"].integer(200) | |
| 83 | + model["binsz"].real(0.02) | |
| 84 | + model["coordsys"].string("CEL") | |
| 85 | + model["proj"].string("CAR") | |
| 86 | + model["xref"].real(83.63) | |
| 87 | + model["yref"].real(22.01) | |
| 88 | + | |
| 89 | + # Run tool | |
| 90 | + self.test_try("Run ctmodel") | |
| 91 | + try: | |
| 92 | + model.run() | |
| 93 | + self.test_try_success() | |
| 94 | + except: | |
| 95 | + self.test_try_failure("Exception occured in ctmodel.") | |
| 96 | + | |
| 97 | + # Save counts cube | |
| 98 | + self.test_try("Save model cube") | |
| 99 | + try: | |
| 100 | + model.save() | |
| 101 | + self.test_try_success() | |
| 102 | + except: | |
| 103 | + self.test_try_failure("Exception occured in saving model cube.") | |
| 104 | + | |
| 64 | 105 | # Return |
| 65 | 106 | return | ... | ... |
test/test_ctobssim.py
| ... | ... | @@ -38,10 +38,9 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | - self.model_name = "data/crab.xml" | |
| 42 | - self.events_name = "events.fits" | |
| 43 | - self.caldb = "irf" | |
| 44 | - self.irf = "cta_dummy_irf" | |
| 41 | + self.model_name = "data/crab.xml" | |
| 42 | + self.caldb = "irf" | |
| 43 | + self.irf = "cta_dummy_irf" | |
| 45 | 44 | |
| 46 | 45 | # Return |
| 47 | 46 | return | ... | ... |
test/test_ctools.sh
| ... | ... | @@ -447,7 +447,7 @@ $ECHO " ok" |
| 447 | 447 | # Test ctcubemask |
| 448 | 448 | # =============== |
| 449 | 449 | $ECHO -n "Test ctcubemask: " |
| 450 | -$ctcubemask infile="data/crab_events.fits" \ | |
| 450 | +$ctcubemask infile="data/crab_cntmap.fits" \ | |
| 451 | 451 | regfile="data/exclusion.reg" \ |
| 452 | 452 | outfile="filtered_cube.fits" \ |
| 453 | 453 | ra=83.63 \ | ... | ... |
test/test_ctpsfcube.py
| ... | ... | @@ -38,6 +38,9 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 42 | + self.caldb = "irf" | |
| 43 | + self.irf = "cta_dummy_irf" | |
| 41 | 44 | |
| 42 | 45 | # Return |
| 43 | 46 | return |
| ... | ... | @@ -61,5 +64,42 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 64 | """ |
| 62 | 65 | Test ctpsfcube functionnality. |
| 63 | 66 | """ |
| 67 | + # Set-up ctpsfcube | |
| 68 | + psfcube = ctools.ctpsfcube() | |
| 69 | + psfcube["infile"].filename(self.events_name) | |
| 70 | + psfcube["cntmap"].filename("NONE") | |
| 71 | + psfcube["outfile"].filename("psfcube.fits") | |
| 72 | + psfcube["caldb"].string(self.caldb) | |
| 73 | + psfcube["irf"].string(self.irf) | |
| 74 | + psfcube["ebinalg"].string("LOG") | |
| 75 | + psfcube["emin"].real(0.1) | |
| 76 | + psfcube["emax"].real(100.0) | |
| 77 | + psfcube["enumbins"].integer(20) | |
| 78 | + psfcube["nxpix"].integer(10) | |
| 79 | + psfcube["nypix"].integer(10) | |
| 80 | + psfcube["binsz"].real(0.4) | |
| 81 | + psfcube["coordsys"].string("CEL") | |
| 82 | + psfcube["proj"].string("CAR") | |
| 83 | + psfcube["xref"].real(83.63) | |
| 84 | + psfcube["yref"].real(22.01) | |
| 85 | + psfcube["amax"].real(0.3) | |
| 86 | + psfcube["anumbins"].integer(10) | |
| 87 | + | |
| 88 | + # Run tool | |
| 89 | + self.test_try("Run ctpsfcube") | |
| 90 | + try: | |
| 91 | + psfcube.run() | |
| 92 | + self.test_try_success() | |
| 93 | + except: | |
| 94 | + self.test_try_failure("Exception occured in ctpsfcube.") | |
| 95 | + | |
| 96 | + # Save PSF cube | |
| 97 | + self.test_try("Save PSF cube") | |
| 98 | + try: | |
| 99 | + psfcube.save() | |
| 100 | + self.test_try_success() | |
| 101 | + except: | |
| 102 | + self.test_try_failure("Exception occured in saving PSF cube.") | |
| 103 | + | |
| 64 | 104 | # Return |
| 65 | 105 | return | ... | ... |
test/test_ctselect.py
| ... | ... | @@ -38,6 +38,7 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 41 | 42 | |
| 42 | 43 | # Return |
| 43 | 44 | return |
| ... | ... | @@ -61,5 +62,33 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 62 | """ |
| 62 | 63 | Test ctselect functionnality. |
| 63 | 64 | """ |
| 65 | + # Set-up ctselect | |
| 66 | + select = ctools.ctselect() | |
| 67 | + select["infile"].filename(self.events_name) | |
| 68 | + select["outfile"].filename("selected_events.fits") | |
| 69 | + select["ra"].real(83.63) | |
| 70 | + select["dec"].real(22.01) | |
| 71 | + select["rad"].real(3.0) | |
| 72 | + select["tmin"].real(0.0) | |
| 73 | + select["tmax"].real(1800.0) | |
| 74 | + select["emin"].real(0.1) | |
| 75 | + select["emax"].real(100.0) | |
| 76 | + | |
| 77 | + # Run tool | |
| 78 | + self.test_try("Run ctselect") | |
| 79 | + try: | |
| 80 | + select.run() | |
| 81 | + self.test_try_success() | |
| 82 | + except: | |
| 83 | + self.test_try_failure("Exception occured in ctselect.") | |
| 84 | + | |
| 85 | + # Save events | |
| 86 | + self.test_try("Save events") | |
| 87 | + try: | |
| 88 | + select.save() | |
| 89 | + self.test_try_success() | |
| 90 | + except: | |
| 91 | + self.test_try_failure("Exception occured in saving events.") | |
| 92 | + | |
| 64 | 93 | # Return |
| 65 | 94 | return | ... | ... |
test/test_ctskymap.py
| ... | ... | @@ -38,6 +38,7 @@ class Test(gammalib.GPythonTestSuite): |
| 38 | 38 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 39 | |
| 40 | 40 | # Set members |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 41 | 42 | |
| 42 | 43 | # Return |
| 43 | 44 | return |
| ... | ... | @@ -61,5 +62,35 @@ class Test(gammalib.GPythonTestSuite): |
| 61 | 62 | """ |
| 62 | 63 | Test ctskymap functionnality. |
| 63 | 64 | """ |
| 65 | + # Set-up ctskymap | |
| 66 | + skymap = ctools.ctskymap() | |
| 67 | + skymap["evfile"].filename(self.events_name) | |
| 68 | + skymap["outfile"].filename("skymap.fits") | |
| 69 | + skymap["emin"].real(0.1) | |
| 70 | + skymap["emax"].real(100.0) | |
| 71 | + skymap["nxpix"].integer(200) | |
| 72 | + skymap["nypix"].integer(200) | |
| 73 | + skymap["binsz"].real(0.02) | |
| 74 | + skymap["coordsys"].string("CEL") | |
| 75 | + skymap["proj"].string("CAR") | |
| 76 | + skymap["xref"].real(83.63) | |
| 77 | + skymap["yref"].real(22.01) | |
| 78 | + | |
| 79 | + # Run tool | |
| 80 | + self.test_try("Run ctskymap") | |
| 81 | + try: | |
| 82 | + skymap.run() | |
| 83 | + self.test_try_success() | |
| 84 | + except: | |
| 85 | + self.test_try_failure("Exception occured in ctskymap.") | |
| 86 | + | |
| 87 | + # Save counts cube | |
| 88 | + self.test_try("Save sky map") | |
| 89 | + try: | |
| 90 | + skymap.save() | |
| 91 | + self.test_try_success() | |
| 92 | + except: | |
| 93 | + self.test_try_failure("Exception occured in saving sky map.") | |
| 94 | + | |
| 64 | 95 | # Return |
| 65 | 96 | return | ... | ... |