@@ -1301,7 +1301,7 @@ def extract_with_period(self, period):
1301
1301
1302
1302
return self .extract_with_mask (self .get_mask_with_period (period ))
1303
1303
1304
- def extract_light_with_mask (self , mask ):
1304
+ def extract_light_with_mask (self , mask , track_extra_variables = [] ):
1305
1305
"""extract data with mask, but only with variables used for coherence, aka self.array_variables
1306
1306
1307
1307
:param mask: mask used to extract
@@ -1319,7 +1319,7 @@ def extract_light_with_mask(self, mask):
1319
1319
variables = ["time" ] + self .array_variables
1320
1320
new = self .__class__ (
1321
1321
size = nb_obs ,
1322
- track_extra_variables = [] ,
1322
+ track_extra_variables = track_extra_variables ,
1323
1323
track_array_variables = self .track_array_variables ,
1324
1324
array_variables = self .array_variables ,
1325
1325
only_variables = variables ,
@@ -1333,9 +1333,22 @@ def extract_light_with_mask(self, mask):
1333
1333
f"{ nb_obs } observations will be extracted ({ nb_obs / self .shape [0 ]:.3%} )"
1334
1334
)
1335
1335
1336
- for field in variables :
1336
+ for field in variables + track_extra_variables :
1337
1337
logger .debug ("Copy of field %s ..." , field )
1338
1338
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
+
1339
1352
return new
1340
1353
1341
1354
def extract_with_mask (self , mask ):
@@ -1495,7 +1508,8 @@ def date2file(julian_day):
1495
1508
1496
1509
t_start , t_end = int (self .period [0 ]), int (self .period [1 ])
1497
1510
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 ))
1499
1513
first_files = [date_function (x ) for x in dates ]
1500
1514
1501
1515
c = GridCollection .from_netcdf_list (first_files , dates , ** uv_params )
@@ -1570,12 +1584,8 @@ def date2file(julian_day):
1570
1584
ptf_final = zeros ((self .obs .size , 2 ), dtype = "i1" )
1571
1585
1572
1586
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
1577
1587
1578
- dates = arange (t_start , t_start + n_days + 1 )
1588
+ dates = arange (t_start , min ( t_start + n_days + 1 , t_end + 1 ) )
1579
1589
first_files = [date_function (x ) for x in dates ]
1580
1590
1581
1591
c = GridCollection .from_netcdf_list (first_files , dates , ** uv_params )
@@ -1699,7 +1709,23 @@ def group_translator(nb, duos):
1699
1709
apply_replace (translate , gr_i , gr_j )
1700
1710
return translate
1701
1711
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
+
1703
1729
results , nb_obs = list (), list ()
1704
1730
# To display print only in INFO
1705
1731
display_iteration = logger .getEffectiveLevel () == logging .INFO
@@ -1713,7 +1739,12 @@ def group_observations(self, **kwargs):
1713
1739
for j in range (i + 1 , min (self .window + i + 1 , self .nb_input )):
1714
1740
xj , yj = self .buffer .load_contour (self .filenames [j ])
1715
1741
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
+ )
1717
1748
results .append ((i , j , ii [m ], ij [m ]))
1718
1749
if display_iteration :
1719
1750
print ()
0 commit comments