Skip to content

Commit 7b05ed3

Browse files
Allow for particle longitude to be any value
* Particle longitude and grid longitudes are re-mapped to [-180,180) inside the curvilinear particle in cell check method. * Depending on the proximity of the particle to +/- 180, cell corners are adjusted to the image position that is closest to the particle.
1 parent 4c73ca3 commit 7b05ed3

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/parcels/_core/index_search.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,22 @@ def curvilinear_point_in_cell(grid, y: np.ndarray, x: np.ndarray, yi: np.ndarray
102102
)
103103

104104
px = np.array([grid.lon[yi, xi], grid.lon[yi, xi + 1], grid.lon[yi + 1, xi + 1], grid.lon[yi + 1, xi]])
105+
# Map grid and particle longitudes to [-180,180)
106+
px = ((px + 180.0) % 360.0) - 180.0
107+
x = ((x + 180.0) % 360.0) - 180.0
108+
109+
# Create a mask for antimeridian cells
105110
lon_span = px.max(axis=0) - px.min(axis=0)
106111
antimeridian_cell = lon_span > 180.0
107-
# For any antimeridian cell, bump the positive longitudes by 360 degrees
108-
# This only works if particle longitudes are always gauranteed to be less than 180 degreeds
109-
mask = (px > 0.0) & antimeridian_cell[np.newaxis, :]
110-
px[mask] -= 360.0
112+
113+
if np.any(antimeridian_cell):
114+
# For any antimeridian cell ...
115+
# If particle longitude is closer to 180.0, then negative cell longitudes need to be bumped by +360
116+
mask = (px < 0.0) & antimeridian_cell[np.newaxis, :] & (x[np.newaxis, :] > 0.0)
117+
px[mask] += 360.0
118+
# If particle longitude is closer to -180.0, then positive cell longitudes need to be bumped by -360
119+
mask = (px > 0.0) & antimeridian_cell[np.newaxis, :] & (x[np.newaxis, :] < 0.0)
120+
px[mask] -= 360.0
111121

112122
py = np.array([grid.lat[yi, xi], grid.lat[yi, xi + 1], grid.lat[yi + 1, xi + 1], grid.lat[yi + 1, xi]])
113123

0 commit comments

Comments
 (0)