Commit 9644a9597f2ea6d00beba9750c7b6b80eab3ab11

Authored by Luigi Tibaldo
1 parent c090b915

added method to generate onoff observations

Showing 1 changed file with 53 additions and 0 deletions
cscripts/obsutils.py
... ... @@ -760,3 +760,56 @@ def get_stacked_obs(cls, obs):
760 760  
761 761 # Return new oberservation container
762 762 return new_obs
  763 +
  764 +# ================================= #
  765 +# Get On/Off observation container #
  766 +# ================================= #
  767 +def get_onoff_obs(cls, obs):
  768 + """
  769 + Create On/Off observations container from given observations
  770 +
  771 + Parameters
  772 + ----------
  773 + cls : `~ctools.cscript`
  774 + cscript class
  775 + obs : `~gammalib.GObservations`
  776 + Observation container
  777 +
  778 + Returns
  779 + -------
  780 + onoff_obs : `~gammalib.GObservations`
  781 + Observation container with On/Off observations
  782 + """
  783 + # Write header
  784 + if cls._logExplicit():
  785 + cls._log.header3('Creating On/Off observations')
  786 +
  787 + phagen = cscripts.csphagen(obs)
  788 + phagen['inexclusion'] = cls['inexclusion'].filename()
  789 + phagen['emin'] = cls['emin'].real()
  790 + phagen['emax'] = cls['emax'].real()
  791 + phagen['enumbins'] = cls['enumbins'].integer()
  792 + phagen['ebinalg'] = 'LOG'
  793 + phagen['srcshape'] = cls['srcshape'].string()
  794 + coordsys = cls['coordsys'].string()
  795 + phagen['coordsys'] = coordsys
  796 + if coordsys == 'CEL':
  797 + phagen['ra'] = cls['xref'].real()
  798 + phagen['dec'] = cls['yref'].real()
  799 + elif coordsys == 'GAL':
  800 + phagen['glon'] = cls['xref'].real()
  801 + phagen['glat'] = cls['yref'].real()
  802 + phagen['rad'] = cls['rad'].real()
  803 + bkgmethod = cls['bkgmethod'].string()
  804 + if bkgmethod == 'REFLECTED':
  805 + phagen['bkgregmin'] = cls['bkgregmin'].string()
  806 + phagen['maxoffset'] = cls['maxoffset'].string()
  807 + phagen['stack'] = True
  808 + phagen['emintrue'] = cls['emintrue'].real()
  809 + phagen['emaxtrue'] = cls['emaxtrue'].real()
  810 + phagen['etruebins'] = cls['etruebins'].integer()
  811 + phagen.run()
  812 +
  813 + onoff_obs = phagen.obs().copy()
  814 +
  815 + return onoff_obs
763 816 \ No newline at end of file
... ...