A fast AEDAT4 decoder with an underlying Rust implementation
Project description
AEDAT is a fast AEDAT 4 python reader, with a Rust underlying implementation.
Run pip install aedat
to install it.
Example
The aedat
library provides a single class: Decoder
. A decoder object is created by passing a file name to Decoder
. The file name must be a path-like object.
import aedat
decoder = aedat.Decoder("/path/to/file.aedat")
print(decoder.id_to_stream())
for packet in decoder:
print(packet["stream_id"], end=": ")
if "events" in packet:
print("{} polarity events".format(len(packet["events"])))
elif "frame" in packet:
print("{} x {} frame".format(packet["frame"]["width"], packet["frame"]["height"]))
elif "imus" in packet:
print("{} IMU samples".format(len(packet["imus"])))
elif "triggers" in packet:
print("{} trigger events".format(len(packet["triggers"])))
Process frames
Pillow (PIL)
import aedat
import PIL.Image # https://pypi.org/project/Pillow/
index = 0
for packet in decoder:
if "frame" in packet:
image = PIL.Image.fromarray(
packet["frame"]["pixels"],
mode=packet["frame"]["format"],
)
image.save(f"{index}.png")
index += 1
OpenCV
import aedat
import cv2 # https://pypi.org/project/opencv-python/
index = 0
for packet in decoder:
if "frame" in packet:
image = packet["frame"]["pixels"]
if packet["frame"]["format"] == "RGB":
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
elif packet["frame"]["format"] == "RGBA":
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)
cv2.imwrite(f"{index}.png", image)
index += 1
Detailed example
This is the same as the first example, with detailed comments:
import aedat
decoder = aedat.Decoder("/path/to/file.aedat")
"""
decoder is a packet iterator with an additional method id_to_stream
id_to_stream returns a dictionary with the following structure:
{
<int>: {
"type": <str>,
}
}
type is one of "events", "frame", "imus", "triggers"
if type is "events" or "frame", its parent dictionary has the following structure:
{
"type": <str>,
"width": <int>,
"height": <int>,
}
"""
print(decoder.id_to_stream())
for packet in decoder:
"""
packet is a dictionary with the following structure:
{
"stream_id": <int>,
}
packet also has exactly one of the following fields:
"events", "frame", "imus", "triggers"
"""
print(packet["stream_id"], end=": ")
if "events" in packet:
"""
packet["events"] is a structured numpy array with the following dtype:
[
("t", "<u8"),
("x", "<u2"),
("y", "<u2"),
("on", "?"),
]
"""
print("{} polarity events".format(len(packet["events"])))
elif "frame" in packet:
"""
packet["frame"] is a dictionary with the following structure:
{
"t": <int>,
"begin_t": <int>,
"end_t": <int>,
"exposure_begin_t": <int>,
"exposure_end_t": <int>,
"format": <str>,
"width": <int>,
"height": <int>,
"offset_x": <int>,
"offset_y": <int>,
"pixels": <numpy.array(shape=(height, width), dtype=uint8)>,
}
format is one of "L", "RGB", "RGBA"
"""
print("{} x {} frame".format(packet["frame"]["width"], packet["frame"]["height"]))
elif "imus" in packet:
"""
packet["imus"] is a structured numpy array with the following dtype:
[
("t", "<u8"),
("temperature", "<f4"),
("accelerometer_x", "<f4"),
("accelerometer_y", "<f4"),
("accelerometer_z", "<f4"),
("gyroscope_x", "<f4"),
("gyroscope_y", "<f4"),
("gyroscope_z", "<f4"),
("magnetometer_x", "<f4"),
("magnetometer_y", "<f4"),
("magnetometer_z", "<f4"),
]
"""
print("{} IMU samples".format(len(packet["imus"])))
elif "triggers" in packet:
"""
packet["triggers"] is a structured numpy array with the following dtype:
[
("t", "<u8"),
("source", "u1"),
]
the source value has the following meaning:
0: timestamp reset
1: external signal rising edge
2: external signal falling edge
3: external signal pulse
4: external generator rising edge
5: external generator falling edge
6: frame begin
7: frame end
8: exposure begin
9: exposure end
"""
print("{} trigger events".format(len(packet["triggers"])))
Because the lifetime of the file handle is managed by Rust, decoder objects are not compatible with the with statement. To ensure garbage collection, point the decoder variable to something else, for example None
, when you are done using it:
import aedat
decoder = aedat.Decoder("/path/to/file.aedat")
# do something with decoder
decoder = None
Install from source
This library requires Python 3.x, x >= 5, and NumPy. This guide assumes that they are installed on your machine.
Note for Windows users: this library requires the x86-64 version of Python. You can download it here: https://www.python.org/downloads/windows/ (the default installer contains the x86 version).
A Rust compiling toolchain is required during the installation (but can be removed afterwards).
Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone https://github.com/neuromorphicsystems/aedat.git
cd aedat
cargo build --release
cp target/release/libaedat.so aedat.so
You can import aedat
from python scripts in the same directory as aedat.so, which can be placed in any directory.
macOS
brew install rustup
rustup-init
git clone https://github.com/neuromorphicsystems/aedat.git
cd aedat
cargo build --release
cp target/release/libaedat.dylib aedat.so
You can import aedat
from python scripts in the same directory as aedat.so, which can be placed in any directory.
Windows
- install rustup (instructions availables at https://www.rust-lang.org/tools/install)
- clone or download this repository
- run in PowerShell from the aedat directory:
cargo build --release
copy .\target\release\aedat.dll .\aedat.pyd
You can import aedat
from python scripts in the same directory as aedat.pyd, which can be placed in any directory.
Contribute
After changing any of the files in framebuffers, one must run:
flatc --rust -o src/ flatbuffers/*.fbs
To format the code, run:
cargo fmt
You may need to install rustfmt first with:
rustup component add rustfmt
Publish
-
Bump the version number in Cargo.toml.
-
Install Cubuzoa in a different directory (https://github.com/neuromorphicsystems/cubuzoa) to build pre-compiled versions for all major operating systems. Cubuzoa depends on VirtualBox (with its extension pack) and requires about 100 GB of free disk space.
cd cubuzoa
python3 -m cubuzoa provision
python3 -m cubuzoa build /path/to/aedat --post /path/to/aedat/test.py
- Install maturin and twine
pip3 install maturin
pip3 install twine
- Upload the compiled wheels and the source code to PyPI:
maturin build --out wheels --interpreter /usr/local/bin/python3
python3 -m twine upload wheels/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for aedat-2.0.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 688bb7468543be3707729633916515e4d7a75b0768fe70b2f7defa10bd8b67d9 |
|
MD5 | 467425a3db6712718c2378beb6172b83 |
|
BLAKE2b-256 | 4c6fe924b5d3355c8e7abc91717199c3ab5867255f89e564c2e168235c4c5ad8 |
Hashes for aedat-2.0.1-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6129ec187bcb1c0121965a8eadfefaab069d81b7f28ca0a03586a71c1cf35515 |
|
MD5 | 8fd61b10989f0743589e905743f8d8b4 |
|
BLAKE2b-256 | c362432fcee926ceb45e046f4d417a34f6b7d3191f97a50309e9ae63e6c004ca |
Hashes for aedat-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e756ab99272ad5dde9215e70ac84c74a9a2d4c85169c1d2873cfbc2abf82f66 |
|
MD5 | 92358cb8ac5edf337202ad65c7bac70a |
|
BLAKE2b-256 | ac665c1ce4ff0820611e4430448660f28bd10a7bf1bb9e7f8d67e48afb65c9e7 |
Hashes for aedat-2.0.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13937d36425f9ca2e37f6f1aa3728325f56e6163f822bd6bfc536010ce8d7926 |
|
MD5 | c68df42bf017e6588a369855d33bf317 |
|
BLAKE2b-256 | e52bb04b4514f3b4d16d82c794aa2f3b029cd4b9c14ad2b947a734a7bd0a6731 |
Hashes for aedat-2.0.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b4f31d46e5292702c70dc046e46e6ea16a8cc4751b3e885e2ad156cbbdba1fb |
|
MD5 | f375987c6c5a64afdfff7b18db3f3158 |
|
BLAKE2b-256 | ddc9a243f48fe39d6a3d5cdd9afdba7ec55c1b5adc1c84d16c869b25998d67d5 |
Hashes for aedat-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6949c0e944f6ad13b8b5b347548ecec38901434664dc82290ba9e9dec314be5 |
|
MD5 | d40fcbc74ead54787da5e622243a87bd |
|
BLAKE2b-256 | 132c0cd148c119901df3408e5fc0d55e774bfd0ad1ad14cf4b6568d2a546bac6 |
Hashes for aedat-2.0.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60e644cb03d45de88efc92074979916df9a11a44cebe3a6b7d631dd5ec846ea4 |
|
MD5 | 8dee8697f31ece8c4962904c3d161680 |
|
BLAKE2b-256 | e59df9f6df7d5493a92b609b5bd6c4c8e979e95915453d12310c2d4b70ab8da9 |
Hashes for aedat-2.0.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 477cf88f908f4c9d5045f328c4f0eb04bf4ed7a3635e1119452d53d12a5d1f26 |
|
MD5 | 525c46be21bd20cc5b99a2ca85b16b0f |
|
BLAKE2b-256 | 5746d9e9db4a391b3c5ccac4574292b5d24edd5599da26d7c7285c3d7e118223 |
Hashes for aedat-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b11e77012a80427c93eb2382b4425243d43efaae09ec0f8203ce21b13cbfedb |
|
MD5 | bc85fc5d73497ddbff29946eaeb3c3e6 |
|
BLAKE2b-256 | 3a1a89031554404d3bea5c78366c1190e22766c37e8fc17802e0db457da14779 |
Hashes for aedat-2.0.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b2fbd69f7aeed25c9c4e2c73defcf4097613b6e1efee9ae2fb509f7c8ba4c44 |
|
MD5 | 8ec6549f5c542869207a3a6395d0f27d |
|
BLAKE2b-256 | e6a219c1c650fcfe91e618539e56c6b77d7b4246374e559a588c249ae36fe02c |
Hashes for aedat-2.0.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efca66a585408dc2e206fb65dd6ed30589245a0e95283f3037ff40a66f06ec31 |
|
MD5 | 790c744988506d15fe0eac0438b52ff7 |
|
BLAKE2b-256 | 31660b0479a0148b687eae86bb6714eef80fe248500c5aabbac88c3be715cf5e |
Hashes for aedat-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 228c47ffc84afda2b3988381a6685fb323ac094e6966fdf05fe22b88431c12c2 |
|
MD5 | df05c20952405cc0d271acd970ac1b44 |
|
BLAKE2b-256 | 3dc0701534746009eb400792ba19f8b0a166751cbb94744c63f72d1865351243 |
Hashes for aedat-2.0.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d95f06610a8b839afb47197d797a3fcea609099653d1f09e7109b67392906d7 |
|
MD5 | 8a8ca911d543d8891d656ce652c720c8 |
|
BLAKE2b-256 | 4b0f39ffc0fd719148aa98ad9b13f54c7d20ad8de210da48a51c62804cc1976a |