From 00c0acbb422bdaaee045f0f143a146006c3f6e3a Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 6 Jun 2018 10:39:26 +0200 Subject: [PATCH] Simplify datapath setting --- cscripts/csfindobs.par | 2 +- cscripts/csfindobs.py | 30 ++++++++++++++---------------- cscripts/csiactdata.par | 2 +- cscripts/csiactdata.py | 23 ++++++++++------------- cscripts/csiactobs.par | 2 +- cscripts/csiactobs.py | 26 ++++++++++++-------------- 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/cscripts/csfindobs.par b/cscripts/csfindobs.par index 44f5808..d319dfa 100644 --- a/cscripts/csfindobs.par +++ b/cscripts/csfindobs.par @@ -16,7 +16,7 @@ # # Input and output parameters #============================ -datapath, s, q, NONE,,, "Path were data are located" +datapath, s, a, NONE,,, "Path were data are located (NONE uses $VHEFITS environment variable)" prodname, s, a, prod-name,,, "Name of FITS production (Run csiactdata to view your options)" outfile, f, a, runlist.lis,,, "Output runlist file" diff --git a/cscripts/csfindobs.py b/cscripts/csfindobs.py index 059d910..6a73ef8 100755 --- a/cscripts/csfindobs.py +++ b/cscripts/csfindobs.py @@ -2,7 +2,7 @@ # ========================================================================== # Find observations from an IACT data store # -# Copyright (C) 2016-2017 Michael Mayer +# Copyright (C) 2016-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,38 +53,36 @@ class csfindobs(ctools.cscript): # Return return - + # Private methods def _get_parameters(self): """ Get parameters from parfile and setup the observation. """ - # Get datapath if not already set - if self['datapath'].current_value() != 'NONE': - # Evaluate earlier user input - self._datapath = self['datapath'].current_value() + # Query datapath. If the parameter is not NONE then use it, otherwise + # use the datapath from the VHEFITS environment variable + datapath = self['datapath'].string() + if gammalib.toupper(datapath) != 'NONE': + self._datapath = datapath else: - if self._datapath == '': - # Query user. Mode has to be re-set from hidden to query. - self['datapath'].mode( 'q' ) - self._datapath = self['datapath'].string() - + self._datapath = os.getenv('VHEFITS','') + # Expand environment self._datapath = gammalib.expand_env(self._datapath) - + # Get production name self._prodname = self['prodname'].string() - + # Master index file name master_indx = self['master_indx'].string() - + # Initialise flag if spatial selection is required self._select_radec = True - + # Initialise invalid radius self._radius = 0.0 - + # Check for validity of spatial parameters if (self['ra'].is_valid() and self['dec'].is_valid() and diff --git a/cscripts/csiactdata.par b/cscripts/csiactdata.par index 6ed7733..7fe1c5f 100644 --- a/cscripts/csiactdata.par +++ b/cscripts/csiactdata.par @@ -16,7 +16,7 @@ # # Input and output parameters #============================ -datapath, s, q, NONE,,, "Path were data is located" +datapath, s, a, NONE,,, "Path were data are located (NONE uses $VHEFITS environment variable)" master_indx, s, h, master.json,,, "Name of master index file" # diff --git a/cscripts/csiactdata.py b/cscripts/csiactdata.py index 322257c..2b1b540 100755 --- a/cscripts/csiactdata.py +++ b/cscripts/csiactdata.py @@ -2,7 +2,7 @@ # ========================================================================== # Inspect an IACT data storage # -# Copyright (C) 2015-2017 Michael Mayer +# Copyright (C) 2015-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -61,24 +61,21 @@ class csiactdata(ctools.cscript): """ Get parameters from parfile and setup the observation """ - - # Set datapath if not already set - if self['datapath'].current_value() != 'NONE': - # Evaluate earlier user input - self._datapath = self['datapath'].current_value() + # Query datapath. If the parameter is not NONE then use it, otherwise + # use the datapath from the VHEFITS environment variable + datapath = self['datapath'].string() + if gammalib.toupper(datapath) != 'NONE': + self._datapath = datapath else: - if self._datapath == '': - # Query user. Mode has to be re-set from hidden to query. - self['datapath'].mode( 'q' ) - self._datapath = self['datapath'].string() - + self._datapath = os.getenv('VHEFITS','') + # Expand environment self._datapath = gammalib.expand_env(self._datapath) - + # Get filename of master index file self._master_indx = self['master_indx'].string() self._master_file = os.path.join(self._datapath, self._master_indx) - + # Check for presence of master index file if not os.path.isfile(self._master_file): raise RuntimeError('Master index file "'+self._master_file+ diff --git a/cscripts/csiactobs.par b/cscripts/csiactobs.par index c84bf4b..5c3f7bd 100644 --- a/cscripts/csiactobs.par +++ b/cscripts/csiactobs.par @@ -16,7 +16,7 @@ # # Input and output parameters #============================ -datapath, s, q, NONE,,, "Path were data is located" +datapath, s, a, NONE,,, "Path were data are located (NONE uses $VHEFITS environment variable)" prodname, s, a, fits-prod-name,,, "Data storage name" infile, f, a, runlist.lis,,, "Input runlist file" inmodel, f, h, NONE,,, "Input model definition XML file (optional)" diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index 3ad68ee..39f42ce 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -2,7 +2,7 @@ # ========================================================================== # Generates an IACT observation definition XML file # -# Copyright (C) 2015-2017 Michael Mayer +# Copyright (C) 2015-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -94,25 +94,23 @@ class csiactobs(ctools.cscript): """ Get parameters from parfile and setup the observation """ - # Set datapath if not already set - if self['datapath'].current_value() != 'NONE': - # Evaluate earlier user input - self._datapath = self['datapath'].current_value() + # Query datapath. If the parameter is not NONE then use it, otherwise + # use the datapath from the VHEFITS environment variable + datapath = self['datapath'].string() + if gammalib.toupper(datapath) != 'NONE': + self._datapath = datapath else: - if self._datapath == '': - # Query user. Mode has to be re-set from hidden to query. - self['datapath'].mode( 'q' ) - self._datapath = self['datapath'].string() - - # Query input parameters - self['inmodel'].filename() + self._datapath = os.getenv('VHEFITS','') # Expand environment self._datapath = gammalib.expand_env(self._datapath) - + + # Query input parameters + self['inmodel'].filename() + # Read FITS production self._prodname = self['prodname'].string() - + # Read runlist file if list not already filled if len(self._runlist) == 0: -- libgit2 0.21.4