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
Local build (first run).
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install maturin numpy
maturin develop # or maturin develop --release to build with optimizations
Local build (subsequent runs).
source .venv/bin/activate
maturin develop # or maturin develop --release to build with optimizations
After changing any of the files in framebuffers, one must run:
flatc --rust -o src/ flatbuffers/*.fbs
To format the code, run:
cargo fmt
Publish
-
Bump the version number in Cargo.toml and pyproject.toml.
-
Create a new release on GitHub.
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.1.0-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94f3b03d1e72889df9ed8cbc1541c0775152ca2e170456bb7204b090170df6d1 |
|
MD5 | 2c0489b397bb489cfef3183ae073b1d8 |
|
BLAKE2b-256 | 4e6d5cc266185d2b286e5e2598e9738ddd163330c9d9e4aedc4edfbbeec01a8e |
Hashes for aedat-2.1.0-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5648637521fc4c71adadcb11bc7e74f3f27599598ffe8ecbfab846ecb8f8fed6 |
|
MD5 | e9a5d8c2cef65957f545de6f3ed89dc0 |
|
BLAKE2b-256 | 15dbacb9f042cc8f0f6c9c7f7ec46a8b956513430b358d1315bf4db554b62ee7 |
Hashes for aedat-2.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 911dc93cae022359276923c7219378642ac724c2872df1163f78ae5754155d70 |
|
MD5 | 79446cfefa7fc1e420097ddad8f53340 |
|
BLAKE2b-256 | b0b6f3306d902f9a69db7052729e5a9cfb3b46775641a3123beae58f7b684abf |
Hashes for aedat-2.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 291526eac7c4edcd6a90ca1de4394849fc1c10d4d31b3d1fef80e0e68380988e |
|
MD5 | 81b4434c7eae8c7250a1a16b4a1eee36 |
|
BLAKE2b-256 | b96d5d8297906e8b0b919c0304281addb2d306ef94252916d22e7b9073f939f3 |
Hashes for aedat-2.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7eca06298910cfd480ff5f91d8288315575981ad6f739c51129e042e0638acd |
|
MD5 | 71a732990ade14984c317e054cca0861 |
|
BLAKE2b-256 | ad904f70ebf4d5cee97bc6b60cdd2790efd47374e981ee65142739794b4d43c4 |
Hashes for aedat-2.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2511e835bf5f8142ddfe3620868dcc8935f2fd3755a7890b0ce02b19e6e9a6e |
|
MD5 | abd4f674df49176634e03e41db9a7698 |
|
BLAKE2b-256 | 2ab7f9fb74b0c52fe14bb5d8349ee0182607ea4577927903e44bec338a6ac79f |
Hashes for aedat-2.1.0-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f0665e45a5ec7852e05d03fab91fee8f821d895dd785a6c6a5c8fa26b7b21b5 |
|
MD5 | 043d79298d4540b1aeaac8c2881dbf1a |
|
BLAKE2b-256 | b6efb974a35b20a822155ec4164fb61498f27d3d35985de68002fcaa63dc0010 |
Hashes for aedat-2.1.0-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efc4e676ea12acab0787efcb05bf6511359009d2fb537ea6142306ba0187dd62 |
|
MD5 | d6dd43a1a44e7af546a5daf8e3f8d9dd |
|
BLAKE2b-256 | 08476d698046c841df397ac66218eb4d39ce213e234e2e731740d2b06a748e75 |
Hashes for aedat-2.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bffcdde8a5a49ce68ceecab101d7d069faf082aa2c47d0e26ff3dcd40cceca12 |
|
MD5 | 439a2eb0fce52cb7d575cad03d88c23c |
|
BLAKE2b-256 | 07e0c6ffdcfad8e2917b0e3874a8daea1305f8cc4d40cc71d01c45258b50a117 |
Hashes for aedat-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fba1b457a6e0b521ad06a972e728ca1a32094acfb9549be9ce71f8225a1418a |
|
MD5 | 85c83bcee7aac1b93b3e5c966cdaa85d |
|
BLAKE2b-256 | bbc4f72e06d164323360ac7a88c1976adbc88f96d7b6b8b52ee0ac01a5aad0a6 |
Hashes for aedat-2.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b97bb0eabaf6039a8cc8609e6bec119d495c0f71936386021acd7c0368592e4e |
|
MD5 | abb5c0112208bfd794403cb2709b3ed5 |
|
BLAKE2b-256 | 08c3b8e1103c18e87c7bde54da68da116469a64dbe0504850ddcd4eb77c93bf5 |
Hashes for aedat-2.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 247cb514ac13b51a598991d6350bcee18edc44d9b9efc8f4637eb2cffb757c67 |
|
MD5 | ea495895fea8b83462964b61fb20513a |
|
BLAKE2b-256 | b22bbc7c7e8be48a40033bbc3ac1aa0eeed2eef924db9ad521fbdacc21194eb3 |
Hashes for aedat-2.1.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8919e8f374d339fd18397c84b456faa4afe747d4bca7d74da3423609e42726 |
|
MD5 | 3a2f5920028d0582b39bd9b829bbd73f |
|
BLAKE2b-256 | 0295c920fb0b4a780a8c4d0d265c75e8f0a5ff847ab34a1125be7de3b4b5ae6b |
Hashes for aedat-2.1.0-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1d21ec549e36aab90580c6e13ae4c491625ff7e6ae778b4adccfb819e0591aa |
|
MD5 | e4ebf4b707366bdf2262e561a909e31b |
|
BLAKE2b-256 | 5453e4502493f8cb6bda24588e1f25a21718e76af10791e1c11ba5cd3e37d6f0 |
Hashes for aedat-2.1.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d8a8ef266688e63fd2213f13a2fa183026fbb484e6c428bd1c5c0b6f33c4e1a |
|
MD5 | 07ea8d2df377a1a9aa62d9fa95ed0602 |
|
BLAKE2b-256 | d317cf9aa461df60e47697e9b644fb338fa37122a4216a1c6745215e5dda0895 |
Hashes for aedat-2.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d0c21bac81c2eeb5c727e8b694452e20f9836be44c8ede0cf7d28e14bddd86d |
|
MD5 | b78c258dace793a53977e8207fa7439e |
|
BLAKE2b-256 | 09cecc8958fb14929763c4697df5c00307e0c99da991b449bd874e84f60ab184 |
Hashes for aedat-2.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c81bbb9ef1102d7efebdf5453132920850551db150bfa8909e2914b0f6828f7f |
|
MD5 | 824edfc05ae9af2fc312778a205d8738 |
|
BLAKE2b-256 | d158ee84965999460a0d99abfc6faad208be67bea08f15af8cf3101dac47d21e |
Hashes for aedat-2.1.0-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f1de07574671190b82177de632a15fdf89dbb565d1e576e3c496e5bc50276d2 |
|
MD5 | d7ffc5b780c30569cf1ecbf10ede813e |
|
BLAKE2b-256 | 56db0ac97bff5452b65e6993261803ef167506e50fd28a87bb6e1274df624a5b |
Hashes for aedat-2.1.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ecfddd2617f49dc5814d36832003437aa9808d7218ada79c353f4ac2a3700e |
|
MD5 | 8adc0f35089bebdd5386993aebed3321 |
|
BLAKE2b-256 | 76db87ab010c7abd4d481f6d9cfae947f7ca173ac5e2581ee4adf00f57a513f1 |
Hashes for aedat-2.1.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc4d3f54cb41ec15a8207c0f0ef700d38d71857158c81ff09717e8ad5603a80 |
|
MD5 | 2824ae0efca7bb65ee280e5879b39bde |
|
BLAKE2b-256 | dad94793f771f6c76336a5d0c75a9a6387d9652c85116f23e8c5a459ebc9dd09 |
Hashes for aedat-2.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc6bae4c62cfa52613ec93645b3c6c6e2d4e25ca863aed6556d6c8fd10fe92d |
|
MD5 | 27cdf5a934c4382c58f0a584075e3e40 |
|
BLAKE2b-256 | 74a64b5aa27a0682321b6bd26b77ad6fd93337d7ceb7f8247b6c69ab00287037 |
Hashes for aedat-2.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3648c37a5e09c798e30ddef1c937ba47735e44b57c14a03d30969d0f3f1e0a5 |
|
MD5 | e3b8d0948b4e5c7f4c8bc8b1e7ecf094 |
|
BLAKE2b-256 | 27621c761de48975348c6b342eeab1ff45dcc32d5c82a9dc0d1b86a3ed49e6d5 |
Hashes for aedat-2.1.0-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99a6e3f18d1749cbccdcb19f696b8f7d21e1c1ec084731f984b3ee2d694ca0af |
|
MD5 | e7a5527ef18976d3149334b933e4b4db |
|
BLAKE2b-256 | 0a821440ae50deda619a5b0d8c5a9a434191156a8a453c8ec7837045e7965db0 |
Hashes for aedat-2.1.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0f7be641017e54ad7fd48ebc9e9a97f148927ab9c99da3037afa00433b03862 |
|
MD5 | 519088f9540e212ee7236e14e52d1c37 |
|
BLAKE2b-256 | bb6d35c8b46c0bc2ee9a61128cc90796907844dd674ec56bb94a9d55feeb1e04 |
Hashes for aedat-2.1.0-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 074c03fd76bce01d5005e9fdf6a899f0e3524a173daaf021459187838d6adfbc |
|
MD5 | d53370bc5f80d1baca392accd8bd282c |
|
BLAKE2b-256 | 1905db7fadca4b570d407587a29498d1719634a910cbceac0a4dfd6e310e8ace |
Hashes for aedat-2.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f99132833e98ff176159ec8f263f3115c95659678eea942b20a524dbd45ce425 |
|
MD5 | c245266f22f5cb164be771ff22890f5e |
|
BLAKE2b-256 | cfdda53fcfaae420db1aa68032bae72739ffee1cbab4bf6834ad736f9a07a8b4 |
Hashes for aedat-2.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 250079141fb3a4308d136dec19f8a2c3cd2e374eecb5f1fa811b472d510ea9cd |
|
MD5 | 801dff84504a8f247dae5b0991192c64 |
|
BLAKE2b-256 | d2382b470a10e40de7bf7e3679763c34b44f1960b86e21d3ab89d738cf1100c9 |
Hashes for aedat-2.1.0-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d99918e4fd62baf42c3918b2c9012aa882e3662b0b009f26d0b546ee4868a586 |
|
MD5 | a7fb47032232685449030d2c06d71131 |
|
BLAKE2b-256 | e5f1fa6d54ca2a171fa2cb1a6e1dad5c3e93d396137972260d2195eed7815ae2 |