Skip to content

Commit

Permalink
partial doc of analyzer components
Browse files Browse the repository at this point in the history
  • Loading branch information
francoislaurent committed Sep 22, 2020
1 parent 2da3ad7 commit 88e4a48
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ The recommended starting point is :mod:`tramway.helper`.
tramway.inference
tramway.feature
tramway.utils
tramway.analyzer


1 change: 1 addition & 0 deletions doc/deconvolution.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.. _deconvolution:

The :mod:`~tramway.deconvolution` module adds several dependencies, including *scikit-image>=0.14.2*, *tifffile* and *tensorflow*. *keras* is optional as it is now included in *tensorflow* releases.

Expand Down
113 changes: 113 additions & 0 deletions doc/tramway.analyzer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

tramway.analyzer package
========================

.. automodule:: tramway.analyzer
:members:
:show-inheritance:


tramway.analyzer.spt_data package
---------------------------------

.. automodule:: tramway.analyzer.spt_data
:members:
:show-inheritance:


tramway.analyzer.roi package
----------------------------

.. automodule:: tramway.analyzer.roi
:members:
:show-inheritance:


tramway.analyzer.time package
-----------------------------

.. automodule:: tramway.analyzer.time
:members:
:show-inheritance:


tramway.analyzer.tesseller package
----------------------------------

.. automodule:: tramway.analyzer.tesseller
:members:
:show-inheritance:


tramway.analyzer.tesseller.stdalg module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This module is exported by the :mod:`tramway.analyzer` package
as *tessellers*.

.. automodule:: tramway.analyzer.tesseller.stdalg
:members:
:show-inheritance:


tramway.analyzer.tesseller.post package
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. automodule:: tramway.analyzer.tesseller.post
:members:
:show-inheritance:


tramway.analyzer.tesseller.post.merger module
"""""""""""""""""""""""""""""""""""""""""""""

This module is exported by the :mod:`tramway.analyzer` package
as *cell_mergers*.

.. automodule:: tramway.analyzer.tesseller.post.merger
:members:
:show-inheritance:


tramway.analyzer.sampler package
--------------------------------

.. automodule:: tramway.analyzer.sampler
:members:
:show-inheritance:


tramway.analyzer.mapper package
-------------------------------

.. automodule:: tramway.analyzer.mapper
:members:
:show-inheritance:


tramway.analyzer.pipeline package
---------------------------------

.. automodule:: tramway.analyzer.pipeline
:members:
:show-inheritance:


tramway.analyzer.env package
----------------------------

.. automodule:: tramway.analyzer.env
:members:
:show-inheritance:


tramway.analyzer.env.environments module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This module is exported by the :mod:`tramway.analyzer` package
as *environments*.

.. automodule:: tramway.analyzer.env.environments
:members:
:show-inheritance:

45 changes: 45 additions & 0 deletions tramway/analyzer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,42 +178,79 @@ def logger(self, logger):
self._logger = logger

def _get_spt_data(self):
"""
SPT data accessor.
See :class:`~spt_data.SPTDataInitializer`.
"""
return self._spt_data
def _set_spt_data(self, data):
self._spt_data = data
spt_data = selfinitializing_property('spt_data', _get_spt_data, _set_spt_data, SPTData)

def _get_roi(self):
"""
ROI accessor.
See :class:`~roi.ROIInitializer`.
"""
return self._roi
def _set_roi(self, roi):
self._roi = roi
roi = selfinitializing_property('roi', _get_roi, _set_roi, ROI)

def _get_time(self):
"""
Time segmentation procedure.
See :class:`~time.TimeInitializer`.
"""
return self._time
def _set_time(self, time):
self._time = time
time = selfinitializing_property('time', _get_time, _set_time, Time)

def _get_tesseller(self):
"""
Tessellation procedure.
See :class:`~tesseller.TessellerInitializer`.
"""
return self._tesseller
def _set_tesseller(self, tesseller):
self._tesseller = tesseller
tesseller = selfinitializing_property('tesseller', _get_tesseller, _set_tesseller, Tesseller)

def _get_sampler(self):
"""
Sampling procedure.
See :class:`~sampler.SamplerInitializer`.
"""
return self._sampler
def _set_sampler(self, sampler):
self._sampler = sampler
sampler = selfinitializing_property('sampler', _get_sampler, _set_sampler, Sampler)

def _get_mapper(self):
"""
Inference procedure.
See :class:`~mapper.MapperInitializer`.
"""
return self._mapper
def _set_mapper(self, mapper):
self._mapper = mapper
mapper = selfinitializing_property('mapper', _get_mapper, _set_mapper, Mapper)

def _get_env(self):
"""
Environment backend for operating the pipeline.
If not set, the pipeline will run locally in the current interpreter.
See :mod:`~env.environments`.
"""
return self._env
def _set_env(self, env):
self._env = env
Expand All @@ -238,9 +275,17 @@ def __init__(self):

@property
def pipeline(self):
"""
Parallelization scheme.
See `env`.
"""
return self._pipeline

def run(self):
"""
launches the pipeline.
"""
return self.pipeline.run()

def __setattr__(self, attrname, obj):
Expand Down
2 changes: 1 addition & 1 deletion tramway/analyzer/pipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Pipeline(AnalyzerNode):
`pipeline` attribute of an :class:`~tramway.analyzer.RWAnalyzer` object.
The main methods are `append_stage` and `run`.
Note that the `run` method is called by :met:`~tramway.analyzer.RWAnalyzer.run`
Note that the `run` method is called by :meth:`~tramway.analyzer.RWAnalyzer.run`
of :class:`~tramway.analyzer.RWAnalyzer`.
"""
__slots__ = ('_stage',)
Expand Down
33 changes: 33 additions & 0 deletions tramway/analyzer/roi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class IndividualROI(BaseRegion):
pass

class BoundingBox(IndividualROI):
""" See :class:`BoundingBoxes`. """
__slots__ = ('_bounding_box',)
def __init__(self, bb, label, spt_data, **kwargs):
IndividualROI.__init__(self, spt_data, label, **kwargs)
Expand All @@ -67,6 +68,9 @@ def bounding_box(self):
return self._bounding_box

class SupportRegion(BaseRegion):
"""
union of overlapping ROI.
"""
__slots__ = ('_sr_index','_support_regions')
def __init__(self, r, regions, spt_data, **kwargs):
BaseRegion.__init__(self,
Expand All @@ -89,12 +93,19 @@ def bounding_box(self):
return np.min(np.stack(minima, axis=0), axis=0), np.max(np.stack(maxima, axis=0), axis=0)

class FullRegion(BaseRegion):
"""
supplies with the full dataset; does not actually crop.
"""
__slots__ = ()
def crop(self, df=None):
return self._spt_data.dataframe if df is None else df


class DecentralizedROIManager(AnalyzerNode):
"""
This class allows to iterate over the ROI defined at the level of
each SPT data item.
"""
__slots__ = ('_records',)
def __init__(self, first_record=None, **kwargs):
AnalyzerNode.__init__(self, **kwargs)
Expand Down Expand Up @@ -145,6 +156,12 @@ def as_support_regions(self, index=None, source=None, **kwargs):


class ROIInitializer(Initializer):
"""
initial value for the `RWAnalyzer.roi` attribute.
`from_...` methods alters the parent attribute which specializes
into an initialized :class:`.abc.ROI` object.
"""
__slots__ = ()
def specialize(self, cls, *args, **kwargs):
Initializer.specialize(self, cls, *args, **kwargs)
Expand All @@ -166,8 +183,14 @@ def _from_common_roi(self, roi):
def _register_decentralized_roi(self, roi):
self.specialize( DecentralizedROIManager, roi )
def from_bounding_boxes(self, bb, label=None, group_overlapping_roi=False):
"""
Defines ROI as bounding boxes.
"""
self.specialize( BoundingBoxes, bb, label, group_overlapping_roi )
def from_squares(self, centers, side, label=None, group_overlapping_roi=False):
"""
Defines ROI as centers for squares/cubes of uniform size.
"""
bb = [ (center-.5*side, center+.5*side) for center in centers ]
self.from_bounding_boxes(bb, label, group_overlapping_roi)
## in the case no ROI are defined
Expand Down Expand Up @@ -211,6 +234,9 @@ def as_individual_roi(self, index=None, collection=None, source=None, **kwargs):


class CommonROI(AnalyzerNode):
"""
Mirrors the global `RWAnalyzer.roi` attribute.
"""
__slots__ = ('_global',)
def __init__(self, roi, parent=None):
AnalyzerNode.__init__(self, parent)
Expand All @@ -232,6 +258,9 @@ def as_individual_roi(self, index=None, collection=None, source=None, return_ind


class SpecializedROI(AnalyzerNode):
"""
Base class for initialized *roi* attributes.
"""
__slots__ = ('_global','_collections')
def __init__(self, **kwargs):
AnalyzerNode.__init__(self, **kwargs)
Expand Down Expand Up @@ -328,6 +357,9 @@ def bear_child(i, *args):


class HasROI(AnalyzerNode):
""" Class to be inherited from by SPT data item classes.
Maintains a self-modifying *roi* attribute."""
__slots__ = ('_roi',)
def _get_roi(self):
return self._roi
Expand All @@ -338,6 +370,7 @@ def _set_roi(self, roi):
assert isinstance(global_roi_attr, DecentralizedROIManager)
global_roi_attr._register_decentralized_roi(self)
roi = selfinitializing_property('roi', _get_roi, _set_roi, ROI)

def __init__(self, roi=ROIInitializer, **kwargs):
AnalyzerNode.__init__(self, **kwargs)
self._roi = roi(self._set_roi, parent=self)
Expand Down

0 comments on commit 88e4a48

Please sign in to comment.