Skip to content

Commit ace5c4f

Browse files
Change uxgrid spherical min/max bounds to unit cube
1 parent 0809675 commit ace5c4f

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

parcels/spatialhash.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,12 @@ def __init__(
123123
elif isinstance(grid, parcels.uxgrid.UxGrid):
124124
if self._source_grid._mesh == "spherical":
125125
# Boundaries of the hash grid are the unit cube
126-
self._xmin = self._source_grid.uxgrid.node_x.min().values
127-
self._xmax = self._source_grid.uxgrid.node_x.max().values
128-
self._ymin = self._source_grid.uxgrid.node_y.min().values
129-
self._ymax = self._source_grid.uxgrid.node_y.max().values
130-
self._zmin = self._source_grid.uxgrid.node_z.min().values
131-
self._zmax = self._source_grid.uxgrid.node_z.max().values
132-
126+
self._xmin = -1.0
127+
self._ymin = -1.0
128+
self._zmin = -1.0
129+
self._xmax = 1.0
130+
self._ymax = 1.0
131+
self._zmax = 1.0 # Compute the cell centers of the source grid (for now, assuming Xgrid)
133132
# Reshape node coordinates to (nfaces, nnodes_per_face)
134133
nids = self._source_grid.uxgrid.face_node_connectivity.values
135134
lon = self._source_grid.uxgrid.node_lon.values[nids]
@@ -200,17 +199,20 @@ def _initialize_hash_table(self):
200199
self._zmax,
201200
self._bitwidth,
202201
)
203-
xqlow = xqlow.ravel()
204-
yqlow = yqlow.ravel()
205-
zqlow = zqlow.ravel()
206-
xqhigh = xqhigh.ravel()
207-
yqhigh = yqhigh.ravel()
208-
zqhigh = zqhigh.ravel()
209-
nx = xqhigh - xqlow + 1
210-
ny = yqhigh - yqlow + 1
211-
nz = zqhigh - zqlow + 1
212-
num_hash_per_face = nx * ny * nz
213-
total_hash_entries = np.sum(num_hash_per_face)
202+
xqlow = xqlow.ravel().astype(np.int32, copy=False)
203+
yqlow = yqlow.ravel().astype(np.int32, copy=False)
204+
zqlow = zqlow.ravel().astype(np.int32, copy=False)
205+
xqhigh = xqhigh.ravel().astype(np.int32, copy=False)
206+
yqhigh = yqhigh.ravel().astype(np.int32, copy=False)
207+
zqhigh = zqhigh.ravel().astype(np.int32, copy=False)
208+
nx = (xqhigh - xqlow + 1).astype(np.int32, copy=False)
209+
ny = (yqhigh - yqlow + 1).astype(np.int32, copy=False)
210+
nz = (zqhigh - zqlow + 1).astype(np.int32, copy=False)
211+
num_hash_per_face = (nx * ny * nz).astype(
212+
np.int32, copy=False
213+
) # Since nx, ny, nz are in the 10-bit range, their product fits in int32
214+
total_hash_entries = int(num_hash_per_face.sum())
215+
214216
# Preallocate output arrays
215217
morton_codes = np.zeros(total_hash_entries, dtype=np.uint32)
216218

0 commit comments

Comments
 (0)