Skip to content

Commit e43bf51

Browse files
committed
Improve simplify function to remove succesive nan
1 parent b789b6a commit e43bf51

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/py_eddy_tracker/generic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,16 @@ def simplify(x, y, precision=0.1):
315315
if j == (nb - 1):
316316
return zeros(0, dtype=x.dtype), zeros(0, dtype=x.dtype)
317317

318+
last_nan = False
318319
for i in range(j + 1, nb):
319320
x_, y_ = x[i], y[i]
320321
if isnan(x_) or isnan(y_):
322+
if last_nan:
323+
mask[i] = False
324+
else:
325+
last_nan = True
321326
continue
327+
last_nan = False
322328
d_x = x_ - x_previous
323329
if d_x > precision:
324330
x_previous, y_previous = x_, y_

tests/test_generic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def test_simplify():
1515
x[4] = nan
1616
x_, y_ = simplify(x, y, precision=1)
1717
assert x_.shape[0] == 6
18+
x[3] = nan
19+
x_, y_ = simplify(x, y, precision=1)
20+
assert x_.shape[0] == 6
1821
x[:4] = nan
1922
x_, y_ = simplify(x, y, precision=1)
2023
assert x_.shape[0] == 3

0 commit comments

Comments
 (0)