Skip to content

Commit

Permalink
fix: ValueError when exporting data from basin-mapped dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed May 31, 2024
1 parent 436e707 commit 48deb8d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.59.1
- fix: ValueError when exporting data from basin-mapped dataset
0.59.0
- feat: support basins with blown indices
- enh: increase verbosity when failing to resolve basins
Expand Down
2 changes: 1 addition & 1 deletion dclab/rtdc_dataset/feat_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def __getitem__(self, index):
return self.feat_obj[self.basinmap[index]]
elif not self.is_scalar:
# image, mask, etc
if index == slice(None):
if isinstance(index, slice) and index == slice(None):
indices = self.basinmap
else:
indices = self.basinmap[index]
Expand Down
41 changes: 41 additions & 0 deletions tests/test_rtdc_feat_basin_mapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,47 @@ def test_basin_mapped(basinmap):
assert np.all(ds1["mask"] == ds0["mask"][:][basinmap])


@pytest.mark.parametrize("basinmap", [
[1, 3, 4], # very simple case
[1, 1, 1, 2], # not trivial, not realizable with hierarchy children
])
def test_basin_mapped_export(basinmap):
path = retrieve_data("fmt-hdf5_image-mask-blood_2021.zip")
with h5py.File(path, "a") as h5:
# delete circularity to avoid ancillary feature computation in this
# test.
del h5["events"]["circ"]

path_out = path.with_name("level1.rtdc")
basinmap = np.array(basinmap, dtype=np.uint64)

# create basin
with dclab.new_dataset(path) as ds0, dclab.RTDCWriter(path_out) as hw1:
hw1.store_metadata(ds0.config.as_dict(pop_filtering=True))
hw1.store_basin(basin_name="level1",
basin_type="file",
basin_format="hdf5",
basin_locs=[path],
basin_map=basinmap
)

path_export = path.with_name("export.rtdc")
with dclab.new_dataset(path_out) as ds1:
ds1.filter.manual[:] = False
ds1.filter.manual[:2] = True
ds1.apply_filter()
ds1.export.hdf5(
path_export,
features=["deform", "image", "mask"]
)

# Export data
with dclab.new_dataset(path) as ds0, dclab.new_dataset(path_export) as ds1:
assert np.all(ds1["deform"] == ds0["deform"][basinmap[:2]])
assert np.all(ds1["image"] == ds0["image"][:][basinmap[:2]])
assert np.all(ds1["mask"] == ds0["mask"][:][basinmap[:2]])


def test_error_when_basinmap_not_given():
"""This is a test for when the basinmap feature for mapping is missing
Expand Down

0 comments on commit 48deb8d

Please sign in to comment.