pydata / pydata/xarray

Does interp() work on curvilinear grids (2D coordinates) ?

Open
#2,281 28 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-indexing topic-interpolation
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

I am evaluating interp() against xESMF. Here's how xESMF would regrid the built-in 'rasm' data to a regular lat-lon grid.

Seems like interp() can convert rectilinear grids (1D coordinates) to curvilinear grids (2D coordinates), according to the last example. How about the reverse? Can it convert 2D coordinate to 1D, or to another 2D coordinate?

That's the test data:

dr = xr.tutorial.load_dataset('rasm')['Tair']
...
Coordinates:
  * time     (time) datetime64[ns] 1980-09-16T12:00:00 1980-10-17 ...
    xc       (y, x) float64 189.2 189.4 189.6 189.7 189.9 190.1 190.2 190.4 ...
    yc       (y, x) float64 16.53 16.78 17.02 17.27 17.51 17.76 18.0 18.25 ...

That's a simple destination grid:

lon = xr.DataArray(np.linspace(-180, 180, 120), dims=['lon'])
lat = xr.DataArray(np.linspace(-90, 90, 60), dims=['lat'])

I would expect a syntax like:

dr_out = dr.interp(xc=lon, yc=lat)

But I got ValueError: dimensions ['xc', 'yc'] do not exist, becauseinterp() only accepts dimensions (which must be 1D), not coordinates.

dr.interp(x=lon, y=lat) runs but the result is not correct. This is expected because x does not mean longitude in the original data.

@crusaderky @fujiisoup

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported interp() behavior with the tutorial rasm dataset and the provided lon/lat destination grid. Read the interpolation documentation example and compare the result with the linked xESMF curvilinear-grid workflow. Done should define whether 2D source coordinates can be mapped to 1D or 2D destination coordinates and document or implement the supported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.