4848@njit (cache = True )
4949def reverse_index (index , nb ):
5050 """
51+ Compute a list of index, which are not in index.
52+
5153 :param array index: index of group which will be set to False
5254 :param array nb: Count for each group
5355 :return: mask of value selected
@@ -61,7 +63,7 @@ def reverse_index(index, nb):
6163
6264@njit (cache = True )
6365def build_index (groups ):
64- """We expected that variable is monotonous, and return index for each step change
66+ """We expected that variable is monotonous, and return index for each step change.
6567
6668 :param array groups: array which contain group to be separated
6769 :return: (first_index of each group, last_index of each group, value to shift group)
@@ -85,12 +87,15 @@ def build_index(groups):
8587
8688@njit (cache = True )
8789def hist_numba (x , bins ):
90+ """Call numba histogram to speed up."""
8891 return histogram (x , bins )
8992
9093
9194@njit (cache = True , fastmath = True , parallel = False )
9295def distance_grid (lon0 , lat0 , lon1 , lat1 ):
9396 """
97+ Get distance for every couple of point.
98+
9499 :param array lon0:
95100 :param array lat0:
96101 :param array lon1:
@@ -127,7 +132,7 @@ def distance_grid(lon0, lat0, lon1, lat1):
127132@njit (cache = True , fastmath = True )
128133def distance (lon0 , lat0 , lon1 , lat1 ):
129134 """
130- Compute distance between points from each line
135+ Compute distance between points from each line.
131136
132137 :param float lon0:
133138 :param float lat0:
@@ -148,7 +153,7 @@ def distance(lon0, lat0, lon1, lat1):
148153@njit (cache = True )
149154def cumsum_by_track (field , track ):
150155 """
151- Cumsum by track
156+ Cumsum by track.
152157
153158 :param array field: data to sum
154159 :pram array(int) track: id of track to separate data
@@ -172,7 +177,7 @@ def cumsum_by_track(field, track):
172177@njit (cache = True , fastmath = True )
173178def interp2d_geo (x_g , y_g , z_g , m_g , x , y ):
174179 """
175- For geographic grid, test of cicularity
180+ For geographic grid, test of cicularity.
176181
177182 :param array x_g: coordinates of grid
178183 :param array y_g: coordinates of grid
@@ -189,6 +194,7 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
189194 x_step = x_g [1 ] - x_ref
190195 y_step = y_g [1 ] - y_ref
191196 nb_x = x_g .shape [0 ]
197+ nb_y = y_g .shape [0 ]
192198 is_circular = (x_g [- 1 ] + x_step ) % 360 == x_g [0 ] % 360
193199 z = empty (x .shape , dtype = z_g .dtype )
194200 for i in prange (x .size ):
@@ -197,11 +203,16 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
197203 i0 = int (floor (x_ ))
198204 i1 = i0 + 1
199205 xd = x_ - i0
206+ j0 = int (floor (y_ ))
207+ j1 = j0 + 1
200208 if is_circular :
201209 i0 %= nb_x
202210 i1 %= nb_x
203- j0 = int (floor (y_ ))
204- j1 = j0 + 1
211+ else :
212+ if i1 >= nb_x or i0 < 0 or j0 < 0 or j1 >= nb_y :
213+ z [i ] = nan
214+ continue
215+
205216 yd = y_ - j0
206217 z00 = z_g [i0 , j0 ]
207218 z01 = z_g [i0 , j1 ]
@@ -219,7 +230,7 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
219230@njit (cache = True , fastmath = True )
220231def uniform_resample (x_val , y_val , num_fac = 2 , fixed_size = None ):
221232 """
222- Resample contours to have (nearly) equal spacing
233+ Resample contours to have (nearly) equal spacing.
223234
224235 :param array_like x_val: input x contour coordinates
225236 :param array_like y_val: input y contour coordinates
@@ -246,7 +257,7 @@ def uniform_resample(x_val, y_val, num_fac=2, fixed_size=None):
246257@njit (cache = True )
247258def flatten_line_matrix (l_matrix ):
248259 """
249- Flat matrix and add on between each line
260+ Flat matrix and add on between each line.
250261
251262 :param l_matrix: matrix of position
252263 :return: array with nan between line
@@ -267,7 +278,7 @@ def flatten_line_matrix(l_matrix):
267278@njit (cache = True )
268279def simplify (x , y , precision = 0.1 ):
269280 """
270- Will remove all middle point which are closer than precision
281+ Will remove all middle point which are closer than precision.
271282
272283 :param array x:
273284 :param array y:
@@ -307,7 +318,7 @@ def simplify(x, y, precision=0.1):
307318@njit (cache = True )
308319def split_line (x , y , i ):
309320 """
310- Split x and y at each i change
321+ Split x and y at each i change.
311322
312323 :param x: array
313324 :param y: array
@@ -335,7 +346,7 @@ def split_line(x, y, i):
335346@njit (cache = True )
336347def wrap_longitude (x , y , ref , cut = False ):
337348 """
338- Will wrap contiguous longitude with reference like west bound
349+ Will wrap contiguous longitude with reference like west bound.
339350
340351 :param array x:
341352 :param array y:
@@ -391,7 +402,7 @@ def wrap_longitude(x, y, ref, cut=False):
391402@njit (cache = True , fastmath = True )
392403def coordinates_to_local (lon , lat , lon0 , lat0 ):
393404 """
394- Take latlong coordinates to transform in local coordinates (in m)
405+ Take latlong coordinates to transform in local coordinates (in m).
395406
396407 :param array x: coordinates to transform
397408 :param array y: coordinates to transform
@@ -420,7 +431,7 @@ def coordinates_to_local(lon, lat, lon0, lat0):
420431@njit (cache = True , fastmath = True )
421432def local_to_coordinates (x , y , lon0 , lat0 ):
422433 """
423- Take local coordinates (in m) to transform to latlong
434+ Take local coordinates (in m) to transform to latlong.
424435
425436 :param array x: coordinates to transform
426437 :param array y: coordinates to transform
@@ -447,7 +458,7 @@ def local_to_coordinates(x, y, lon0, lat0):
447458@njit (cache = True , fastmath = True )
448459def nearest_grd_indice (x , y , x0 , y0 , xstep , ystep ):
449460 """
450- Get nearest grid indice from a position
461+ Get nearest grid indice from a position.
451462
452463 :param x: longitude
453464 :param y: latitude
@@ -465,7 +476,7 @@ def nearest_grd_indice(x, y, x0, y0, xstep, ystep):
465476@njit (cache = True )
466477def bbox_indice_regular (vertices , x0 , y0 , xstep , ystep , N , circular , x_size ):
467478 """
468- Get bbox indice of a contour in a regular grid
479+ Get bbox indice of a contour in a regular grid.
469480
470481 :param vertices: vertice of contour
471482 :param float x0: first grid longitude
@@ -492,7 +503,7 @@ def bbox_indice_regular(vertices, x0, y0, xstep, ystep, N, circular, x_size):
492503@njit (cache = True , fastmath = True )
493504def get_pixel_in_regular (vertices , x_c , y_c , x_start , x_stop , y_start , y_stop ):
494505 """
495- Get a pixel list of a regular grid contain in a contour
506+ Get a pixel list of a regular grid contain in a contour.
496507
497508 :param array_like vertices: contour vertice (N,2)
498509 :param array_like x_c: longitude coordinate of grid
@@ -532,7 +543,7 @@ def get_pixel_in_regular(vertices, x_c, y_c, x_start, x_stop, y_start, y_stop):
532543
533544def build_circle (x0 , y0 , r ):
534545 """
535- Method to built circle from center coordinates
546+ Build circle from center coordinates.
536547
537548 :param float x0: center coordinate
538549 :param float y0: center coordinate
0 commit comments