Skip to content

xarray interp with method="cubic" fails for time/lon/lat interpolation #11342

Open

Description

@mnergizci

Hi, I am trying to interpolate a TEC DataArray using xarray:

tec_val0 = float(
    tecxr.interp(time=pretime, lon=lon0, lat=lat, method="cubic")
)

This work with 'method="linear"' but it never ends when I use 'method="cubic"'?

I am a bit confused as it was alright; just for couple of months ago

Is anyone experience same problem or any update?

Cheers,
MN

Activity

  1. added
    needs triageIssue that has not been reviewed by xarray team member
    on May 15, 2026
  2. headtr1ck commented on May 19, 2026

    @headtr1ck
    Collaborator

    Can you please post a minimal complete code example that we can test? Thanks!

  3. added
    needs mcvehttps://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
    on May 19, 2026
  4. ghostiee-11 commented on Aug 10, 2026

    @ghostiee-11

    mcve

    import numpy as np, pandas as pd, xarray as xr
    
    nt = 288
    da = xr.DataArray(
        np.random.rand(nt, 71, 73), dims=("time", "lat", "lon"),
        coords={"time": pd.date_range("2026-01-01", periods=nt, freq="15min"),
                "lat": np.linspace(-87.5, 87.5, 71),
                "lon": np.linspace(-180, 180, 73)},
    )
    pt = dict(time=da.time[nt // 2], lon=12.3, lat=45.6)
    
    da.interp(**pt, method="linear").item()   # 0.24s, +42 MB
    da.interp(**pt, method="cubic").item()    # 3.93s, +1.8 GB

    dont think its xarray though. same call straight to scipy costs the same, 3.69s and 2.2 GB

    from scipy.interpolate import interpn
    interpn((np.arange(nt, dtype=float), da.lat.values, da.lon.values),
            da.values, np.array([[nt / 2, 45.6, 12.3]]), method="cubic")

    nd cubic builds a spline over the whole grid even for one point, linear only touches the cells around it. so it scales with the array not with how many points you ask for.

    @mnergizci if your tec is a month of 15 min maps thats ~2880 steps, 10x the above. that one got oom killed here (exit 137), so it looks like a hang but its memory.

    workaround, cubic on time only then linear on lat lon, 0.04s

    da.interp(time=pt["time"], method="cubic").interp(lon=12.3, lat=45.6, method="linear")

    scipy 1.18.0, xarray 2026.7.1.dev24

  5. added and removed
    needs mcvehttps://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
    needs triageIssue that has not been reviewed by xarray team member
    on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions