diff --git a/src/data_handling/bootstraps.py b/src/data_handling/bootstraps.py index f68532dac279994b235514bcdec0cf9f6decfdc1..0d2eb7ef0a825c9b29c1e153ce95e0504ce45558 100644 --- a/src/data_handling/bootstraps.py +++ b/src/data_handling/bootstraps.py @@ -42,7 +42,7 @@ class BootStrapGenerator: shuffled_var = shuffled_data.sel(variables=var, boots=boot).expand_dims("variables").drop("boots") shuffled_var = shuffled_var.transpose("datetime", "window", "Stations", "variables") boot_hist = boot_hist.combine_first(shuffled_var) - boot_hist = boot_hist.sortby("variables") + boot_hist = boot_hist.reindex_like(hist) yield boot_hist return diff --git a/src/plotting/postprocessing_plotting.py b/src/plotting/postprocessing_plotting.py index 854182613cdb63456dc8f62d2421560d829ee629..3338ce4c0d6f14aa8c0173779329a2fd81f0f57e 100644 --- a/src/plotting/postprocessing_plotting.py +++ b/src/plotting/postprocessing_plotting.py @@ -497,6 +497,7 @@ class PlotBootstrapSkillScore(RunEnvironment): """ super().__init__() self._labels = None + self._x_name = "boot_var" self._data = self._prepare_data(data) self._plot(plot_folder, model_setup) @@ -507,7 +508,7 @@ class PlotBootstrapSkillScore(RunEnvironment): :param data: dictionary with station names as keys and 2D xarrays as values :return: pre-processed data set """ - data = helpers.dict_to_xarray(data, "station") + data = helpers.dict_to_xarray(data, "station").sortby(self._x_name) self._labels = [str(i) + "d" for i in data.coords["ahead"].values] return data.to_dataframe("data").reset_index(level=[0, 1, 2]) @@ -526,7 +527,7 @@ class PlotBootstrapSkillScore(RunEnvironment): :param model_setup: architecture type to specify plot name """ fig, ax = plt.subplots() - sns.boxplot(x="boot_var", y="data", hue="ahead", data=self._data, ax=ax, whis=1., palette="Blues_d", + sns.boxplot(x=self._x_name, y="data", hue="ahead", data=self._data, ax=ax, whis=1., palette="Blues_d", showmeans=True, meanprops={"markersize": 1, "markeredgecolor": "k"}, flierprops={"marker": "."}) ax.axhline(y=0, color="grey", linewidth=.5) ax.set(ylabel=f"skill score", xlabel="", title="summary of all stations") diff --git a/src/run_modules/post_processing.py b/src/run_modules/post_processing.py index 01822c3d744569981fef7edcb1dcce48222763ee..aa7cce0e9c52e54ecdedaf53f2e0e03dded2b795 100644 --- a/src/run_modules/post_processing.py +++ b/src/run_modules/post_processing.py @@ -62,7 +62,8 @@ class PostProcessing(RunEnvironment): self.bootstrap_postprocessing(create_new_bootstraps) # skill scores - self.skill_scores = self.calculate_skill_scores() + with TimeTracking(name="calculate skill scores"): + self.skill_scores = self.calculate_skill_scores() # plotting self.plot() @@ -195,6 +196,8 @@ class PostProcessing(RunEnvironment): plot_list = self.data_store.get("plot_list", "postprocessing") + if self.bootstrap_skill_scores is not None and "PlotBootstrapSkillScore" in plot_list: + PlotBootstrapSkillScore(self.bootstrap_skill_scores, plot_folder=self.plot_path, model_setup="CNN") if "plot_conditional_quantiles" in plot_list: plot_conditional_quantiles(self.test_data.stations, pred_name="CNN", ref_name="obs", forecast_path=path, plot_name_affix="cali-ref", plot_folder=self.plot_path) @@ -211,8 +214,6 @@ class PostProcessing(RunEnvironment): extra_name_tag="all_terms_", model_setup="CNN") if "PlotCompetitiveSkillScore" in plot_list: PlotCompetitiveSkillScore(self.skill_scores[0], plot_folder=self.plot_path, model_setup="CNN") - if self.bootstrap_skill_scores is not None and "PlotBootstrapSkillScore" in plot_list: - PlotBootstrapSkillScore(self.bootstrap_skill_scores, plot_folder=self.plot_path, model_setup="CNN") if "PlotTimeSeries" in plot_list: PlotTimeSeries(self.test_data.stations, path, r"forecasts_%s_test.nc", plot_folder=self.plot_path, sampling=self._sampling)