Commit f8c17cb376487d43de28d28cf6b92273a1353da4
1 parent
25a6a46b
Adapt to new GApplication interfac with private methods.
Showing
6 changed files
with
804 additions
and
750 deletions
cscripts/csfindobs.py
| ... | ... | @@ -30,32 +30,34 @@ import json |
| 30 | 30 | # =============== # |
| 31 | 31 | class csfindobs(ctools.cscript): |
| 32 | 32 | """ |
| 33 | - This class can be used to find observations from an IACT data store. | |
| 33 | + Find observations from an IACT data store. | |
| 34 | 34 | """ |
| 35 | + | |
| 36 | + # Constructors and destructors | |
| 35 | 37 | def __init__(self, *argv): |
| 36 | 38 | """ |
| 37 | 39 | Constructor. |
| 38 | 40 | """ |
| 39 | 41 | # Set name |
| 40 | - self.name = "csfindobs" | |
| 41 | - self.version = "1.0.0" | |
| 42 | - self.verbose = False | |
| 43 | - self.datapath = os.getenv("VHEFITS","") | |
| 42 | + self._name = "csfindobs" | |
| 43 | + self._version = "1.1.0" | |
| 44 | + self._verbose = False | |
| 45 | + self._datapath = os.getenv("VHEFITS","") | |
| 44 | 46 | |
| 45 | 47 | # Make sure that parfile exists |
| 46 | - file = self.parfile() | |
| 48 | + self._parfile() | |
| 47 | 49 | |
| 48 | 50 | # Initialise application |
| 49 | 51 | if len(argv) == 0: |
| 50 | - ctools.cscript.__init__(self, self.name, self.version) | |
| 52 | + ctools.cscript.__init__(self, self._name, self._version) | |
| 51 | 53 | elif len(argv) ==1: |
| 52 | - ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 54 | + ctools.cscript.__init__(self, self._name, self._version, *argv) | |
| 53 | 55 | else: |
| 54 | 56 | raise TypeError("Invalid number of arguments given.") |
| 55 | 57 | |
| 56 | 58 | # Set logger properties |
| 57 | - self.log_header() | |
| 58 | - self.log.date(True) | |
| 59 | + self._log_header() | |
| 60 | + self._log.date(True) | |
| 59 | 61 | |
| 60 | 62 | # Return |
| 61 | 63 | return |
| ... | ... | @@ -65,19 +67,20 @@ class csfindobs(ctools.cscript): |
| 65 | 67 | Destructor. |
| 66 | 68 | """ |
| 67 | 69 | # Write separator into logger |
| 68 | - if self.logTerse(): | |
| 69 | - self.log("\n") | |
| 70 | + if self._logTerse(): | |
| 71 | + self._log("\n") | |
| 70 | 72 | |
| 71 | 73 | # Return |
| 72 | 74 | return |
| 73 | 75 | |
| 74 | - def parfile(self): | |
| 76 | + def _parfile(self): | |
| 75 | 77 | """ |
| 76 | 78 | Check if parfile exists. If parfile does not exist then create a |
| 77 | - default parfile. This kluge avoids shipping the cscript with a parfile. | |
| 79 | + default parfile. This kluge avoids shipping the cscript with a | |
| 80 | + parfile. | |
| 78 | 81 | """ |
| 79 | 82 | # Set parfile name |
| 80 | - parfile = self.name+".par" | |
| 83 | + parfile = self._name+".par" | |
| 81 | 84 | |
| 82 | 85 | try: |
| 83 | 86 | pars = gammalib.GApplicationPars(parfile) |
| ... | ... | @@ -87,7 +90,7 @@ class csfindobs(ctools.cscript): |
| 87 | 90 | |
| 88 | 91 | # Create default parfile |
| 89 | 92 | pars = gammalib.GApplicationPars() |
| 90 | - pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data are located")) | |
| 93 | + pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data are located")) | |
| 91 | 94 | pars.append(gammalib.GApplicationPar("prodname","s","a","prod-name","","","Name of FITS production (Run csiactdata to view your options)")) |
| 92 | 95 | pars.append(gammalib.GApplicationPar("outfile","f","a","runlist.lis","","","Runlist outfile")) |
| 93 | 96 | pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","","","Right ascension")) |
| ... | ... | @@ -103,89 +106,105 @@ class csfindobs(ctools.cscript): |
| 103 | 106 | # Return |
| 104 | 107 | return |
| 105 | 108 | |
| 106 | - def get_parameters(self): | |
| 109 | + def _get_parameters(self): | |
| 107 | 110 | """ |
| 108 | 111 | Get parameters from parfile and setup the observation. |
| 109 | 112 | """ |
| 110 | 113 | # Get parameters |
| 111 | - if self.datapath == "": | |
| 112 | - self.datapath = self["datapath"].string() | |
| 114 | + if self._datapath == "": | |
| 115 | + self._datapath = self["datapath"].string() | |
| 113 | 116 | |
| 114 | 117 | # Expand environment |
| 115 | - self.datapath = gammalib.expand_env(self.datapath) | |
| 118 | + self._datapath = gammalib.expand_env(self._datapath) | |
| 116 | 119 | |
| 117 | 120 | # Get production name |
| 118 | - self.m_prodname = self["prodname"].string() | |
| 121 | + self._prodname = self["prodname"].string() | |
| 119 | 122 | |
| 120 | 123 | # Master index file name |
| 121 | - self.m_master_indx = self["master_indx"].string() | |
| 124 | + self._master_indx = self["master_indx"].string() | |
| 122 | 125 | |
| 123 | 126 | # Intiialise flag if spatial selection is required |
| 124 | - self.select_radec = True | |
| 127 | + self._select_radec = True | |
| 125 | 128 | |
| 126 | 129 | # Initialise invalid radius |
| 127 | - self.m_radius = 0.0 | |
| 130 | + self._radius = 0.0 | |
| 128 | 131 | |
| 129 | 132 | # Check for vailidity of spatial parameters |
| 130 | - if self["ra"].is_valid() and self["dec"].is_valid() and self["rad"].is_valid(): | |
| 133 | + if (self["ra"].is_valid() and | |
| 134 | + self["dec"].is_valid() and | |
| 135 | + self["rad"].is_valid()): | |
| 131 | 136 | |
| 132 | 137 | # Read spatial parameters |
| 133 | - self.m_ra = self["ra"].real() | |
| 134 | - self.m_dec = self["dec"].real() | |
| 135 | - self.m_radius = self["rad"].real() | |
| 138 | + self._ra = self["ra"].real() | |
| 139 | + self._dec = self["dec"].real() | |
| 140 | + self._radius = self["rad"].real() | |
| 136 | 141 | |
| 137 | 142 | else: |
| 138 | - self.select_radec = False | |
| 143 | + self._select_radec = False | |
| 139 | 144 | |
| 140 | 145 | # Check Radius for validity |
| 141 | - if self.m_radius <= 0.0: | |
| 142 | - self.select_radec = False | |
| 146 | + if self._radius <= 0.0: | |
| 147 | + self._select_radec = False | |
| 143 | 148 | |
| 144 | 149 | # Read other parameters |
| 145 | - self.m_quality = self["min_qual"].integer() | |
| 146 | - self.m_expression = self["expression"].string() | |
| 150 | + self._quality = self["min_qual"].integer() | |
| 151 | + self._expression = self["expression"].string() | |
| 147 | 152 | |
| 148 | 153 | # Check for validity of expression |
| 149 | - if self.m_expression == "NONE" or self.m_expression == "INDEF": | |
| 150 | - self.m_expression = "" | |
| 154 | + if self._expression == "NONE" or self._expression == "INDEF": | |
| 155 | + self._expression = "" | |
| 151 | 156 | |
| 152 | 157 | # Read outfile |
| 153 | - self.m_outfile = self["outfile"].filename() | |
| 158 | + self._outfile = self["outfile"].filename() | |
| 154 | 159 | |
| 155 | 160 | # Open master index file and look for prodname |
| 156 | - master_file = os.path.join(self.datapath, self.m_master_indx) | |
| 161 | + master_file = os.path.join(self._datapath, self._master_indx) | |
| 157 | 162 | if not os.path.isfile(master_file): |
| 158 | - raise RuntimeError("FITS data store not available. No master index file found at \""+master_file+"\". Make sure the file is copied from the server and your datapath is set correctly.") | |
| 163 | + raise RuntimeError("FITS data store not available. "+ | |
| 164 | + "No master index file found at \""+ | |
| 165 | + master_file+"\". Make sure the file "+ | |
| 166 | + "is copied from the server and your "+ | |
| 167 | + "datapath is set correctly.") | |
| 159 | 168 | |
| 160 | 169 | # Open and load JSON file |
| 161 | 170 | json_data = open(master_file).read() |
| 162 | 171 | data = json.loads(json_data) |
| 163 | 172 | if not "datasets" in data: |
| 164 | - raise RuntimeError("Key \"datasets\" not available in master index file.") | |
| 173 | + raise RuntimeError("Key \"datasets\" not available in "+ | |
| 174 | + "master index file.") | |
| 165 | 175 | |
| 166 | 176 | # Get configurations |
| 167 | 177 | configs = data["datasets"] |
| 168 | 178 | |
| 169 | 179 | # Initialise obs index file |
| 170 | - self.m_obs_index = "" | |
| 180 | + self._obs_index = "" | |
| 171 | 181 | |
| 172 | 182 | # Get HDUs |
| 173 | 183 | for config in configs: |
| 174 | - if self.m_prodname == config["name"]: | |
| 175 | - self.m_obs_index = str(os.path.join(self.datapath, config["obsindx"])) | |
| 184 | + if self._prodname == config["name"]: | |
| 185 | + self._obs_index = str(os.path.join(self._datapath, | |
| 186 | + config["obsindx"])) | |
| 176 | 187 | break |
| 177 | 188 | |
| 178 | 189 | # Check HDUs |
| 179 | - if self.m_obs_index == "": | |
| 180 | - raise RuntimeError("FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") | |
| 181 | - filename = gammalib.GFilename(self.m_obs_index+"[OBS_INDEX]") | |
| 190 | + if self._obs_index == "": | |
| 191 | + raise RuntimeError("FITS data store \""+self._prodname+ | |
| 192 | + "\" not available. Run csiactdata to get "+ | |
| 193 | + "a list of available storage names") | |
| 194 | + filename = gammalib.GFilename(self._obs_index+"[OBS_INDEX]") | |
| 182 | 195 | if not filename.is_fits(): |
| 183 | - raise RuntimeError("Observation index file \""+self.m_obs_index+"[OBS_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.") | |
| 196 | + raise RuntimeError("Observation index file \""+ | |
| 197 | + self._obs_index+ | |
| 198 | + "[OBS_INDEX]\" for FITS data store \""+ | |
| 199 | + self._prodname+ | |
| 200 | + "\" not available. "+ | |
| 201 | + "Check your master index file or run "+ | |
| 202 | + "csiactdata to get a list of available "+ | |
| 203 | + "storage names.") | |
| 184 | 204 | |
| 185 | 205 | # Set other members |
| 186 | - self.m_log = False # Logging in client tools | |
| 187 | - self.m_debug = False # Debugging in client tools | |
| 188 | - self.m_clobber = self["clobber"].boolean() | |
| 206 | + self._debug = False # Debugging in client tools | |
| 207 | + self._clobber = self["clobber"].boolean() | |
| 189 | 208 | |
| 190 | 209 | # Return |
| 191 | 210 | return |
| ... | ... | @@ -206,7 +225,7 @@ class csfindobs(ctools.cscript): |
| 206 | 225 | self.run() |
| 207 | 226 | |
| 208 | 227 | # Save residual map |
| 209 | - self.save(self.m_outfile) | |
| 228 | + self.save(self._outfile) | |
| 210 | 229 | |
| 211 | 230 | # Return |
| 212 | 231 | return |
| ... | ... | @@ -216,40 +235,41 @@ class csfindobs(ctools.cscript): |
| 216 | 235 | Run the script. |
| 217 | 236 | """ |
| 218 | 237 | # Switch screen logging on in debug mode |
| 219 | - if self.logDebug(): | |
| 220 | - self.log.cout(True) | |
| 238 | + if self._logDebug(): | |
| 239 | + self._log.cout(True) | |
| 221 | 240 | |
| 222 | 241 | # Get parameters |
| 223 | - self.get_parameters() | |
| 242 | + self._get_parameters() | |
| 224 | 243 | |
| 225 | 244 | # Write input parameters into logger |
| 226 | - if self.logTerse(): | |
| 227 | - self.log_parameters() | |
| 228 | - self.log("\n") | |
| 245 | + if self._logTerse(): | |
| 246 | + self._log_parameters() | |
| 247 | + self._log("\n") | |
| 229 | 248 | |
| 230 | 249 | # Initialise run list |
| 231 | - self.runs = [] | |
| 250 | + self._runs = [] | |
| 232 | 251 | |
| 233 | 252 | # Initialise selction expression |
| 234 | 253 | expr = "" |
| 235 | 254 | |
| 236 | 255 | # Add spatial expression if possible |
| 237 | - if self.select_radec: | |
| 238 | - expr += "ANGSEP("+str(self.m_ra)+","+str(self.m_dec)+",RA_PNT,DEC_PNT)<="+str(self.m_radius) | |
| 256 | + if self._select_radec: | |
| 257 | + expr += "ANGSEP("+str(self._ra)+","+str(self._dec)+ \ | |
| 258 | + ",RA_PNT,DEC_PNT)<="+str(self._radius) | |
| 239 | 259 | |
| 240 | 260 | # Add connector if expression is empty |
| 241 | 261 | if len(expr): |
| 242 | 262 | expr += "&&" |
| 243 | 263 | |
| 244 | 264 | # Add quality expression |
| 245 | - expr += "QUALITY<="+str(self.m_quality) | |
| 265 | + expr += "QUALITY<="+str(self._quality) | |
| 246 | 266 | |
| 247 | 267 | # Add user expression |
| 248 | - if self.m_expression == "NONE" or len(self.m_expression) > 0: | |
| 249 | - expr += "&&"+self.m_expression | |
| 268 | + if self._expression == "NONE" or len(self._expression) > 0: | |
| 269 | + expr += "&&"+self._expression | |
| 250 | 270 | |
| 251 | 271 | # Initialise filename |
| 252 | - openfile = self.m_obs_index+"[OBS_INDEX]["+expr+"]" | |
| 272 | + openfile = self._obs_index+"[OBS_INDEX]["+expr+"]" | |
| 253 | 273 | |
| 254 | 274 | # Open file |
| 255 | 275 | fits = gammalib.GFits(openfile) |
| ... | ... | @@ -262,21 +282,21 @@ class csfindobs(ctools.cscript): |
| 262 | 282 | |
| 263 | 283 | # Read observation IDs into array |
| 264 | 284 | for i in range(obs_indx.nrows()): |
| 265 | - self.runs.append(obs_indx["OBS_ID"][i]) | |
| 285 | + self._runs.append(obs_indx["OBS_ID"][i]) | |
| 266 | 286 | |
| 267 | 287 | # Dump expression |
| 268 | - if self.logNormal(): | |
| 269 | - self.log("\n") | |
| 270 | - self.log.header3("Expression") | |
| 271 | - self.log(expr) | |
| 272 | - self.log("\n") | |
| 288 | + if self._logNormal(): | |
| 289 | + self._log("\n") | |
| 290 | + self._log.header3("Expression") | |
| 291 | + self._log(expr) | |
| 292 | + self._log("\n") | |
| 273 | 293 | |
| 274 | 294 | # Dump number of observations |
| 275 | - if self.logTerse(): | |
| 276 | - self.log("\n") | |
| 277 | - self.log.header3("Observations") | |
| 278 | - self.log("Found "+str(len(self.runs))+" observations") | |
| 279 | - self.log("\n") | |
| 295 | + if self._logTerse(): | |
| 296 | + self._log("\n") | |
| 297 | + self._log.header3("Observations") | |
| 298 | + self._log("Found "+str(len(self._runs))+" observations") | |
| 299 | + self._log("\n") | |
| 280 | 300 | |
| 281 | 301 | # Close file |
| 282 | 302 | fits.close() |
| ... | ... | @@ -285,34 +305,35 @@ class csfindobs(ctools.cscript): |
| 285 | 305 | return |
| 286 | 306 | |
| 287 | 307 | def save(self, outfile): |
| 288 | - | |
| 308 | + """ | |
| 309 | + Save. | |
| 310 | + """ | |
| 289 | 311 | # Check for clobber |
| 290 | - if outfile.exists() and not self.clobber(): | |
| 291 | - self.log("File "+outfile+" already exists. Set clobber=yes to overwrite file") | |
| 292 | - self.log("\n") | |
| 312 | + if outfile.exists() and not self._clobber(): | |
| 313 | + self._log("File \""+outfile+"\" already exists. ") | |
| 314 | + self._log("Set clobber=yes to overwrite file.") | |
| 315 | + self._log("\n") | |
| 293 | 316 | else: |
| 294 | 317 | # Write runs to file |
| 295 | 318 | f = open(repr(outfile),"w") |
| 296 | - for run in self.runs: | |
| 319 | + for run in self._runs: | |
| 297 | 320 | f.write(str(run)+" \n") |
| 298 | 321 | f.close() |
| 299 | 322 | |
| 300 | 323 | # Return |
| 301 | 324 | return |
| 302 | - | |
| 325 | + | |
| 326 | + | |
| 303 | 327 | # ======================== # |
| 304 | 328 | # Main routine entry point # |
| 305 | 329 | # ======================== # |
| 306 | 330 | if __name__ == '__main__': |
| 307 | - """ | |
| 308 | - Find IACT observations. | |
| 309 | - """ | |
| 331 | + | |
| 310 | 332 | # Create instance of application |
| 311 | 333 | app = csfindobs(sys.argv) |
| 312 | 334 | |
| 313 | 335 | # Open logfile |
| 314 | - app.logFileOpen() | |
| 336 | + app._logFileOpen() | |
| 315 | 337 | |
| 316 | 338 | # Execute application |
| 317 | 339 | app.execute() |
| 318 | - | ... | ... |
cscripts/csiactcopy.py
| ... | ... | @@ -39,24 +39,24 @@ class csiactcopy(ctools.cscript): |
| 39 | 39 | Constructor. |
| 40 | 40 | """ |
| 41 | 41 | # Set name |
| 42 | - self.name = "csiactcopy" | |
| 43 | - self.version = "1.1.0" | |
| 44 | - self.datapath = os.getenv("VHEFITS","") | |
| 42 | + self._name = "csiactcopy" | |
| 43 | + self._version = "1.1.0" | |
| 44 | + self._datapath = os.getenv("VHEFITS","") | |
| 45 | 45 | |
| 46 | 46 | # Make sure that parfile exists |
| 47 | - file = self.parfile() | |
| 47 | + self._parfile() | |
| 48 | 48 | |
| 49 | 49 | # Initialise application |
| 50 | 50 | if len(argv) == 0: |
| 51 | - ctools.cscript.__init__(self, self.name, self.version) | |
| 51 | + ctools.cscript.__init__(self, self._name, self._version) | |
| 52 | 52 | elif len(argv) == 1: |
| 53 | - ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 53 | + ctools.cscript.__init__(self, self._name, self._version, *argv) | |
| 54 | 54 | else: |
| 55 | 55 | raise TypeError("Invalid number of arguments given.") |
| 56 | 56 | |
| 57 | 57 | # Set logger properties |
| 58 | - self.log_header() | |
| 59 | - self.log.date(True) | |
| 58 | + self._log_header() | |
| 59 | + self._log.date(True) | |
| 60 | 60 | |
| 61 | 61 | # Return |
| 62 | 62 | return |
| ... | ... | @@ -69,14 +69,14 @@ class csiactcopy(ctools.cscript): |
| 69 | 69 | # Return |
| 70 | 70 | return |
| 71 | 71 | |
| 72 | - def parfile(self): | |
| 72 | + def _parfile(self): | |
| 73 | 73 | """ |
| 74 | 74 | Check if parfile exists. If parfile does not exist then create a |
| 75 | 75 | default parfile. This kluge avoids shipping the cscript with a |
| 76 | 76 | parfile. |
| 77 | 77 | """ |
| 78 | 78 | # Set parfile name |
| 79 | - parfile = self.name+".par" | |
| 79 | + parfile = self._name+".par" | |
| 80 | 80 | |
| 81 | 81 | try: |
| 82 | 82 | pars = gammalib.GApplicationPars(parfile) |
| ... | ... | @@ -97,23 +97,23 @@ class csiactcopy(ctools.cscript): |
| 97 | 97 | # Return |
| 98 | 98 | return |
| 99 | 99 | |
| 100 | - def get_parameters(self): | |
| 100 | + def _get_parameters(self): | |
| 101 | 101 | """ |
| 102 | 102 | Get parameters from parfile and setup the observation. |
| 103 | 103 | """ |
| 104 | 104 | |
| 105 | 105 | # Get Parameters |
| 106 | - self.m_remote_master = self["remote_master"].filename() | |
| 107 | - if not self.m_remote_master.exists(): | |
| 106 | + self._remote_master = self["remote_master"].filename() | |
| 107 | + if not self._remote_master.exists(): | |
| 108 | 108 | raise RuntimeError("*** ERROR: FITS data not available. No " |
| 109 | 109 | "master index file found in \""+ |
| 110 | - self.m_remote_master+"\". Make sure remote " | |
| 110 | + self._remote_master+"\". Make sure remote " | |
| 111 | 111 | "file system is properly mounted.") |
| 112 | 112 | |
| 113 | 113 | # Get parameters |
| 114 | - self.m_prodname = self["prodname"].string() | |
| 115 | - self.m_outpath = gammalib.expand_env(self["outpath"].string()) | |
| 116 | - self.m_runlist = self["runlist"].filename() | |
| 114 | + self._prodname = self["prodname"].string() | |
| 115 | + self._outpath = gammalib.expand_env(self["outpath"].string()) | |
| 116 | + self._runlist = self["runlist"].filename() | |
| 117 | 117 | |
| 118 | 118 | # Return |
| 119 | 119 | return |
| ... | ... | @@ -133,76 +133,76 @@ class csiactcopy(ctools.cscript): |
| 133 | 133 | Run the script. |
| 134 | 134 | """ |
| 135 | 135 | # Switch screen logging on |
| 136 | - self.log.cout(True) | |
| 136 | + self._log.cout(True) | |
| 137 | 137 | |
| 138 | 138 | # Get parameters |
| 139 | - self.get_parameters() | |
| 139 | + self._get_parameters() | |
| 140 | 140 | |
| 141 | 141 | # Write input parameters into logger |
| 142 | - if self.logTerse(): | |
| 143 | - self.log_parameters() | |
| 144 | - self.log("\n") | |
| 142 | + if self._logTerse(): | |
| 143 | + self._log_parameters() | |
| 144 | + self._log("\n") | |
| 145 | 145 | |
| 146 | 146 | # Make destination directory if not available |
| 147 | - if not os.path.isdir(self.m_outpath): | |
| 148 | - os.makedirs(self.m_outpath) | |
| 147 | + if not os.path.isdir(self._outpath): | |
| 148 | + os.makedirs(self._outpath) | |
| 149 | 149 | |
| 150 | 150 | # Log output |
| 151 | - if self.logTerse(): | |
| 152 | - self.log("\n") | |
| 153 | - self.log.header2("Runlist information") | |
| 151 | + if self._logTerse(): | |
| 152 | + self._log("\n") | |
| 153 | + self._log.header2("Runlist information") | |
| 154 | 154 | |
| 155 | 155 | # Initialise runlist array |
| 156 | - self.runlist = [] | |
| 156 | + self._runs = [] | |
| 157 | 157 | |
| 158 | 158 | # Check if runlist file is available |
| 159 | - if self.m_runlist.exists(): | |
| 160 | - runfile = open(self.m_runlist) | |
| 159 | + if self._runlist.exists(): | |
| 160 | + runfile = open(self._runlist) | |
| 161 | 161 | for line in runfile.readlines(): |
| 162 | 162 | if len(line) == 0: |
| 163 | 163 | continue |
| 164 | 164 | if line[0] == '#': |
| 165 | 165 | continue |
| 166 | 166 | if len(line.split()) > 0: |
| 167 | - self.runlist.append(int(line.split()[0])) | |
| 167 | + self._runs.append(int(line.split()[0])) | |
| 168 | 168 | runfile.close() |
| 169 | 169 | |
| 170 | 170 | # Logging |
| 171 | - if self.logTerse(): | |
| 172 | - self.log.parformat("Number of observations") | |
| 173 | - self.log(str(len(self.runlist))) | |
| 174 | - self.log("\n") | |
| 171 | + if self._logTerse(): | |
| 172 | + self._log.parformat("Number of observations") | |
| 173 | + self._log(str(len(self._runs))) | |
| 174 | + self._log("\n") | |
| 175 | 175 | |
| 176 | 176 | # Copy all data if runlist file is "NONE" |
| 177 | - elif self.m_runlist == "NONE": | |
| 178 | - if self.logTerse(): | |
| 179 | - self.log("Copy all available data") | |
| 180 | - self.log("\n") | |
| 177 | + elif self._runlist == "NONE": | |
| 178 | + if self._logTerse(): | |
| 179 | + self._log("Copy all available data") | |
| 180 | + self._log("\n") | |
| 181 | 181 | |
| 182 | 182 | # Raise exception if file not valid |
| 183 | 183 | else: |
| 184 | 184 | raise RuntimeError("*** ERROR: Runlist file \""+ |
| 185 | - self.m_runlist+"\" not available.") | |
| 185 | + self._runlist+"\" not available.") | |
| 186 | 186 | |
| 187 | 187 | # Check for availability of remote master file |
| 188 | - if not self.m_remote_master.exists(): | |
| 188 | + if not self._remote_master.exists(): | |
| 189 | 189 | raise RuntimeError("*** ERROR: Remote master file \""+ |
| 190 | - self.m_remote_master+"\" does not exist.") | |
| 190 | + self._remote_master+"\" does not exist.") | |
| 191 | 191 | |
| 192 | 192 | # Retrieve json data from remote master |
| 193 | - json_data = open(self.m_remote_master.url()).read() | |
| 193 | + json_data = open(self._remote_master.url()).read() | |
| 194 | 194 | data = json.loads(json_data) |
| 195 | 195 | if not "datasets" in data: |
| 196 | 196 | raise RuntimeError("*** ERROR: Key \"datasets\" not available " |
| 197 | 197 | "in remote master index file \""+ |
| 198 | - self.m_remote_master+"\".") | |
| 198 | + self._remote_master+"\".") | |
| 199 | 199 | |
| 200 | 200 | # Get array of configurations |
| 201 | 201 | configs = data["datasets"] |
| 202 | 202 | |
| 203 | 203 | # Get remote paths |
| 204 | - #self.remote_base = os.path.dirname(self.m_remote_master.url()) | |
| 205 | - self.remote_base = self.m_remote_master.path() | |
| 204 | + #self._remote_base = os.path.dirname(self._remote_master.url()) | |
| 205 | + self._remote_base = self._remote_master.path() | |
| 206 | 206 | |
| 207 | 207 | # Initialise flag if prod has been found |
| 208 | 208 | has_prod = False |
| ... | ... | @@ -211,36 +211,36 @@ class csiactcopy(ctools.cscript): |
| 211 | 211 | files = set() |
| 212 | 212 | |
| 213 | 213 | # Logging |
| 214 | - if self.logTerse(): | |
| 215 | - self.log("\n") | |
| 216 | - self.log.header2("Loop over remote configs") | |
| 214 | + if self._logTerse(): | |
| 215 | + self._log("\n") | |
| 216 | + self._log.header2("Loop over remote configs") | |
| 217 | 217 | |
| 218 | 218 | # Loop over configs |
| 219 | 219 | for config in configs: |
| 220 | 220 | |
| 221 | 221 | # Logging |
| 222 | - if self.logVerbose(): | |
| 223 | - self.log.header2(str(config["name"])) | |
| 222 | + if self._logVerbose(): | |
| 223 | + self._log.header2(str(config["name"])) | |
| 224 | 224 | |
| 225 | 225 | # Check if prodname was found |
| 226 | - if config["name"] == self.m_prodname: | |
| 226 | + if config["name"] == self._prodname: | |
| 227 | 227 | |
| 228 | 228 | # Inidicate that prodname has been found |
| 229 | 229 | has_prod = True |
| 230 | 230 | |
| 231 | 231 | # Build path of index files |
| 232 | - remote_hdu = os.path.join(self.remote_base, config["hduindx"]) | |
| 233 | - remote_obs = os.path.join(self.remote_base, config["obsindx"]) | |
| 232 | + remote_hdu = os.path.join(self._remote_base, config["hduindx"]) | |
| 233 | + remote_obs = os.path.join(self._remote_base, config["obsindx"]) | |
| 234 | 234 | |
| 235 | 235 | # Log information |
| 236 | - if self.logTerse(): | |
| 237 | - self.log.header3("Remote config \""+self.m_prodname+"\"") | |
| 238 | - self.log.parformat("HDU index") | |
| 239 | - self.log(str(remote_hdu)) | |
| 240 | - self.log("\n") | |
| 241 | - self.log.parformat("Observation index") | |
| 242 | - self.log(str(remote_obs)) | |
| 243 | - self.log("\n") | |
| 236 | + if self._logTerse(): | |
| 237 | + self._log.header3("Remote config \""+self._prodname+"\"") | |
| 238 | + self._log.parformat("HDU index") | |
| 239 | + self._log(str(remote_hdu)) | |
| 240 | + self._log("\n") | |
| 241 | + self._log.parformat("Observation index") | |
| 242 | + self._log(str(remote_obs)) | |
| 243 | + self._log("\n") | |
| 244 | 244 | |
| 245 | 245 | # Open remote HDU index file |
| 246 | 246 | fits = gammalib.GFits(str(remote_hdu)) |
| ... | ... | @@ -259,12 +259,12 @@ class csiactcopy(ctools.cscript): |
| 259 | 259 | remote_ids.add(table["OBS_ID"][row]) |
| 260 | 260 | |
| 261 | 261 | # Log runs that are not available remotely |
| 262 | - for run in self.runlist: | |
| 262 | + for run in self._runs: | |
| 263 | 263 | if not run in remote_ids: |
| 264 | - if self.logNormal(): | |
| 265 | - self.log("Skip observation "+str(run)+": ") | |
| 266 | - self.log("ID not available remotely") | |
| 267 | - self.log("\n") | |
| 264 | + if self._logNormal(): | |
| 265 | + self._log("Skip observation "+str(run)+": ") | |
| 266 | + self._log("ID not available remotely") | |
| 267 | + self._log("\n") | |
| 268 | 268 | |
| 269 | 269 | # Loop over remote HDU index file |
| 270 | 270 | for row in range(table.nrows()): |
| ... | ... | @@ -279,10 +279,10 @@ class csiactcopy(ctools.cscript): |
| 279 | 279 | continue |
| 280 | 280 | |
| 281 | 281 | # Check if we need to consider an input runlist |
| 282 | - if len(self.runlist): | |
| 282 | + if len(self._runs): | |
| 283 | 283 | |
| 284 | 284 | # Check if obs id is in runlist |
| 285 | - if obs_id in self.runlist: | |
| 285 | + if obs_id in self._runs: | |
| 286 | 286 | |
| 287 | 287 | # Get filename |
| 288 | 288 | fname = os.path.join(os.path.dirname(remote_hdu), file_dir, file_name) |
| ... | ... | @@ -311,44 +311,44 @@ class csiactcopy(ctools.cscript): |
| 311 | 311 | cp_size += table["SIZE"][row] |
| 312 | 312 | |
| 313 | 313 | # Log file information |
| 314 | - if self.logTerse(): | |
| 315 | - self.log("\n") | |
| 316 | - self.log.header2("File information") | |
| 317 | - self.log.parformat("Number of files") | |
| 318 | - self.log(str(len(files))) | |
| 319 | - self.log("\n") | |
| 314 | + if self._logTerse(): | |
| 315 | + self._log("\n") | |
| 316 | + self._log.header2("File information") | |
| 317 | + self._log.parformat("Number of files") | |
| 318 | + self._log(str(len(files))) | |
| 319 | + self._log("\n") | |
| 320 | 320 | if has_size: |
| 321 | - self.log.parformat("Size") | |
| 322 | - self.log("%.2f"%(float(cp_size)*1e-6)+" MB") | |
| 323 | - self.log("\n") | |
| 324 | - if self.logVerbose(): | |
| 325 | - self.log("\n") | |
| 326 | - self.log.header3("File names") | |
| 321 | + self._log.parformat("Size") | |
| 322 | + self._log("%.2f"%(float(cp_size)*1e-6)+" MB") | |
| 323 | + self._log("\n") | |
| 324 | + if self._logVerbose(): | |
| 325 | + self._log("\n") | |
| 326 | + self._log.header3("File names") | |
| 327 | 327 | for filename in files: |
| 328 | - self.log(str(filename)+"\n") | |
| 328 | + self._log(str(filename)+"\n") | |
| 329 | 329 | |
| 330 | 330 | # Close HDU index file |
| 331 | 331 | fits.close() |
| 332 | 332 | |
| 333 | 333 | # If prodname is not found just log that we skip the config |
| 334 | 334 | else: |
| 335 | - if self.logExplicit(): | |
| 336 | - self.log("\n") | |
| 337 | - self.log.header3("Skipping config \""+str(config["name"])+"\"") | |
| 338 | - self.log("\n") | |
| 335 | + if self._logExplicit(): | |
| 336 | + self._log("\n") | |
| 337 | + self._log.header3("Skipping config \""+str(config["name"])+"\"") | |
| 338 | + self._log("\n") | |
| 339 | 339 | |
| 340 | 340 | # Raise Exception if prodname was not found |
| 341 | 341 | if not has_prod: |
| 342 | - msg = "*** ERROR: FITS production \""+self.m_prodname+\ | |
| 342 | + msg = "*** ERROR: FITS production \""+self._prodname+\ | |
| 343 | 343 | "\" not available. Available productions are:\n" |
| 344 | 344 | for config in configs: |
| 345 | 345 | msg += " - "+config["name"]+"\n" |
| 346 | 346 | raise RuntimeError(msg) |
| 347 | 347 | |
| 348 | 348 | # Logging |
| 349 | - if self.logNormal(): | |
| 350 | - self.log("\n") | |
| 351 | - self.log.header1("Copying files") | |
| 349 | + if self._logNormal(): | |
| 350 | + self._log("\n") | |
| 351 | + self._log.header1("Copying files") | |
| 352 | 352 | |
| 353 | 353 | # intialise counter |
| 354 | 354 | k = 0 |
| ... | ... | @@ -356,11 +356,11 @@ class csiactcopy(ctools.cscript): |
| 356 | 356 | # initialise values for logging |
| 357 | 357 | last_fraction = 0.0 |
| 358 | 358 | fraction_increment = 20.0 |
| 359 | - if self.logNormal(): | |
| 359 | + if self._logNormal(): | |
| 360 | 360 | fraction_increment = 10.0 |
| 361 | - if self.logTerse(): | |
| 361 | + if self._logTerse(): | |
| 362 | 362 | fraction_increment = 5.0 |
| 363 | - if self.logExplicit(): | |
| 363 | + if self._logExplicit(): | |
| 364 | 364 | fraction_increment = 2.0 |
| 365 | 365 | |
| 366 | 366 | # initialise logging properties |
| ... | ... | @@ -373,14 +373,14 @@ class csiactcopy(ctools.cscript): |
| 373 | 373 | # Log progress |
| 374 | 374 | fraction = float(k) / float(len(files)) * 100.0 |
| 375 | 375 | while fraction > last_fraction: |
| 376 | - if self.logNormal() and not self.logVerbose(): | |
| 377 | - self.log.parformat("Status") | |
| 378 | - self.log(str(int(last_fraction))+"%") | |
| 379 | - self.log("\n") | |
| 376 | + if self._logNormal() and not self._logVerbose(): | |
| 377 | + self._log.parformat("Status") | |
| 378 | + self._log(str(int(last_fraction))+"%") | |
| 379 | + self._log("\n") | |
| 380 | 380 | last_fraction += fraction_increment |
| 381 | 381 | |
| 382 | 382 | # Copy file |
| 383 | - filesize = self.copy(filename, self.clobber()) | |
| 383 | + filesize = self.copy(filename, self._clobber()) | |
| 384 | 384 | |
| 385 | 385 | if filesize > 0.0: |
| 386 | 386 | total_size += filesize |
| ... | ... | @@ -390,51 +390,51 @@ class csiactcopy(ctools.cscript): |
| 390 | 390 | k += 1 |
| 391 | 391 | |
| 392 | 392 | # Logging |
| 393 | - if self.logNormal() and not self.logVerbose(): | |
| 394 | - self.log.parformat("Status") | |
| 395 | - self.log("Finished") | |
| 396 | - self.log("\n") | |
| 397 | - if self.logTerse(): | |
| 398 | - self.log("\n") | |
| 399 | - self.log.header1("Updating index files") | |
| 393 | + if self._logNormal() and not self._logVerbose(): | |
| 394 | + self._log.parformat("Status") | |
| 395 | + self._log("Finished") | |
| 396 | + self._log("\n") | |
| 397 | + if self._logTerse(): | |
| 398 | + self._log("\n") | |
| 399 | + self._log.header1("Updating index files") | |
| 400 | 400 | |
| 401 | 401 | # Build local index file names |
| 402 | - local_hdu = os.path.join(self.m_outpath, os.path.relpath(remote_hdu, self.remote_base)) | |
| 403 | - local_obs = os.path.join(self.m_outpath, os.path.relpath(remote_obs, self.remote_base)) | |
| 402 | + local_hdu = os.path.join(self._outpath, os.path.relpath(remote_hdu, self._remote_base)) | |
| 403 | + local_obs = os.path.join(self._outpath, os.path.relpath(remote_obs, self._remote_base)) | |
| 404 | 404 | |
| 405 | 405 | # If we have a runlist then merge index file |
| 406 | - if len(self.runlist): | |
| 406 | + if len(self._runs): | |
| 407 | 407 | |
| 408 | 408 | # Logging |
| 409 | - if self.logTerse(): | |
| 410 | - self.log("\n") | |
| 411 | - self.log.header3("HDU index") | |
| 409 | + if self._logTerse(): | |
| 410 | + self._log("\n") | |
| 411 | + self._log.header3("HDU index") | |
| 412 | 412 | |
| 413 | 413 | # Merge remote index files with local files |
| 414 | - self.merge(local_hdu, remote_hdu, "HDU_INDEX", self.clobber()) | |
| 414 | + self.merge(local_hdu, remote_hdu, "HDU_INDEX", self._clobber()) | |
| 415 | 415 | |
| 416 | - if self.logTerse(): | |
| 417 | - self.log("\n") | |
| 418 | - self.log.header3("OBS index") | |
| 416 | + if self._logTerse(): | |
| 417 | + self._log("\n") | |
| 418 | + self._log.header3("OBS index") | |
| 419 | 419 | |
| 420 | 420 | # Merge remote index files with local files |
| 421 | - self.merge(local_obs, remote_obs, "OBS_INDEX", self.clobber()) | |
| 421 | + self.merge(local_obs, remote_obs, "OBS_INDEX", self._clobber()) | |
| 422 | 422 | |
| 423 | 423 | else: |
| 424 | 424 | # If all files were copied, just copy index files too |
| 425 | - self.copy(remote_hdu, self.clobber()) | |
| 426 | - self.copy(remote_obs, self.clobber()) | |
| 425 | + self.copy(remote_hdu, self._clobber()) | |
| 426 | + self.copy(remote_obs, self._clobber()) | |
| 427 | 427 | |
| 428 | - if self.logTerse(): | |
| 429 | - self.log("\n") | |
| 430 | - self.log.header3("Master index file") | |
| 428 | + if self._logTerse(): | |
| 429 | + self._log("\n") | |
| 430 | + self._log.header3("Master index file") | |
| 431 | 431 | |
| 432 | 432 | # Adding prodname to local master |
| 433 | - localmaster = os.path.join(self.m_outpath, "master.json") | |
| 433 | + localmaster = os.path.join(self._outpath, "master.json") | |
| 434 | 434 | |
| 435 | 435 | # If no local master is found, copy master over first |
| 436 | 436 | if not os.path.isfile(localmaster): |
| 437 | - self.copy(self.m_remote_master.url(), self.clobber()) | |
| 437 | + self.copy(self._remote_master.url(), self._clobber()) | |
| 438 | 438 | |
| 439 | 439 | # Load local master |
| 440 | 440 | json_data = open(localmaster).read() |
| ... | ... | @@ -452,37 +452,37 @@ class csiactcopy(ctools.cscript): |
| 452 | 452 | for config in configs: |
| 453 | 453 | |
| 454 | 454 | # Get hdu and obs index files |
| 455 | - hdu = os.path.join(self.m_outpath, config["hduindx"]) | |
| 456 | - obs = os.path.join(self.m_outpath, config["obsindx"]) | |
| 455 | + hdu = os.path.join(self._outpath, config["hduindx"]) | |
| 456 | + obs = os.path.join(self._outpath, config["obsindx"]) | |
| 457 | 457 | |
| 458 | 458 | # Check if index files are available |
| 459 | 459 | if not (gammalib.GFilename(str(hdu)).is_fits() and |
| 460 | 460 | gammalib.GFilename(str(obs)).is_fits()): |
| 461 | - if self.logTerse(): | |
| 462 | - self.log("Removing \""+str(config["name"])+"\" ") | |
| 463 | - self.log("(not available)") | |
| 464 | - self.log("\n") | |
| 461 | + if self._logTerse(): | |
| 462 | + self._log("Removing \""+str(config["name"])+"\" ") | |
| 463 | + self._log("(not available)") | |
| 464 | + self._log("\n") | |
| 465 | 465 | else: |
| 466 | 466 | # Append config if valid |
| 467 | 467 | newconfigs.append(config) |
| 468 | - if self.logTerse(): | |
| 469 | - self.log("Keeping \""+str(config["name"])+"\"") | |
| 470 | - self.log("\n") | |
| 468 | + if self._logTerse(): | |
| 469 | + self._log("Keeping \""+str(config["name"])+"\"") | |
| 470 | + self._log("\n") | |
| 471 | 471 | |
| 472 | 472 | # Signals that downloaded config is available |
| 473 | - if config["name"] == self.m_prodname: | |
| 473 | + if config["name"] == self._prodname: | |
| 474 | 474 | has_config = True |
| 475 | 475 | |
| 476 | 476 | # Create new entry if config was not available |
| 477 | 477 | if not has_config: |
| 478 | 478 | newdict = dict.fromkeys(["name","hduindx","obsindx"]) |
| 479 | - newdict["name"] = self.m_prodname | |
| 480 | - newdict["hduindx"] = os.path.relpath(local_hdu, self.m_outpath) | |
| 481 | - newdict["obsindx"] = os.path.relpath(local_obs, self.m_outpath) | |
| 479 | + newdict["name"] = self._prodname | |
| 480 | + newdict["hduindx"] = os.path.relpath(local_hdu, self._outpath) | |
| 481 | + newdict["obsindx"] = os.path.relpath(local_obs, self._outpath) | |
| 482 | 482 | newconfigs.append(newdict) |
| 483 | - if self.logTerse(): | |
| 484 | - self.log("Adding \""+str(newdict["name"])+"\"") | |
| 485 | - self.log("\n") | |
| 483 | + if self._logTerse(): | |
| 484 | + self._log("Adding \""+str(newdict["name"])+"\"") | |
| 485 | + self._log("\n") | |
| 486 | 486 | |
| 487 | 487 | # Write new json master file |
| 488 | 488 | f = open(localmaster, "w") |
| ... | ... | @@ -491,27 +491,27 @@ class csiactcopy(ctools.cscript): |
| 491 | 491 | f.close() |
| 492 | 492 | |
| 493 | 493 | # Log summary |
| 494 | - if self.logNormal(): | |
| 495 | - self.log("\n") | |
| 496 | - self.log.header1("Summary") | |
| 497 | - self.log.parformat("Data files found") | |
| 498 | - self.log(str(len(files))) | |
| 499 | - self.log("\n") | |
| 500 | - self.log.parformat("Data files copied") | |
| 501 | - self.log(str(n_copied)) | |
| 502 | - self.log("\n") | |
| 503 | - self.log.parformat("Size") | |
| 504 | - self.log("%.2f"%(float(total_size)*1e-6)+" MB") | |
| 505 | - self.log("\n") | |
| 506 | - self.log.parformat("Local configs") | |
| 507 | - self.log(str(len(newconfigs))) | |
| 508 | - self.log("\n") | |
| 509 | - if self.logTerse(): | |
| 510 | - self.log("\n") | |
| 511 | - self.log.header3("Content of master index") | |
| 494 | + if self._logNormal(): | |
| 495 | + self._log("\n") | |
| 496 | + self._log.header1("Summary") | |
| 497 | + self._log.parformat("Data files found") | |
| 498 | + self._log(str(len(files))) | |
| 499 | + self._log("\n") | |
| 500 | + self._log.parformat("Data files copied") | |
| 501 | + self._log(str(n_copied)) | |
| 502 | + self._log("\n") | |
| 503 | + self._log.parformat("Size") | |
| 504 | + self._log("%.2f"%(float(total_size)*1e-6)+" MB") | |
| 505 | + self._log("\n") | |
| 506 | + self._log.parformat("Local configs") | |
| 507 | + self._log(str(len(newconfigs))) | |
| 508 | + self._log("\n") | |
| 509 | + if self._logTerse(): | |
| 510 | + self._log("\n") | |
| 511 | + self._log.header3("Content of master index") | |
| 512 | 512 | for config in newconfigs: |
| 513 | - self.log(str(config["name"])) | |
| 514 | - self.log("\n") | |
| 513 | + self._log(str(config["name"])) | |
| 514 | + self._log("\n") | |
| 515 | 515 | |
| 516 | 516 | # Return |
| 517 | 517 | return |
| ... | ... | @@ -521,43 +521,44 @@ class csiactcopy(ctools.cscript): |
| 521 | 521 | copy file to m_outpath |
| 522 | 522 | """ |
| 523 | 523 | # Get file destination |
| 524 | - destination = os.path.join(self.m_outpath,os.path.relpath(source, self.remote_base)) | |
| 524 | + destination = os.path.join(self._outpath, | |
| 525 | + os.path.relpath(source, self._remote_base)) | |
| 525 | 526 | |
| 526 | 527 | # Initialise return value |
| 527 | 528 | filesize = 0.0 |
| 528 | 529 | |
| 529 | 530 | # Logging |
| 530 | - if self.logVerbose(): | |
| 531 | - self.log("\n") | |
| 532 | - self.log.header3("Copy file") | |
| 533 | - self.log.parformat("Source") | |
| 534 | - self.log(str(source)) | |
| 535 | - self.log("\n") | |
| 536 | - self.log.parformat("Destination") | |
| 537 | - self.log(str(destination)) | |
| 538 | - self.log("\n") | |
| 539 | - self.log.parformat("Already exists") | |
| 540 | - self.log(str(os.path.isfile(destination))) | |
| 541 | - self.log("\n") | |
| 542 | - self.log.parformat("Overwrite") | |
| 543 | - self.log(str(clobber)) | |
| 544 | - self.log("\n") | |
| 545 | - self.log.parformat("Copying") | |
| 531 | + if self._logVerbose(): | |
| 532 | + self._log("\n") | |
| 533 | + self._log.header3("Copy file") | |
| 534 | + self._log.parformat("Source") | |
| 535 | + self._log(str(source)) | |
| 536 | + self._log("\n") | |
| 537 | + self._log.parformat("Destination") | |
| 538 | + self._log(str(destination)) | |
| 539 | + self._log("\n") | |
| 540 | + self._log.parformat("Already exists") | |
| 541 | + self._log(str(os.path.isfile(destination))) | |
| 542 | + self._log("\n") | |
| 543 | + self._log.parformat("Overwrite") | |
| 544 | + self._log(str(clobber)) | |
| 545 | + self._log("\n") | |
| 546 | + self._log.parformat("Copying") | |
| 546 | 547 | |
| 547 | 548 | # Flag if file destination is already available |
| 548 | 549 | is_file = os.path.isfile(destination) |
| 549 | 550 | |
| 550 | 551 | # check if file could be skipped because clobber=no |
| 551 | 552 | if is_file and clobber == False: |
| 552 | - if self.logVerbose(): | |
| 553 | - self.log("Skip (clobber=no)") | |
| 554 | - self.log("\n") | |
| 553 | + if self._logVerbose(): | |
| 554 | + self._log("Skip (clobber=no)") | |
| 555 | + self._log("\n") | |
| 555 | 556 | |
| 556 | 557 | # check if file could be skipped because it is the same file |
| 557 | 558 | elif is_file and os.path.samefile(destination, source): |
| 558 | - if self.logVerbose(): | |
| 559 | - self.log("Skip (same file)") | |
| 560 | - self.log("\n") | |
| 559 | + if self._logVerbose(): | |
| 560 | + self._log("Skip (same file)") | |
| 561 | + self._log("\n") | |
| 561 | 562 | |
| 562 | 563 | else: |
| 563 | 564 | # Create directory if not existent |
| ... | ... | @@ -572,9 +573,9 @@ class csiactcopy(ctools.cscript): |
| 572 | 573 | filesize = os.stat(destination).st_size |
| 573 | 574 | |
| 574 | 575 | # Logging |
| 575 | - if self.logVerbose(): | |
| 576 | - self.log("Done!") | |
| 577 | - self.log("\n") | |
| 576 | + if self._logVerbose(): | |
| 577 | + self._log("Done!") | |
| 578 | + self._log("\n") | |
| 578 | 579 | |
| 579 | 580 | # Return |
| 580 | 581 | return filesize |
| ... | ... | @@ -586,22 +587,22 @@ class csiactcopy(ctools.cscript): |
| 586 | 587 | If local fits file not present, a new one is created |
| 587 | 588 | """ |
| 588 | 589 | |
| 589 | - if self.logTerse(): | |
| 590 | - self.log.parformat("Local file") | |
| 591 | - self.log(str(localfits)) | |
| 592 | - self.log("\n") | |
| 593 | - self.log.parformat("Remote file") | |
| 594 | - self.log(str(remotefits)) | |
| 595 | - self.log("\n") | |
| 596 | - self.log.parformat("HDU name") | |
| 597 | - self.log(str(hduname)) | |
| 598 | - self.log("\n") | |
| 599 | - self.log.parformat("Conflict preference") | |
| 590 | + if self._logTerse(): | |
| 591 | + self._log.parformat("Local file") | |
| 592 | + self._log(str(localfits)) | |
| 593 | + self._log("\n") | |
| 594 | + self._log.parformat("Remote file") | |
| 595 | + self._log(str(remotefits)) | |
| 596 | + self._log("\n") | |
| 597 | + self._log.parformat("HDU name") | |
| 598 | + self._log(str(hduname)) | |
| 599 | + self._log("\n") | |
| 600 | + self._log.parformat("Conflict preference") | |
| 600 | 601 | if clobber: |
| 601 | - self.log("Remote") | |
| 602 | + self._log("Remote") | |
| 602 | 603 | else: |
| 603 | - self.log("Local") | |
| 604 | - self.log("\n") | |
| 604 | + self._log("Local") | |
| 605 | + self._log("\n") | |
| 605 | 606 | |
| 606 | 607 | # Check if local fits file is available |
| 607 | 608 | if os.path.isfile(localfits): |
| ... | ... | @@ -621,9 +622,9 @@ class csiactcopy(ctools.cscript): |
| 621 | 622 | |
| 622 | 623 | # Create selection expression for opening remote fits file |
| 623 | 624 | selection = "" |
| 624 | - if len(self.runlist): | |
| 625 | + if len(self._runs): | |
| 625 | 626 | selection += "["+hduname+"][" |
| 626 | - for run in self.runlist: | |
| 627 | + for run in self._runs: | |
| 627 | 628 | selection += "OBS_ID=="+str(run) |
| 628 | 629 | selection += "||" |
| 629 | 630 | selection = selection[:-2] |
| ... | ... | @@ -642,13 +643,13 @@ class csiactcopy(ctools.cscript): |
| 642 | 643 | for obs_id in robs_col: |
| 643 | 644 | remote_obs.append(obs_id) |
| 644 | 645 | |
| 645 | - if self.logTerse(): | |
| 646 | - self.log.parformat("Remote entries") | |
| 647 | - self.log(str(len(remote_obs))) | |
| 648 | - self.log("\n") | |
| 649 | - self.log.parformat("Local entries") | |
| 650 | - self.log(str(len(local_obs))) | |
| 651 | - self.log("\n") | |
| 646 | + if self._logTerse(): | |
| 647 | + self._log.parformat("Remote entries") | |
| 648 | + self._log(str(len(remote_obs))) | |
| 649 | + self._log("\n") | |
| 650 | + self._log.parformat("Local entries") | |
| 651 | + self._log(str(len(local_obs))) | |
| 652 | + self._log("\n") | |
| 652 | 653 | |
| 653 | 654 | # initialise counter for logging |
| 654 | 655 | removed_rows = 0 |
| ... | ... | @@ -706,13 +707,13 @@ class csiactcopy(ctools.cscript): |
| 706 | 707 | # Add rmeote HDUs |
| 707 | 708 | local_hdu.insert_rows(old_local_rows, remote_hdu.nrows()) |
| 708 | 709 | |
| 709 | - if self.logTerse(): | |
| 710 | + if self._logTerse(): | |
| 710 | 711 | if clobber: |
| 711 | - self.log.parformat("Removed local rows") | |
| 712 | + self._log.parformat("Removed local rows") | |
| 712 | 713 | else: |
| 713 | - self.log.parformat("Skipped remote rows") | |
| 714 | - self.log(str(removed_rows)) | |
| 715 | - self.log("\n") | |
| 714 | + self._log.parformat("Skipped remote rows") | |
| 715 | + self._log(str(removed_rows)) | |
| 716 | + self._log("\n") | |
| 716 | 717 | |
| 717 | 718 | # Loop over columns |
| 718 | 719 | for i in range(local_hdu.ncols()): |
| ... | ... | @@ -735,14 +736,12 @@ class csiactcopy(ctools.cscript): |
| 735 | 736 | # Main routine entry point # |
| 736 | 737 | # ======================== # |
| 737 | 738 | if __name__ == '__main__': |
| 738 | - """ | |
| 739 | - Copy IACT data | |
| 740 | - """ | |
| 739 | + | |
| 741 | 740 | # Create instance of application |
| 742 | 741 | app = csiactcopy(sys.argv) |
| 743 | 742 | |
| 744 | 743 | # Open logfile |
| 745 | - app.logFileOpen() | |
| 744 | + app._logFileOpen() | |
| 746 | 745 | |
| 747 | 746 | # Execute application |
| 748 | 747 | app.execute() | ... | ... |
cscripts/csiactdata.py
| ... | ... | @@ -40,25 +40,25 @@ class csiactdata(ctools.cscript): |
| 40 | 40 | Constructor. |
| 41 | 41 | """ |
| 42 | 42 | # Set name |
| 43 | - self.name = "csiactdata" | |
| 44 | - self.version = "1.0.0" | |
| 45 | - self.datapath = os.getenv("VHEFITS","") | |
| 46 | - self.prodnames = [] | |
| 43 | + self._name = "csiactdata" | |
| 44 | + self._version = "1.1.0" | |
| 45 | + self._datapath = os.getenv("VHEFITS","") | |
| 46 | + self._prodnames = [] | |
| 47 | 47 | |
| 48 | 48 | # Make sure that parfile exists |
| 49 | - file = self.parfile() | |
| 49 | + file = self._parfile() | |
| 50 | 50 | |
| 51 | 51 | # Initialise application |
| 52 | 52 | if len(argv) == 0: |
| 53 | - ctools.cscript.__init__(self, self.name, self.version) | |
| 53 | + ctools.cscript.__init__(self, self._name, self._version) | |
| 54 | 54 | elif len(argv) == 1: |
| 55 | - ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 55 | + ctools.cscript.__init__(self, self._name, self._version, *argv) | |
| 56 | 56 | else: |
| 57 | 57 | raise TypeError("Invalid number of arguments given.") |
| 58 | 58 | |
| 59 | 59 | # Set logger properties |
| 60 | - self.log_header() | |
| 61 | - self.log.date(True) | |
| 60 | + self._log_header() | |
| 61 | + self._log.date(True) | |
| 62 | 62 | |
| 63 | 63 | # Return |
| 64 | 64 | return |
| ... | ... | @@ -70,14 +70,14 @@ class csiactdata(ctools.cscript): |
| 70 | 70 | # Return |
| 71 | 71 | return |
| 72 | 72 | |
| 73 | - def parfile(self): | |
| 73 | + def _parfile(self): | |
| 74 | 74 | """ |
| 75 | 75 | Check if parfile exists. If parfile does not exist then create a |
| 76 | 76 | default parfile. This kluge avoids shipping the cscript with a |
| 77 | 77 | parfile. |
| 78 | 78 | """ |
| 79 | 79 | # Set parfile name |
| 80 | - parfile = self.name+".par" | |
| 80 | + parfile = self._name+".par" | |
| 81 | 81 | |
| 82 | 82 | try: |
| 83 | 83 | pars = gammalib.GApplicationPars(parfile) |
| ... | ... | @@ -87,7 +87,7 @@ class csiactdata(ctools.cscript): |
| 87 | 87 | |
| 88 | 88 | # Create default parfile |
| 89 | 89 | pars = gammalib.GApplicationPars() |
| 90 | - pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data is located")) | |
| 90 | + pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data is located")) | |
| 91 | 91 | pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) |
| 92 | 92 | pars.append_standard() |
| 93 | 93 | pars.append(gammalib.GApplicationPar("logfile","f","h","csiactdata.log","","","Log filename")) |
| ... | ... | @@ -102,19 +102,19 @@ class csiactdata(ctools.cscript): |
| 102 | 102 | """ |
| 103 | 103 | |
| 104 | 104 | # Get datapath if not already set |
| 105 | - if self.datapath == "": | |
| 106 | - self.datapath = self["datapath"].string() | |
| 105 | + if self._datapath == "": | |
| 106 | + self._datapath = self["datapath"].string() | |
| 107 | 107 | |
| 108 | 108 | # Expand environment |
| 109 | - self.datapath = gammalib.expand_env(self.datapath) | |
| 109 | + self._datapath = gammalib.expand_env(self._datapath) | |
| 110 | 110 | |
| 111 | 111 | # Get filename of master index file |
| 112 | - self.m_master_indx = self["master_indx"].string() | |
| 113 | - self.m_master_file = os.path.join(self.datapath, self.m_master_indx) | |
| 112 | + self._master_indx = self["master_indx"].string() | |
| 113 | + self._master_file = os.path.join(self._datapath, self._master_indx) | |
| 114 | 114 | |
| 115 | 115 | # Check for presence of master index file |
| 116 | - if not os.path.isfile(self.m_master_file): | |
| 117 | - raise RuntimeError("Master index file \""+self.m_master_file+"\" not found. Use hidden parameter \"master_indx\" to specifiy a different filename.") | |
| 116 | + if not os.path.isfile(self._master_file): | |
| 117 | + raise RuntimeError("Master index file \""+self._master_file+"\" not found. Use hidden parameter \"master_indx\" to specifiy a different filename.") | |
| 118 | 118 | |
| 119 | 119 | # Return |
| 120 | 120 | return |
| ... | ... | @@ -134,58 +134,58 @@ class csiactdata(ctools.cscript): |
| 134 | 134 | Run the script. |
| 135 | 135 | """ |
| 136 | 136 | # Switch screen logging on |
| 137 | - self.log.cout(True) | |
| 137 | + self._log.cout(True) | |
| 138 | 138 | |
| 139 | 139 | # Get parameters |
| 140 | - self.get_parameters() | |
| 140 | + self._get_parameters() | |
| 141 | 141 | |
| 142 | 142 | # Write input parameters into logger |
| 143 | - if self.logTerse(): | |
| 144 | - self.log_parameters() | |
| 145 | - self.log("\n") | |
| 143 | + if self._logTerse(): | |
| 144 | + self._log_parameters() | |
| 145 | + self._log("\n") | |
| 146 | 146 | |
| 147 | - self.log("\n") | |
| 148 | - self.log.header1("Data storage entries") | |
| 149 | - self.log("\n") | |
| 150 | - self.log.parformat("Master index file") | |
| 151 | - self.log(self.m_master_file) | |
| 152 | - self.log("\n") | |
| 153 | - self.log("\n") | |
| 147 | + self._log("\n") | |
| 148 | + self._log.header1("Data storage entries") | |
| 149 | + self._log("\n") | |
| 150 | + self._log.parformat("Master index file") | |
| 151 | + self._log(self._master_file) | |
| 152 | + self._log("\n") | |
| 153 | + self._log("\n") | |
| 154 | 154 | |
| 155 | 155 | # Open and load JSON file |
| 156 | - json_data = open(self.m_master_file).read() | |
| 156 | + json_data = open(self._master_file).read() | |
| 157 | 157 | data = json.loads(json_data) |
| 158 | 158 | configs = data["datasets"] |
| 159 | 159 | |
| 160 | 160 | # Initialise array for available names |
| 161 | - self.prodnames = [] | |
| 161 | + self._prodnames = [] | |
| 162 | 162 | |
| 163 | 163 | # Loop over configs and display unavailable storage first |
| 164 | 164 | for config in configs: |
| 165 | 165 | |
| 166 | 166 | # Create hdu and obs index files |
| 167 | - hdu = os.path.join(self.datapath, config["hduindx"]) | |
| 168 | - obs = os.path.join(self.datapath, config["obsindx"]) | |
| 167 | + hdu = os.path.join(self._datapath, config["hduindx"]) | |
| 168 | + obs = os.path.join(self._datapath, config["obsindx"]) | |
| 169 | 169 | |
| 170 | 170 | filename_hdu = gammalib.GFilename(str(hdu)+"[HDU_INDEX]") |
| 171 | 171 | filename_obs = gammalib.GFilename(str(obs)+"[OBS_INDEX]") |
| 172 | 172 | |
| 173 | 173 | # Check if index files are available |
| 174 | 174 | if not (filename_hdu.is_fits() and filename_obs.is_fits()): |
| 175 | - self.log.parformat(str(config["name"])) | |
| 176 | - self.log("Not available") | |
| 177 | - self.log("\n") | |
| 175 | + self._log.parformat(str(config["name"])) | |
| 176 | + self._log("Not available") | |
| 177 | + self._log("\n") | |
| 178 | 178 | |
| 179 | 179 | |
| 180 | - self.log("\n") | |
| 181 | - self.log.header2("Available data configs") | |
| 180 | + self._log("\n") | |
| 181 | + self._log.header2("Available data configs") | |
| 182 | 182 | |
| 183 | 183 | # Loop over configs and log available configs |
| 184 | 184 | for config in configs: |
| 185 | 185 | |
| 186 | 186 | # Create hdu and obs index files |
| 187 | - hdu = os.path.join(self.datapath, config["hduindx"]) | |
| 188 | - obs = os.path.join(self.datapath, config["obsindx"]) | |
| 187 | + hdu = os.path.join(self._datapath, config["hduindx"]) | |
| 188 | + obs = os.path.join(self._datapath, config["obsindx"]) | |
| 189 | 189 | |
| 190 | 190 | filename_hdu = gammalib.GFilename(str(hdu)+"[HDU_INDEX]") |
| 191 | 191 | filename_obs = gammalib.GFilename(str(obs)+"[OBS_INDEX]") |
| ... | ... | @@ -194,30 +194,30 @@ class csiactdata(ctools.cscript): |
| 194 | 194 | if (filename_hdu.is_fits() and filename_obs.is_fits()): |
| 195 | 195 | |
| 196 | 196 | # Log data information |
| 197 | - self.log("\n") | |
| 198 | - self.log.header3(str(config["name"])) | |
| 197 | + self._log("\n") | |
| 198 | + self._log.header3(str(config["name"])) | |
| 199 | 199 | |
| 200 | 200 | # Print important informations first |
| 201 | - self.log.parformat("Name") | |
| 202 | - self.log(str(config["name"])) | |
| 203 | - self.log("\n") | |
| 204 | - self.log.parformat("Observation index") | |
| 205 | - self.log(str(config["obsindx"])) | |
| 206 | - self.log("\n") | |
| 207 | - self.log.parformat("HDU index") | |
| 208 | - self.log(str(config["hduindx"])) | |
| 209 | - self.log("\n") | |
| 201 | + self._log.parformat("Name") | |
| 202 | + self._log(str(config["name"])) | |
| 203 | + self._log("\n") | |
| 204 | + self._log.parformat("Observation index") | |
| 205 | + self._log(str(config["obsindx"])) | |
| 206 | + self._log("\n") | |
| 207 | + self._log.parformat("HDU index") | |
| 208 | + self._log(str(config["hduindx"])) | |
| 209 | + self._log("\n") | |
| 210 | 210 | |
| 211 | 211 | # Append to available names |
| 212 | - self.prodnames.append(str(config["name"])) | |
| 212 | + self._prodnames.append(str(config["name"])) | |
| 213 | 213 | |
| 214 | 214 | # Print additional information |
| 215 | 215 | for key in config: |
| 216 | 216 | if key in ["name","hduindx","obsindx"]: |
| 217 | 217 | continue |
| 218 | - self.log.parformat(str(key)) | |
| 219 | - self.log(str(config[key])) | |
| 220 | - self.log("\n") | |
| 218 | + self._log.parformat(str(key)) | |
| 219 | + self._log(str(config[key])) | |
| 220 | + self._log("\n") | |
| 221 | 221 | |
| 222 | 222 | # Return |
| 223 | 223 | return |
| ... | ... | @@ -228,20 +228,19 @@ class csiactdata(ctools.cscript): |
| 228 | 228 | """ |
| 229 | 229 | |
| 230 | 230 | # Return |
| 231 | - return self.prodnames | |
| 231 | + return self._prodnames | |
| 232 | + | |
| 232 | 233 | |
| 233 | 234 | # ======================== # |
| 234 | 235 | # Main routine entry point # |
| 235 | 236 | # ======================== # |
| 236 | 237 | if __name__ == '__main__': |
| 237 | - """ | |
| 238 | - Shows data storage information | |
| 239 | - """ | |
| 238 | + | |
| 240 | 239 | # Create instance of application |
| 241 | 240 | app = csiactdata(sys.argv) |
| 242 | 241 | |
| 243 | 242 | # Open logfile |
| 244 | - app.logFileOpen() | |
| 243 | + app._logFileOpen() | |
| 245 | 244 | |
| 246 | 245 | # Execute application |
| 247 | 246 | app.execute() | ... | ... |
cscripts/csiactobs.py
| ... | ... | @@ -42,31 +42,31 @@ class csiactobs(ctools.cscript): |
| 42 | 42 | Constructor. |
| 43 | 43 | """ |
| 44 | 44 | # Set name and version |
| 45 | - self.name = "csiactobs" | |
| 46 | - self.version = "1.1.0" | |
| 45 | + self._name = "csiactobs" | |
| 46 | + self._version = "1.1.0" | |
| 47 | 47 | |
| 48 | 48 | # Initialise some members |
| 49 | - self.m_ebounds = gammalib.GEbounds() | |
| 50 | - self.datapath = os.getenv("VHEFITS","") | |
| 51 | - self.inmodels = None | |
| 52 | - self.xml = gammalib.GXml() | |
| 53 | - self.models = gammalib.GModels() | |
| 54 | - self.m_runlist = [] | |
| 49 | + self._ebounds = gammalib.GEbounds() | |
| 50 | + self._datapath = os.getenv("VHEFITS","") | |
| 51 | + self._inmodels = None | |
| 52 | + self._xml = gammalib.GXml() | |
| 53 | + self._models = gammalib.GModels() | |
| 54 | + self._runlist = [] | |
| 55 | 55 | |
| 56 | 56 | # Make sure that parfile exists |
| 57 | - file = self.parfile() | |
| 57 | + file = self._parfile() | |
| 58 | 58 | |
| 59 | 59 | # Initialise application |
| 60 | 60 | if len(argv) == 0: |
| 61 | - ctools.cscript.__init__(self, self.name, self.version) | |
| 61 | + ctools.cscript.__init__(self, self._name, self._version) | |
| 62 | 62 | elif len(argv) == 1: |
| 63 | - ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 63 | + ctools.cscript.__init__(self, self._name, self._version, *argv) | |
| 64 | 64 | else: |
| 65 | 65 | raise TypeError("Invalid number of arguments given.") |
| 66 | 66 | |
| 67 | 67 | # Set logger properties |
| 68 | - self.log_header() | |
| 69 | - self.log.date(True) | |
| 68 | + self._log_header() | |
| 69 | + self._log.date(True) | |
| 70 | 70 | |
| 71 | 71 | # Return |
| 72 | 72 | return |
| ... | ... | @@ -78,13 +78,13 @@ class csiactobs(ctools.cscript): |
| 78 | 78 | # Return |
| 79 | 79 | return |
| 80 | 80 | |
| 81 | - def parfile(self): | |
| 81 | + def _parfile(self): | |
| 82 | 82 | """ |
| 83 | 83 | Check if parfile exists. If parfile does not exist then create a |
| 84 | 84 | default parfile. This kluge avoids shipping the cscript with a parfile. |
| 85 | 85 | """ |
| 86 | 86 | # Set parfile name |
| 87 | - parfile = self.name+".par" | |
| 87 | + parfile = self._name+".par" | |
| 88 | 88 | |
| 89 | 89 | try: |
| 90 | 90 | pars = gammalib.GApplicationPars(parfile) |
| ... | ... | @@ -94,7 +94,7 @@ class csiactobs(ctools.cscript): |
| 94 | 94 | |
| 95 | 95 | # Create default parfile |
| 96 | 96 | pars = gammalib.GApplicationPars() |
| 97 | - pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data is located")) | |
| 97 | + pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data is located")) | |
| 98 | 98 | pars.append(gammalib.GApplicationPar("prodname","s","a","","","","Data storage name (Run csiactdata to view your options)")) |
| 99 | 99 | pars.append(gammalib.GApplicationPar("infile","f","a","runlist.lis","","","Runlist file")) |
| 100 | 100 | pars.append(gammalib.GApplicationPar("inmodel","f","h","NONE","","","Input model XML file (optional)")) |
| ... | ... | @@ -122,74 +122,74 @@ class csiactobs(ctools.cscript): |
| 122 | 122 | # Return |
| 123 | 123 | return |
| 124 | 124 | |
| 125 | - def get_parameters(self): | |
| 125 | + def _get_parameters(self): | |
| 126 | 126 | """ |
| 127 | 127 | Get parameters from parfile and setup the observation. |
| 128 | 128 | """ |
| 129 | 129 | |
| 130 | - if self.datapath == "": | |
| 131 | - self.datapath = self["datapath"].string() | |
| 130 | + if self._datapath == "": | |
| 131 | + self._datapath = self["datapath"].string() | |
| 132 | 132 | |
| 133 | 133 | # Check for input models |
| 134 | 134 | if not self["inmodel"].filename() == "NONE": |
| 135 | - self.inmodels = gammalib.GModels(self["inmodel"].filename()) | |
| 135 | + self._inmodels = gammalib.GModels(self["inmodel"].filename()) | |
| 136 | 136 | |
| 137 | 137 | # Expand environment |
| 138 | - self.datapath = gammalib.expand_env(self.datapath) | |
| 138 | + self._datapath = gammalib.expand_env(self._datapath) | |
| 139 | 139 | |
| 140 | 140 | # Read FITS production |
| 141 | - self.m_prodname = self["prodname"].string() | |
| 141 | + self._prodname = self["prodname"].string() | |
| 142 | 142 | |
| 143 | 143 | # Read runlist file if list not already filled |
| 144 | - if len(self.m_runlist) == 0: | |
| 144 | + if len(self._runlist) == 0: | |
| 145 | 145 | |
| 146 | 146 | # Get file name |
| 147 | - self.m_runlistfile = self["infile"].filename() | |
| 147 | + self._runlistfile = self["infile"].filename() | |
| 148 | 148 | |
| 149 | 149 | # Read runlist from file |
| 150 | - runfile = open(self.m_runlistfile.url()) | |
| 150 | + runfile = open(self._runlistfile.url()) | |
| 151 | 151 | for line in runfile.readlines(): |
| 152 | 152 | if len(line) == 0: |
| 153 | 153 | continue |
| 154 | 154 | if line[0] == '#': |
| 155 | 155 | continue |
| 156 | 156 | if len(line.split()) > 0: |
| 157 | - self.m_runlist.append(line.split()[0]) | |
| 157 | + self._runlist.append(line.split()[0]) | |
| 158 | 158 | runfile.close() |
| 159 | 159 | |
| 160 | 160 | # Read number of background parameters |
| 161 | - self.m_bkgpars = self["bkgpars"].integer() | |
| 161 | + self._bkgpars = self["bkgpars"].integer() | |
| 162 | 162 | |
| 163 | 163 | # Output model file |
| 164 | - self.m_outmodel = self["outmodel"].filename() | |
| 164 | + self._outmodel = self["outmodel"].filename() | |
| 165 | 165 | |
| 166 | 166 | # Observation outfile |
| 167 | - self.m_outobs = self["outobs"].filename() | |
| 167 | + self._outobs = self["outobs"].filename() | |
| 168 | 168 | |
| 169 | 169 | # Master index file name |
| 170 | - self.m_master_indx = self["master_indx"].string() | |
| 170 | + self._master_indx = self["master_indx"].string() | |
| 171 | 171 | |
| 172 | 172 | # Read flag for background scaling factor |
| 173 | - self.m_use_bkg_scale = self["bkg_scale"].boolean() | |
| 173 | + self._use_bkg_scale = self["bkg_scale"].boolean() | |
| 174 | 174 | |
| 175 | 175 | # Read hierarchy of file loading |
| 176 | - self.m_ev_hiera = self["ev_hiera"].string().split("|") | |
| 177 | - self.m_aeff_hiera = self["aeff_hiera"].string().split("|") | |
| 178 | - self.m_psf_hiera = self["psf_hiera"].string().split("|") | |
| 179 | - self.m_bkg_hiera = self["bkg_hiera"].string().split("|") | |
| 180 | - self.m_edisp_hiera = self["edisp_hiera"].string().split("|") | |
| 181 | - self.m_bkg_mod_hiera = self["bkg_mod_hiera"].string().split("|") | |
| 176 | + self._ev_hiera = self["ev_hiera"].string().split("|") | |
| 177 | + self._aeff_hiera = self["aeff_hiera"].string().split("|") | |
| 178 | + self._psf_hiera = self["psf_hiera"].string().split("|") | |
| 179 | + self._bkg_hiera = self["bkg_hiera"].string().split("|") | |
| 180 | + self._edisp_hiera = self["edisp_hiera"].string().split("|") | |
| 181 | + self._bkg_mod_hiera = self["bkg_mod_hiera"].string().split("|") | |
| 182 | 182 | |
| 183 | 183 | # Read hidden background parameters |
| 184 | - self.m_bkg_gauss_norm = self["bkg_gauss_norm"].real() | |
| 185 | - self.m_bkg_gauss_index = self["bkg_gauss_index"].real() | |
| 186 | - self.m_bkg_gauss_sigma = self["bkg_gauss_sigma"].real() | |
| 187 | - self.m_bkg_aeff_index = self["bkg_aeff_index"].real() | |
| 188 | - self.m_bkg_aeff_norm = self["bkg_aeff_norm"].real() | |
| 189 | - self.m_bkg_range_factor = self["bkg_range_factor"].real() | |
| 184 | + self._bkg_gauss_norm = self["bkg_gauss_norm"].real() | |
| 185 | + self._bkg_gauss_index = self["bkg_gauss_index"].real() | |
| 186 | + self._bkg_gauss_sigma = self["bkg_gauss_sigma"].real() | |
| 187 | + self._bkg_aeff_index = self["bkg_aeff_index"].real() | |
| 188 | + self._bkg_aeff_norm = self["bkg_aeff_norm"].real() | |
| 189 | + self._bkg_range_factor = self["bkg_range_factor"].real() | |
| 190 | 190 | |
| 191 | 191 | # Open master index file and look for prodname |
| 192 | - master_file = os.path.join(self.datapath, self.m_master_indx) | |
| 192 | + master_file = os.path.join(self._datapath, self._master_indx) | |
| 193 | 193 | if not os.path.isfile(master_file): |
| 194 | 194 | raise RuntimeError("FITS data store not available. No master index file found. Make sure the file is copied from the server and your datapath is set correctly.") |
| 195 | 195 | |
| ... | ... | @@ -203,38 +203,37 @@ class csiactobs(ctools.cscript): |
| 203 | 203 | configs = data["datasets"] |
| 204 | 204 | |
| 205 | 205 | # Initialise HDUs |
| 206 | - self.m_hdu_index = self.m_obs_index = "" | |
| 206 | + self._hdu_index = self._obs_index = "" | |
| 207 | 207 | |
| 208 | 208 | # Get HDUs |
| 209 | 209 | for config in configs: |
| 210 | - if self.m_prodname == config["name"]: | |
| 211 | - self.m_hdu_index = str(os.path.join(self.datapath, config["hduindx"])) | |
| 212 | - self.m_obs_index = str(os.path.join(self.datapath, config["obsindx"])) | |
| 210 | + if self._prodname == config["name"]: | |
| 211 | + self._hdu_index = str(os.path.join(self._datapath, config["hduindx"])) | |
| 212 | + self._obs_index = str(os.path.join(self._datapath, config["obsindx"])) | |
| 213 | 213 | break |
| 214 | 214 | |
| 215 | 215 | # Check HDUs |
| 216 | - if self.m_hdu_index == "" or self.m_obs_index == "": | |
| 217 | - raise RuntimeError("*** ERROR: FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") | |
| 218 | - filename = gammalib.GFilename(self.m_hdu_index+"[HDU_INDEX]") | |
| 216 | + if self._hdu_index == "" or self._obs_index == "": | |
| 217 | + raise RuntimeError("*** ERROR: FITS data store \""+self._prodname+"\" not available. Run csiactdata to get a list of available storage names") | |
| 218 | + filename = gammalib.GFilename(self._hdu_index+"[HDU_INDEX]") | |
| 219 | 219 | if not filename.is_fits(): |
| 220 | - raise RuntimeError("*** ERROR: HDU index file \""+self.m_hdu_index+"[HDU_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.") | |
| 220 | + raise RuntimeError("*** ERROR: HDU index file \""+self._hdu_index+"[HDU_INDEX]\" for FITS data store \""+self._prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.") | |
| 221 | 221 | |
| 222 | 222 | # Check for existence of "BKG_SCALE" in the observation index file if required |
| 223 | - if self.m_use_bkg_scale: | |
| 224 | - filename = gammalib.GFilename(self.m_obs_index+"[OBS_INDEX]") | |
| 223 | + if self._use_bkg_scale: | |
| 224 | + filename = gammalib.GFilename(self._obs_index+"[OBS_INDEX]") | |
| 225 | 225 | if filename.is_fits(): |
| 226 | - fits = gammalib.GFits(self.m_obs_index) | |
| 226 | + fits = gammalib.GFits(self._obs_index) | |
| 227 | 227 | if not fits["OBS_INDEX"].contains("BKG_SCALE"): |
| 228 | - self.m_use_bkg_scale = False | |
| 228 | + self._use_bkg_scale = False | |
| 229 | 229 | fits.close() |
| 230 | 230 | else: |
| 231 | - self.m_use_bkg_scale = False | |
| 231 | + self._use_bkg_scale = False | |
| 232 | 232 | |
| 233 | 233 | # Create base data directory from hdu index file location |
| 234 | - self.subdir = os.path.dirname(self.m_hdu_index) | |
| 235 | - self.m_log = False # Logging in client tools | |
| 236 | - self.m_debug = False # Debugging in client tools | |
| 237 | - self.m_clobber = self["clobber"].boolean() | |
| 234 | + self._subdir = os.path.dirname(self._hdu_index) | |
| 235 | + self._debug = False # Debugging in client tools | |
| 236 | + self._clobber = self["clobber"].boolean() | |
| 238 | 237 | |
| 239 | 238 | # Return |
| 240 | 239 | return |
| ... | ... | @@ -248,7 +247,7 @@ class csiactobs(ctools.cscript): |
| 248 | 247 | try: |
| 249 | 248 | |
| 250 | 249 | # Store a copy of input argument |
| 251 | - self.m_runlist = list(runlist) | |
| 250 | + self._runlist = list(runlist) | |
| 252 | 251 | |
| 253 | 252 | except: |
| 254 | 253 | |
| ... | ... | @@ -258,15 +257,15 @@ class csiactobs(ctools.cscript): |
| 258 | 257 | # Return |
| 259 | 258 | return |
| 260 | 259 | |
| 261 | - def background_spectrum(self, run, prefactor, index, emin = 0.01, emax = 100.0): | |
| 260 | + def _background_spectrum(self, run, prefactor, index, emin = 0.01, emax = 100.0): | |
| 262 | 261 | |
| 263 | 262 | # Handle constant spectral model |
| 264 | - if index == 0.0 and self.m_bkgpars <= 1: | |
| 263 | + if index == 0.0 and self._bkgpars <= 1: | |
| 265 | 264 | spec = gammalib.GModelSpectralConst() |
| 266 | - spec["Value"].min(prefactor / self.m_bkg_range_factor) | |
| 267 | - spec["Value"].max(prefactor * self.m_bkg_range_factor) | |
| 265 | + spec["Value"].min(prefactor / self._bkg_range_factor) | |
| 266 | + spec["Value"].max(prefactor * self._bkg_range_factor) | |
| 268 | 267 | spec["Value"].value(prefactor) |
| 269 | - if self.m_bkgpars == 0: | |
| 268 | + if self._bkgpars == 0: | |
| 270 | 269 | spec["Value"].fix() |
| 271 | 270 | else: |
| 272 | 271 | spec["Value"].free() |
| ... | ... | @@ -274,7 +273,7 @@ class csiactobs(ctools.cscript): |
| 274 | 273 | else: |
| 275 | 274 | |
| 276 | 275 | # Create power law model |
| 277 | - if self.m_bkgpars <= 2: | |
| 276 | + if self._bkgpars <= 2: | |
| 278 | 277 | e = gammalib.GEnergy(1.0,"TeV") |
| 279 | 278 | spec = gammalib.GModelSpectralPlaw(prefactor, index, e) |
| 280 | 279 | |
| ... | ... | @@ -286,10 +285,10 @@ class csiactobs(ctools.cscript): |
| 286 | 285 | spec[1].max(5.0) |
| 287 | 286 | |
| 288 | 287 | # Set number of free parameters |
| 289 | - if self.m_bkgpars == 0: | |
| 288 | + if self._bkgpars == 0: | |
| 290 | 289 | spec[0].fix() |
| 291 | 290 | spec[1].fix() |
| 292 | - elif self.m_bkgpars == 1: | |
| 291 | + elif self._bkgpars == 1: | |
| 293 | 292 | spec[0].free() |
| 294 | 293 | spec[1].fix() |
| 295 | 294 | else: |
| ... | ... | @@ -303,7 +302,7 @@ class csiactobs(ctools.cscript): |
| 303 | 302 | |
| 304 | 303 | # Create spectral model and energy values |
| 305 | 304 | spec = gammalib.GModelSpectralNodes() |
| 306 | - bounds = gammalib.GEbounds(self.m_bkgpars,gammalib.GEnergy(emin,"TeV"),gammalib.GEnergy(emax,"TeV"), True) | |
| 305 | + bounds = gammalib.GEbounds(self._bkgpars,gammalib.GEnergy(emin,"TeV"),gammalib.GEnergy(emax,"TeV"), True) | |
| 307 | 306 | for i in range(bounds.size()): |
| 308 | 307 | energy = bounds.elogmean(i) |
| 309 | 308 | value = plaw.eval(energy, gammalib.GTime()) |
| ... | ... | @@ -313,41 +312,41 @@ class csiactobs(ctools.cscript): |
| 313 | 312 | if "Energy" in par.name(): |
| 314 | 313 | par.fix() |
| 315 | 314 | elif "Intensity" in par.name(): |
| 316 | - par.min(value / self.m_bkg_range_factor) | |
| 317 | - par.max(value * self.m_bkg_range_factor) | |
| 315 | + par.min(value / self._bkg_range_factor) | |
| 316 | + par.max(value * self._bkg_range_factor) | |
| 318 | 317 | |
| 319 | 318 | # Return spectrum |
| 320 | 319 | return spec |
| 321 | 320 | |
| 322 | - def iact_background(self, telescope, obs_id, bkg_scale, bkgtype, emin=0.01, emax=100): | |
| 321 | + def _iact_background(self, telescope, obs_id, bkg_scale, bkgtype, emin=0.01, emax=100): | |
| 323 | 322 | |
| 324 | 323 | # handle IrfBackground |
| 325 | 324 | if bkgtype == "irf": |
| 326 | 325 | prefactor = 1.0 |
| 327 | 326 | index = 0.0 |
| 328 | 327 | prefactor *= bkg_scale |
| 329 | - spec = self.background_spectrum(obs_id, prefactor, index, emin, emax) | |
| 328 | + spec = self._background_spectrum(obs_id, prefactor, index, emin, emax) | |
| 330 | 329 | |
| 331 | 330 | # Create background model instance |
| 332 | 331 | bck = gammalib.GCTAModelIrfBackground(spec) |
| 333 | 332 | |
| 334 | 333 | # Set AeffBackground |
| 335 | 334 | elif bkgtype == "aeff": |
| 336 | - prefactor = bkg_scale * self.m_bkg_aeff_norm | |
| 337 | - spec = self.background_spectrum(obs_id, prefactor, self.m_bkg_aeff_index, emin, emax) | |
| 335 | + prefactor = bkg_scale * self._bkg_aeff_norm | |
| 336 | + spec = self._background_spectrum(obs_id, prefactor, self._bkg_aeff_index, emin, emax) | |
| 338 | 337 | |
| 339 | 338 | # Create background model instance |
| 340 | 339 | bck = gammalib.GCTAModelAeffBackground(spec) |
| 341 | 340 | |
| 342 | 341 | # Set Gaussian Background |
| 343 | 342 | elif bkgtype == "gauss": |
| 344 | - prefactor = bkg_scale * self.m_bkg_gauss_norm | |
| 345 | - spec = self.background_spectrum(obs_id, prefactor, self.m_bkg_gauss_index, emin, emax) | |
| 346 | - radial = gammalib.GCTAModelRadialGauss(self.m_bkg_gauss_sigma) | |
| 343 | + prefactor = bkg_scale * self._bkg_gauss_norm | |
| 344 | + spec = self._background_spectrum(obs_id, prefactor, self._bkg_gauss_index, emin, emax) | |
| 345 | + radial = gammalib.GCTAModelRadialGauss(self._bkg_gauss_sigma) | |
| 347 | 346 | bck = gammalib.GCTAModelRadialAcceptance(radial, spec) |
| 348 | 347 | |
| 349 | 348 | else: |
| 350 | - sys.exit("Background type \""+self.bkgtype+"\" unsupported") | |
| 349 | + sys.exit("Background type \""+self._bkgtype+"\" unsupported") | |
| 351 | 350 | |
| 352 | 351 | # Copy model |
| 353 | 352 | model = bck.clone() |
| ... | ... | @@ -371,7 +370,7 @@ class csiactobs(ctools.cscript): |
| 371 | 370 | """ |
| 372 | 371 | Returns runlist energy range |
| 373 | 372 | """ |
| 374 | - return self.m_ebounds | |
| 373 | + return self._ebounds | |
| 375 | 374 | |
| 376 | 375 | def obs(self): |
| 377 | 376 | """ |
| ... | ... | @@ -381,11 +380,11 @@ class csiactobs(ctools.cscript): |
| 381 | 380 | obs = gammalib.GObservations() |
| 382 | 381 | |
| 383 | 382 | # Read observations if XML is filled |
| 384 | - if self.xml.size(): | |
| 385 | - obs.read(self.xml) | |
| 383 | + if self._xml.size(): | |
| 384 | + obs.read(self._xml) | |
| 386 | 385 | |
| 387 | 386 | # Assign models |
| 388 | - obs.models(self.models) | |
| 387 | + obs.models(self._models) | |
| 389 | 388 | |
| 390 | 389 | # Return observations |
| 391 | 390 | return obs |
| ... | ... | @@ -399,7 +398,7 @@ class csiactobs(ctools.cscript): |
| 399 | 398 | self.run() |
| 400 | 399 | |
| 401 | 400 | # Save residual map |
| 402 | - self.save(self.m_outobs, self.m_clobber) | |
| 401 | + self.save(self._outobs, self._clobber) | |
| 403 | 402 | |
| 404 | 403 | # Return |
| 405 | 404 | return |
| ... | ... | @@ -409,41 +408,41 @@ class csiactobs(ctools.cscript): |
| 409 | 408 | Run the script. |
| 410 | 409 | """ |
| 411 | 410 | # Switch screen logging on in debug mode |
| 412 | - if self.logDebug(): | |
| 413 | - self.log.cout(True) | |
| 411 | + if self._logDebug(): | |
| 412 | + self._log.cout(True) | |
| 414 | 413 | |
| 415 | 414 | # Get parameters |
| 416 | - self.get_parameters() | |
| 415 | + self._get_parameters() | |
| 417 | 416 | |
| 418 | 417 | # Write input parameters into logger |
| 419 | - if self.logTerse(): | |
| 420 | - self.log_parameters() | |
| 421 | - self.log("\n") | |
| 418 | + if self._logTerse(): | |
| 419 | + self._log_parameters() | |
| 420 | + self._log("\n") | |
| 422 | 421 | |
| 423 | 422 | # Clear models |
| 424 | - self.models.clear() | |
| 423 | + self._models.clear() | |
| 425 | 424 | |
| 426 | 425 | # Clear xml file and append an observation list |
| 427 | - self.xml.clear() | |
| 428 | - self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) | |
| 429 | - lib = self.xml.element("observation_list", 0) | |
| 426 | + self._xml.clear() | |
| 427 | + self._xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) | |
| 428 | + lib = self._xml.element("observation_list", 0) | |
| 430 | 429 | |
| 431 | 430 | # Log output |
| 432 | - if self.logTerse(): | |
| 433 | - self.log("\n") | |
| 434 | - self.log.header1("Looping over "+str(len(self.m_runlist))+" runs") | |
| 431 | + if self._logTerse(): | |
| 432 | + self._log("\n") | |
| 433 | + self._log.header1("Looping over "+str(len(self._runlist))+" runs") | |
| 435 | 434 | |
| 436 | 435 | # Initialise energy range values for logging |
| 437 | - self.m_ebounds.clear() | |
| 436 | + self._ebounds.clear() | |
| 438 | 437 | |
| 439 | 438 | # Loop over runs |
| 440 | - for obs_id in self.m_runlist: | |
| 439 | + for obs_id in self._runlist: | |
| 441 | 440 | |
| 442 | 441 | # Create selection string |
| 443 | 442 | obs_selection = "[OBS_ID=="+str(obs_id)+"]" |
| 444 | 443 | |
| 445 | 444 | # Open HDU index file |
| 446 | - hduindx = gammalib.GFits(self.m_hdu_index+"[HDU_INDEX]"+obs_selection) | |
| 445 | + hduindx = gammalib.GFits(self._hdu_index+"[HDU_INDEX]"+obs_selection) | |
| 447 | 446 | hduindx_hdu = hduindx["HDU_INDEX"] |
| 448 | 447 | |
| 449 | 448 | # Initialise files and hdu names |
| ... | ... | @@ -458,80 +457,80 @@ class csiactobs(ctools.cscript): |
| 458 | 457 | |
| 459 | 458 | # Handle events |
| 460 | 459 | index = -1 |
| 461 | - for version in self.m_ev_hiera: | |
| 460 | + for version in self._ev_hiera: | |
| 462 | 461 | n = formats.count(version) |
| 463 | 462 | if n > 0: |
| 464 | 463 | index = formats.index(version) |
| 465 | 464 | break |
| 466 | 465 | if index >= 0: |
| 467 | - eventfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 466 | + eventfile = os.path.join(self._subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 468 | 467 | eventhdu = hduindx_hdu["HDU_NAME"][index] |
| 469 | 468 | eventfile += "["+eventhdu+"]" |
| 470 | 469 | if not gammalib.GFilename(eventfile).is_fits(): |
| 471 | - if self.logTerse(): | |
| 472 | - self.log("Skipping observation "+str(obs_id)+": eventfile \""+eventfile+"\" not found\n") | |
| 470 | + if self._logTerse(): | |
| 471 | + self._log("Skipping observation "+str(obs_id)+": eventfile \""+eventfile+"\" not found\n") | |
| 473 | 472 | continue |
| 474 | 473 | |
| 475 | 474 | # Handle Aeff |
| 476 | 475 | index = -1 |
| 477 | - for version in self.m_aeff_hiera: | |
| 476 | + for version in self._aeff_hiera: | |
| 478 | 477 | n = formats.count(version) |
| 479 | 478 | if n > 0: |
| 480 | 479 | index = formats.index(version) |
| 481 | 480 | break |
| 482 | 481 | if index >= 0: |
| 483 | - aefffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 482 | + aefffile = os.path.join(self._subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 484 | 483 | aeffhdu = hduindx_hdu["HDU_NAME"][index] |
| 485 | 484 | aefffile += "["+aeffhdu+"]" |
| 486 | 485 | if not gammalib.GFilename(aefffile).is_fits(): |
| 487 | - if self.logTerse(): | |
| 488 | - self.log("Skipping observation "+str(obs_id)+": effective area \""+aefffile+"\" not found\n") | |
| 486 | + if self._logTerse(): | |
| 487 | + self._log("Skipping observation "+str(obs_id)+": effective area \""+aefffile+"\" not found\n") | |
| 489 | 488 | continue |
| 490 | 489 | |
| 491 | 490 | # Handle psf |
| 492 | 491 | index = -1 |
| 493 | - for version in self.m_psf_hiera: | |
| 492 | + for version in self._psf_hiera: | |
| 494 | 493 | n = formats.count(version) |
| 495 | 494 | if n > 0: |
| 496 | 495 | index = formats.index(version) |
| 497 | 496 | break |
| 498 | 497 | if index >= 0: |
| 499 | - psffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 498 | + psffile = os.path.join(self._subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 500 | 499 | psffile += "["+hduindx_hdu["HDU_NAME"][index]+"]" |
| 501 | 500 | if not gammalib.GFilename(psffile).is_fits(): |
| 502 | - if self.logTerse(): | |
| 503 | - self.log("Skipping observation "+str(obs_id)+": point spread function \""+psffile+"\" not found\n") | |
| 501 | + if self._logTerse(): | |
| 502 | + self._log("Skipping observation "+str(obs_id)+": point spread function \""+psffile+"\" not found\n") | |
| 504 | 503 | continue |
| 505 | 504 | |
| 506 | 505 | # Handle edisp |
| 507 | 506 | index = -1 |
| 508 | - for version in self.m_edisp_hiera: | |
| 507 | + for version in self._edisp_hiera: | |
| 509 | 508 | n = formats.count(version) |
| 510 | 509 | if n > 0: |
| 511 | 510 | index = formats.index(version) |
| 512 | 511 | break |
| 513 | 512 | if index >= 0: |
| 514 | - edispfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 513 | + edispfile = os.path.join(self._subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 515 | 514 | edispfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" |
| 516 | 515 | if not gammalib.GFilename(edispfile).is_fits(): |
| 517 | - if self.logTerse(): | |
| 518 | - self.log("Warning: observation "+str(obs_id)+" has no energy dispersion \""+edispfile+"\" information\n") | |
| 516 | + if self._logTerse(): | |
| 517 | + self._log("Warning: observation "+str(obs_id)+" has no energy dispersion \""+edispfile+"\" information\n") | |
| 519 | 518 | edispfile = "" |
| 520 | 519 | |
| 521 | 520 | # Handle background |
| 522 | 521 | index = -1 |
| 523 | - bkg_mod_hierarchy = list(self.m_bkg_mod_hiera) | |
| 524 | - for version in self.m_bkg_hiera: | |
| 522 | + bkg_mod_hierarchy = list(self._bkg_mod_hiera) | |
| 523 | + for version in self._bkg_hiera: | |
| 525 | 524 | n = formats.count(version) |
| 526 | 525 | if n > 0: |
| 527 | 526 | index = formats.index(version) |
| 528 | 527 | break |
| 529 | 528 | if index >= 0: |
| 530 | - bkgfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 529 | + bkgfile = os.path.join(self._subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 531 | 530 | bkgfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" |
| 532 | 531 | if not gammalib.GFilename(bkgfile).is_fits(): |
| 533 | - if self.logTerse(): | |
| 534 | - self.log("Warning: observation "+str(obs_id)+" has no background information (file=\""+bkgfile+"\"). IRF background cannot be used\n") | |
| 532 | + if self._logTerse(): | |
| 533 | + self._log("Warning: observation "+str(obs_id)+" has no background information (file=\""+bkgfile+"\"). IRF background cannot be used\n") | |
| 535 | 534 | bkgfile = "" |
| 536 | 535 | if "irf" in bkg_mod_hierarchy: |
| 537 | 536 | bkg_mod_hierarchy.remove("irf") |
| ... | ... | @@ -541,8 +540,8 @@ class csiactobs(ctools.cscript): |
| 541 | 540 | |
| 542 | 541 | # Handle background scale information if available |
| 543 | 542 | bkg_scale = 1.0 |
| 544 | - if self.m_use_bkg_scale: | |
| 545 | - obsindx = gammalib.GFits(self.m_obs_index+"[OBS_INDEX]"+obs_selection) | |
| 543 | + if self._use_bkg_scale: | |
| 544 | + obsindx = gammalib.GFits(self._obs_index+"[OBS_INDEX]"+obs_selection) | |
| 546 | 545 | bkg_scale = obsindx["OBS_INDEX"]["BKG_SCALE"][0] |
| 547 | 546 | obsindx.close() |
| 548 | 547 | |
| ... | ... | @@ -567,7 +566,7 @@ class csiactobs(ctools.cscript): |
| 567 | 566 | run_emax = gammalib.GEnergy(aeff_table.real("HI_THRES"), "TeV") |
| 568 | 567 | |
| 569 | 568 | # Append to ebounds |
| 570 | - self.m_ebounds.append(run_emin, run_emax) | |
| 569 | + self._ebounds.append(run_emin, run_emax) | |
| 571 | 570 | |
| 572 | 571 | else: |
| 573 | 572 | # Set default values for energy range |
| ... | ... | @@ -578,21 +577,21 @@ class csiactobs(ctools.cscript): |
| 578 | 577 | aeff_fits.close() |
| 579 | 578 | |
| 580 | 579 | # Append instrumental background model |
| 581 | - self.models.append(self.iact_background(telescope, obs_id, bkg_scale, bkg_mod_hierarchy[0], run_emin.TeV(), run_emax.TeV())) | |
| 580 | + self._models.append(self._iact_background(telescope, obs_id, bkg_scale, bkg_mod_hierarchy[0], run_emin.TeV(), run_emax.TeV())) | |
| 582 | 581 | |
| 583 | 582 | # Logging |
| 584 | - if self.logTerse(): | |
| 585 | - self.log("Adding observation "+str(obs_id)+" (\""+object_name+"\")\n") | |
| 586 | - | |
| 587 | - if self.logExplicit(): | |
| 588 | - self.log(" Event file: "+eventfile+"\n") | |
| 589 | - self.log(" Effective area: "+aefffile+"\n") | |
| 590 | - self.log(" Point spread function: "+psffile+"\n") | |
| 591 | - self.log(" Energy dispersion: "+edispfile+"\n") | |
| 592 | - self.log(" Background file: "+bkgfile+"\n") | |
| 593 | - if self.m_use_bkg_scale: | |
| 594 | - self.log(" Background scale: "+str(bkg_scale)+"\n") | |
| 595 | - self.log("\n") | |
| 583 | + if self._logTerse(): | |
| 584 | + self._log("Adding observation "+str(obs_id)+" (\""+object_name+"\")\n") | |
| 585 | + | |
| 586 | + if self._logExplicit(): | |
| 587 | + self._log(" Event file: "+eventfile+"\n") | |
| 588 | + self._log(" Effective area: "+aefffile+"\n") | |
| 589 | + self._log(" Point spread function: "+psffile+"\n") | |
| 590 | + self._log(" Energy dispersion: "+edispfile+"\n") | |
| 591 | + self._log(" Background file: "+bkgfile+"\n") | |
| 592 | + if self._use_bkg_scale: | |
| 593 | + self._log(" Background scale: "+str(bkg_scale)+"\n") | |
| 594 | + self._log("\n") | |
| 596 | 595 | |
| 597 | 596 | # Append observation to XML and set attributes |
| 598 | 597 | obs = lib.append("observation"); |
| ... | ... | @@ -631,37 +630,37 @@ class csiactobs(ctools.cscript): |
| 631 | 630 | if lib.size(): |
| 632 | 631 | |
| 633 | 632 | # Log header of energy range |
| 634 | - if self.logTerse(): | |
| 635 | - self.log("\n") | |
| 636 | - self.log.header3("Energy range of obervation list") | |
| 633 | + if self._logTerse(): | |
| 634 | + self._log("\n") | |
| 635 | + self._log.header3("Energy range of obervation list") | |
| 637 | 636 | |
| 638 | 637 | # Logging if energy range is available |
| 639 | - if self.m_ebounds.size() > 0: | |
| 638 | + if self._ebounds.size() > 0: | |
| 640 | 639 | |
| 641 | 640 | # Write energy range into log file |
| 642 | - self.log(str(self.m_ebounds.emin())+" - "+str(self.m_ebounds.emax())) | |
| 643 | - self.log("\n") | |
| 641 | + self._log(str(self._ebounds.emin())+" - "+str(self._ebounds.emax())) | |
| 642 | + self._log("\n") | |
| 644 | 643 | |
| 645 | 644 | else: |
| 646 | 645 | |
| 647 | 646 | # Write 'not available' into log file |
| 648 | - self.log("not available") | |
| 649 | - self.log("\n") | |
| 647 | + self._log("not available") | |
| 648 | + self._log("\n") | |
| 650 | 649 | |
| 651 | 650 | else: |
| 652 | - self.log.header2("WARNING: No observation from given runlist available") | |
| 651 | + self._log.header2("WARNING: No observation from given runlist available") | |
| 653 | 652 | |
| 654 | 653 | # Append models provided by 'inmodels' if necessary |
| 655 | - if not self.inmodels == None: | |
| 656 | - if self.logTerse(): | |
| 657 | - self.log("\n") | |
| 658 | - self.log.header1("Appending models") | |
| 654 | + if not self._inmodels == None: | |
| 655 | + if self._logTerse(): | |
| 656 | + self._log("\n") | |
| 657 | + self._log.header1("Appending models") | |
| 659 | 658 | |
| 660 | 659 | # Loop over input models |
| 661 | - for model in self.inmodels: | |
| 662 | - if self.logTerse(): | |
| 663 | - self.log.header3("Adding model \""+model.name()+"\"") | |
| 664 | - self.models.append(model) | |
| 660 | + for model in self._inmodels: | |
| 661 | + if self._logTerse(): | |
| 662 | + self._log.header3("Adding model \""+model.name()+"\"") | |
| 663 | + self._models.append(model) | |
| 665 | 664 | |
| 666 | 665 | # Return |
| 667 | 666 | return |
| ... | ... | @@ -669,10 +668,10 @@ class csiactobs(ctools.cscript): |
| 669 | 668 | def save(self,outfile,clobber): |
| 670 | 669 | |
| 671 | 670 | # Save observation XML file |
| 672 | - self.xml.save(outfile) | |
| 671 | + self._xml.save(outfile) | |
| 673 | 672 | |
| 674 | 673 | # Save model XML file |
| 675 | - self.models.save(self.m_outmodel) | |
| 674 | + self._models.save(self._outmodel) | |
| 676 | 675 | |
| 677 | 676 | # Return |
| 678 | 677 | return |
| ... | ... | @@ -682,14 +681,12 @@ class csiactobs(ctools.cscript): |
| 682 | 681 | # Main routine entry point # |
| 683 | 682 | # ======================== # |
| 684 | 683 | if __name__ == '__main__': |
| 685 | - """ | |
| 686 | - Generates observation file. | |
| 687 | - """ | |
| 684 | + | |
| 688 | 685 | # Create instance of application |
| 689 | 686 | app = csiactobs(sys.argv) |
| 690 | 687 | |
| 691 | 688 | # Open logfile |
| 692 | - app.logFileOpen() | |
| 689 | + app._logFileOpen() | |
| 693 | 690 | |
| 694 | 691 | # Execute application |
| 695 | 692 | app.execute() | ... | ... |
cscripts/cslightcrv.py
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | # ========================================================================== |
| 3 | -# Light curve generation script. | |
| 3 | +# Generates a lightcurve. | |
| 4 | 4 | # |
| 5 | 5 | # Copyright (C) 2014-2016 Michael Mayer |
| 6 | 6 | # |
| ... | ... | @@ -23,51 +23,53 @@ import ctools |
| 23 | 23 | import sys |
| 24 | 24 | |
| 25 | 25 | |
| 26 | -# ============ # | |
| 27 | -# csspec class # | |
| 28 | -# ============ # | |
| 26 | +# ================ # | |
| 27 | +# cslightcrv class # | |
| 28 | +# ================ # | |
| 29 | 29 | class cslightcrv(ctools.cscript): |
| 30 | 30 | """ |
| 31 | + Generates a lightcurve. | |
| 32 | + | |
| 31 | 33 | This class implements the creation of a light curve. It derives from |
| 32 | 34 | the ctools.cscript class which provides support for parameter files, |
| 33 | 35 | command line arguments, and logging. In that way the Python script |
| 34 | 36 | behaves just as a regular ctool. |
| 35 | 37 | """ |
| 38 | + | |
| 39 | + # Constructors and destructors | |
| 36 | 40 | def __init__(self, *argv): |
| 37 | 41 | """ |
| 38 | 42 | Constructor. |
| 39 | 43 | """ |
| 40 | 44 | |
| 41 | 45 | # Set name |
| 42 | - self.name = "cslightcrv" | |
| 43 | - self.version = "1.1.0" | |
| 46 | + self._name = "cslightcrv" | |
| 47 | + self._version = "1.1.0" | |
| 44 | 48 | |
| 45 | 49 | # Initialise some members |
| 46 | - self.obs = None | |
| 50 | + self._outfile = "" | |
| 47 | 51 | |
| 48 | - # Initialise some members | |
| 52 | + # Initialise observation | |
| 49 | 53 | if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations): |
| 50 | - self.obs = argv[0] | |
| 51 | - argv = argv[1:] | |
| 54 | + self._obs = argv[0] | |
| 55 | + argv = argv[1:] | |
| 52 | 56 | else: |
| 53 | - self.obs = gammalib.GObservations() | |
| 54 | - self.obs.clear() | |
| 55 | - self.m_outfile = "" | |
| 57 | + self._obs = gammalib.GObservations() | |
| 56 | 58 | |
| 57 | 59 | # Make sure that parfile exists |
| 58 | - file = self.parfile() | |
| 60 | + self._parfile() | |
| 59 | 61 | |
| 60 | 62 | # Initialise application |
| 61 | 63 | if len(argv) == 0: |
| 62 | - ctools.cscript.__init__(self, self.name, self.version) | |
| 64 | + ctools.cscript.__init__(self, self._name, self._version) | |
| 63 | 65 | elif len(argv) ==1: |
| 64 | - ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 66 | + ctools.cscript.__init__(self, self._name, self._version, *argv) | |
| 65 | 67 | else: |
| 66 | 68 | raise TypeError("Invalid number of arguments given.") |
| 67 | 69 | |
| 68 | 70 | # Set logger properties |
| 69 | - self.log_header() | |
| 70 | - self.log.date(True) | |
| 71 | + self._log_header() | |
| 72 | + self._log.date(True) | |
| 71 | 73 | |
| 72 | 74 | # Return |
| 73 | 75 | return |
| ... | ... | @@ -76,20 +78,18 @@ class cslightcrv(ctools.cscript): |
| 76 | 78 | """ |
| 77 | 79 | Destructor. |
| 78 | 80 | """ |
| 79 | - # Write separator into logger | |
| 80 | - if self.logTerse(): | |
| 81 | - self.log("\n") | |
| 82 | - | |
| 83 | 81 | # Return |
| 84 | 82 | return |
| 85 | 83 | |
| 86 | - def parfile(self): | |
| 84 | + | |
| 85 | + # Private methods | |
| 86 | + def _parfile(self): | |
| 87 | 87 | """ |
| 88 | 88 | Check if parfile exists. If parfile does not exist then create a |
| 89 | 89 | default parfile. This kluge avoids shipping the cscript with a parfile. |
| 90 | 90 | """ |
| 91 | 91 | # Set parfile name |
| 92 | - parfile = self.name+".par" | |
| 92 | + parfile = self._name+".par" | |
| 93 | 93 | |
| 94 | 94 | try: |
| 95 | 95 | pars = gammalib.GApplicationPars(parfile) |
| ... | ... | @@ -136,15 +136,15 @@ class cslightcrv(ctools.cscript): |
| 136 | 136 | # Return |
| 137 | 137 | return |
| 138 | 138 | |
| 139 | - def create_tbounds(self): | |
| 139 | + def _create_tbounds(self): | |
| 140 | 140 | |
| 141 | 141 | # Create time bin container |
| 142 | - self.m_tbins = gammalib.GGti() | |
| 142 | + self._tbins = gammalib.GGti() | |
| 143 | 143 | |
| 144 | 144 | # check for binning algorithm |
| 145 | 145 | if self["tbinalg"].string() == "FILE": |
| 146 | 146 | try: |
| 147 | - self.m_tbins.load(self["tbinfile"].filename()) | |
| 147 | + self._tbins.load(self["tbinfile"].filename()) | |
| 148 | 148 | except: |
| 149 | 149 | csv = gammalib.GCsv(self["tbinfile"].filename()) |
| 150 | 150 | for i in range(csv.nrows()): |
| ... | ... | @@ -152,7 +152,7 @@ class cslightcrv(ctools.cscript): |
| 152 | 152 | tmax = gammalib.GTime() |
| 153 | 153 | tmin.mjd(csv.real(i,0)) |
| 154 | 154 | tmax.mjd(csv.real(i,1)) |
| 155 | - self.m_tbins.append(tmin,tmax) | |
| 155 | + self._tbins.append(tmin,tmax) | |
| 156 | 156 | elif self["tbinalg"].string() == "LIN": |
| 157 | 157 | # Use linear time binning |
| 158 | 158 | time_min = self["tmin"].real() |
| ... | ... | @@ -164,165 +164,143 @@ class cslightcrv(ctools.cscript): |
| 164 | 164 | tmin.mjd(time_min + i*step)# ref) |
| 165 | 165 | tmax = gammalib.GTime() |
| 166 | 166 | tmax.mjd(time_min + (i+1)*step)#ref) |
| 167 | - self.m_tbins.append(tmin,tmax) | |
| 167 | + self._tbins.append(tmin,tmax) | |
| 168 | 168 | elif self["tbinalg"].string() == "GTI": |
| 169 | 169 | # Use GTIs of observations |
| 170 | - for obs in self.obs: | |
| 170 | + for obs in self._obs: | |
| 171 | 171 | for i in range(obs.events().gti().size()): |
| 172 | - self.m_tbins.append(obs.events().gti().tstart(i),obs.events().gti().tstop(i)) | |
| 172 | + self._tbins.append(obs.events().gti().tstart(i),obs.events().gti().tstop(i)) | |
| 173 | 173 | else: |
| 174 | 174 | raise AttributeError("tbinalg=\""+self["tbinalg"].string()+"\" unkown. Must be one of \"FILE\", \"LIN\" or \"GTI\"") |
| 175 | 175 | |
| 176 | 176 | # Return |
| 177 | 177 | return |
| 178 | 178 | |
| 179 | - def get_parameters(self): | |
| 179 | + def _get_parameters(self): | |
| 180 | 180 | """ |
| 181 | 181 | Get parameters from parfile and setup the observation. |
| 182 | 182 | """ |
| 183 | 183 | # Set observation if not done before |
| 184 | - if self.obs == None or self.obs.size() == 0: | |
| 184 | + if self._obs == None or self._obs.size() == 0: | |
| 185 | 185 | self._require_inobs("cslightcrv::get_parameters()") |
| 186 | - self.obs = self._get_observations() | |
| 186 | + self._obs = self._get_observations() | |
| 187 | 187 | |
| 188 | 188 | # Set models if we have none |
| 189 | - if self.obs.models().size() == 0: | |
| 190 | - self.obs.models(self["inmodel"].filename()) | |
| 189 | + if self._obs.models().size() == 0: | |
| 190 | + self._obs.models(self["inmodel"].filename()) | |
| 191 | 191 | |
| 192 | 192 | # Get source name |
| 193 | - self.m_srcname = self["srcname"].string() | |
| 193 | + self._srcname = self["srcname"].string() | |
| 194 | 194 | |
| 195 | 195 | # Get energy dispersion flag |
| 196 | - self.m_edisp = self["edisp"].boolean() | |
| 196 | + self._edisp = self["edisp"].boolean() | |
| 197 | 197 | |
| 198 | 198 | # Get time boundaries |
| 199 | - self.create_tbounds() | |
| 199 | + self._create_tbounds() | |
| 200 | 200 | |
| 201 | 201 | # Unbinned or binned analysis? |
| 202 | - self.m_ebins = self["enumbins"].integer() | |
| 203 | - if self.m_ebins == 0: | |
| 204 | - self.m_binned = False | |
| 202 | + self._ebins = self["enumbins"].integer() | |
| 203 | + if self._ebins == 0: | |
| 204 | + self._binned = False | |
| 205 | 205 | else: |
| 206 | - self.m_binned = True | |
| 206 | + self._binned = True | |
| 207 | 207 | |
| 208 | 208 | # Get energy range |
| 209 | - self.m_emin = self["emin"].real() | |
| 210 | - self.m_emax = self["emax"].real() | |
| 209 | + self._emin = self["emin"].real() | |
| 210 | + self._emax = self["emax"].real() | |
| 211 | 211 | |
| 212 | 212 | # Get binning flag |
| 213 | - if self.m_binned: | |
| 214 | - self.m_coordsys = self["coordsys"].string() | |
| 215 | - self.m_proj = self["proj"].string() | |
| 216 | - self.m_xref = self["xref"].real() | |
| 217 | - self.m_yref = self["yref"].real() | |
| 218 | - self.m_nxpix = self["nxpix"].integer() | |
| 219 | - self.m_nypix = self["nypix"].integer() | |
| 220 | - self.m_binsz = self["binsz"].real() | |
| 213 | + if self._binned: | |
| 214 | + self._coordsys = self["coordsys"].string() | |
| 215 | + self._proj = self["proj"].string() | |
| 216 | + self._xref = self["xref"].real() | |
| 217 | + self._yref = self["yref"].real() | |
| 218 | + self._nxpix = self["nxpix"].integer() | |
| 219 | + self._nypix = self["nypix"].integer() | |
| 220 | + self._binsz = self["binsz"].real() | |
| 221 | 221 | |
| 222 | 222 | # Read other parameters |
| 223 | - self.m_outfile = self["outfile"].filename() | |
| 223 | + self._outfile = self["outfile"].filename() | |
| 224 | 224 | |
| 225 | 225 | # Get other parameeters |
| 226 | - self.m_calc_ulimit = self["calc_ulim"].boolean() | |
| 227 | - self.m_calc_ts = self["calc_ts"].boolean() | |
| 228 | - self.m_fix_bkg = self["fix_bkg"].boolean() | |
| 229 | - self.m_fix_srcs = self["fix_srcs"].boolean() | |
| 226 | + self._calc_ulimit = self["calc_ulim"].boolean() | |
| 227 | + self._calc_ts = self["calc_ts"].boolean() | |
| 228 | + self._fix_bkg = self["fix_bkg"].boolean() | |
| 229 | + self._fix_srcs = self["fix_srcs"].boolean() | |
| 230 | 230 | |
| 231 | 231 | # Set some fixed parameters |
| 232 | - self.m_log = False # Logging in client tools | |
| 233 | - self.m_chatter = self["chatter"].integer() | |
| 234 | - self.m_clobber = self["clobber"].boolean() | |
| 235 | - self.m_debug = self["debug"].boolean() | |
| 232 | + self._chatter = self["chatter"].integer() | |
| 233 | + self._clobber = self["clobber"].boolean() | |
| 234 | + self._debug = self["debug"].boolean() | |
| 236 | 235 | |
| 237 | - # Return | |
| 238 | - return | |
| 239 | - | |
| 240 | - def models(self, models): | |
| 241 | - """ | |
| 242 | - Set model. | |
| 243 | - """ | |
| 244 | - # Copy models | |
| 245 | - self.obs.models(models.clone()) | |
| 236 | + # Write input parameters into logger | |
| 237 | + if self._logTerse(): | |
| 238 | + self._log_parameters() | |
| 239 | + self._log("\n") | |
| 246 | 240 | |
| 247 | 241 | # Return |
| 248 | 242 | return |
| 249 | 243 | |
| 250 | - def execute(self): | |
| 251 | - """ | |
| 252 | - Execute the script. | |
| 253 | - """ | |
| 254 | - # Run the script | |
| 255 | - self.run() | |
| 256 | - | |
| 257 | - # Save residual map | |
| 258 | - self.fits.saveto(self.m_outfile, self.m_clobber) | |
| 259 | - | |
| 260 | - # Return | |
| 261 | - return | |
| 262 | 244 | |
| 245 | + # Public methods | |
| 263 | 246 | def run(self): |
| 264 | 247 | """ |
| 265 | 248 | Run the script. |
| 266 | 249 | """ |
| 267 | 250 | # Switch screen logging on in debug mode |
| 268 | - if self.logDebug(): | |
| 269 | - self.log.cout(True) | |
| 251 | + if self._logDebug(): | |
| 252 | + self._log.cout(True) | |
| 270 | 253 | |
| 271 | 254 | # Get parameters |
| 272 | - self.get_parameters() | |
| 273 | - | |
| 274 | - # Write input parameters into logger | |
| 275 | - if self.logTerse(): | |
| 276 | - self.log_parameters() | |
| 277 | - self.log("\n") | |
| 255 | + self._get_parameters() | |
| 278 | 256 | |
| 279 | 257 | # Write observation into logger |
| 280 | - if self.logTerse(): | |
| 281 | - self.log("\n") | |
| 282 | - self.log.header1("Observation") | |
| 283 | - self.log(str(self.obs)) | |
| 284 | - self.log("\n") | |
| 258 | + if self._logTerse(): | |
| 259 | + self._log("\n") | |
| 260 | + self._log.header1("Observation") | |
| 261 | + self._log(str(self._obs)) | |
| 262 | + self._log("\n") | |
| 285 | 263 | |
| 286 | 264 | # Write header |
| 287 | - if self.logTerse(): | |
| 288 | - self.log("\n") | |
| 289 | - self.log.header1("Adjust model parameters") | |
| 265 | + if self._logTerse(): | |
| 266 | + self._log("\n") | |
| 267 | + self._log.header1("Adjust model parameters") | |
| 290 | 268 | |
| 291 | 269 | # Adjust model parameters dependent on input user parameters |
| 292 | - for model in self.obs.models(): | |
| 270 | + for model in self._obs.models(): | |
| 293 | 271 | |
| 294 | 272 | # Set TS flag for all models to false. |
| 295 | 273 | # Source of interest will be set to true later |
| 296 | 274 | model.tscalc(False) |
| 297 | 275 | |
| 298 | 276 | # Log model name |
| 299 | - if self.logExplicit(): | |
| 300 | - self.log.header3(model.name()) | |
| 277 | + if self._logExplicit(): | |
| 278 | + self._log.header3(model.name()) | |
| 301 | 279 | |
| 302 | 280 | # Deal with the source of interest |
| 303 | - if model.name() == self.m_srcname: | |
| 304 | - if self.m_calc_ts: | |
| 281 | + if model.name() == self._srcname: | |
| 282 | + if self._calc_ts: | |
| 305 | 283 | model.tscalc(True) |
| 306 | 284 | |
| 307 | - elif self.m_fix_bkg and not model.classname() == "GModelSky": | |
| 285 | + elif self._fix_bkg and not model.classname() == "GModelSky": | |
| 308 | 286 | for par in model: |
| 309 | - if par.is_free() and self.logExplicit(): | |
| 310 | - self.log(" Fixing \""+par.name()+"\"\n") | |
| 287 | + if par.is_free() and self._logExplicit(): | |
| 288 | + self._log(" Fixing \""+par.name()+"\"\n") | |
| 311 | 289 | par.fix() |
| 312 | 290 | |
| 313 | - elif self.m_fix_srcs and model.classname() == "GModelSky": | |
| 291 | + elif self._fix_srcs and model.classname() == "GModelSky": | |
| 314 | 292 | for par in model: |
| 315 | - if par.is_free() and self.logExplicit(): | |
| 316 | - self.log(" Fixing \""+par.name()+"\"\n") | |
| 293 | + if par.is_free() and self._logExplicit(): | |
| 294 | + self._log(" Fixing \""+par.name()+"\"\n") | |
| 317 | 295 | par.fix() |
| 318 | 296 | |
| 319 | 297 | # Write header |
| 320 | - if self.logTerse(): | |
| 321 | - self.log("\n") | |
| 322 | - self.log.header1("Generate lightcurve") | |
| 298 | + if self._logTerse(): | |
| 299 | + self._log("\n") | |
| 300 | + self._log.header1("Generate lightcurve") | |
| 323 | 301 | |
| 324 | 302 | # Initialise FITS Table with extension "LIGHTCURVE" |
| 325 | - table = gammalib.GFitsBinTable(self.m_tbins.size()) | |
| 303 | + table = gammalib.GFitsBinTable(self._tbins.size()) | |
| 326 | 304 | table.extname("LIGHTCURVE") |
| 327 | 305 | |
| 328 | 306 | # Add Header for compatibility with gammalib.GMWLSpectrum |
| ... | ... | @@ -330,38 +308,38 @@ class cslightcrv(ctools.cscript): |
| 330 | 308 | table.card("TELESCOP", "CTA", "Name of Telescope") |
| 331 | 309 | |
| 332 | 310 | # Create FITS table columns |
| 333 | - MJD = gammalib.GFitsTableDoubleCol("MJD", self.m_tbins.size()) | |
| 311 | + MJD = gammalib.GFitsTableDoubleCol("MJD", self._tbins.size()) | |
| 334 | 312 | MJD.unit("days") |
| 335 | - e_MJD = gammalib.GFitsTableDoubleCol("e_MJD", self.m_tbins.size()) | |
| 313 | + e_MJD = gammalib.GFitsTableDoubleCol("e_MJD", self._tbins.size()) | |
| 336 | 314 | e_MJD.unit("days") |
| 337 | 315 | |
| 338 | 316 | # Create a FITS column for every free parameter |
| 339 | 317 | columns = [] |
| 340 | - for par in self.obs.models()[self.m_srcname]: | |
| 318 | + for par in self._obs.models()[self._srcname]: | |
| 341 | 319 | if par.is_free(): |
| 342 | - col = gammalib.GFitsTableDoubleCol(par.name(), self.m_tbins.size()) | |
| 320 | + col = gammalib.GFitsTableDoubleCol(par.name(), self._tbins.size()) | |
| 343 | 321 | col.unit(par.unit()) |
| 344 | 322 | columns.append(col) |
| 345 | - e_col = gammalib.GFitsTableDoubleCol("e_"+par.name(), self.m_tbins.size()) | |
| 323 | + e_col = gammalib.GFitsTableDoubleCol("e_"+par.name(), self._tbins.size()) | |
| 346 | 324 | e_col.unit(par.unit()) |
| 347 | 325 | columns.append(e_col) |
| 348 | 326 | |
| 349 | 327 | # Create TS and upper limit columns |
| 350 | - TSvalues = gammalib.GFitsTableDoubleCol("TS", self.m_tbins.size()) | |
| 351 | - ulim_values = gammalib.GFitsTableDoubleCol("UpperLimit", self.m_tbins.size()) | |
| 328 | + TSvalues = gammalib.GFitsTableDoubleCol("TS", self._tbins.size()) | |
| 329 | + ulim_values = gammalib.GFitsTableDoubleCol("UpperLimit", self._tbins.size()) | |
| 352 | 330 | ulim_values.unit("ph/cm2/s") |
| 353 | 331 | |
| 354 | 332 | # Loop over energy bins |
| 355 | - for i in range(self.m_tbins.size()): | |
| 333 | + for i in range(self._tbins.size()): | |
| 356 | 334 | |
| 357 | 335 | # Log information |
| 358 | - if self.logTerse(): | |
| 359 | - self.log("\n") | |
| 360 | - self.log.header2("Time bin "+str(i)) | |
| 336 | + if self._logTerse(): | |
| 337 | + self._log("\n") | |
| 338 | + self._log.header2("Time bin "+str(i)) | |
| 361 | 339 | |
| 362 | 340 | # Get time boundaries |
| 363 | - tmin = self.m_tbins.tstart(i) | |
| 364 | - tmax = self.m_tbins.tstop(i) | |
| 341 | + tmin = self._tbins.tstart(i) | |
| 342 | + tmax = self._tbins.tstop(i) | |
| 365 | 343 | |
| 366 | 344 | # Compute time bin center and time width |
| 367 | 345 | twidth = 0.5 * (tmax - tmin) # in seconds |
| ... | ... | @@ -372,13 +350,13 @@ class cslightcrv(ctools.cscript): |
| 372 | 350 | e_MJD[i] = twidth / gammalib.sec_in_day # in days |
| 373 | 351 | |
| 374 | 352 | # Log information |
| 375 | - if self.logExplicit(): | |
| 376 | - self.log.header3("Selecting events") | |
| 353 | + if self._logExplicit(): | |
| 354 | + self._log.header3("Selecting events") | |
| 377 | 355 | |
| 378 | 356 | # Select events |
| 379 | - select = ctools.ctselect(self.obs) | |
| 380 | - select["emin"] = self.m_emin | |
| 381 | - select["emax"] = self.m_emax | |
| 357 | + select = ctools.ctselect(self._obs) | |
| 358 | + select["emin"] = self._emin | |
| 359 | + select["emax"] = self._emax | |
| 382 | 360 | select["tmin"] = tmin.convert(select._time_reference()) |
| 383 | 361 | select["tmax"] = tmax.convert(select._time_reference()) |
| 384 | 362 | select["rad"] = "UNDEFINED" |
| ... | ... | @@ -390,113 +368,113 @@ class cslightcrv(ctools.cscript): |
| 390 | 368 | obs = select.obs() |
| 391 | 369 | |
| 392 | 370 | # Binned analysis |
| 393 | - if self.m_binned: | |
| 371 | + if self._binned: | |
| 394 | 372 | |
| 395 | 373 | # Header |
| 396 | - if self.logTerse(): | |
| 397 | - self.log.header3("Binning events") | |
| 374 | + if self._logTerse(): | |
| 375 | + self._log.header3("Binning events") | |
| 398 | 376 | |
| 399 | 377 | # Bin events |
| 400 | 378 | bin = ctools.ctbin(select.obs()) |
| 401 | 379 | bin["usepnt"] = False |
| 402 | 380 | bin["ebinalg"] = "LOG" |
| 403 | - bin["xref"] = self.m_xref | |
| 404 | - bin["yref"] = self.m_yref | |
| 405 | - bin["binsz"] = self.m_binsz | |
| 406 | - bin["nxpix"] = self.m_nxpix | |
| 407 | - bin["nypix"] = self.m_nypix | |
| 408 | - bin["enumbins"] = self.m_ebins | |
| 409 | - bin["emin"] = self.m_emin | |
| 410 | - bin["emax"] = self.m_emax | |
| 411 | - bin["coordsys"] = self.m_coordsys | |
| 412 | - bin["proj"] = self.m_proj | |
| 381 | + bin["xref"] = self._xref | |
| 382 | + bin["yref"] = self._yref | |
| 383 | + bin["binsz"] = self._binsz | |
| 384 | + bin["nxpix"] = self._nxpix | |
| 385 | + bin["nypix"] = self._nypix | |
| 386 | + bin["enumbins"] = self._ebins | |
| 387 | + bin["emin"] = self._emin | |
| 388 | + bin["emax"] = self._emax | |
| 389 | + bin["coordsys"] = self._coordsys | |
| 390 | + bin["proj"] = self._proj | |
| 413 | 391 | bin.run() |
| 414 | 392 | |
| 415 | 393 | # Header |
| 416 | - if self.logTerse(): | |
| 417 | - self.log.header3("Creating exposure cube") | |
| 394 | + if self._logTerse(): | |
| 395 | + self._log.header3("Creating exposure cube") | |
| 418 | 396 | |
| 419 | 397 | # Create exposure cube |
| 420 | 398 | expcube = ctools.ctexpcube(select.obs()) |
| 421 | 399 | expcube["incube"] = "NONE" |
| 422 | 400 | expcube["usepnt"] = False |
| 423 | 401 | expcube["ebinalg"] = "LOG" |
| 424 | - expcube["xref"] = self.m_xref | |
| 425 | - expcube["yref"] = self.m_yref | |
| 426 | - expcube["binsz"] = self.m_binsz | |
| 427 | - expcube["nxpix"] = self.m_nxpix | |
| 428 | - expcube["nypix"] = self.m_nypix | |
| 429 | - expcube["enumbins"] = self.m_ebins | |
| 430 | - expcube["emin"] = self.m_emin | |
| 431 | - expcube["emax"] = self.m_emax | |
| 432 | - expcube["coordsys"] = self.m_coordsys | |
| 433 | - expcube["proj"] = self.m_proj | |
| 402 | + expcube["xref"] = self._xref | |
| 403 | + expcube["yref"] = self._yref | |
| 404 | + expcube["binsz"] = self._binsz | |
| 405 | + expcube["nxpix"] = self._nxpix | |
| 406 | + expcube["nypix"] = self._nypix | |
| 407 | + expcube["enumbins"] = self._ebins | |
| 408 | + expcube["emin"] = self._emin | |
| 409 | + expcube["emax"] = self._emax | |
| 410 | + expcube["coordsys"] = self._coordsys | |
| 411 | + expcube["proj"] = self._proj | |
| 434 | 412 | expcube.run() |
| 435 | 413 | |
| 436 | 414 | # Header |
| 437 | - if self.logTerse(): | |
| 438 | - self.log.header3("Creating point spread function cube") | |
| 415 | + if self._logTerse(): | |
| 416 | + self._log.header3("Creating point spread function cube") | |
| 439 | 417 | |
| 440 | 418 | # Create psf cube |
| 441 | 419 | psfcube = ctools.ctpsfcube(select.obs()) |
| 442 | 420 | psfcube["incube"] = "NONE" |
| 443 | 421 | psfcube["usepnt"] = False |
| 444 | 422 | psfcube["ebinalg"] = "LOG" |
| 445 | - psfcube["xref"] = self.m_xref | |
| 446 | - psfcube["yref"] = self.m_yref | |
| 447 | - psfcube["binsz"] = self.m_binsz | |
| 448 | - psfcube["nxpix"] = self.m_nxpix | |
| 449 | - psfcube["nypix"] = self.m_nypix | |
| 450 | - psfcube["enumbins"] = self.m_ebins | |
| 451 | - psfcube["emin"] = self.m_emin | |
| 452 | - psfcube["emax"] = self.m_emax | |
| 453 | - psfcube["coordsys"] = self.m_coordsys | |
| 454 | - psfcube["proj"] = self.m_proj | |
| 423 | + psfcube["xref"] = self._xref | |
| 424 | + psfcube["yref"] = self._yref | |
| 425 | + psfcube["binsz"] = self._binsz | |
| 426 | + psfcube["nxpix"] = self._nxpix | |
| 427 | + psfcube["nypix"] = self._nypix | |
| 428 | + psfcube["enumbins"] = self._ebins | |
| 429 | + psfcube["emin"] = self._emin | |
| 430 | + psfcube["emax"] = self._emax | |
| 431 | + psfcube["coordsys"] = self._coordsys | |
| 432 | + psfcube["proj"] = self._proj | |
| 455 | 433 | psfcube.run() |
| 456 | 434 | |
| 457 | 435 | # Check if we need to include energy dispersion |
| 458 | - if self.m_edisp: | |
| 436 | + if self._edisp: | |
| 459 | 437 | |
| 460 | 438 | # Header |
| 461 | - if self.logTerse(): | |
| 462 | - self.log.header3("Creating energy dispersion cube") | |
| 439 | + if self._logTerse(): | |
| 440 | + self._log.header3("Creating energy dispersion cube") | |
| 463 | 441 | |
| 464 | 442 | # Create edisp cube |
| 465 | 443 | edispcube = ctools.ctedispcube(select.obs()) |
| 466 | 444 | edispcube["incube"] = "NONE" |
| 467 | 445 | edispcube["usepnt"] = False |
| 468 | 446 | edispcube["ebinalg"] = "LOG" |
| 469 | - edispcube["xref"] = self.m_xref | |
| 470 | - edispcube["yref"] = self.m_yref | |
| 471 | - edispcube["binsz"] = self.m_binsz | |
| 472 | - edispcube["nxpix"] = self.m_nxpix | |
| 473 | - edispcube["nypix"] = self.m_nypix | |
| 474 | - edispcube["enumbins"] = self.m_ebins | |
| 475 | - edispcube["emin"] = self.m_emin | |
| 476 | - edispcube["emax"] = self.m_emax | |
| 477 | - edispcube["coordsys"] = self.m_coordsys | |
| 478 | - edispcube["proj"] = self.m_proj | |
| 447 | + edispcube["xref"] = self._xref | |
| 448 | + edispcube["yref"] = self._yref | |
| 449 | + edispcube["binsz"] = self._binsz | |
| 450 | + edispcube["nxpix"] = self._nxpix | |
| 451 | + edispcube["nypix"] = self._nypix | |
| 452 | + edispcube["enumbins"] = self._ebins | |
| 453 | + edispcube["emin"] = self._emin | |
| 454 | + edispcube["emax"] = self._emax | |
| 455 | + edispcube["coordsys"] = self._coordsys | |
| 456 | + edispcube["proj"] = self._proj | |
| 479 | 457 | edispcube.run() |
| 480 | 458 | |
| 481 | 459 | # Header |
| 482 | - if self.logTerse(): | |
| 483 | - self.log.header3("Creating background cube") | |
| 460 | + if self._logTerse(): | |
| 461 | + self._log.header3("Creating background cube") | |
| 484 | 462 | |
| 485 | 463 | # Create background cube |
| 486 | 464 | bkgcube = ctools.ctbkgcube(select.obs()) |
| 487 | 465 | bkgcube["incube"] = "NONE" |
| 488 | 466 | bkgcube["usepnt"] = False |
| 489 | 467 | bkgcube["ebinalg"] = "LOG" |
| 490 | - bkgcube["xref"] = self.m_xref | |
| 491 | - bkgcube["yref"] = self.m_yref | |
| 492 | - bkgcube["binsz"] = self.m_binsz | |
| 493 | - bkgcube["nxpix"] = self.m_nxpix | |
| 494 | - bkgcube["nypix"] = self.m_nypix | |
| 495 | - bkgcube["enumbins"] = self.m_ebins | |
| 496 | - bkgcube["emin"] = self.m_emin | |
| 497 | - bkgcube["emax"] = self.m_emax | |
| 498 | - bkgcube["coordsys"] = self.m_coordsys | |
| 499 | - bkgcube["proj"] = self.m_proj | |
| 468 | + bkgcube["xref"] = self._xref | |
| 469 | + bkgcube["yref"] = self._yref | |
| 470 | + bkgcube["binsz"] = self._binsz | |
| 471 | + bkgcube["nxpix"] = self._nxpix | |
| 472 | + bkgcube["nypix"] = self._nypix | |
| 473 | + bkgcube["enumbins"] = self._ebins | |
| 474 | + bkgcube["emin"] = self._emin | |
| 475 | + bkgcube["emax"] = self._emax | |
| 476 | + bkgcube["coordsys"] = self._coordsys | |
| 477 | + bkgcube["proj"] = self._proj | |
| 500 | 478 | bkgcube.run() |
| 501 | 479 | |
| 502 | 480 | # Set new binned observation |
| ... | ... | @@ -506,7 +484,7 @@ class cslightcrv(ctools.cscript): |
| 506 | 484 | models = bkgcube.models() |
| 507 | 485 | |
| 508 | 486 | # Set precomputed binned response |
| 509 | - if self.m_edisp: | |
| 487 | + if self._edisp: | |
| 510 | 488 | obs[0].response(expcube.expcube(), psfcube.psfcube(), |
| 511 | 489 | edispcube.edispcube(), bkgcube.bkgcube()) |
| 512 | 490 | else: |
| ... | ... | @@ -514,7 +492,7 @@ class cslightcrv(ctools.cscript): |
| 514 | 492 | bkgcube.bkgcube()) |
| 515 | 493 | |
| 516 | 494 | # Fix background models if required |
| 517 | - if self.m_fix_bkg: | |
| 495 | + if self._fix_bkg: | |
| 518 | 496 | for model in models: |
| 519 | 497 | if not model.classname() == "GModelSky": |
| 520 | 498 | for par in model: |
| ... | ... | @@ -524,20 +502,20 @@ class cslightcrv(ctools.cscript): |
| 524 | 502 | obs.models(models) |
| 525 | 503 | |
| 526 | 504 | # Header |
| 527 | - if self.logTerse(): | |
| 528 | - self.log.header3("Performing fit") | |
| 505 | + if self._logTerse(): | |
| 506 | + self._log.header3("Performing fit") | |
| 529 | 507 | |
| 530 | 508 | # Likelihood |
| 531 | 509 | like = ctools.ctlike(obs) |
| 532 | - like["edisp"] = self.m_edisp | |
| 510 | + like["edisp"] = self._edisp | |
| 533 | 511 | like.run() |
| 534 | 512 | |
| 535 | 513 | # Skip bin if no event was present |
| 536 | 514 | if like.obs().logL() == 0.0: |
| 537 | 515 | |
| 538 | 516 | # Log information |
| 539 | - if self.logTerse(): | |
| 540 | - self.log("No event in this time bin. Bin is skipped\n") | |
| 517 | + if self._logTerse(): | |
| 518 | + self._log("No event in this time bin. Bin is skipped\n") | |
| 541 | 519 | |
| 542 | 520 | # Set all values to 0 |
| 543 | 521 | for col in columns: |
| ... | ... | @@ -548,19 +526,19 @@ class cslightcrv(ctools.cscript): |
| 548 | 526 | |
| 549 | 527 | # Get results |
| 550 | 528 | fitted_models = like.obs().models() |
| 551 | - source = fitted_models[self.m_srcname] | |
| 529 | + source = fitted_models[self._srcname] | |
| 552 | 530 | |
| 553 | 531 | # Calculate Upper Limit |
| 554 | 532 | ulimit_value = -1.0 |
| 555 | - if self.m_calc_ulimit: | |
| 533 | + if self._calc_ulimit: | |
| 556 | 534 | |
| 557 | 535 | # Logging information |
| 558 | - if self.logTerse(): | |
| 559 | - self.log.header3("Computing upper limit") | |
| 536 | + if self._logTerse(): | |
| 537 | + self._log.header3("Computing upper limit") | |
| 560 | 538 | |
| 561 | 539 | # Create upper limit object |
| 562 | 540 | ulimit = ctools.ctulimit(like.obs()) |
| 563 | - ulimit["srcname"] = self.m_srcname | |
| 541 | + ulimit["srcname"] = self._srcname | |
| 564 | 542 | ulimit["eref"] = 1.0 |
| 565 | 543 | |
| 566 | 544 | # Try to run upper limit and catch exceptions |
| ... | ... | @@ -568,13 +546,13 @@ class cslightcrv(ctools.cscript): |
| 568 | 546 | ulimit.run() |
| 569 | 547 | ulimit_value = ulimit.flux_ulimit() |
| 570 | 548 | except: |
| 571 | - if self.logTerse(): | |
| 572 | - self.log("Upper limit calculation failed\n") | |
| 549 | + if self._logTerse(): | |
| 550 | + self._log("Upper limit calculation failed\n") | |
| 573 | 551 | ulimit_value = -1.0 |
| 574 | 552 | |
| 575 | 553 | # Get TS value |
| 576 | 554 | TS = -1.0 |
| 577 | - if self.m_calc_ts: | |
| 555 | + if self._calc_ts: | |
| 578 | 556 | TS = source.ts() |
| 579 | 557 | |
| 580 | 558 | # Set values for storage |
| ... | ... | @@ -592,20 +570,20 @@ class cslightcrv(ctools.cscript): |
| 592 | 570 | ulim_values[i] = ulimit_value |
| 593 | 571 | |
| 594 | 572 | # Log information |
| 595 | - if self.logExplicit(): | |
| 596 | - self.log.header3("Results of bin "+str(i)+": MJD "+str(tmin.mjd())+"-"+str(tmax.mjd())) | |
| 573 | + if self._logExplicit(): | |
| 574 | + self._log.header3("Results of bin "+str(i)+": MJD "+str(tmin.mjd())+"-"+str(tmax.mjd())) | |
| 597 | 575 | for col in columns: |
| 598 | 576 | if "e_" == col.name()[:2]: |
| 599 | 577 | continue |
| 600 | 578 | value = source.spectral()[col.name()].value() |
| 601 | 579 | error = source.spectral()[col.name()].error() |
| 602 | 580 | unit = source.spectral()[col.name()].unit() |
| 603 | - self.log(" > "+col.name()+": "+str(value)+" +- "+str(error)+" "+unit+"\n") | |
| 604 | - if self.m_calc_ts and TSvalues[i] > 0.0: | |
| 605 | - self.log(" > TS = "+str(TS)+" \n") | |
| 606 | - if self.m_calc_ulimit and ulim_values[i] > 0.0: | |
| 607 | - self.log(" > UL = "+str(ulim_values[i])+" [ph/cm2/s]") | |
| 608 | - self.log("\n") | |
| 581 | + self._log(" > "+col.name()+": "+str(value)+" +- "+str(error)+" "+unit+"\n") | |
| 582 | + if self._calc_ts and TSvalues[i] > 0.0: | |
| 583 | + self._log(" > TS = "+str(TS)+" \n") | |
| 584 | + if self._calc_ulimit and ulim_values[i] > 0.0: | |
| 585 | + self._log(" > UL = "+str(ulim_values[i])+" [ph/cm2/s]") | |
| 586 | + self._log("\n") | |
| 609 | 587 | |
| 610 | 588 | # Append filles columns to fits table |
| 611 | 589 | table.append(MJD) |
| ... | ... | @@ -616,8 +594,69 @@ class cslightcrv(ctools.cscript): |
| 616 | 594 | table.append(ulim_values) |
| 617 | 595 | |
| 618 | 596 | # Create the FITS file now |
| 619 | - self.fits = gammalib.GFits() | |
| 620 | - self.fits.append(table) | |
| 597 | + self._fits = gammalib.GFits() | |
| 598 | + self._fits.append(table) | |
| 599 | + | |
| 600 | + # Return | |
| 601 | + return | |
| 602 | + | |
| 603 | + def execute(self): | |
| 604 | + """ | |
| 605 | + Execute the script. | |
| 606 | + """ | |
| 607 | + # Read ahead output parameters | |
| 608 | + self._read_ahead(True) | |
| 609 | + | |
| 610 | + # Run the script | |
| 611 | + self.run() | |
| 612 | + | |
| 613 | + # Save lightcurve | |
| 614 | + self.save() | |
| 615 | + | |
| 616 | + # Return | |
| 617 | + return | |
| 618 | + | |
| 619 | + def save(self): | |
| 620 | + """ | |
| 621 | + Save lightcurve. | |
| 622 | + """ | |
| 623 | + # Write header | |
| 624 | + if self._logTerse(): | |
| 625 | + self._log("\n") | |
| 626 | + self._log.header1("Save lightcurve") | |
| 627 | + | |
| 628 | + # Get outmap parameter | |
| 629 | + self._outfile = self["outfile"].filename() | |
| 630 | + | |
| 631 | + # Continue only filename and residual map are valid | |
| 632 | + if self._outfile != "NONE" and self._fits != None: | |
| 633 | + | |
| 634 | + # Log file name | |
| 635 | + if self._logTerse(): | |
| 636 | + self._log("Save lightcurve into \""+self._outfile+"\".\n") | |
| 637 | + | |
| 638 | + # Save spectrum | |
| 639 | + self._fits.saveto(self._outfile, self._clobber) | |
| 640 | + | |
| 641 | + # Return | |
| 642 | + return | |
| 643 | + | |
| 644 | + def lightcurve(self): | |
| 645 | + """ | |
| 646 | + Return lightcurve FITS file. | |
| 647 | + | |
| 648 | + Returns: | |
| 649 | + FITS file containing lightcurve. | |
| 650 | + """ | |
| 651 | + # Return | |
| 652 | + return self._fits | |
| 653 | + | |
| 654 | + def models(self, models): | |
| 655 | + """ | |
| 656 | + Set model. | |
| 657 | + """ | |
| 658 | + # Copy models | |
| 659 | + self._obs.models(models.clone()) | |
| 621 | 660 | |
| 622 | 661 | # Return |
| 623 | 662 | return |
| ... | ... | @@ -627,14 +666,12 @@ class cslightcrv(ctools.cscript): |
| 627 | 666 | # Main routine entry point # |
| 628 | 667 | # ======================== # |
| 629 | 668 | if __name__ == '__main__': |
| 630 | - """ | |
| 631 | - Generates light curve. | |
| 632 | - """ | |
| 669 | + | |
| 633 | 670 | # Create instance of application |
| 634 | 671 | app = cslightcrv(sys.argv) |
| 635 | 672 | |
| 636 | 673 | # Open logfile |
| 637 | - app.logFileOpen() | |
| 674 | + app._logFileOpen() | |
| 638 | 675 | |
| 639 | 676 | # Execute application |
| 640 | 677 | app.execute() | ... | ... |
cscripts/csspec.py
| ... | ... | @@ -59,7 +59,6 @@ class csspec(ctools.cscript): |
| 59 | 59 | self._chatter = 2 |
| 60 | 60 | self._clobber = True |
| 61 | 61 | self._debug = False |
| 62 | - self._log_clients = False | |
| 63 | 62 | |
| 64 | 63 | # Initialise observation |
| 65 | 64 | if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations): |
| ... | ... | @@ -206,6 +205,8 @@ class csspec(ctools.cscript): |
| 206 | 205 | # Return |
| 207 | 206 | return |
| 208 | 207 | |
| 208 | + | |
| 209 | + # Public methods | |
| 209 | 210 | def run(self): |
| 210 | 211 | """ |
| 211 | 212 | Run the script. | ... | ... |