diff --git a/cscripts/csiactdata.py b/cscripts/csiactdata.py index d00f5e2..c396292 100755 --- a/cscripts/csiactdata.py +++ b/cscripts/csiactdata.py @@ -40,9 +40,10 @@ class csiactdata(ctools.cscript): Constructor. """ # Set name - self.name = "csiactdata" - self.version = "1.0.0" - self.datapath = os.getenv("VHEFITS","") + self.name = "csiactdata" + self.version = "1.0.0" + self.datapath = os.getenv("VHEFITS","") + self.prodnames = [] # Make sure that parfile exists file = self.parfile() @@ -156,6 +157,9 @@ class csiactdata(ctools.cscript): data = json.loads(json_data) configs = data["datasets"] + # Initialise array for available names + self.prodnames = [] + # Loop over configs and display unavailable storage first for config in configs: @@ -204,6 +208,9 @@ class csiactdata(ctools.cscript): self.log(str(config["hduindx"])) self.log("\n") + # Append to available names + self.prodnames.append(str(config["name"])) + # Print additional information for key in config: if key in ["name","hduindx","obsindx"]: @@ -215,6 +222,14 @@ class csiactdata(ctools.cscript): # Return return + def names(self): + """ + Return available FITS production names + """ + + # Return + return self.prodnames + # ======================== # # Main routine entry point # # ======================== # diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index 452a446..af1805a 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -51,6 +51,7 @@ class csiactobs(ctools.cscript): self.inmodels = None self.xml = gammalib.GXml() self.models = gammalib.GModels() + self.m_runlist = [] # Make sure that parfile exists file = self.parfile() @@ -136,9 +137,27 @@ class csiactobs(ctools.cscript): # Expand environment self.datapath = gammalib.expand_env(self.datapath) - # Read user parameters + # Read FITS production self.m_prodname = self["prodname"].string() - self.m_runlistfile = self["infile"].filename() + + # Read runlist file if list not already filled + if len(self.m_runlist) == 0: + + # Get file name + self.m_runlistfile = self["infile"].filename() + + # Read runlist from file + runfile = open(self.m_runlistfile.url()) + for line in runfile.readlines(): + if len(line) == 0: + continue + if line[0] == '#': + continue + if len(line.split()) > 0: + self.m_runlist.append(line.split()[0]) + runfile.close() + + # Read number of background parameters self.m_bkgpars = self["bkgpars"].integer() # Output model file @@ -225,13 +244,13 @@ class csiactobs(ctools.cscript): Set observation list """ - # Type check - if isinstance(runlist, list): + # Check if convertable to a python list + try: # Store a copy of input argument - self.runlist = list(runlist) + self.m_runlist = list(runlist) - else: + except: # raise error if wrong type detected raise RuntimeError("Argument of csiactobs.runlist() must be of type 'list'") @@ -409,30 +428,16 @@ class csiactobs(ctools.cscript): self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) lib = self.xml.element("observation_list", 0) - # Read runlist from file - runlist = [] - runfile = open(self.m_runlistfile.url()) - for line in runfile.readlines(): - if len(line) == 0: - continue - if line[0] == '#': - continue - if len(line.split()) > 0: - runlist.append(line.split()[0]) - else: - runlist.append('') - runfile.close() - # Log output if self.logTerse(): self.log("\n") - self.log.header1("Looping over "+str(len(runlist))+" runs") + self.log.header1("Looping over "+str(len(self.m_runlist))+" runs") # Initialise energy range values for logging self.m_ebounds.clear() # Loop over runs - for obs_id in runlist: + for obs_id in self.m_runlist: # Create selection string obs_selection = "[OBS_ID=="+str(obs_id)+"]" diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py index 3d96700..0dad0d3 100755 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -40,6 +40,14 @@ class csobsinfo(ctools.cscript): self.name = "csobsinfo" self.version = "1.1.0" + # Initialise some members + if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations): + self.obs = argv[0] + argv = argv[1:] + else: + self.obs = gammalib.GObservations() + self.obs.clear() + # Make sure that parfile exists file = self.parfile() @@ -99,9 +107,10 @@ class csobsinfo(ctools.cscript): """ Get parameters from parfile and setup the observation. """ - # Get parameters - self.require_inobs("csobsinfo::get_parameters") - self.obs = self.get_observations(False) + # Get parameters + if self.obs.size() == 0: + self.require_inobs("csobsinfo::get_parameters") + self.obs = self.get_observations(False) # Initialise object position self.obj_dir = gammalib.GSkyDir()