3
3
4
4
from numba import njit
5
5
from numba import types as nb_types
6
- from numpy import arange , int32 , interp , median , where , zeros , meshgrid , concatenate
6
+ from numpy import arange , array , int32 , interp , median , where , zeros
7
7
8
+ from ..poly import create_vertice , reduce_size , winding_number_poly
8
9
from .observation import EddiesObservations
9
- from ..poly import group_obs
10
10
11
11
logger = logging .getLogger ("pet" )
12
12
@@ -88,6 +88,24 @@ def advect(x, y, c, t0, n_days):
88
88
return t , x , y
89
89
90
90
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
+
91
109
def create_particles (eddies , step ):
92
110
"""create particles only inside speed contour. Avoid creating too large numpy arrays, only to me masked
93
111
@@ -102,36 +120,7 @@ def create_particles(eddies, step):
102
120
lon = eddies .contour_lon_s
103
121
lat = eddies .contour_lat_s
104
122
105
- # compute bounding boxes of each eddies
106
- lonMins = lon .min (axis = 1 )
107
- lonMins = lonMins - (lonMins % step )
108
- lonMaxs = lon .max (axis = 1 )
109
- lonMaxs = lonMaxs - (lonMaxs % step ) + step * 2
110
-
111
- latMins = lat .min (axis = 1 )
112
- latMins = latMins - (latMins % step )
113
- latMaxs = lat .max (axis = 1 )
114
- latMaxs = latMaxs - (latMaxs % step ) + step * 2
115
-
116
- lon = []
117
- lat = []
118
- # for each eddies, create mesh with particles then concatenate
119
- for lonMin , lonMax , latMin , latMax in zip (lonMins , lonMaxs , latMins , latMaxs ):
120
- x0 , y0 = meshgrid (arange (lonMin , lonMax , step ), arange (latMin , latMax , step ))
121
-
122
- x0 , y0 = x0 .reshape (- 1 ), y0 .reshape (- 1 )
123
- lon .append (x0 )
124
- lat .append (y0 )
125
-
126
- x = concatenate (lon )
127
- y = concatenate (lat )
128
-
129
- _ , i = group_obs (x , y , 1 , 360 )
130
- x , y = x [i ], y [i ]
131
-
132
- i_start = eddies .contains (x , y , intern = True )
133
- m = i_start != - 1
134
- return x [m ], y [m ], i_start [m ]
123
+ return _create_meshed_particles (lon , lat , step )
135
124
136
125
137
126
def particle_candidate (c , eddies , step_mesh , t_start , i_target , pct , ** kwargs ):
0 commit comments