From 417e17a4b06b3feebe862bdfa3a8657ca6ccb2ce Mon Sep 17 00:00:00 2001
From: Arin Wongprommoon <arin.wongprommoon@ed.ac.uk>
Date: Tue, 6 Dec 2022 15:01:28 +0000
Subject: [PATCH] [WIP] fix(postproc): separate variables for traps, mothers,
 daughters

WHY IS THIS CHANGE NEEDED?:
- IndexError raised when processor is invoked

HOW DOES THE CHANGE SOLVE THE PROBLEM?:
- multii variable (line 208) assumes that daughters is a 2d numpy array
  with at least 2 columns.  this is wrong, both mothers & daughters are
  lists.
- bug uncovers poor handling of variables that store info on traps,
  mothers, and daughters, so refactored them too.  specifically, the
  mothers variables stored traps AND mothers information -- now i've
  separated them.
- this also means that numpy.append makes no sense and i use
  numpy.column_stack() instead.

WHAT SIDE EFFECTS DOES THIS CHANGE HAVE?:
- tech debt: potentially more refactoring along the line in this file --
  the logic is quite convoluted.

EVIDENCE THAT COMMIT WORKS:
- yet to see

REFERENCES:
- issue #37
---
 src/postprocessor/core/processor.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/postprocessor/core/processor.py b/src/postprocessor/core/processor.py
index 6efbddaf..2819cc2b 100644
--- a/src/postprocessor/core/processor.py
+++ b/src/postprocessor/core/processor.py
@@ -201,13 +201,15 @@ class PostProcessor(ProcessABC):
             self._signal[self.targets["prepost"]["picker"][0]]
         )
 
-        mothers, daughters = np.array(self.picker.mothers), np.array(
-            self.picker.daughters
-        )
+        # picker.mothers and picker.daughters already assigned based on
+        # picker.cells.mothers_daughters, but there is no picker.traps variable
+        traps = self.cells.mothers_daughters[:, 0].tolist()
+        mothers = np.array(self.picker.mothers)
+        daughters = np.array(self.picker.daughters)
 
         multii = pd.MultiIndex.from_arrays(
             (
-                np.append(mothers, daughters[:, 1].reshape(-1, 1), axis=1).T
+                np.column_stack((traps, mothers, daughters))
                 if daughters.any()
                 else [[], [], []]
             ),
@@ -257,7 +259,7 @@ class PostProcessor(ProcessABC):
 
             self.lineage_merged = pd.MultiIndex.from_arrays(
                 np.unique(
-                    np.append(mothers, daughters[:, 1].reshape(-1, 1), axis=1),
+                    np.column_stack((traps, mothers, daughters)),
                     axis=0,
                 ).T,
                 names=["trap", "mother_label", "daughter_label"],
-- 
GitLab