Metadata-Version: 2.1
Name: evutils
Version: 0.3.16
Summary: Utilities for event-based vision
Keywords: events,dvs,neuromorphic,vision,event-based
Author-Email: Jakub Mandula <jakub.mandula@pbl.ee.ethz.ch>
License: Copyright (c) 2024 Jakub Mandula
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: C
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Typing :: Typed
Project-URL: Source Code, https://github.com/mandulaj/evutils
Project-URL: Documentation, https://mandulaj.github.io/evutils/
Project-URL: Bug Tracker, https://github.com/mandulaj/evutils/issues
Project-URL: Homepage, https://mandulaj.github.io/evutils/
Requires-Python: >=3.10
Requires-Dist: numpy>=2.0.0
Requires-Dist: opencv-python>=4.2
Requires-Dist: numba>=0.57
Provides-Extra: aedat
Requires-Dist: lz4>=4.0; extra == "aedat"
Requires-Dist: zstandard>=0.22; python_version < "3.14" and extra == "aedat"
Provides-Extra: torch
Requires-Dist: torch>=2.0; extra == "torch"
Provides-Extra: hdf5
Requires-Dist: hdf5plugin==6.0.0; extra == "hdf5"
Requires-Dist: h5py>=3.16.0; extra == "hdf5"
Provides-Extra: vis
Requires-Dist: matplotlib>=3.1; extra == "vis"
Requires-Dist: open3d>=0.19.0; python_version < "3.13" and extra == "vis"
Requires-Dist: scipy>=1.15.3; extra == "vis"
Requires-Dist: tqdm>=4.41; extra == "vis"
Provides-Extra: test
Requires-Dist: pytest>=9.0.2; extra == "test"
Requires-Dist: pytest-benchmark>=5.2.3; extra == "test"
Requires-Dist: zstandard>=0.22; python_version < "3.14" and extra == "test"
Provides-Extra: compare
Requires-Dist: expelliarmus>=1.1.0; extra == "compare"
Requires-Dist: evlib>=0.12.0; python_version >= "3.11" and extra == "compare"
Requires-Dist: evlib>=0.8.0; python_version < "3.11" and extra == "compare"
Requires-Dist: evt3>=0.3; extra == "compare"
Provides-Extra: docs
Requires-Dist: sphinx>=8.0.0; extra == "docs"
Requires-Dist: sphinx-autoapi>=3.6.1; extra == "docs"
Requires-Dist: sphinx-autodoc-typehints>=3.0.1; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=3.1.0; extra == "docs"
Requires-Dist: sphinx_book_theme>=1.0.0; extra == "docs"
Requires-Dist: pydata_sphinx_theme>=0.19.0; extra == "docs"
Requires-Dist: myst-parser>=4.0.0; extra == "docs"
Provides-Extra: all
Requires-Dist: evutils[aedat,hdf5,torch,vis]; extra == "all"
Provides-Extra: dev
Requires-Dist: evutils[all,docs,test]; extra == "dev"
Description-Content-Type: text/markdown

# <a href="https://mandulaj.github.io/evutils"><img src="https://mandulaj.github.io/evutils/_static/event_hexagon_broken.webp" alt="evutils_logo" width="50" align="top" style="background-color: #fff0;"></a> EV-Utils
[![PyPI Version](https://img.shields.io/pypi/v/evutils)](https://pypi.org/project/evutils/)
![PyPI Python Version](https://img.shields.io/pypi/pyversions/evutils)
[![Test](https://github.com/mandulaj/evutils/actions/workflows/test.yaml/badge.svg)](https://github.com/mandulaj/evutils/actions/workflows/test.yaml)
[![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://mandulaj.github.io/evutils/)
![GitHub repo size](https://img.shields.io/github/repo-size/mandulaj/evutils)


## Overview
EV-Utils (`evutils`) is a performant collection of utilities for working with event-based vision data. Built with minimal dependencies, it relies on a compiled C backend for speed while offering a clean, modular Python interface.

### Core Philosophy
* **Fast & Lightweight:** Highly optimized C parsers for zero-bottleneck data ingestion.
* **Minimal Footprint:** Core features run entirely on NumPy and Numba.
* **Lazy Loading:** All heavy integrations (PyTorch, HDF5, Polars, etc.) are lazy-loaded. If you don't use them, you don't need them installed, and they won't slow down import times.
* **Simple & Extensible:** Clean modular APIs.



### Inspirations & Related Work 
This project draws inspiration from several excellent libraries in the event-based vision ecosystem and attempts to fill in their shortcomings:

* [Tonic](https://github.com/neuromorphs/tonic)
* [event_utils](https://github.com/TimoStoff/event_utils)
* [evlib](https://github.com/tallamjr/evlib)
* [expelliarmus](https://github.com/open-neuromorphic/expelliarmus)
* [event-vision-library](https://github.com/shiba24/event-vision-library)
* [evt3](https://github.com/muthmann/evt3)
* [openeb](https://github.com/prophesee-ai/openeb)


## Installation
We recommend installing `evutils` using `uv`. 
### From PyPi
```bash
uv add evutils # Basic library
uv add evutils[all] # All groups (torch, hdf5, aedat, vis, etc..)
uv add evutils[dev] # Dev group
```

### From Git
```bash
git clone --recurse-submodules https://github.com/mandulaj/evutils.git
cd evutils

uv pip install -e ".[dev]"
```

Note: You can also install specific optional dependency groups like `uv add evutils[torch,hdf5]`.

## Architecture
The library is divided into several discrete modules. Many can be used independently without installing the full suite of dependencies:

```
└── augment     - Event augmentations
└── chunking    - Splitting event streams into fixed-size windows
└── dataset     - Wrappers for various dataset loaders
└── io          - Event reading and writing interfaces
    ├── reader 
    └── writer
└── processing  - Event stream processing and filtering (denoising, masking)
└── random      - Random event generation and noise injection
└── repr        - Dense representations (voxel grids, time surfaces, histograms)
└── torch       - PyTorch integration (requires evutils[torch])
└── types       - Standard types for representing Events in NumPy arrays
└── utils       - General-purpose helpers
└── vis         - Visualization methods
    ├── histogram
    └── reconstructor
```

### Quick API overview 

<!-- ### `augment`

Event augmentations

### `dataset`

Wrappers for various dataset loaders -->

#### `io`: Reading and Writing Events

The `io` module provides methods for reading and writing events into various event formats. It provides a simple `.read()` and `.write()` interface as well as more advanced interfaces using iterators and slicing.

Supported formats (see the [formats documentation](https://mandulaj.github.io/evutils/formats.html) for details):

| Format | Extensions | Read | Write | Notes |
|---|---|:---:|:---:|---|
| EVT3 / EVT2.1 / EVT2 (Prophesee RAW) | `.raw`, `.evt*` | ✅ | ✅ | native C decoder, external triggers |
| DAT (Prophesee) | `.dat` | ✅ | ✅ | native C decoder |
| AER (Prophesee) | `.aer` | ✅ | ✅ | timestamp generation selectable |
| AEDAT 1.0 / 2.0 / 3.1 / 4.0 | `.aedat`, `.aedat4` | ✅ | 🚧 | AEDAT4 compression: `evutils[aedat]` |
| HDF5 (DSEC/RVT layout) | `.h5`, `.hdf5` | ✅ | ✅ | `evutils[hdf5]`, ms-index random access |
| HDF5 (Prophesee layout) | `.h5`, `.hdf5` | ✅ | 🚧 | ECF-compressed files need the ECF plugin |
| NPZ | `.npz` | ✅ | ✅ | streaming, `np.load`-compatible |
| CSV / TXT | `.csv`, `.txt` | ✅ | ✅ | native C parser |
| BIN | `.bin` | 🚧 | 🚧 | planned |

```python
from evutils.io import EventReader


ev_file = EventReader("raw_file.raw", delta_t=10e3)

events = ev_file.read()

```

#### `utils`

Various utility functions

#### `random`

Generating random events and adding noise to event recordings

#### `types`

This provides several standard types for representing Events in numpy arrays


#### `vis`

The `vis` moduels provides several methods for visualizing the events (for example as histograms), but also provides a streamlined interface for more complex visualization techneques, such as using the [E2Vid](https://github.com/uzh-rpg/rpg_e2vid) reconstructor.


```python
from evutils.vis.reconstructor import RPG_Reconstructor

reconstructor = RPG_Reconstructor(1280, 720)

img = reconstructor.gen_frame(events)

```

## Running tests

Tests are managed via `pytest`. If you installed the package with the `[dev]` or `[test]` flag, you can run the standard test suite via:
```bash
uv run pytest -s
```

### Testing Docstrings
The library uses `doctest` to ensure all Python `>>>` examples inside docstrings are correct and functional. Because the default configuration only scans the `tests/` directory, you must explicitly tell pytest to scan the source code and ignore legacy submodules (like `rpg_e2vid` which contains Python 2 syntax):

```bash
uv run pytest --doctest-modules src/evutils --ignore=src/evutils/vis/reconstructor/rpg_e2vid/
```

## [Benchmarks](benchmarks/README.md)

Read/write throughput benchmarks (using [pytest-benchmark](https://pytest-benchmark.readthedocs.io)) live in `benchmarks/` and are kept out of the normal test run. Run them explicitly:

```bash
uv run pytest benchmarks/                                   # evutils only
uv run pytest benchmarks/ --benchmark-group-by=param:fmt    # compare libraries per format
```

The benchmarks download a real Prophesee recording on first use. Optional cross-library comparisons run automatically once the libraries are installed (`uv pip install -e ".[compare]"`); OpenEB/Metavision is compared via the Docker image in `benchmarks/docker/`. See [`benchmarks/README.md`](benchmarks/README.md) for details.



## & Roadmap
We aim for universal event format support, prioritizing blazing fast read/write speeds, completeness, and extensibility. 
- [x] Universal format support (`.raw`, `.evt2`, `.dat`, `.aedat4`, `.hdf5`, `.npz`, `.csv`, etc.)
- [x] Full Read/Write parity where possible
- [x] Chunked & Streaming access
- [x] External trigger data parsing
- [ ] **Random access / Timestamp indexing** (Big TODO for the future)
- [ ] **Arbitrary input sources:** memory-mapped IO, pure in-memory streams, HTTP streams
- [ ] **On-the-fly Compression wrappers:** passing file handles through `zstd` or `lz4` compression transparently before decoding
- [ ] **EventStreamer Pipeline Refactor:** Decouple `EventReader`'s monolithic chunking logic into composable functional generators in `chunking.py`, exposing a native `EventStreamer` for power-users while turning `EventReader` into a clean Façade.


## Acknowledgements

Thanks to all the contributors for supporting this project:

* Elia Franc
* Jakub Mandula


## Cite
```bibtex
@PhDThesis{2024mandula_evutils,
  author        = {Jakub Mandula},
  title         = {EV-Utils: collection of utilities for working with event-based vision data},
  school        = {Dept. of Information Technology and Electrical Engineering, ETH Zurich},
  year          = 2024
}
```