Commit dd7e6a653b771edb60a03289c702bdab7b79e6f8
Merge branch '1828-enhance-csiactdata-tests' into integration
Showing
24 changed files
with
496 additions
and
274 deletions
cscripts/Makefile.am
| @@ -155,30 +155,44 @@ testdata = $(top_srcdir)/test/data/crab.xml \ | @@ -155,30 +155,44 @@ testdata = $(top_srcdir)/test/data/crab.xml \ | ||
| 155 | $(top_srcdir)/test/data/model_filefunction.txt \ | 155 | $(top_srcdir)/test/data/model_filefunction.txt \ |
| 156 | $(top_srcdir)/test/data/model_map.fits.gz \ | 156 | $(top_srcdir)/test/data/model_map.fits.gz \ |
| 157 | $(top_srcdir)/test/data/model_mapcube.fits.gz \ | 157 | $(top_srcdir)/test/data/model_mapcube.fits.gz \ |
| 158 | - $(top_srcdir)/test/data/iact_runlist.dat | 158 | + $(top_srcdir)/test/data/iact_runlist.dat \ |
| 159 | + $(top_srcdir)/test/data/iact_runlist_1.dat \ | ||
| 160 | + $(top_srcdir)/test/data/iact_runlist_2.dat | ||
| 159 | 161 | ||
| 160 | # Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata | 162 | # Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata |
| 161 | testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \ | 163 | testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \ |
| 162 | $(top_srcdir)/test/data/iactdata/master.json \ | 164 | $(top_srcdir)/test/data/iactdata/master.json \ |
| 163 | - $(top_srcdir)/test/data/iactdata/obs-index.fits.gz \ | ||
| 164 | - $(top_srcdir)/test/data/iactdata/irf_file.fits.gz \ | ||
| 165 | - $(top_srcdir)/test/data/iactdata/events.fits.gz | 165 | + $(top_srcdir)/test/data/iactdata/obs-index.fits.gz |
| 166 | + | ||
| 167 | +# Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata/events | ||
| 168 | +testiactevents = $(top_srcdir)/test/data/iactdata/events/irf_file.fits.gz \ | ||
| 169 | + $(top_srcdir)/test/data/iactdata/events/events_0.fits.gz \ | ||
| 170 | + $(top_srcdir)/test/data/iactdata/events/events_1.fits.gz \ | ||
| 171 | + $(top_srcdir)/test/data/iactdata/events/events_2.fits.gz \ | ||
| 172 | + $(top_srcdir)/test/data/iactdata/events/events_3.fits.gz \ | ||
| 173 | + $(top_srcdir)/test/data/iactdata/events/events_4.fits.gz \ | ||
| 174 | + $(top_srcdir)/test/data/iactdata/events/events_5.fits.gz \ | ||
| 175 | + $(top_srcdir)/test/data/iactdata/events/events_6.fits.gz \ | ||
| 176 | + $(top_srcdir)/test/data/iactdata/events/events_7.fits.gz \ | ||
| 177 | + $(top_srcdir)/test/data/iactdata/events/events_8.fits.gz | ||
| 166 | 178 | ||
| 167 | # Install scripts, parfiles, test scripts and test data. Note that we don't | 179 | # Install scripts, parfiles, test scripts and test data. Note that we don't |
| 168 | # need to prepend $(DESTDIR) here (not fully clear why, but that's the way | 180 | # need to prepend $(DESTDIR) here (not fully clear why, but that's the way |
| 169 | # it is) | 181 | # it is) |
| 170 | -binscriptsdir = $(bindir) | ||
| 171 | -binscripts_DATA = $(binscripts) | ||
| 172 | -pythonscriptsdir = $(pyexecdir)/cscripts | ||
| 173 | -pythonscripts_DATA = $(pythonscripts) | ||
| 174 | -pfilesdir = $(prefix)/syspfiles | ||
| 175 | -pfiles_DATA = $(parfiles) | ||
| 176 | -testscriptsdir = $(pyexecdir)/cscripts/tests | ||
| 177 | -testscripts_DATA = $(testscripts) | ||
| 178 | -testdatadir = $(pyexecdir)/cscripts/tests/data | ||
| 179 | -testdata_DATA = $(testdata) | ||
| 180 | -testiactdatadir = $(pyexecdir)/cscripts/tests/data/iactdata | ||
| 181 | -testiactdata_DATA = $(testiactdata) | 182 | +binscriptsdir = $(bindir) |
| 183 | +binscripts_DATA = $(binscripts) | ||
| 184 | +pythonscriptsdir = $(pyexecdir)/cscripts | ||
| 185 | +pythonscripts_DATA = $(pythonscripts) | ||
| 186 | +pfilesdir = $(prefix)/syspfiles | ||
| 187 | +pfiles_DATA = $(parfiles) | ||
| 188 | +testscriptsdir = $(pyexecdir)/cscripts/tests | ||
| 189 | +testscripts_DATA = $(testscripts) | ||
| 190 | +testdatadir = $(pyexecdir)/cscripts/tests/data | ||
| 191 | +testdata_DATA = $(testdata) | ||
| 192 | +testiactdatadir = $(pyexecdir)/cscripts/tests/data/iactdata | ||
| 193 | +testiactdata_DATA = $(testiactdata) | ||
| 194 | +testiacteventsdir = $(pyexecdir)/cscripts/tests/data/iactdata/events | ||
| 195 | +testiactevents_DATA = $(testiactdata) | ||
| 182 | 196 | ||
| 183 | # Files to be distributed in the tar file | 197 | # Files to be distributed in the tar file |
| 184 | EXTRA_DIST = $(binscripts) $(pythonscripts) $(parfiles) \ | 198 | EXTRA_DIST = $(binscripts) $(pythonscripts) $(parfiles) \ |
cscripts/csiactcopy.py
| @@ -377,9 +377,7 @@ class csiactcopy(ctools.cscript): | @@ -377,9 +377,7 @@ class csiactcopy(ctools.cscript): | ||
| 377 | 377 | ||
| 378 | # Copy all data if runlist file is 'NONE' | 378 | # Copy all data if runlist file is 'NONE' |
| 379 | elif self._runlist == 'NONE': | 379 | elif self._runlist == 'NONE': |
| 380 | - if self._logTerse(): | ||
| 381 | - self._log('Copy all available data') | ||
| 382 | - self._log('\n') | 380 | + self._log_string(gammalib.TERSE, 'Copy all available data') |
| 383 | 381 | ||
| 384 | # Raise exception if file not valid | 382 | # Raise exception if file not valid |
| 385 | else: | 383 | else: |
cscripts/csiactobs.py
| @@ -172,8 +172,10 @@ class csiactobs(ctools.cscript): | @@ -172,8 +172,10 @@ class csiactobs(ctools.cscript): | ||
| 172 | 172 | ||
| 173 | # Check if prodname is present | 173 | # Check if prodname is present |
| 174 | if self._prodname == config['name']: | 174 | if self._prodname == config['name']: |
| 175 | - self._hdu_index = str(os.path.join(self._datapath, config['hduindx'])) | ||
| 176 | - self._obs_index = str(os.path.join(self._datapath, config['obsindx'])) | 175 | + self._hdu_index = str(os.path.join(self._datapath, |
| 176 | + config['hduindx'])) | ||
| 177 | + self._obs_index = str(os.path.join(self._datapath, | ||
| 178 | + config['obsindx'])) | ||
| 177 | 179 | ||
| 178 | # Leave loop if index file names were found | 180 | # Leave loop if index file names were found |
| 179 | break | 181 | break |
| @@ -292,7 +294,9 @@ class csiactobs(ctools.cscript): | @@ -292,7 +294,9 @@ class csiactobs(ctools.cscript): | ||
| 292 | spec = gammalib.GModelSpectralNodes() | 294 | spec = gammalib.GModelSpectralNodes() |
| 293 | 295 | ||
| 294 | # Create logarithmic energy nodes | 296 | # Create logarithmic energy nodes |
| 295 | - bounds = gammalib.GEbounds(self._bkgpars,gammalib.GEnergy(emin,'TeV'),gammalib.GEnergy(emax,'TeV'), True) | 297 | + bounds = gammalib.GEbounds(self._bkgpars, |
| 298 | + gammalib.GEnergy(emin,'TeV'), | ||
| 299 | + gammalib.GEnergy(emax,'TeV'), True) | ||
| 296 | 300 | ||
| 297 | # Loop over bounds and set intensity value | 301 | # Loop over bounds and set intensity value |
| 298 | for i in range(bounds.size()): | 302 | for i in range(bounds.size()): |
| @@ -319,7 +323,8 @@ class csiactobs(ctools.cscript): | @@ -319,7 +323,8 @@ class csiactobs(ctools.cscript): | ||
| 319 | # Return spectrum | 323 | # Return spectrum |
| 320 | return spec | 324 | return spec |
| 321 | 325 | ||
| 322 | - def _iact_background(self, telescope, obs_id, bkg_scale, bkgtype, emin=0.01, emax=100): | 326 | + def _iact_background(self, telescope, obs_id, bkg_scale, bkgtype, |
| 327 | + emin=0.01, emax=100): | ||
| 323 | """ | 328 | """ |
| 324 | Create an IACT background model | 329 | Create an IACT background model |
| 325 | 330 | ||
| @@ -348,27 +353,35 @@ class csiactobs(ctools.cscript): | @@ -348,27 +353,35 @@ class csiactobs(ctools.cscript): | ||
| 348 | prefactor *= bkg_scale | 353 | prefactor *= bkg_scale |
| 349 | 354 | ||
| 350 | # Create background spectrum | 355 | # Create background spectrum |
| 351 | - spec = self._background_spectrum(prefactor, index, emin, emax) | 356 | + spec = self._background_spectrum(prefactor, index, emin, emax) |
| 352 | 357 | ||
| 353 | - # Create background model instance | 358 | + # Create background model |
| 354 | bck = gammalib.GCTAModelIrfBackground(spec) | 359 | bck = gammalib.GCTAModelIrfBackground(spec) |
| 355 | 360 | ||
| 356 | # Set AeffBackground | 361 | # Set AeffBackground |
| 357 | elif bkgtype == 'aeff': | 362 | elif bkgtype == 'aeff': |
| 363 | + | ||
| 364 | + # Set background components | ||
| 358 | prefactor = bkg_scale * self._bkg_aeff_norm | 365 | prefactor = bkg_scale * self._bkg_aeff_norm |
| 359 | - spec = self._background_spectrum(prefactor, self._bkg_aeff_index, emin, emax) | 366 | + spec = self._background_spectrum(prefactor, |
| 367 | + self._bkg_aeff_index, | ||
| 368 | + emin, emax) | ||
| 360 | 369 | ||
| 361 | - # Create background model instance | 370 | + # Create background model |
| 362 | bck = gammalib.GCTAModelAeffBackground(spec) | 371 | bck = gammalib.GCTAModelAeffBackground(spec) |
| 363 | 372 | ||
| 364 | # Set Gaussian Background | 373 | # Set Gaussian Background |
| 365 | elif bkgtype == 'gauss': | 374 | elif bkgtype == 'gauss': |
| 375 | + | ||
| 376 | + # Set background components | ||
| 366 | prefactor = bkg_scale * self._bkg_gauss_norm | 377 | prefactor = bkg_scale * self._bkg_gauss_norm |
| 367 | - | ||
| 368 | - # Create background spectrum | ||
| 369 | - spec = self._background_spectrum(prefactor, self._bkg_gauss_index, emin, emax) | 378 | + spec = self._background_spectrum(prefactor, |
| 379 | + self._bkg_gauss_index, | ||
| 380 | + emin, emax) | ||
| 370 | radial = gammalib.GCTAModelRadialGauss(self._bkg_gauss_sigma) | 381 | radial = gammalib.GCTAModelRadialGauss(self._bkg_gauss_sigma) |
| 371 | - bck = gammalib.GCTAModelRadialAcceptance(radial, spec) | 382 | + |
| 383 | + # Create background model | ||
| 384 | + bck = gammalib.GCTAModelRadialAcceptance(radial, spec) | ||
| 372 | 385 | ||
| 373 | else: | 386 | else: |
| 374 | msg = 'Background type "'+bkgtype+'" unsupported' | 387 | msg = 'Background type "'+bkgtype+'" unsupported' |
| @@ -422,7 +435,7 @@ class csiactobs(ctools.cscript): | @@ -422,7 +435,7 @@ class csiactobs(ctools.cscript): | ||
| 422 | Write observation summary | 435 | Write observation summary |
| 423 | """ | 436 | """ |
| 424 | # Log header | 437 | # Log header |
| 425 | - self._log_header1(gammalib.TERSE, 'Observation summary') | 438 | + self._log_header1(gammalib.NORMAL, 'Observation summary') |
| 426 | 439 | ||
| 427 | # Set energy range dependent on whether boundaries exist or | 440 | # Set energy range dependent on whether boundaries exist or |
| 428 | # not | 441 | # not |
| @@ -438,6 +451,95 @@ class csiactobs(ctools.cscript): | @@ -438,6 +451,95 @@ class csiactobs(ctools.cscript): | ||
| 438 | # Return | 451 | # Return |
| 439 | return | 452 | return |
| 440 | 453 | ||
| 454 | + def _get_filename(self, hdu, hierarchy, formats): | ||
| 455 | + """ | ||
| 456 | + Retrieves a filename from a hdu index | ||
| 457 | + | ||
| 458 | + Parameters | ||
| 459 | + ---------- | ||
| 460 | + hdu : `~gammalib.GFitsTable` | ||
| 461 | + HDU FITS table | ||
| 462 | + hierarchy : list of str | ||
| 463 | + List of strings containing the hierarchy how to look for files | ||
| 464 | + formats : list of str | ||
| 465 | + File formats available for this observation | ||
| 466 | + | ||
| 467 | + Returns | ||
| 468 | + ------- | ||
| 469 | + filename : str | ||
| 470 | + Filename of requested file | ||
| 471 | + """ | ||
| 472 | + | ||
| 473 | + # Initialise filename | ||
| 474 | + filename = '' | ||
| 475 | + | ||
| 476 | + # Handle hierarchies | ||
| 477 | + index = -1 | ||
| 478 | + | ||
| 479 | + # Loop over possible formats | ||
| 480 | + for version in hierarchy: | ||
| 481 | + | ||
| 482 | + # Count number of same available versions | ||
| 483 | + n = formats.count(version) | ||
| 484 | + | ||
| 485 | + # Leave loop and store index of first occurence | ||
| 486 | + if n > 0: | ||
| 487 | + index = formats.index(version) | ||
| 488 | + break | ||
| 489 | + | ||
| 490 | + # Build filename from information stored in hduindx_hdu | ||
| 491 | + if index >= 0: | ||
| 492 | + filename = os.path.join(self._subdir, | ||
| 493 | + hdu['FILE_DIR'][index], | ||
| 494 | + hdu['FILE_NAME'][index]) | ||
| 495 | + filehdu = hdu['HDU_NAME'][index] | ||
| 496 | + filename += '['+filehdu+']' | ||
| 497 | + | ||
| 498 | + # Return filename | ||
| 499 | + return filename | ||
| 500 | + | ||
| 501 | + | ||
| 502 | + def _is_present(self, filename, obs_id, filetype): | ||
| 503 | + """ | ||
| 504 | + Checks if a filename is present | ||
| 505 | + | ||
| 506 | + Parameters | ||
| 507 | + ---------- | ||
| 508 | + filename : str | ||
| 509 | + Filename | ||
| 510 | + obs_id : int | ||
| 511 | + Observation ID | ||
| 512 | + filetype : str | ||
| 513 | + Type of file | ||
| 514 | + | ||
| 515 | + Returns | ||
| 516 | + ------- | ||
| 517 | + present : bool | ||
| 518 | + True if filename is present, False otherwise | ||
| 519 | + """ | ||
| 520 | + | ||
| 521 | + # Initialise return value | ||
| 522 | + present = True | ||
| 523 | + | ||
| 524 | + # Create filename instance | ||
| 525 | + fname = gammalib.GFilename(filename) | ||
| 526 | + | ||
| 527 | + # Check if file is empty | ||
| 528 | + if fname.is_empty(): | ||
| 529 | + msg = 'Skipping observation "%s": No %s found' % (obs_id, filetype) | ||
| 530 | + self._log_string(gammalib.NORMAL, msg) | ||
| 531 | + present = False | ||
| 532 | + | ||
| 533 | + # Check if file exists | ||
| 534 | + elif not fname.exists(): | ||
| 535 | + msg = ('Skipping observation "%s": %s "%s" does not exist' % | ||
| 536 | + (obs_id, filetype, filename)) | ||
| 537 | + self._log_string(gammalib.NORMAL, msg) | ||
| 538 | + present = False | ||
| 539 | + | ||
| 540 | + # Return present flag | ||
| 541 | + return present | ||
| 542 | + | ||
| 441 | 543 | ||
| 442 | # Public methods | 544 | # Public methods |
| 443 | def run(self): | 545 | def run(self): |
| @@ -460,9 +562,8 @@ class csiactobs(ctools.cscript): | @@ -460,9 +562,8 @@ class csiactobs(ctools.cscript): | ||
| 460 | lib = self._xml.element('observation_list', 0) | 562 | lib = self._xml.element('observation_list', 0) |
| 461 | 563 | ||
| 462 | # Log output | 564 | # Log output |
| 463 | - if self._logTerse(): | ||
| 464 | - self._log('\n') | ||
| 465 | - self._log.header1('Looping over '+str(len(self._runlist))+' runs') | 565 | + msg = 'Looping over %d runs' % len(self._runlist) |
| 566 | + self._log_header1(gammalib.TERSE, msg) | ||
| 466 | 567 | ||
| 467 | # Initialise energy range values for logging | 568 | # Initialise energy range values for logging |
| 468 | self._ebounds.clear() | 569 | self._ebounds.clear() |
| @@ -474,152 +575,86 @@ class csiactobs(ctools.cscript): | @@ -474,152 +575,86 @@ class csiactobs(ctools.cscript): | ||
| 474 | obs_selection = '[OBS_ID=='+str(obs_id)+']' | 575 | obs_selection = '[OBS_ID=='+str(obs_id)+']' |
| 475 | 576 | ||
| 476 | # Open HDU index file | 577 | # Open HDU index file |
| 477 | - hduindx = gammalib.GFits(self._hdu_index+'[HDU_INDEX]'+obs_selection) | 578 | + hduindx = gammalib.GFits(self._hdu_index+'[HDU_INDEX]'+ |
| 579 | + obs_selection) | ||
| 478 | hduindx_hdu = hduindx['HDU_INDEX'] | 580 | hduindx_hdu = hduindx['HDU_INDEX'] |
| 479 | 581 | ||
| 480 | - # Initialise files and hdu names | ||
| 481 | - eventfile = aefffile = psffile = edispfile = bkgfile = '' | ||
| 482 | - eventhdu = aeffhdu = '' | ||
| 483 | - | ||
| 484 | # Initialise types and formats | 582 | # Initialise types and formats |
| 485 | - types = [] | ||
| 486 | formats = [] | 583 | formats = [] |
| 487 | for i in range(hduindx_hdu.nrows()): | 584 | for i in range(hduindx_hdu.nrows()): |
| 488 | - types.append(hduindx_hdu['HDU_TYPE'][i]) | ||
| 489 | formats.append(hduindx_hdu['HDU_CLASS'][i]) | 585 | formats.append(hduindx_hdu['HDU_CLASS'][i]) |
| 490 | 586 | ||
| 491 | - # Handle events | ||
| 492 | - index = -1 | ||
| 493 | - for version in self._ev_hiera: | ||
| 494 | - n = formats.count(version) | ||
| 495 | - if n > 0: | ||
| 496 | - index = formats.index(version) | ||
| 497 | - break | ||
| 498 | - if index >= 0: | ||
| 499 | - eventfile = os.path.join(self._subdir, | ||
| 500 | - hduindx_hdu['FILE_DIR'][index], | ||
| 501 | - hduindx_hdu['FILE_NAME'][index]) | ||
| 502 | - eventhdu = hduindx_hdu['HDU_NAME'][index] | ||
| 503 | - eventfile += '['+eventhdu+']' | ||
| 504 | - | ||
| 505 | - # Check if psf file is available | ||
| 506 | - if not gammalib.GFilename(eventfile).is_fits(): | ||
| 507 | - | ||
| 508 | - # Print warning that observation will be skipped since no | ||
| 509 | - # events are present | ||
| 510 | - if self._logTerse(): | ||
| 511 | - self._log('Skipping observation '+str(obs_id)+ | ||
| 512 | - ': eventfile "'+eventfile+'" not found\n') | 587 | + # Retrieve filenames |
| 588 | + eventfile = self._get_filename(hduindx_hdu, self._ev_hiera, formats) | ||
| 589 | + aefffile = self._get_filename(hduindx_hdu, self._aeff_hiera, formats) | ||
| 590 | + psffile = self._get_filename(hduindx_hdu, self._psf_hiera, formats) | ||
| 591 | + edispfile = self._get_filename(hduindx_hdu, self._edisp_hiera, formats) | ||
| 592 | + bkgfile = self._get_filename(hduindx_hdu, self._bkg_hiera, formats) | ||
| 593 | + | ||
| 594 | + # Check for presence of required event file | ||
| 595 | + if not self._is_present(eventfile, obs_id, "event file"): | ||
| 513 | continue | 596 | continue |
| 514 | 597 | ||
| 515 | - # Handle Aeff | ||
| 516 | - index = -1 | ||
| 517 | - for version in self._aeff_hiera: | ||
| 518 | - n = formats.count(version) | ||
| 519 | - if n > 0: | ||
| 520 | - index = formats.index(version) | ||
| 521 | - break | ||
| 522 | - if index >= 0: | ||
| 523 | - aefffile = os.path.join(self._subdir, | ||
| 524 | - hduindx_hdu['FILE_DIR'][index], | ||
| 525 | - hduindx_hdu['FILE_NAME'][index]) | ||
| 526 | - aeffhdu = hduindx_hdu['HDU_NAME'][index] | ||
| 527 | - aefffile += '['+aeffhdu+']' | ||
| 528 | - | ||
| 529 | - # Check if psf file is available | ||
| 530 | - if not gammalib.GFilename(aefffile).is_fits(): | ||
| 531 | - | ||
| 532 | - # Print warning that observation will be skipped since no effective area is present | ||
| 533 | - if self._logTerse(): | ||
| 534 | - self._log('Skipping observation '+str(obs_id)+ | ||
| 535 | - ': effective area "'+aefffile+'" not found\n') | 598 | + # Check for presence of required effective area file |
| 599 | + if not self._is_present(aefffile, obs_id, "effective area file"): | ||
| 536 | continue | 600 | continue |
| 537 | - | ||
| 538 | - # Handle psf | ||
| 539 | - index = -1 | ||
| 540 | - for version in self._psf_hiera: | ||
| 541 | - n = formats.count(version) | ||
| 542 | - if n > 0: | ||
| 543 | - index = formats.index(version) | ||
| 544 | - break | ||
| 545 | - if index >= 0: | ||
| 546 | - psffile = os.path.join(self._subdir, | ||
| 547 | - hduindx_hdu['FILE_DIR'][index], | ||
| 548 | - hduindx_hdu['FILE_NAME'][index]) | ||
| 549 | - psffile += '['+hduindx_hdu['HDU_NAME'][index]+']' | ||
| 550 | - | ||
| 551 | - # Check if psf file is available | ||
| 552 | - if not gammalib.GFilename(psffile).is_fits(): | ||
| 553 | - | ||
| 554 | - # Print warning that observation will be skipped since no PSF is present | ||
| 555 | - if self._logTerse(): | ||
| 556 | - self._log('Skipping observation '+str(obs_id)+ | ||
| 557 | - ': point spread function "'+psffile+ | ||
| 558 | - '" not found\n') | 601 | + |
| 602 | + # Check for presence of required psf file | ||
| 603 | + if not self._is_present(psffile, obs_id, "PSF file"): | ||
| 559 | continue | 604 | continue |
| 560 | - | ||
| 561 | - # Handle edisp | ||
| 562 | - index = -1 | ||
| 563 | - for version in self._edisp_hiera: | ||
| 564 | - n = formats.count(version) | ||
| 565 | - if n > 0: | ||
| 566 | - index = formats.index(version) | ||
| 567 | - break | ||
| 568 | - if index >= 0: | ||
| 569 | - edispfile = os.path.join(self._subdir, | ||
| 570 | - hduindx_hdu['FILE_DIR'][index], | ||
| 571 | - hduindx_hdu['FILE_NAME'][index]) | ||
| 572 | - edispfile += '['+hduindx_hdu['HDU_NAME'][index]+']' | ||
| 573 | - | ||
| 574 | - # Check if edisp file is available | ||
| 575 | - if not gammalib.GFilename(edispfile).is_fits(): | 605 | + |
| 606 | + # Check for optional energy dispersion file | ||
| 607 | + if not gammalib.GFilename(edispfile).exists(): | ||
| 576 | 608 | ||
| 577 | # Print warning that edisp cannot be used for this observation | 609 | # Print warning that edisp cannot be used for this observation |
| 578 | - if self._logTerse(): | ||
| 579 | - self._log('Warning: observation '+str(obs_id)+ | ||
| 580 | - ' has no energy dispersion "'+edispfile+ | ||
| 581 | - '" information\n') | ||
| 582 | - edispfile = '' | 610 | + msg = ('Warning: observation "%s" has no energy dispersion ' |
| 611 | + 'information' % obs_id) | ||
| 612 | + self._log_string(gammalib.NORMAL, msg) | ||
| 583 | 613 | ||
| 584 | - # Handle background | ||
| 585 | - index = -1 | ||
| 586 | - bkg_mod_hierarchy = list(self._bkg_mod_hiera) | ||
| 587 | - for version in self._bkg_hiera: | ||
| 588 | - n = formats.count(version) | ||
| 589 | - if n > 0: | ||
| 590 | - index = formats.index(version) | ||
| 591 | - break | ||
| 592 | - if index >= 0: | ||
| 593 | - bkgfile = os.path.join(self._subdir, | ||
| 594 | - hduindx_hdu['FILE_DIR'][index], | ||
| 595 | - hduindx_hdu['FILE_NAME'][index]) | ||
| 596 | - bkgfile += '['+hduindx_hdu['HDU_NAME'][index]+']' | ||
| 597 | - if 'irf' in bkg_mod_hierarchy and not gammalib.GFilename(bkgfile).is_fits(): | ||
| 598 | - bkg_mod_hierarchy.remove('irf') | 614 | + # Set energy dispersion file as empty |
| 615 | + edispfile = '' | ||
| 616 | + | ||
| 617 | + # Create a copy of background model hierarchy for this run | ||
| 618 | + run_bkg_mod_hierarchy = list(self._bkg_mod_hiera) | ||
| 619 | + | ||
| 620 | + # Check if background file is available | ||
| 621 | + # Remove IRF background from hierarchy if file doesnt exist | ||
| 622 | + if not gammalib.GFilename(bkgfile).exists(): | ||
| 599 | 623 | ||
| 600 | - # Throw warning if IRF background cannot be used | ||
| 601 | - if self._logTerse(): | ||
| 602 | - self._log('Warning: observation '+str(obs_id)+ | ||
| 603 | - ' has no background information (file="'+ | ||
| 604 | - bkgfile+'"). IRF background cannot be used\n') | ||
| 605 | - bkgfile = '' | ||
| 606 | - if len(bkg_mod_hierarchy) == 0: | ||
| 607 | - | ||
| 608 | - # Skip observation if no background can be used | ||
| 609 | - if self._logTerse(): | ||
| 610 | - self._log('Skipping observation '+str(obs_id)+ | ||
| 611 | - ': No background can be used\n') | ||
| 612 | - continue | ||
| 613 | - else: | ||
| 614 | - # Log if we fall back to next background approach | ||
| 615 | - if self._logTerse(): | ||
| 616 | - self._log('Observation '+str(obs_id)+ | ||
| 617 | - ': Falling back to background "'+ | ||
| 618 | - bkg_mod_hierarchy[0]+'"\n') | 624 | + # Set background file as empty |
| 625 | + bkgfile = '' | ||
| 626 | + | ||
| 627 | + # Check for IRF background in background model hierarchy | ||
| 628 | + if 'irf' in run_bkg_mod_hierarchy: | ||
| 629 | + | ||
| 630 | + # Remove IRF background if file doesnt exist | ||
| 631 | + run_bkg_mod_hierarchy.remove('irf') | ||
| 632 | + | ||
| 633 | + # Print warning that edisp cannot be used for this | ||
| 634 | + # observation | ||
| 635 | + msg = ('Warning: observation "%s" has no background ' | ||
| 636 | + 'information (IRF background cannot be used)' % | ||
| 637 | + obs_id) | ||
| 638 | + self._log_string(gammalib.NORMAL, msg) | ||
| 639 | + | ||
| 640 | + # Check if background model hierarchy is empty | ||
| 641 | + if len(run_bkg_mod_hierarchy) == 0: | ||
| 642 | + | ||
| 643 | + # Skip observation if no background can be used | ||
| 644 | + msg = ('Skipping observation "%s": No background can be ' | ||
| 645 | + 'used' % obs_id) | ||
| 646 | + self._log_string(gammalib.NORMAL, msg) | ||
| 647 | + continue | ||
| 648 | + | ||
| 649 | + else: | ||
| 650 | + # Log if we fall back to next background approach | ||
| 651 | + msg = ('Observation "%s": Falling back to background "%s"' % | ||
| 652 | + (obs_id, run_bkg_mod_hierarchy[0])) | ||
| 653 | + self._log_string(gammalib.NORMAL, msg) | ||
| 619 | 654 | ||
| 620 | # Close hdu index file | 655 | # Close hdu index file |
| 621 | hduindx.close() | 656 | hduindx.close() |
| 622 | - | 657 | + |
| 623 | # Initialise background scale | 658 | # Initialise background scale |
| 624 | bkg_scale = 1.0 | 659 | bkg_scale = 1.0 |
| 625 | 660 | ||
| @@ -627,7 +662,8 @@ class csiactobs(ctools.cscript): | @@ -627,7 +662,8 @@ class csiactobs(ctools.cscript): | ||
| 627 | if self._use_bkg_scale: | 662 | if self._use_bkg_scale: |
| 628 | 663 | ||
| 629 | # Read background scale from fits file | 664 | # Read background scale from fits file |
| 630 | - obsindx = gammalib.GFits(self._obs_index+'[OBS_INDEX]'+obs_selection) | 665 | + obsindx = gammalib.GFits(self._obs_index+'[OBS_INDEX]'+ |
| 666 | + obs_selection) | ||
| 631 | bkg_scale = obsindx['OBS_INDEX']['BKG_SCALE'][0] | 667 | bkg_scale = obsindx['OBS_INDEX']['BKG_SCALE'][0] |
| 632 | obsindx.close() | 668 | obsindx.close() |
| 633 | 669 | ||
| @@ -635,7 +671,7 @@ class csiactobs(ctools.cscript): | @@ -635,7 +671,7 @@ class csiactobs(ctools.cscript): | ||
| 635 | fits = gammalib.GFits(eventfile) | 671 | fits = gammalib.GFits(eventfile) |
| 636 | 672 | ||
| 637 | # Get object and telescope strings from event hdu | 673 | # Get object and telescope strings from event hdu |
| 638 | - events = fits[eventhdu] | 674 | + events = fits[gammalib.GFilename(eventfile).extname()] |
| 639 | object_name = events.string('OBJECT') | 675 | object_name = events.string('OBJECT') |
| 640 | telescope = events.string('TELESCOP') | 676 | telescope = events.string('TELESCOP') |
| 641 | 677 | ||
| @@ -644,7 +680,7 @@ class csiactobs(ctools.cscript): | @@ -644,7 +680,7 @@ class csiactobs(ctools.cscript): | ||
| 644 | 680 | ||
| 645 | # Open effective area file to look for threshold | 681 | # Open effective area file to look for threshold |
| 646 | aeff_fits = gammalib.GFits(aefffile) | 682 | aeff_fits = gammalib.GFits(aefffile) |
| 647 | - aeff_table = aeff_fits[aeffhdu] | 683 | + aeff_table = aeff_fits[gammalib.GFilename(aefffile).extname()] |
| 648 | 684 | ||
| 649 | # Set energy range from header keyword if present | 685 | # Set energy range from header keyword if present |
| 650 | if aeff_table.has_card('LO_THRES') and aeff_table.has_card('HI_THRES'): | 686 | if aeff_table.has_card('LO_THRES') and aeff_table.has_card('HI_THRES'): |
| @@ -668,7 +704,7 @@ class csiactobs(ctools.cscript): | @@ -668,7 +704,7 @@ class csiactobs(ctools.cscript): | ||
| 668 | self._models.append(self._iact_background(telescope, | 704 | self._models.append(self._iact_background(telescope, |
| 669 | obs_id, | 705 | obs_id, |
| 670 | bkg_scale, | 706 | bkg_scale, |
| 671 | - bkg_mod_hierarchy[0], | 707 | + run_bkg_mod_hierarchy[0], |
| 672 | run_emin.TeV(), | 708 | run_emin.TeV(), |
| 673 | run_emax.TeV())) | 709 | run_emax.TeV())) |
| 674 | 710 | ||
| @@ -684,19 +720,19 @@ class csiactobs(ctools.cscript): | @@ -684,19 +720,19 @@ class csiactobs(ctools.cscript): | ||
| 684 | 720 | ||
| 685 | # Append effective area | 721 | # Append effective area |
| 686 | aeff = gammalib.GXmlElement('parameter name="EffectiveArea"') | 722 | aeff = gammalib.GXmlElement('parameter name="EffectiveArea"') |
| 687 | - aeff.attribute('file',aefffile) | 723 | + aeff.attribute('file', aefffile) |
| 688 | 724 | ||
| 689 | # Append PSF | 725 | # Append PSF |
| 690 | psf = gammalib.GXmlElement('parameter name="PointSpreadFunction"') | 726 | psf = gammalib.GXmlElement('parameter name="PointSpreadFunction"') |
| 691 | - psf.attribute('file',psffile) | 727 | + psf.attribute('file', psffile) |
| 692 | 728 | ||
| 693 | # Append energy dispersion | 729 | # Append energy dispersion |
| 694 | edisp = gammalib.GXmlElement('parameter name="EnergyDispersion"') | 730 | edisp = gammalib.GXmlElement('parameter name="EnergyDispersion"') |
| 695 | - edisp.attribute('file',edispfile) | 731 | + edisp.attribute('file', edispfile) |
| 696 | 732 | ||
| 697 | # Append background | 733 | # Append background |
| 698 | bck = gammalib.GXmlElement('parameter name="Background"') | 734 | bck = gammalib.GXmlElement('parameter name="Background"') |
| 699 | - bck.attribute('file',bkgfile) | 735 | + bck.attribute('file', bkgfile) |
| 700 | 736 | ||
| 701 | # Assign events and IRFs to observation | 737 | # Assign events and IRFs to observation |
| 702 | obs.append(ev) | 738 | obs.append(ev) |
| @@ -706,17 +742,20 @@ class csiactobs(ctools.cscript): | @@ -706,17 +742,20 @@ class csiactobs(ctools.cscript): | ||
| 706 | obs.append(bck) | 742 | obs.append(bck) |
| 707 | 743 | ||
| 708 | # Log the observation ID and object name that has been appended | 744 | # Log the observation ID and object name that has been appended |
| 709 | - self._log_value(gammalib.TERSE, 'Append observation', '%s ("%s")' % | ||
| 710 | - (obs_id, object_name)) | 745 | + self._log_value(gammalib.NORMAL, 'Append observation', '%s ("%s")' % |
| 746 | + (obs_id, object_name)) | ||
| 711 | 747 | ||
| 712 | # Log the file names of the event and response files | 748 | # Log the file names of the event and response files |
| 713 | self._log_value(gammalib.EXPLICIT, ' Event file', eventfile) | 749 | self._log_value(gammalib.EXPLICIT, ' Event file', eventfile) |
| 714 | self._log_value(gammalib.EXPLICIT, ' Effective area file', aefffile) | 750 | self._log_value(gammalib.EXPLICIT, ' Effective area file', aefffile) |
| 715 | - self._log_value(gammalib.EXPLICIT, ' Point spread function file', psffile) | ||
| 716 | - self._log_value(gammalib.EXPLICIT, ' Energy dispersion file', edispfile) | 751 | + self._log_value(gammalib.EXPLICIT, ' Point spread function file', |
| 752 | + psffile) | ||
| 753 | + self._log_value(gammalib.EXPLICIT, ' Energy dispersion file', | ||
| 754 | + edispfile) | ||
| 717 | self._log_value(gammalib.EXPLICIT, ' Background file', bkgfile) | 755 | self._log_value(gammalib.EXPLICIT, ' Background file', bkgfile) |
| 718 | if self._use_bkg_scale: | 756 | if self._use_bkg_scale: |
| 719 | - self._log_value(gammalib.EXPLICIT, ' Background scale', bkg_scale) | 757 | + self._log_value(gammalib.EXPLICIT, ' Background scale', |
| 758 | + bkg_scale) | ||
| 720 | 759 | ||
| 721 | # Append models provided by "inmodel" to the model container | 760 | # Append models provided by "inmodel" to the model container |
| 722 | self._append_inmodels() | 761 | self._append_inmodels() |
| @@ -726,8 +765,8 @@ class csiactobs(ctools.cscript): | @@ -726,8 +765,8 @@ class csiactobs(ctools.cscript): | ||
| 726 | 765 | ||
| 727 | # Write warning in no observation could be used from runlist | 766 | # Write warning in no observation could be used from runlist |
| 728 | if lib.size() == 0: | 767 | if lib.size() == 0: |
| 729 | - self._log('WARNING: No observation was appended from specified ' | ||
| 730 | - 'runlist') | 768 | + self._log_string(gammalib.NORMAL, 'WARNING: No observation was ' |
| 769 | + 'appended from specified runlist') | ||
| 731 | 770 | ||
| 732 | # Return | 771 | # Return |
| 733 | return | 772 | return |
| @@ -756,28 +795,22 @@ class csiactobs(ctools.cscript): | @@ -756,28 +795,22 @@ class csiactobs(ctools.cscript): | ||
| 756 | Save observation definition and model definition XML file | 795 | Save observation definition and model definition XML file |
| 757 | """ | 796 | """ |
| 758 | # Write header | 797 | # Write header |
| 759 | - if self._logTerse(): | ||
| 760 | - self._log('\n') | ||
| 761 | - self._log.header1('Save XML files') | 798 | + self._log_header1(gammalib.TERSE, 'Save XML files') |
| 762 | 799 | ||
| 763 | # Get filenames | 800 | # Get filenames |
| 764 | outobs = self['outobs'].filename() | 801 | outobs = self['outobs'].filename() |
| 765 | outmodel = self['outmodel'].filename() | 802 | outmodel = self['outmodel'].filename() |
| 766 | 803 | ||
| 767 | - # Log file name | ||
| 768 | - if self._logTerse(): | ||
| 769 | - self._log(gammalib.parformat('Obs. definition XML file')) | ||
| 770 | - self._log(outobs.url()) | ||
| 771 | - self._log('\n') | 804 | + # Log observation definition file name |
| 805 | + self._log_value(gammalib.NORMAL, 'Obs. definition XML file', | ||
| 806 | + outobs.url()) | ||
| 772 | 807 | ||
| 773 | # Save observation definition XML file | 808 | # Save observation definition XML file |
| 774 | self._xml.save(outobs.url()) | 809 | self._xml.save(outobs.url()) |
| 775 | 810 | ||
| 776 | - # Log file name | ||
| 777 | - if self._logTerse(): | ||
| 778 | - self._log(gammalib.parformat('Model definiton XML file')) | ||
| 779 | - self._log(outmodel.url()) | ||
| 780 | - self._log('\n') | 811 | + # Log model definition file name |
| 812 | + self._log_value(gammalib.NORMAL, 'Model definiton XML file', | ||
| 813 | + outmodel.url()) | ||
| 781 | 814 | ||
| 782 | # Save model XML file | 815 | # Save model XML file |
| 783 | self._models.save(outmodel.url()) | 816 | self._models.save(outmodel.url()) |
cscripts/csobsdef.py
| @@ -336,7 +336,7 @@ class csobsdef(ctools.cscript): | @@ -336,7 +336,7 @@ class csobsdef(ctools.cscript): | ||
| 336 | # Write observation into logger | 336 | # Write observation into logger |
| 337 | name = obs.instrument()+' observation' | 337 | name = obs.instrument()+' observation' |
| 338 | value = 'Name="%s" ID="%s"' % (obs.name(), obs.id()) | 338 | value = 'Name="%s" ID="%s"' % (obs.name(), obs.id()) |
| 339 | - self._log_value(gammalib.TERSE, name, value) | 339 | + self._log_value(gammalib.NORMAL, name, value) |
| 340 | self._log_string(gammalib.EXPLICIT, str(obs)+'\n') | 340 | self._log_string(gammalib.EXPLICIT, str(obs)+'\n') |
| 341 | 341 | ||
| 342 | # Append observation | 342 | # Append observation |
| @@ -386,6 +386,17 @@ class csobsdef(ctools.cscript): | @@ -386,6 +386,17 @@ class csobsdef(ctools.cscript): | ||
| 386 | # Return | 386 | # Return |
| 387 | return | 387 | return |
| 388 | 388 | ||
| 389 | + def obs(self): | ||
| 390 | + """ | ||
| 391 | + Returns observation container | ||
| 392 | + ----- | ||
| 393 | + Returns | ||
| 394 | + obs : `~gammalib.GObservations` | ||
| 395 | + Observation container | ||
| 396 | + """ | ||
| 397 | + # Return container | ||
| 398 | + return self._obs | ||
| 399 | + | ||
| 389 | def pntdef(self, csv): | 400 | def pntdef(self, csv): |
| 390 | """ | 401 | """ |
| 391 | Set pointing definition from a CSV table | 402 | Set pointing definition from a CSV table |
test/data/iact_runlist.dat
test/data/iact_runlist_1.dat
0 → 100644
test/data/iact_runlist_2.dat
0 → 100644
test/data/iactdata/events.fits.gz deleted
No preview for this file type
test/data/iactdata/events/events_0.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_1.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_2.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_3.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_4.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_5.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_6.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_7.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/events/events_8.fits.gz
0 → 100644
No preview for this file type
test/data/iactdata/irf_file.fits.gz renamed to test/data/iactdata/events/irf_file.fits.gz
No preview for this file type
test/data/iactdata/hdu-index.fits.gz
No preview for this file type
test/data/iactdata/master.json
| 1 | { | 1 | { |
| 2 | - "datasets": [ | ||
| 3 | - { | ||
| 4 | - "name": "unit-test", | ||
| 5 | - "obsindx": "obs-index.fits.gz", | ||
| 6 | - "hduindx": "hdu-index.fits.gz", | ||
| 7 | - "comment": "this is a comment" | ||
| 8 | - }, | ||
| 9 | - { | ||
| 10 | - "name": "unit-test-that-doesnt-exist", | ||
| 11 | - "obsindx": "badfile.fits.gz", | ||
| 12 | - "hduindx": "unavailable_file.fits.gz", | ||
| 13 | - "comment": "this is a comment" | ||
| 14 | - } | ||
| 15 | - ] | ||
| 16 | -} | 2 | + "datasets": [ |
| 3 | + { | ||
| 4 | + "name": "unit-test", | ||
| 5 | + "hduindx": "hdu-index.fits.gz", | ||
| 6 | + "obsindx": "obs-index.fits.gz", | ||
| 7 | + "Total observations": 9, | ||
| 8 | + "Total time": "0.07 hours", | ||
| 9 | + "Total events": 533, | ||
| 10 | + "Disk usage": "0.43 MB", | ||
| 11 | + "Date created": "2016-08-03" | ||
| 12 | + } | ||
| 13 | + ] | ||
| 14 | +} | ||
| 17 | \ No newline at end of file | 15 | \ No newline at end of file |
test/data/iactdata/obs-index.fits.gz
No preview for this file type
test/test_csfindobs.py
| @@ -74,7 +74,7 @@ class Test(test): | @@ -74,7 +74,7 @@ class Test(test): | ||
| 74 | # Setup csfindobs command | 74 | # Setup csfindobs command |
| 75 | cmd = csfindobs+' datapath="'+self._datapath+'"'+ \ | 75 | cmd = csfindobs+' datapath="'+self._datapath+'"'+ \ |
| 76 | ' prodname="unit-test"'+ \ | 76 | ' prodname="unit-test"'+ \ |
| 77 | - ' ra=83.63 dec=22.01 rad=1.0'+ \ | 77 | + ' ra=83.63 dec=22.01 rad=1.5'+ \ |
| 78 | ' outfile="runlist_cmd1.dat"'+ \ | 78 | ' outfile="runlist_cmd1.dat"'+ \ |
| 79 | ' logfile="csfindobs_cmd1.log" chatter=1' | 79 | ' logfile="csfindobs_cmd1.log" chatter=1' |
| 80 | 80 | ||
| @@ -87,12 +87,12 @@ class Test(test): | @@ -87,12 +87,12 @@ class Test(test): | ||
| 87 | 'Check successful execution from command line') | 87 | 'Check successful execution from command line') |
| 88 | 88 | ||
| 89 | # Check run list | 89 | # Check run list |
| 90 | - self._check_runlist('runlist_cmd1.dat') | 90 | + self._check_runlist('runlist_cmd1.dat',5) |
| 91 | 91 | ||
| 92 | # Setup csfindobs command | 92 | # Setup csfindobs command |
| 93 | cmd = csfindobs+' datapath="path_that_does_not_exist"'+ \ | 93 | cmd = csfindobs+' datapath="path_that_does_not_exist"'+ \ |
| 94 | ' prodname="unit-test"'+ \ | 94 | ' prodname="unit-test"'+ \ |
| 95 | - ' ra=83.63 dec=22.01 rad=1.0'+ \ | 95 | + ' ra=83.63 dec=22.01 rad=1.5'+ \ |
| 96 | ' outfile="runlist_cmd2.dat"'+ \ | 96 | ' outfile="runlist_cmd2.dat"'+ \ |
| 97 | ' logfile="csfindobs_cmd2.log"' | 97 | ' logfile="csfindobs_cmd2.log"' |
| 98 | 98 | ||
| @@ -114,10 +114,10 @@ class Test(test): | @@ -114,10 +114,10 @@ class Test(test): | ||
| 114 | findobs['prodname'] = 'unit-test' | 114 | findobs['prodname'] = 'unit-test' |
| 115 | findobs['ra'] = 83.63 | 115 | findobs['ra'] = 83.63 |
| 116 | findobs['dec'] = 22.01 | 116 | findobs['dec'] = 22.01 |
| 117 | - findobs['rad'] = 1.0 | 117 | + findobs['rad'] = 1.5 |
| 118 | findobs['outfile'] = 'runlist_py1.dat' | 118 | findobs['outfile'] = 'runlist_py1.dat' |
| 119 | findobs['logfile'] = 'csfindobs_py1.log' | 119 | findobs['logfile'] = 'csfindobs_py1.log' |
| 120 | - findobs['chatter'] = 2 | 120 | + findobs['chatter'] = 4 |
| 121 | 121 | ||
| 122 | # Run csfindobs script | 122 | # Run csfindobs script |
| 123 | findobs.logFileOpen() # Make sure we get a log file | 123 | findobs.logFileOpen() # Make sure we get a log file |
| @@ -125,16 +125,16 @@ class Test(test): | @@ -125,16 +125,16 @@ class Test(test): | ||
| 125 | 125 | ||
| 126 | # Check list of runs | 126 | # Check list of runs |
| 127 | runs = findobs.runs() | 127 | runs = findobs.runs() |
| 128 | - self.test_value(len(runs), 1, | 128 | + self.test_value(len(runs), 5, |
| 129 | 'Check for number of runs in runlist') | 129 | 'Check for number of runs in runlist') |
| 130 | - self.test_value(str(runs[0]), '0', | 130 | + self.test_value(str(runs[0]), '15000', |
| 131 | 'Check run ID in runlist') | 131 | 'Check run ID in runlist') |
| 132 | 132 | ||
| 133 | # Save run list | 133 | # Save run list |
| 134 | findobs.save() | 134 | findobs.save() |
| 135 | 135 | ||
| 136 | # Check run list | 136 | # Check run list |
| 137 | - self._check_runlist('runlist_py1.dat') | 137 | + self._check_runlist('runlist_py1.dat', runs=5) |
| 138 | 138 | ||
| 139 | # Set-up csfindobs for undefined spatial parameters | 139 | # Set-up csfindobs for undefined spatial parameters |
| 140 | findobs = cscripts.csfindobs() | 140 | findobs = cscripts.csfindobs() |
| @@ -151,16 +151,16 @@ class Test(test): | @@ -151,16 +151,16 @@ class Test(test): | ||
| 151 | findobs.execute() | 151 | findobs.execute() |
| 152 | 152 | ||
| 153 | # Check run list | 153 | # Check run list |
| 154 | - self._check_runlist('runlist_py2.dat') | 154 | + self._check_runlist('runlist_py2.dat', runs=9) |
| 155 | 155 | ||
| 156 | # Set-up csfindobs for user expression | 156 | # Set-up csfindobs for user expression |
| 157 | findobs = cscripts.csfindobs() | 157 | findobs = cscripts.csfindobs() |
| 158 | findobs['datapath'] = self._datapath | 158 | findobs['datapath'] = self._datapath |
| 159 | findobs['prodname'] = 'unit-test' | 159 | findobs['prodname'] = 'unit-test' |
| 160 | - findobs['ra'] = 83.63 | ||
| 161 | - findobs['dec'] = 22.01 | ||
| 162 | - findobs['rad'] = 0.0 | ||
| 163 | - findobs['expression'] = 'ONTIME<10.0' | 160 | + findobs['ra'] = 329.71 |
| 161 | + findobs['dec'] = -30.2339 | ||
| 162 | + findobs['rad'] = 2.0 | ||
| 163 | + findobs['expression'] = 'ONTIME<5.0' | ||
| 164 | findobs['outfile'] = 'runlist_py3.dat' | 164 | findobs['outfile'] = 'runlist_py3.dat' |
| 165 | findobs['logfile'] = 'csfindobs_py3.log' | 165 | findobs['logfile'] = 'csfindobs_py3.log' |
| 166 | findobs['chatter'] = 4 | 166 | findobs['chatter'] = 4 |
| @@ -195,7 +195,7 @@ class Test(test): | @@ -195,7 +195,7 @@ class Test(test): | ||
| 195 | if runs > 0: | 195 | if runs > 0: |
| 196 | self.test_value(runlist.ncols(), 1, | 196 | self.test_value(runlist.ncols(), 1, |
| 197 | 'Check for single column in runlist file') | 197 | 'Check for single column in runlist file') |
| 198 | - self.test_value(runlist[0,0], '0', | 198 | + self.test_value(runlist[0,0], '15000', |
| 199 | 'Check for run ID in runlist file') | 199 | 'Check for run ID in runlist file') |
| 200 | 200 | ||
| 201 | # Return | 201 | # Return |
test/test_csiactcopy.py
| @@ -18,6 +18,7 @@ | @@ -18,6 +18,7 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | +import os | ||
| 21 | import gammalib | 22 | import gammalib |
| 22 | import cscripts | 23 | import cscripts |
| 23 | from testing import test | 24 | from testing import test |
| @@ -43,7 +44,9 @@ class Test(test): | @@ -43,7 +44,9 @@ class Test(test): | ||
| 43 | test.__init__(self) | 44 | test.__init__(self) |
| 44 | 45 | ||
| 45 | # Set data members | 46 | # Set data members |
| 46 | - self._remote = self._datadir + '/iactdata/master.json' | 47 | + self._remote = self._datadir + '/iactdata/master.json' |
| 48 | + self._runlist1 = self._datadir + '/iact_runlist_1.dat' | ||
| 49 | + self._runlist2 = self._datadir + '/iact_runlist_2.dat' | ||
| 47 | 50 | ||
| 48 | # Return | 51 | # Return |
| 49 | return | 52 | return |
| @@ -107,20 +110,115 @@ class Test(test): | @@ -107,20 +110,115 @@ class Test(test): | ||
| 107 | Test csiactcopy from Python | 110 | Test csiactcopy from Python |
| 108 | """ | 111 | """ |
| 109 | # Set-up csiactcopy | 112 | # Set-up csiactcopy |
| 110 | - findobs = cscripts.csiactcopy() | ||
| 111 | - findobs['remote_master'] = self._remote | ||
| 112 | - findobs['prodname'] = 'unit-test' | ||
| 113 | - findobs['outpath'] = 'iactdata_py1' | ||
| 114 | - findobs['logfile'] = 'csiactcopy_py1.log' | ||
| 115 | - findobs['chatter'] = 2 | 113 | + iactcopy = cscripts.csiactcopy() |
| 114 | + iactcopy['remote_master'] = self._remote | ||
| 115 | + iactcopy['prodname'] = 'unit-test' | ||
| 116 | + iactcopy['outpath'] = 'iactdata_py1' | ||
| 117 | + iactcopy['logfile'] = 'csiactcopy_py1.log' | ||
| 118 | + iactcopy['chatter'] = 4 | ||
| 116 | 119 | ||
| 117 | # Run csiactcopy script and save run list | 120 | # Run csiactcopy script and save run list |
| 118 | - findobs.logFileOpen() # Make sure we get a log file | ||
| 119 | - findobs.run() | ||
| 120 | - findobs.save() | 121 | + iactcopy.logFileOpen() # Make sure we get a log file |
| 122 | + iactcopy.run() | ||
| 123 | + iactcopy.save() | ||
| 124 | + | ||
| 125 | + # Check IACT data store | ||
| 126 | + self._check_copy('iactdata_py1') | ||
| 127 | + self._check_n_obs('iactdata_py1', 9) | ||
| 128 | + | ||
| 129 | + # Set-up csiactcopy | ||
| 130 | + iactcopy = cscripts.csiactcopy() | ||
| 131 | + iactcopy['remote_master'] = self._remote | ||
| 132 | + iactcopy['prodname'] = 'unit-test' | ||
| 133 | + iactcopy['outpath'] = 'iactdata_py1' | ||
| 134 | + iactcopy['logfile'] = 'csiactcopy_py2.log' | ||
| 135 | + iactcopy['chatter'] = 4 | ||
| 136 | + iactcopy['clobber'] = True | ||
| 121 | 137 | ||
| 138 | + # Run csiactcopy script and save run list | ||
| 139 | + iactcopy.logFileOpen() # Make sure we get a log file | ||
| 140 | + iactcopy.run() | ||
| 141 | + iactcopy.save() | ||
| 142 | + | ||
| 122 | # Check copy | 143 | # Check copy |
| 123 | self._check_copy('iactdata_py1') | 144 | self._check_copy('iactdata_py1') |
| 145 | + self._check_n_obs('iactdata_py1', 9) | ||
| 146 | + | ||
| 147 | + # Set-up csiactcopy | ||
| 148 | + iactcopy = cscripts.csiactcopy() | ||
| 149 | + iactcopy['remote_master'] = self._remote | ||
| 150 | + iactcopy['prodname'] = 'unit-test' | ||
| 151 | + iactcopy['outpath'] = 'iactdata_py1' | ||
| 152 | + iactcopy['logfile'] = 'csiactcopy_py3.log' | ||
| 153 | + iactcopy['chatter'] = 4 | ||
| 154 | + iactcopy['clobber'] = False | ||
| 155 | + | ||
| 156 | + # Run csiactcopy script and save run list | ||
| 157 | + iactcopy.logFileOpen() # Make sure we get a log file | ||
| 158 | + iactcopy.run() | ||
| 159 | + iactcopy.save() | ||
| 160 | + | ||
| 161 | + # Check copy | ||
| 162 | + self._check_copy('iactdata_py1') | ||
| 163 | + self._check_n_obs('iactdata_py1', 9) | ||
| 164 | + | ||
| 165 | + if os.path.isdir('iactdata_py2'): | ||
| 166 | + os.system("rm -r iactdata_py2") | ||
| 167 | + | ||
| 168 | + # Set-up csiactcopy | ||
| 169 | + iactcopy = cscripts.csiactcopy() | ||
| 170 | + iactcopy['runlist'] = self._runlist1 | ||
| 171 | + iactcopy['remote_master'] = self._remote | ||
| 172 | + iactcopy['prodname'] = 'unit-test' | ||
| 173 | + iactcopy['outpath'] = 'iactdata_py2' | ||
| 174 | + iactcopy['logfile'] = 'csiactcopy_py4.log' | ||
| 175 | + iactcopy['chatter'] = 3 | ||
| 176 | + | ||
| 177 | + # Run csiactcopy script and save run list | ||
| 178 | + iactcopy.logFileOpen() # Make sure we get a log file | ||
| 179 | + iactcopy.run() | ||
| 180 | + iactcopy.save() | ||
| 181 | + | ||
| 182 | + # Check copy | ||
| 183 | + self._check_copy('iactdata_py2') | ||
| 184 | + self._check_n_obs('iactdata_py2', 5) | ||
| 185 | + | ||
| 186 | + # Set-up csiactcopy | ||
| 187 | + iactcopy = cscripts.csiactcopy() | ||
| 188 | + iactcopy['runlist'] = self._runlist2 | ||
| 189 | + iactcopy['remote_master'] = self._remote | ||
| 190 | + iactcopy['prodname'] = 'unit-test' | ||
| 191 | + iactcopy['outpath'] = 'iactdata_py2' | ||
| 192 | + iactcopy['logfile'] = 'csiactcopy_py5.log' | ||
| 193 | + iactcopy['chatter'] = 3 | ||
| 194 | + | ||
| 195 | + # Run csiactcopy script and save run list | ||
| 196 | + iactcopy.logFileOpen() # Make sure we get a log file | ||
| 197 | + iactcopy.run() | ||
| 198 | + iactcopy.save() | ||
| 199 | + | ||
| 200 | + # Check copy | ||
| 201 | + self._check_copy('iactdata_py2') | ||
| 202 | + self._check_n_obs('iactdata_py2', 9) | ||
| 203 | + | ||
| 204 | + # Set-up csiactcopy | ||
| 205 | + iactcopy = cscripts.csiactcopy() | ||
| 206 | + iactcopy['runlist'] = self._runlist2 | ||
| 207 | + iactcopy['remote_master'] = self._remote | ||
| 208 | + iactcopy['prodname'] = 'unit-test' | ||
| 209 | + iactcopy['outpath'] = 'iactdata_py2' | ||
| 210 | + iactcopy['logfile'] = 'csiactcopy_py6.log' | ||
| 211 | + iactcopy['chatter'] = 3 | ||
| 212 | + iactcopy['clobber'] = True | ||
| 213 | + | ||
| 214 | + # Run csiactcopy script and save run list | ||
| 215 | + iactcopy.logFileOpen() # Make sure we get a log file | ||
| 216 | + iactcopy.run() | ||
| 217 | + iactcopy.save() | ||
| 218 | + | ||
| 219 | + # Check copy | ||
| 220 | + self._check_copy('iactdata_py2') | ||
| 221 | + self._check_n_obs('iactdata_py2',9) | ||
| 124 | 222 | ||
| 125 | # Return | 223 | # Return |
| 126 | return | 224 | return |
| @@ -151,3 +249,27 @@ class Test(test): | @@ -151,3 +249,27 @@ class Test(test): | ||
| 151 | 249 | ||
| 152 | # Return | 250 | # Return |
| 153 | return | 251 | return |
| 252 | + | ||
| 253 | + # Check copy | ||
| 254 | + def _check_n_obs(self, pathname, n_expected): | ||
| 255 | + """ | ||
| 256 | + Check number of available observations. | ||
| 257 | + """ | ||
| 258 | + # Set file name | ||
| 259 | + obs_index_name = gammalib.GFilename(pathname+'/obs-index.fits[OBS_INDEX]') | ||
| 260 | + | ||
| 261 | + # Open index file | ||
| 262 | + fits = gammalib.GFits(obs_index_name) | ||
| 263 | + | ||
| 264 | + # Get number of observations | ||
| 265 | + n_obs = fits[obs_index_name.extname()].nrows() | ||
| 266 | + | ||
| 267 | + # Close FITS file | ||
| 268 | + fits.close() | ||
| 269 | + | ||
| 270 | + # Check for existence of observations | ||
| 271 | + self.test_assert(n_obs == n_expected, | ||
| 272 | + 'Check for '+str(n_expected)+' observations.') | ||
| 273 | + | ||
| 274 | + # Return | ||
| 275 | + return | ||
| 154 | \ No newline at end of file | 276 | \ No newline at end of file |
test/test_csiactobs.py
| @@ -90,10 +90,10 @@ class Test(test): | @@ -90,10 +90,10 @@ class Test(test): | ||
| 90 | 'Check successful execution from command line') | 90 | 'Check successful execution from command line') |
| 91 | 91 | ||
| 92 | # Check observation definition XML file | 92 | # Check observation definition XML file |
| 93 | - self._check_obsdef('csiactobs_obs_cmd1.xml') | 93 | + self._check_obsdef('csiactobs_obs_cmd1.xml', 6) |
| 94 | 94 | ||
| 95 | # Check model definition XML file | 95 | # Check model definition XML file |
| 96 | - self._check_moddef('csiactobs_bgd_cmd1.xml') | 96 | + self._check_moddef('csiactobs_bgd_cmd1.xml', 6) |
| 97 | 97 | ||
| 98 | # Setup csiactobs command | 98 | # Setup csiactobs command |
| 99 | cmd = csiactobs+' datapath="data_path_that_does_not_exist"'+ \ | 99 | cmd = csiactobs+' datapath="data_path_that_does_not_exist"'+ \ |
| @@ -146,13 +146,13 @@ class Test(test): | @@ -146,13 +146,13 @@ class Test(test): | ||
| 146 | iactobs.save() | 146 | iactobs.save() |
| 147 | 147 | ||
| 148 | # Check observation definition XML file | 148 | # Check observation definition XML file |
| 149 | - self._check_obsdef('csiactobs_obs_py1.xml') | 149 | + self._check_obsdef('csiactobs_obs_py1.xml', 6) |
| 150 | 150 | ||
| 151 | # Check model definition XML file | 151 | # Check model definition XML file |
| 152 | - self._check_moddef('csiactobs_bgd_py1.xml') | 152 | + self._check_moddef('csiactobs_bgd_py1.xml', 6) |
| 153 | 153 | ||
| 154 | # Create test runlist | 154 | # Create test runlist |
| 155 | - runlist = ['0'] | 155 | + runlist = ['15000','15001'] |
| 156 | 156 | ||
| 157 | # Set-up csiactobs using a runlist with 2 background parameters | 157 | # Set-up csiactobs using a runlist with 2 background parameters |
| 158 | iactobs = cscripts.csiactobs() | 158 | iactobs = cscripts.csiactobs() |
| @@ -171,16 +171,16 @@ class Test(test): | @@ -171,16 +171,16 @@ class Test(test): | ||
| 171 | iactobs.save() | 171 | iactobs.save() |
| 172 | 172 | ||
| 173 | # Test return functions | 173 | # Test return functions |
| 174 | - self.test_value(iactobs.obs().size(), 1, | 174 | + self.test_value(iactobs.obs().size(), 2, |
| 175 | 'Check number of observations in container') | 175 | 'Check number of observations in container') |
| 176 | self.test_value(iactobs.ebounds().size(), 0, | 176 | self.test_value(iactobs.ebounds().size(), 0, |
| 177 | 'Check number of energy boundaries') | 177 | 'Check number of energy boundaries') |
| 178 | 178 | ||
| 179 | # Check observation definition XML file | 179 | # Check observation definition XML file |
| 180 | - self._check_obsdef('csiactobs_obs_py2.xml') | 180 | + self._check_obsdef('csiactobs_obs_py2.xml',2) |
| 181 | 181 | ||
| 182 | # Check model definition XML file | 182 | # Check model definition XML file |
| 183 | - self._check_moddef('csiactobs_bgd_py2.xml') | 183 | + self._check_moddef('csiactobs_bgd_py2.xml',2) |
| 184 | 184 | ||
| 185 | # Set-up csiactobs with a large number of free parameters and "aeff" | 185 | # Set-up csiactobs with a large number of free parameters and "aeff" |
| 186 | # background | 186 | # background |
| @@ -199,10 +199,10 @@ class Test(test): | @@ -199,10 +199,10 @@ class Test(test): | ||
| 199 | iactobs.execute() | 199 | iactobs.execute() |
| 200 | 200 | ||
| 201 | # Check observation definition XML file | 201 | # Check observation definition XML file |
| 202 | - self._check_obsdef('csiactobs_obs_py3.xml') | 202 | + self._check_obsdef('csiactobs_obs_py3.xml',6) |
| 203 | 203 | ||
| 204 | # Check model definition XML file | 204 | # Check model definition XML file |
| 205 | - self._check_moddef('csiactobs_bgd_py3.xml') | 205 | + self._check_moddef('csiactobs_bgd_py3.xml',6) |
| 206 | 206 | ||
| 207 | # Set-up csiactobs with a "gauss" background and "inmodel" parameter | 207 | # Set-up csiactobs with a "gauss" background and "inmodel" parameter |
| 208 | iactobs = cscripts.csiactobs() | 208 | iactobs = cscripts.csiactobs() |
| @@ -222,56 +222,85 @@ class Test(test): | @@ -222,56 +222,85 @@ class Test(test): | ||
| 222 | iactobs.run() | 222 | iactobs.run() |
| 223 | 223 | ||
| 224 | # Check number of observations | 224 | # Check number of observations |
| 225 | - self.test_value(iactobs.obs().size(), 1, | 225 | + self.test_value(iactobs.obs().size(), 6, |
| 226 | 'Check number of observations in container') | 226 | 'Check number of observations in container') |
| 227 | 227 | ||
| 228 | # Check number of models | 228 | # Check number of models |
| 229 | - self.test_value(iactobs.obs().models().size(), 3, | ||
| 230 | - 'Check number of models in container') | 229 | + self.test_value(iactobs.obs().models().size(), 8, |
| 230 | + 'Check number of models in container') | ||
| 231 | + | ||
| 232 | + # Set-up csiactobs with a "gauss" background and "inmodel" parameter | ||
| 233 | + iactobs = cscripts.csiactobs() | ||
| 234 | + iactobs['datapath'] = self._datapath | ||
| 235 | + iactobs['inmodel'] = self._model | ||
| 236 | + iactobs['prodname'] = 'unit-test' | ||
| 237 | + iactobs['infile'] = self._runlist | ||
| 238 | + iactobs['bkgpars'] = 1 | ||
| 239 | + iactobs['bkg_mod_hiera'] = 'irf' | ||
| 240 | + iactobs['outobs'] = 'NONE' | ||
| 241 | + iactobs['outmodel'] = 'NONE' | ||
| 242 | + iactobs['logfile'] = 'csiactobs_py4.log' | ||
| 243 | + iactobs['chatter'] = 4 | ||
| 244 | + | ||
| 245 | + # Run csiactobs script | ||
| 246 | + iactobs.logFileOpen() # Make sure we get a log file | ||
| 247 | + iactobs.run() | ||
| 248 | + | ||
| 249 | + # Check number of observations | ||
| 250 | + self.test_value(iactobs.obs().size(), 5, | ||
| 251 | + 'Check number of observations in container') | ||
| 252 | + | ||
| 253 | + # Check number of models | ||
| 254 | + self.test_value(iactobs.obs().models().size(), 7, | ||
| 255 | + 'Check number of models in container') | ||
| 231 | 256 | ||
| 232 | # Return | 257 | # Return |
| 233 | return | 258 | return |
| 234 | 259 | ||
| 235 | # Check observation definition XML file | 260 | # Check observation definition XML file |
| 236 | - def _check_obsdef(self, filename): | 261 | + def _check_obsdef(self, filename, obs_expected): |
| 237 | """ | 262 | """ |
| 238 | Check observation definition XML file | 263 | Check observation definition XML file |
| 239 | """ | 264 | """ |
| 240 | # Load observation definition XML file | 265 | # Load observation definition XML file |
| 241 | obs = gammalib.GObservations(filename) | 266 | obs = gammalib.GObservations(filename) |
| 242 | 267 | ||
| 243 | - # Get response | ||
| 244 | - rsp = obs[0].response() | ||
| 245 | - | ||
| 246 | # Check number of observations | 268 | # Check number of observations |
| 247 | - self.test_value(obs.size(), 1, | ||
| 248 | - 'Check for single observation in XML file') | ||
| 249 | - self.test_value(obs[0].eventfile().file(), 'events.fits.gz', | ||
| 250 | - 'Check event file name') | ||
| 251 | - self.test_value(obs[0].eventfile().extname(), 'EVENTS', | ||
| 252 | - 'Check event extension name') | ||
| 253 | - self.test_value(rsp.aeff().filename().file(), 'irf_file.fits.gz', | ||
| 254 | - 'Check effective area file name') | ||
| 255 | - self.test_value(rsp.aeff().filename().extname(), 'EFFECTIVE AREA', | ||
| 256 | - 'Check effective area extension name') | ||
| 257 | - self.test_value(rsp.psf().filename().file(), 'irf_file.fits.gz', | ||
| 258 | - 'Check point spread function file name') | ||
| 259 | - self.test_value(rsp.psf().filename().extname(), 'POINT SPREAD FUNCTION', | ||
| 260 | - 'Check point spread function extension name') | ||
| 261 | - self.test_value(rsp.edisp().filename().file(), 'irf_file.fits.gz', | ||
| 262 | - 'Check energy dispersion file name') | ||
| 263 | - self.test_value(rsp.edisp().filename().extname(), 'ENERGY DISPERSION', | ||
| 264 | - 'Check energy dispersion extension name') | ||
| 265 | - self.test_value(rsp.background().filename().file(), 'irf_file.fits.gz', | ||
| 266 | - 'Check background file name') | ||
| 267 | - self.test_value(rsp.background().filename().extname(), 'BACKGROUND', | ||
| 268 | - 'Check background extension name') | 269 | + self.test_value(obs.size(), obs_expected, |
| 270 | + 'Check for '+str(obs_expected)+' observations in XML file') | ||
| 271 | + | ||
| 272 | + if obs_expected > 0: | ||
| 273 | + | ||
| 274 | + # Get response | ||
| 275 | + rsp = obs[0].response() | ||
| 276 | + | ||
| 277 | + # Test response | ||
| 278 | + self.test_value(obs[0].eventfile().file(), 'events_0.fits.gz', | ||
| 279 | + 'Check event file name') | ||
| 280 | + self.test_value(obs[0].eventfile().extname(), 'EVENTS', | ||
| 281 | + 'Check event extension name') | ||
| 282 | + self.test_value(rsp.aeff().filename().file(), 'irf_file.fits.gz', | ||
| 283 | + 'Check effective area file name') | ||
| 284 | + self.test_value(rsp.aeff().filename().extname(), 'EFFECTIVE AREA', | ||
| 285 | + 'Check effective area extension name') | ||
| 286 | + self.test_value(rsp.psf().filename().file(), 'irf_file.fits.gz', | ||
| 287 | + 'Check point spread function file name') | ||
| 288 | + self.test_value(rsp.psf().filename().extname(), 'POINT SPREAD FUNCTION', | ||
| 289 | + 'Check point spread function extension name') | ||
| 290 | + self.test_value(rsp.edisp().filename().file(), 'irf_file.fits.gz', | ||
| 291 | + 'Check energy dispersion file name') | ||
| 292 | + self.test_value(rsp.edisp().filename().extname(), 'ENERGY DISPERSION', | ||
| 293 | + 'Check energy dispersion extension name') | ||
| 294 | + self.test_value(rsp.background().filename().file(), 'irf_file.fits.gz', | ||
| 295 | + 'Check background file name') | ||
| 296 | + self.test_value(rsp.background().filename().extname(), 'BACKGROUND', | ||
| 297 | + 'Check background extension name') | ||
| 269 | 298 | ||
| 270 | # Return | 299 | # Return |
| 271 | return | 300 | return |
| 272 | 301 | ||
| 273 | # Check model XML file | 302 | # Check model XML file |
| 274 | - def _check_moddef(self, filename): | 303 | + def _check_moddef(self, filename, models_expected): |
| 275 | """ | 304 | """ |
| 276 | Check model definition XML file | 305 | Check model definition XML file |
| 277 | """ | 306 | """ |
| @@ -279,8 +308,8 @@ class Test(test): | @@ -279,8 +308,8 @@ class Test(test): | ||
| 279 | models = gammalib.GModels(filename) | 308 | models = gammalib.GModels(filename) |
| 280 | 309 | ||
| 281 | # Check number of models | 310 | # Check number of models |
| 282 | - self.test_value(models.size(), 1, | ||
| 283 | - 'Check for single model in XML file') | 311 | + self.test_value(models.size(), models_expected, |
| 312 | + 'Check for '+str(models_expected)+' models in XML file') | ||
| 284 | 313 | ||
| 285 | # Return | 314 | # Return |
| 286 | return | 315 | return |