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 @@ -53,6 +53,9 @@
so their pipeline identifier could not be resolved
- fix: `detect_flickering` raised a `TypeError` for `HDF5Data`
instances, although the docstring allowed them
- fix: files with more than one basin without a name could not be
opened (regression in 0.28.3), and basins without a name or
description could not be copied
- docs: comment on intended behavior of `fill_holes` (mask
post-processing), Haralick texture features, and the sparsemed
background assignment after cleansing
Expand Down
4 changes: 2 additions & 2 deletions dcnum/logic/ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ def task_enforce_basin_strategy(self):
else:
basinmap1 = basinmap_in[basinmap0]
# Store the internal mapping in the output file
hw.store_basin(name=bn_dict["name"],
description=bn_dict["description"],
hw.store_basin(name=bn_dict.get("name"),
description=bn_dict.get("description"),
mapping=basinmap1,
internal_data={"image_bg": bg_images1}
)
Expand Down
5 changes: 3 additions & 2 deletions dcnum/read/hdf5_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ def __setstate__(self, state):
def basin_sort_cmp(a, b):
"""Sort internal basins before any other basins"""
if a["type"] == b["type"]:
an = a["name"]
bn = b["name"]
# The basin name is optional
an = a.get("name") or ""
bn = b.get("name") or ""
if an == bn:
return 0
if an < bn:
Expand Down
8 changes: 4 additions & 4 deletions dcnum/write/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ def copy_basins(h5_src: "h5py.File",
internal_data = {}
for feat in bn_dict["features"]:
internal_data[feat] = h5_src["basin_events"][feat]
hw.store_basin(name=bn_dict["name"],
description=bn_dict["description"],
hw.store_basin(name=bn_dict.get("name"),
description=bn_dict.get("description"),
mapping=h5_src["events"][bn_dict["mapping"]][:],
internal_data=internal_data,
)
Expand All @@ -428,8 +428,8 @@ def copy_basins(h5_src: "h5py.File",
mapping = h5_src["events"][bn_dict["mapping"]][:]
else:
mapping = None
hw.store_basin(name=bn_dict["name"],
description=bn_dict["description"],
hw.store_basin(name=bn_dict.get("name"),
description=bn_dict.get("description"),
paths=bn_dict["paths"],
features=bn_dict["features"],
mapping=mapping,
Expand Down
44 changes: 44 additions & 0 deletions tests/test_read_hdf5_basins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pathlib

import h5py
Expand Down Expand Up @@ -257,6 +258,49 @@ def test_basin_multiple(mapping, numevents):
assert "area_um" not in hd


@pytest.mark.parametrize("names", [
[None, None],
["peter", None],
["omitted", "omitted"],
["peter", "omitted"],
])
def test_basin_without_name(tmp_path, names):
"""The basin name is optional (dcnum 0.31.2 could not open the file)"""
path_src = retrieve_data(
"fmt-hdf5_cytoshot_full-features_legacy_allev_2023.zip")
path = tmp_path / "unnamed.rtdc"
path_copy = tmp_path / "copy.rtdc"

with h5py.File(path_src) as src, h5py.File(path, "w") as dst:
write.copy_metadata(h5_src=src, h5_dst=dst)
dst["events/deform"] = src["events/deform"][:]
image = src["events/image"][:]
for ii, (name, bpath) in enumerate(zip(
names, [str(path_src), str(tmp_path / "missing.rtdc")])):
bn_dict = {"type": "file",
"format": "hdf5",
"paths": [bpath],
"features": ["image"],
}
if name != "omitted":
bn_dict["name"] = name
dst.require_group("basins").create_dataset(
f"basin_{ii}",
data=[ln.encode() for ln in
json.dumps(bn_dict, indent=2).split("\n")])

with read.HDF5Data(path) as hd:
assert len(hd.basins) == 2
assert np.all(hd["image"][:] == image)

with h5py.File(path) as src, h5py.File(path_copy, "w") as dst:
write.copy_metadata(h5_src=src, h5_dst=dst)
write.copy_basins(h5_src=src, h5_dst=dst)

with read.HDF5Data(path_copy) as hd:
assert len(hd.basins) == 2


def test_basin_no_inception():
"""We do not support basin inception in dcnum

Expand Down
Loading