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

Merge branch 'lukas_issue330_bug_calculate-bootstraps' into 'develop'

Resolve "BUGFIX: calculate bootstraps"

See merge request !334
parents b5d706f4 c5ece882
No related branches found
No related tags found
8 merge requests!353add developments to release v1.5.0,!352Resolve "release v1.5.0",!351Lukas issue337 bug ci pipeline fails for docs,!350Resolve "upgrade code to TensorFlow V2",!343Update wrf with develop,!342Include sample-uncertainty to wrf workflow,!334Resolve "BUGFIX: calculate bootstraps",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline #80829 passed
...@@ -88,6 +88,7 @@ class PostProcessing(RunEnvironment): ...@@ -88,6 +88,7 @@ class PostProcessing(RunEnvironment):
self.competitors = to_list(self.data_store.get_default("competitors", default=[])) self.competitors = to_list(self.data_store.get_default("competitors", default=[]))
self.forecast_indicator = "nn" self.forecast_indicator = "nn"
self.ahead_dim = "ahead" self.ahead_dim = "ahead"
self.boot_var_dim = "boot_var"
self._run() self._run()
def _run(self): def _run(self):
...@@ -109,6 +110,8 @@ class PostProcessing(RunEnvironment): ...@@ -109,6 +110,8 @@ class PostProcessing(RunEnvironment):
bootstrap_type = self.data_store.get("bootstrap_type", "postprocessing") bootstrap_type = self.data_store.get("bootstrap_type", "postprocessing")
self.bootstrap_postprocessing(create_new_bootstraps, bootstrap_type=bootstrap_type, self.bootstrap_postprocessing(create_new_bootstraps, bootstrap_type=bootstrap_type,
bootstrap_method=bootstrap_method) bootstrap_method=bootstrap_method)
if self.bootstrap_skill_scores is not None:
self.report_bootstrap_results(self.bootstrap_skill_scores)
# skill scores and error metrics # skill scores and error metrics
with TimeTracking(name="calculate skill scores"): with TimeTracking(name="calculate skill scores"):
...@@ -155,6 +158,7 @@ class PostProcessing(RunEnvironment): ...@@ -155,6 +158,7 @@ class PostProcessing(RunEnvironment):
:param _iter: internal counter to reduce unnecessary recursive calls (maximum number is 2, otherwise something :param _iter: internal counter to reduce unnecessary recursive calls (maximum number is 2, otherwise something
went wrong). went wrong).
""" """
if _iter == 0:
self.bootstrap_skill_scores = {} self.bootstrap_skill_scores = {}
for boot_type in to_list(bootstrap_type): for boot_type in to_list(bootstrap_type):
self.bootstrap_skill_scores[boot_type] = {} self.bootstrap_skill_scores[boot_type] = {}
...@@ -265,7 +269,7 @@ class PostProcessing(RunEnvironment): ...@@ -265,7 +269,7 @@ class PostProcessing(RunEnvironment):
skill.loc[boot_var] = np.array(boot_scores) skill.loc[boot_var] = np.array(boot_scores)
# collect all results in single dictionary # collect all results in single dictionary
score[str(station)] = xr.DataArray(skill, dims=["boot_var", self.ahead_dim]) score[str(station)] = xr.DataArray(skill, dims=[self.boot_var_dim, self.ahead_dim])
return score return score
def get_orig_prediction(self, path, file_name, number_of_bootstraps, prediction_name=None): def get_orig_prediction(self, path, file_name, number_of_bootstraps, prediction_name=None):
...@@ -788,6 +792,23 @@ class PostProcessing(RunEnvironment): ...@@ -788,6 +792,23 @@ class PostProcessing(RunEnvironment):
avg_error[error_metric] = new_val avg_error[error_metric] = new_val
return avg_error return avg_error
def report_bootstrap_results(self, results):
"""Create a csv file containing all results from bootstrapping."""
report_path = os.path.join(self.data_store.get("experiment_path"), "latex_report")
path_config.check_path_and_create(report_path)
res = [["type", "method", "station", self.boot_var_dim, self.ahead_dim, "vals"]]
for boot_type, d0 in results.items():
for boot_method, d1 in d0.items():
for station_name, vals in d1.items():
for boot_var in vals.coords[self.boot_var_dim].values.tolist():
for ahead in vals.coords[self.ahead_dim].values.tolist():
res.append([boot_type, boot_method, station_name, boot_var, ahead,
float(vals.sel({self.boot_var_dim: boot_var, self.ahead_dim: ahead}))])
col_names = res.pop(0)
df = pd.DataFrame(res, columns=col_names)
file_name = "bootstrap_skill_score_report_raw.csv"
df.to_csv(os.path.join(report_path, file_name), sep=";")
def report_error_metrics(self, errors): def report_error_metrics(self, errors):
report_path = os.path.join(self.data_store.get("experiment_path"), "latex_report") report_path = os.path.join(self.data_store.get("experiment_path"), "latex_report")
path_config.check_path_and_create(report_path) path_config.check_path_and_create(report_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment