Skip to content
Snippets Groups Projects
Commit 403b483d authored by Alán Muñoz's avatar Alán Muñoz
Browse files

refactor(cells): make lineage consistent

parent e73797ca
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ import typing as t ...@@ -3,7 +3,7 @@ import typing as t
from collections.abc import Iterable from collections.abc import Iterable
from itertools import groupby from itertools import groupby
from pathlib import Path, PosixPath from pathlib import Path, PosixPath
from functools import lru_cache from functools import lru_cache, cached_property
import h5py import h5py
import numpy as np import numpy as np
...@@ -264,10 +264,11 @@ class Cells: ...@@ -264,10 +264,11 @@ class Cells:
rand = np.random.randint(mat.sum()) rand = np.random.randint(mat.sum())
return (traps[rand], tps[rand]) return (traps[rand], tps[rand])
@lru_cache(20)
def mothers_in_trap(self, trap_id: int): def mothers_in_trap(self, trap_id: int):
return self.mothers[trap_id] return self.mothers[trap_id]
@property @cached_property
def mothers(self): def mothers(self):
""" """
Return nested list with final prediction of mother id for each cell Return nested list with final prediction of mother id for each cell
...@@ -279,24 +280,29 @@ class Cells: ...@@ -279,24 +280,29 @@ class Cells:
self.ntraps, self.ntraps,
) )
@property @cached_property
def mothers_daughters(self): def mothers_daughters(self) -> np.ndarray:
"""
Return mothers and daugters as a single array with three columns:
trap, mothers and daughters
"""
nested_massign = self.mothers nested_massign = self.mothers
if sum([x for y in nested_massign for x in y]): if sum([x for y in nested_massign for x in y]):
mothers, daughters = zip( mothers_daughters = np.array(
*[ [
((tid, m), (tid, d)) (tid, m, d)
for tid, trapcells in enumerate(nested_massign) for tid, trapcells in enumerate(nested_massign)
for d, m in enumerate(trapcells, 1) for d, m in enumerate(trapcells, 1)
if m if m
] ],
dtype=np.uint16,
) )
else: else:
mothers, daughters = ([], []) mothers_daughters = np.array([])
# print("Warning:Cells: No mother-daughters assigned") # print("Warning:Cells: No mother-daughters assigned")
return mothers, daughters return mothers_daughters
@staticmethod @staticmethod
def mother_assign_to_mb_matrix(ma: t.List[np.array]): def mother_assign_to_mb_matrix(ma: t.List[np.array]):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment