lazyslice
Lazy transposing and slicing of h5py datasets and zarr arrays
lazyslice allows you to compose multiple slice and transpose operations on h5py datasets and zarr arrays without reading data until explicitly requested. This is useful for working with large datasets where you want to defer I/O operations.
Installation
pip install lazyslice
For zarr support:
pip install lazyslice[zarr]
Quick Start
from lazyslice import DatasetView
import h5py
# Open an HDF5 file and create a lazy view
with h5py.File('data.h5', 'r') as f:
view = DatasetView(f['dataset'])
# Chain lazy operations - no data is read yet
result = (view
.lazy_slice[1:40:2, :, 0:50:5]
.lazy_transpose([2, 0, 1])
.lazy_slice[8, 5:10])
# Data is only read when you access it
data = result[:] # or result.read()
Usage
h5py Datasets
from lazyslice import DatasetView
import h5py
with h5py.File('data.h5', 'r') as f:
dsetview = DatasetView(f['dataset'])
# Lazy slicing
view1 = dsetview.lazy_slice[1:40:2, :, 0:50:5]
# Lazy transpose
view2 = view1.lazy_transpose([2, 0, 1])
# Chain operations
view3 = view2.lazy_slice[8, 5:10]
# Read data
data = view3[:] # Using indexing
data = view3.read() # Using read() method
zarr Arrays
from lazyslice import DatasetView
import zarr
zarray = zarr.open('data.zarr')
zarrview = DatasetView(zarray)
# Same API as h5py
view = zarrview.lazy_slice[1:10:2, :, 5:10].lazy_transpose([0, 2, 1])
data = view.read()
Lazy Iteration
# Iterate over slices without loading all data at once
for slice_view in view.lazy_iter(axis=1):
chunk = slice_view[:]
process(chunk)
Transpose Shortcut
from lazyslice import lazy_transpose
# Quick transpose without creating a view first
transposed_view = lazy_transpose(dataset, axes=[2, 0, 1])
data = transposed_view[:]
API Reference
DatasetView
The main class for creating lazy views over datasets.
Properties:
shape- Shape of the view after all lazy operationsdataset- The underlying datasetlazy_slice- Enable lazy slicing mode for the next indexing operationT- Transpose (reverse axis order)
Methods:
read()- Read and return the data as a numpy arraylazy_transpose(axis_order=None)- Lazily transpose the arraylazy_iter(axis=0)- Lazily iterate over slices along an axisread_direct(dest, source_sel=None, dest_sel=None)- Read directly into an existing array
lazy_transpose(dset, axes=None)
Convenience function to create a transposed view of a dataset.
Migration from lazy_ops
If you're upgrading from lazy_ops, the main changes are:
- Package renamed:
lazy_ops→lazyslice - Import path changed:
from lazy_ops import DatasetView→from lazyslice import DatasetView - New
read()method (recommended overdsetread(), which is still available for backward compatibility)
Development
# Clone the repository
git clone https://github.com/catalystneuro/lazyslice.git
cd lazyslice
# Install in development mode with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=lazyslice
License
BSD-3-Clause
Metadata
Release files for lazyslice 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lazyslice-0.3.0.tar.gz | 17.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lazyslice-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.0 kB
Release files / lazyslice-0.3.0.tar.gz
| Download URL | lazyslice-0.3.0.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9911cd6e9cede1a11bb5379e9357f0af31c2444e309223e32b2cb79ec573827b
|
|
BLAKE2b-256 checksum How to use checksums |
bdafdaa40fe57cc909fcc8768102e541dde9cb69c794feb91ff054dab34423a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Release files / lazyslice-0.3.0-py3-none-any.whl
| Download URL | lazyslice-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
485df89191d481f74e203ff6236101ecdd0d7c83ac86e116b52143f4214a01bc
|
|
BLAKE2b-256 checksum How to use checksums |
78218db5d3036715f109d7371af9361eb839f7208a03e4b8687a182be2dc399a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|