Skip to content

Commit 92c3d82

Browse files
Fixing bug in creation of xi and yi indices
Speeding this up to be explored later...
1 parent dd9bfd2 commit 92c3d82

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

parcels/application_kernels/interpolation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ def XLinear(
7171
zi = np.tile(np.stack([zi, zi, zi, zi, zi_1, zi_1, zi_1, zi_1], axis=1).flatten(), lenT)
7272

7373
# Y coordinates: [yi, yi, yi+1, yi+1] pattern repeated
74+
# TODO consider using np.repeat for better performance
7475
yi_1 = np.clip(yi + 1, 0, data.shape[2] - 1)
75-
yi = np.tile(np.repeat([yi, yi_1], 2), (lenT) * (lenZ))
76+
yi = np.tile(np.stack([yi, yi, yi_1, yi_1], axis=1).flatten(), (lenT) * (lenZ))
7677

7778
# X coordinates: [xi, xi+1] for each spatial point, repeated for time/depth
79+
# TODO consider using np.repeat for better performance
7880
xi_1 = np.clip(xi + 1, 0, data.shape[3] - 1)
79-
xi = np.repeat([xi, xi_1], 2 * (lenT) * (lenZ))
81+
xi = np.tile(np.stack([xi, xi_1, xi, xi_1], axis=1).flatten(), (lenT) * (lenZ))
8082

8183
# Create DataArrays for indexing
8284
ti_da = xr.DataArray(ti, dims=("points"))
@@ -87,7 +89,7 @@ def XLinear(
8789
F = data.isel({axis_dim["X"]: xi_da, axis_dim["Y"]: yi_da, axis_dim["Z"]: zi_da, "time": ti_da})
8890
F = F.data.reshape(-1, lenT, lenZ, 4)
8991
# TODO check if numpy can handle this more efficiently
90-
# F = data.values[tti, zii, yii, xii].reshape(-1, 4)
92+
# F = data.values[ti, zi, yi, xi].reshape(-1, lenT, lenZ, 4)
9193

9294
if lenT == 2:
9395
F_t0, F_t1 = F[:, 0, :, :], F[:, 1, :, :]

0 commit comments

Comments
 (0)