From de4c25e7b98e1d5e5ee617646941370dd1e41f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk> Date: Tue, 10 Jan 2023 23:46:54 +0000 Subject: [PATCH] feat(aliby): integrate logging into existing steps --- src/aliby/baby_client.py | 9 +++------ src/aliby/tile/tiler.py | 6 +++--- src/extraction/core/extractor.py | 24 ++++++++++-------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/aliby/baby_client.py b/src/aliby/baby_client.py index f13c5b02..8fcd0f06 100644 --- a/src/aliby/baby_client.py +++ b/src/aliby/baby_client.py @@ -13,7 +13,7 @@ import baby.errors import h5py import numpy as np import requests -from agora.abc import ParametersABC +from agora.abc import ParametersABC, StepABC from baby import modelsets from baby.brain import BabyBrain from baby.crawler import BabyCrawler @@ -128,7 +128,7 @@ class BabyParameters(ParametersABC): self.update("model_config", weights_flattener) -class BabyRunner: +class BabyRunner(StepABC): """A BabyRunner object for cell segmentation. Does segmentation one time point at a time.""" @@ -157,20 +157,17 @@ class BabyRunner: .swapaxes(1, 2) ) - def run_tp(self, tp, with_edgemasks=True, assign_mothers=True, **kwargs): + def _run_tp(self, tp, with_edgemasks=True, assign_mothers=True, **kwargs): """Simulating processing time with sleep""" # Access the image t = perf_counter() img = self.get_data(tp) - logging.debug(f"Timing:BF_fetch:{perf_counter()-t}s") - t = perf_counter() segmentation = self.crawler.step( img, with_edgemasks=with_edgemasks, assign_mothers=assign_mothers, **kwargs, ) - logging.debug(f"Timing:crawler_step:{perf_counter()-t}s") return format_segmentation(segmentation, tp) diff --git a/src/aliby/tile/tiler.py b/src/aliby/tile/tiler.py index 16f9b2f8..f0a75472 100644 --- a/src/aliby/tile/tiler.py +++ b/src/aliby/tile/tiler.py @@ -28,7 +28,7 @@ import h5py import numpy as np from skimage.registration import phase_cross_correlation -from agora.abc import ParametersABC, ProcessABC +from agora.abc import ParametersABC, StepABC from agora.io.writer import BridgeH5 from aliby.io.image import ImageLocalOME, ImageDir from aliby.tile.traps import segment_traps @@ -200,7 +200,7 @@ class TilerParameters(ParametersABC): _defaults = {"tile_size": 117, "ref_channel": "Brightfield", "ref_z": 0} -class Tiler(ProcessABC): +class Tiler(StepABC): """ Remote Timelapse Tiler. @@ -455,7 +455,7 @@ class Tiler(ProcessABC): ndtrap = self.ifoob_pad(full, trap.as_range(tp)) return ndtrap - def run_tp(self, tp): + def _run_tp(self, tp): """ Find traps if they have not yet been found. Determine any translational drift of the current image from the diff --git a/src/extraction/core/extractor.py b/src/extraction/core/extractor.py index 6a5af6bc..443bbc59 100644 --- a/src/extraction/core/extractor.py +++ b/src/extraction/core/extractor.py @@ -1,4 +1,3 @@ -import logging import typing as t from time import perf_counter from typing import List @@ -6,7 +5,7 @@ from typing import List import h5py import numpy as np import pandas as pd -from agora.abc import ParametersABC, ProcessABC +from agora.abc import ParametersABC, StepABC from agora.io.cells import Cells from agora.io.writer import Writer, load_attributes @@ -89,7 +88,7 @@ class ExtractorParameters(ParametersABC): return cls(**exparams_from_meta(meta)) -class Extractor(ProcessABC): +class Extractor(StepABC): """ The Extractor applies a metric, such as area or median, to cells identified in the image tiles using the cell masks. @@ -584,28 +583,22 @@ class Extractor(ProcessABC): elif channel in self.img_bgsub: return self.img_bgsub[channel] - def run_tp(self, tp, **kwargs): - """ - Wrapper to add compatiblibility with other steps of the pipeline. - """ - return self.run(tps=[tp], **kwargs) - - def run( + def _run_tp( self, - tree=None, tps: List[int] = None, + tree=None, save=True, **kwargs, ) -> dict: """ Parameters ---------- - tree: dict + tps: list of int (optional) + Time points to include. + tree: dict (optional) Nested dictionary indicating channels, reduction functions and metrics to be used. For example: {'general': {'None': ['area', 'volume', 'eccentricity']}} - tps: list of int (optional) - Time points to include. save: boolean (optional) If True, save results to h5 file. kwargs: keyword arguments (optional) @@ -620,6 +613,9 @@ class Extractor(ProcessABC): tree = self.params.tree if tps is None: tps = list(range(self.meta["time_settings/ntimepoints"][0])) + elif isinstance(tps, int): + tps = [tps] + # store results in dict d = {} for tp in tps: -- GitLab