-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
expose zarr caching from xarray #2812
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
Comments
Or should we use xarray's own caching mechanism? |
I have created two PRs which attempt to provide zarr caching in different ways. I would welcome some advice on which one is a better approach. |
Hi @rabernat, I looked at your PRs, and they seem to haven't gotten much attention. I tried using a store with LRUCache in For our use cases in https://github.com/TGSAI/mdio-python, we usually want to use any form of LRUCache (it doesn't have to be Zarr's necessarily).
|
I have successfully used the Zarr LRU cache with Xarray. You just have to initialize the Store object outside of Xarray and then pass it to Have you tried that? |
This would be good to document! |
@rabernat, yes, I have tried that like this: from zarr.storage import FSStore, LRUStoreCache
import xarray as xr
path = "gs://prefix/object.zarr"
store_nocache = FSStore(path)
store_cached = LRUStoreCache(store_nocache, max_size=2**30)
ds = xr.open_zarr(store_cached) When I read the same data twice, it still downloads. Am I doing something wrong? While I wait for a response, I will try it again and update if it works, but the last time I checked, it didn't. Note to self: I also need to check it with Zarr backend and Dask backend. |
@tasansal a PR would be very welcome! |
Glad you got it working! So you're saying it does not work with
Yes, I think I experienced that as well. I think the entire cache is serialized and passed around between workers. |
I couldn't get |
@dcherian, I will start a PR. Where do you think this belongs in the docs? Some places I can think of: |
docs.xarray.dev/en/stable/user-guide/io.html seems great to me. |
I am working on a project where caching would be highly desirable. Version 3.0 of Zarr-Python does not contain LRUStoreCache anymore. Any idea on how caching to disk could now be implemented? |
Zarr has its own internal mechanism for caching, described here:
However, this capability is currently inaccessible from xarray.
I propose to add a new keyword
cache=True/False
toopen_zarr
which wraps the store in anLRUStoreCache
.The text was updated successfully, but these errors were encountered: