Commit fa8e11ff816e03e3437a2d41d8f66f7687525f9c

Authored by Jürgen Knödlseder
1 parent e5588dc2

Correct gammalib and ctools module import order (gammalib has to come first). Re…

…vise csresmap parameters and attach response to observation if needed.
doc/source/reference_manual/csresmap.rst
1   -.. _csresmap: csresmap ======== Generates residual counts map. Synopsis -------- This scripts generates a residual counts map. General parameters ------------------ ``inobs = obs.mlx [file]`` Input event list, cube or observation definition XML file. ``inmodel = crab.xml [file]`` Model XML file. ``outmap = resmap.fits [file]`` Output residual counts map file. ``binfile = binned.fits [file]`` Output binned file name (not used). ``modfile = model.fits [file]`` Output model file name (not used). ``caldb = dummy [string]`` Calibration database. ``irf = cta_dummy_irf [string]`` Response function. ``ebinalg = LOG <FILE|LIN|LOG> [string]`` Algorithm for defining energy bins. ``emin = 0.1 [double]`` Lower energy value for first energy bin (in TeV). ``emax = 100.0 [double]`` Upper energy value for last energy bin (in TeV). ``enumbins =20 [integer]`` Number of energy bins. ``ebinfile = NONE [file]`` Name of the file containing the energy bin definition. ``nxpix = 200 [integer]`` Number of cube bins in Right Ascension or Galactic longitude. ``nypix = 200 [integer]`` Number of cube bins in Declination or Galactic latitude. ``binsz = 0.02 [double]`` Cube bin size (in degrees/pixel). ``coordsys = CEL <CEL|GAL> [string]`` Coordinate system (CEL - celestial, GAL - galactic). ``xref = 83.63 [double]`` Right Ascension / Galactic longitude of cube centre (J2000, in degrees). ``yref = 22.01 [double]`` Declination / Galactic latitude of cube centre (J2000, in degrees). ``proj = CAR <AIT|AZP|CAR|MER|MOL|STG|TAN> [string]`` Projection method. ``algorithm = SUBDIV <SUB|SUBDIV|SUBDIVSQRT> [string]`` Algorithm used to generate the residual map. Standard parameters ------------------- ``(chatter = 2) [integer]`` Verbosity of the executable: chatter = 0: no information will be logged chatter = 1: only errors will be logged chatter = 2: errors and actions will be logged chatter = 3: report about the task execution chatter = 4: detailed report about the task execution ``(clobber = yes) [boolean]`` Specifies whether an existing output counts cube should be overwritten. ``(debug = no) [boolean]`` Enables debug mode. In debug mode the executable will dump any log file output to the console. ``(mode = ql) [string]`` Mode of automatic parameters (default is "ql", i.e. "query and learn"). Related tools ------------- None
2 1 \ No newline at end of file
  2 +.. _csresmap: csresmap ======== Generates residual counts map. Synopsis -------- This scripts generates a residual counts map. General parameters ------------------ ``inobs = obs.mlx [file]`` Input event list, counts cube or observation definition XML file. ``inmodel = crab.xml [file]`` Model XML file. ``outmap = resmap.fits [file]`` Output residual counts map file. ``caldb = dummy [string]`` Calibration database. ``irf = cta_dummy_irf [string]`` Instrument response function. ``ebinalg = LOG <FILE|LIN|LOG> [string]`` Algorithm for defining energy bins. ``emin = 0.1 [double]`` Lower energy value for first energy bin (in TeV). ``emax = 100.0 [double]`` Upper energy value for last energy bin (in TeV). ``enumbins =20 [integer]`` Number of energy bins. ``ebinfile = NONE [file]`` Name of the file containing the energy bin definition. ``nxpix = 200 [integer]`` Number of cube bins in Right Ascension or Galactic longitude. ``nypix = 200 [integer]`` Number of cube bins in Declination or Galactic latitude. ``binsz = 0.02 [double]`` Cube bin size (in degrees/pixel). ``coordsys = CEL <CEL|GAL> [string]`` Coordinate system (CEL - celestial, GAL - galactic). ``xref = 83.63 [double]`` Right Ascension / Galactic longitude of cube centre (J2000, in degrees). ``yref = 22.01 [double]`` Declination / Galactic latitude of cube centre (J2000, in degrees). ``proj = CAR <AIT|AZP|CAR|MER|MOL|STG|TAN> [string]`` Projection method. ``algorithm = SUBDIV <SUB|SUBDIV|SUBDIVSQRT> [string]`` Algorithm used to generate the residual map. Standard parameters ------------------- ``(chatter = 2) [integer]`` Verbosity of the executable: chatter = 0: no information will be logged chatter = 1: only errors will be logged chatter = 2: errors and actions will be logged chatter = 3: report about the task execution chatter = 4: detailed report about the task execution ``(clobber = yes) [boolean]`` Specifies whether an existing output counts cube should be overwritten. ``(debug = no) [boolean]`` Enables debug mode. In debug mode the executable will dump any log file output to the console. ``(mode = ql) [string]`` Mode of automatic parameters (default is "ql", i.e. "query and learn"). Related tools ------------- None
3 3 \ No newline at end of file
... ...
scripts/csresmap.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Residual map generation script.
4 4 #
5   -# Copyright (C) 2014 Michael Mayer
  5 +# Copyright (C) 2014-2015 Michael Mayer
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -18,8 +18,8 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -import ctools
22 21 import gammalib
  22 +import ctools
23 23 import sys
24 24 import os
25 25  
... ... @@ -39,7 +39,7 @@ class csresmap(gammalib.GApplication):
39 39 """
40 40 # Set name
41 41 self.name = "csresmap"
42   - self.version = "0.2.0"
  42 + self.version = "1.0.0"
43 43  
44 44 # Initialise some members
45 45 self.obs = None
... ... @@ -100,11 +100,11 @@ class csresmap(gammalib.GApplication):
100 100  
101 101 # Create default parfile
102 102 pars = gammalib.GApplicationPars()
103   - pars.append(gammalib.GApplicationPar("inobs","f","a","obs.xml","","","Observation definition"))
104   - pars.append(gammalib.GApplicationPar("inmodel","f","a","crab.xml","","","Model file name"))
105   - pars.append(gammalib.GApplicationPar("outmap","f","a","resmap.fits","","","Output file name"))
106   - pars.append(gammalib.GApplicationPar("binfile","f","h","binned.fits","","","Output binned file name"))
107   - pars.append(gammalib.GApplicationPar("modfile","f","h","model.fits","","","Output model file name"))
  103 + pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Event list, counts cube, or observation definition file"))
  104 + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model"))
  105 + pars.append(gammalib.GApplicationPar("outmap","f","a","resmap.fits","","","Output residual map"))
  106 + #pars.append(gammalib.GApplicationPar("binfile","f","h","binned.fits","","","Output binned file name"))
  107 + #pars.append(gammalib.GApplicationPar("modfile","f","h","model.fits","","","Output model file name"))
108 108 pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database"))
109 109 pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
110 110 pars.append(gammalib.GApplicationPar("emin","r","h","0.1","0.0","","Lower energy limit (TeV)"))
... ... @@ -112,13 +112,13 @@ class csresmap(gammalib.GApplication):
112 112 pars.append(gammalib.GApplicationPar("enumbins","i","h","20","","","Number of energy bins"))
113 113 pars.append(gammalib.GApplicationPar("ebinalg","s","h","LOG","LIN|LOG|FILE","","Binning algorithm"))
114 114 pars.append(gammalib.GApplicationPar("coordsys","s","a","CEL","CEL|GAL","","Coordinate System"))
115   - pars.append(gammalib.GApplicationPar("proj","s","a","TAN","AIT|AZP|CAR|MER|STG|TAN","","Projection method e.g. AIT|AZP|CAR|MER|STG|TAN"))
116   - pars.append(gammalib.GApplicationPar("xref","r","a","83.6331","","","First coordinate of image center in degrees (RA or galactic l)"))
  115 + pars.append(gammalib.GApplicationPar("proj","s","a","CAR","AIT|AZP|CAR|MER|MOL|STG|TAN","","Projection method e.g. AIT|AZP|CAR|MER|MOL|STG|TAN"))
  116 + pars.append(gammalib.GApplicationPar("xref","r","a","83.63","","","First coordinate of image center in degrees (RA or galactic l)"))
117 117 pars.append(gammalib.GApplicationPar("yref","r","a","22.01","","","Second coordinate of image center in degrees (DEC or galactic b)"))
118 118 pars.append(gammalib.GApplicationPar("nxpix","i","h","200","","","Size of the X axis in pixels"))
119 119 pars.append(gammalib.GApplicationPar("nypix","i","h","200","","","Size of the Y axis in pixels"))
120 120 pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size (deg/pixel)"))
121   - pars.append(gammalib.GApplicationPar("algorithm","s","h","SUBDIV","SUB|SUBDIV|SUBDIVSQRT","","Residualmap algorithm"))
  121 + pars.append(gammalib.GApplicationPar("algorithm","s","h","SUBDIV","SUB|SUBDIV|SUBDIVSQRT","","Residual map computation algorithm"))
122 122 pars.append_standard()
123 123 pars.save(parfile)
124 124  
... ... @@ -133,27 +133,39 @@ class csresmap(gammalib.GApplication):
133 133  
134 134 # Set observation if not done before
135 135 if self.obs.size() == 0:
136   -
  136 +
  137 + # Get observation filename
137 138 obsfile = self["inobs"].filename()
  139 +
  140 + # Setup observation
138 141 try:
139   -
140 142 self.obs = gammalib.GObservations(obsfile)
141 143 except:
142 144 self.obs.clear()
143   - observation = gammalib.GCTAObservation()
144   - observation.load(obsfile)
145   -
146   - self.m_irf = self["irf"].string()
  145 + obs = gammalib.GCTAObservation()
  146 + obs.load(obsfile)
147 147 self.m_caldb = self["caldb"].string()
148   -
149   - caldb = gammalib.GCaldb()
  148 + self.m_irf = self["irf"].string()
  149 + caldb = gammalib.GCaldb()
150 150 if os.path.isdir(self.m_caldb):
151 151 caldb.rootdir(self.m_caldb)
152 152 else:
153 153 caldb.open("cta",self. m_caldb)
  154 + obs.response(self.m_irf, caldb);
  155 + self.obs.append(obs)
154 156  
155   - observation.response(self.m_irf, caldb);
156   - self.obs.append(observation)
  157 + # Make sure that all observations contain a valid response
  158 + # function
  159 + for obs in self.obs:
  160 + if not obs.has_response():
  161 + self.m_caldb = self["caldb"].string()
  162 + self.m_irf = self["irf"].string()
  163 + caldb = gammalib.GCaldb()
  164 + if os.path.isdir(self.m_caldb):
  165 + caldb.rootdir(self.m_caldb)
  166 + else:
  167 + caldb.open("cta",self. m_caldb)
  168 + obs.response(self.m_irf, caldb);
157 169  
158 170 # Check for models in the container
159 171 # read models from file if there were none
... ... @@ -162,8 +174,8 @@ class csresmap(gammalib.GApplication):
162 174 if self.obs.models().size() == 0:
163 175 self.obs.models(self["inmodel"].filename())
164 176 self.m_outfile = self["outmap"].filename()
165   - self.m_modfile = self["modfile"].filename()
166   - self.m_binfile = self["binfile"].filename()
  177 + #self.m_modfile = self["modfile"].filename()
  178 + #self.m_binfile = self["binfile"].filename()
167 179 self.m_xref = self["xref"].real()
168 180 self.m_yref = self["yref"].real()
169 181 self.m_emin = self["emin"].real()
... ... @@ -178,9 +190,10 @@ class csresmap(gammalib.GApplication):
178 190 self.m_algorithm = self["algorithm"].string()
179 191  
180 192 # Set some fixed parameters
181   - self.m_log = False # Logging in client tools
182   - self.m_debug = False # Debugging in client tools
  193 + self.m_log = False # Logging in client tools
  194 + self.m_chatter = self["chatter"].integer()
183 195 self.m_clobber = self["clobber"].boolean()
  196 + self.m_debug = self["debug"].boolean()
184 197  
185 198 # Return
186 199 return
... ... @@ -234,11 +247,10 @@ class csresmap(gammalib.GApplication):
234 247 # Write header
235 248 if self.logTerse():
236 249 self.log("\n")
237   - self.log.header1("Generate binned map")
  250 + self.log.header1("Generate binned map (ctbin)")
238 251  
239 252 # Create countsmap
240 253 bin = ctools.ctbin(self.obs)
241   - bin["debug"].boolean(True)
242 254 bin["nxpix"].integer(self.m_nxpix)
243 255 bin["nypix"].integer(self.m_nypix)
244 256 bin["proj"].string(self.m_proj)
... ... @@ -250,7 +262,9 @@ class csresmap(gammalib.GApplication):
250 262 bin["emin"].real(self.m_emin)
251 263 bin["emax"].real(self.m_emax)
252 264 bin["binsz"].real(self.m_binsz)
  265 + bin["chatter"].integer(self.m_chatter)
253 266 bin["clobber"].boolean(self.m_clobber)
  267 + bin["debug"].boolean(self.m_debug)
254 268 bin.run()
255 269  
256 270 # Store counts map as residual map. Note that we need a
... ... @@ -265,13 +279,14 @@ class csresmap(gammalib.GApplication):
265 279 # Write header
266 280 if self.logTerse():
267 281 self.log("\n")
268   - self.log.header1("Generate model map")
269   -
  282 + self.log.header1("Generate model map (ctmodel)")
  283 +
270 284 # Create model map
271 285 model = ctools.ctmodel(self.obs)
272   - model["debug"].boolean(True)
273 286 model.cube(bin.cube())
  287 + model["chatter"].integer(self.m_chatter)
274 288 model["clobber"].boolean(self.m_clobber)
  289 + model["debug"].boolean(self.m_debug)
275 290 model.run()
276 291  
277 292 # Get model map into GSkymap object
... ...
src/ctmodel/ctmodel.par
... ... @@ -24,7 +24,7 @@ edisp, b, h, no,,, &quot;Apply energy dispersion?&quot;
24 24 #
25 25 # Observation parameters
26 26 #=======================
27   -inobs, f, a, "NONE",,, "Input event list, counts cube or observation definition file"
  27 +inobs, f, a, "NONE",,, "Event list, counts cube or observation definition file"
28 28 expcube, f, a, NONE,,, "Exposure cube file (only needed for stacked analysis)"
29 29 psfcube, f, a, NONE,,, "PSF cube file (only needed for stacked analysis)"
30 30 caldb, s, a, "dummy",,, "Calibration database"
... ...