Skip to content
Snippets Groups Projects
Commit f4e6a50a authored by lukas leufen's avatar lukas leufen
Browse files

added small check for var and stat

parent 36496b84
No related branches found
No related tags found
2 merge requests!37include new development,!32added small check for var and stat
Pipeline #29045 passed
......@@ -67,6 +67,7 @@ class ExperimentSetup(RunEnvironment):
self._set_param("station_type", station_type, default=None)
self._set_param("variables", variables, default=list(self.data_store.get("var_all_dict", "general").keys()))
self._set_param("statistics_per_var", statistics_per_var, default=self.data_store.get("var_all_dict", "general"))
self._compare_variables_and_statistics()
self._set_param("start", start, default="1997-01-01", scope="general")
self._set_param("end", end, default="2017-12-31", scope="general")
self._set_param("window_history_size", window_history_size, default=13)
......@@ -122,6 +123,17 @@ class ExperimentSetup(RunEnvironment):
else:
return {}
def _compare_variables_and_statistics(self):
logging.debug("check if all variables are included in statistics_per_var")
var = self.data_store.get("variables", "general")
stat = self.data_store.get("statistics_per_var", "general")
if not set(var).issubset(stat.keys()):
missing = set(var).difference(stat.keys())
raise ValueError(f"Comparison of given variables and statistics_per_var show that not all requested "
f"variables are part of statistics_per_var. Please add also information on the missing "
f"statistics for the variables: {missing}")
if __name__ == "__main__":
......
......@@ -149,3 +149,14 @@ class TestExperimentSetup:
assert data_store.get("end", "general.test") == "2000-01-06"
# use all stations on all data sets (train, val, test)
assert data_store.get("use_all_stations_on_all_data_sets", "general.test") is False
def test_compare_variables_and_statistics(self):
kwargs = dict(parser_args={"experiment_date": "TODAY"},
var_all_dict={'o3': 'dma8eu', 'temp': 'maximum'},
stations=['DEBY053', 'DEBW059', 'DEBW027'], variables=["o3", "relhum"], statistics_per_var=None)
with pytest.raises(ValueError) as e:
ExperimentSetup(**kwargs)
assert "for the variables: {'relhum'}" in e.value.args[0]
kwargs["variables"] = ["o3", "temp"]
assert ExperimentSetup(**kwargs) is not None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment