home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1692523672

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1692523672 I_kwDOAMm_X85k4dyY 7807 Interpolation on unstructured data/irregular grid 16798775 open 0     1 2023-05-02T14:22:15Z 2023-05-02T14:23:54Z   NONE      

Is your feature request related to a problem?

Hello all. First, thanks for this amazing library!

I'm working with unstructured data ( points that are not in a grid ), and I want to interpolate them onto a regular grid. However, it seems it is not directly supported by xarray and I have to manually call scipy's griddata. This is annoying because: * It's verbose and I'm lazy * I loose my array's metadata

It seems the problem is encoutered by some other people as a google search on xarray interp irregular data yields to some results: * https://stackoverflow.com/questions/60495410/add-irregular-data-lat-lons-to-xarray-dataset-for-interpolation * https://gis.stackexchange.com/questions/455149/interpolate-irregularly-sampled-data-to-a-regular-grid

Searching for issues related to this topic led me to this single issue https://github.com/pydata/xarray/issues/5281 where the user uses directly scipy's griddata to interpolate.

Here is a sample script to reproduce and illustrate the problem: ```python from xarray import DataArray import numpy as np import matplotlib.pyplot as plt

Sample 1000 uniform points in [-1,1]

Thus, those points are unstructured

x, y = points = np.random.uniform(-1, 1, (2, 1000)) x, y = points = DataArray( points, coords=dict( variable=list("XY"), point=np.arange(1000), x=("point", x), y=("point", y) ), dims=("variable", "point"), )

Compute a dummy "function"

z = np.sqrt(x2 + y2) print(z)

We now have a function sampled on unstructured points

fig, ax = plt.subplots(1, 1) ax.scatter(x, y, c=z) ax.set_xlabel("x") ax.set_ylabel("y") ax.set_aspect(1)

plt.show() I get the following value for `z`:text <xarray.DataArray (point: 1000)> array([...blablabla whatever...]) Coordinates: * point (point) int64 0 1 2 3 4 5 6 7 8 ... 992 993 994 995 996 997 998 999 x (point) float64 -0.4088 -0.7709 -0.7345 ... 0.5191 0.6061 -0.7329 y (point) float64 -0.8546 -0.6544 -0.6771 ... -0.8286 -0.04476 -0.574 ``` And it looks like so:

So we can see z is correctly annotated and we've got the x and y value for each point, but I still cannot interpolate on a regular grid: python z.interp(x=np.linspace(-1, 1, 100), y=np.linspace(-1, 1, 100)) It raises the following error: Dimensions {'x', 'y'} do not exist. Expected one or more of Frozen({'point': 1000})

Describe the solution you'd like

It would be nice to allow a direct unstructured interpolation if variables are correctly annotated (I supposed it's done with panda's multi indexes?)

This could be done using Scipy's griddata

A check could be added in interp function to see if the user wants to interpolate on sub-dimensions (i'm not sure if the name is appropriate), and if so, using griddata instead of the other interpolation methods.

Describe alternatives you've considered

Alternative solutions could be to use only scipy grid data by hand, but that would be sad.

Additional context

No response

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7807/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 1.058ms · About: xarray-datasette