earth-mover / community

Community support for Arraylake
7 stars 0 forks source link

Zarr experimental v3 api #5

Closed RichardScottOZ closed 11 months ago

RichardScottOZ commented 11 months ago

zarr 2.16.0 pyhd8ed1ab_0 conda-forge

import xarray as xr
import os
os.environ["ZARR_V3_EXPERIMENTAL_API"] = "1"

client = al.Client()

repo_name = "OZ-Minerals/private-beta-email"

# Open your data using Xarray
# ds = xr.open_dataset(...)
# or use the tutorial dataset (requires the 'pooch' package)
ds = xr.tutorial.open_dataset("air_temperature")
# Open your existing repository
repo = client.get_or_create_repo(repo_name)
repo.checkout()
# Write your dataset to Arraylake
ds.to_zarr(repo.store, group="mygroup", zarr_version=3, mode="w")
#ds.to_zarr(repo.store, group="mygroup", mode="w")
# Make your first commit.
repo.commit("my first commit!")

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[5], line 18
     16 repo.checkout()
     17 # Write your dataset to Arraylake
---> 18 ds.to_zarr(repo.store, group="mygroup", zarr_version=3, mode="w")
     19 #ds.to_zarr(repo.store, group="mygroup", mode="w")
     20 # Make your first commit.
     21 repo.commit("my first commit!")

File ~\anaconda3\envs\pyvistaxarray\lib\site-packages\xarray\core\dataset.py:2099, in Dataset.to_zarr(self, store, chunk_store, mode, synchronizer, group, encoding, compute, consolidated, append_dim, region, safe_chunks, storage_options, zarr_version)
   1982 """Write dataset contents to a zarr group.
   1983 
   1984 Zarr chunks are determined in the following way:
   (...)
   2095     The I/O user guide, with more details and examples.
   2096 """
   2097 from xarray.backends.api import to_zarr
-> 2099 return to_zarr(  # type: ignore
   2100     self,
   2101     store=store,
   2102     chunk_store=chunk_store,
   2103     storage_options=storage_options,
   2104     mode=mode,
   2105     synchronizer=synchronizer,
   2106     group=group,
   2107     encoding=encoding,
   2108     compute=compute,
   2109     consolidated=consolidated,
   2110     append_dim=append_dim,
   2111     region=region,
   2112     safe_chunks=safe_chunks,
   2113     zarr_version=zarr_version,
   2114 )

File ~\anaconda3\envs\pyvistaxarray\lib\site-packages\xarray\backends\api.py:1629, in to_zarr(dataset, store, chunk_store, mode, synchronizer, group, encoding, compute, consolidated, append_dim, region, safe_chunks, storage_options, zarr_version)
   1627     already_consolidated = False
   1628     consolidate_on_close = consolidated or consolidated is None
-> 1629 zstore = backends.ZarrStore.open_group(
   1630     store=mapper,
   1631     mode=mode,
   1632     synchronizer=synchronizer,
   1633     group=group,
   1634     consolidated=already_consolidated,
   1635     consolidate_on_close=consolidate_on_close,
   1636     chunk_store=chunk_mapper,
   1637     append_dim=append_dim,
   1638     write_region=region,
   1639     safe_chunks=safe_chunks,
   1640     stacklevel=4,  # for Dataset.to_zarr()
   1641     zarr_version=zarr_version,
   1642 )
   1644 if mode in ["a", "r+"]:
   1645     _validate_datatypes_for_zarr_append(zstore, dataset)

File ~\anaconda3\envs\pyvistaxarray\lib\site-packages\xarray\backends\zarr.py:425, in ZarrStore.open_group(cls, store, mode, synchronizer, group, consolidated, consolidate_on_close, chunk_store, storage_options, append_dim, write_region, safe_chunks, stacklevel, zarr_version)
    423     zarr_group = zarr.open_consolidated(store, **open_kwargs)
    424 else:
--> 425     zarr_group = zarr.open_group(store, **open_kwargs)
    426 return cls(
    427     zarr_group,
    428     mode,
   (...)
    432     safe_chunks,
    433 )

File ~\anaconda3\envs\pyvistaxarray\lib\site-packages\zarr\hierarchy.py:1501, in open_group(store, mode, cache_attrs, synchronizer, path, chunk_store, storage_options, zarr_version, meta_array)
   1450 """Open a group using file-mode-like semantics.
   1451 
   1452 Parameters
   (...)
   1497 
   1498 """
   1500 # handle polymorphic store arg
-> 1501 store = _normalize_store_arg(
   1502     store, storage_options=storage_options, mode=mode, zarr_version=zarr_version
   1503 )
   1504 if zarr_version is None:
   1505     zarr_version = getattr(store, "_store_version", DEFAULT_ZARR_VERSION)

File ~\anaconda3\envs\pyvistaxarray\lib\site-packages\zarr\hierarchy.py:1346, in _normalize_store_arg(store, storage_options, mode, zarr_version)
   1343     zarr_version = getattr(store, "_store_version", DEFAULT_ZARR_VERSION)
   1345 if zarr_version != 2:
-> 1346     assert_zarr_v3_api_available()
   1348 if store is None:
   1349     return MemoryStore() if zarr_version == 2 else MemoryStoreV3()

File ~\anaconda3\envs\pyvistaxarray\lib\site-packages\zarr\_storage\store.py:29, in assert_zarr_v3_api_available()
     27 def assert_zarr_v3_api_available():
     28     if not v3_api_available:
---> 29         raise NotImplementedError(
     30             "# V3 reading and writing is experimental! To enable support, set:\n"
     31             "ZARR_V3_EXPERIMENTAL_API=1"
     32         )

NotImplementedError: # V3 reading and writing is experimental! To enable support, set:
ZARR_V3_EXPERIMENTAL_API=1
jhamman commented 11 months ago

Thanks for flagging this issue @RichardScottOZ. You'll need to make sure ZARR_V3_EXPERIMENTAL_API is set before you import Zarr (or arraylake?). I tend to do this outside of python but if you are careful, you can do this inside a python interpreter too.

import os
os.environ["ZARR_V3_EXPERIMENTAL_API"] = "1"

import arraylake

...
RichardScottOZ commented 11 months ago

ok, so environment import first, got it - maybe just make a note in the example on the website?

that seems ok I think now