create_smart_array¶
- create_smart_array(shape, dtype, memory_threshold, name, zarr_path, chunks='auto')[source]¶
Allocate a NumPy or Zarr array depending on available memory and a threshold.
This function estimates the memory required for an array of the given shape and dtype. If the required memory is below the allowed fraction of available RAM (defined by memory_threshold), a NumPy array is created in memory. Otherwise, a Zarr array is created on disk. This enables seamless scaling between in-memory and out-of-core workflows.
- Parameters:
shape (tuple(int,...)) – Shape of the array to allocate, e.g., (height, width, channels).
dtype (np.dtype | str) – NumPy dtype or dtype string for the array, e.g., np.float32 or “float32”.
memory_threshold (float) – Fraction of available RAM allowed for this allocation. Must be between 0.0 and 100. A value of 100 allows using all available RAM; 0.0 forces Zarr allocation.
name (str | None) – Name for the zarr dataset.
zarr_path (str | None) – Filesystem path where the Zarr array will be created if needed.
chunks (tuple(int,...) | None) – Chunk shape for the Zarr array. If None, a reasonable default is chosen based on the array shape.
- Returns:
The allocated array (NumPy or Zarr).
- Return type:
np.ndarray | zarr.core.Array