Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 33fe1ee

Browse files
committed
Add debugging
1 parent a69d94b commit 33fe1ee

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

ecml_tools/data.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121

2222
LOG = logging.getLogger(__name__)
2323

24-
__all__ = ["open_dataset", "open_zarr"]
24+
__all__ = ["open_dataset", "open_zarr", "debug_zarr_loading"]
25+
26+
DEBUG_ZARR_LOADING = False
27+
28+
29+
def debug_zarr_loading(on_off):
30+
global DEBUG_ZARR_LOADING
31+
DEBUG_ZARR_LOADING = on_off
2532

2633

2734
class Dataset:
@@ -258,15 +265,36 @@ def __getitem__(self, key):
258265
return response["Body"].read()
259266

260267

268+
class DebugStore(ReadOnlyStore):
269+
def __init__(self, store):
270+
self.store = store
271+
272+
def __getitem__(self, key):
273+
print("GET", key)
274+
return self.store[key]
275+
276+
def __len__(self):
277+
return len(self.store)
278+
279+
def __iter__(self):
280+
return iter(self.store)
281+
282+
261283
def open_zarr(path):
262284
try:
263285
store = path
286+
264287
if store.startswith("http://") or store.startswith("https://"):
265288
store = HTTPStore(store)
266289

267290
elif store.startswith("s3://"):
268291
store = S3Store(store)
269292

293+
if DEBUG_ZARR_LOADING:
294+
if isinstance(store, str):
295+
store = zarr.storage.DirectoryStore(store)
296+
store = DebugStore(store)
297+
270298
return zarr.convenience.open(store, "r")
271299
except Exception:
272300
LOG.exception("Failed to open %r", path)

0 commit comments

Comments
 (0)