Skip to content
Snippets Groups Projects
Commit d4360872 authored by pswain's avatar pswain
Browse files

docs(extractor): add docstring to top of file

parent e5e7984c
No related branches found
No related tags found
No related merge requests found
"""
The Extractor applies a metric, such as area or median, to image tiles using the cell masks.
Its methods therefore require both tile images and masks.
Usually one metric is applied per mask, but there are tile-specific backgrounds, which apply one metric per tile.
Extraction follows a three-level tree structure. Channels, such as GFP, are the root level; the second level is the reduction algorithm, such as maximum projection; the last level is the metric -- the specific operation to apply to the cells in the image identified by the mask, such as median -- the median value of the pixels in each cell.
"""
import logging import logging
import typing as t
from time import perf_counter from time import perf_counter
from typing import Callable, Dict, List from typing import Callable, Dict, List
...@@ -323,23 +333,24 @@ class Extractor(ProcessABC): ...@@ -323,23 +333,24 @@ class Extractor(ProcessABC):
masks=None, masks=None,
labels=None, labels=None,
**kwargs, **kwargs,
) -> dict: ) -> t.Dict[str, t.Dict[str, pd.Series]]:
"""Core extraction method for an individual time-point. """
Core extraction method for an individual time-point.
Parameters Parameters
---------- ----------
tp : int tp : int
Time-point being analysed. Time point being analysed.
tree : dict tree : dict
Nested dictionary indicating channels, reduction functions and Nested dictionary indicating channels, reduction functions and
metrics to use during extraction. metrics to be used.
tile_size : int tile_size : int
size of the tile to be extracted. size of the tile to be extracted.
masks : np.ndarray masks : np.ndarray
3-D boolean numpy array with dimensions (ncells, tile_size, A 3-D boolean numpy array with dimensions (ncells, tile_size,
tile_size. tile_size).
labels : t.List[t.List[int]] labels : t.List[t.List[int]]
List of list of ints indicating the ids of masks. List of lists of ints indicating the ids of masks.
**kwargs : Additional keyword arguments to be passed to extractor.reduce_extract. **kwargs : Additional keyword arguments to be passed to extractor.reduce_extract.
Returns Returns
...@@ -352,11 +363,12 @@ class Extractor(ProcessABC): ...@@ -352,11 +363,12 @@ class Extractor(ProcessABC):
""" """
if tree is None: if tree is None:
# use default
tree = self.params.tree tree = self.params.tree
# dictionary with channel: {reduction algorithm : metric}
ch_tree = {ch: v for ch, v in tree.items() if ch != "general"} ch_tree = {ch: v for ch, v in tree.items() if ch != "general"}
# tuple of the channels
tree_chs = (*ch_tree,) tree_chs = (*ch_tree,)
cells = Cells(self.local) cells = Cells(self.local)
...@@ -384,6 +396,7 @@ class Extractor(ProcessABC): ...@@ -384,6 +396,7 @@ class Extractor(ProcessABC):
self.img_bgsub = {} self.img_bgsub = {}
if self.params.sub_bg: if self.params.sub_bg:
# Generate boolean masks for background
bg = [ bg = [
~np.sum(m, axis=2).astype(bool) ~np.sum(m, axis=2).astype(bool)
if np.any(m) if np.any(m)
......
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