@@ -626,27 +626,6 @@ def split_network(self, intern=True, **kwargs):
626
626
m = local_ids ["next_obs" ] == - 1
627
627
local_ids ["next_obs" ][m ] += i_s
628
628
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
- # )
650
629
651
630
def set_tracks (self , x , y , ids , window ):
652
631
"""
@@ -670,6 +649,8 @@ def set_tracks(self, x, y, ids, window):
670
649
continue
671
650
self .follow_obs (i , track_id , used , ids , polygons , * time_index , window )
672
651
track_id += 1
652
+ # Search a possible ancestor
653
+ self .previous_obs (i , ids , polygons , * time_index , window )
673
654
674
655
@classmethod
675
656
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):
694
675
ids ["previous_obs" ][i_next_ ] = i_next
695
676
i_next = i_next_
696
677
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
+
697
701
@staticmethod
698
702
def next_obs (i_current , ids , polygons , time_s , time_e , time_ref , window ):
699
703
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):
707
711
if i0 == i1 :
708
712
continue
709
713
# 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 )
711
715
# We remove low overlap
712
716
c [c < 0.1 ] = 0
713
717
# We get index of maximal overlap
0 commit comments