Commit b422a22792dbf0b7a94360b26bacf6a4ca6ba810
1 parent
eecf0c9d
Enhance ctfindvar unit test
Showing
1 changed file
with
80 additions
and
25 deletions
test/test_ctfindvar.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | from testing import test |
| ... | ... | @@ -85,6 +86,9 @@ class Test(test): |
| 85 | 86 | self.test_value(self._execute(cmd), 0, |
| 86 | 87 | 'Check successful execution from command line') |
| 87 | 88 | |
| 89 | + # Check result | |
| 90 | + self._check_result_files('ctfindvar_cmd1.fits', 'ctfindvar_cmd1.xml', 0) | |
| 91 | + | |
| 88 | 92 | # Setup ctfindvar command |
| 89 | 93 | cmd = ctfindvar+' inobs="event_file_that_does_not_exist.fits"'+ \ |
| 90 | 94 | ' outmap="ctfindvar_cmd2.fits"'+ \ |
| ... | ... | @@ -113,11 +117,24 @@ class Test(test): |
| 113 | 117 | """ |
| 114 | 118 | Test ctfindvar from Python |
| 115 | 119 | """ |
| 116 | - | |
| 117 | 120 | # Allocate ctfindvar |
| 118 | 121 | ctfindvar = ctools.ctfindvar() |
| 119 | 122 | |
| 120 | - # Setup ctfindvar | |
| 123 | + # Check that saving does not nothing | |
| 124 | + ctfindvar['logfile'] = 'ctfindvar_py0.log' | |
| 125 | + ctfindvar['outmap'] = 'ctfindvar_py0.fits' | |
| 126 | + ctfindvar['outmodel'] = 'ctfindvar_py0.xml' | |
| 127 | + ctfindvar.logFileOpen() | |
| 128 | + ctfindvar.save() | |
| 129 | + self.test_assert(not os.path.isfile('ctfindvar_py0.fits'), | |
| 130 | + 'Check that no output map has been created') | |
| 131 | + self.test_assert(not os.path.isfile('ctfindvar_py0.xml'), | |
| 132 | + 'Check that no output model definition XML file has been created') | |
| 133 | + | |
| 134 | + # Check that clearing does not lead to an exception or segfault | |
| 135 | + ctfindvar.clear() | |
| 136 | + | |
| 137 | + # Now set ctfindvar parameters | |
| 121 | 138 | ctfindvar['inobs'] = self._events |
| 122 | 139 | ctfindvar['tmin'] = 'NONE' |
| 123 | 140 | ctfindvar['tmax'] = 'NONE' |
| ... | ... | @@ -135,30 +152,25 @@ class Test(test): |
| 135 | 152 | ctfindvar['ysrc'] = 22.51 |
| 136 | 153 | ctfindvar['caldb'] = 'prod2' |
| 137 | 154 | ctfindvar['irf'] = 'South_0.5h' |
| 138 | - ctfindvar['outmap'] = 'ctfindvar_py0.fits' | |
| 139 | - ctfindvar['outmodel'] = 'ctfindvar_py0.xml' | |
| 140 | - ctfindvar['logfile'] = 'ctfindvar_py0.log' | |
| 141 | - ctfindvar['chatter'] = 1 | |
| 155 | + ctfindvar['outmap'] = 'ctfindvar_py1.fits' | |
| 156 | + ctfindvar['outmodel'] = 'ctfindvar_py1.xml' | |
| 157 | + ctfindvar['logfile'] = 'ctfindvar_py1.log' | |
| 158 | + ctfindvar['chatter'] = 2 | |
| 142 | 159 | |
| 143 | - # Run ctfindvar tool | |
| 160 | + # Execute ctfindvar tool | |
| 144 | 161 | ctfindvar.logFileOpen() |
| 145 | - ctfindvar.run() | |
| 162 | + ctfindvar.execute() | |
| 146 | 163 | |
| 147 | - # Check that saving does not nothing | |
| 148 | - ctfindvar['outmap'] = 'ctfindvar_py1.fits' | |
| 149 | - ctfindvar['outmodel'] = 'ctfindvar_py1.xml' | |
| 150 | - ctfindvar['logfile'] = 'ctfindvar_py1.log' | |
| 151 | - ctfindvar.logFileOpen() | |
| 152 | - ctfindvar.save() | |
| 153 | - | |
| 154 | 164 | # Check result |
| 155 | - self._check_result_file('ctfindvar_py1.fits') | |
| 165 | + self._check_result_files('ctfindvar_py1.fits', 'ctfindvar_py1.xml', 0) | |
| 156 | 166 | |
| 157 | 167 | # Copy ctfindvar tool |
| 158 | 168 | cpy_tool = ctfindvar.copy() |
| 159 | 169 | |
| 160 | - # Run copy of ctfindvar tool again with lower threshold | |
| 170 | + # Execute copy of ctfindvar tool again with lower threshold and now | |
| 171 | + # with output cube file | |
| 161 | 172 | cpy_tool['threshold'] = 1.0 |
| 173 | + cpy_tool['outcube'] = 'ctfindvar_py2_cube.fits' | |
| 162 | 174 | cpy_tool['outmap'] = 'ctfindvar_py2.fits' |
| 163 | 175 | cpy_tool['outmodel'] = 'ctfindvar_py2.xml' |
| 164 | 176 | cpy_tool['logfile'] = 'ctfindvar_py2.log' |
| ... | ... | @@ -167,27 +179,70 @@ class Test(test): |
| 167 | 179 | cpy_tool.execute() |
| 168 | 180 | |
| 169 | 181 | # Check result |
| 170 | - self._check_result_file('ctfindvar_py2.fits') | |
| 182 | + self._check_result_files('NONE', 'ctfindvar_py2.xml', 1) | |
| 183 | + fits = gammalib.GFits('ctfindvar_py2_cube.fits') | |
| 184 | + self.test_value(fits.size(), 1, 'Check for 1 extension in cube file') | |
| 171 | 185 | |
| 172 | - # Check that clearing does not lead to an exception or segfault | |
| 186 | + # Now run with an input model and time window, a smoothing kernel | |
| 187 | + # and set the number of threads | |
| 173 | 188 | ctfindvar.clear() |
| 189 | + ctfindvar['inobs'] = self._events | |
| 190 | + ctfindvar['inmodel'] = self._model | |
| 191 | + ctfindvar['tmin'] = '2020-01-01T00:01:10' | |
| 192 | + ctfindvar['tmax'] = '2020-01-01T00:03:40' | |
| 193 | + ctfindvar['tinterval'] = 10 | |
| 194 | + ctfindvar['smooth_kernel'] = 'DISK' | |
| 195 | + ctfindvar['smooth_rad'] = 0.05 | |
| 196 | + ctfindvar['emin'] = 0.2 | |
| 197 | + ctfindvar['emax'] = 1.1 | |
| 198 | + ctfindvar['nxpix'] = 200 | |
| 199 | + ctfindvar['nypix'] = 200 | |
| 200 | + ctfindvar['binsz'] = 0.05 | |
| 201 | + ctfindvar['coordsys'] = 'CEL' | |
| 202 | + ctfindvar['proj'] = 'CAR' | |
| 203 | + ctfindvar['xref'] = 83.63 | |
| 204 | + ctfindvar['yref'] = 22.51 | |
| 205 | + ctfindvar['caldb'] = 'prod2' | |
| 206 | + ctfindvar['irf'] = 'South_0.5h' | |
| 207 | + ctfindvar['outmap'] = 'ctfindvar_py3.fits' | |
| 208 | + ctfindvar['outmodel'] = 'ctfindvar_py3.xml' | |
| 209 | + ctfindvar['logfile'] = 'ctfindvar_py3.log' | |
| 210 | + ctfindvar['chatter'] = 4 | |
| 211 | + ctfindvar['nthreads'] = 2 | |
| 212 | + | |
| 213 | + # Execute ctfindvar tool | |
| 214 | + ctfindvar.logFileOpen() | |
| 215 | + ctfindvar.execute() | |
| 216 | + | |
| 217 | + # Check result | |
| 218 | + self._check_result_files('ctfindvar_py3.fits', 'ctfindvar_py3.xml', 0) | |
| 174 | 219 | |
| 175 | 220 | # Return |
| 176 | 221 | return |
| 177 | 222 | |
| 178 | 223 | # Check ctfindvar result |
| 179 | - def _check_result_file(self, filename): | |
| 224 | + def _check_result_files(self, fitsfile, xmlfile, nmodels): | |
| 180 | 225 | """ |
| 181 | 226 | Check ctfindvar result |
| 182 | 227 | |
| 183 | 228 | Parameters |
| 184 | 229 | ---------- |
| 185 | - filename : str | |
| 186 | - Output file | |
| 230 | + fitsfile : str | |
| 231 | + FITS file name | |
| 232 | + xmlfile : str | |
| 233 | + Model definition XML file name | |
| 234 | + nmodels : int | |
| 235 | + Expected number of models | |
| 187 | 236 | """ |
| 188 | - # Read variability file | |
| 189 | - fits = gammalib.GFits(filename) | |
| 190 | - self.test_value(fits.size(), 3, 'Check for 3 extensions in output file') | |
| 237 | + # Read variability FITS file | |
| 238 | + if fitsfile is not 'NONE': | |
| 239 | + fits = gammalib.GFits(fitsfile) | |
| 240 | + self.test_value(fits.size(), 3, 'Check for 3 extensions in output file') | |
| 241 | + | |
| 242 | + # Read model definition XML file | |
| 243 | + models = gammalib.GModels(xmlfile) | |
| 244 | + self.test_value(models.size(), nmodels, | |
| 245 | + 'Check for %d models in model definition XML file' % nmodels) | |
| 191 | 246 | |
| 192 | 247 | # Return |
| 193 | 248 | return | ... | ... |