Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 93
Support for consolidated remote zarr#278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d8e0107b3fa292fe5e72a49745dc8d97cfd8346e2d027c64a63fb5eda7626fb5add8f42068ba5ef4dec7a580595cd56eb946202d6fe6bebe315c83b88a633daa4dceb0016c1bcf692307e1e57bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,13 +9,13 @@ | ||
| import zarr | ||
| from anndata import AnnData | ||
| from dask.dataframe import read_parquet | ||
| from dask.dataframe.core import DataFrame as DaskDataFrame | ||
| from dask.delayed import Delayed | ||
| from geopandas import GeoDataFrame | ||
| from multiscale_spatial_image.multiscale_spatial_image import MultiscaleSpatialImage | ||
| from ome_zarr.io import parse_url | ||
| from ome_zarr.types import JSONDict | ||
| from pyarrow.parquet import read_table | ||
| from spatial_image import SpatialImage | ||
| from spatialdata._io import ( | ||
| @@ -917,6 +917,7 @@ def write( | ||
| file_path: str | Path, | ||
| storage_options: JSONDict | list[JSONDict] | None = None, | ||
| overwrite: bool = False, | ||
| consolidate_metadata: bool = True, | ||
| ) -> None: | ||
| """Write the SpatialData object to Zarr.""" | ||
| if isinstance(file_path, str): | ||
| @@ -1052,6 +1053,12 @@ def write( | ||
| self.path = None | ||
| raise e | ||
| if consolidate_metadata: | ||
| # consolidate metadata to more easily support remote reading | ||
| # bug in zarr, 'zmetadata' is written instead of '.zmetadata' | ||
| # see discussion https://github.com/zarr-developers/zarr-python/issues/1121 | ||
| zarr.consolidate_metadata(store, metadata_key=".zmetadata") | ||
| # old code to support overwriting the backing file | ||
| # if target_path is not None: | ||
| # if os.path.isdir(file_path): | ||
| @@ -1133,10 +1140,24 @@ def table(self) -> None: | ||
| del root["table/table"] | ||
| @staticmethod | ||
| def read(file_path: str) -> SpatialData: | ||
| def read(file_path: str, selection: tuple[str] | None = None) -> SpatialData: | ||
| """ | ||
| Read a SpatialData object from a Zarr storage (on-disk or remote). | ||
| Parameters | ||
| ---------- | ||
| file_path | ||
| The path or URL to the Zarr storage. | ||
| selection | ||
| The elements to read (images, labels, points, shapes, table). If None, all elements are read. | ||
| Returns | ||
| ------- | ||
| The SpatialData object. | ||
| """ | ||
| from spatialdata import read_zarr | ||
| return read_zarr(file_path) | ||
| return read_zarr(file_path, selection=selection) | ||
| @property | ||
| def images(self) -> dict[str, SpatialImage | MultiscaleSpatialImage]: | ||
| @@ -1238,7 +1259,7 @@ def h(s: str) -> str: | ||
| assert isinstance(t, tuple) | ||
| assert len(t) == 1 | ||
| parquet_file = t[0] | ||
| table = read_table(parquet_file) | ||
| table = read_parquet(parquet_file) | ||
LucaMarconato marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| length = len(table) | ||
| else: | ||
| # length = len(v) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import os | ||
| from collections.abc import MutableMapping | ||
| from pathlib import Path | ||
| from typing import Union | ||
| @@ -29,8 +30,10 @@ def _read_points( | ||
| assert isinstance(store, (str, Path)) | ||
| f = zarr.open(store, mode="r") | ||
| path = Path(f._store.path) / f.path / "points.parquet" | ||
| table = read_parquet(path) | ||
| path = os.path.join(f._store.path, f.path, "points.parquet") | ||
| # cache on remote file needed for parquet reader to work | ||
| # TODO: allow reading in the metadata without caching all the data | ||
| table = read_parquet("simplecache::" + path if "http" in path else path) | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. googled this cause i didn't know what it should do and found this option catalyst-cooperative/pudl#1496 (comment) and intake/intake-parquet#18 (comment) , maybe better? Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we would need to benchmark that. I'd do that in a follow up PR. @berombau WDYT? | ||
| assert isinstance(table, DaskDataFrame) | ||
| transformations = _get_transformations_from_ngff_dict(f.attrs.asdict()["coordinateTransformations"]) | ||
Uh oh!
There was an error while loading. Please reload this page.