From 0fc495a57595c454923ba1efadfe5bd4a3c77db2 Mon Sep 17 00:00:00 2001 From: Eric Jelli <36883188+erjel@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:39:09 +0200 Subject: [PATCH] Fix merging annotations with compressed fallback layers (#1191) * tests: Add failing test * bugfix: Extend output layer bounding box to prevent concurrent writes to properties * doc: Add changelog message * rf: Change formatting --------- Co-authored-by: Norman Rzepka Co-authored-by: Tom Herold --- webknossos/Changelog.md | 1 + webknossos/tests/test_cli.py | 12 ++++++++++-- webknossos/webknossos/dataset/mag_view.py | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/webknossos/Changelog.md b/webknossos/Changelog.md index d42e93b11..913ec4ba8 100644 --- a/webknossos/Changelog.md +++ b/webknossos/Changelog.md @@ -20,6 +20,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section ### Changed ### Fixed +- Fixed an issue with merging annotations with compressed fallback layers. ## [0.15.6](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.15.6) - 2024-10-16 diff --git a/webknossos/tests/test_cli.py b/webknossos/tests/test_cli.py index afe18d2ff..9deed9561 100644 --- a/webknossos/tests/test_cli.py +++ b/webknossos/tests/test_cli.py @@ -542,7 +542,10 @@ def test_export_tiff_stack_tiles_per_dimension(tmp_path: Path) -> None: ) -def test_merge_fallback_no_fallback_layer(tmp_path: Path) -> None: +@pytest.mark.parametrize("use_compression", [True, False]) +def test_merge_fallback_no_fallback_layer( + tmp_path: Path, use_compression: bool +) -> None: from zipfile import ZIP_DEFLATED, ZipFile from zlib import Z_BEST_SPEED @@ -558,7 +561,12 @@ def test_merge_fallback_no_fallback_layer(tmp_path: Path) -> None: SEGMENTATION_CATEGORY, dtype_per_channel=fallback_layer_data.dtype, ) - .add_mag(1, chunk_shape=(32,) * 3, chunks_per_shard=(1,) * 3) + .add_mag( + 1, + chunk_shape=(32,) * 3, + chunks_per_shard=(1,) * 3, + compress=use_compression, + ) ) fallback_mag.write(absolute_offset=(0,) * 3, data=fallback_layer_data) diff --git a/webknossos/webknossos/dataset/mag_view.py b/webknossos/webknossos/dataset/mag_view.py index 0c870c500..78b8931b1 100644 --- a/webknossos/webknossos/dataset/mag_view.py +++ b/webknossos/webknossos/dataset/mag_view.py @@ -491,6 +491,13 @@ def merge_with_view( bboxes, Mag(self.info.shard_shape * self.mag) ) + new_bbox = self.bounding_box + for shard_bbox in shards_with_bboxes.keys(): + new_bbox = new_bbox.extended_by(shard_bbox) + + logging.info(f"Set mag layer bounding box to {new_bbox}") + self.layer.bounding_box = new_bbox + args = [(other, shard, bboxes) for shard, bboxes in shards_with_bboxes.items()] logging.info("Merging %s shards.", len(args))