Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_src_mask and use_tgt_mask with nearest regridding scheme do not produce correct results #368

Open
bouweandela opened this issue Jun 17, 2024 · 2 comments · May be fixed by #369
Open
Assignees

Comments

@bouweandela
Copy link
Member

The nearest regridding scheme in ESMF skips masked points. Therefore, this scheme cannot be used to regrid the mask and special treatment is needed. Example of the issue with the current code:

import iris
import iris
import iris.quickplot
import esmf_regrid
import numpy as np
import dask.array as da

filename = "/home/bandela/climate_data/CMIP6/CMIP/EC-Earth-Consortium/EC-Earth3/historical/r1i1p1f1/Omon/tos/gn/v20200918/tos_Omon_EC-Earth3_historical_r1i1p1f1_gn_201401-201412.nc"

cube = iris.load_cube(filename)

grid = iris.cube.Cube(
  np.empty((181, 360)),
  dim_coords_and_dims=[
      (iris.coords.DimCoord(np.arange(-90, 91), 'latitude', units='degrees'), 0),
      (iris.coords.DimCoord(np.arange(0, 360), 'longitude', units='degrees'), 1),
  ],
)

mask = da.ma.getmaskarray(cube.core_data()[0]).compute()

result = cube.regrid(grid, esmf_regrid.ESMFNearest(use_src_mask=mask))

first_time_step = result[0]
first_time_step.data
iris.quickplot.pcolormesh(first_time_step)

results in the following plot, note that the mask is missing:
image

while I would expect a plot that looks like this:
image

The file in the example can be downloaded from one of the following URLs:

@bouweandela
Copy link
Member Author

See here (and click the Regrid_Iris_Esmf_Nearest tab) for an overview of which CMIP6 models currently cannot be regridded using the ESMFNearest scheme. That is approximately 40% of the 46 models, so quite a large fraction, making the ESMFNearest regridding scheme almost unusable with CMIP6 ocean data. This is regardless of whether use_src_mask=True (issue here occurs) or use_src_mask=False (regridding fails because the bounds are discontiguous, this would be solved by #276).

Regarding our discussion at the @SciTools/peloton today: I checked the ocean component of a few of the Earth System Models that failed to regrid and the issue does not seem limited to ORCA grids.

@stephenworsley
Copy link
Contributor

stephenworsley commented Sep 11, 2024

@bouweandela Would there still be a need for #369 if I were to extend the work done by #276 to go beyond simply allowing boundless coordinates but ignoring bounds, and therefore there discontiguities, entirely when doing Nearest (and perhaps also Bilinear) regridding? This ought to mean that the use_src_mask argument is no longer necessary in order to get regridding to work for coords with discontiguities. This should give you the behaviour you want by default without removing the old behaviour in cases where that might be appropriate. It may make sense to add a check_for_discontiguities argument when creating such regridders.


Edit: on further inspecition, it looks like Nearest and Bilinear already do ignore discontiguous bounds which are present on the cube. Do you get the desired behaviour when repeating the above code while removing the argument use_src_mask=mask?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants