diff --git a/CHANGELOG b/CHANGELOG index adc3664..5d066f2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/dcnum/feat/gate.py b/dcnum/feat/gate.py index 5115284..b558f6d 100644 --- a/dcnum/feat/gate.py +++ b/dcnum/feat/gate.py @@ -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)""" @@ -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""" diff --git a/tests/test_feat_gate.py b/tests/test_feat_gate.py index 26f395c..1336eda 100644 --- a/tests/test_feat_gate.py +++ b/tests/test_feat_gate.py @@ -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