Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
pipeline identifier still contains the user-specified value)
- fix: negative "index_mapping" values and mappings that do not
select any events now raise a `ValueError`
- fix: segmenters more than two levels below `Segmenter` (e.g. a
subclass of `SegmentThresh`) were not found by `get_segmenters`,
so their pipeline identifier could not be resolved
- docs: comment on intended behavior of `fill_holes` (mask
post-processing), Haralick texture features, and the sparsemed
background assignment after cleansing
Expand Down
14 changes: 9 additions & 5 deletions dcnum/segm/segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,17 @@ def assert_labels(arr):
def get_segmenters():
"""Return dictionary of all segmenters, keyed by their PPID code

Segmenters are the subclasses of the direct subclasses of
:class:`Segmenter`, regardless of whether they are available
(see ``get_available_segmenters``).
Segmenters are all non-abstract subclasses of :class:`Segmenter`
at any depth (e.g. also subclasses of
:class:`~dcnum.segm.segm_thresh.SegmentThresh`), regardless of
whether they are available (see ``get_available_segmenters``).
"""
segmenters = {}
for scls in Segmenter.__subclasses__():
for cls in scls.__subclasses__():
subclasses = list(Segmenter.__subclasses__())
while subclasses:
cls = subclasses.pop(0)
subclasses += cls.__subclasses__()
if not inspect.isabstract(cls):
segmenters[cls.get_ppid_code()] = cls
return segmenters

Expand Down
22 changes: 22 additions & 0 deletions tests/test_meta_ppid_segm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dcnum.meta import ppid
from dcnum import segm
from dcnum.segm.segm_thresh import SegmentThresh

import pytest

Expand Down Expand Up @@ -27,6 +28,27 @@ def test_ppid_decoding_thresh_check_kwargs():
assert kwargs["kwargs_mask"]["closing_disk"] == 3


def test_ppid_decoding_subclass_of_segmenter_subclass():
"""Subclasses of concrete segmenters must be found (dcnum 0.31.2)"""
class SegmentThreshCustom(SegmentThresh):
pass

segm.get_segmenters.cache_clear()
segm_dict = segm.get_segmenters()
assert segm_dict["threshcustom"] is SegmentThreshCustom
assert segm_dict["thresh"] is SegmentThresh
# abstract base classes are not segmenters
assert segm.UNISegmenter not in segm_dict.values()

segm_ppid = SegmentThreshCustom(thresh=-4).get_ppid()
assert segm_ppid == "threshcustom:t=-4:cle=1^f=1^clo=2"
kwargs = segm.Segmenter.get_ppkw_from_ppid(segm_ppid)
assert kwargs["thresh"] == -4

# cleanup
segm.get_segmenters.cache_clear()


def test_ppid_kwargs_to_ppid():
"""Make sure that subclasses correctly implement __init__ (if they do)"""
segm_dict = segm.get_available_segmenters()
Expand Down
Loading