Commit fa8e11ff816e03e3437a2d41d8f66f7687525f9c
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.
Showing
3 changed files
with
47 additions
and
32 deletions
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 | \ No newline at end of file | 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 | \ No newline at end of file | 3 | \ No newline at end of file |
scripts/csresmap.py
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | # Residual map generation script. | 3 | # Residual map generation script. |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2014 Michael Mayer | 5 | +# Copyright (C) 2014-2015 Michael Mayer |
| 6 | # | 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -18,8 +18,8 @@ | @@ -18,8 +18,8 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import ctools | ||
| 22 | import gammalib | 21 | import gammalib |
| 22 | +import ctools | ||
| 23 | import sys | 23 | import sys |
| 24 | import os | 24 | import os |
| 25 | 25 | ||
| @@ -39,7 +39,7 @@ class csresmap(gammalib.GApplication): | @@ -39,7 +39,7 @@ class csresmap(gammalib.GApplication): | ||
| 39 | """ | 39 | """ |
| 40 | # Set name | 40 | # Set name |
| 41 | self.name = "csresmap" | 41 | self.name = "csresmap" |
| 42 | - self.version = "0.2.0" | 42 | + self.version = "1.0.0" |
| 43 | 43 | ||
| 44 | # Initialise some members | 44 | # Initialise some members |
| 45 | self.obs = None | 45 | self.obs = None |
| @@ -100,11 +100,11 @@ class csresmap(gammalib.GApplication): | @@ -100,11 +100,11 @@ class csresmap(gammalib.GApplication): | ||
| 100 | 100 | ||
| 101 | # Create default parfile | 101 | # Create default parfile |
| 102 | pars = gammalib.GApplicationPars() | 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 | pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database")) | 108 | pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database")) |
| 109 | pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) | 109 | pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) |
| 110 | pars.append(gammalib.GApplicationPar("emin","r","h","0.1","0.0","","Lower energy limit (TeV)")) | 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,13 +112,13 @@ class csresmap(gammalib.GApplication): | ||
| 112 | pars.append(gammalib.GApplicationPar("enumbins","i","h","20","","","Number of energy bins")) | 112 | pars.append(gammalib.GApplicationPar("enumbins","i","h","20","","","Number of energy bins")) |
| 113 | pars.append(gammalib.GApplicationPar("ebinalg","s","h","LOG","LIN|LOG|FILE","","Binning algorithm")) | 113 | pars.append(gammalib.GApplicationPar("ebinalg","s","h","LOG","LIN|LOG|FILE","","Binning algorithm")) |
| 114 | pars.append(gammalib.GApplicationPar("coordsys","s","a","CEL","CEL|GAL","","Coordinate System")) | 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 | pars.append(gammalib.GApplicationPar("yref","r","a","22.01","","","Second coordinate of image center in degrees (DEC or galactic b)")) | 117 | pars.append(gammalib.GApplicationPar("yref","r","a","22.01","","","Second coordinate of image center in degrees (DEC or galactic b)")) |
| 118 | pars.append(gammalib.GApplicationPar("nxpix","i","h","200","","","Size of the X axis in pixels")) | 118 | pars.append(gammalib.GApplicationPar("nxpix","i","h","200","","","Size of the X axis in pixels")) |
| 119 | pars.append(gammalib.GApplicationPar("nypix","i","h","200","","","Size of the Y axis in pixels")) | 119 | pars.append(gammalib.GApplicationPar("nypix","i","h","200","","","Size of the Y axis in pixels")) |
| 120 | pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size (deg/pixel)")) | 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 | pars.append_standard() | 122 | pars.append_standard() |
| 123 | pars.save(parfile) | 123 | pars.save(parfile) |
| 124 | 124 | ||
| @@ -133,27 +133,39 @@ class csresmap(gammalib.GApplication): | @@ -133,27 +133,39 @@ class csresmap(gammalib.GApplication): | ||
| 133 | 133 | ||
| 134 | # Set observation if not done before | 134 | # Set observation if not done before |
| 135 | if self.obs.size() == 0: | 135 | if self.obs.size() == 0: |
| 136 | - | 136 | + |
| 137 | + # Get observation filename | ||
| 137 | obsfile = self["inobs"].filename() | 138 | obsfile = self["inobs"].filename() |
| 139 | + | ||
| 140 | + # Setup observation | ||
| 138 | try: | 141 | try: |
| 139 | - | ||
| 140 | self.obs = gammalib.GObservations(obsfile) | 142 | self.obs = gammalib.GObservations(obsfile) |
| 141 | except: | 143 | except: |
| 142 | self.obs.clear() | 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 | self.m_caldb = self["caldb"].string() | 147 | self.m_caldb = self["caldb"].string() |
| 148 | - | ||
| 149 | - caldb = gammalib.GCaldb() | 148 | + self.m_irf = self["irf"].string() |
| 149 | + caldb = gammalib.GCaldb() | ||
| 150 | if os.path.isdir(self.m_caldb): | 150 | if os.path.isdir(self.m_caldb): |
| 151 | caldb.rootdir(self.m_caldb) | 151 | caldb.rootdir(self.m_caldb) |
| 152 | else: | 152 | else: |
| 153 | caldb.open("cta",self. m_caldb) | 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 | # Check for models in the container | 170 | # Check for models in the container |
| 159 | # read models from file if there were none | 171 | # read models from file if there were none |
| @@ -162,8 +174,8 @@ class csresmap(gammalib.GApplication): | @@ -162,8 +174,8 @@ class csresmap(gammalib.GApplication): | ||
| 162 | if self.obs.models().size() == 0: | 174 | if self.obs.models().size() == 0: |
| 163 | self.obs.models(self["inmodel"].filename()) | 175 | self.obs.models(self["inmodel"].filename()) |
| 164 | self.m_outfile = self["outmap"].filename() | 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 | self.m_xref = self["xref"].real() | 179 | self.m_xref = self["xref"].real() |
| 168 | self.m_yref = self["yref"].real() | 180 | self.m_yref = self["yref"].real() |
| 169 | self.m_emin = self["emin"].real() | 181 | self.m_emin = self["emin"].real() |
| @@ -178,9 +190,10 @@ class csresmap(gammalib.GApplication): | @@ -178,9 +190,10 @@ class csresmap(gammalib.GApplication): | ||
| 178 | self.m_algorithm = self["algorithm"].string() | 190 | self.m_algorithm = self["algorithm"].string() |
| 179 | 191 | ||
| 180 | # Set some fixed parameters | 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 | self.m_clobber = self["clobber"].boolean() | 195 | self.m_clobber = self["clobber"].boolean() |
| 196 | + self.m_debug = self["debug"].boolean() | ||
| 184 | 197 | ||
| 185 | # Return | 198 | # Return |
| 186 | return | 199 | return |
| @@ -234,11 +247,10 @@ class csresmap(gammalib.GApplication): | @@ -234,11 +247,10 @@ class csresmap(gammalib.GApplication): | ||
| 234 | # Write header | 247 | # Write header |
| 235 | if self.logTerse(): | 248 | if self.logTerse(): |
| 236 | self.log("\n") | 249 | self.log("\n") |
| 237 | - self.log.header1("Generate binned map") | 250 | + self.log.header1("Generate binned map (ctbin)") |
| 238 | 251 | ||
| 239 | # Create countsmap | 252 | # Create countsmap |
| 240 | bin = ctools.ctbin(self.obs) | 253 | bin = ctools.ctbin(self.obs) |
| 241 | - bin["debug"].boolean(True) | ||
| 242 | bin["nxpix"].integer(self.m_nxpix) | 254 | bin["nxpix"].integer(self.m_nxpix) |
| 243 | bin["nypix"].integer(self.m_nypix) | 255 | bin["nypix"].integer(self.m_nypix) |
| 244 | bin["proj"].string(self.m_proj) | 256 | bin["proj"].string(self.m_proj) |
| @@ -250,7 +262,9 @@ class csresmap(gammalib.GApplication): | @@ -250,7 +262,9 @@ class csresmap(gammalib.GApplication): | ||
| 250 | bin["emin"].real(self.m_emin) | 262 | bin["emin"].real(self.m_emin) |
| 251 | bin["emax"].real(self.m_emax) | 263 | bin["emax"].real(self.m_emax) |
| 252 | bin["binsz"].real(self.m_binsz) | 264 | bin["binsz"].real(self.m_binsz) |
| 265 | + bin["chatter"].integer(self.m_chatter) | ||
| 253 | bin["clobber"].boolean(self.m_clobber) | 266 | bin["clobber"].boolean(self.m_clobber) |
| 267 | + bin["debug"].boolean(self.m_debug) | ||
| 254 | bin.run() | 268 | bin.run() |
| 255 | 269 | ||
| 256 | # Store counts map as residual map. Note that we need a | 270 | # Store counts map as residual map. Note that we need a |
| @@ -265,13 +279,14 @@ class csresmap(gammalib.GApplication): | @@ -265,13 +279,14 @@ class csresmap(gammalib.GApplication): | ||
| 265 | # Write header | 279 | # Write header |
| 266 | if self.logTerse(): | 280 | if self.logTerse(): |
| 267 | self.log("\n") | 281 | self.log("\n") |
| 268 | - self.log.header1("Generate model map") | ||
| 269 | - | 282 | + self.log.header1("Generate model map (ctmodel)") |
| 283 | + | ||
| 270 | # Create model map | 284 | # Create model map |
| 271 | model = ctools.ctmodel(self.obs) | 285 | model = ctools.ctmodel(self.obs) |
| 272 | - model["debug"].boolean(True) | ||
| 273 | model.cube(bin.cube()) | 286 | model.cube(bin.cube()) |
| 287 | + model["chatter"].integer(self.m_chatter) | ||
| 274 | model["clobber"].boolean(self.m_clobber) | 288 | model["clobber"].boolean(self.m_clobber) |
| 289 | + model["debug"].boolean(self.m_debug) | ||
| 275 | model.run() | 290 | model.run() |
| 276 | 291 | ||
| 277 | # Get model map into GSkymap object | 292 | # Get model map into GSkymap object |
src/ctmodel/ctmodel.par
| @@ -24,7 +24,7 @@ edisp, b, h, no,,, "Apply energy dispersion?" | @@ -24,7 +24,7 @@ edisp, b, h, no,,, "Apply energy dispersion?" | ||
| 24 | # | 24 | # |
| 25 | # Observation parameters | 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 | expcube, f, a, NONE,,, "Exposure cube file (only needed for stacked analysis)" | 28 | expcube, f, a, NONE,,, "Exposure cube file (only needed for stacked analysis)" |
| 29 | psfcube, f, a, NONE,,, "PSF cube file (only needed for stacked analysis)" | 29 | psfcube, f, a, NONE,,, "PSF cube file (only needed for stacked analysis)" |
| 30 | caldb, s, a, "dummy",,, "Calibration database" | 30 | caldb, s, a, "dummy",,, "Calibration database" |