From d43d57101761cba2d692916316d70cdf5ed1537d Mon Sep 17 00:00:00 2001 From: Peter Swain <peter.swain@ed.ac.uk> Date: Fri, 27 Oct 2023 15:13:42 +0100 Subject: [PATCH] renamed dunder routines in indexing --- src/agora/utils/indexing.py | 24 ++++++++++++------------ src/postprocessor/core/postprocessing.py | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/agora/utils/indexing.py b/src/agora/utils/indexing.py index 23f3a533..371a69e6 100644 --- a/src/agora/utils/indexing.py +++ b/src/agora/utils/indexing.py @@ -73,7 +73,7 @@ def validate_lineage( """ if lineage.ndim == 2: # [trap, mother, daughter] becomes [[trap, mother], [trap, daughter]] - lineage = _assoc_indices_to_3d(lineage) + lineage = assoc_indices_to_3d(lineage) if how == "mothers": c_index = 0 elif how == "daughters": @@ -123,7 +123,7 @@ def index_isin(x: np.ndarray, y: np.ndarray) -> np.ndarray: return x_bool -def _assoc_indices_to_3d(ndarray: np.ndarray): +def assoc_indices_to_3d(ndarray: np.ndarray): """ Convert the last column to a new row and repeat first column's values. @@ -153,6 +153,16 @@ def _assoc_indices_to_3d(ndarray: np.ndarray): return result +def assoc_indices_to_2d(array: np.ndarray): + """Convert indices to 2d.""" + result = array + if len(array): + result = np.concatenate( + (array[:, 0, :], array[:, 1, 1, np.newaxis]), axis=1 + ) + return result + + ################################################################### @@ -250,16 +260,6 @@ def validate_association( return valid_association, valid_indices -def _3d_index_to_2d(array: np.ndarray): - """Revert _assoc_indices_to_3d.""" - result = array - if len(array): - result = np.concatenate( - (array[:, 0, :], array[:, 1, 1, np.newaxis]), axis=1 - ) - return result - - def compare_indices(x: np.ndarray, y: np.ndarray) -> np.ndarray: """ Fetch two 2-D indices and return a binary 2-D matrix diff --git a/src/postprocessor/core/postprocessing.py b/src/postprocessor/core/postprocessing.py index 33a6ebe1..2b13b68c 100644 --- a/src/postprocessor/core/postprocessing.py +++ b/src/postprocessor/core/postprocessing.py @@ -10,8 +10,8 @@ from agora.io.cells import Cells from agora.io.signal import Signal from agora.io.writer import Writer from agora.utils.indexing import ( - _3d_index_to_2d, - _assoc_indices_to_3d, + assoc_indices_to_2d, + assoc_indices_to_3d, ) from agora.utils.merge import merge_lineage from postprocessor.core.abc import get_parameters, get_process @@ -133,19 +133,19 @@ class PostProcessor(ProcessABC): record = self.signal.get_raw(self.targets["merging_picking"]["merger"]) merges = self.merger.run(record) # get lineages from cells object attached to picker - lineage = _assoc_indices_to_3d(self.picker.cells.mothers_daughters) + lineage = assoc_indices_to_3d(self.picker.cells.mothers_daughters) if merges.any(): # update lineages and merges after merging new_lineage, new_merges = merge_lineage(lineage, merges) else: new_lineage = lineage new_merges = merges - self.lineage = _3d_index_to_2d(new_lineage) + self.lineage = assoc_indices_to_2d(new_lineage) self.writer.write( "modifiers/merges", data=[np.array(x) for x in new_merges] ) self.writer.write( - "modifiers/lineage_merged", _3d_index_to_2d(new_lineage) + "modifiers/lineage_merged", assoc_indices_to_2d(new_lineage) ) # run picker picked_indices = self.picker.run( -- GitLab