diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index ae531b2526dee93672ab989d621d92eba541f19f..8d3be27ad6f1e7908041c7b5135ba965030ad8bf 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -15,6 +15,7 @@ import pandas as pd import seaborn as sns import xarray as xr from matplotlib.backends.backend_pdf import PdfPages +from matplotlib.offsetbox import AnchoredText from mlair import helpers from mlair.data_handler.iterator import DataCollection @@ -1001,30 +1002,33 @@ class PlotSeparationOfScales(AbstractPlotClass): class PlotSampleUncertaintyFromBootstrap(AbstractPlotClass): def __init__(self, data: xr.DataArray, plot_folder: str = ".", model_type_dim: str = "type", - error_measure: str = "mse", dim_name_boots: str = 'boots'): - plot_folder = os.path.join(plot_folder) + error_measure: str = "mse", error_unit: str = None, dim_name_boots: str = 'boots'): super().__init__(plot_folder, "sample_uncertainty_from_bootstrap") self.model_type_dim = model_type_dim self.error_measure = error_measure self.dim_name_boots = dim_name_boots + self.error_unit = error_unit self._plot(data) def _plot(self, data): data_table = data.to_pandas() + n_boots = data_table.shape[0] size = max([len(np.unique(data_table.columns)), 6]) fig, ax = plt.subplots(figsize=(size, size * 0.8)) - # fig, ax = plt.subplots() sns.boxplot(data=data_table, ax=ax, whis=1., color="white", showmeans=True, meanprops={"markersize": 3, "markeredgecolor": "k"}, - flierprops={"marker": ".", "markerfacecolor": 'black', "markeredgecolor": 'none', "markersize": 1}, + flierprops={"marker": ".", "markerfacecolor": 'black', "markeredgecolor": 'none'}, width=.3) - ax.set_ylabel(f"{self.error_measure} " + r" in ppb$^2$") + ax.set_ylabel(f"{self.error_measure} (in {self.error_unit})") ax.set_xticklabels(ax.get_xticklabels(), rotation=45) + text_box = AnchoredText(f"n={n_boots}", frameon=True, loc=4, pad=0.5) + plt.setp(text_box.patch, facecolor='white', alpha=0.5) + ax.add_artist(text_box) plt.tight_layout() self._save() # a = xr.DataArray(np.array(range(20)).reshape(2,-1).T, dims={'time':range(10), 'model': ['m1', 'm2']}, coords={'time':range(10), 'model': ['m1', 'm2']}) -# create_n_bootstrap_realizations(a, dim_name_time='time', dim_name_model='model', n_boots=100) +# data = create_n_bootstrap_realizations(a, dim_name_time='time', dim_name_model='model', n_boots=100) if __name__ == "__main__": stations = ['DEBW107', 'DEBY081', 'DEBW013', 'DEBW076', 'DEBW087'] diff --git a/mlair/run_modules/post_processing.py b/mlair/run_modules/post_processing.py index e9110b43273894365b7ef336f16096944a4a5c10..4e045df7897a7782d9e5d8a12db27df844572a77 100644 --- a/mlair/run_modules/post_processing.py +++ b/mlair/run_modules/post_processing.py @@ -539,7 +539,8 @@ class PostProcessing(RunEnvironment): try: if "PlotSampleUncertaintyFromBootstrap" in plot_list: PlotSampleUncertaintyFromBootstrap(data=None, plot_folder=self.plot_path, - model_type_dim=self.model_type_dim) + model_type_dim=self.model_type_dim, + error_measure="mean squared error", error_unit=r"ppb^2") except Exception as e: logging.error(f"Could not create plot PlotSampleUncertaintyFromBootstrap due to the following error: {e}" f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}")