From 245066ebb4edf3d32d2cff61e54441033ec03328 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk>
Date: Wed, 28 Sep 2022 00:47:04 +0100
Subject: [PATCH] feat(signal): add lineage method

---
 src/agora/io/signal.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/agora/io/signal.py b/src/agora/io/signal.py
index f5976a4f..3a3a5512 100644
--- a/src/agora/io/signal.py
+++ b/src/agora/io/signal.py
@@ -91,6 +91,31 @@ class Signal(BridgeH5):
         elif isinstance(df, list):
             return [self.get_retained(d, cutoff=cutoff) for d in df]
 
+    def lineage(
+        self, lineage_location: t.Optional[str] = None, merged: bool = False
+    ) -> np.ndarray:
+        """
+        Return lineage data from a given location as a matrix where
+        the first column is the trap id,
+        the second column is the mother label and
+        the third column is the daughter label.
+        """
+        if lineage_location is None:
+            lineage_location = "postprocessing/lineage"
+            if merged:
+                lineage_location += "_merged"
+
+        with h5py.File(self.filename, "r") as f:
+            trap_mo_da = f[lineage_location]
+            lineage = np.array(
+                (
+                    trap_mo_da["trap"],
+                    trap_mo_da["mother_label"],
+                    trap_mo_da["daughter_label"],
+                )
+            ).T
+        return lineage
+
     def apply_prepost(self, dataset: str, skip_pick: t.Optional[bool] = None):
         """
         Apply modifier operations (picker, merger) to a given dataframe.
-- 
GitLab