question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Value Error when using bilinear interpolation method

See original GitHub issue

Hi! I was using the bilinear method and kept encountering an error message:

import gcsfs
import xarray as xr
import xesmf as xe

fs = gcsfs.GCSFileSystem(token='anon', access='read_only')
mapper = fs.get_mapper('gs://cmip6/CMIP6/CMIP/MPI-M/MPI-ESM1-2-HR/historical/r1i1p1f1/Omon/thetao/gn/v20190710/')
ds = xr.open_zarr(mapper, consolidated=True)
target_grid = xe.util.grid_global(1,1)
regridder = xe.Regridder(ds, target_grid, 'bilinear')
var_regrid = regridder(ds)

Error:

ValueError: ESMC_FieldRegridStore failed with rc = 506. Please check the log files (named "*ESMF_LogFile").

Fortunately @jbusecke guided me to a solution:

regridder = xe.Regridder(ds, target_grid, 'bilinear', ignore_degenerate=True)

I was wondering if the error message could be edited to reflect that adding the kwarg ignore_degenerate=True resolves it? Its difficult to work out how to resolve the issue with the existing ValueError message. Thanks!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sol1105commented, Sep 28, 2022

Hi @jdldeauna ,

this problem is caused by the data having been published on a grid which still contains the grid halo (rows or columns of duplicated grid cells), which is required during the model run. The grid halo cells are often not properly defined and are collapsing to lines or points and are only sharing the cell centers with their original, which then leads to this ValueError in ESMF (see #109).

This problem exists for quite a few CMIP ocean models. What you can usually do (besides using ignore_degenerated=True), is to remove the grid halo before creating remapping weights with xesmf or other tools. Beware that not removing the grid halo can lead to incorrect results when using the conservative remapping method. Also beware that data not defined on the grid cell centers, but rather on the vertices / edges, require special treatment.

Here is an example with CDOs (Climate Data Operators): https://wiki.mpimet.mpg.de/doku.php?id=analysis:postprocessing_mpiesm:regridding (here, GR15 corresponds to MPI-ESM1-2-LR MPIOM; TP04 to MPI-ESM1-2-HR MPIOM)

And here an example for xarray, for MPI-ESM1-2-LR/HR (see also #109 or this notebook):

# Define paths to the data
path_mpiesmlr="./tos_Omon_MPI-ESM1-2-LR_historical_r1i1p1f1_gn_201001-201412.nc"
path_mpiesmhr="./tos_Omon_MPI-ESM1-2-HR_historical_r1i1p1f1_gn_201001-201412.nc"

# Read the data with halo
ds_mpiesmlr_halo=xr.open_dataset(path_mpiesmlr).isel(time=0)
ds_mpiesmhr_halo=xr.open_dataset(path_mpiesmhr).isel(time=0)

# Read the data without halo (LR - omit first and last column, HR - omit first and last column, first 2 rows)
ds_mpiesmlr=xr.open_dataset(path_mpiesmlr).isel(time=0).isel(i=slice(1, 255))
ds_mpiesmhr=xr.open_dataset(path_mpiesmhr).isel(time=0).isel(i=slice(1, 801), j=slice(2,404))
1reaction
jbuseckecommented, Sep 28, 2022

I just wanted to chime in and say that this could be very helpful for the broader community. Since I found the workaround at some point in the past, I have interacted with many folks who experienced this issue.

Also many thanks for raising this issue @jdldeauna!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR IN LINEAR INTERPOLATION
when interpolating in a table of given function values (e.g. log10 x). The quantity ... would have an error comparable to a table...
Read more >
Bilinear Interpolation - an overview ... - ScienceDirect.com
This error is affected by the interpolation method. Empirically, we find that bilinear interpolation works better than quartic interpolation in terms of ...
Read more >
Bilinear interpolation - Wikipedia
In mathematics, bilinear interpolation is a method for interpolating functions of two variables (e.g., x and y) using repeated linear interpolation.
Read more >
Image Processing – Bilinear Interpolation | TheAILearner
In this blog, we will discuss Bi-linear interpolation method in detail. ... Linear interpolation means we estimate the value using linear ...
Read more >
Confidence intervals for bilinear interpolation - Cross Validated
I have 4 data points which I am using to interpolate a query point using bilinear interpolation. Each of the 4 data points...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found