33
44from numba import njit
55from numba import types as nb_types
6- from numpy import arange , array , int32 , interp , median , where , zeros
6+ from numpy import arange , int32 , interp , median , where , zeros
77
8- from ..poly import create_vertice , reduce_size , winding_number_poly
98from .observation import EddiesObservations
109
1110logger = logging .getLogger ("pet" )
@@ -88,41 +87,6 @@ def advect(x, y, c, t0, n_days):
8887 return t , x , y
8988
9089
91- @njit (cache = True )
92- def _create_meshed_particles (lons , lats , step ):
93- x_out , y_out , i_out = list (), list (), list ()
94- for i , (lon , lat ) in enumerate (zip (lons , lats )):
95- lon_min , lon_max = lon .min (), lon .max ()
96- lat_min , lat_max = lat .min (), lat .max ()
97- lon_min -= lon_min % step
98- lon_max -= lon_max % step - step * 2
99- lat_min -= lat_min % step
100- lat_max -= lat_max % step - step * 2
101-
102- for x in arange (lon_min , lon_max , step ):
103- for y in arange (lat_min , lat_max , step ):
104- if winding_number_poly (x , y , create_vertice (* reduce_size (lon , lat ))):
105- x_out .append (x ), y_out .append (y ), i_out .append (i )
106- return array (x_out ), array (y_out ), array (i_out )
107-
108-
109- def create_particles (eddies , step ):
110- """create particles only inside speed contour. Avoid creating too large numpy arrays, only to me masked
111-
112- :param eddies: network where eddies are
113- :type eddies: network
114- :param step: step for particles
115- :type step: float
116- :return: lon, lat and indices of particles in contour speed
117- :rtype: tuple(np.array)
118- """
119-
120- lon = eddies .contour_lon_s
121- lat = eddies .contour_lat_s
122-
123- return _create_meshed_particles (lon , lat , step )
124-
125-
12690def particle_candidate (c , eddies , step_mesh , t_start , i_target , pct , ** kwargs ):
12791 """Select particles within eddies, advect them, return target observation and associated percentages
12892
@@ -141,7 +105,7 @@ def particle_candidate(c, eddies, step_mesh, t_start, i_target, pct, **kwargs):
141105 # to be able to get global index
142106 translate_start = where (m_start )[0 ]
143107
144- x , y , i_start = create_particles (e , step_mesh )
108+ x , y , i_start = e . create_particles (step_mesh )
145109
146110 # Advection
147111 t_end , x , y = advect (x , y , c , t_start , ** kwargs )
0 commit comments