MCPcopy Index your code
hub / github.com/pydata/xarray / test_interpolate_nd

Function test_interpolate_nd

xarray/tests/test_interp.py:304–363  ·  view source on GitHub ↗
(case: int, method: InterpnOptions, nd_interp_coords)

Source from the content-addressed store, hash-verified

302 ],
303)
304def test_interpolate_nd(case: int, method: InterpnOptions, nd_interp_coords) -> None:
305 da = get_example_data(case)
306
307 # grid -> grid
308 xdestnp = nd_interp_coords["xdestnp"]
309 ydestnp = nd_interp_coords["ydestnp"]
310 zdestnp = nd_interp_coords["zdestnp"]
311 grid_grid_points = nd_interp_coords["grid_grid_points"]
312 # the presence/absence of z coordinate may affect nd interpolants, even when the
313 # coordinate is unchanged
314 # TODO: test this?
315 actual = da.interp(x=xdestnp, y=ydestnp, z=zdestnp, method=method)
316 expected_data = scipy.interpolate.interpn(
317 points=(da.x, da.y, da.z),
318 values=da.load().data,
319 xi=grid_grid_points,
320 method=method,
321 bounds_error=False,
322 ).reshape((len(xdestnp), len(ydestnp), len(zdestnp)))
323 expected = xr.DataArray(
324 expected_data,
325 dims=["x", "y", "z"],
326 coords={
327 "x": xdestnp,
328 "y": ydestnp,
329 "z": zdestnp,
330 "x2": da["x2"].interp(x=xdestnp, method=method),
331 },
332 )
333 assert_allclose(actual.transpose("x", "y", "z"), expected.transpose("x", "y", "z"))
334
335 # grid -> 1d-sample
336 xdest = nd_interp_coords["xdest"]
337 ydest = nd_interp_coords["ydest"]
338 zdest = nd_interp_coords["zdest"]
339 grid_oned_points = nd_interp_coords["grid_oned_points"]
340 actual = da.interp(x=xdest, y=ydest, z=zdest, method=method)
341 expected_data_1d: np.ndarray = scipy.interpolate.interpn(
342 points=(da.x, da.y, da.z),
343 values=da.data,
344 xi=grid_oned_points,
345 method=method,
346 bounds_error=False,
347 ).reshape([len(xdest), len(zdest)])
348 expected = xr.DataArray(
349 expected_data_1d,
350 dims=["y", "z"],
351 coords={
352 "y": ydest,
353 "z": zdest,
354 "x": ("y", xdest.values),
355 "x2": da["x2"].interp(x=xdest, method=method),
356 },
357 )
358
359 assert_allclose(actual.transpose("y", "z"), expected)
360
361 # reversed order

Callers

nothing calls this directly

Calls 6

transposeMethod · 0.95
assert_allcloseFunction · 0.90
get_example_dataFunction · 0.85
interpMethod · 0.45
loadMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…