Commit d89b29212a3787552a26888eb87cc249ae131df8
1 parent
976a9ff9
Remove old test scripts
Showing
2 changed files
with
0 additions
and
151 deletions
pyext/ctools/tests/__init__.py deleted
pyext/ctools/tests/unbinned.py deleted
| 1 | -# ========================================================================== | ||
| 2 | -# This script tests the unbinned analysis. | ||
| 3 | -# | ||
| 4 | -# Copyright (C) 2015 Christoph Deil | ||
| 5 | -# | ||
| 6 | -# This program is free software: you can redistribute it and/or modify | ||
| 7 | -# it under the terms of the GNU General Public License as published by | ||
| 8 | -# the Free Software Foundation, either version 3 of the License, or | ||
| 9 | -# (at your option) any later version. | ||
| 10 | -# | ||
| 11 | -# This program is distributed in the hope that it will be useful, | ||
| 12 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | -# GNU General Public License for more details. | ||
| 15 | -# | ||
| 16 | -# You should have received a copy of the GNU General Public License | ||
| 17 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | -# | ||
| 19 | -# ========================================================================== | ||
| 20 | -import os | ||
| 21 | -from tempfile import mkdtemp | ||
| 22 | -import unittest | ||
| 23 | -import ctools | ||
| 24 | - | ||
| 25 | - | ||
| 26 | -# ================== # | ||
| 27 | -# Analysis pipelines # | ||
| 28 | -# ================== # | ||
| 29 | -class pipelines(unittest.TestCase): | ||
| 30 | - """ | ||
| 31 | - Test a simple unbinned analysis pipeline. | ||
| 32 | - """ | ||
| 33 | - # Setup of test class | ||
| 34 | - def setUp(self): | ||
| 35 | - gammalib_dir = os.environ['GAMMALIB'] | ||
| 36 | - self.model_name = os.path.join(gammalib_dir, "share/models/crab.xml") | ||
| 37 | - self.workdir = mkdtemp() | ||
| 38 | - | ||
| 39 | - # Test unbinned analysis with FITS files | ||
| 40 | - def test_unbinned_fits(self): | ||
| 41 | - """ | ||
| 42 | - Test unbinned pipeline with FITS file saving. | ||
| 43 | - """ | ||
| 44 | - # Set script parameters | ||
| 45 | - model_name = self.model_name | ||
| 46 | - events_name = os.path.join(self.workdir, "events.fits") | ||
| 47 | - selected_events_name = os.path.join(self.workdir, "selected_events.fits") | ||
| 48 | - result_name = os.path.join(self.workdir, "results.xml") | ||
| 49 | - caldb = "prod2" | ||
| 50 | - irf = "South_50h" | ||
| 51 | - ra = 83.63 | ||
| 52 | - dec = 22.01 | ||
| 53 | - rad_sim = 10.0 | ||
| 54 | - tstart = 0.0 | ||
| 55 | - tstop = 1800.0 | ||
| 56 | - emin = 0.1 | ||
| 57 | - emax = 100.0 | ||
| 58 | - rad_select = 3.0 | ||
| 59 | - | ||
| 60 | - # Simulate events | ||
| 61 | - sim = ctools.ctobssim() | ||
| 62 | - sim["inmodel"] = model_name | ||
| 63 | - sim["outevents"] = events_name | ||
| 64 | - sim["caldb"] = caldb | ||
| 65 | - sim["irf"] = irf | ||
| 66 | - sim["ra"] = ra | ||
| 67 | - sim["dec"] = dec | ||
| 68 | - sim["rad"] = rad_sim | ||
| 69 | - sim["tmin"] = tstart | ||
| 70 | - sim["tmax"] = tstop | ||
| 71 | - sim["emin"] = emin | ||
| 72 | - sim["emax"] = emax | ||
| 73 | - sim.execute() | ||
| 74 | - | ||
| 75 | - # Select events | ||
| 76 | - select = ctools.ctselect() | ||
| 77 | - select["inobs"] = events_name | ||
| 78 | - select["outobs"] = selected_events_name | ||
| 79 | - select["ra"] = ra | ||
| 80 | - select["dec"] = dec | ||
| 81 | - select["rad"] = rad_select | ||
| 82 | - select["tmin"] = tstart | ||
| 83 | - select["tmax"] = tstop | ||
| 84 | - select["emin"] = emin | ||
| 85 | - select["emax"] = emax | ||
| 86 | - select.execute() | ||
| 87 | - | ||
| 88 | - # Perform maximum likelihood fitting | ||
| 89 | - like = ctools.ctlike() | ||
| 90 | - like["inobs"] = selected_events_name | ||
| 91 | - like["inmodel"] = model_name | ||
| 92 | - like["outmodel"] = result_name | ||
| 93 | - like["caldb"] = caldb | ||
| 94 | - like["irf"] = irf | ||
| 95 | - like.execute() | ||
| 96 | - | ||
| 97 | - # TODO: add asserts | ||
| 98 | - assert True | ||
| 99 | - | ||
| 100 | - # Test unbinned analysis in memory | ||
| 101 | - def test_unbinned_mem(self): | ||
| 102 | - """ | ||
| 103 | - Test unbinned in-memory pipeline. | ||
| 104 | - """ | ||
| 105 | - # Set script parameters | ||
| 106 | - model_name = self.model_name | ||
| 107 | - caldb = "prod2" | ||
| 108 | - irf = "South_50h" | ||
| 109 | - ra = 83.63 | ||
| 110 | - dec = 22.01 | ||
| 111 | - rad_sim = 10.0 | ||
| 112 | - tstart = 0.0 | ||
| 113 | - tstop = 1800.0 | ||
| 114 | - emin = 0.1 | ||
| 115 | - emax = 100.0 | ||
| 116 | - rad_select = 3.0 | ||
| 117 | - | ||
| 118 | - # Simulate events | ||
| 119 | - sim = ctools.ctobssim() | ||
| 120 | - sim["inmodel"] = model_name | ||
| 121 | - sim["caldb"] = caldb | ||
| 122 | - sim["irf"] = irf | ||
| 123 | - sim["ra"] = ra | ||
| 124 | - sim["dec"] = dec | ||
| 125 | - sim["rad"] = rad_sim | ||
| 126 | - sim["tmin"] = tstart | ||
| 127 | - sim["tmax"] = tstop | ||
| 128 | - sim["emin"] = emin | ||
| 129 | - sim["emax"] = emax | ||
| 130 | - sim.run() | ||
| 131 | - | ||
| 132 | - # Select events | ||
| 133 | - select = ctools.ctselect(sim.obs()) | ||
| 134 | - select["ra"] = ra | ||
| 135 | - select["dec"] = dec | ||
| 136 | - select["rad"] = rad_select | ||
| 137 | - select["tmin"] = tstart | ||
| 138 | - select["tmax"] = tstop | ||
| 139 | - select["emin"] = emin | ||
| 140 | - select["emax"] = emax | ||
| 141 | - select.run() | ||
| 142 | - | ||
| 143 | - # Perform maximum likelihood fitting | ||
| 144 | - like = ctools.ctlike(select.obs()) | ||
| 145 | - like.run() | ||
| 146 | - | ||
| 147 | - # TODO: add asserts | ||
| 148 | - assert True |