Skip to content

Commit 0a5458d

Browse files
authored
Dataset api read at a specific bounding box (#347)
* add function to read at a specific bounding box * update changelog
1 parent a144b3b commit 0a5458d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Changelog.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1212
### Breaking Changes in Config & CLI
1313

1414
### Added
15-
- Added `add_copy_layer()` to `wkcuber.api.dataset.Dataset` to copy the layer of a different dataset. [#345](https://github.com/scalableminds/webknossos-cuber/pull/345)
1615

1716
### Changed
1817

1918
### Fixed
2019

20+
## [0.8.1](https://github.com/scalableminds/webknossos-cuber/releases/tag/v0.8.1) - 2021-07-22
21+
[Commits](https://github.com/scalableminds/webknossos-cuber/compare/v0.8.0...v0.8.1)
22+
23+
### Breaking Changes in Config & CLI
24+
25+
### Added
26+
- Added `add_copy_layer()` to `wkcuber.api.dataset.Dataset` to copy the layer of a different dataset. [#345](https://github.com/scalableminds/webknossos-cuber/pull/345)
27+
- Added `View.read_bbox()` which takes only a single bounding box as parameter (instead of an offset and size). [#347](https://github.com/scalableminds/webknossos-cuber/pull/347)
28+
29+
### Changed
30+
31+
### Fixed
2132

2233
## [0.8.0](https://github.com/scalableminds/webknossos-cuber/releases/tag/v0.8.0) - 2021-07-16
2334
[Commits](https://github.com/scalableminds/webknossos-cuber/compare/v0.7.0...v0.8.0)

tests/test_dataset.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,21 @@ def test_dataset_name(tmp_path: Path) -> None:
14421442
assert ds2.name == "very important dataset"
14431443

14441444

1445+
def test_read_bbox(tmp_path: Path) -> None:
1446+
ds = Dataset.create(tmp_path, scale=(2, 2, 1))
1447+
layer = ds.add_layer("color", LayerCategories.COLOR_TYPE)
1448+
mag = layer.add_mag(1)
1449+
mag.write(
1450+
offset=(10, 20, 30), data=(np.random.rand(50, 60, 70) * 255).astype(np.uint8)
1451+
)
1452+
1453+
assert np.array_equal(mag.read(), mag.read_bbox())
1454+
assert np.array_equal(
1455+
mag.read(offset=(20, 30, 40), size=(40, 50, 60)),
1456+
mag.read_bbox(BoundingBox(topleft=(20, 30, 40), size=(40, 50, 60))),
1457+
)
1458+
1459+
14451460
def test_add_copy_layer(tmp_path: Path) -> None:
14461461
ds = Dataset.create(tmp_path / "ds", scale=(2, 2, 1))
14471462

@@ -1462,7 +1477,7 @@ def test_add_copy_layer(tmp_path: Path) -> None:
14621477
assert color_layer.mags.keys() == original_color_layer.mags.keys()
14631478
assert len(color_layer.mags.keys()) >= 1
14641479
for mag in color_layer.mags.keys():
1465-
np.array_equal(
1480+
assert np.array_equal(
14661481
color_layer.get_mag(mag).read(), original_color_layer.get_mag(mag).read()
14671482
)
14681483
# Test if the copied layer contains actual data

wkcuber/api/view.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ def read(
163163
cast(Tuple[int, int, int], absolute_offset), size
164164
)
165165

166+
def read_bbox(self, bounding_box: Optional[BoundingBox] = None) -> np.array:
167+
"""
168+
The user can specify the `bounding_box` of the requested data.
169+
See `read()` for more details.
170+
"""
171+
if bounding_box is None:
172+
return self.read()
173+
else:
174+
return self.read(bounding_box.topleft, bounding_box.size)
175+
166176
def _read_without_checks(
167177
self,
168178
absolute_offset: Tuple[int, int, int],

0 commit comments

Comments
 (0)