Commit 9a18cc98202e205e841285b25d5ebb43df303fd3
Merge branch '1408-adapt-cscripts-to-ctool-base-class' into integration
Conflicts: doc/source/reference_manual/csresmap.rst
Showing
3 changed files
with
186 additions
and
57 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, 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 [real]`` Lower energy value for first energy bin (in TeV). ``emax = 100.0 [real]`` 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 [real]`` Cube bin size (in degrees/pixel). ``coordsys = CEL <CEL|GAL> [string]`` Coordinate system (CEL - celestial, GAL - galactic). ``xref = 83.63 [real]`` Right Ascension / Galactic longitude of cube centre (J2000, in degrees). ``yref = 22.01 [real]`` 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: | |
| 3 | + | |
| 4 | +csresmap | |
| 5 | +======== | |
| 6 | + | |
| 7 | +Generates residual counts map. | |
| 8 | + | |
| 9 | + | |
| 10 | +Synopsis | |
| 11 | +-------- | |
| 12 | + | |
| 13 | +This scripts generates a residual counts map. | |
| 14 | + | |
| 15 | + | |
| 16 | +General parameters | |
| 17 | +------------------ | |
| 18 | + | |
| 19 | +``inobs = obs.xml [file]`` | |
| 20 | + Input event list, counts cube or observation definition XML file. | |
| 21 | + | |
| 22 | +``inmodel = crab.xml [file]`` | |
| 23 | + Model XML file. | |
| 24 | + | |
| 25 | +``outmap = resmap.fits [file]`` | |
| 26 | + Output residual counts map file. | |
| 27 | + | |
| 28 | +``expcube = NONE [file]`` | |
| 29 | + Exposure cube file (only needed for stacked analysis). | |
| 30 | + | |
| 31 | +``psfcube = NONE [file]`` | |
| 32 | + PSF cube file (only needed for stacked analysis). | |
| 33 | + | |
| 34 | +``caldb = dummy [string]`` | |
| 35 | + Calibration database. | |
| 36 | + | |
| 37 | +``irf = cta_dummy_irf [string]`` | |
| 38 | + Instrument response function. | |
| 39 | + | |
| 40 | +``ebinalg = LOG <FILE|LIN|LOG> [string]`` | |
| 41 | + Algorithm for defining energy bins. | |
| 42 | + | |
| 43 | +``emin = 0.1 [double]`` | |
| 44 | + Lower energy value for first energy bin (in TeV). | |
| 45 | + | |
| 46 | +``emax = 100.0 [double]`` | |
| 47 | + Upper energy value for last energy bin (in TeV). | |
| 48 | + | |
| 49 | +``enumbins =20 [integer]`` | |
| 50 | + Number of energy bins. | |
| 51 | + | |
| 52 | +``ebinfile = NONE [file]`` | |
| 53 | + Name of the file containing the energy bin definition. | |
| 54 | + | |
| 55 | +``nxpix = 200 [integer]`` | |
| 56 | + Number of cube bins in Right Ascension or Galactic longitude. | |
| 57 | + | |
| 58 | +``nypix = 200 [integer]`` | |
| 59 | + Number of cube bins in Declination or Galactic latitude. | |
| 60 | + | |
| 61 | +``binsz = 0.02 [double]`` | |
| 62 | + Cube bin size (in degrees/pixel). | |
| 63 | + | |
| 64 | +``coordsys = CEL <CEL|GAL> [string]`` | |
| 65 | + Coordinate system (CEL - celestial, GAL - galactic). | |
| 66 | + | |
| 67 | +``xref = 83.63 [double]`` | |
| 68 | + Right Ascension / Galactic longitude of cube centre (J2000, in degrees). | |
| 69 | + | |
| 70 | +``yref = 22.01 [double]`` | |
| 71 | + Declination / Galactic latitude of cube centre (J2000, in degrees). | |
| 72 | + | |
| 73 | +``proj = CAR <AIT|AZP|CAR|MER|MOL|STG|TAN> [string]`` | |
| 74 | + Projection method. | |
| 75 | + | |
| 76 | +``algorithm = SUBDIV <SUB|SUBDIV|SUBDIVSQRT> [string]`` | |
| 77 | + Algorithm used to generate the residual map. | |
| 78 | + | |
| 79 | + | |
| 80 | +Standard parameters | |
| 81 | +------------------- | |
| 82 | + | |
| 83 | +``(chatter = 2) [integer]`` | |
| 84 | + Verbosity of the executable: | |
| 85 | + chatter = 0: no information will be logged | |
| 86 | + | |
| 87 | + chatter = 1: only errors will be logged | |
| 88 | + | |
| 89 | + chatter = 2: errors and actions will be logged | |
| 90 | + | |
| 91 | + chatter = 3: report about the task execution | |
| 92 | + | |
| 93 | + chatter = 4: detailed report about the task execution | |
| 94 | + | |
| 95 | +``(clobber = yes) [boolean]`` | |
| 96 | + Specifies whether an existing output counts cube should be overwritten. | |
| 97 | + | |
| 98 | +``(debug = no) [boolean]`` | |
| 99 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 100 | + | |
| 101 | +``(mode = ql) [string]`` | |
| 102 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 103 | + | |
| 104 | + | |
| 105 | +Related tools | |
| 106 | +------------- | |
| 107 | + | |
| 108 | +None | ... | ... |
pyext/ctool.i
| ... | ... | @@ -27,8 +27,37 @@ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #define SWIG |
| 29 | 29 | #include "ctool.hpp" |
| 30 | + | |
| 31 | + | |
| 32 | +/***********************************************************************//** | |
| 33 | + * @class cscript | |
| 34 | + * | |
| 35 | + * @brief cscript base class | |
| 36 | + ***************************************************************************/ | |
| 37 | +class cscript : public ctool { | |
| 38 | +public: | |
| 39 | + // Constructors and destructors | |
| 40 | + cscript(void) : ctool() {} | |
| 41 | + cscript(const std::string& name, const std::string& version) : ctool(name, version) {} | |
| 42 | + cscript(const std::string& name, const std::string& version, | |
| 43 | + int argc, char* argv[]) : ctool(name, version, argc, argv) {} | |
| 44 | + cscript(const ctool& app) : ctool(app) {} | |
| 45 | + virtual ~cscript(void) {} | |
| 46 | + | |
| 47 | + // Dummy methods (implementation makes this class non-abstract) | |
| 48 | + virtual void clear(void) { | |
| 49 | + } | |
| 50 | + virtual void run(void) { | |
| 51 | + } | |
| 52 | + virtual void save(void) { | |
| 53 | + } | |
| 54 | +}; | |
| 30 | 55 | %} |
| 31 | 56 | |
| 57 | +// Include (int ARGC, char **ARGV) typemap to allow passing command line | |
| 58 | +// arguments to GApplication constructor | |
| 59 | +%include "argcargv.i" | |
| 60 | + | |
| 32 | 61 | |
| 33 | 62 | /***********************************************************************//** |
| 34 | 63 | * @class ctool |
| ... | ... | @@ -41,10 +70,11 @@ public: |
| 41 | 70 | ctool(void); |
| 42 | 71 | ctool(const std::string& name, const std::string& version); |
| 43 | 72 | ctool(const std::string& name, const std::string& version, |
| 44 | - int argc, char* argv[]); | |
| 73 | + int ARGC, char **ARGV); | |
| 45 | 74 | ctool(const ctool& app); |
| 46 | 75 | virtual ~ctool(void); |
| 47 | 76 | |
| 77 | + | |
| 48 | 78 | // Pure virtual methods |
| 49 | 79 | virtual void clear(void) = 0; |
| 50 | 80 | virtual void run(void) = 0; |
| ... | ... | @@ -75,3 +105,30 @@ public: |
| 75 | 105 | GSkyDir get_mean_pointing(const GObservations& obs); |
| 76 | 106 | size_t get_current_rss(void); |
| 77 | 107 | }; |
| 108 | + | |
| 109 | + | |
| 110 | +/***********************************************************************//** | |
| 111 | + * @class cscript | |
| 112 | + * | |
| 113 | + * @brief cscript base class | |
| 114 | + * | |
| 115 | + * This is the base class from which all cscripts should derive. This | |
| 116 | + * enabled using of ctool base class methods for generic parameter | |
| 117 | + * handling. | |
| 118 | + ***************************************************************************/ | |
| 119 | +class cscript : public ctool { | |
| 120 | +public: | |
| 121 | + // Constructors and destructors | |
| 122 | + cscript(void); | |
| 123 | + cscript(const std::string& name, const std::string& version); | |
| 124 | + cscript(const std::string& name, const std::string& version, | |
| 125 | + int ARGC, char **ARGV); | |
| 126 | + cscript(const ctool& app); | |
| 127 | + virtual ~cscript(void); | |
| 128 | + | |
| 129 | + // Methods | |
| 130 | + virtual void clear(void); | |
| 131 | + virtual void run(void); | |
| 132 | + virtual void save(void); | |
| 133 | +}; | |
| 134 | + | ... | ... |
scripts/csresmap.py
| ... | ... | @@ -21,22 +21,22 @@ |
| 21 | 21 | import gammalib |
| 22 | 22 | import ctools |
| 23 | 23 | import sys |
| 24 | -import os | |
| 25 | 24 | |
| 26 | 25 | # ============== # |
| 27 | 26 | # cstsdist class # |
| 28 | 27 | # ============== # |
| 29 | -class csresmap(gammalib.GApplication): | |
| 28 | +class csresmap(ctools.cscript): | |
| 30 | 29 | """ |
| 31 | - This class implements the creation of a residual map. It derives | |
| 32 | - from the GammaLib::GApplication class which provides support for parameter | |
| 33 | - files, command line arguments, and logging. In that way the Python | |
| 34 | - script behaves just as a regular ctool. | |
| 30 | + This class implements the creation of a residual map. It derives from | |
| 31 | + the ctools.cscript class which provides support for parameter files, | |
| 32 | + command line arguments, and logging. In that way the Python script | |
| 33 | + behaves just as a regular ctool. | |
| 35 | 34 | """ |
| 36 | 35 | def __init__(self, *argv): |
| 37 | 36 | """ |
| 38 | 37 | Constructor. |
| 39 | 38 | """ |
| 39 | + | |
| 40 | 40 | # Set name |
| 41 | 41 | self.name = "csresmap" |
| 42 | 42 | self.version = "1.0.0" |
| ... | ... | @@ -60,9 +60,9 @@ class csresmap(gammalib.GApplication): |
| 60 | 60 | |
| 61 | 61 | # Initialise application |
| 62 | 62 | if len(argv) == 0: |
| 63 | - gammalib.GApplication.__init__(self, self.name, self.version) | |
| 63 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 64 | 64 | elif len(argv) ==1: |
| 65 | - gammalib.GApplication.__init__(self, self.name, self.version, *argv) | |
| 65 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 66 | 66 | else: |
| 67 | 67 | raise TypeError("Invalid number of arguments given.") |
| 68 | 68 | |
| ... | ... | @@ -103,23 +103,24 @@ class csresmap(gammalib.GApplication): |
| 103 | 103 | pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Event list, counts cube, or observation definition file")) |
| 104 | 104 | pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) |
| 105 | 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")) | |
| 106 | + pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 107 | + pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 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 | - pars.append(gammalib.GApplicationPar("emin","r","h","0.1","0.0","","Lower energy limit (TeV)")) | |
| 111 | - pars.append(gammalib.GApplicationPar("emax","r","h","100.0","0.0","","Upper energy limit (TeV)")) | |
| 110 | + pars.append(gammalib.GApplicationPar("emin","r","h","0.1","0","","Lower energy limit (TeV)")) | |
| 111 | + pars.append(gammalib.GApplicationPar("emax","r","h","100.0","0","","Upper energy limit (TeV)")) | |
| 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","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)")) | |
| 115 | + pars.append(gammalib.GApplicationPar("proj","s","a","CAR","AIT|AZP|CAR|MER|MOL|STG|TAN","","Projection method")) | |
| 116 | + pars.append(gammalib.GApplicationPar("xref","r","a","83.63","0","360","First coordinate of image center in degrees (RA or galactic l)")) | |
| 117 | + pars.append(gammalib.GApplicationPar("yref","r","a","22.01","-90","90","Second coordinate of image center in degrees (DEC or galactic b)")) | |
| 118 | 118 | pars.append(gammalib.GApplicationPar("nxpix","i","a","200","","","Size of the X axis in pixels")) |
| 119 | 119 | pars.append(gammalib.GApplicationPar("nypix","i","a","200","","","Size of the Y axis in pixels")) |
| 120 | 120 | pars.append(gammalib.GApplicationPar("binsz","r","a","0.02","","","Pixel size (deg/pixel)")) |
| 121 | 121 | pars.append(gammalib.GApplicationPar("algorithm","s","h","SUBDIV","SUB|SUBDIV|SUBDIVSQRT","","Residual map computation algorithm")) |
| 122 | 122 | pars.append_standard() |
| 123 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csresmap.log","","","Log filename")) | |
| 123 | 124 | pars.save(parfile) |
| 124 | 125 | |
| 125 | 126 | # Return |
| ... | ... | @@ -133,49 +134,14 @@ class csresmap(gammalib.GApplication): |
| 133 | 134 | |
| 134 | 135 | # Set observation if not done before |
| 135 | 136 | if self.obs.size() == 0: |
| 137 | + self.obs = self.get_observations() | |
| 136 | 138 | |
| 137 | - # Get observation filename | |
| 138 | - obsfile = self["inobs"].filename() | |
| 139 | - | |
| 140 | - # Setup observation | |
| 141 | - try: | |
| 142 | - self.obs = gammalib.GObservations(obsfile) | |
| 143 | - except: | |
| 144 | - self.obs.clear() | |
| 145 | - obs = gammalib.GCTAObservation() | |
| 146 | - obs.load(obsfile) | |
| 147 | - self.m_caldb = self["caldb"].string() | |
| 148 | - self.m_irf = self["irf"].string() | |
| 149 | - caldb = gammalib.GCaldb() | |
| 150 | - if os.path.isdir(self.m_caldb): | |
| 151 | - caldb.rootdir(self.m_caldb) | |
| 152 | - else: | |
| 153 | - caldb.open("cta",self. m_caldb) | |
| 154 | - obs.response(self.m_irf, caldb); | |
| 155 | - self.obs.append(obs) | |
| 156 | - | |
| 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); | |
| 169 | - | |
| 170 | - # Check for models in the container | |
| 171 | - # read models from file if there were none | |
| 172 | - # Note that the models should be optimised for | |
| 173 | - # meaningful residual map | |
| 139 | + # Set models if we have none | |
| 174 | 140 | if self.obs.models().size() == 0: |
| 175 | 141 | self.obs.models(self["inmodel"].filename()) |
| 142 | + | |
| 143 | + # Read other parameters | |
| 176 | 144 | self.m_outfile = self["outmap"].filename() |
| 177 | - #self.m_modfile = self["modfile"].filename() | |
| 178 | - #self.m_binfile = self["binfile"].filename() | |
| 179 | 145 | self.m_xref = self["xref"].real() |
| 180 | 146 | self.m_yref = self["yref"].real() |
| 181 | 147 | self.m_emin = self["emin"].real() |
| ... | ... | @@ -194,7 +160,7 @@ class csresmap(gammalib.GApplication): |
| 194 | 160 | self.m_chatter = self["chatter"].integer() |
| 195 | 161 | self.m_clobber = self["clobber"].boolean() |
| 196 | 162 | self.m_debug = self["debug"].boolean() |
| 197 | - | |
| 163 | + | |
| 198 | 164 | # Return |
| 199 | 165 | return |
| 200 | 166 | ... | ... |