Skip to content

Commit e4cc109

Browse files
committed
Simplify median filter
1 parent 68cfe98 commit e4cc109

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/py_eddy_tracker/observations/tracking.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -374,23 +374,13 @@ def track_median_filter(half_window, x, y, track):
374374
375375
"""
376376
nb = y.shape[0]
377-
last = nb - 1
378377
y_new = empty(y.shape, dtype=y.dtype)
378+
i_previous, i_next = 0, 0
379379
for i in range(nb):
380380
cur_track = track[i]
381-
i_previous = i
382-
i_next = i
383-
dx = 0
384-
while dx <= half_window and i_previous != 0 and cur_track == track[i_previous]:
385-
i_previous -= 1
386-
dx = x[i] - x[i_previous]
387-
if dx > half_window or cur_track != track[i_previous]:
381+
while x[i] - x[i_previous] > half_window or cur_track != track[i_previous]:
388382
i_previous += 1
389-
dx = 0
390-
while dx <= half_window and i_next != last and cur_track == track[i_next]:
383+
while i_next < nb and x[i_next] - x[i] <= half_window and cur_track == track[i_next]:
391384
i_next += 1
392-
dx = x[i_next] - x[i]
393-
if dx > half_window or cur_track != track[i_next]:
394-
i_next -= 1
395-
y_new[i] = median(y[i_previous:i_next + 1])
385+
y_new[i] = median(y[i_previous:i_next])
396386
return y_new

0 commit comments

Comments
 (0)