SciTools-incubator / iris-esmf-regrid

A collection of structured and unstructured ESMF regridding schemes for Iris.
BSD 3-Clause "New" or "Revised" License
17 stars 16 forks source link

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

Open bouweandela opened 2 weeks ago

bouweandela commented 2 weeks ago

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 commented 2 weeks ago

See here (and click the _Regrid_Iris_EsmfNearest 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.