|
1 | | -from pathlib import Path |
2 | 1 | from typing import Any, Literal |
3 | 2 |
|
4 | 3 | import dask.array as da |
5 | 4 | import numpy as np |
6 | 5 | import zarr |
| 6 | +import zarr.storage |
7 | 7 | from ome_zarr.format import Format |
8 | 8 | from ome_zarr.io import ZarrLocation |
9 | 9 | from ome_zarr.reader import Label, Multiscales, Node, Reader |
|
15 | 15 | from ome_zarr.writer import write_multiscale_labels as write_multiscale_labels_ngff |
16 | 16 | from xarray import DataArray, Dataset, DataTree |
17 | 17 |
|
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 |
28 | 20 | from spatialdata._utils import get_pyramid_levels |
29 | 21 | from spatialdata.models._utils import get_channel_names |
30 | 22 | from spatialdata.models.models import ATTRS_KEY |
|
36 | 28 | ) |
37 | 29 |
|
38 | 30 |
|
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) |
41 | 33 | assert raster_type in ["image", "labels"] |
42 | 34 |
|
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) |
45 | 37 | # old spatialdata datasets don't have format metadata for raster elements; this line ensure backwards compatibility, |
46 | 38 | # interpreting the lack of such information as the presence of the format v01 |
47 | 39 | format = RasterFormatV01() if version is None else RasterFormats[version] |
48 | | - f.store.close() |
| 40 | + store.close() |
49 | 41 |
|
50 | 42 | nodes: list[Node] = [] |
51 | 43 | image_loc = ZarrLocation(store) |
|
0 commit comments