Interpolate nd array with multiple independent indexers It should do a series of 1d interpolation
(
method: InterpOptions, data_ndim, interp_ndim, nscalar, chunked: bool
)
| 901 | ) |
| 902 | @pytest.mark.filterwarnings("ignore:Increasing number of chunks") |
| 903 | def test_interpolate_chunk_1d( |
| 904 | method: InterpOptions, data_ndim, interp_ndim, nscalar, chunked: bool |
| 905 | ) -> None: |
| 906 | """Interpolate nd array with multiple independent indexers |
| 907 | |
| 908 | It should do a series of 1d interpolation |
| 909 | """ |
| 910 | |
| 911 | if method in ["cubic", "pchip", "quintic"] and interp_ndim == 3: |
| 912 | pytest.skip("Too slow.") |
| 913 | |
| 914 | # 3d non chunked data |
| 915 | x = np.linspace(0, 1, 6) |
| 916 | y = np.linspace(2, 4, 7) |
| 917 | z = np.linspace(-0.5, 0.5, 8) |
| 918 | da = xr.DataArray( |
| 919 | data=np.sin(x[:, np.newaxis, np.newaxis]) |
| 920 | * np.cos(y[:, np.newaxis]) |
| 921 | * np.exp(z), |
| 922 | coords=[("x", x), ("y", y), ("z", z)], |
| 923 | ) |
| 924 | |
| 925 | # choose the data dimensions |
| 926 | for data_dims in permutations(da.dims, data_ndim): |
| 927 | # select only data_ndim dim |
| 928 | da = da.isel( # take the middle line |
| 929 | {dim: len(da.coords[dim]) // 2 for dim in da.dims if dim not in data_dims} |
| 930 | ) |
| 931 | |
| 932 | # chunk data |
| 933 | da = da.chunk(chunks={dim: i + 1 for i, dim in enumerate(da.dims)}) |
| 934 | |
| 935 | # choose the interpolation dimensions |
| 936 | for interp_dims in permutations(da.dims, interp_ndim): |
| 937 | # choose the scalar interpolation dimensions |
| 938 | for scalar_dims in combinations(interp_dims, nscalar): |
| 939 | dest = {} |
| 940 | for dim in interp_dims: |
| 941 | if dim in scalar_dims: |
| 942 | # take the middle point |
| 943 | dest[dim] = 0.5 * (da.coords[dim][0] + da.coords[dim][-1]) |
| 944 | else: |
| 945 | # pick some points, including outside the domain |
| 946 | before = 2 * da.coords[dim][0] - da.coords[dim][1] |
| 947 | after = 2 * da.coords[dim][-1] - da.coords[dim][-2] |
| 948 | |
| 949 | dest[dim] = cast( |
| 950 | xr.DataArray, |
| 951 | np.linspace( |
| 952 | before.item(), after.item(), len(da.coords[dim]) * 13 |
| 953 | ), |
| 954 | ) |
| 955 | if chunked: |
| 956 | dest[dim] = xr.DataArray(data=dest[dim], dims=[dim]) |
| 957 | dest[dim] = dest[dim].chunk(2) |
| 958 | actual = da.interp(method=method, **dest) |
| 959 | expected = da.compute().interp(method=method, **dest) |
| 960 |
nothing calls this directly
no test coverage detected
searching dependent graphs…