@@ -216,13 +216,14 @@ def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
216216 else :
217217 _ei = particles .ei [:, self .igrid ]
218218
219- position = {"time" : time , "z" : z , "lat" : y , "lon" : x }
220- position .update (_search_time_index (self , time ))
221- position .update (self .grid .search (z , y , x , ei = _ei ))
222- _update_particles_ei (particles , position , self )
223- _update_particle_states_position (particles , position )
219+ particle_positions = {"time" : time , "z" : z , "lat" : y , "lon" : x }
220+ grid_positions = {}
221+ grid_positions .update (_search_time_index (self , time ))
222+ grid_positions .update (self .grid .search (z , y , x , ei = _ei ))
223+ _update_particles_ei (particles , grid_positions , self )
224+ _update_particle_states_position (particles , grid_positions )
224225
225- value = self ._interp_method (position , self )
226+ value = self ._interp_method (particle_positions , grid_positions , self )
226227
227228 _update_particle_states_interp_value (particles , value )
228229
@@ -301,21 +302,22 @@ def eval(self, time: datetime, z, y, x, particles=None, applyConversion=True):
301302 else :
302303 _ei = particles .ei [:, self .igrid ]
303304
304- position = {"time" : time , "z" : z , "lat" : y , "lon" : x }
305- position .update (_search_time_index (self .U , time ))
306- position .update (self .grid .search (z , y , x , ei = _ei ))
307- _update_particles_ei (particles , position , self )
308- _update_particle_states_position (particles , position )
305+ particle_positions = {"time" : time , "z" : z , "lat" : y , "lon" : x }
306+ grid_positions = {}
307+ grid_positions .update (_search_time_index (self .U , time ))
308+ grid_positions .update (self .grid .search (z , y , x , ei = _ei ))
309+ _update_particles_ei (particles , grid_positions , self )
310+ _update_particle_states_position (particles , grid_positions )
309311
310312 if self ._vector_interp_method is None :
311- u = self .U ._interp_method (position , self .U )
312- v = self .V ._interp_method (position , self .V )
313+ u = self .U ._interp_method (particle_positions , grid_positions , self .U )
314+ v = self .V ._interp_method (particle_positions , grid_positions , self .V )
313315 if "3D" in self .vector_type :
314- w = self .W ._interp_method (position , self .W )
316+ w = self .W ._interp_method (particle_positions , grid_positions , self .W )
315317 else :
316318 w = 0.0
317319 else :
318- (u , v , w ) = self ._vector_interp_method (position , self )
320+ (u , v , w ) = self ._vector_interp_method (particle_positions , grid_positions , self )
319321
320322 if applyConversion :
321323 u = self .U .units .to_target (u , z , y , x )
@@ -341,45 +343,54 @@ def __getitem__(self, key):
341343 return _deal_with_errors (error , key , vector_type = self .vector_type )
342344
343345
344- def _update_particles_ei (particles , position , field ):
346+ def _update_particles_ei (particles , grid_positions , field ):
345347 """Update the element index (ei) of the particles"""
346348 if particles is not None :
347349 if isinstance (field .grid , XGrid ):
348350 particles .ei [:, field .igrid ] = field .grid .ravel_index (
349351 {
350- "X" : position [ "xi " ],
351- "Y" : position [ "yi " ],
352- "Z" : position [ "zi " ],
352+ "X" : grid_positions [ "X" ][ "index " ],
353+ "Y" : grid_positions [ "Y" ][ "index " ],
354+ "Z" : grid_positions [ "Z" ][ "index " ],
353355 }
354356 )
355357 elif isinstance (field .grid , UxGrid ):
356358 particles .ei [:, field .igrid ] = field .grid .ravel_index (
357359 {
358- "Z" : position ["Z" ][0 ],
359- "FACE" : position ["FACE" ][0 ],
360+ "Z" : grid_positions ["Z" ]["index" ],
361+ "FACE" : grid_positions ["FACE" ]["index" ],
360362 }
361363 )
362364
363365
364- def _update_particle_states_position (particles , position ):
366+ def _update_particle_states_position (particles , grid_positions ):
365367 """Update the particle states based on the position dictionary."""
366368 if particles : # TODO also support uxgrid search
367- for dim in ["xi " , "yi " ]:
368- if dim in position :
369+ for dim in ["X " , "Y " ]:
370+ if dim in grid_positions :
369371 particles .state = np .maximum (
370- np .where (position [dim ] == - 1 , StatusCode .ErrorOutOfBounds , particles .state ), particles .state
372+ np .where (grid_positions [dim ]["index" ] == - 1 , StatusCode .ErrorOutOfBounds , particles .state ),
373+ particles .state ,
371374 )
372375 particles .state = np .maximum (
373- np .where (position [dim ] == GRID_SEARCH_ERROR , StatusCode .ErrorGridSearching , particles .state ),
376+ np .where (
377+ grid_positions [dim ]["index" ] == GRID_SEARCH_ERROR ,
378+ StatusCode .ErrorGridSearching ,
379+ particles .state ,
380+ ),
374381 particles .state ,
375382 )
376- if "zi " in position :
383+ if "Z " in grid_positions :
377384 particles .state = np .maximum (
378- np .where (position ["zi" ][0 ] == RIGHT_OUT_OF_BOUNDS , StatusCode .ErrorOutOfBounds , particles .state ),
385+ np .where (
386+ grid_positions ["Z" ]["index" ] == RIGHT_OUT_OF_BOUNDS , StatusCode .ErrorOutOfBounds , particles .state
387+ ),
379388 particles .state ,
380389 )
381390 particles .state = np .maximum (
382- np .where (position ["zi" ][0 ] == LEFT_OUT_OF_BOUNDS , StatusCode .ErrorThroughSurface , particles .state ),
391+ np .where (
392+ grid_positions ["Z" ]["index" ] == LEFT_OUT_OF_BOUNDS , StatusCode .ErrorThroughSurface , particles .state
393+ ),
383394 particles .state ,
384395 )
385396
0 commit comments