Commit a93fe3b62a05eaf761f56f570afdd289d2a3e86b

Authored by Jürgen Knödlseder
1 parent 26046f94

Increase ctmodel code coverage

pyext/Makefile.am
@@ -66,6 +66,11 @@ testscripts = ctools/tests/__init__.py \ @@ -66,6 +66,11 @@ testscripts = ctools/tests/__init__.py \
66 testdata = $(top_srcdir)/test/data/crab.xml \ 66 testdata = $(top_srcdir)/test/data/crab.xml \
67 $(top_srcdir)/test/data/crab_events.fits \ 67 $(top_srcdir)/test/data/crab_events.fits \
68 $(top_srcdir)/test/data/crab_cntmap.fits \ 68 $(top_srcdir)/test/data/crab_cntmap.fits \
  69 + $(top_srcdir)/test/data/crab_expcube.fits.gz \
  70 + $(top_srcdir)/test/data/crab_psfcube.fits.gz \
  71 + $(top_srcdir)/test/data/crab_edispcube.fits.gz \
  72 + $(top_srcdir)/test/data/crab_bkgcube.fits.gz \
  73 + $(top_srcdir)/test/data/crab_bkgcube.xml \
69 $(top_srcdir)/test/data/phased_events.fits.gz \ 74 $(top_srcdir)/test/data/phased_events.fits.gz \
70 $(top_srcdir)/test/data/invalid_event_list.fits.gz \ 75 $(top_srcdir)/test/data/invalid_event_list.fits.gz \
71 $(top_srcdir)/test/data/model_temporal_phasecurve.xml \ 76 $(top_srcdir)/test/data/model_temporal_phasecurve.xml \
test/test_ctmodel.py
@@ -39,6 +39,14 @@ class Test(test): @@ -39,6 +39,14 @@ class Test(test):
39 # Call base class constructor 39 # Call base class constructor
40 test.__init__(self) 40 test.__init__(self)
41 41
  42 + # Set test data
  43 + self._obs_unbinned = self._datadir + '/obs_unbinned.xml'
  44 + self._expcube = self._datadir + '/crab_expcube.fits'
  45 + self._psfcube = self._datadir + '/crab_psfcube.fits'
  46 + self._edispcube = self._datadir + '/crab_edispcube.fits'
  47 + self._bkgcube = self._datadir + '/crab_bkgcube.fits'
  48 + self._bkgmodel = self._datadir + '/crab_bkgcube.xml'
  49 +
42 # Return 50 # Return
43 return 51 return
44 52
@@ -218,6 +226,156 @@ class Test(test): @@ -218,6 +226,156 @@ class Test(test):
218 # Publish with name 226 # Publish with name
219 model.publish('My model') 227 model.publish('My model')
220 228
  229 + # Setup ctmodel from event list FITS file
  230 + model = ctools.ctmodel()
  231 + model['inobs'] = self._events
  232 + model['incube'] = 'NONE'
  233 + model['inmodel'] = self._model
  234 + model['expcube'] = 'NONE'
  235 + model['psfcube'] = 'NONE'
  236 + model['edispcube'] = 'NONE'
  237 + model['bkgcube'] = 'NONE'
  238 + model['caldb'] = self._caldb
  239 + model['irf'] = self._irf
  240 + model['rad'] = 5
  241 + model['ra'] = 83.63
  242 + model['dec'] = 22.01
  243 + model['tmin'] = 0
  244 + model['tmax'] = 1800
  245 + model['ebinalg'] = 'LOG'
  246 + model['emin'] = 1.0
  247 + model['emax'] = 100.0
  248 + model['enumbins'] = 5
  249 + model['nxpix'] = 40
  250 + model['nypix'] = 40
  251 + model['binsz'] = 0.1
  252 + model['coordsys'] = 'CEL'
  253 + model['proj'] = 'CAR'
  254 + model['xref'] = 83.63
  255 + model['yref'] = 22.01
  256 + model['outcube'] = 'ctmodel_py4.fits'
  257 + model['logfile'] = 'ctmodel_py4.log'
  258 + model['chatter'] = 2
  259 +
  260 + # Run ctmodel tool
  261 + model.logFileOpen() # Make sure we get a log file
  262 + model.execute()
  263 +
  264 + # Check result file
  265 + self._check_result_file('ctmodel_py4.fits')
  266 +
  267 + # Setup ctmodel from observation definition XML file
  268 + model = ctools.ctmodel()
  269 + model['inobs'] = self._obs_unbinned
  270 + model['incube'] = 'NONE'
  271 + model['inmodel'] = self._model
  272 + model['expcube'] = 'NONE'
  273 + model['psfcube'] = 'NONE'
  274 + model['edispcube'] = 'NONE'
  275 + model['bkgcube'] = 'NONE'
  276 + model['caldb'] = self._caldb
  277 + model['irf'] = self._irf
  278 + model['rad'] = 5
  279 + model['ra'] = 83.63
  280 + model['dec'] = 22.01
  281 + model['tmin'] = 0
  282 + model['tmax'] = 1800
  283 + model['ebinalg'] = 'LOG'
  284 + model['emin'] = 1.0
  285 + model['emax'] = 100.0
  286 + model['enumbins'] = 5
  287 + model['nxpix'] = 40
  288 + model['nypix'] = 40
  289 + model['binsz'] = 0.1
  290 + model['coordsys'] = 'CEL'
  291 + model['proj'] = 'CAR'
  292 + model['xref'] = 83.63
  293 + model['yref'] = 22.01
  294 + model['outcube'] = 'ctmodel_py5.fits'
  295 + model['logfile'] = 'ctmodel_py5.log'
  296 + model['chatter'] = 2
  297 +
  298 + # Run ctmodel tool
  299 + model.logFileOpen() # Make sure we get a log file
  300 + model.execute()
  301 +
  302 + # Check result file
  303 + self._check_result_file('ctmodel_py5.fits')
  304 +
  305 + # Setup ctmodel for stacked IRF
  306 + model = ctools.ctmodel()
  307 + model['inobs'] = 'NONE'
  308 + model['incube'] = 'NONE'
  309 + model['inmodel'] = self._bkgmodel
  310 + model['expcube'] = self._expcube
  311 + model['psfcube'] = self._psfcube
  312 + model['edispcube'] = 'NONE'
  313 + model['bkgcube'] = self._bkgcube
  314 + model['edisp'] = False
  315 + model['rad'] = 5
  316 + model['ra'] = 83.63
  317 + model['dec'] = 22.01
  318 + model['tmin'] = 0
  319 + model['tmax'] = 1800
  320 + model['ebinalg'] = 'LOG'
  321 + model['emin'] = 1.0
  322 + model['emax'] = 100.0
  323 + model['enumbins'] = 5
  324 + model['nxpix'] = 40
  325 + model['nypix'] = 40
  326 + model['binsz'] = 0.1
  327 + model['coordsys'] = 'CEL'
  328 + model['proj'] = 'CAR'
  329 + model['xref'] = 83.63
  330 + model['yref'] = 22.01
  331 + model['outcube'] = 'ctmodel_py6.fits'
  332 + model['logfile'] = 'ctmodel_py6.log'
  333 + model['chatter'] = 2
  334 +
  335 + # Run ctmodel tool
  336 + model.logFileOpen() # Make sure we get a log file
  337 + model.execute()
  338 +
  339 + # Check result file
  340 + self._check_result_file('ctmodel_py6.fits')
  341 +
  342 + # Setup ctmodel for stacked IRF using energy dispersion
  343 + model = ctools.ctmodel()
  344 + model['inobs'] = 'NONE'
  345 + model['incube'] = 'NONE'
  346 + model['inmodel'] = self._bkgmodel
  347 + model['expcube'] = self._expcube
  348 + model['psfcube'] = self._psfcube
  349 + model['edispcube'] = self._edispcube
  350 + model['bkgcube'] = self._bkgcube
  351 + model['edisp'] = True
  352 + model['rad'] = 5
  353 + model['ra'] = 83.63
  354 + model['dec'] = 22.01
  355 + model['tmin'] = 0
  356 + model['tmax'] = 1800
  357 + model['ebinalg'] = 'LOG'
  358 + model['emin'] = 1.0
  359 + model['emax'] = 100.0
  360 + model['enumbins'] = 5
  361 + model['nxpix'] = 40
  362 + model['nypix'] = 40
  363 + model['binsz'] = 0.1
  364 + model['coordsys'] = 'CEL'
  365 + model['proj'] = 'CAR'
  366 + model['xref'] = 83.63
  367 + model['yref'] = 22.01
  368 + model['outcube'] = 'ctmodel_py7.fits'
  369 + model['logfile'] = 'ctmodel_py7.log'
  370 + model['chatter'] = 2
  371 +
  372 + # Run ctmodel tool
  373 + model.logFileOpen() # Make sure we get a log file
  374 + model.execute()
  375 +
  376 + # Check result file
  377 + self._check_result_file('ctmodel_py7.fits')
  378 +
221 # Return 379 # Return
222 return 380 return
223 381