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

cali-ref and like-bas plots can be created now

parent 93bfcab9
No related branches found
No related tags found
2 merge requests!37include new development,!27Lukas issue032 feat plotting postprocessing
Pipeline #28265 passed
...@@ -22,7 +22,6 @@ logging.getLogger('matplotlib').setLevel(logging.WARNING) ...@@ -22,7 +22,6 @@ logging.getLogger('matplotlib').setLevel(logging.WARNING)
def plot_monthly_summary(stations, data_path, name: str, window_lead_time, target_var, plot_folder="."): def plot_monthly_summary(stations, data_path, name: str, window_lead_time, target_var, plot_folder="."):
logging.debug("run plot_monthly_summary()") logging.debug("run plot_monthly_summary()")
forecasts = None forecasts = None
...@@ -48,9 +47,10 @@ def plot_monthly_summary(stations, data_path, name: str, window_lead_time, targe ...@@ -48,9 +47,10 @@ def plot_monthly_summary(stations, data_path, name: str, window_lead_time, targe
forecasts = forecasts.to_dataset(name='values').to_dask_dataframe() forecasts = forecasts.to_dataset(name='values').to_dask_dataframe()
logging.debug("... start plotting") logging.debug("... start plotting")
ax = sns.boxplot(x='index', y='values', hue='ahead', data=forecasts.compute(), whis=1., ax = sns.boxplot(x='index', y='values', hue='ahead', data=forecasts.compute(), whis=1.,
palette=[matplotlib.colors.cnames["green"]]+sns.color_palette("Blues_d", window_lead_time).as_hex(), palette=[matplotlib.colors.cnames["green"]] + sns.color_palette("Blues_d",
flierprops={'marker': '.', 'markersize': 1}, window_lead_time).as_hex(),
showmeans=True, meanprops={'markersize': 1, 'markeredgecolor': 'k'}) flierprops={'marker': '.', 'markersize': 1}, showmeans=True,
meanprops={'markersize': 1, 'markeredgecolor': 'k'})
ax.set(xlabel='month', ylabel=f'{target_var}') ax.set(xlabel='month', ylabel=f'{target_var}')
plt.tight_layout() plt.tight_layout()
plot_path = os.path.join(os.path.abspath(plot_folder), 'test_monthly_box.pdf') plot_path = os.path.join(os.path.abspath(plot_folder), 'test_monthly_box.pdf')
...@@ -64,7 +64,6 @@ def plot_climsum_boxplot(): ...@@ -64,7 +64,6 @@ def plot_climsum_boxplot():
def plot_station_map(generators, plot_folder="."): def plot_station_map(generators, plot_folder="."):
logging.debug("run station_map()") logging.debug("run station_map()")
fig = plt.figure(figsize=(10, 5)) fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree()) ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
...@@ -80,7 +79,8 @@ def plot_station_map(generators, plot_folder="."): ...@@ -80,7 +79,8 @@ def plot_station_map(generators, plot_folder="."):
for k, v in enumerate(gen): for k, v in enumerate(gen):
station_coords = gen.get_data_generator(k).meta.loc[['station_lon', 'station_lat']] station_coords = gen.get_data_generator(k).meta.loc[['station_lon', 'station_lat']]
station_names = gen.get_data_generator(k).meta.loc[['station_id']] station_names = gen.get_data_generator(k).meta.loc[['station_id']]
IDx, IDy = float(station_coords.loc['station_lon'].values), float(station_coords.loc['station_lat'].values) IDx, IDy = float(station_coords.loc['station_lon'].values), float(
station_coords.loc['station_lat'].values)
ax.plot(IDx, IDy, mfc=color, mec='k', marker='s', markersize=6, transform=ccrs.PlateCarree()) ax.plot(IDx, IDy, mfc=color, mec='k', marker='s', markersize=6, transform=ccrs.PlateCarree())
plot_path = os.path.join(os.path.abspath(plot_folder), 'test_map_plot.pdf') plot_path = os.path.join(os.path.abspath(plot_folder), 'test_map_plot.pdf')
...@@ -89,7 +89,8 @@ def plot_station_map(generators, plot_folder="."): ...@@ -89,7 +89,8 @@ def plot_station_map(generators, plot_folder="."):
def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_window: int = 3, ref_name: str = 'orig', def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_window: int = 3, ref_name: str = 'orig',
pred_name: str = 'CNN', season: str = "", forecast_path: str = None): pred_name: str = 'CNN', season: str = "", forecast_path: str = None,
plot_name_affix: str = "", units: str = "ppb"):
""" """
This plot was originally taken from Murphy, Brown and Chen (1989): This plot was originally taken from Murphy, Brown and Chen (1989):
https://journals.ametsoc.org/doi/pdf/10.1175/1520-0434%281989%29004%3C0485%3ADVOTF%3E2.0.CO%3B2 https://journals.ametsoc.org/doi/pdf/10.1175/1520-0434%281989%29004%3C0485%3ADVOTF%3E2.0.CO%3B2
...@@ -102,6 +103,8 @@ def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_w ...@@ -102,6 +103,8 @@ def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_w
:param pred_name: name of the investigated data series :param pred_name: name of the investigated data series
:param season: season name to highlight if not empty :param season: season name to highlight if not empty
:param forecast_path: path to save the plot file :param forecast_path: path to save the plot file
:param plot_name_affix: name to specify this plot (e.g. 'cali-ref', default: '')
:param units: units of the forecasted values (default: ppb)
""" """
time = TimeTracking() time = TimeTracking()
logging.debug(f"started plot_conditional_quantiles()") logging.debug(f"started plot_conditional_quantiles()")
...@@ -146,15 +149,24 @@ def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_w ...@@ -146,15 +149,24 @@ def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_w
return quantile_panel return quantile_panel
opts = {"q": [.1, .25, .5, .75, .9], def labels(plot_type, data_unit="ppb"):
"linetype": [':', '-.', '--', '-.', ':'], names = (f"forecast concentration (in {data_unit})", f"observed concentration (in {data_unit})")
if plot_type == "orig":
return names
else:
return names[::-1]
xlabel, ylabel = labels(ref_name, units)
opts = {"q": [.1, .25, .5, .75, .9], "linetype": [':', '-.', '--', '-.', ':'],
"legend": ['.10th and .90th quantile', '.25th and .75th quantile', '.50th quantile', 'reference 1:1'], "legend": ['.10th and .90th quantile', '.25th and .75th quantile', '.50th quantile', 'reference 1:1'],
"xlabel": "forecast concentration (in ppb)", "xlabel": xlabel, "ylabel": ylabel}
"ylabel": "observed concentration (in ppb)"}
# set name and path of the plot # set name and path of the plot
plot_name = f"test_conditional_quantiles{f'_{season}' if len(season) > 0 else ''}" base_name = "conditional_quantiles"
plot_path = os.path.join(os.path.abspath(plot_folder), f"{plot_name}_plot.pdf") def add_affix(x): return f"_{x}" if len(x) > 0 else ""
plot_name = f"{base_name}{add_affix(season)}{add_affix(plot_name_affix)}_plot.pdf"
plot_path = os.path.join(os.path.abspath(plot_folder), plot_name)
# check forecast path # check forecast path
if forecast_path is None: if forecast_path is None:
...@@ -182,8 +194,8 @@ def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_w ...@@ -182,8 +194,8 @@ def plot_conditional_quantiles(stations: list, plot_folder: str = ".", rolling_w
ax.plot([0, bins.max()], [0, bins.max()], color='k', label='reference 1:1', linewidth=.8) ax.plot([0, bins.max()], [0, bins.max()], color='k', label='reference 1:1', linewidth=.8)
# add histogram of the segmented data (pred_name) # add histogram of the segmented data (pred_name)
handles, labels = ax.get_legend_handles_labels() handles, labels = ax.get_legend_handles_labels()
segmented_data.loc[pred_name, d, :].to_pandas().hist(bins=bins, ax=ax2, color='k', segmented_data.loc[pred_name, d, :].to_pandas().hist(bins=bins, ax=ax2, color='k', alpha=.3, grid=False,
alpha=.3, grid=False, rwidth=1) rwidth=1)
# add legend # add legend
plt.legend(handles[:3] + [handles[-1]], opts["legend"], loc='upper left', fontsize='large') plt.legend(handles[:3] + [handles[-1]], opts["legend"], loc='upper left', fontsize='large')
# adjust limits and set labels # adjust limits and set labels
......
...@@ -57,7 +57,10 @@ class PostProcessing(RunEnvironment): ...@@ -57,7 +57,10 @@ class PostProcessing(RunEnvironment):
window_lead_time = self.data_store.get("window_lead_time", "general") window_lead_time = self.data_store.get("window_lead_time", "general")
target_var = self.data_store.get("target_var", "general") target_var = self.data_store.get("target_var", "general")
plot_conditional_quantiles(self.test_data.stations, plot_folder=self.plot_path, forecast_path=self.data_store.get("forecast_path", "general")) plot_conditional_quantiles(self.test_data.stations, plot_folder=self.plot_path, pred_name="CNN", ref_name="orig",
forecast_path=self.data_store.get("forecast_path", "general"), plot_name_affix="cali-ref")
plot_conditional_quantiles(self.test_data.stations, plot_folder=self.plot_path, pred_name="orig", ref_name="CNN",
forecast_path=self.data_store.get("forecast_path", "general"), plot_name_affix="like-bas")
plot_station_map(generators={'b': self.test_data}, plot_folder=self.plot_path) plot_station_map(generators={'b': self.test_data}, plot_folder=self.plot_path)
plot_monthly_summary(self.test_data.stations, path, r"forecasts_%s_test.nc", window_lead_time, target_var, plot_monthly_summary(self.test_data.stations, path, r"forecasts_%s_test.nc", window_lead_time, target_var,
plot_folder=self.plot_path) plot_folder=self.plot_path)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment