@@ -70,6 +70,15 @@ def __init__(self, *args, **kwargs):
70
70
self .__obs_by_track = None
71
71
self .__nb_track = None
72
72
73
+ def iter_track (self ):
74
+ """
75
+ Yield track
76
+ """
77
+ for i0 , nb in zip (self .index_from_track , self .nb_obs_by_track ):
78
+ if nb == 0 :
79
+ continue
80
+ yield self .index (slice (i0 , i0 + nb ))
81
+
73
82
@property
74
83
def nb_tracks (self ):
75
84
"""
@@ -491,6 +500,13 @@ def extract_with_mask(
491
500
new .track = id_translate [new .track ]
492
501
return new
493
502
503
+ @staticmethod
504
+ def re_reference_index (index , ref ):
505
+ if isinstance (ref , slice ):
506
+ return index + ref .start
507
+ else :
508
+ return ref [index ]
509
+
494
510
def shape_polygon (self , intern = False ):
495
511
"""
496
512
Get polygons which enclosed each track
@@ -528,6 +544,28 @@ def display_shape(self, ax, ref=None, intern=False, **kwargs):
528
544
x , y = wrap_longitude (x , y , ref , cut = True )
529
545
return ax .plot (x , y , ** kwargs )
530
546
547
+ def close_tracks (self , other , nb_obs_min = 10 , ** kwargs ):
548
+ """
549
+ Get close from another atlas.
550
+
551
+ :param self other: Atlas to compare
552
+ :param int nb_obs_min: Minimal number of overlap for one track
553
+ :param dict kwargs: keyword arguments for match function
554
+ :return: return other atlas reduce to common track with self
555
+
556
+ .. warning::
557
+ It could be a costly operation for huge dataset
558
+ """
559
+ p0 , p1 = self .period
560
+ indexs = list ()
561
+ for i_self , i_other , t0 , t1 in self .align_on (other , bins = range (p0 , p1 + 2 )):
562
+ i , j , s = self .index (i_self ).match (other .index (i_other ), ** kwargs )
563
+ indexs .append (other .re_reference_index (j , i_other ))
564
+ indexs = concatenate (indexs )
565
+ tr , nb = unique (other .track [indexs ], return_counts = True )
566
+ return other .extract_ids (tr [nb >= nb_obs_min ])
567
+
568
+
531
569
def format_label (self , label ):
532
570
t0 , t1 = self .period
533
571
return label .format (
0 commit comments