Commit 48524efbe910771c7bd6326e68ab88e4a11c73ba
1 parent
c2657fcb
Added improvements, bug fixes and flexibility to some iact cscripts
Showing
3 changed files
with
57 additions
and
28 deletions
cscripts/csiactdata.py
| @@ -40,9 +40,10 @@ class csiactdata(ctools.cscript): | @@ -40,9 +40,10 @@ class csiactdata(ctools.cscript): | ||
| 40 | Constructor. | 40 | Constructor. |
| 41 | """ | 41 | """ |
| 42 | # Set name | 42 | # Set name |
| 43 | - self.name = "csiactdata" | ||
| 44 | - self.version = "1.0.0" | ||
| 45 | - self.datapath = os.getenv("VHEFITS","") | 43 | + self.name = "csiactdata" |
| 44 | + self.version = "1.0.0" | ||
| 45 | + self.datapath = os.getenv("VHEFITS","") | ||
| 46 | + self.prodnames = [] | ||
| 46 | 47 | ||
| 47 | # Make sure that parfile exists | 48 | # Make sure that parfile exists |
| 48 | file = self.parfile() | 49 | file = self.parfile() |
| @@ -156,6 +157,9 @@ class csiactdata(ctools.cscript): | @@ -156,6 +157,9 @@ class csiactdata(ctools.cscript): | ||
| 156 | data = json.loads(json_data) | 157 | data = json.loads(json_data) |
| 157 | configs = data["datasets"] | 158 | configs = data["datasets"] |
| 158 | 159 | ||
| 160 | + # Initialise array for available names | ||
| 161 | + self.prodnames = [] | ||
| 162 | + | ||
| 159 | # Loop over configs and display unavailable storage first | 163 | # Loop over configs and display unavailable storage first |
| 160 | for config in configs: | 164 | for config in configs: |
| 161 | 165 | ||
| @@ -204,6 +208,9 @@ class csiactdata(ctools.cscript): | @@ -204,6 +208,9 @@ class csiactdata(ctools.cscript): | ||
| 204 | self.log(str(config["hduindx"])) | 208 | self.log(str(config["hduindx"])) |
| 205 | self.log("\n") | 209 | self.log("\n") |
| 206 | 210 | ||
| 211 | + # Append to available names | ||
| 212 | + self.prodnames.append(str(config["name"])) | ||
| 213 | + | ||
| 207 | # Print additional information | 214 | # Print additional information |
| 208 | for key in config: | 215 | for key in config: |
| 209 | if key in ["name","hduindx","obsindx"]: | 216 | if key in ["name","hduindx","obsindx"]: |
| @@ -215,6 +222,14 @@ class csiactdata(ctools.cscript): | @@ -215,6 +222,14 @@ class csiactdata(ctools.cscript): | ||
| 215 | # Return | 222 | # Return |
| 216 | return | 223 | return |
| 217 | 224 | ||
| 225 | + def names(self): | ||
| 226 | + """ | ||
| 227 | + Return available FITS production names | ||
| 228 | + """ | ||
| 229 | + | ||
| 230 | + # Return | ||
| 231 | + return self.prodnames | ||
| 232 | + | ||
| 218 | # ======================== # | 233 | # ======================== # |
| 219 | # Main routine entry point # | 234 | # Main routine entry point # |
| 220 | # ======================== # | 235 | # ======================== # |
cscripts/csiactobs.py
| @@ -51,6 +51,7 @@ class csiactobs(ctools.cscript): | @@ -51,6 +51,7 @@ class csiactobs(ctools.cscript): | ||
| 51 | self.inmodels = None | 51 | self.inmodels = None |
| 52 | self.xml = gammalib.GXml() | 52 | self.xml = gammalib.GXml() |
| 53 | self.models = gammalib.GModels() | 53 | self.models = gammalib.GModels() |
| 54 | + self.m_runlist = [] | ||
| 54 | 55 | ||
| 55 | # Make sure that parfile exists | 56 | # Make sure that parfile exists |
| 56 | file = self.parfile() | 57 | file = self.parfile() |
| @@ -136,9 +137,27 @@ class csiactobs(ctools.cscript): | @@ -136,9 +137,27 @@ class csiactobs(ctools.cscript): | ||
| 136 | # Expand environment | 137 | # Expand environment |
| 137 | self.datapath = gammalib.expand_env(self.datapath) | 138 | self.datapath = gammalib.expand_env(self.datapath) |
| 138 | 139 | ||
| 139 | - # Read user parameters | 140 | + # Read FITS production |
| 140 | self.m_prodname = self["prodname"].string() | 141 | self.m_prodname = self["prodname"].string() |
| 141 | - self.m_runlistfile = self["infile"].filename() | 142 | + |
| 143 | + # Read runlist file if list not already filled | ||
| 144 | + if len(self.m_runlist) == 0: | ||
| 145 | + | ||
| 146 | + # Get file name | ||
| 147 | + self.m_runlistfile = self["infile"].filename() | ||
| 148 | + | ||
| 149 | + # Read runlist from file | ||
| 150 | + runfile = open(self.m_runlistfile.url()) | ||
| 151 | + for line in runfile.readlines(): | ||
| 152 | + if len(line) == 0: | ||
| 153 | + continue | ||
| 154 | + if line[0] == '#': | ||
| 155 | + continue | ||
| 156 | + if len(line.split()) > 0: | ||
| 157 | + self.m_runlist.append(line.split()[0]) | ||
| 158 | + runfile.close() | ||
| 159 | + | ||
| 160 | + # Read number of background parameters | ||
| 142 | self.m_bkgpars = self["bkgpars"].integer() | 161 | self.m_bkgpars = self["bkgpars"].integer() |
| 143 | 162 | ||
| 144 | # Output model file | 163 | # Output model file |
| @@ -225,13 +244,13 @@ class csiactobs(ctools.cscript): | @@ -225,13 +244,13 @@ class csiactobs(ctools.cscript): | ||
| 225 | Set observation list | 244 | Set observation list |
| 226 | """ | 245 | """ |
| 227 | 246 | ||
| 228 | - # Type check | ||
| 229 | - if isinstance(runlist, list): | 247 | + # Check if convertable to a python list |
| 248 | + try: | ||
| 230 | 249 | ||
| 231 | # Store a copy of input argument | 250 | # Store a copy of input argument |
| 232 | - self.runlist = list(runlist) | 251 | + self.m_runlist = list(runlist) |
| 233 | 252 | ||
| 234 | - else: | 253 | + except: |
| 235 | 254 | ||
| 236 | # raise error if wrong type detected | 255 | # raise error if wrong type detected |
| 237 | raise RuntimeError("Argument of csiactobs.runlist() must be of type 'list'") | 256 | raise RuntimeError("Argument of csiactobs.runlist() must be of type 'list'") |
| @@ -409,30 +428,16 @@ class csiactobs(ctools.cscript): | @@ -409,30 +428,16 @@ class csiactobs(ctools.cscript): | ||
| 409 | self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) | 428 | self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) |
| 410 | lib = self.xml.element("observation_list", 0) | 429 | lib = self.xml.element("observation_list", 0) |
| 411 | 430 | ||
| 412 | - # Read runlist from file | ||
| 413 | - runlist = [] | ||
| 414 | - runfile = open(self.m_runlistfile.url()) | ||
| 415 | - for line in runfile.readlines(): | ||
| 416 | - if len(line) == 0: | ||
| 417 | - continue | ||
| 418 | - if line[0] == '#': | ||
| 419 | - continue | ||
| 420 | - if len(line.split()) > 0: | ||
| 421 | - runlist.append(line.split()[0]) | ||
| 422 | - else: | ||
| 423 | - runlist.append('') | ||
| 424 | - runfile.close() | ||
| 425 | - | ||
| 426 | # Log output | 431 | # Log output |
| 427 | if self.logTerse(): | 432 | if self.logTerse(): |
| 428 | self.log("\n") | 433 | self.log("\n") |
| 429 | - self.log.header1("Looping over "+str(len(runlist))+" runs") | 434 | + self.log.header1("Looping over "+str(len(self.m_runlist))+" runs") |
| 430 | 435 | ||
| 431 | # Initialise energy range values for logging | 436 | # Initialise energy range values for logging |
| 432 | self.m_ebounds.clear() | 437 | self.m_ebounds.clear() |
| 433 | 438 | ||
| 434 | # Loop over runs | 439 | # Loop over runs |
| 435 | - for obs_id in runlist: | 440 | + for obs_id in self.m_runlist: |
| 436 | 441 | ||
| 437 | # Create selection string | 442 | # Create selection string |
| 438 | obs_selection = "[OBS_ID=="+str(obs_id)+"]" | 443 | obs_selection = "[OBS_ID=="+str(obs_id)+"]" |
cscripts/csobsinfo.py
| @@ -40,6 +40,14 @@ class csobsinfo(ctools.cscript): | @@ -40,6 +40,14 @@ class csobsinfo(ctools.cscript): | ||
| 40 | self.name = "csobsinfo" | 40 | self.name = "csobsinfo" |
| 41 | self.version = "1.1.0" | 41 | self.version = "1.1.0" |
| 42 | 42 | ||
| 43 | + # Initialise some members | ||
| 44 | + if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations): | ||
| 45 | + self.obs = argv[0] | ||
| 46 | + argv = argv[1:] | ||
| 47 | + else: | ||
| 48 | + self.obs = gammalib.GObservations() | ||
| 49 | + self.obs.clear() | ||
| 50 | + | ||
| 43 | # Make sure that parfile exists | 51 | # Make sure that parfile exists |
| 44 | file = self.parfile() | 52 | file = self.parfile() |
| 45 | 53 | ||
| @@ -99,9 +107,10 @@ class csobsinfo(ctools.cscript): | @@ -99,9 +107,10 @@ class csobsinfo(ctools.cscript): | ||
| 99 | """ | 107 | """ |
| 100 | Get parameters from parfile and setup the observation. | 108 | Get parameters from parfile and setup the observation. |
| 101 | """ | 109 | """ |
| 102 | - # Get parameters | ||
| 103 | - self.require_inobs("csobsinfo::get_parameters") | ||
| 104 | - self.obs = self.get_observations(False) | 110 | + # Get parameters |
| 111 | + if self.obs.size() == 0: | ||
| 112 | + self.require_inobs("csobsinfo::get_parameters") | ||
| 113 | + self.obs = self.get_observations(False) | ||
| 105 | 114 | ||
| 106 | # Initialise object position | 115 | # Initialise object position |
| 107 | self.obj_dir = gammalib.GSkyDir() | 116 | self.obj_dir = gammalib.GSkyDir() |