Skip to content

Commit 4dc0deb

Browse files
Clean up face vertices construction and min/max setting for uxgrid spherical mesh type
1 parent 25c5e7e commit 4dc0deb

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

parcels/spatialhash.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ 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 = -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)
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
132132

133133
# Reshape node coordinates to (nfaces, nnodes_per_face)
134134
nids = self._source_grid.uxgrid.face_node_connectivity.values
135-
lon = self._source_grid.uxgrid.node_lon[nids.ravel()].values.reshape(nids.shape)
136-
lat = self._source_grid.uxgrid.node_lat[nids.ravel()].values.reshape(nids.shape)
135+
lon = self._source_grid.uxgrid.node_lon.values[nids]
136+
lat = self._source_grid.uxgrid.node_lat.values[nids]
137137
x, y, z = _latlon_rad_to_xyz(np.deg2rad(lat), np.deg2rad(lon))
138138
_xbound, _ybound, _zbound = _latlon_rad_to_xyz(np.deg2rad(lat), np.deg2rad(lon))
139139

@@ -156,8 +156,8 @@ def __init__(
156156
self._zmax = 0.0
157157
# Reshape node coordinates to (nfaces, nnodes_per_face)
158158
nids = self._source_grid.uxgrid.face_node_connectivity.values
159-
lon = self._source_grid.uxgrid.node_lon[nids.ravel()].values.reshape(nids.shape)
160-
lat = self._source_grid.uxgrid.node_lat[nids.ravel()].values.reshape(nids.shape)
159+
lon = self._source_grid.uxgrid.node_lon.values[nids]
160+
lat = self._source_grid.uxgrid.node_lat.values[nids]
161161

162162
# Compute bounding box of each face
163163
self._xlow = np.atleast_2d(np.min(lon, axis=-1))
@@ -211,6 +211,7 @@ def _initialize_hash_table(self):
211211
nz = zqhigh - zqlow + 1
212212
num_hash_per_face = nx * ny * nz
213213
total_hash_entries = np.sum(num_hash_per_face)
214+
# Preallocate output arrays
214215
morton_codes = np.zeros(total_hash_entries, dtype=np.uint32)
215216

216217
# Compute the j, i indices corresponding to each hash entry

0 commit comments

Comments
 (0)