hoops_ai.storage.OptStorage
- class hoops_ai.storage.OptStorage(store_path, compress_extension='.data')
Bases:
DataStorage- Handles storage and retrieval of data using Zarr, including:
Setting dimension names so that xarray can open each array.
Checking for NaNs before writing and before zipping.
Compressing into a .zip-based Zarr store.
metadata.json is cached in memory (no read+write on every save_metadata call) and written to disk only when flush_metadata() is called (e.g., close() / compress_store()).
file size tracking uses estimated size from input data (no os.walk/stat scanning).
- close()
Deletes all sibling DirectoryStores with same hash. Thread-safe. Also flushes metadata cache before copying/deleting.
- Return type:
None
- compress_store()
Copies data from the DirectoryStore to a ZipStore, verifying no NaNs exist in raw arrays. If everything is OK, removes the DirectoryStore. Returns size of generated zip.
- Return type:
- flush_metadata()
Write cached metadata to metadata.json once (if dirty).
- Return type:
None
- get_file_path(data_key)
Returns the direct path for a particular data key (sub-directory or array).
- get_group_for_array(array_name)
Determines which group an array belongs to based on the schema.
- get_schema()
Retrieves the schema definition for this storage instance.
- Returns:
The schema definition, or empty dict if no schema is set
- Return type:
- get_store_group()
- Return type:
StoreGroup
- load_data(data_key)
Loads data from the Zarr store by key.
- load_metadata(key)
Loads custom metadata by key from cached metadata.
- save_data(data_key, data)
Saves data (numpy arrays, lists, dicts, scalars, strings) under data_key. Overwrites if that key already exists.
- save_metadata(key, value)
Saves custom metadata (JSON-serializable) to cached metadata (no disk I/O here).