From 4be04bf26f9eb3c3f835ef784aebb82c955f7e84 Mon Sep 17 00:00:00 2001 From: Tom Vo Date: Thu, 8 Feb 2024 13:43:57 -0800 Subject: [PATCH] Apply suggestions from code review --- e3sm_diags/driver/zonal_mean_2d_driver.py | 6 ++--- e3sm_diags/metrics/metrics.py | 4 ++-- e3sm_diags/plot/cartopy/zonal_mean_2d_plot.py | 7 +++--- e3sm_diags/plot/utils.py | 23 +++++++++++-------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/e3sm_diags/driver/zonal_mean_2d_driver.py b/e3sm_diags/driver/zonal_mean_2d_driver.py index 25962786c..e7d69668e 100755 --- a/e3sm_diags/driver/zonal_mean_2d_driver.py +++ b/e3sm_diags/driver/zonal_mean_2d_driver.py @@ -295,8 +295,7 @@ def _create_metrics_dict( """Calculate metrics using the variable in the datasets. Metrics include min value, max value, spatial average (mean), standard - deviation, correlation (pearson_r), and RMSE. The default value for - optional metrics is None. + deviation, correlation (pearson_r), and RMSE. Parameters ---------- @@ -310,7 +309,8 @@ def _create_metrics_dict( The reference dataset. ds_ref_regrid : xr.Dataset The regridded reference dataset. - The difference between ``ds_test_regrid`` and ``ds_ref_regrid``. + ds_diff : xr. Dataset + The difference between ``ds_test_regrid`` and ``ds_ref_regrid``. Returns ------- diff --git a/e3sm_diags/metrics/metrics.py b/e3sm_diags/metrics/metrics.py index 569a9f338..68410f08a 100644 --- a/e3sm_diags/metrics/metrics.py +++ b/e3sm_diags/metrics/metrics.py @@ -284,8 +284,8 @@ def _get_dims(da: xr.DataArray, axis: List[Axis]) -> List[str]: da : xr.DataArray The array. axis : List[Axis] - The list of axes to get dimensions for, by default ["X", "Y"]. - Valid strings include "X", "Y", and "Z". + The list of axes to get dimensions for. Valid strings + include "X", "Y", and "Z". Returns ------- diff --git a/e3sm_diags/plot/cartopy/zonal_mean_2d_plot.py b/e3sm_diags/plot/cartopy/zonal_mean_2d_plot.py index f112483b0..a72bf5dce 100644 --- a/e3sm_diags/plot/cartopy/zonal_mean_2d_plot.py +++ b/e3sm_diags/plot/cartopy/zonal_mean_2d_plot.py @@ -39,7 +39,7 @@ def plot( da_diff: xr.DataArray, metrics_dict: MetricsDict, ): - """Plot the variable's metrics generated for the lat_lon set. + """Plot the variable's metrics generated by the zonal_mean_2d set. Parameters ---------- @@ -49,8 +49,9 @@ def plot( The test data. da_ref : xr.DataArray The reference data. - ds_diff : xr.DataArray - The difference between ``ds_test_regrid`` and ``ds_ref_regrid``. + da_diff : xr.DataArray + The difference between `da_test` and `da_ref` (both are regridded to + the lower resolution of the two beforehand). metrics_dict : Metrics The metrics. """ diff --git a/e3sm_diags/plot/utils.py b/e3sm_diags/plot/utils.py index abd1d016a..fb42b622b 100644 --- a/e3sm_diags/plot/utils.py +++ b/e3sm_diags/plot/utils.py @@ -352,14 +352,14 @@ def _add_contour_plot( The coordinates of the X axis for the plot. y : xr.DataArray The coordinates of the Y axis for the plot. + color_map : str + The color map file path. projection : ccrs.PlateCarree | None The optional cartopy projection. norm : colors.BoundaryNorm | None The optional norm boundaries. c_levels : List[float] | None The optional contour levels. - color_map : str - The color map file path. Returns ------- @@ -488,7 +488,7 @@ def _configure_titles( Parameters ---------- ax : matplotlib.axes.Axes - The axes objects. + The figure axes object. title : Tuple[str | None, str, str] A tuple of strings to form the title of the colormap, in the format ( years, title, units). @@ -523,17 +523,17 @@ def _configure_x_and_y_axes( Parameters ---------- ax : matplotlib.axes.Axes - The axes object. + The figure axes object. x_ticks : np.ndarray The array of X ticks. y_ticks : np.ndarray | None The optional array of Y ticks. Some set plotters pass None to configure the Y axis ticks using other ticks such as Z axis plevs instead. + projection : ccrs.PlateCarree | None + The optional cartopy projection to use for X and Y ticks. set_name : set_name The name of the current set which determines whether the latitude and longitude major formatters are used. - projection : ccrs.PlateCarree | None - The optional cartopy projection to use for X and Y ticks. """ # For `ax.set_xticks` and `ax.set_yticks`, `crs` cannot be `None` and we # must split up arguments passed to these methods using a conditional @@ -578,12 +578,15 @@ def _add_colorbar( ---------- fig : plt.Figure The figure object. - contour_plot : mcontour.QuadContourSet - The contour plot object. subplot_num : int The subplot number. + panel_configs : PanelConfig + A list of panel configs consisting of positions and sizes, with each + element representing a panel. + contour_plot : mcontour.QuadContourSet + The contour plot object. c_levels : List[float] | None - The optional contour level used for configure the colobar. + The optional contour levels used to configure the colorbar. """ cbax = fig.add_axes( ( @@ -666,7 +669,7 @@ def _add_min_mean_max_text( metrics : Tuple[float, ...] The tuple of metrics, with the first three elements being max, mean, and min. - set_name : str | None, optional + set_name : str | None The optional set name used to determine float format, by default None. fontsize : float The text font size, by default 9.5.