Commit f476909b13f983afceae0619a3f2f89a651cfa66

Authored by Jürgen Knödlseder
1 parent 706e318f

Change logic of csresmap script.

If now a counts cube is provided, the script with first ask for a model cube. If it has the model cube, no response information is needed and the tool directly shows the residual map.
Showing 1 changed file with 27 additions and 18 deletions
scripts/csresmap.py
... ... @@ -42,9 +42,12 @@ class csresmap(ctools.cscript):
42 42 self.version = "1.0.0"
43 43  
44 44 # Initialise some members
45   - self.obs = None
46   - self.algorithm = "SUB"
47   - self.resmap = None
  45 + self.obs = None
  46 + self.algorithm = "SUB"
  47 + self.resmap = None
  48 + self.m_modcube = "None"
  49 + self.m_use_maps = False
  50 + self.m_skip_binning = False
48 51  
49 52 # Initialise some members
50 53 if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations):
... ... @@ -101,8 +104,10 @@ class csresmap(ctools.cscript):
101 104 # Create default parfile
102 105 pars = gammalib.GApplicationPars()
103 106 pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Event list, counts cube, or observation definition file"))
104   - pars.append(gammalib.GApplicationPar("cntcube","f","h","NONE","","","Input model cube (generated with ctmodel)"))
105   - pars.append(gammalib.GApplicationPar("modcube","f","h","NONE","","","Input counts cube (generated with ctbin)"))
  107 + pars.append(gammalib.GApplicationPar("modcube","f","a","NONE","","","Model cube file (generated with ctmodel)"))
  108 + pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Exposure cube file (only needed for stacked analysis)"))
  109 + pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","PSF cube file (only needed for stacked analysis)"))
  110 + pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Background cube file (only needed for stacked analysis)"))
106 111 pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model"))
107 112 pars.append(gammalib.GApplicationPar("outmap","f","a","resmap.fits","","","Output residual map"))
108 113 pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database"))
... ... @@ -131,19 +136,23 @@ class csresmap(ctools.cscript):
131 136 """
132 137 Get parameters from parfile and setup the observation.
133 138 """
134   - # Get parameters
135   -
136 139 # Initialise some flags
137   - self.m_use_maps = False
  140 + self.m_use_maps = False
138 141 self.m_skip_binning = False
139   -
140   - # First check for cntcube and modcube parameters
141   - self.m_cntcube = self["cntcube"].filename()
142   - self.m_modcube = self["modcube"].filename()
143   - if not (self.m_cntcube == "NONE" or self.m_modcube == "NONE"):
144   -
145   - # Signal that we can use the maps directly without ctbin and ctmodel
146   - self.m_use_maps = True
  142 +
  143 + # First check if the inobs parameter is a counts cube
  144 + if self["inobs"].filename() != "NONE":
  145 + if gammalib.is_fits(self["inobs"].filename()):
  146 + cta = gammalib.GCTAObservation()
  147 + cta.load(self["inobs"].filename())
  148 + if self.obs[0].eventtype() == "CountsCube":
  149 + self.m_skip_binning = True
  150 +
  151 + # If we have a counts cube, then ask whether we also have a model
  152 + if self.m_skip_binning:
  153 + self.m_modcube = self["modcube"].filename()
  154 + if self.m_modcube != "NONE":
  155 + self.m_use_maps = True
147 156  
148 157 # If not two maps are given, proceed to set up observation
149 158 if not self.m_use_maps:
... ... @@ -245,8 +254,8 @@ class csresmap(ctools.cscript):
245 254  
246 255 # Use input file directly if given
247 256 if self.m_use_maps:
248   - countmap = gammalib.GSkymap(self["cntcube"].filename())
249   - modelmap = gammalib.GSkymap(self["modcube"].filename())
  257 + countmap = gammalib.GSkymap(self.m_cntcube)
  258 + modelmap = gammalib.GSkymap(self.m_modcube)
250 259  
251 260 else:
252 261  
... ...