diff --git a/dataloader.py b/dataloader.py index b3c4525c69af1c8e4400832dc73814fba00d3f6d..2b789f70eef2a8a6bbcd1654bfbe23602f9fd109 100644 --- a/dataloader.py +++ b/dataloader.py @@ -509,6 +509,30 @@ class dataloader: """ return self.df.pivot(y, x, signal) + def sub_df(self, signal, duration_threshold): + """ + Find a sub dataframe of dataloader's main dataframe. + + Parameters + ---------- + duration_threshold: float + Specifies the fraction of the total duration of the time-lapse + experiment for which a cell must be present in a trap. + """ + if duration_threshold < 0 or duration_threshold > 1: + print( + f"The threshold must be a fraction, not {duration_threshold}." + ) + return + else: + wdf = self.wide_df(signal) + keep = ( + wdf.notna().sum(axis=1) > duration_threshold * wdf.columns.size + ).values + ids_to_keep = list(wdf.index[keep]) + sdf = self.df[self.df.id.isin(ids_to_keep)] + return sdf + def get_time_series(self, signal, group=None): """ Extract a signal as a 2D array with each row a time series.