Skip to content

Commit b605b8b

Browse files
committed
CDAT Migration Phase 2: Refactor core utilities and lat_lon set (#677)
Refer to the PR for more information because the changelog is massive. Update build workflow to run on `cdat-migration-fy24` branch CDAT Migration Phase 2: Add CDAT regression test notebook template and fix GH Actions build (#743) - Add Makefile for quick access to multiple Python-based commands such as linting, testing, cleaning up cache and build files - Fix some lingering unit tests failure - Update `xcdat=0.6.0rc1` to `xcdat >=0.6.0` in `ci.yml`, `dev.yml` and `dev-nompi.yml` - Add `xskillscore` to `ci.yml` - Fix `pre-commit` issues CDAT Migration Phase 2: Regression testing for `lat_lon`, `lat_lon_land`, and `lat_lon_river` (#744) - Add Makefile that simplifies common development commands (building and installing, testing, etc.) - Write unit tests to cover all new code for utility functions - `dataset_xr.py`, `metrics.py`, `climo_xr.py`, `io.py`, `regrid.py` - Metrics comparison for `cdat-migration-fy24` `lat_lon` and `main` branch of `lat_lon` -- `NET_FLUX_SRF` and `RESTOM` have the highest spatial average diffs - Test run with 3D variables (`_run_3d_diags()`) - Fix Python 3.9 bug with using pipe command to represent Union -- doesn't work with `from __future__ import annotations` still - Fix subsetting syntax bug using ilev - Fix regridding bug where a single plev is passed and xCDAT does not allow generating bounds for coordinates of len <= 1 -- add conditional that just ignores adding new bounds for regridded output datasets, fix related tests - Fix accidentally calling save plots and metrics twice in `_get_metrics_by_region()` - Fix failing integration tests pass in CI/CD - Refactor `test_diags.py` -- replace unittest with pytest - Refactor `test_all_sets.py` -- replace unittest with pytest - Test climatology datasets -- tested with 3d variables using `test_all_sets.py` CDAT Migration Phase 2: Refactor utilities and CoreParameter methods for reusability across diagnostic sets (#746) - Move driver type annotations to `type_annotations.py` - Move `lat_lon_driver._save_data_metrics_and_plots()` to `io.py` - Update `_save_data_metrics_and_plots` args to accept `plot_func` callable - Update `metrics.spatial_avg` to return an optionally `xr.DataArray` with `as_list=False` - Move `parameter` arg to the top in `lat_lon_plot.plot` - Move `_set_param_output_attrs` and `_set_name_yr_attrs` from `lat_lon_driver` to `CoreParameter` class Regression testing for lat_lon variables `NET_FLUX_SRF` and `RESTOM` (#754) Update regression test notebook to show validation of all vars Add `subset_and_align_datasets()` to regrid.py (#776) Add template run scripts CDAT Migration Phase: Refactor `cosp_histogram` set (#748) - Refactor `cosp_histogram_driver.py` and `cosp_histogram_plot.py` - `formulas_cosp.py` (new file) - Includes refactored, Xarray-based `cosp_histogram_standard()` and `cosp_bin_sum()` functions - I wrote a lot of new code in `formulas_cosp.py` to clean up `derivations.py` and the old equivalent functions in `utils.py` - `derivations.py` - Cleaned up portions of `DERIVED_VARIABLES` dictionary - Removed unnecessary `OrderedDict` usage for `cosp_histogram` related variables (we should do this for the rest of the variables in in #716) - Remove unnecessary `convert_units()` function calls - Move cloud levels passed to derived variable formulas to `formulas_cosp.CLOUD_BIN_SUM_MAP` - `utils.py` - Delete deprecated, CDAT-based `cosp_histogram` functions - `dataset_xr.py` - Add `dataset_xr.Dataset._open_climo_dataset()` method with a catch for dataset quality issues where "time" is a scalar variable that does not match the "time" dimension array length, drops this variable and replaces it with the correct coordinate - Update `_get_dataset_with_derivation_func()` to handle derivation functions that require the `xr.Dataset` and `target_var_key` args (e.g., `cosp_histogram_standardize()` and `cosp_bin_sum()`) - `io.py` - Update `_write_vars_to_netcdf()` to write test, ref, and diff variables to individual netCDF (required for easy comparison to CDAT-based code that does the same thing) - Add `cdat_migration_regression_test_netcdf.ipynb` validation notebook template for comparing `.nc` files CDAT Migration Phase 2: Refactor `zonal_mean_2d()` and `zonal_mean_2d_stratosphere()` sets (#774) Refactor 654 zonal mean xy (#752) Co-authored-by: Tom Vo <[email protected]> CDAT Migration - Update run script output directory to NERSC public webserver (#793) [PR]: CDAT Migration: Refactor `aerosol_aeronet` set (#788) CDAT Migration: Test `lat_lon` set with run script and debug any issues (#794) CDAT Migration: Refactor `polar` set (#749) Co-authored-by: Tom Vo <[email protected]> Align order of calls to `_set_param_output_attrs` CDAT Migration: Refactor `meridional_mean_2d` set (#795) CDAT Migration: Refactor `aerosol_budget` (#800) Add `acme.py` changes from PR #712 (#814) * Add `acme.py` changes from PR #712 * Replace unnecessary lambda call Refactor area_mean_time_series and add ccb slice flag feature (#750) Co-authored-by: Tom Vo <[email protected]> [Refactor]: Validate fix in PR #750 for #759 (#815) CDAT Migration Phase 2: Refactor `diurnal_cycle` set (#819) CDAT Migration: Refactor annual_cycle_zonal_mean set (#798) * Refactor `annual_cycle_zonal_mean` set * Address PR review comments * Add lat lon regression testing * Add debugging scripts * Update `_open_climo_dataset()` to decode times as workaround to misaligned time coords - Update `annual_cycle_zonal_mean_plot.py` to convert time coordinates to month integers * Fix unit tests * Remove old plotter * Add script to debug decode_times=True and ncclimo file * Update plotter time values to month integers * Fix slow `.load()` and multiprocessing issue - Due to incorrectly updating `keep_bnds` logic - Add `_encode_time_coords()` to workaround cftime issue `ValueError: "months since" units only allowed for "360_day" calendar` * Update `_encode_time_coords()` docstring * Add AODVIS debug script * update AODVIS obs datasets; regression test results --------- Co-authored-by: Tom Vo <[email protected]> CDAT Migration Phase 2: Refactor `qbo` set (#826) CDAT Migration Phase 2: Refactor tc_analysis set (#829) * start tc_analysis_refactor * update driver * update plotting * Clean up plotter - Remove unused variables - Make `plot_info` a constant called `PLOT_INFO`, which is now a dict of dicts - Reorder functions for top-down readability * Remove unused notebook --------- Co-authored-by: tomvothecoder <[email protected]> CDAT Migration Phase 2: Refactor `enso_diags` set (#832) CDAT Migration Phase 2: Refactor `streamflow` set (#837) [Bug]: CDAT Migration Phase 2: enso_diags plot fixes (#841) [Refactor]: CDAT Migration Phase 3: testing and documentation update (#846) CDAT Migration Phase 3 - Port QBO Wavelet feature to Xarray/xCDAT codebase (#860) CDAT Migration Phase 2: Refactor arm_diags set (#842) Add performance benchmark material (#864) Add function to add CF axis attr to Z axis if missing for downstream xCDAT operations (#865) CDAT Migration Phase 3: Add Convective Precipitation Fraction in lat-lon (#875) CDAT Migration Phase 3: Fix LHFLX name and add catch for non-existent or empty TE stitch file (#876) Add support for time series datasets via glob and fix `enso_diags` set (#866) Add fix for checking `is_time_series()` property based on `data_type` attr (#881) CDAT migration: Fix African easterly wave density plots in TC analysis and convert H20LNZ units to ppm/volume (#882) CDAT Migration: Update `mp_partition_driver.py` to use Dataset from `dataset_xr.py` (#883) CDAT Migration - Port JJB tropical subseasonal diags to Xarray/xCDAT (#887) CDAT Migration: Prepare branch for merge to `main` (#885) [Refactor]: CDAT Migration - Update dependencies and remove Dataset._add_cf_attrs_to_z_axes() (#891) CDAT Migration Phase 2: Refactor core utilities and `lat_lon` set (#677) Refer to the PR for more information because the changelog is massive. Update build workflow to run on `cdat-migration-fy24` branch CDAT Migration Phase 2: Add CDAT regression test notebook template and fix GH Actions build (#743) - Add Makefile for quick access to multiple Python-based commands such as linting, testing, cleaning up cache and build files - Fix some lingering unit tests failure - Update `xcdat=0.6.0rc1` to `xcdat >=0.6.0` in `ci.yml`, `dev.yml` and `dev-nompi.yml` - Add `xskillscore` to `ci.yml` - Fix `pre-commit` issues CDAT Migration Phase 2: Regression testing for `lat_lon`, `lat_lon_land`, and `lat_lon_river` (#744) - Add Makefile that simplifies common development commands (building and installing, testing, etc.) - Write unit tests to cover all new code for utility functions - `dataset_xr.py`, `metrics.py`, `climo_xr.py`, `io.py`, `regrid.py` - Metrics comparison for `cdat-migration-fy24` `lat_lon` and `main` branch of `lat_lon` -- `NET_FLUX_SRF` and `RESTOM` have the highest spatial average diffs - Test run with 3D variables (`_run_3d_diags()`) - Fix Python 3.9 bug with using pipe command to represent Union -- doesn't work with `from __future__ import annotations` still - Fix subsetting syntax bug using ilev - Fix regridding bug where a single plev is passed and xCDAT does not allow generating bounds for coordinates of len <= 1 -- add conditional that just ignores adding new bounds for regridded output datasets, fix related tests - Fix accidentally calling save plots and metrics twice in `_get_metrics_by_region()` - Fix failing integration tests pass in CI/CD - Refactor `test_diags.py` -- replace unittest with pytest - Refactor `test_all_sets.py` -- replace unittest with pytest - Test climatology datasets -- tested with 3d variables using `test_all_sets.py` CDAT Migration Phase 2: Refactor utilities and CoreParameter methods for reusability across diagnostic sets (#746) - Move driver type annotations to `type_annotations.py` - Move `lat_lon_driver._save_data_metrics_and_plots()` to `io.py` - Update `_save_data_metrics_and_plots` args to accept `plot_func` callable - Update `metrics.spatial_avg` to return an optionally `xr.DataArray` with `as_list=False` - Move `parameter` arg to the top in `lat_lon_plot.plot` - Move `_set_param_output_attrs` and `_set_name_yr_attrs` from `lat_lon_driver` to `CoreParameter` class CDAT Migration Phase 2: Refactor `zonal_mean_2d()` and `zonal_mean_2d_stratosphere()` sets (#774) CDAT Migration Phase 2: Refactor `qbo` set (#826)
1 parent 70ecf94 commit b605b8b

File tree

13 files changed

+2094
-4
lines changed

13 files changed

+2094
-4
lines changed

.github/workflows/build_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: [main]
66

77
pull_request:
8-
branches: [main]
8+
branches: [main, cdat-migration-fy24]
99

1010
workflow_dispatch:
1111

auxiliary_tools/template_cdat_regression_test.ipynb

Lines changed: 1333 additions & 0 deletions
Large diffs are not rendered by default.

e3sm_diags/driver/aerosol_budget_driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
script is integrated in e3sm_diags by Jill Zhang, with input from Kai Zhang,
44
Taufiq Hassan, Xue Zheng, Ziming Ke, Susannah Burrows, and Naser Mahfouz.
55
"""
6+
67
from __future__ import annotations
78

89
import csv

e3sm_diags/driver/qbo_driver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ def run_diag(parameter: QboParameter) -> QboParameter:
125125
test_dict["name"] = test_ds._get_test_name()
126126
ref_dict["name"] = ref_ds._get_ref_name()
127127

128+
try:
129+
ref_dict["name"] = ref_ds._get_ref_name()
130+
except AttributeError:
131+
ref_dict["name"] = parameter.ref_name
132+
128133
_save_metrics_to_json(parameter, test_dict, "test") # type: ignore
129134
_save_metrics_to_json(parameter, ref_dict, "ref") # type: ignore
130135

e3sm_diags/driver/utils/climo_xr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""This module stores climatology functions operating on Xarray objects.
22
3-
43
This file will eventually be refactored to use xCDAT's climatology API.
54
"""
5+
66
from typing import Dict, List, Literal, get_args
77

88
import numpy as np

e3sm_diags/driver/utils/dataset_xr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""This module stores the Dataset class, which is the primary class for I/O.
22
3-
43
This Dataset class operates on `xr.Dataset` objects, which are created using
54
netCDF files. These `xr.Dataset` contain either the reference or test variable.
65
This variable can either be from a climatology file or a time series file.
76
If the variable is from a time series file, the climatology of the variable is
87
calculated. Reference and test variables can also be derived using other
98
variables from dataset files.
109
"""
10+
1111
from __future__ import annotations
1212

1313
import collections

e3sm_diags/metrics/metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This module stores functions to calculate metrics using Xarray objects."""
2+
23
from __future__ import annotations
34

45
from typing import List, Literal
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import os
2+
3+
import cartopy.crs as ccrs
4+
import matplotlib
5+
import numpy as np
6+
7+
from e3sm_diags.driver.utils.general import get_output_dir
8+
from e3sm_diags.logger import custom_logger
9+
from e3sm_diags.metrics import mean
10+
from e3sm_diags.plot.cartopy.deprecated_lat_lon_plot import plot_panel
11+
12+
matplotlib.use("Agg")
13+
import matplotlib.pyplot as plt # isort:skip # noqa: E402
14+
15+
logger = custom_logger(__name__)
16+
17+
plotTitle = {"fontsize": 11.5}
18+
plotSideTitle = {"fontsize": 9.5}
19+
20+
21+
def plot(test, test_site, ref_site, parameter):
22+
# Plot scatter plot
23+
# Position and sizes of subplot axes in page coordinates (0 to 1)
24+
# (left, bottom, width, height) in page coordinates
25+
panel = [
26+
(0.09, 0.40, 0.72, 0.30),
27+
(0.19, 0.2, 0.62, 0.30),
28+
]
29+
# Border padding relative to subplot axes for saving individual panels
30+
# (left, bottom, right, top) in page coordinates
31+
border = (-0.06, -0.03, 0.13, 0.03)
32+
33+
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)
34+
fig.suptitle(parameter.var_id, x=0.5, y=0.97)
35+
proj = ccrs.PlateCarree()
36+
max1 = test.max()
37+
min1 = test.min()
38+
mean1 = mean(test)
39+
# TODO: Replace this function call with `e3sm_diags.plot.utils._add_colormap()`.
40+
plot_panel(
41+
0,
42+
fig,
43+
proj,
44+
test,
45+
parameter.contour_levels,
46+
parameter.test_colormap,
47+
(parameter.test_name_yrs, None, None),
48+
parameter,
49+
stats=(max1, mean1, min1),
50+
)
51+
52+
ax = fig.add_axes(panel[1])
53+
ax.set_title(f"{parameter.var_id} from AERONET sites")
54+
55+
# define 1:1 line, and x y axis limits
56+
57+
if parameter.var_id == "AODVIS":
58+
x1 = np.arange(0.01, 3.0, 0.1)
59+
y1 = np.arange(0.01, 3.0, 0.1)
60+
plt.xlim(0.03, 1)
61+
plt.ylim(0.03, 1)
62+
else:
63+
x1 = np.arange(0.0001, 1.0, 0.01)
64+
y1 = np.arange(0.0001, 1.0, 0.01)
65+
plt.xlim(0.001, 0.3)
66+
plt.ylim(0.001, 0.3)
67+
68+
plt.loglog(x1, y1, "-k", linewidth=0.5)
69+
plt.loglog(x1, y1 * 0.5, "--k", linewidth=0.5)
70+
plt.loglog(x1 * 0.5, y1, "--k", linewidth=0.5)
71+
72+
corr = np.corrcoef(ref_site, test_site)
73+
xmean = np.mean(ref_site)
74+
ymean = np.mean(test_site)
75+
ax.text(
76+
0.3,
77+
0.9,
78+
f"Mean (test): {ymean:.3f} \n Mean (ref): {xmean:.3f}\n Corr: {corr[0, 1]:.2f}",
79+
horizontalalignment="right",
80+
verticalalignment="top",
81+
transform=ax.transAxes,
82+
)
83+
84+
# axis ticks
85+
plt.tick_params(axis="both", which="major")
86+
plt.tick_params(axis="both", which="minor")
87+
88+
# axis labels
89+
plt.xlabel(f"ref: {parameter.ref_name_yrs}")
90+
plt.ylabel(f"test: {parameter.test_name_yrs}")
91+
92+
plt.loglog(ref_site, test_site, "kx", markersize=3.0, mfc="none")
93+
94+
# legend
95+
plt.legend(frameon=False, prop={"size": 5})
96+
97+
# TODO: This section can be refactored to use `plot.utils._save_plot()`.
98+
for f in parameter.output_format:
99+
f = f.lower().split(".")[-1]
100+
fnm = os.path.join(
101+
get_output_dir(parameter.current_set, parameter),
102+
f"{parameter.output_file}" + "." + f,
103+
)
104+
plt.savefig(fnm)
105+
logger.info(f"Plot saved in: {fnm}")
106+
107+
for f in parameter.output_format_subplot:
108+
fnm = os.path.join(
109+
get_output_dir(parameter.current_set, parameter),
110+
parameter.output_file,
111+
)
112+
page = fig.get_size_inches()
113+
i = 0
114+
for p in panel:
115+
# Extent of subplot
116+
subpage = np.array(p).reshape(2, 2)
117+
subpage[1, :] = subpage[0, :] + subpage[1, :]
118+
subpage = subpage + np.array(border).reshape(2, 2)
119+
subpage = list(((subpage) * page).flatten()) # type: ignore
120+
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
121+
# Save subplot
122+
fname = fnm + ".%i." % (i) + f
123+
plt.savefig(fname, bbox_inches=extent)
124+
125+
orig_fnm = os.path.join(
126+
get_output_dir(parameter.current_set, parameter),
127+
parameter.output_file,
128+
)
129+
fname = orig_fnm + ".%i." % (i) + f
130+
logger.info(f"Sub-plot saved in: {fname}")
131+
132+
i += 1
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
from typing import List, Optional, Tuple
2+
3+
import matplotlib
4+
import numpy as np
5+
import xarray as xr
6+
import xcdat as xc
7+
8+
from e3sm_diags.driver.utils.type_annotations import MetricsDict
9+
from e3sm_diags.logger import custom_logger
10+
from e3sm_diags.parameter.core_parameter import CoreParameter
11+
from e3sm_diags.parameter.zonal_mean_2d_parameter import DEFAULT_PLEVS
12+
from e3sm_diags.plot.utils import (
13+
DEFAULT_PANEL_CFG,
14+
_add_colorbar,
15+
_add_contour_plot,
16+
_add_min_mean_max_text,
17+
_add_rmse_corr_text,
18+
_configure_titles,
19+
_configure_x_and_y_axes,
20+
_get_c_levels_and_norm,
21+
_save_plot,
22+
)
23+
24+
matplotlib.use("Agg")
25+
import matplotlib.pyplot as plt # isort:skip # noqa: E402
26+
27+
logger = custom_logger(__name__)
28+
29+
30+
# Configs for x axis ticks and x axis limits.
31+
X_TICKS = np.array([-90, -60, -30, 0, 30, 60, 90])
32+
X_LIM = -90, 90
33+
34+
35+
def plot(
36+
parameter: CoreParameter,
37+
da_test: xr.DataArray,
38+
da_ref: xr.DataArray,
39+
da_diff: xr.DataArray,
40+
metrics_dict: MetricsDict,
41+
):
42+
"""Plot the variable's metrics generated by the zonal_mean_2d set.
43+
44+
Parameters
45+
----------
46+
parameter : CoreParameter
47+
The CoreParameter object containing plot configurations.
48+
da_test : xr.DataArray
49+
The test data.
50+
da_ref : xr.DataArray
51+
The reference data.
52+
da_diff : xr.DataArray
53+
The difference between `da_test` and `da_ref` (both are regridded to
54+
the lower resolution of the two beforehand).
55+
metrics_dict : Metrics
56+
The metrics.
57+
"""
58+
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)
59+
fig.suptitle(parameter.main_title, x=0.5, y=0.96, fontsize=18)
60+
61+
# The variable units.
62+
units = metrics_dict["units"]
63+
64+
# Add the first subplot for test data.
65+
min1 = metrics_dict["test"]["min"] # type: ignore
66+
mean1 = metrics_dict["test"]["mean"] # type: ignore
67+
max1 = metrics_dict["test"]["max"] # type: ignore
68+
69+
_add_colormap(
70+
0,
71+
da_test,
72+
fig,
73+
parameter,
74+
parameter.test_colormap,
75+
parameter.contour_levels,
76+
title=(parameter.test_name_yrs, parameter.test_title, units), # type: ignore
77+
metrics=(max1, mean1, min1), # type: ignore
78+
)
79+
80+
# Add the second and third subplots for ref data and the differences,
81+
# respectively.
82+
min2 = metrics_dict["ref"]["min"] # type: ignore
83+
mean2 = metrics_dict["ref"]["mean"] # type: ignore
84+
max2 = metrics_dict["ref"]["max"] # type: ignore
85+
86+
_add_colormap(
87+
1,
88+
da_ref,
89+
fig,
90+
parameter,
91+
parameter.reference_colormap,
92+
parameter.contour_levels,
93+
title=(parameter.ref_name_yrs, parameter.reference_title, units), # type: ignore
94+
metrics=(max2, mean2, min2), # type: ignore
95+
)
96+
97+
min3 = metrics_dict["diff"]["min"] # type: ignore
98+
mean3 = metrics_dict["diff"]["mean"] # type: ignore
99+
max3 = metrics_dict["diff"]["max"] # type: ignore
100+
r = metrics_dict["misc"]["rmse"] # type: ignore
101+
c = metrics_dict["misc"]["corr"] # type: ignore
102+
103+
_add_colormap(
104+
2,
105+
da_diff,
106+
fig,
107+
parameter,
108+
parameter.diff_colormap,
109+
parameter.diff_levels,
110+
title=(None, parameter.diff_title, da_diff.attrs["units"]), #
111+
metrics=(max3, mean3, min3, r, c), # type: ignore
112+
)
113+
114+
_save_plot(fig, parameter)
115+
116+
plt.close()
117+
118+
119+
def _add_colormap(
120+
subplot_num: int,
121+
var: xr.DataArray,
122+
fig: plt.Figure,
123+
parameter: CoreParameter,
124+
color_map: str,
125+
contour_levels: List[float],
126+
title: Tuple[Optional[str], str, str],
127+
metrics: Tuple[float, ...],
128+
):
129+
lat = xc.get_dim_coords(var, axis="Y")
130+
plev = xc.get_dim_coords(var, axis="Z")
131+
var = var.squeeze()
132+
133+
# Configure contour levels
134+
# --------------------------------------------------------------------------
135+
c_levels, norm = _get_c_levels_and_norm(contour_levels)
136+
137+
# Add the contour plot
138+
# --------------------------------------------------------------------------
139+
ax = fig.add_axes(DEFAULT_PANEL_CFG[subplot_num], projection=None)
140+
141+
contour_plot = _add_contour_plot(
142+
ax, parameter, var, lat, plev, color_map, None, norm, c_levels
143+
)
144+
145+
# Configure the aspect ratio and plot titles.
146+
# --------------------------------------------------------------------------
147+
ax.set_aspect("auto")
148+
_configure_titles(ax, title)
149+
150+
# Configure x and y axis.
151+
# --------------------------------------------------------------------------
152+
_configure_x_and_y_axes(ax, X_TICKS, None, None, parameter.current_set)
153+
ax.set_xlim(X_LIM)
154+
155+
if parameter.plot_log_plevs:
156+
ax.set_yscale("log")
157+
158+
if parameter.plot_plevs:
159+
plev_ticks = parameter.plevs
160+
plt.yticks(plev_ticks, plev_ticks)
161+
162+
# For default plevs, specify the pressure axis and show the 50 mb tick
163+
# at the top.
164+
if (
165+
not parameter.plot_log_plevs
166+
and not parameter.plot_plevs
167+
and parameter.plevs == DEFAULT_PLEVS
168+
):
169+
plev_ticks = parameter.plevs
170+
new_ticks = [plev_ticks[0]] + plev_ticks[1::2]
171+
new_ticks = [int(x) for x in new_ticks]
172+
plt.yticks(new_ticks, new_ticks)
173+
174+
plt.ylabel("pressure (mb)")
175+
ax.invert_yaxis()
176+
177+
# Add and configure the color bar.
178+
# --------------------------------------------------------------------------
179+
_add_colorbar(fig, subplot_num, DEFAULT_PANEL_CFG, contour_plot, c_levels)
180+
181+
# Add metrics text.
182+
# --------------------------------------------------------------------------
183+
# Min, Mean, Max
184+
_add_min_mean_max_text(fig, subplot_num, DEFAULT_PANEL_CFG, metrics)
185+
186+
if len(metrics) == 5:
187+
_add_rmse_corr_text(fig, subplot_num, DEFAULT_PANEL_CFG, metrics)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import xarray as xr
2+
3+
from e3sm_diags.driver.utils.type_annotations import MetricsDict
4+
from e3sm_diags.parameter.core_parameter import CoreParameter
5+
from e3sm_diags.plot.cartopy.zonal_mean_2d_plot import plot as base_plot
6+
7+
8+
def plot(
9+
parameter: CoreParameter,
10+
da_test: xr.DataArray,
11+
da_ref: xr.DataArray,
12+
da_diff: xr.DataArray,
13+
metrics_dict: MetricsDict,
14+
):
15+
return base_plot(parameter, da_test, da_ref, da_diff, metrics_dict)

0 commit comments

Comments
 (0)