Skip to content
Snippets Groups Projects
Commit aac76eaf authored by Felix Kleinert's avatar Felix Kleinert
Browse files

include first draft of PlotSampleUncertaintyFromBootstrap

parent 622b2a58
Branches
Tags
7 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",!342Include sample-uncertainty to wrf workflow,!337Resolve "Test Set Sample Uncertainty in PostProcessing",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline #80966 failed
......@@ -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']
......
......@@ -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]}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment