Commit c64145b5455c551720e5cf9a0265508ae5540a0e

Authored by Luigi Tibaldo
1 parent 34404766

cleaned up header keywords assignment and added more keywords

Showing 1 changed file with 45 additions and 15 deletions
cscripts/csscs.py
... ... @@ -601,6 +601,47 @@ class csscs(ctools.csobservation):
601 601 # Return result
602 602 return result
603 603  
  604 + def _write_hdu_keywords(self,hdu, is_flux = False):
  605 + """
  606 + Append cards to HDU
  607 +
  608 + Parameters
  609 + ----------
  610 + hdu : `dict` HDU
  611 + """
  612 +
  613 + # Flux units
  614 + if is_flux:
  615 + hdu.card('BUNIT', 'ph/cm2/s/sr' , 'Photon flux')
  616 +
  617 + # Minimum and maximum energy
  618 + hdu.card("E_MIN", self['emin'].real(), "[TeV] Lower energy boundary")
  619 + hdu.card("E_MAX", self['emax'].real(), "[TeV] Upper energy boundary")
  620 + hdu.card("EUNIT", "TeV", "Units for E_MIN and E_MAX")
  621 +
  622 + # ROI size
  623 + hdu.card('ROISZ', self['rad'].real() ,
  624 + '[deg] Size of ROI used for component separation')
  625 +
  626 + # Analysis method
  627 + hdu.card('METHOD',self._method, 'Analysis method')
  628 +
  629 + # For On/Off log information
  630 + if self._method == 'ONOFF':
  631 +
  632 + # Exclusion map
  633 + if (self._excl_reg_map is not None) and self['inexclusion'].is_valid():
  634 + hdu.card("EXCLMAP", self['inexclusion'].filename().url(), "Exclusion map name")
  635 +
  636 + # Model background?
  637 + hdu.card("BKGMODEL", self['use_model_bkg'].boolean(),'Use background model?')
  638 +
  639 + # Fit statistic
  640 + hdu.card("STAT", self['statistic'].string(),'Fit statistic')
  641 +
  642 + return
  643 +
  644 +
604 645 def _fill_fits(self,results):
605 646 """
606 647 Fill FITS object to store the results
... ... @@ -620,12 +661,6 @@ class csscs(ctools.csobservation):
620 661 # Append empty primary HDU
621 662 fits.append(gammalib.GFitsImageDouble())
622 663  
623   - # Prepare some header cards
624   - # Flux units
625   - fcard = gammalib.GFitsHeaderCard('BUNIT', 'ph/cm2/s/sr' , 'Photon flux')
626   - txt = 'Correlation radius %f deg' %(self['rad'].real())
627   - roiszcard = gammalib.GFitsHeaderCard('COMMENT', '' , txt)
628   -
629 664 # Loop over target sources
630 665 for s, name in enumerate(self._srcnames):
631 666  
... ... @@ -648,24 +683,19 @@ class csscs(ctools.csobservation):
648 683  
649 684 # Write maps to Fits
650 685 fhdu = fmap.write(fits, name + ' FLUX')
  686 + self._write_hdu_keywords(fhdu,is_flux=True)
651 687 errhdu = errmap.write(fits, name + ' FLUX ERROR')
652   -
653   - # Add units and comments to headers
654   - fhdu.header().append(fcard)
655   - errhdu.header().append(fcard)
656   - fhdu.header().append(roiszcard)
657   - errhdu.header().append(roiszcard)
  688 + self._write_hdu_keywords(errhdu, is_flux=True)
658 689  
659 690 # If requested write TS map to fits
660 691 if self['calc_ts'].boolean():
661 692 tshdu = tsmap.write(fits, name + ' TS')
662   - tshdu.header().append(roiszcard)
  693 + self._write_hdu_keywords(tshdu)
663 694  
664 695 # If requested write upper limit map to fits
665 696 if self['calc_ulim'].boolean():
666 697 ulhdu = ulmap.write(fits, name + ' FLUX UPPER LIMIT')
667   - ulhdu.header().append(fcard)
668   - ulhdu.header().append(roiszcard)
  698 + self._write_hdu_keywords(ulhdu, is_flux=True)
669 699  
670 700 # Return
671 701 return fits
... ...