Skip to content

Commit 802ff2b

Browse files
add MagView.get_views_on_disk() (#621)
* add deprecation note * add MagView.get_views_on_disk() * add changelog entry * Update webknossos/webknossos/skeleton/__init__.py Co-authored-by: Philipp Otto <[email protected]> Co-authored-by: Philipp Otto <[email protected]>
1 parent 30ec42e commit 802ff2b

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

webknossos/Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ For upgrade instructions, please check the respective *Breaking Changes* section
3434
* `Annotation`s can now be initialized from their attributes and an optional skeleton.
3535
* New methods on `Annotation`: `upload`, `add_volume_layer`, `delete_volume_layer`
3636
* `Annotation.load()` and `annoation.save()` also works with `.nml` files.
37+
- Added `MagView.get_views_on_disk()` as a shortcut to turning `get_bounding_boxes_on_disk` into views.
38+
[#621](https://github.com/scalableminds/webknossos-libs/pull/621)
3739

3840
### Changed
3941

webknossos/webknossos/annotation/annotation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ def export_volume_layer_to_dataset(
571571

572572
if largest_segment_id is None:
573573
max_value = max(
574-
best_mag_view.read(absolute_bounding_box=bbox).max()
575-
for bbox in best_mag_view.get_bounding_boxes_on_disk()
574+
view.read().max()
575+
for view in best_mag_view.get_views_on_disk(read_only=True)
576576
)
577577
layer.largest_segment_id = int(max_value)
578578
else:

webknossos/webknossos/dataset/mag_view.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55
from argparse import Namespace
66
from pathlib import Path
7-
from typing import TYPE_CHECKING, Generator, Optional, Union
7+
from typing import TYPE_CHECKING, Iterator, Optional, Union
88
from uuid import uuid4
99

1010
import numpy as np
@@ -227,7 +227,7 @@ def get_view(
227227

228228
def get_bounding_boxes_on_disk(
229229
self,
230-
) -> Generator[BoundingBox, None, None]:
230+
) -> Iterator[BoundingBox]:
231231
"""
232232
Returns a Mag(1) bounding box for each file on disk.
233233
@@ -242,6 +242,18 @@ def get_bounding_boxes_on_disk(
242242

243243
yield BoundingBox(cube_offset, cube_size).from_mag_to_mag1(self._mag)
244244

245+
def get_views_on_disk(
246+
self,
247+
read_only: Optional[bool] = None,
248+
) -> Iterator[View]:
249+
"""
250+
Yields a view for each file on disk, which can be used for efficient parallelization.
251+
"""
252+
for bbox in self.get_bounding_boxes_on_disk():
253+
yield self.get_view(
254+
absolute_offset=bbox.topleft, size=bbox.size, read_only=read_only
255+
)
256+
245257
def compress(
246258
self,
247259
target_path: Optional[Union[str, Path]] = None,

webknossos/webknossos/skeleton/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
def open_nml(file_path: Union[PathLike, str]) -> Skeleton:
12+
"""open_nml is deprecated, please use Skeleton.load instead."""
1213
warnings.warn(
1314
"[DEPRECATION] open_nml is deprecated, please use Skeleton.load instead."
1415
)

0 commit comments

Comments
 (0)