Interpolate nd array with an nd indexer sharing coordinates.
(method: InterpOptions)
| 972 | @pytest.mark.parametrize("method", ("linear", "nearest", "slinear", "cubic", "pchip")) |
| 973 | @pytest.mark.filterwarnings("ignore:Increasing number of chunks") |
| 974 | def test_interpolate_chunk_advanced(method: InterpOptions) -> None: |
| 975 | """Interpolate nd array with an nd indexer sharing coordinates.""" |
| 976 | # Create original array |
| 977 | x = np.linspace(-1, 1, 5) |
| 978 | y = np.linspace(-1, 1, 7) |
| 979 | z = np.linspace(-1, 1, 11) |
| 980 | t = np.linspace(0, 1, 13) |
| 981 | q = np.linspace(0, 1, 17) |
| 982 | da = xr.DataArray( |
| 983 | data=np.sin(x[:, np.newaxis, np.newaxis, np.newaxis, np.newaxis]) |
| 984 | * np.cos(y[:, np.newaxis, np.newaxis, np.newaxis]) |
| 985 | * np.exp(z[:, np.newaxis, np.newaxis]) |
| 986 | * t[:, np.newaxis] |
| 987 | + q, |
| 988 | dims=("x", "y", "z", "t", "q"), |
| 989 | coords={"x": x, "y": y, "z": z, "t": t, "q": q, "label": "dummy_attr"}, |
| 990 | ) |
| 991 | |
| 992 | # Create indexer into `da` with shared coordinate ("full-twist" Möbius strip) |
| 993 | theta = np.linspace(0, 2 * np.pi, 5) |
| 994 | w = np.linspace(-0.25, 0.25, 7) |
| 995 | r = xr.DataArray( |
| 996 | data=1 + w[:, np.newaxis] * np.cos(theta), |
| 997 | coords=[("w", w), ("theta", theta)], |
| 998 | ) |
| 999 | |
| 1000 | xda = r * np.cos(theta) |
| 1001 | yda = r * np.sin(theta) |
| 1002 | zda = xr.DataArray( |
| 1003 | data=w[:, np.newaxis] * np.sin(theta), |
| 1004 | coords=[("w", w), ("theta", theta)], |
| 1005 | ) |
| 1006 | |
| 1007 | kwargs = {"fill_value": None} |
| 1008 | expected = da.interp(t=0.5, x=xda, y=yda, z=zda, kwargs=kwargs, method=method) |
| 1009 | |
| 1010 | da = da.chunk(2) |
| 1011 | xda = xda.chunk(1) |
| 1012 | zda = zda.chunk(3) |
| 1013 | actual = da.interp(t=0.5, x=xda, y=yda, z=zda, kwargs=kwargs, method=method) |
| 1014 | assert_identical(actual, expected) |
| 1015 | |
| 1016 | |
| 1017 | @requires_scipy |