Skip to content

Commit d8a0572

Browse files
authored
Merge branch 'master' into copy-fs
2 parents 926004c + 16c1f8c commit d8a0572

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

cluster_tools/Changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/) `MAJOR.MIN
77
For upgrade instructions, please check the respective *Breaking Changes* sections.
88

99
## Unreleased
10-
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.9...HEAD)
10+
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.10...HEAD)
1111

1212
### Breaking Changes
1313

@@ -18,6 +18,10 @@ For upgrade instructions, please check the respective *Breaking Changes* section
1818
### Fixed
1919

2020

21+
## [2.4.10](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.4.10) - 2025-08-25
22+
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.9...v2.4.10)
23+
24+
2125
## [2.4.9](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.4.9) - 2025-08-11
2226
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.8...v2.4.9)
2327

webknossos/Changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/) `MAJOR.MIN
1010
For upgrade instructions, please check the respective _Breaking Changes_ sections.
1111

1212
## Unreleased
13-
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.9...HEAD)
13+
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.10...HEAD)
1414

1515
### Breaking Changes
1616

@@ -21,6 +21,13 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
2121
### Fixed
2222

2323

24+
## [2.4.10](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.4.10) - 2025-08-25
25+
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.9...v2.4.10)
26+
27+
### Added
28+
- Added support for remote datasets and annotations to `webknossos export-as-tiff`. [#1356](https://github.com/scalableminds/webknossos-libs/pull/1356)
29+
30+
2431
## [2.4.9](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.4.9) - 2025-08-11
2532
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v2.4.8...v2.4.9)
2633

webknossos/webknossos/cli/export_as_tiff.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
"""This module takes care of exporting tiff images."""
22

33
import logging
4+
import re
45
from argparse import Namespace
56
from functools import partial
67
from math import ceil
78
from multiprocessing import cpu_count
89
from pathlib import Path
910
from typing import Annotated, Any
11+
from urllib.parse import urlparse
1012

1113
import numpy as np
1214
import typer
1315
from PIL import Image
1416
from scipy.ndimage import zoom
17+
from upath import UPath
1518

19+
from ..annotation.annotation import _ANNOTATION_URL_REGEX, Annotation
20+
from ..client import webknossos_context
21+
from ..client._resolve_short_link import resolve_short_link
1622
from ..dataset import Dataset, MagView, View
23+
from ..dataset.dataset import _DATASET_DEPRECATED_URL_REGEX, _DATASET_URL_REGEX
1724
from ..dataset.defaults import DEFAULT_CHUNK_SHAPE
1825
from ..geometry import BoundingBox, Mag, Vec3Int
19-
from ..utils import get_executor_for_args, wait_and_ensure_success
26+
from ..utils import get_executor_for_args, is_fs_path, wait_and_ensure_success
2027
from ._utils import (
2128
DistributionStrategy,
2229
Vec2Int,
@@ -173,11 +180,9 @@ def export_tiff_stack(
173180
def main(
174181
*,
175182
source: Annotated[
176-
Any,
183+
str,
177184
typer.Argument(
178-
help="Path to your raw image data.",
179-
show_default=False,
180-
parser=parse_path,
185+
help="Path or URL to your raw image data.",
181186
),
182187
],
183188
target: Annotated[
@@ -258,10 +263,47 @@ def main(
258263
rich_help_panel="Executor options",
259264
),
260265
] = None,
266+
token: Annotated[
267+
str | None,
268+
typer.Option(
269+
help="Authentication token for WEBKNOSSOS instance "
270+
"(https://webknossos.org/auth/token).",
271+
rich_help_panel="WEBKNOSSOS context",
272+
envvar="WK_TOKEN",
273+
),
274+
] = None,
261275
) -> None:
262276
"""Export your WEBKNOSSOS dataset to TIFF image data."""
263277

264-
mag_view = Dataset.open(source).get_layer(layer_name).get_mag(mag)
278+
mag_view = None
279+
source_path = UPath(source)
280+
if not is_fs_path(source_path):
281+
url = resolve_short_link(source)
282+
parsed = urlparse(url)
283+
domain = f"{parsed.scheme}://{parsed.netloc}"
284+
285+
with webknossos_context(url=domain, token=token):
286+
if re.match(_DATASET_URL_REGEX, url) or re.match(
287+
_DATASET_DEPRECATED_URL_REGEX, url
288+
):
289+
mag_view = Dataset.open_remote(url).get_layer(layer_name).get_mag(mag)
290+
elif re.match(_ANNOTATION_URL_REGEX, url):
291+
mag_view = (
292+
Annotation.open_as_remote_dataset(annotation_id_or_url=url)
293+
.get_layer(layer_name)
294+
.get_mag(mag)
295+
)
296+
else:
297+
raise ValueError(
298+
"The provided URL does not lead to a dataset or annotation."
299+
)
300+
else:
301+
mag_view = Dataset.open(source_path).get_layer(layer_name).get_mag(mag)
302+
303+
if mag_view is None:
304+
raise ValueError(
305+
f"The provided source does not lead to a dataset or annotation. Got: {source}"
306+
)
265307

266308
bbox = BoundingBox.from_ndbbox(mag_view.bounding_box) if bbox is None else bbox
267309
bbox = bbox.align_with_mag(mag_view.mag)

webknossos/webknossos/dataset/dataset.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def _parse_remote(
627627
sharing_token: str | None = None,
628628
webknossos_url: str | None = None,
629629
dataset_id: str | None = None,
630-
) -> tuple[AbstractContextManager, str]:
630+
) -> tuple[AbstractContextManager, str, str | None]:
631631
"""Parses the given arguments to
632632
* context_manager that should be entered,
633633
* dataset_id,
@@ -699,10 +699,7 @@ def _parse_remote(
699699
+ "Please see https://docs.webknossos.org/api/webknossos/client/context.html to adapt the URL and token."
700700
)
701701
context_manager = webknossos_context(webknossos_url, None)
702-
return (
703-
context_manager,
704-
dataset_id,
705-
)
702+
return (context_manager, dataset_id, sharing_token)
706703

707704
@classmethod
708705
def open_remote(
@@ -740,10 +737,7 @@ def open_remote(
740737

741738
from ..client.context import _get_context
742739

743-
(
744-
context_manager,
745-
dataset_id,
746-
) = cls._parse_remote(
740+
(context_manager, dataset_id, sharing_token) = cls._parse_remote(
747741
dataset_name_or_url,
748742
organization_id,
749743
sharing_token,
@@ -801,10 +795,7 @@ def download(
801795

802796
from ..client._download_dataset import download_dataset
803797

804-
(
805-
context_manager,
806-
dataset_id,
807-
) = cls._parse_remote(
798+
(context_manager, dataset_id, sharing_token) = cls._parse_remote(
808799
dataset_name_or_url, organization_id, sharing_token, webknossos_url
809800
)
810801

0 commit comments

Comments
 (0)