Skip to content

Conversation

@erikvansebille
Copy link
Member

@erikvansebille erikvansebille commented Aug 19, 2025

This PR adds a unit test for spatial hash on 1/4 degree NEMO curvilinear grid (from https://github.com/OceanParcels/parcels-data/tree/main/data/NemoCurvilinear_data).

The unit test currently fails, because the spatial hash index returned is the cell on the anti-meridian (between 179.875 and 179.875; which technically also surrounds the location) instead of the cell that snugly surrounds the location

The unit test currently fails, because the spatial hash index returned is the cell on the anti-meridian (between 179.875 and 179.875)
@erikvansebille
Copy link
Member Author

A simple change to the lines below seems to fix the failing unit test
https://github.com/OceanParcels/Parcels/blob/85f025be11cd122f8ac4bba463db2a97860c2549/parcels/spatialhash.py#L141-L150

- if xi1[eid] <= xi2[eid]:
+ if abs(xi1[eid] - xi2[eid]) > 225:
+     pass
+ elif xi1[eid] <= xi2[eid]:

This way, the grid cells that span the antemeridian (where the left corner is 179.875 and the right corner is -179.875) are not included in the hash table. However, we would need to make this work only when the field _mesh_type="spherical" (because on flat grids, it's to be expected that grid cells have distances of more than 225 meters between them)

@fluidnumerics-joe, does this give you some pointers/ideas how to fix the spatial hash.py function to make the unit test in this PR pass?

PS: Note that the 'special' value of 225 used above is also present in the v3-version of _index_search:
https://github.com/OceanParcels/Parcels/blob/fb88390d2bc9e2d45cd3056c601c7acaa9afcdac/parcels/_index_search.py#L253-L254

Base automatically changed from vectorized-kernel to v4-dev August 19, 2025 18:26
@erikvansebille
Copy link
Member Author

Here's a map of the longitude grid
image

erikvansebille added a commit that referenced this pull request Aug 22, 2025
@erikvansebille
Copy link
Member Author

With the new Morton having, this test passes. Good to pull it into the test-suite?

@erikvansebille erikvansebille marked this pull request as ready for review September 1, 2025 10:26
@erikvansebille erikvansebille merged commit b185396 into v4-dev Sep 3, 2025
8 of 9 checks passed
@erikvansebille erikvansebille deleted the testing_nemo_spatialhash branch September 3, 2025 06:13
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants