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 @@ -64,6 +64,9 @@
- fix: the cached arrays returned by `get_mapping_indices` could be
modified by callers, changing the result of later calls; they are
read-only now
- fix: an explicit `size_thresh_mask=0` for `Gate` (also via the
"bin area min" metadata with online gates) was replaced by the
default value 10
- docs: comment on intended behavior of `fill_holes` (mask
post-processing), Haralick texture features, and the sparsemed
background assignment after cleansing
Expand Down
11 changes: 7 additions & 4 deletions dcnum/feat/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def __init__(self, data, *,
considered to be a valid event; Originally, the
``bin area min / trig_thresh`` value defaulted to 200 which is
too large; defaults to 10 or the original value in case
``online_gates`` is set.
``online_gates`` is set. Set this to 0 to keep all
non-empty masks.
"""
self.box_gates = {}
"""box gating (value range for each feature)"""
Expand All @@ -48,11 +49,13 @@ def __init__(self, data, *,
size_thresh_mask = data.meta_nest.get(
"online_contour", {}).get("bin area min")

if size_thresh_mask is None:
size_thresh_mask = self._default_size_thresh_mask

self.kwargs = {
"online_gates": online_gates,
# Set the size threshold, defaulting to `_default_size_thresh_mask`
"size_thresh_mask":
size_thresh_mask or self._default_size_thresh_mask
# Set the size threshold (an explicit 0 keeps all masks)
"size_thresh_mask": size_thresh_mask,
}
"""gating keyword arguments"""

Expand Down
29 changes: 29 additions & 0 deletions tests/test_feat_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,35 @@ def test_gate_mask():
assert gt.gate_mask(mask2, mask_sum=np.sum(mask2))


def test_gate_mask_size_thresh_zero():
"""An explicit `size_thresh_mask=0` keeps all non-empty masks

In dcnum 0.31.2, 0 was replaced by the default value 10.
"""
path = retrieve_data(
"fmt-hdf5_cytoshot_full-features_legacy_allev_2023.zip")
with h5py.File(path, "a") as h5:
h5.attrs["online_contour:bin area min"] = 0

with HDF5Data(path) as hd:
gt = Gate(data=hd, online_gates=False, size_thresh_mask=0)
assert gt.kwargs["size_thresh_mask"] == 0
assert gt.get_ppid() == "norm:o=0^s=0"
mask = np.zeros((20, 20), dtype=bool)
mask[2, 2] = True
assert gt.gate_mask(mask)
assert not gt.gate_mask(np.zeros((20, 20), dtype=bool))

# value from the metadata
gt2 = Gate(data=hd, online_gates=True)
assert gt2.kwargs["size_thresh_mask"] == 0
assert gt2.get_ppid() == "norm:o=1^s=0"

# round trip with the pipeline identifier
kw = Gate.get_ppkw_from_ppid(gt.get_ppid())
assert Gate(data=hd, **kw).kwargs["size_thresh_mask"] == 0


def test_get_ppkw_from_ppid():
kw = Gate.get_ppkw_from_ppid("norm:o=true^s=23")
assert len(kw) == 2
Expand Down
Loading