@@ -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,19 @@ 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 "previous_obs" in track_extra_variables and "next_obs" in track_extra_variables :
1341+ # n & p must be re-index
1342+ n , p = self .next_obs [mask ], self .previous_obs [mask ]
1343+ # we add 2 for -1 index return index -1
1344+ translate = - ones (len (self ) + 1 , dtype = "i4" )
1345+ translate [:- 1 ][mask ] = arange (nb_obs )
1346+ new .next_obs [:] = translate [n ]
1347+ new .previous_obs [:] = translate [p ]
1348+
13391349 return new
13401350
13411351 def extract_with_mask (self , mask ):
0 commit comments