Skip to content

Commit cfc84ac

Browse files
Set the number of computational coordinates during init
This ensures that "no-hit" queries return coordinates with the right dimensions
1 parent 92b6b49 commit cfc84ac

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

parcels/spatialhash.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(
3636
self._bitwidth = bitwidth # Max integer to use per coordinate in quantization (10 bits = 0..1023)
3737

3838
if isinstance(grid, parcels.xgrid.XGrid):
39+
self._coord_dim = 2 # Number of computational coordinates is 2 (bilinear interpolation)
3940
if self._source_grid._mesh == "spherical":
4041
# Boundaries of the hash grid are the unit cube
4142
self._xmin = -1.0
@@ -121,6 +122,7 @@ def __init__(
121122
self._zhigh = np.zeros_like(self._xlow)
122123

123124
elif isinstance(grid, parcels.uxgrid.UxGrid):
125+
self._coord_dim = grid.uxgrid.n_max_face_nodes # Number of barycentric coordinates
124126
if self._source_grid._mesh == "spherical":
125127
# Boundaries of the hash grid are the unit cube
126128
self._xmin = -1.0
@@ -356,7 +358,7 @@ def query(self, y, x):
356358
return (
357359
j_best.reshape(query_codes.shape),
358360
i_best.reshape(query_codes.shape),
359-
np.full((num_queries, 2), -1.0, dtype=np.float32),
361+
np.full((num_queries, self._coord_dim), -1.0, dtype=np.float32),
360362
)
361363

362364
# Now, for each query, we need to gather the candidate (j,i) indices from the hash table

0 commit comments

Comments
 (0)