Skip to content

Commit 9be8cea

Browse files
[Bug]: CDAT Migration Phase 2: enso_diags plot fixes (#841)
1 parent 6f889f8 commit 9be8cea

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

auxiliary_tools/cdat_regression_testing/663-enso-diags/regression_test_png.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
},
162162
{
163163
"cell_type": "code",
164-
"execution_count": null,
164+
"execution_count": 6,
165165
"metadata": {},
166166
"outputs": [
167167
{
@@ -192,7 +192,7 @@
192192
},
193193
{
194194
"cell_type": "code",
195-
"execution_count": 6,
195+
"execution_count": 7,
196196
"metadata": {},
197197
"outputs": [
198198
{
@@ -224,7 +224,7 @@
224224
" '/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/663-enso-diags/enso_diags/TAUY-response_diff/regression-coefficient-tauy-over-nino34.png']"
225225
]
226226
},
227-
"execution_count": 6,
227+
"execution_count": 7,
228228
"metadata": {},
229229
"output_type": "execute_result"
230230
}
@@ -235,7 +235,7 @@
235235
},
236236
{
237237
"cell_type": "code",
238-
"execution_count": 7,
238+
"execution_count": 8,
239239
"metadata": {},
240240
"outputs": [
241241
{

e3sm_diags/driver/enso_diags_driver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from e3sm_diags.driver.utils.regrid import _subset_on_region, align_grids_to_lower_res
1919
from e3sm_diags.logger import custom_logger
20-
from e3sm_diags.metrics.metrics import spatial_avg, std
20+
from e3sm_diags.metrics.metrics import correlation, rmse, spatial_avg, std
2121
from e3sm_diags.plot.enso_diags_plot import plot_map, plot_scatter
2222

2323
if TYPE_CHECKING:
@@ -44,6 +44,8 @@ class MetricsSubDict(TypedDict):
4444
max: float
4545
mean: List[float]
4646
std: List[float]
47+
rmse: float | None
48+
corr: float | None
4749

4850

4951
# A type annotation representing the metrics dictionary.
@@ -531,6 +533,8 @@ def _create_metrics_dict(
531533
metrics_dict["test"] = get_metrics_subdict(ds_test, var_key)
532534
metrics_dict["test_regrid"] = get_metrics_subdict(ds_test_regrid, var_key)
533535
metrics_dict["diff"] = get_metrics_subdict(ds_diff, var_key)
536+
metrics_dict["diff"]["rmse"] = rmse(ds_test_regrid, ds_ref_regrid, var_key) # type: ignore
537+
metrics_dict["diff"]["corr"] = correlation(ds_test_regrid, ds_ref_regrid, var_key) # type: ignore
534538

535539
metrics_dict["unit"] = ds_test[var_key].units
536540

e3sm_diags/plot/enso_diags_plot.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def plot_map(
190190
(None, parameter.diff_title, da_test.units),
191191
metrics_dict["diff"], # type: ignore
192192
)
193+
_plot_diff_rmse_and_corr(fig, metrics_dict["diff"]) # type: ignore
193194

194195
_save_plot(fig, parameter)
195196

@@ -296,7 +297,7 @@ def _add_colormap(
296297

297298
# Add metrics text to the figure.
298299
# --------------------------------------------------------------------------
299-
metrics_values = tuple(metrics.values())
300+
metrics_values = (metrics["max"], metrics["min"], metrics["mean"], metrics["std"])
300301
top_text = "Max\nMin\nMean\nSTD"
301302
fig.text(
302303
DEFAULT_PANEL_CFG[subplot_num][0] + 0.6635,
@@ -325,6 +326,26 @@ def _add_colormap(
325326
)
326327

327328

329+
def _plot_diff_rmse_and_corr(fig: plt.Figure, metrics_dict: MetricsSubDict):
330+
bottom_stats = (metrics_dict["rmse"], metrics_dict["corr"])
331+
bottom_text = "RMSE\nCORR"
332+
333+
fig.text(
334+
DEFAULT_PANEL_CFG[2][0] + 0.6635,
335+
DEFAULT_PANEL_CFG[2][1] - 0.0205,
336+
bottom_text,
337+
ha="left",
338+
fontdict={"fontsize": SECONDARY_TITLE_FONTSIZE},
339+
)
340+
fig.text(
341+
DEFAULT_PANEL_CFG[2][0] + 0.7635,
342+
DEFAULT_PANEL_CFG[2][1] - 0.0205,
343+
"%.2f\n%.2f" % bottom_stats, # type: ignore
344+
ha="right",
345+
fontdict={"fontsize": SECONDARY_TITLE_FONTSIZE},
346+
)
347+
348+
328349
def _determine_tick_step(degrees_covered: float) -> int:
329350
"""Determine the number of tick steps based on the degrees covered by the axis.
330351

0 commit comments

Comments
 (0)