Skip to content

Commit 3e2d18e

Browse files
Move xbound,ybound calculation to spatialhash.__init__
1 parent 9622349 commit 3e2d18e

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

parcels/spatialhash.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ def __init__(
3737
lon_max = self._source_grid.lon.max()
3838
lat_max = self._source_grid.lat.max()
3939

40+
# Get corner vertices of each face
41+
self._xbound = np.stack(
42+
(
43+
self._source_grid.lon[:-1, :-1],
44+
self._source_grid.lon[:-1, 1:],
45+
self._source_grid.lon[1:, 1:],
46+
self._source_grid.lon[1:, :-1],
47+
),
48+
axis=-1,
49+
)
50+
self._ybound = np.stack(
51+
(
52+
self._source_grid.lat[:-1, :-1],
53+
self._source_grid.lat[:-1, 1:],
54+
self._source_grid.lat[1:, 1:],
55+
self._source_grid.lat[1:, :-1],
56+
),
57+
axis=-1,
58+
)
59+
4060
self._xmin = lon_min - self._dh
4161
self._ymin = lat_min - self._dh
4262
self._xmax = lon_max + self._dh
@@ -152,33 +172,13 @@ def query(
152172
# Get the list of candidate faces for each coordinate
153173
candidate_faces = [self._face_hash_table[pid] for pid in self._hash_index(coords)]
154174

155-
# Get corner vertices of each face
156-
xbound = np.stack(
157-
(
158-
self._source_grid.lon[:-1, :-1],
159-
self._source_grid.lon[:-1, 1:],
160-
self._source_grid.lon[1:, 1:],
161-
self._source_grid.lon[1:, :-1],
162-
),
163-
axis=-1,
164-
)
165-
ybound = np.stack(
166-
(
167-
self._source_grid.lat[:-1, :-1],
168-
self._source_grid.lat[:-1, 1:],
169-
self._source_grid.lat[1:, 1:],
170-
self._source_grid.lat[1:, :-1],
171-
),
172-
axis=-1,
173-
)
174-
175175
for i, (coord, candidates) in enumerate(zip(coords, candidate_faces, strict=False)):
176176
for face_id in candidates:
177177
xi, yi = self._grid_ij_for_eid(face_id)
178178
nodes = np.stack(
179179
(
180-
xbound[yi, xi, :],
181-
ybound[yi, xi, :],
180+
self._xbound[yi, xi, :],
181+
self._ybound[yi, xi, :],
182182
),
183183
axis=-1,
184184
)

0 commit comments

Comments
 (0)