Skip to content

Commit d123d37

Browse files
committed
modification of network cost function
1 parent bc44b65 commit d123d37

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/py_eddy_tracker/observations/tracking.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -626,27 +626,6 @@ def split_network(self, intern=True, **kwargs):
626626
m = local_ids["next_obs"] == -1
627627
local_ids["next_obs"][m] += i_s
628628
return ids
629-
# ids_sort = ids[new_i]
630-
# # To be able to follow indices sorting
631-
# reverse_sort = empty(new_i.shape[0], dtype="u4")
632-
# reverse_sort[new_i] = arange(new_i.shape[0])
633-
# # Redirect indices
634-
# m = ids_sort["next_obs"] != -1
635-
# ids_sort["next_obs"][m] = reverse_sort[
636-
# ids_sort["next_obs"][m]
637-
# ]
638-
# m = ids_sort["previous_obs"] != -1
639-
# ids_sort["previous_obs"][m] = reverse_sort[
640-
# ids_sort["previous_obs"][m]
641-
# ]
642-
# # print(ids_sort)
643-
# display_network(
644-
# x[new_i],
645-
# y[new_i],
646-
# ids_sort["track"],
647-
# ids_sort["time"],
648-
# ids_sort["next_cost"],
649-
# )
650629

651630
def set_tracks(self, x, y, ids, window):
652631
"""
@@ -670,6 +649,8 @@ def set_tracks(self, x, y, ids, window):
670649
continue
671650
self.follow_obs(i, track_id, used, ids, polygons, *time_index, window)
672651
track_id += 1
652+
# Search a possible ancestor
653+
self.previous_obs(i, ids, polygons, *time_index, window)
673654

674655
@classmethod
675656
def follow_obs(cls, i_next, track_id, used, ids, *args):
@@ -694,6 +675,29 @@ def follow_obs(cls, i_next, track_id, used, ids, *args):
694675
ids["previous_obs"][i_next_] = i_next
695676
i_next = i_next_
696677

678+
@staticmethod
679+
def previous_obs(i_current, ids, polygons, time_s, time_e, time_ref, window):
680+
time_cur = ids["time"][i_current]
681+
t0, t1 = time_cur - 1 - time_ref, max(time_cur - window - time_ref, 0)
682+
for t_step in range(t0, t1 - 1, -1):
683+
i0, i1 = time_s[t_step], time_e[t_step]
684+
# No observation at the time step
685+
if i0 == i1:
686+
continue
687+
# Intersection / union, to be able to separte in case of multiple inside
688+
c = polygon_overlap(polygons[i_current], polygons[i0:i1], minimal_area=True)
689+
# We remove low overlap
690+
c[c < 0.1] = 0
691+
# We get index of maximal overlap
692+
i = c.argmax()
693+
c_i = c[i]
694+
# No overlap found
695+
if c_i == 0:
696+
continue
697+
ids["previous_cost"][i_current] = c_i
698+
ids["previous_obs"][i_current] = i0 + i
699+
break
700+
697701
@staticmethod
698702
def next_obs(i_current, ids, polygons, time_s, time_e, time_ref, window):
699703
time_max = time_e.shape[0] - 1
@@ -707,7 +711,7 @@ def next_obs(i_current, ids, polygons, time_s, time_e, time_ref, window):
707711
if i0 == i1:
708712
continue
709713
# Intersection / union, to be able to separte in case of multiple inside
710-
c = polygon_overlap(polygons[i_current], polygons[i0:i1])
714+
c = polygon_overlap(polygons[i_current], polygons[i0:i1], minimal_area=True)
711715
# We remove low overlap
712716
c[c < 0.1] = 0
713717
# We get index of maximal overlap

0 commit comments

Comments
 (0)