Skip to content

Commit

Permalink
Fix merging annotations with compressed fallback layers (#1191)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Tom Herold <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent 4a21fbd commit 0fc495a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions webknossos/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions webknossos/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions webknossos/webknossos/dataset/mag_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 0fc495a

Please sign in to comment.