Skip to content

Commit 1b38f3f

Browse files
authored
Merge pull request #20 from llsuo/noresm
Fix: add safe error handling in Taylor diagram and global mean plots;
2 parents 06c2150 + 9e9707e commit 1b38f3f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

scripts/plotting/cam_taylor_diagram.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ def cam_taylor_diagram(adfobj):
164164
# LOOP OVER VARIABLES
165165
#
166166
for v in var_list:
167-
base_x = _retrieve(adfobj, v, data_name, data_loc) # get the baseline field
167+
try:
168+
base_x = _retrieve(adfobj, v, data_name, data_loc) # get the baseline field
169+
except Exception as e:
170+
print(f"[WARN] Skipping variable '{v}' due to error: {e}")
171+
continue
168172
for casenumber, case in enumerate(case_names): # LOOP THROUGH CASES
169173
case_x = _retrieve(adfobj, v, case, case_climo_loc[casenumber])
170174
# ASSUMING `time` is 1-12, get the current season:
@@ -590,4 +594,4 @@ def taylor_plot_finalize(wks, test_nicknames, casecolors, syear_cases, eyear_cas
590594
bias_legend_labels = ["> 20%", "10-20%", "5-10%", "1-5%", "< 1%"]
591595
wks.legend(handles=bias_legend_elements, labels=bias_legend_labels, loc='upper left', handler_map={tuple: HandlerTuple(ndivide=None, pad=2.)}, labelspacing=2, handletextpad=2, frameon=False, title=" - / + Bias",
592596
title_fontsize=18)
593-
return wks
597+
return wks

scripts/plotting/global_mean_timeseries.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ def make_plot(ref_ts_da, case_ts, var, label=None):
304304
ax.set_title(var, loc="left")
305305
ax.set_xlabel("YEAR")
306306
# Place the legend
307-
ax.legend(
308-
bbox_to_anchor=(0.5, -0.15), loc="upper center", ncol=min(len(case_ts), 3)
309-
)
307+
handles, labels = ax.get_legend_handles_labels()
308+
if handles and labels:
309+
ax.legend(
310+
bbox_to_anchor=(0.5, -0.15),loc="upper center", ncol=min(len(handles), 3),
311+
)
310312
plt.tight_layout(pad=2, w_pad=1.0, h_pad=1.0)
311313

312314
return fig, ax

0 commit comments

Comments
 (0)