Skip to content

Commit 069a1f6

Browse files
committed
working on command line overwrite issue
1 parent 4c5d3dc commit 069a1f6

File tree

7 files changed

+65
-52
lines changed

7 files changed

+65
-52
lines changed

configurations/test_forecast.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ experiments = a59g-regional-000, a59j-regional-006
99
temporal_colocation = True
1010
spatial_colocation = True
1111
statistic_mode = Spatial|Temporal
12-
#forecast = daily
12+
forecast = daily
1313
report_type = operational

providentia/canvas.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def __init__(self, read_instance):
6969
self.plot_characteristics_templates = self.read_instance.plot_characteristics_templates
7070
self.plot_characteristics = {}
7171

72-
# add general plot characteristics to self
72+
# add general plot characteristics to self (if not passed via command line)
7373
for k, val in self.plot_characteristics_templates['general'].items():
74-
setattr(self, k, val)
74+
if k not in self.read_instance.commandline_arguments:
75+
setattr(self, k, val)
7576

7677
# initialise some key vars
7778
self.filter_data = None

providentia/dashboard.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def __init__(self, **kwargs):
5959
# allow access to methods of parent class QtWidgets.QWidget
6060
super(Dashboard, self).__init__()
6161

62+
# update self with command line arguments
63+
self.commandline_arguments = copy.deepcopy(kwargs)
64+
self.commandline_arguments['dashboard'] = True
65+
6266
# load statistical yamls
6367
self.basic_stats = yaml.safe_load(open(join(PROVIDENTIA_ROOT, 'settings/basic_stats.yaml')))
6468
self.expbias_stats = yaml.safe_load(open(join(PROVIDENTIA_ROOT, 'settings/experiment_bias_stats.yaml')))
@@ -70,11 +74,9 @@ def __init__(self, **kwargs):
7074
self.delay = True
7175
self.delayed_warnings = []
7276

73-
kwargs['dashboard'] = True
74-
7577
# initialise default configuration variables
7678
# modified by commandline arguments, if given
77-
self.provconf = ProvConfiguration(self, **kwargs)
79+
self.provconf = ProvConfiguration(self, **self.commandline_arguments)
7880

7981
# update variables from config file (if available)
8082
self.from_conf = False
@@ -90,15 +92,15 @@ def __init__(self, **kwargs):
9092
read_conf = True
9193

9294
if read_conf:
93-
if 'section' in kwargs:
95+
if 'section' in self.commandline_arguments:
9496
# config and section defined
9597
load_conf(self, fpath=self.config)
96-
if kwargs['section'] in self.all_sections:
98+
if self.commandline_arguments['section'] in self.all_sections:
9799
self.from_conf = True
98-
self.current_config = self.sub_opts[kwargs['section']]
99-
self.section = kwargs['section']
100+
self.current_config = self.sub_opts[self.commandline_arguments['section']]
101+
self.section = self.commandline_arguments['section']
100102
else:
101-
msg = 'Error: The section specified in the command line ({0}) does not exist.'.format(kwargs['section'])
103+
msg = 'Error: The section specified in the command line ({0}) does not exist.'.format(self.commandline_arguments['section'])
102104
msg += '\nTip: For subsections, add the name of the parent section followed by an interpunct (·) '
103105
msg += 'before the subsection name (e.g. SECTIONA·Spain). Available: {0}'.format(self.all_sections)
104106
self.logger.error(msg)
@@ -142,10 +144,11 @@ def __init__(self, **kwargs):
142144
self.previous_calibration_factor = {}
143145
self.calibration_factor = {}
144146

145-
# update variables from defined config file
147+
# update variables from defined config file (if not passed via command line)
146148
if self.current_config:
147149
for k, val in self.current_config.items():
148-
setattr(self, k, self.provconf.parse_parameter(k, val))
150+
if k not in self.commandline_arguments:
151+
setattr(self, k, self.provconf.parse_parameter(k, val))
149152

150153
# now all variables have been parsed, check validity of those, throwing errors where necessary
151154
self.provconf.check_validity()
@@ -185,7 +188,7 @@ def __init__(self, **kwargs):
185188
OrderedDict(sorted(self.expbias_stats.items(), key=lambda x: x[1]['order'])).keys()))
186189

187190
# initialise UI
188-
self.init_ui(**kwargs)
191+
self.init_ui()
189192

190193
# setup callback events upon resizing/moving of Providentia window
191194
self.resized.connect(self.get_geometry)
@@ -322,7 +325,7 @@ def update_qt_elements_geometry(self, plot_types='ALL', positions = [1,2,3,4,5],
322325

323326
break
324327

325-
def init_ui(self, **kwargs):
328+
def init_ui(self):
326329
""" Initialise user interface. """
327330

328331
self.logger.info("Starting Providentia dashboard...")

providentia/download.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
class Download(object):
3737
def __init__(self, **kwargs):
3838

39+
# update self with command line arguments
40+
self.commandline_arguments = copy.deepcopy(kwargs)
41+
3942
# get providentia start time
4043
self.prov_start_time = time.time()
4144

@@ -55,7 +58,7 @@ def __init__(self, **kwargs):
5558

5659
# initialise default configuration variables
5760
# modified by commandline arguments, if given
58-
self.provconf = ProvConfiguration(self, **kwargs)
61+
self.provconf = ProvConfiguration(self, **self.commandline_arguments)
5962

6063
self.logger.info("Starting Providentia download...")
6164

@@ -72,12 +75,12 @@ def __init__(self, **kwargs):
7275
load_conf(self, self.config)
7376
self.from_conf = True
7477
# get the section in case it was passed on the command line
75-
if 'section' in kwargs:
78+
if 'section' in self.commandline_arguments:
7679
# config and section defined
77-
if kwargs['section'] in self.all_sections:
78-
self.sections = [kwargs['section']]
80+
if self.commandline_arguments['section'] in self.all_sections:
81+
self.sections = [self.commandline_arguments['section']]
7982
else:
80-
msg = 'Error: The section specified in the command line ({0}) does not exist.'.format(kwargs['section'])
83+
msg = 'Error: The section specified in the command line ({0}) does not exist.'.format(self.commandline_arguments['section'])
8184
msg += '\nTip: For subsections, add the name of the parent section followed by an interpunct (·) '
8285
msg += 'before the subsection name (e.g. SECTIONA·Spain). Available: {0}'.format(self.all_sections)
8386
self.logger.error(msg)
@@ -114,15 +117,15 @@ def __init__(self, **kwargs):
114117
# initialise boolean thath indicates whether remote machine changed
115118
self.switched_remote = False
116119

117-
def run(self, **kwargs):
120+
def run(self):
118121
for section_ind, section in enumerate(self.sections):
119122
# update for new section parameters
120123
self.section = section
121124
self.section_opts = self.sub_opts[self.section]
122125

123-
# update self with section variables
126+
# update self with section variables (if not passed via command line)
124127
for k, val in self.section_opts.items():
125-
if k not in kwargs:
128+
if k not in self.commandline_arguments:
126129
setattr(self, k, self.provconf.parse_parameter(k, val))
127130

128131
# now all variables have been parsed, check validity of those, throwing errors where necessary
@@ -1501,4 +1504,4 @@ def main(**kwargs):
15011504
""" Main function when running download function. """
15021505

15031506
download = Download(**kwargs)
1504-
download.run(**kwargs)
1507+
download.run()

providentia/interpolation/experiment_interpolation_submission.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
class SubmitInterpolation(object):
3131
""" Class that handles the interpolation submission. """
3232

33-
def __init__(self,**kwargs):
33+
def __init__(self, **kwargs):
34+
35+
# update self with command line arguments
36+
self.commandline_arguments = copy.deepcopy(kwargs)
3437

3538
# start timer
3639
self.start = time.time()
@@ -43,7 +46,7 @@ def __init__(self,**kwargs):
4346
self.interpolation_log_dir = join(PROVIDENTIA_ROOT, 'logs/interpolation/interpolation_logs')
4447

4548
# initialize commandline arguments, if given
46-
provconf = ProvConfiguration(self, **kwargs)
49+
provconf = ProvConfiguration(self, **self.commandline_arguments)
4750

4851
print('\n')
4952

@@ -67,8 +70,8 @@ def __init__(self,**kwargs):
6770
sys.exit(error)
6871

6972
# get section args
70-
if "section" in kwargs:
71-
section = kwargs["section"]
73+
if "section" in self.commandline_arguments:
74+
section = self.commandline_arguments["section"]
7275
if section in self.parent_section_names:
7376
self.current_config = self.sub_opts[section]
7477
else:
@@ -94,10 +97,11 @@ def __init__(self,**kwargs):
9497
# dictionary that stores utilized interpolation variables
9598
self.interpolation_variables = {}
9699

97-
# update variables from defined config file
100+
# update variables from defined config file (if not passed via command line)
98101
if self.current_config:
99102
for k, val in sorted(self.current_config.items()):
100-
setattr(self, k, provconf.parse_parameter(k, val))
103+
if k not in self.commandline_arguments:
104+
setattr(self, k, provconf.parse_parameter(k, val))
101105

102106
# now all variables have been parsed, check validity of those, throwing errors where necessary
103107
provconf.check_validity()

providentia/report.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class Report:
4545

4646
def __init__(self, **kwargs):
4747

48+
# update self with command line arguments
49+
self.commandline_arguments = copy.deepcopy(kwargs)
50+
4851
# load statistical yamls
4952
self.basic_stats = yaml.safe_load(open(join(PROVIDENTIA_ROOT, 'settings/basic_stats.yaml')))
5053
self.expbias_stats = yaml.safe_load(open(join(PROVIDENTIA_ROOT, 'settings/experiment_bias_stats.yaml')))
@@ -54,10 +57,7 @@ def __init__(self, **kwargs):
5457

5558
# initialise default configuration variables
5659
# modified by commandline arguments, if given
57-
provconf = ProvConfiguration(self, **kwargs)
58-
59-
# update self with command line arguments
60-
self.commandline_arguments = copy.deepcopy(kwargs)
60+
provconf = ProvConfiguration(self, **self.commandline_arguments)
6161

6262
self.logger.info("Creating a Providentia Report...")
6363

@@ -143,10 +143,11 @@ def __init__(self, **kwargs):
143143
# get GHOST version before reading configuration file section parameters
144144
current_ghost_version = self.ghost_version
145145

146-
# update self with section variables
146+
# update self with section variables (if not passed via command line)
147147
for k, val in self.section_opts.items():
148-
setattr(self, k, provconf.parse_parameter(k, val))
149-
148+
if k not in self.commandline_arguments:
149+
setattr(self, k, provconf.parse_parameter(k, val))
150+
150151
# if first section or GHOST version has changed
151152
if (section_ind == 0) or (current_ghost_version != self.ghost_version):
152153
generate_file_trees(self)
@@ -164,9 +165,10 @@ def __init__(self, **kwargs):
164165
# initialise Plotting class
165166
self.plotting = Plotting(read_instance=self, canvas_instance=self)
166167

167-
# add general plot characteristics to self
168+
# add general plot characteristics to self (if not passed via command line)
168169
for k, val in self.plot_characteristics_templates['general'].items():
169-
setattr(self, k, val)
170+
if k not in self.commandline_arguments:
171+
setattr(self, k, val)
170172

171173
# now all variables have been parsed, check validity of those, throwing errors where necessary
172174
provconf.check_validity()
@@ -842,34 +844,34 @@ def make_plots_per_subsection(self, summary_plots_to_make, station_plots_to_make
842844
read_species = copy.deepcopy(self.species)
843845
read_networkspecies = copy.deepcopy(self.networkspecies)
844846

847+
# if have forecast active then save current experiment variable in memory as may need to set it if not re-reading data
848+
if len(self.forecast) != 0:
849+
forecast_experiments = copy.deepcopy(self.experiments)
850+
845851
# get subsection variables
846852
self.subsection_opts = self.sub_opts[self.subsection]
847853

848854
# ensure all fixed section variables defined in subsection have same value as current section variables
849855
self.subsection_opts = {k: (self.section_opts[k] if k in self.fixed_section_vars else val)
850856
for (k, val) in self.subsection_opts.items()}
851857

852-
# if have forecast active then save current experiment variable in memory as may need to set it if not re-reading data
853-
if len(self.forecast) != 0:
854-
forecast_experiments = copy.deepcopy(self.experiments)
855-
856858
# reinitialise default configuration variables
857859
# modified by commandline arguments, if given
858860
provconf = ProvConfiguration(self, **self.commandline_arguments)
859861

860-
# update subsection variables
862+
# update subsection variables (if not passed via command line)
861863
for k, val in self.subsection_opts.items():
862-
value = provconf.parse_parameter(k, val, deactivate_warning=True)
863-
# keep only the species that were available when we read the parent section data
864-
if k == 'species':
865-
value = [speci for speci in value if speci in read_species]
866-
elif k == 'networkspecies':
867-
value = [speci for speci in value if speci in read_networkspecies]
868-
setattr(self, k, value)
864+
if k not in self.commandline_arguments:
865+
value = provconf.parse_parameter(k, val, deactivate_warning=True)
866+
setattr(self, k, value)
869867

870868
# now all variables have been parsed, check validity of those, throwing errors where necessary
871869
provconf.check_validity(deactivate_warning=True)
872870

871+
# keep only the species that were available when we read the parent section data
872+
self.species = read_species
873+
self.networkspecies = read_networkspecies
874+
873875
# determine if need to re-read data (qa, flags, filter_species or calibration factor have changed)
874876
if (np.array_equal(self.qa, self.previous_qa) == False) or (
875877
np.array_equal(self.flags, self.previous_flags) == False) or (

providentia/statistics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_selected_station_data(read_instance, canvas_instance, networkspecies,
126126
order='F')
127127

128128
# aggregate across the time dimension, after this shape is (24, label, station, fct)
129-
data_array_forecast_agg = aggregation(read_instance, read_instance, read_instance, read_instance, read_instance, read_instance, data_array_forecast_grouped_rs, read_instance.timeseries_statistic_aggregation, axis=-2)
129+
data_array_forecast_agg = aggregation(data_array_forecast_grouped_rs, read_instance.timeseries_statistic_aggregation, axis=-2)
130130

131131
# move per hour dimension from first to second last
132132
data_array_forecast_agg = data_array_forecast_agg.transpose(1, 2, 0, 3)

0 commit comments

Comments
 (0)