Skip to content

Commit 3eb2803

Browse files
Vectorizing _reconnect_bnd_indices
1 parent e476ebe commit 3eb2803

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

parcels/_index_search.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77

8+
from parcels._typing import Mesh
89
from parcels.tools.statuscodes import (
910
_raise_field_out_of_bound_error,
1011
_raise_field_sampling_error,
@@ -108,21 +109,13 @@ def _search_indices_curvilinear_2d(
108109
return (yi, eta, xi, xsi)
109110

110111

111-
def _reconnect_bnd_indices(yi: int, xi: int, ydim: int, xdim: int, sphere_mesh: bool):
112-
if xi < 0:
113-
if sphere_mesh:
114-
xi = xdim - 2
115-
else:
116-
xi = 0
117-
if xi > xdim - 2:
118-
if sphere_mesh:
119-
xi = 0
120-
else:
121-
xi = xdim - 2
122-
if yi < 0:
123-
yi = 0
124-
if yi > ydim - 2:
125-
yi = ydim - 2
126-
if sphere_mesh:
127-
xi = xdim - xi
112+
def _reconnect_bnd_indices(yi: int, xi: int, ydim: int, xdim: int, mesh: Mesh):
113+
xi = np.where(xi < 0, (xdim - 2) if mesh == "spherical" else 0, xi)
114+
xi = np.where(xi > xdim - 2, 0 if mesh == "spherical" else (xdim - 2), xi)
115+
116+
xi = np.where(yi > ydim - 2, xdim - xi if mesh == "spherical" else xi, xi)
117+
118+
yi = np.where(yi < 0, 0, yi)
119+
yi = np.where(yi > ydim - 2, ydim - 2, yi)
120+
128121
return yi, xi

0 commit comments

Comments
 (0)