48
48
@njit (cache = True )
49
49
def reverse_index (index , nb ):
50
50
"""
51
+ Compute a list of index, which are not in index.
52
+
51
53
:param array index: index of group which will be set to False
52
54
:param array nb: Count for each group
53
55
:return: mask of value selected
@@ -61,7 +63,7 @@ def reverse_index(index, nb):
61
63
62
64
@njit (cache = True )
63
65
def 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.
65
67
66
68
:param array groups: array which contain group to be separated
67
69
:return: (first_index of each group, last_index of each group, value to shift group)
@@ -85,12 +87,15 @@ def build_index(groups):
85
87
86
88
@njit (cache = True )
87
89
def hist_numba (x , bins ):
90
+ """Call numba histogram to speed up."""
88
91
return histogram (x , bins )
89
92
90
93
91
94
@njit (cache = True , fastmath = True , parallel = False )
92
95
def distance_grid (lon0 , lat0 , lon1 , lat1 ):
93
96
"""
97
+ Get distance for every couple of point.
98
+
94
99
:param array lon0:
95
100
:param array lat0:
96
101
:param array lon1:
@@ -127,7 +132,7 @@ def distance_grid(lon0, lat0, lon1, lat1):
127
132
@njit (cache = True , fastmath = True )
128
133
def distance (lon0 , lat0 , lon1 , lat1 ):
129
134
"""
130
- Compute distance between points from each line
135
+ Compute distance between points from each line.
131
136
132
137
:param float lon0:
133
138
:param float lat0:
@@ -148,7 +153,7 @@ def distance(lon0, lat0, lon1, lat1):
148
153
@njit (cache = True )
149
154
def cumsum_by_track (field , track ):
150
155
"""
151
- Cumsum by track
156
+ Cumsum by track.
152
157
153
158
:param array field: data to sum
154
159
:pram array(int) track: id of track to separate data
@@ -172,7 +177,7 @@ def cumsum_by_track(field, track):
172
177
@njit (cache = True , fastmath = True )
173
178
def interp2d_geo (x_g , y_g , z_g , m_g , x , y ):
174
179
"""
175
- For geographic grid, test of cicularity
180
+ For geographic grid, test of cicularity.
176
181
177
182
:param array x_g: coordinates of grid
178
183
:param array y_g: coordinates of grid
@@ -189,6 +194,7 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
189
194
x_step = x_g [1 ] - x_ref
190
195
y_step = y_g [1 ] - y_ref
191
196
nb_x = x_g .shape [0 ]
197
+ nb_y = y_g .shape [0 ]
192
198
is_circular = (x_g [- 1 ] + x_step ) % 360 == x_g [0 ] % 360
193
199
z = empty (x .shape , dtype = z_g .dtype )
194
200
for i in prange (x .size ):
@@ -197,11 +203,16 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
197
203
i0 = int (floor (x_ ))
198
204
i1 = i0 + 1
199
205
xd = x_ - i0
206
+ j0 = int (floor (y_ ))
207
+ j1 = j0 + 1
200
208
if is_circular :
201
209
i0 %= nb_x
202
210
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
+
205
216
yd = y_ - j0
206
217
z00 = z_g [i0 , j0 ]
207
218
z01 = z_g [i0 , j1 ]
@@ -219,7 +230,7 @@ def interp2d_geo(x_g, y_g, z_g, m_g, x, y):
219
230
@njit (cache = True , fastmath = True )
220
231
def uniform_resample (x_val , y_val , num_fac = 2 , fixed_size = None ):
221
232
"""
222
- Resample contours to have (nearly) equal spacing
233
+ Resample contours to have (nearly) equal spacing.
223
234
224
235
:param array_like x_val: input x contour coordinates
225
236
: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):
246
257
@njit (cache = True )
247
258
def flatten_line_matrix (l_matrix ):
248
259
"""
249
- Flat matrix and add on between each line
260
+ Flat matrix and add on between each line.
250
261
251
262
:param l_matrix: matrix of position
252
263
:return: array with nan between line
@@ -267,7 +278,7 @@ def flatten_line_matrix(l_matrix):
267
278
@njit (cache = True )
268
279
def simplify (x , y , precision = 0.1 ):
269
280
"""
270
- Will remove all middle point which are closer than precision
281
+ Will remove all middle point which are closer than precision.
271
282
272
283
:param array x:
273
284
:param array y:
@@ -307,7 +318,7 @@ def simplify(x, y, precision=0.1):
307
318
@njit (cache = True )
308
319
def split_line (x , y , i ):
309
320
"""
310
- Split x and y at each i change
321
+ Split x and y at each i change.
311
322
312
323
:param x: array
313
324
:param y: array
@@ -335,7 +346,7 @@ def split_line(x, y, i):
335
346
@njit (cache = True )
336
347
def wrap_longitude (x , y , ref , cut = False ):
337
348
"""
338
- Will wrap contiguous longitude with reference like west bound
349
+ Will wrap contiguous longitude with reference like west bound.
339
350
340
351
:param array x:
341
352
:param array y:
@@ -391,7 +402,7 @@ def wrap_longitude(x, y, ref, cut=False):
391
402
@njit (cache = True , fastmath = True )
392
403
def coordinates_to_local (lon , lat , lon0 , lat0 ):
393
404
"""
394
- Take latlong coordinates to transform in local coordinates (in m)
405
+ Take latlong coordinates to transform in local coordinates (in m).
395
406
396
407
:param array x: coordinates to transform
397
408
:param array y: coordinates to transform
@@ -420,7 +431,7 @@ def coordinates_to_local(lon, lat, lon0, lat0):
420
431
@njit (cache = True , fastmath = True )
421
432
def local_to_coordinates (x , y , lon0 , lat0 ):
422
433
"""
423
- Take local coordinates (in m) to transform to latlong
434
+ Take local coordinates (in m) to transform to latlong.
424
435
425
436
:param array x: coordinates to transform
426
437
:param array y: coordinates to transform
@@ -447,7 +458,7 @@ def local_to_coordinates(x, y, lon0, lat0):
447
458
@njit (cache = True , fastmath = True )
448
459
def nearest_grd_indice (x , y , x0 , y0 , xstep , ystep ):
449
460
"""
450
- Get nearest grid indice from a position
461
+ Get nearest grid indice from a position.
451
462
452
463
:param x: longitude
453
464
:param y: latitude
@@ -465,7 +476,7 @@ def nearest_grd_indice(x, y, x0, y0, xstep, ystep):
465
476
@njit (cache = True )
466
477
def bbox_indice_regular (vertices , x0 , y0 , xstep , ystep , N , circular , x_size ):
467
478
"""
468
- Get bbox indice of a contour in a regular grid
479
+ Get bbox indice of a contour in a regular grid.
469
480
470
481
:param vertices: vertice of contour
471
482
:param float x0: first grid longitude
@@ -492,7 +503,7 @@ def bbox_indice_regular(vertices, x0, y0, xstep, ystep, N, circular, x_size):
492
503
@njit (cache = True , fastmath = True )
493
504
def get_pixel_in_regular (vertices , x_c , y_c , x_start , x_stop , y_start , y_stop ):
494
505
"""
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.
496
507
497
508
:param array_like vertices: contour vertice (N,2)
498
509
: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):
532
543
533
544
def build_circle (x0 , y0 , r ):
534
545
"""
535
- Method to built circle from center coordinates
546
+ Build circle from center coordinates.
536
547
537
548
:param float x0: center coordinate
538
549
:param float y0: center coordinate
0 commit comments