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

Changes to docs in extractor in line with pylsp

parent 32661aec
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ RED_FUNS = load_redfuns() ...@@ -39,7 +39,7 @@ RED_FUNS = load_redfuns()
class ExtractorParameters(ParametersABC): class ExtractorParameters(ParametersABC):
""" """
Base class to define parameters for extraction Base class to define parameters for extraction.
""" """
def __init__( def __init__(
...@@ -55,7 +55,7 @@ class ExtractorParameters(ParametersABC): ...@@ -55,7 +55,7 @@ class ExtractorParameters(ParametersABC):
Nested dictionary indicating channels, reduction functions and Nested dictionary indicating channels, reduction functions and
metrics to be used. metrics to be used.
str channel -> U(function,None) reduction -> str metric str channel -> U(function,None) reduction -> str metric
If not of depth three, tree will be filled with Nones. If not of depth three, tree will be filled with None.
sub_bg: set sub_bg: set
multichannel_ops: dict multichannel_ops: dict
""" """
...@@ -66,7 +66,7 @@ class ExtractorParameters(ParametersABC): ...@@ -66,7 +66,7 @@ class ExtractorParameters(ParametersABC):
@staticmethod @staticmethod
def guess_from_meta(store_name: str, suffix="fast"): def guess_from_meta(store_name: str, suffix="fast"):
""" """
Find the microscope used from the h5 metadata Find the microscope used from the h5 metadata.
Parameters Parameters
---------- ----------
...@@ -91,25 +91,28 @@ class ExtractorParameters(ParametersABC): ...@@ -91,25 +91,28 @@ class ExtractorParameters(ParametersABC):
class Extractor(ProcessABC): class Extractor(ProcessABC):
""" """
The Extractor applies a metric, such as area or median, to cells identified in the image tiles using the cell masks. Apply a metric to cells identified in the tiles.
Its methods therefore require both tile images and masks. Using the cell masks, the Extractor applies a metric, such as area or median, to cells identified in the image tiles.
Usually one metric is applied to the masked area in a tile, but there are metrics that depend on the whole tile. Its methods require both tile images and masks.
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, which is the median value of the pixels in each cell. Usually the metric is applied to only a tile's masked area, but some metrics depend on the whole tile.
Extraction follows a three-level tree structure. Channels, such as GFP, are the root level; the reduction algorithm, such as maximum projection, is the second level; the specific metric, or operation, to apply to the masks is the third level.
Parameters Parameters
---------- ----------
parameters: core.extractor Parameters parameters: core.extractor Parameters
Parameters that include with channels, reduction and Parameters that include the channels, and reduction and
extraction functions to use. extraction functions.
store: str store: str
Path to hdf5 storage file. Must contain cell outlines. Path to the h5 file, which must contain the cell masks.
tiler: pipeline-core.core.segmentation tiler tiler: pipeline-core.core.segmentation tiler
Class that contains or fetches the image to be used for segmentation. Class that contains or fetches the images used for segmentation.
""" """
# Alan: should this data be stored here or all such data in a separate file
default_meta = { default_meta = {
"pixel_size": 0.236, "pixel_size": 0.236,
"z_size": 0.6, "z_size": 0.6,
...@@ -150,7 +153,7 @@ class Extractor(ProcessABC): ...@@ -150,7 +153,7 @@ class Extractor(ProcessABC):
store: str, store: str,
tiler: Tiler, tiler: Tiler,
): ):
# initate from tiler """Initiate from a tiler instance."""
return cls(parameters, store=store, tiler=tiler) return cls(parameters, store=store, tiler=tiler)
@classmethod @classmethod
...@@ -160,12 +163,12 @@ class Extractor(ProcessABC): ...@@ -160,12 +163,12 @@ class Extractor(ProcessABC):
store: str, store: str,
img_meta: tuple, img_meta: tuple,
): ):
# initiate from image """Initiate from images."""
return cls(parameters, store=store, tiler=Tiler(*img_meta)) return cls(parameters, store=store, tiler=Tiler(*img_meta))
@property @property
def channels(self): def channels(self):
# returns a tuple of strings of the available channels """Get a tuple of the available channels."""
if not hasattr(self, "_channels"): if not hasattr(self, "_channels"):
if type(self.params.tree) is dict: if type(self.params.tree) is dict:
self._channels = tuple(self.params.tree.keys()) self._channels = tuple(self.params.tree.keys())
...@@ -226,7 +229,7 @@ class Extractor(ProcessABC): ...@@ -226,7 +229,7 @@ class Extractor(ProcessABC):
self._all_funs = {**self._custom_funs, **FUNS} self._all_funs = {**self._custom_funs, **FUNS}
def load_meta(self): def load_meta(self):
# load metadata from h5 file whose name is given by self.local """Load metadata from h5 file."""
self.meta = load_attributes(self.local) self.meta = load_attributes(self.local)
def get_tiles( def get_tiles(
...@@ -237,8 +240,9 @@ class Extractor(ProcessABC): ...@@ -237,8 +240,9 @@ class Extractor(ProcessABC):
**kwargs, **kwargs,
) -> t.Optional[np.ndarray]: ) -> t.Optional[np.ndarray]:
""" """
Finds traps for a given time point and given channels and z-stacks. Find tiles for a given time point and given channels and z-stacks.
Returns None if no traps are found.
Returns None if no tiles are found.
Any additional keyword arguments are passed to tiler.get_tiles_timepoint Any additional keyword arguments are passed to tiler.get_tiles_timepoint
...@@ -378,7 +382,6 @@ class Extractor(ProcessABC): ...@@ -378,7 +382,6 @@ class Extractor(ProcessABC):
self.reduce_dims(trap, method=RED_FUNS[red_fun]) self.reduce_dims(trap, method=RED_FUNS[red_fun])
for trap in traps for trap in traps
] ]
d = { d = {
red_fun: self.extract_funs( red_fun: self.extract_funs(
metrics=metrics, metrics=metrics,
...@@ -395,6 +398,7 @@ class Extractor(ProcessABC): ...@@ -395,6 +398,7 @@ class Extractor(ProcessABC):
) -> np.ndarray: ) -> np.ndarray:
""" """
Collapse a z-stack into 2d array using method. Collapse a z-stack into 2d array using method.
If method is None, return the original data. If method is None, return the original data.
Parameters Parameters
...@@ -419,7 +423,7 @@ class Extractor(ProcessABC): ...@@ -419,7 +423,7 @@ class Extractor(ProcessABC):
**kwargs, **kwargs,
) -> t.Dict[str, t.Dict[str, t.Dict[str, tuple]]]: ) -> t.Dict[str, t.Dict[str, t.Dict[str, tuple]]]:
""" """
Core extraction method for an individual time-point. Extract for an individual time-point.
Parameters Parameters
---------- ----------
...@@ -561,7 +565,7 @@ class Extractor(ProcessABC): ...@@ -561,7 +565,7 @@ class Extractor(ProcessABC):
def get_imgs(self, channel: t.Optional[str], traps, channels=None): def get_imgs(self, channel: t.Optional[str], traps, channels=None):
""" """
Returns the image from a correct source, either raw or bgsub Return image from a correct source, either raw or bgsub.
Parameters Parameters
---------- ----------
...@@ -586,7 +590,7 @@ class Extractor(ProcessABC): ...@@ -586,7 +590,7 @@ class Extractor(ProcessABC):
def run_tp(self, tp, **kwargs): def run_tp(self, tp, **kwargs):
""" """
Wrapper to add compatiblibility with other steps of the pipeline. Wrapper to add compatibility with other steps of the pipeline.
""" """
return self.run(tps=[tp], **kwargs) return self.run(tps=[tp], **kwargs)
...@@ -680,7 +684,7 @@ def flatten_nesteddict( ...@@ -680,7 +684,7 @@ def flatten_nesteddict(
nest: dict, to="series", tp: int = None nest: dict, to="series", tp: int = None
) -> t.Dict[str, pd.Series]: ) -> t.Dict[str, pd.Series]:
""" """
Converts a nested extraction dict into a dict of pd.Series Convert a nested extraction dict into a dict of pd.Series.
Parameters Parameters
---------- ----------
...@@ -709,6 +713,7 @@ def flatten_nesteddict( ...@@ -709,6 +713,7 @@ def flatten_nesteddict(
class hollowExtractor(Extractor): class hollowExtractor(Extractor):
""" """
Extractor that only cares about receiving images and masks. Extractor that only cares about receiving images and masks.
Used for testing. Used for testing.
""" """
......
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