Skip to content

Commit

Permalink
[easy] Rename all the algorithm base classes to *Algorithm (#1553)
Browse files Browse the repository at this point in the history
There were some that were *AlgorithmBase.  There were some that were *Base.  This unifies them all to *Algorithm.

Also fixed some stale docs.
  • Loading branch information
Tony Tung authored Sep 18, 2019
1 parent b887d66 commit d293e13
Show file tree
Hide file tree
Showing 41 changed files with 89 additions and 101 deletions.
18 changes: 6 additions & 12 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ Creating a new algorithm for an existing `pipeline_component`

For example, to add a new image filter, one would:

1. Create a new python file `new_filter.py` in the `starfish/pipeline/filter/` directory.
1. Create a new python file `new_filter.py` in the `starfish/core/image/Filter/` directory.
2. Find the corresponding `AlgorithmBase` for your component.
For filters, this is `FilterAlgorithmBase`, which is found in `starfish/pipeline/filter/_base.py`.
For filters, this is `FilterAlgorithm`, which is found in `starfish/core/image/Filter/_base.py`.
Import that base into `new_filter.py`, and have your new algorithm subclass it,
e.g. create `class NewFilter(FilterAlgorithmBase)`
e.g. create `class NewFilter(FilterAlgorithm)`
3. Implement all required methods from the base class.
4. For the command line arguments to mimic the API, the arguments passed to the CLI must exactly
match the names of the parameters for `NewFilter.__init__`, after dashes are automatically converted by argparse.
For example, `--foo-bar` would convert to `foo_bar` and init must accept such an argument:
`NewFilter.__init__(foo_bar, ..., **kwargs)`
5. `NewFilter.__init__()` must have a `**kwargs` parameter to accept arbitrary CLI args.

That's it! Your `NewFilter` algoritm will automatically register and be available under `starfish filter` in the CLI.
If at any point something gets confusing, it should be possible to look at existing pipeline components of the same
category for guidance on implementation.

That's it! If at any point something gets confusing, it should be possible to look at existing pipeline components of
the same category for guidance on implementation.

Reporting bugs
--------------
Expand Down
8 changes: 4 additions & 4 deletions docs/source/api/image/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Filtering
---------

Filters can be imported using ``starfish.image.Filter``, which registers all classes that subclass
``FilterAlgorithmBase``:
``FilterAlgorithm``:

.. code-block:: python
Expand All @@ -33,7 +33,7 @@ Learn Transform
---------------

LearnTransform can be imported using ``starfish.image.LearnTransform``, the subclasses of
``LearnTransformBase`` are available for transform learning.
``LearnTransformAlgorithm`` are available for transform learning.

.. code-block:: python
Expand All @@ -49,7 +49,7 @@ Apply Transform
---------------

ApplyTransform can be imported using ``starfish.image.ApplyTransform``, the subclasses of
``ApplyTransformBase`` are available for transform learning.
``ApplyTransformAlgorithm`` are available for transform learning.

.. code-block:: python
Expand All @@ -65,7 +65,7 @@ Segmentation
------------

Segmentation can be imported using ``starfish.image.Segment``, which registers all classes that subclass
``SegmentAlgorithmBase``:
``SegmentAlgorithm``:

.. code-block:: python
Expand Down
8 changes: 4 additions & 4 deletions docs/source/api/spots/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ These include :py:class:`starfish.spots.DetectPixels`, which exposes methods tha
Detecting Pixels
----------------

Pixel Detectors can be imported using ``starfish.spots.DetectPixels``, which registers all classes that subclass ``DetectPixelsAlgorithmBase``:
Pixel Detectors can be imported using ``starfish.spots.DetectPixels``, which registers all classes that subclass ``DetectPixelsAlgorithm``:

.. code-block:: python
Expand All @@ -29,7 +29,7 @@ Pixel Detectors can be imported using ``starfish.spots.DetectPixels``, which reg
Detecting Spots
---------------

Spot Detectors can be imported using ``starfish.spots.DetectSpots``, which registers all classes that subclass ``DetectSpotsAlgorithmBase``:
Spot Detectors can be imported using ``starfish.spots.DetectSpots``, which registers all classes that subclass ``DetectSpotsAlgorithm``:

.. code-block:: python
Expand All @@ -44,7 +44,7 @@ Spot Detectors can be imported using ``starfish.spots.DetectSpots``, which regis
Decoding
--------

Decoders can be imported using ``starfish.spots.Decode``, which registers all classes that subclass ``DecodeAlgorithmBase``:
Decoders can be imported using ``starfish.spots.Decode``, which registers all classes that subclass ``DecodeAlgorithm``:

.. code-block:: python
Expand All @@ -59,7 +59,7 @@ Decoders can be imported using ``starfish.spots.Decode``, which registers all cl
Target Assignment
-----------------

Target Assignment can be imported using ``starfish.spots.AssignTargets``, which registers all classes that subclass ``AssignTargetsAlgorithmBase``:
Target Assignment can be imported using ``starfish.spots.AssignTargets``, which registers all classes that subclass ``AssignTargetsAlgorithm``:

.. code-block:: python
Expand Down
18 changes: 6 additions & 12 deletions docs/source/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@ Creating a new algorithm for an existing `pipeline_component`

For example, to add a new image filter, one would:

1. Create a new python file `new_filter.py` in the `starfish/pipeline/filter/` directory.
1. Create a new python file `new_filter.py` in the `starfish/core/image/Filter/` directory.
2. Find the corresponding `AlgorithmBase` for your component.
For filters, this is `FilterAlgorithmBase`, which is found in `starfish/pipeline/filter/_base.py`.
For filters, this is `FilterAlgorithm`, which is found in `starfish/core/image/Filter/_base.py`.
Import that base into `new_filter.py`, and have your new algorithm subclass it,
e.g. create `class NewFilter(FilterAlgorithmBase)`
e.g. create `class NewFilter(FilterAlgorithm)`
3. Implement all required methods from the base class.
4. For the command line arguments to mimic the API, the arguments passed to the CLI must exactly
match the names of the parameters for `NewFilter.__init__`, after dashes are automatically converted by argparse.
For example, `--foo-bar` would convert to `foo_bar` and init must accept such an argument:
`NewFilter.__init__(foo_bar, ..., **kwargs)`
5. `NewFilter.__init__()` must have a `**kwargs` parameter to accept arbitrary CLI args.

That's it! Your `NewFilter` algoritm will automatically register and be available under `starfish filter` in the CLI.
If at any point something gets confusing, it should be possible to look at existing pipeline components of the same
category for guidance on implementation.

That's it! If at any point something gets confusing, it should be possible to look at existing pipeline components of
the same category for guidance on implementation.

Reporting bugs
--------------
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .bandpass import Bandpass
from .clip import Clip
from .clip_percentile_to_zero import ClipPercentileToZero
Expand All @@ -21,6 +21,6 @@
all_filters = {
filter_name: filter_cls
for filter_name, filter_cls in locals().items()
if isinstance(filter_cls, type) and FilterAlgorithmBase in filter_cls.__mro__
if isinstance(filter_cls, type) and FilterAlgorithm in filter_cls.__mro__
}
__all__ = list(all_filters.keys())
2 changes: 1 addition & 1 deletion starfish/core/image/Filter/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from starfish.core.pipeline.algorithmbase import AlgorithmBase


class FilterAlgorithmBase(metaclass=AlgorithmBase):
class FilterAlgorithm(metaclass=AlgorithmBase):

@abstractmethod
def run(self, stack: ImageStack, *args) -> Optional[ImageStack]:
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip, Number
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import determine_axes_to_group_by


class Bandpass(FilterAlgorithmBase):
class Bandpass(FilterAlgorithm):
"""
Convolve with a Gaussian to remove short-wavelength noise and subtract out long-wavelength
variations, retaining features of intermediate scale. This implementation relies on
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/call_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.types import Axes
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class CallBases(FilterAlgorithmBase):
class CallBases(FilterAlgorithm):
"""
The CallBases filter determines the nucleotide present in each pixel of each
(round, channel). The pixel values in the resulting image are the base quality
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import xarray as xr

from starfish.core.imagestack.imagestack import ImageStack
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import determine_axes_to_group_by


class Clip(FilterAlgorithmBase):
class Clip(FilterAlgorithm):
"""
Image clipping filter that clips values below a minimum percentile and above a maximum
percentile.
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/clip_percentile_to_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import xarray as xr

from starfish.core.imagestack.imagestack import ImageStack
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import determine_axes_to_group_by


class ClipPercentileToZero(FilterAlgorithmBase):
class ClipPercentileToZero(FilterAlgorithm):
"""
Image clipping filter that clips values below a minimum percentile and
above a maximum percentile, and follows up by subtracting the minimum
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/clip_value_to_zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Number
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import determine_axes_to_group_by


class ClipValueToZero(FilterAlgorithmBase):
class ClipValueToZero(FilterAlgorithm):
"""
Image clipping filter that clips values below a minimum value and above a
maximum value. The filter then subtracts the minimum value from the
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/element_wise_mult.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip
from starfish.core.util.dtype import preserve_float_range
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class ElementWiseMultiply(FilterAlgorithmBase):
class ElementWiseMultiply(FilterAlgorithm):
"""
Perform element-wise multiplication on the image tensor. This is useful for
performing operations such as image normalization or field flatness correction
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/gaussian_high_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip, Number
from starfish.core.util.dtype import preserve_float_range
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import (
determine_axes_to_group_by,
validate_and_broadcast_kernel_size,
)


class GaussianHighPass(FilterAlgorithmBase):
class GaussianHighPass(FilterAlgorithm):
"""
Applies a Gaussian high pass filter to the ImageStack. This is useful to remove cellular
autofluorescence, which is typically low frequency.
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/gaussian_low_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip, Number
from starfish.core.util.dtype import preserve_float_range
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import (
determine_axes_to_group_by,
validate_and_broadcast_kernel_size,
)


class GaussianLowPass(FilterAlgorithmBase):
class GaussianLowPass(FilterAlgorithm):
"""
Multi-dimensional low-pass gaussian filter. This filter blurs image data, and can be
useful to apply prior to pixel decoding or watershed segmentation to spread intensity across
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xarray as xr
from scipy.ndimage import gaussian_laplace

from starfish.core.image.Filter._base import FilterAlgorithmBase
from starfish.core.image.Filter._base import FilterAlgorithm
from starfish.core.image.Filter.util import (
determine_axes_to_group_by,
validate_and_broadcast_kernel_size,
Expand All @@ -15,7 +15,7 @@
from starfish.core.types import Clip, Number


class Laplace(FilterAlgorithmBase):
class Laplace(FilterAlgorithm):
"""
Multi-dimensional Gaussian-Laplacian filter used to enhance dots against background
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/linear_unmixing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Axes, Clip
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class LinearUnmixing(FilterAlgorithmBase):
class LinearUnmixing(FilterAlgorithm):
"""
LinearUnmixing enables the user to correct fluorescent bleed by subtracting fractions of the
intensities of other channels from each channel in the ImageStack.
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Axes, Clip
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class Map(FilterAlgorithmBase):
class Map(FilterAlgorithm):
"""
Map from input to output by applying a specified function to the input. The output must have
the same shape as the input.
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/match_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Axes
from starfish.core.util import enum
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class MatchHistograms(FilterAlgorithmBase):
class MatchHistograms(FilterAlgorithm):
"""
Normalize data by matching distributions of each tile or volume to a reference volume
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/max_proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Axes
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class MaxProject(FilterAlgorithmBase):
class MaxProject(FilterAlgorithm):
"""
Creates a maximum projection over one or more axis of the image tensor
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/mean_high_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip, Number
from starfish.core.util.dtype import preserve_float_range
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import (
determine_axes_to_group_by, validate_and_broadcast_kernel_size
)


class MeanHighPass(FilterAlgorithmBase):
class MeanHighPass(FilterAlgorithm):
"""
The mean high pass filter reduces low spatial frequency features by subtracting a
mean filtered image from the original image. The mean filter smooths an image by replacing
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Axes, Clip, Coordinates, Number
from starfish.core.util.dtype import preserve_float_range
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm


class Reduce(FilterAlgorithmBase):
class Reduce(FilterAlgorithm):
"""
Reduces the cardinality of one or more axes to 1 by applying a function across those axes.
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/richardson_lucy_deconvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip, Number
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import (
determine_axes_to_group_by,
gaussian_kernel,
)


class DeconvolvePSF(FilterAlgorithmBase):
class DeconvolvePSF(FilterAlgorithm):
"""
Deconvolve a point spread function from the image. The point spread function is assumed to be
an isotropic Gaussian, with a user specified standard deviation, sigma.
Expand Down
4 changes: 2 additions & 2 deletions starfish/core/image/Filter/white_tophat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from starfish.core.imagestack.imagestack import ImageStack
from starfish.core.types import Clip
from ._base import FilterAlgorithmBase
from ._base import FilterAlgorithm
from .util import determine_axes_to_group_by


class WhiteTophat(FilterAlgorithmBase):
class WhiteTophat(FilterAlgorithm):
"""
Performs "white top hat" filtering of an image to enhance spots. White top hat filtering
finds spots that are both smaller and brighter than their surroundings by subtracting an
Expand Down
Loading

0 comments on commit d293e13

Please sign in to comment.