Skip to content

Commit

Permalink
fixes compression of downsampled mags (#667)
Browse files Browse the repository at this point in the history
* fixes compression of downsampled mags
* changelog
* changelog
* types
  • Loading branch information
normanrz authored Mar 23, 2022
1 parent bf5c801 commit a3611b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions webknossos/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ For upgrade instructions, please check the respective *Breaking Changes* section
### Added

### Changed
- `MagView.compress` now skips in-place compression of already compressed mags. [#667](https://github.com/scalableminds/webknossos-libs/pull/667)

### Fixed
- Fixed compression of downsampled mags for layers with arbitrary and potentially mag-unaligned bounding boxes. [#667](https://github.com/scalableminds/webknossos-libs/pull/667)


## [0.9.12](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.9.12) - 2022-03-18
Expand Down
16 changes: 16 additions & 0 deletions webknossos/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2155,3 +2155,19 @@ def test_warn_outdated_properties(tmp_path: Path) -> None:
# Changing ds1 should raise a warning, since ds1
# does not know about the change in ds2
ds1.add_layer("color", COLOR_CATEGORY)


def test_can_compress_mag8(tmp_path: Path) -> None:
ds = Dataset(tmp_path / "ds", scale=(1, 1, 1))

layer = ds.add_layer("color", COLOR_CATEGORY)
layer.bounding_box = BoundingBox((0, 0, 0), (12240, 12240, 685))
for mag in ["1", "2-2-1", "4-4-1", "8-8-2"]:
layer.add_mag(mag)

assert layer.bounding_box == BoundingBox((0, 0, 0), (12240, 12240, 685))

mag_view = layer.get_mag("8-8-2")
data_to_write = (np.random.rand(1, 10, 10, 10) * 255).astype(np.uint8)
mag_view.write(data_to_write, absolute_offset=(11264, 11264, 0))
mag_view.compress()
5 changes: 5 additions & 0 deletions webknossos/webknossos/dataset/mag_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ def compress(

from webknossos.dataset.dataset import Dataset

if target_path is None and self._is_compressed():
logging.info(f"Mag {self.name} is already compressed")
return

if target_path is not None:
target_path = Path(target_path)

Expand Down Expand Up @@ -308,6 +312,7 @@ def compress(
for bbox in self.get_bounding_boxes_on_disk():
bbox = bbox.intersected_with(self.layer.bounding_box, dont_assert=True)
if not bbox.is_empty():
bbox = bbox.align_with_mag(self.mag, ceil=True)
source_view = self.get_view(
absolute_offset=bbox.topleft, size=bbox.size
)
Expand Down

0 comments on commit a3611b6

Please sign in to comment.