Commit ce677783119e3470c7bf362aa9972ab4f963f9af

Authored by Jürgen Knödlseder
1 parent 523323c9

Enhance cscripts

cscripts/csiactobs.py
... ... @@ -53,15 +53,12 @@ class csiactobs(ctools.cscript):
53 53 self._obs = gammalib.GObservations()
54 54 self._ebounds = gammalib.GEbounds()
55 55 self._datapath = os.getenv('VHEFITS','')
56   - self._inmodels = gammalib.GModels()
57 56 self._prodname = ''
58 57 self._xml = gammalib.GXml()
59 58 self._models = gammalib.GModels()
60 59 self._runlist = []
61 60 self._runlistfile = gammalib.GFilename()
62 61 self._bkgpars = 0
63   - #self._outmodel = gammalib.GFilename()
64   - #self._outobs = gammalib.GFilename()
65 62 self._master_indx = ''
66 63 self._use_bkg_scale = False
67 64 self._ev_hiera = ['']
... ... @@ -97,10 +94,9 @@ class csiactobs(ctools.cscript):
97 94 if self._datapath == '':
98 95 self._datapath = self['datapath'].string()
99 96  
100   - # Check for input models
101   - if not self['inmodel'].filename() == 'NONE':
102   - self._inmodels = gammalib.GModels(self['inmodel'].filename())
103   -
  97 + # Query input parameters
  98 + self['inmodel'].filename()
  99 +
104 100 # Expand environment
105 101 self._datapath = gammalib.expand_env(self._datapath)
106 102  
... ... @@ -246,7 +242,6 @@ class csiactobs(ctools.cscript):
246 242 spec : `~gammalib.GModelSpectral()`
247 243 Spectral model for the background shape
248 244 """
249   -
250 245 # Handle constant spectral model
251 246 if index == 0.0 and self._bkgpars <= 1:
252 247 spec = gammalib.GModelSpectralConst()
... ... @@ -346,8 +341,7 @@ class csiactobs(ctools.cscript):
346 341 model : `~gammalib.GModelData()`
347 342 Background model for IACT observation
348 343 """
349   -
350   - # handle IrfBackground
  344 + # Handle IrfBackground
351 345 if bkgtype == 'irf':
352 346  
353 347 # Set parameters to have a constant spectral model
... ... @@ -400,11 +394,63 @@ class csiactobs(ctools.cscript):
400 394 # Return model
401 395 return model
402 396  
  397 + def _append_inmodels(self):
  398 + """
  399 + Append input models
  400 + """
  401 + # If there are models provided by "inmodels" then append them now to
  402 + # the model container
  403 + filename = self['inmodel'].filename().url()
  404 + if filename != '' and filename != 'NONE':
  405 +
  406 + # Write header
  407 + if self._logTerse():
  408 + self._log('\n')
  409 + self._log.header1('Append input models')
  410 + self._log_value('Input model file', filename)
  411 +
  412 + # Load input models
  413 + models = gammalib.GModels(filename)
  414 +
  415 + # Loop over input models and append them to the model container
  416 + for model in models:
  417 + self._models.append(model)
  418 + if self._logTerse():
  419 + self._log_value('Append model', '"'+model.name()+'"')
  420 +
  421 + # Return
  422 + return
  423 +
  424 + def _write_summary(self):
  425 + """
  426 + Write observation summary
  427 + """
  428 + # Write observation summary
  429 + if self._logTerse():
  430 +
  431 + # Log header
  432 + self._log('\n')
  433 + self._log.header1('Observation summary')
  434 +
  435 + # Set energy range dependent on whether boundaries exist or
  436 + # not
  437 + if self._ebounds.size() > 0:
  438 + erange = '%s - %s' % (str(self._ebounds.emin()),
  439 + str(self._ebounds.emax()))
  440 + else:
  441 + erange = 'not available'
  442 +
  443 + # Log energy range
  444 + self._log_value('Energy range', erange)
  445 +
  446 + # Return
  447 + return
  448 +
403 449  
404 450 # Public methods
405 451 def run(self):
406 452 """
407   - Run the script.
  453 + Run the script
408 454 """
409 455 # Switch screen logging on in debug mode
410 456 if self._logDebug():
... ... @@ -416,7 +462,7 @@ class csiactobs(ctools.cscript):
416 462 # Clear models
417 463 self._models.clear()
418 464  
419   - # Clear xml file and append an observation list
  465 + # Clear XML file and append an observation list
420 466 self._xml.clear()
421 467 self._xml.append(gammalib.GXmlElement('observation_list title="observation list"'))
422 468 lib = self._xml.element('observation_list', 0)
... ... @@ -467,7 +513,8 @@ class csiactobs(ctools.cscript):
467 513 # Check if psf file is available
468 514 if not gammalib.GFilename(eventfile).is_fits():
469 515  
470   - # Print warning that observation will be skipped since no events are present
  516 + # Print warning that observation will be skipped since no
  517 + # events are present
471 518 if self._logTerse():
472 519 self._log('Skipping observation '+str(obs_id)+
473 520 ': eventfile "'+eventfile+'" not found\n')
... ... @@ -633,22 +680,6 @@ class csiactobs(ctools.cscript):
633 680 run_emin.TeV(),
634 681 run_emax.TeV()))
635 682  
636   - # Logging
637   - if self._logTerse():
638   - self._log('Adding observation '+str(obs_id)+
639   - ' ("'+object_name+'")\n')
640   -
641   - # log more details
642   - if self._logExplicit():
643   - self._log(' Event file: '+eventfile+'\n')
644   - self._log(' Effective area: '+aefffile+'\n')
645   - self._log(' Point spread function: '+psffile+'\n')
646   - self._log(' Energy dispersion: '+edispfile+'\n')
647   - self._log(' Background file: '+bkgfile+'\n')
648   - if self._use_bkg_scale:
649   - self._log(' Background scale: '+str(bkg_scale)+'\n')
650   - self._log('\n')
651   -
652 683 # Append observation to XML and set attributes
653 684 obs = lib.append('observation')
654 685 obs.attribute('name', object_name)
... ... @@ -675,51 +706,38 @@ class csiactobs(ctools.cscript):
675 706 bck = gammalib.GXmlElement('parameter name="Background"')
676 707 bck.attribute('file',bkgfile)
677 708  
678   - # assign events and IRFs to observation
  709 + # Assign events and IRFs to observation
679 710 obs.append(ev)
680 711 obs.append(aeff)
681 712 obs.append(psf)
682 713 obs.append(edisp)
683 714 obs.append(bck)
684   -
685   - # Continue only if there are observations available
686   - if lib.size():
687   -
688   - # Log header of energy range
689   - if self._logTerse():
690   - self._log('\n')
691   - self._log.header3('Energy range of obervation list')
692   -
693   - # Logging if energy range is available
694   - if self._ebounds.size() > 0:
695   -
696   - # Write energy range into log file
697   - self._log(str(self._ebounds.emin())+' - '+str(self._ebounds.emax()))
698   - self._log('\n')
699   -
700   - else:
701   -
702   - # Write 'not available' into log file
703   - self._log('not available')
704   - self._log('\n')
705   -
706   - else:
707   - # Print warning if no observation could be be used from runlist
708   - self._log.header2('WARNING: No observation from given runlist available')
709 715  
710   - # Append models provided by 'inmodels' if necessary
711   - if self._inmodels.size() > 0:
712   -
713   - # Logging
  716 + # Log the observation ID and object name that has been appended
714 717 if self._logTerse():
715   - self._log('\n')
716   - self._log.header1('Appending models')
  718 + self._log_value('Append observation', '%s ("%s")' %
  719 + (obs_id, object_name))
717 720  
718   - # Loop over input models
719   - for model in self._inmodels:
720   - if self._logTerse():
721   - self._log.header3('Adding model "'+model.name()+'"')
722   - self._models.append(model)
  721 + # Log the file names of the event and response files
  722 + if self._logExplicit():
  723 + self._log_value(' Event file', eventfile)
  724 + self._log_value(' Effective area file', aefffile)
  725 + self._log_value(' Point spread function file', psffile)
  726 + self._log_value(' Energy dispersion file', edispfile)
  727 + self._log_value(' Background file', bkgfile)
  728 + if self._use_bkg_scale:
  729 + self._log_value(' Background scale', bkg_scale)
  730 +
  731 + # Append models provided by "inmodel" to the model container
  732 + self._append_inmodels()
  733 +
  734 + # Write observation summary
  735 + self._write_summary()
  736 +
  737 + # Write warning in no observation could be used from runlist
  738 + if lib.size() == 0:
  739 + self._log('WARNING: No observation was appended from specified '
  740 + 'runlist')
723 741  
724 742 # Return
725 743 return
... ...
cscripts/csroot2caldb.py
... ... @@ -51,14 +51,6 @@ class csroot2caldb(ctools.cscript):
51 51 self._name = 'csroot2caldb'
52 52 self._version = '1.2.0'
53 53  
54   - # Initialise file members
55   - self._cif = None
56   - self._ea = None
57   - self._psf = None
58   - self._edisp = None
59   - self._bgd = None
60   - self._hdu_cif = None
61   -
62 54 # Initialise application by calling the appropriate class constructor
63 55 self._init_cscript(argv)
64 56  
... ... @@ -240,18 +232,18 @@ class csroot2caldb(ctools.cscript):
240 232 ----------
241 233 irf : dict
242 234 IRF metadata dictionary
243   - dir : dir
  235 + dir : dict
244 236 Directory structure dictionary
245 237 """
246 238 # Open calibration database index
247   - self._cif = gammalib.GFits(dir['BASE_PATH']+'/caldb.indx', True)
  239 + dir['CIF'] = gammalib.GFits(dir['BASE_PATH']+'/caldb.indx', True)
248 240  
249 241 # If file has no CIF extension than create it now
250 242 try:
251   - self._hdu_cif = self._cif.table('CIF')
  243 + dir['HDU_CIF'] = dir['CIF'].table('CIF')
252 244 except:
253   - self._cif.append(calutils.create_cif_table())
254   - self._hdu_cif = self._cif.table('CIF')
  245 + dir['CIF'].append(calutils.create_cif_table())
  246 + dir['HDU_CIF'] = dir['CIF'].table('CIF')
255 247  
256 248 # Set IRF component filenames
257 249 ea_filename = dir['EA_PATH']+'/'+dir['EA_FILE']
... ... @@ -261,25 +253,29 @@ class csroot2caldb(ctools.cscript):
261 253  
262 254 # Open IRF component files
263 255 if self['split'].boolean():
264   - self._ea = gammalib.GFits(ea_filename, True)
265   - self._psf = gammalib.GFits(psf_filename, True)
266   - self._edisp = gammalib.GFits(edisp_filename, True)
267   - self._bgd = gammalib.GFits(bgd_filename, True)
  256 + dir['EA_FITS'] = gammalib.GFits(ea_filename, True)
  257 + dir['PSF_FITS'] = gammalib.GFits(psf_filename, True)
  258 + dir['EDISP_FITS'] = gammalib.GFits(edisp_filename, True)
  259 + dir['BGD_FITS'] = gammalib.GFits(bgd_filename, True)
268 260 else:
269   - self._ea = gammalib.GFits(ea_filename, True)
270   - self._psf = self._ea
271   - self._edisp = self._ea
272   - self._bgd = self._ea
  261 + dir['EA_FITS'] = gammalib.GFits(ea_filename, True)
  262 + dir['PSF_FITS'] = dir['EA_FITS']
  263 + dir['EDISP_FITS'] = dir['EA_FITS']
  264 + dir['BGD_FITS'] = dir['EA_FITS']
273 265  
274 266 # Open HDUs
275   - self._hdu_ea = self._open_hdu(self._ea, "EFFECTIVE AREA",
276   - irf['EA_NAME'], irf['EA_DOC'], irf)
277   - self._hdu_psf = self._open_hdu(self._psf, "POINT SPREAD FUNCTION",
278   - irf['PSF_NAME'], irf['PSF_DOC'], irf)
279   - self._hdu_edisp = self._open_hdu(self._edisp, "ENERGY DISPERSION",
280   - irf['EDISP_NAME'], irf['EDISP_DOC'], irf)
281   - self._hdu_bgd = self._open_hdu(self._bgd, "BACKGROUND",
282   - irf['BGD_NAME'], irf['BGD_DOC'], irf)
  267 + dir['HDU_EA'] = self._open_hdu(dir['EA_FITS'], "EFFECTIVE AREA",
  268 + irf['EA_NAME'], irf['EA_DOC'],
  269 + irf)
  270 + dir['HDU_PSF'] = self._open_hdu(dir['PSF_FITS'], "POINT SPREAD FUNCTION",
  271 + irf['PSF_NAME'], irf['PSF_DOC'],
  272 + irf)
  273 + dir['HDU_EDISP'] = self._open_hdu(dir['EDISP_FITS'], "ENERGY DISPERSION",
  274 + irf['EDISP_NAME'], irf['EDISP_DOC'],
  275 + irf)
  276 + dir['HDU_BGD'] = self._open_hdu(dir['BGD_FITS'], "BACKGROUND",
  277 + irf['BGD_NAME'], irf['BGD_DOC'],
  278 + irf)
283 279  
284 280 # Return
285 281 return
... ... @@ -301,21 +297,21 @@ class csroot2caldb(ctools.cscript):
301 297 self._add_cif_info(irf, dir)
302 298  
303 299 # Save and close CIF
304   - self._cif.save(True)
305   - self._cif.close()
  300 + dir['CIF'].save(True)
  301 + dir['CIF'].close()
306 302  
307 303 # Close all IRF components. If the files have been split all components
308 304 # need to be closed, otherwise only the effective area component needs
309 305 # to be closed as representative for all components.
310   - self._ea.save(True)
311   - self._ea.close()
  306 + dir['EA_FITS'].save(True)
  307 + dir['EA_FITS'].close()
312 308 if self['split'].boolean():
313   - self._psf.save(True)
314   - self._edisp.save(True)
315   - self._bgd.save(True)
316   - self._psf.close()
317   - self._edisp.close()
318   - self._bgd.close()
  309 + dir['PSF_FITS'].save(True)
  310 + dir['EDISP_FITS'].save(True)
  311 + dir['BGD_FITS'].save(True)
  312 + dir['PSF_FITS'].close()
  313 + dir['EDISP_FITS'].close()
  314 + dir['BGD_FITS'].close()
319 315  
320 316 # Return
321 317 return
... ... @@ -412,10 +408,10 @@ class csroot2caldb(ctools.cscript):
412 408 names = ['EA', 'PSF', 'EDISP', 'BGD']
413 409  
414 410 # Initialise CIF row index
415   - row = self._hdu_cif.nrows()
  411 + row = dir['HDU_CIF'].nrows()
416 412  
417 413 # Append rows for all components to CIF extension
418   - self._hdu_cif.append_rows(len(names))
  414 + dir['HDU_CIF'].append_rows(len(names))
419 415  
420 416 # Add information for all components
421 417 for name in names:
... ... @@ -428,30 +424,30 @@ class csroot2caldb(ctools.cscript):
428 424 key_bounds = '%s_BOUNDS' % name
429 425  
430 426 # Set generic information
431   - self._hdu_cif['TELESCOP'][row] = irf['CAL_TEL']
432   - self._hdu_cif['INSTRUME'][row] = irf['CAL_INST']
433   - self._hdu_cif['DETNAM'][row] = irf['CAL_DET']
434   - self._hdu_cif['FILTER'][row] = irf['CAL_FLT']
435   - self._hdu_cif['CAL_DEV'][row] = 'ONLINE'
436   - self._hdu_cif['CAL_CLAS'][row] = irf['CAL_CLASS']
437   - self._hdu_cif['CAL_DTYP'][row] = irf['CAL_TYPE']
438   - self._hdu_cif['CAL_VSD'][row] = irf['VAL_DATE']
439   - self._hdu_cif['CAL_VST'][row] = irf['VAL_TIME']
440   - self._hdu_cif['REF_TIME'][row] = irf['REF_TIME']
441   - self._hdu_cif['CAL_QUAL'][row] = irf['CAL_QUAL']
442   - self._hdu_cif['CAL_DATE'][row] = irf['CAL_DATE']
  427 + dir['HDU_CIF']['TELESCOP'][row] = irf['CAL_TEL']
  428 + dir['HDU_CIF']['INSTRUME'][row] = irf['CAL_INST']
  429 + dir['HDU_CIF']['DETNAM'][row] = irf['CAL_DET']
  430 + dir['HDU_CIF']['FILTER'][row] = irf['CAL_FLT']
  431 + dir['HDU_CIF']['CAL_DEV'][row] = 'ONLINE'
  432 + dir['HDU_CIF']['CAL_CLAS'][row] = irf['CAL_CLASS']
  433 + dir['HDU_CIF']['CAL_DTYP'][row] = irf['CAL_TYPE']
  434 + dir['HDU_CIF']['CAL_VSD'][row] = irf['VAL_DATE']
  435 + dir['HDU_CIF']['CAL_VST'][row] = irf['VAL_TIME']
  436 + dir['HDU_CIF']['REF_TIME'][row] = irf['REF_TIME']
  437 + dir['HDU_CIF']['CAL_QUAL'][row] = irf['CAL_QUAL']
  438 + dir['HDU_CIF']['CAL_DATE'][row] = irf['CAL_DATE']
443 439  
444 440 # Set component specific information
445   - self._hdu_cif['CAL_DIR'][row] = dir[key_dir]
446   - self._hdu_cif['CAL_FILE'][row] = dir[key_file]
447   - self._hdu_cif['CAL_CNAM'][row] = irf[key_name]
448   - self._hdu_cif['CAL_DESC'][row] = irf[key_desc]
449   - self._hdu_cif['CAL_XNO'][row] = 1
  441 + dir['HDU_CIF']['CAL_DIR'][row] = dir[key_dir]
  442 + dir['HDU_CIF']['CAL_FILE'][row] = dir[key_file]
  443 + dir['HDU_CIF']['CAL_CNAM'][row] = irf[key_name]
  444 + dir['HDU_CIF']['CAL_DESC'][row] = irf[key_desc]
  445 + dir['HDU_CIF']['CAL_XNO'][row] = 1
450 446 for i in range(9):
451 447 if i >= len(irf[key_bounds]):
452   - self._hdu_cif['CAL_CBD'][row,i] = 'NONE'
  448 + dir['HDU_CIF']['CAL_CBD'][row,i] = 'NONE'
453 449 else:
454   - self._hdu_cif['CAL_CBD'][row,i] = irf[key_bounds][i]
  450 + dir['HDU_CIF']['CAL_CBD'][row,i] = irf[key_bounds][i]
455 451  
456 452 # Increment row index
457 453 row += 1
... ... @@ -474,7 +470,7 @@ class csroot2caldb(ctools.cscript):
474 470 desc : str
475 471 Calibration description
476 472 irf : dict
477   - IRF dictionary
  473 + IRF metadata dictionary
478 474 """
479 475 # Set standard CIF keywords
480 476 hdu.card('CSYSNAME', 'XMA_POL', '')
... ... @@ -503,34 +499,36 @@ class csroot2caldb(ctools.cscript):
503 499  
504 500  
505 501 # ROOT specific private members
506   - def _root2caldb(self, irf):
  502 + def _root2caldb(self, irf, dir):
507 503 """
508 504 Translate ROOT to CALDB information
509 505  
510 506 Parameters
511 507 ----------
512 508 irf : dict
513   - IRF dictionary
  509 + IRF metadata dictionary
  510 + dir : dict
  511 + Directory structure dictionary
514 512 """
515 513 # Open ROOT performance file
516 514 file = TFile(self['infile'].filename().url())
517 515  
518 516 # Create effective area
519   - self._root2ea(file, irf)
  517 + self._root2ea(file, irf, dir)
520 518  
521 519 # Create point spread function
522   - self._root2psf(file, irf)
  520 + self._root2psf(file, irf, dir)
523 521  
524 522 # Create energy dispersion
525   - self._root2edisp(file, irf)
  523 + self._root2edisp(file, irf, dir)
526 524  
527 525 # Create background
528   - self._root2bgd(file, irf)
  526 + self._root2bgd(file, irf, dir)
529 527  
530 528 # Return
531 529 return
532 530  
533   - def _root2ea(self, file, irf):
  531 + def _root2ea(self, file, irf, dir):
534 532 """
535 533 Translate ROOT to CALDB effective area extension
536 534  
... ... @@ -544,6 +542,8 @@ class csroot2caldb(ctools.cscript):
544 542 ROOT file
545 543 irf : dict
546 544 IRF metadata dictionary
  545 + dir : dict
  546 + Directory structure dictionary
547 547 """
548 548 # Write header
549 549 if self._logTerse():
... ... @@ -594,24 +594,24 @@ class csroot2caldb(ctools.cscript):
594 594 ereco.SetBinContent(ieng+1,ioff+1,value)
595 595  
596 596 # Set boundaries (use Ereco boundaries)
597   - bounds = self._make_2D(ereco, self._hdu_ea, None, 'm2')
  597 + bounds = self._make_2D(ereco, dir['HDU_EA'], None, 'm2')
598 598 for b in bounds:
599 599 irf['EA_BOUNDS'].append(b)
600 600  
601 601 # Write boundary keywords
602   - self._set_cif_keywords(self._hdu_ea, irf['EA_NAME'],
  602 + self._set_cif_keywords(dir['HDU_EA'], irf['EA_NAME'],
603 603 irf['EA_BOUNDS'], irf['EA_DESC'], irf)
604 604  
605 605 # Create "EFFAREA" data column
606   - self._make_2D(etrue, self._hdu_ea, 'EFFAREA', 'm2')
  606 + self._make_2D(etrue, dir['HDU_EA'], 'EFFAREA', 'm2')
607 607  
608 608 # Create "EFFAREA_RECO" data column
609   - self._make_2D(ereco, self._hdu_ea, 'EFFAREA_RECO', 'm2')
  609 + self._make_2D(ereco, dir['HDU_EA'], 'EFFAREA_RECO', 'm2')
610 610  
611 611 # Return
612 612 return
613 613  
614   - def _root2psf(self, file, irf):
  614 + def _root2psf(self, file, irf, dir):
615 615 """
616 616 Translate ROOT to CALDB point spread function extension
617 617  
... ... @@ -621,6 +621,8 @@ class csroot2caldb(ctools.cscript):
621 621 ROOT file
622 622 irf : dict
623 623 IRF metadata dictionary
  624 + dir : dict
  625 + Directory structure dictionary
624 626 """
625 627 # Write header
626 628 if self._logTerse():
... ... @@ -629,16 +631,16 @@ class csroot2caldb(ctools.cscript):
629 631  
630 632 # King profile PSF
631 633 if self['psftype'].string() == 'King':
632   - self._root2psf_king(file, irf)
  634 + self._root2psf_king(file, irf, dir)
633 635  
634 636 # ... otherwise use Gaussian profile PSF
635 637 else:
636   - self._root2psf_gauss(file, irf)
  638 + self._root2psf_gauss(file, irf, dir)
637 639  
638 640 # Return
639 641 return
640 642  
641   - def _root2psf_gauss(self, file, irf):
  643 + def _root2psf_gauss(self, file, irf, dir):
642 644 """
643 645 Translate ROOT to CALDB point spread function extension
644 646  
... ... @@ -656,6 +658,8 @@ class csroot2caldb(ctools.cscript):
656 658 ROOT file
657 659 irf : dict
658 660 IRF metadata dictionary
  661 + dir : dict
  662 + Directory structure dictionary
659 663 """
660 664 # Get relevant ROOT histograms
661 665 r68 = file.Get('AngRes_offaxis')
... ... @@ -689,37 +693,37 @@ class csroot2caldb(ctools.cscript):
689 693 zero.SetBinContent(ieng+1,ioff+1,0.0)
690 694  
691 695 # Set boundaries
692   - bounds = self._make_2D(r68, self._hdu_psf, None, 'deg')
  696 + bounds = self._make_2D(r68, dir['HDU_PSF'], None, 'deg')
693 697 for b in bounds:
694 698 irf['PSF_BOUNDS'].append(b)
695 699 irf['PSF_BOUNDS'].append('PSF(GAUSS)')
696 700  
697 701 # Write boundary keywords
698   - self._set_cif_keywords(self._hdu_psf, irf['PSF_NAME'],
  702 + self._set_cif_keywords(dir['HDU_PSF'], irf['PSF_NAME'],
699 703 irf['PSF_BOUNDS'], irf['PSF_DESC'], irf)
700 704  
701 705 # Create "SCALE" data column
702   - self._make_2D(scale, self._hdu_psf, 'SCALE', '')
  706 + self._make_2D(scale, dir['HDU_PSF'], 'SCALE', '')
703 707  
704 708 # Create "SIGMA_1" data column
705   - self._make_2D(r68, self._hdu_psf, 'SIGMA_1', 'deg')
  709 + self._make_2D(r68, dir['HDU_PSF'], 'SIGMA_1', 'deg')
706 710  
707 711 # Create "AMPL_2" data column
708   - self._make_2D(zero, self._hdu_psf, 'AMPL_2', '')
  712 + self._make_2D(zero, dir['HDU_PSF'], 'AMPL_2', '')
709 713  
710 714 # Create "SIGMA_2" data column
711   - self._make_2D(zero, self._hdu_psf, 'SIGMA_2', 'deg')
  715 + self._make_2D(zero, dir['HDU_PSF'], 'SIGMA_2', 'deg')
712 716  
713 717 # Create "AMPL_3" data column
714   - self._make_2D(zero, self._hdu_psf, 'AMPL_3', '')
  718 + self._make_2D(zero, dir['HDU_PSF'], 'AMPL_3', '')
715 719  
716 720 # Create "SIGMA_3" data column
717   - self._make_2D(zero, self._hdu_psf, 'SIGMA_3', 'deg')
  721 + self._make_2D(zero, dir['HDU_PSF'], 'SIGMA_3', 'deg')
718 722  
719 723 # Return
720 724 return
721 725  
722   - def _root2psf_king(self, file, irf):
  726 + def _root2psf_king(self, file, irf, dir):
723 727 """
724 728 Translate ROOT to CALDB point spread function extension
725 729  
... ... @@ -733,6 +737,8 @@ class csroot2caldb(ctools.cscript):
733 737 ROOT file
734 738 irf : dict
735 739 IRF metadata dictionary
  740 + dir : dict
  741 + Directory structure dictionary
736 742 """
737 743 # Get relevant ROOT histograms
738 744 r68 = file.Get('AngRes_offaxis')
... ... @@ -828,25 +834,25 @@ class csroot2caldb(ctools.cscript):
828 834 sigma2D.SetBinContent(ieng+1,ioff+1,sigma)
829 835  
830 836 # Set boundaries
831   - bounds = self._make_2D(r68, self._hdu_psf, None, 'deg')
  837 + bounds = self._make_2D(r68, dir['HDU_PSF'], None, 'deg')
832 838 for b in bounds:
833 839 irf['PSF_BOUNDS'].append(b)
834 840 irf['PSF_BOUNDS'].append('PSF(KING)')
835 841  
836 842 # Write boundary keywords
837   - self._set_cif_keywords(self._hdu_psf, irf['PSF_NAME'],
  843 + self._set_cif_keywords(dir['HDU_PSF'], irf['PSF_NAME'],
838 844 irf['PSF_BOUNDS'], irf['PSF_DESC'], irf)
839 845  
840 846 # Create "GAMMA" data column
841   - self._make_2D(gamma2D, self._hdu_psf, 'GAMMA', '')
  847 + self._make_2D(gamma2D, dir['HDU_PSF'], 'GAMMA', '')
842 848  
843 849 # Create "SIGMA" data column
844   - self._make_2D(sigma2D, self._hdu_psf, 'SIGMA', 'deg')
  850 + self._make_2D(sigma2D, dir['HDU_PSF'], 'SIGMA', 'deg')
845 851  
846 852 # Return
847 853 return
848 854  
849   - def _root2edisp(self, file, irf):
  855 + def _root2edisp(self, file, irf, dir):
850 856 """
851 857 Translate ROOT to CALDB energy dispersion extension
852 858  
... ... @@ -859,6 +865,8 @@ class csroot2caldb(ctools.cscript):
859 865 ROOT file
860 866 irf : dict
861 867 IRF metadata dictionary
  868 + dir : dict
  869 + Directory structure dictionary
862 870 """
863 871 # Write header
864 872 if self._logTerse():
... ... @@ -869,21 +877,21 @@ class csroot2caldb(ctools.cscript):
869 877 matrix = file.Get('EestOverEtrue_offaxis')
870 878  
871 879 # Set boundaries
872   - bounds = self._make_3D_migra(matrix, self._hdu_edisp, None, '')
  880 + bounds = self._make_3D_migra(matrix, dir['HDU_EDISP'], None, '')
873 881 for b in bounds:
874 882 irf['EDISP_BOUNDS'].append(b)
875 883  
876 884 # Write boundary keywords
877   - self._set_cif_keywords(self._hdu_edisp, irf['EDISP_NAME'],
  885 + self._set_cif_keywords(dir['HDU_EDISP'], irf['EDISP_NAME'],
878 886 irf['EDISP_BOUNDS'], irf['EDISP_DESC'], irf)
879 887  
880 888 # Create "MATRIX" data column
881   - self._make_3D_migra(matrix, self._hdu_edisp, 'MATRIX', '')
  889 + self._make_3D_migra(matrix, dir['HDU_EDISP'], 'MATRIX', '')
882 890  
883 891 # Return
884 892 return
885 893  
886   - def _root2bgd(self, file, irf):
  894 + def _root2bgd(self, file, irf, dir):
887 895 """
888 896 Translate ROOT to CALDB background extension.
889 897  
... ... @@ -896,6 +904,8 @@ class csroot2caldb(ctools.cscript):
896 904 ROOT file
897 905 irf : dict
898 906 IRF metadata dictionary
  907 + dir : dict
  908 + Directory structure dictionary
899 909 """
900 910 # Write header
901 911 if self._logTerse():
... ... @@ -920,16 +930,16 @@ class csroot2caldb(ctools.cscript):
920 930 self._renorm_onaxis(array, array_1D)
921 931  
922 932 # Set boundaries
923   - bounds = self._make_3D(array, self._hdu_bgd, None, 'deg')
  933 + bounds = self._make_3D(array, dir['HDU_BGD'], None, 'deg')
924 934 for b in bounds:
925 935 irf['BGD_BOUNDS'].append(b)
926 936  
927 937 # Write boundary keywords
928   - self._set_cif_keywords(self._hdu_bgd, irf['BGD_NAME'],
  938 + self._set_cif_keywords(dir['HDU_BGD'], irf['BGD_NAME'],
929 939 irf['BGD_BOUNDS'], irf['BGD_DESC'], irf)
930 940  
931 941 # Create "BGD" data column
932   - self._make_3D(array, self._hdu_bgd, 'BGD', '1/s/MeV/sr')
  942 + self._make_3D(array, dir['HDU_BGD'], 'BGD', '1/s/MeV/sr')
933 943  
934 944 # Return
935 945 return
... ... @@ -1547,7 +1557,7 @@ class csroot2caldb(ctools.cscript):
1547 1557  
1548 1558 # Translate ROOT to CALDB information
1549 1559 if _has_root:
1550   - self._root2caldb(irf)
  1560 + self._root2caldb(irf, dir)
1551 1561  
1552 1562 # Close calibration files
1553 1563 self._close(irf, dir)
... ...