Skip to content

Commit 926004c

Browse files
committed
use fs-based copy
1 parent 5900684 commit 926004c

File tree

2 files changed

+57
-17
lines changed

2 files changed

+57
-17
lines changed

webknossos/webknossos/dataset/_array.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def from_array_info(cls, array_info: ArrayInfo) -> "Zarr3ArrayInfo":
133133
axis_order=array_info.axis_order,
134134
)
135135

136+
@property
137+
def zarr3_config(self) -> "Zarr3Config":
138+
return Zarr3Config(
139+
codecs=self.codecs,
140+
chunk_key_encoding=self.chunk_key_encoding,
141+
)
142+
136143

137144
@dataclass(frozen=True)
138145
class Zarr3Config:

webknossos/webknossos/dataset/dataset.py

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
)
4141
from ..geometry.mag import MagLike
4242
from ..geometry.nd_bounding_box import derive_nd_bounding_box_from_shape
43-
from ._array import ArrayException, ArrayInfo, BaseArray
43+
from ._array import ArrayException, ArrayInfo, BaseArray, Zarr3ArrayInfo, Zarr3Config
4444
from ._metadata import DatasetMetadata
4545
from ._utils import pims_images
4646
from .defaults import (
@@ -522,7 +522,7 @@ def announce_manual_upload(
522522
datastore_url = _cached_get_upload_datastore(context)
523523
datastore_api = context.get_datastore_api_client(datastore_url)
524524
response = datastore_api.dataset_reserve_manual_upload(
525-
dataset_announce, token=token
525+
dataset_announce=dataset_announce, token=token
526526
)
527527
return response.new_dataset_id, response.directory_name
528528

@@ -563,7 +563,9 @@ def trigger_reload_in_datastore(
563563
context = _get_context()
564564
upload_url = datastore_url or _cached_get_upload_datastore(context)
565565
datastore_api = context.get_datastore_api_client(upload_url)
566-
datastore_api.dataset_trigger_reload(organization, dataset_name, token=token)
566+
datastore_api.dataset_trigger_reload(
567+
organization_id=organization, dataset_name=dataset_name, token=token
568+
)
567569

568570
@classmethod
569571
def trigger_dataset_import(
@@ -2235,7 +2237,7 @@ def add_layer_as_copy(
22352237
shard_shape: Vec3IntLike | int | None = None,
22362238
chunks_per_shard: Vec3IntLike | int | None = None,
22372239
data_format: str | DataFormat | None = None,
2238-
compress: bool | None = None,
2240+
compress: bool | Zarr3Config | None = None,
22392241
exists_ok: bool = False,
22402242
executor: Executor | None = None,
22412243
with_attachments: bool = True,
@@ -2315,17 +2317,48 @@ def add_layer_as_copy(
23152317
f"Copying {mag_view.layer.name}/{mag_view.mag.to_layer_name()}"
23162318
)
23172319

2318-
layer.add_mag_as_copy(
2319-
mag_view,
2320-
extend_layer_bounding_box=False,
2321-
chunk_shape=chunk_shape,
2322-
shard_shape=shard_shape,
2323-
chunks_per_shard=chunks_per_shard,
2324-
compress=compress,
2325-
exists_ok=exists_ok,
2326-
executor=executor,
2327-
progress_desc=progress_desc,
2328-
)
2320+
can_use_fs_copy = True
2321+
if (
2322+
(chunk_shape is not None and chunk_shape != mag_view.info.chunk_shape)
2323+
or (
2324+
shard_shape is not None and shard_shape != mag_view.info.shard_shape
2325+
)
2326+
or (
2327+
chunks_per_shard is not None
2328+
and chunks_per_shard != mag_view.info.chunks_per_shard
2329+
)
2330+
or (
2331+
data_format is not None and data_format != mag_view.info.data_format
2332+
)
2333+
or (
2334+
compress is not None
2335+
and (
2336+
isinstance(compress, Zarr3Config)
2337+
and isinstance(mag_view.info, Zarr3ArrayInfo)
2338+
and compress != mag_view.info.zarr3_config
2339+
)
2340+
or compress != mag_view.info.compression_mode
2341+
)
2342+
):
2343+
can_use_fs_copy = False
2344+
2345+
if can_use_fs_copy:
2346+
layer.add_fs_copy_mag(
2347+
mag_view,
2348+
extend_layer_bounding_box=False,
2349+
)
2350+
else:
2351+
layer.add_mag_as_copy(
2352+
mag_view,
2353+
extend_layer_bounding_box=False,
2354+
chunk_shape=chunk_shape,
2355+
shard_shape=shard_shape,
2356+
chunks_per_shard=chunks_per_shard,
2357+
compress=compress,
2358+
exists_ok=exists_ok,
2359+
executor=executor,
2360+
progress_desc=progress_desc,
2361+
)
23292362

23302363
if (
23312364
with_attachments
@@ -2743,7 +2776,7 @@ def fs_copy_dataset(
27432776

27442777
if any(layer.data_format == DataFormat.WKW for layer in self.layers.values()):
27452778
assert is_fs_path(new_dataset_path), (
2746-
"Cannot create WKW layers in remote datasets. Use explicit `data_format='zarr3'`."
2779+
"Cannot create WKW layers in remote datasets. Use `Dataset.copy_dataset` with `data_format='zarr3'`."
27472780
)
27482781

27492782
new_dataset = Dataset(
@@ -3579,7 +3612,7 @@ def download_mesh(
35793612
"When you attempt to download a mesh without a tracing_id, the layer_name must be set."
35803613
)
35813614
mesh_download = datastore.download_mesh(
3582-
mesh_info,
3615+
mesh_info=mesh_info,
35833616
organization_id=organization_id or context.organization_id,
35843617
directory_name=directory_name,
35853618
layer_name=layer_name,

0 commit comments

Comments
 (0)