Skip to content

Commit 7e497ff

Browse files
committed
read image element from base store
1 parent 0207ff7 commit 7e497ff

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/spatialdata/_io/io_raster.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from pathlib import Path
21
from typing import Any, Literal
32

43
import dask.array as da
54
import numpy as np
65
import zarr
6+
import zarr.storage
77
from ome_zarr.format import Format
88
from ome_zarr.io import ZarrLocation
99
from ome_zarr.reader import Label, Multiscales, Node, Reader
@@ -15,16 +15,8 @@
1515
from ome_zarr.writer import write_multiscale_labels as write_multiscale_labels_ngff
1616
from xarray import DataArray, Dataset, DataTree
1717

18-
from spatialdata._io._utils import (
19-
_get_transformations_from_ngff_dict,
20-
overwrite_coordinate_transformations_raster,
21-
)
22-
from spatialdata._io.format import (
23-
CurrentRasterFormat,
24-
RasterFormats,
25-
RasterFormatV01,
26-
_parse_version,
27-
)
18+
from spatialdata._io._utils import _get_transformations_from_ngff_dict, overwrite_coordinate_transformations_raster
19+
from spatialdata._io.format import CurrentRasterFormat, RasterFormats, RasterFormatV01, _parse_version
2820
from spatialdata._utils import get_pyramid_levels
2921
from spatialdata.models._utils import get_channel_names
3022
from spatialdata.models.models import ATTRS_KEY
@@ -36,16 +28,16 @@
3628
)
3729

3830

39-
def _read_multiscale(store: str | Path, raster_type: Literal["image", "labels"]) -> DataArray | DataTree:
40-
assert isinstance(store, str | Path)
31+
def _read_multiscale(store: zarr.storage.BaseStore, raster_type: Literal["image", "labels"]) -> DataArray | DataTree:
32+
assert isinstance(store, zarr.storage.BaseStore)
4133
assert raster_type in ["image", "labels"]
4234

43-
f = zarr.open(store, mode="r")
44-
version = _parse_version(f, expect_attrs_key=True)
35+
group = zarr.group(store=store)
36+
version = _parse_version(group, expect_attrs_key=True)
4537
# old spatialdata datasets don't have format metadata for raster elements; this line ensure backwards compatibility,
4638
# interpreting the lack of such information as the presence of the format v01
4739
format = RasterFormatV01() if version is None else RasterFormats[version]
48-
f.store.close()
40+
store.close()
4941

5042
nodes: list[Node] = []
5143
image_loc = ZarrLocation(store)

0 commit comments

Comments
 (0)