Skip to content

Commit 7961f16

Browse files
committed
add optional caching in open_zarr
1 parent 4426fd7 commit 7961f16

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/anemoi/datasets/data/stores.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __contains__(self, key):
102102
return key in self.store
103103

104104

105-
def open_zarr(path, dont_fail=False):
105+
def open_zarr(path, dont_fail=False, cache=None):
106106
try:
107107
store = path
108108

@@ -117,6 +117,9 @@ def open_zarr(path, dont_fail=False):
117117
store = zarr.storage.DirectoryStore(store)
118118
store = DebugStore(store)
119119

120+
if cache is not None:
121+
store = zarr.LRUStoreCache(store, max_size=cache)
122+
120123
return zarr.convenience.open(store, "r")
121124
except zarr.errors.PathNotFoundError:
122125
if not dont_fail:

0 commit comments

Comments
 (0)