@@ -1301,7 +1301,7 @@ def extract_with_period(self, period):
13011301
13021302 return self .extract_with_mask (self .get_mask_with_period (period ))
13031303
1304- def extract_light_with_mask (self , mask ):
1304+ def extract_light_with_mask (self , mask , track_extra_variables = [] ):
13051305 """extract data with mask, but only with variables used for coherence, aka self.array_variables
13061306
13071307 :param mask: mask used to extract
@@ -1319,7 +1319,7 @@ def extract_light_with_mask(self, mask):
13191319 variables = ["time" ] + self .array_variables
13201320 new = self .__class__ (
13211321 size = nb_obs ,
1322- track_extra_variables = [] ,
1322+ track_extra_variables = track_extra_variables ,
13231323 track_array_variables = self .track_array_variables ,
13241324 array_variables = self .array_variables ,
13251325 only_variables = variables ,
@@ -1333,9 +1333,22 @@ def extract_light_with_mask(self, mask):
13331333 f"{ nb_obs } observations will be extracted ({ nb_obs / self .shape [0 ]:.3%} )"
13341334 )
13351335
1336- for field in variables :
1336+ for field in variables + track_extra_variables :
13371337 logger .debug ("Copy of field %s ..." , field )
13381338 new .obs [field ] = self .obs [field ][mask ]
1339+
1340+ if (
1341+ "previous_obs" in track_extra_variables
1342+ and "next_obs" in track_extra_variables
1343+ ):
1344+ # n & p must be re-index
1345+ n , p = self .next_obs [mask ], self .previous_obs [mask ]
1346+ # we add 2 for -1 index return index -1
1347+ translate = - ones (len (self ) + 1 , dtype = "i4" )
1348+ translate [:- 1 ][mask ] = arange (nb_obs )
1349+ new .next_obs [:] = translate [n ]
1350+ new .previous_obs [:] = translate [p ]
1351+
13391352 return new
13401353
13411354 def extract_with_mask (self , mask ):
@@ -1495,7 +1508,8 @@ def date2file(julian_day):
14951508
14961509 t_start , t_end = int (self .period [0 ]), int (self .period [1 ])
14971510
1498- dates = arange (t_start , t_start + n_days + 1 )
1511+ # dates = arange(t_start, t_start + n_days + 1)
1512+ dates = arange (t_start , min (t_start + n_days + 1 , t_end + 1 ))
14991513 first_files = [date_function (x ) for x in dates ]
15001514
15011515 c = GridCollection .from_netcdf_list (first_files , dates , ** uv_params )
@@ -1570,12 +1584,8 @@ def date2file(julian_day):
15701584 ptf_final = zeros ((self .obs .size , 2 ), dtype = "i1" )
15711585
15721586 t_start , t_end = int (self .period [0 ]), int (self .period [1 ])
1573- # if begin is not None and begin > t_start:
1574- # t_start = begin
1575- # if end is not None and end < t_end:
1576- # t_end = end
15771587
1578- dates = arange (t_start , t_start + n_days + 1 )
1588+ dates = arange (t_start , min ( t_start + n_days + 1 , t_end + 1 ) )
15791589 first_files = [date_function (x ) for x in dates ]
15801590
15811591 c = GridCollection .from_netcdf_list (first_files , dates , ** uv_params )
@@ -1699,7 +1709,23 @@ def group_translator(nb, duos):
16991709 apply_replace (translate , gr_i , gr_j )
17001710 return translate
17011711
1702- def group_observations (self , ** kwargs ):
1712+ def group_observations (self , min_overlap = 0.2 , minimal_area = False ):
1713+ """Store every interaction between identifications
1714+
1715+ Parameters
1716+ ----------
1717+ minimal_area : bool, optional
1718+ If True, function will compute intersection/little polygon, else intersection/union, by default False
1719+
1720+ min_overlap : float, optional
1721+ minimum overlap area to associate observations, by default 0.2
1722+
1723+ Returns
1724+ -------
1725+ TrackEddiesObservations
1726+ netcdf with interactions
1727+ """
1728+
17031729 results , nb_obs = list (), list ()
17041730 # To display print only in INFO
17051731 display_iteration = logger .getEffectiveLevel () == logging .INFO
@@ -1713,7 +1739,12 @@ def group_observations(self, **kwargs):
17131739 for j in range (i + 1 , min (self .window + i + 1 , self .nb_input )):
17141740 xj , yj = self .buffer .load_contour (self .filenames [j ])
17151741 ii , ij = bbox_intersection (xi , yi , xj , yj )
1716- m = vertice_overlap (xi [ii ], yi [ii ], xj [ij ], yj [ij ], ** kwargs ) > 0.2
1742+ m = (
1743+ vertice_overlap (
1744+ xi [ii ], yi [ii ], xj [ij ], yj [ij ], minimal_area = minimal_area
1745+ )
1746+ > min_overlap
1747+ )
17171748 results .append ((i , j , ii [m ], ij [m ]))
17181749 if display_iteration :
17191750 print ()
0 commit comments