Skip to content

Commit a3611b6

Browse files
authored
fixes compression of downsampled mags (#667)
* fixes compression of downsampled mags * changelog * changelog * types
1 parent bf5c801 commit a3611b6

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

webknossos/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1818
### Added
1919

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

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

2426

2527
## [0.9.12](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.9.12) - 2022-03-18

webknossos/tests/test_dataset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,3 +2155,19 @@ def test_warn_outdated_properties(tmp_path: Path) -> None:
21552155
# Changing ds1 should raise a warning, since ds1
21562156
# does not know about the change in ds2
21572157
ds1.add_layer("color", COLOR_CATEGORY)
2158+
2159+
2160+
def test_can_compress_mag8(tmp_path: Path) -> None:
2161+
ds = Dataset(tmp_path / "ds", scale=(1, 1, 1))
2162+
2163+
layer = ds.add_layer("color", COLOR_CATEGORY)
2164+
layer.bounding_box = BoundingBox((0, 0, 0), (12240, 12240, 685))
2165+
for mag in ["1", "2-2-1", "4-4-1", "8-8-2"]:
2166+
layer.add_mag(mag)
2167+
2168+
assert layer.bounding_box == BoundingBox((0, 0, 0), (12240, 12240, 685))
2169+
2170+
mag_view = layer.get_mag("8-8-2")
2171+
data_to_write = (np.random.rand(1, 10, 10, 10) * 255).astype(np.uint8)
2172+
mag_view.write(data_to_write, absolute_offset=(11264, 11264, 0))
2173+
mag_view.compress()

webknossos/webknossos/dataset/mag_view.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ def compress(
269269

270270
from webknossos.dataset.dataset import Dataset
271271

272+
if target_path is None and self._is_compressed():
273+
logging.info(f"Mag {self.name} is already compressed")
274+
return
275+
272276
if target_path is not None:
273277
target_path = Path(target_path)
274278

@@ -308,6 +312,7 @@ def compress(
308312
for bbox in self.get_bounding_boxes_on_disk():
309313
bbox = bbox.intersected_with(self.layer.bounding_box, dont_assert=True)
310314
if not bbox.is_empty():
315+
bbox = bbox.align_with_mag(self.mag, ceil=True)
311316
source_view = self.get_view(
312317
absolute_offset=bbox.topleft, size=bbox.size
313318
)

0 commit comments

Comments
 (0)