Skip to content

Commit 9b0e3ec

Browse files
Fix ravel_index call for uxgrid grids
1 parent 47fbb58 commit 9b0e3ec

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

parcels/field.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,21 @@ def __getitem__(self, key):
345345
def _update_particles_ei(particles, position, field):
346346
"""Update the element index (ei) of the particles"""
347347
if particles is not None:
348-
particles.ei[:, field.igrid] = field.grid.ravel_index(
349-
{
350-
"X": position["X"][0],
351-
"Y": position["Y"][0],
352-
"Z": position["Z"][0],
353-
}
354-
)
348+
if isinstance(field.grid, XGrid):
349+
particles.ei[:, field.igrid] = field.grid.ravel_index(
350+
{
351+
"X": position["X"][0],
352+
"Y": position["Y"][0],
353+
"Z": position["Z"][0],
354+
}
355+
)
356+
elif isinstance(field.grid, UxGrid):
357+
particles.ei[:, field.igrid] = field.grid.ravel_index(
358+
{
359+
"Z": position["Z"][0],
360+
"FACE": position["FACE"][0],
361+
}
362+
)
355363

356364

357365
def _update_particle_states_position(particle, position):

tests/v4/test_particleset_execute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ def test_uxstommelgyre_pset_execute():
400400
dt=np.timedelta64(60, "s"),
401401
pyfunc=AdvectionEE,
402402
)
403-
assert utils.round_and_hash_float_array([p.lon for p in pset]) == 1165396086
404-
assert utils.round_and_hash_float_array([p.lat for p in pset]) == 1142124776
403+
assert utils.round_and_hash_float_array([p.lon for p in pset]) == 1165397121
404+
assert utils.round_and_hash_float_array([p.lat for p in pset]) == 1142123780
405405

406406

407407
@pytest.mark.xfail(reason="Output file not implemented yet")

0 commit comments

Comments
 (0)