Skip to main content

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

  1. Bump the version number in Cargo.toml and pyproject.toml.

  2. Create a new release on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aedat-2.0.3.tar.gz (5.1 MB view hashes)

Uploaded Source

Built Distributions

aedat-2.0.3-cp312-none-win_amd64.whl (259.4 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

aedat-2.0.3-cp312-none-win32.whl (241.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

aedat-2.0.3-cp312-cp312-musllinux_1_1_x86_64.whl (941.9 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

aedat-2.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (901.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

aedat-2.0.3-cp312-cp312-macosx_11_0_arm64.whl (425.5 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

aedat-2.0.3-cp312-cp312-macosx_10_9_x86_64.whl (485.3 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

aedat-2.0.3-cp311-none-win_amd64.whl (259.3 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

aedat-2.0.3-cp311-none-win32.whl (241.1 kB view hashes)

Uploaded CPython 3.11 Windows x86

aedat-2.0.3-cp311-cp311-musllinux_1_1_x86_64.whl (941.9 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

aedat-2.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (901.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

aedat-2.0.3-cp311-cp311-macosx_11_0_arm64.whl (425.8 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

aedat-2.0.3-cp311-cp311-macosx_10_9_x86_64.whl (485.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

aedat-2.0.3-cp310-none-win_amd64.whl (259.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

aedat-2.0.3-cp310-none-win32.whl (241.1 kB view hashes)

Uploaded CPython 3.10 Windows x86

aedat-2.0.3-cp310-cp310-musllinux_1_1_x86_64.whl (941.9 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

aedat-2.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (901.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

aedat-2.0.3-cp310-cp310-macosx_11_0_arm64.whl (425.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

aedat-2.0.3-cp310-cp310-macosx_10_9_x86_64.whl (485.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

aedat-2.0.3-cp39-none-win_amd64.whl (259.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

aedat-2.0.3-cp39-none-win32.whl (241.2 kB view hashes)

Uploaded CPython 3.9 Windows x86

aedat-2.0.3-cp39-cp39-musllinux_1_1_x86_64.whl (942.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

aedat-2.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (902.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

aedat-2.0.3-cp39-cp39-macosx_11_0_arm64.whl (426.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

aedat-2.0.3-cp39-cp39-macosx_10_9_x86_64.whl (486.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

aedat-2.0.3-cp38-none-win_amd64.whl (259.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

aedat-2.0.3-cp38-none-win32.whl (241.0 kB view hashes)

Uploaded CPython 3.8 Windows x86

aedat-2.0.3-cp38-cp38-musllinux_1_1_x86_64.whl (942.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

aedat-2.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (902.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

aedat-2.0.3-cp38-cp38-macosx_11_0_arm64.whl (426.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

aedat-2.0.3-cp38-cp38-macosx_10_9_x86_64.whl (486.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page