E3SM-Project / e3sm_diags

E3SM Diagnostics package
https://e3sm-project.github.io/e3sm_diags
BSD 3-Clause "New" or "Revised" License
39 stars 32 forks source link

Consider making logic for regridding to lower resolution more robust #739

Open tomvothecoder opened 11 months ago

tomvothecoder commented 11 months ago

Overview

In this discussion, @chengzhuzhang and I talked about the logic for determining which variable has lower resolution.

My comment:

In the old version, regrid_to_lower_res(), there is a comment that says:

https://github.com/E3SM-Project/e3sm_diags/blob/a2d00eb114cf505a4ecf4dd429bb8710778cc087/e3sm_diags/driver/utils/general.py#L246-L248

I interpreted this comment as also meaning that if the lat lengths are the same, the resolutions are the same. Is this comment incorrect or am I misinterpreting it?

Here's a comparison of the logic.

Original logic

1. If `ds_a` is lower res (a <= b): `return ds_a, ds_b_regrid`

2. Else always assume `ds_b` is lower res: `return ds_a_regrid, ds_b`

My logic

1. If `ds_a` is lower res (a < b): `return ds_a, ds_b_regrid`

2. If `ds_b` is lower res (b < a): `return ds_a_regrid, ds_b`

3. Otherwise same resolution (a = b): `return ds_a, ds_b`

   * Avoid unnecessary call to regridder APIs to possibly save on runtime, for example [for model-only runs ](https://github.com/E3SM-Project/e3sm_diags/blob/ae0d649eba7da29a410022f43ae9abc0d77af991/e3sm_diags/driver/lat_lon_driver.py#L87-L92) where `ds_a` and `ds_b` are the same datasets.

-- https://github.com/E3SM-Project/e3sm_diags/pull/677#discussion_r1347733892

Possible Solutions:

@golaz suggested that comparing the number of grid points might be more robust. This involves taking the product of lat and lon.