Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running parcels in a grid with a coordinate grid with missing values (nans) #1495

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,14 @@
continue

tree_data = np.stack((grid.lon.flat, grid.lat.flat), axis=-1)
tree = KDTree(tree_data)
IN = np.all(~np.isnan(tree_data), axis=1)
tree = KDTree(tree_data[IN, :])

Check warning on line 454 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L453-L454

Added lines #L453 - L454 were not covered by tests
# stack all the particle positions for a single query
pts = np.stack((self.particledata.data['lon'], self.particledata.data['lat']), axis=-1)
# query datatype needs to match tree datatype
_, idx = tree.query(pts.astype(tree_data.dtype))
_, idx_nan = tree.query(pts.astype(tree_data.dtype))

Check warning on line 458 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L458

Added line #L458 was not covered by tests

idx = np.where(IN)[0][idx_nan]

Check warning on line 460 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L460

Added line #L460 was not covered by tests
yi, xi = np.unravel_index(idx, grid.lon.shape)

self.particledata.data['xi'][:, i] = xi
Expand Down
Loading