Skip to content

Commit

Permalink
update single_cell.py: fix bugs and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dummyindex committed Nov 23, 2023
1 parent e84c799 commit 138b27a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions livecellx/core/single_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pandas as pd
from skimage.measure._regionprops import RegionProperties
from skimage.measure import regionprops
import tqdm
import uuid

from livecellx.core.datasets import LiveCellImageDataset, SingleImageDataset
Expand Down Expand Up @@ -424,16 +425,20 @@ def load_single_cells_json(path: str) -> List["SingleCellStatic"]:
_type_
_description_
"""
main_info("loading single cells from json file: " + path)
with open(path, "r") as f:
sc_json_dict_list = json.load(f)
main_info("loaded " + str(len(sc_json_dict_list)) + " single cells")

main_info("constructing single cells from json dict...")
# contour = [] here to suppress warning
single_cells = []
for sc_json_dict in sc_json_dict_list:
for sc_json_dict in tqdm.tqdm(sc_json_dict_list):
# Load the single cell from json dict
sc = SingleCellStatic(contour=[]).load_from_json_dict(sc_json_dict)
single_cells.append(sc)

main_info("done constructing single cells from json dict")
return single_cells

@staticmethod
Expand Down Expand Up @@ -1060,10 +1065,16 @@ def copy(self):

return copy.deepcopy(self)

def is_empty(self):
return len(self.timeframe_set) == 0

def subsct(self, min_time, max_time, track_id=None, keep_track_id=False):
"""return a subtrajectory of this trajectory, with timeframes between min_time and max_time. Mother and daugher info will be copied if the min_time and max_time are the start and end of the new trajectory, respectively."""
require_copy_mothers_info = False
require_copy_daughters_info = False
if self.is_empty():
return SingleCellTrajectory(track_id=track_id)

self_span = self.get_timeframe_span()

# TODO: if time is float case, consider round-off errors
Expand Down Expand Up @@ -1268,11 +1279,14 @@ def remove_empty_sct(self):
remove_scs = []
for tid, sct in self:
_tmp_scs = sct.get_all_scs()
to_be_removed = True
for sc in _tmp_scs:
if len(sc.contour) > 0:
to_be_removed = False
break
remove_tids.append(tid)
remove_scs.extend(_tmp_scs)
if to_be_removed:
remove_tids.append(tid)
remove_scs.extend(_tmp_scs)
for tid in remove_tids:
self.pop_trajectory(tid)

Expand Down

0 comments on commit 138b27a

Please sign in to comment.