SciTools / iris-esmf-regrid

A collection of structured and unstructured ESMF regridding schemes for Iris.
https://iris-esmf-regrid.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
19 stars 17 forks source link

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

Open bouweandela opened 3 months ago

bouweandela commented 3 months 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 3 months 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.

stephenworsley commented 3 weeks ago

@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?