Package: aedat
AEDAT is a fast AEDAT 4 python reader, with a Rust underlying implementation.Runpip install aedatto install it.ExampleProcess framesPillow (PIL)OpenCVDetailed exampleInstall from sourceLinuxmacOSWindowsContributePublishExampleTheaedatlibrary provides a single class:Decoder. A decoder object is created by passing a file name toDecoder. The file name must be apath-like object.importaedatdecoder=aedat.Decoder("/path/to/file.aedat")print(decoder.id_to_stream())forpacketindecoder:print(packet["stream_id"],end=": ")if"events"inpacket:print("{}polarity events".format(len(packet["events"])))elif"frame"inpacket:print("{}x{}frame".format(packet["frame"]["width"],packet["frame"]["height"]))elif"imus"inpacket:print("{}IMU samples".format(len(packet["imus"])))elif"triggers"inpacket:print("{}trigger events".format(len(packet["triggers"])))Process framesPillow (PIL)importaedatimportPIL.Image# https://pypi.org/project/Pillow/index=0forpacketindecoder:if"frame"inpacket:image=PIL.Image.fromarray(packet["frame"]["pixels"],mode=packet["frame"]["format"],)image.save(f"{index}.png")index+=1OpenCVimportaedatimportcv2# https://pypi.org/project/opencv-python/index=0forpacketindecoder:if"frame"inpacket:image=packet["frame"]["pixels"]ifpacket["frame"]["format"]=="RGB":image=cv2.cvtColor(image,cv2.COLOR_RGB2BGR)elifpacket["frame"]["format"]=="RGBA":image=cv2.cvtColor(image,cv2.COLOR_RGBA2BGRA)cv2.imwrite(f"{index}.png",image)index+=1Detailed exampleThis is the same as the first example, with detailed comments:importaedatdecoder=aedat.Decoder("/path/to/file.aedat")"""decoder is a packet iterator with an additional method id_to_streamid_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())forpacketindecoder:"""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"inpacket:"""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"inpacket:"""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"inpacket:"""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"inpacket:"""packet["triggers"] is a structured numpy array with the following dtype:[("t", "<u8"),("source", "u1"),]the source value has the following meaning:0: timestamp reset1: external signal rising edge2: external signal falling edge3: external signal pulse4: external generator rising edge5: external generator falling edge6: frame begin7: frame end8: exposure begin9: 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 thewithstatement. To ensure garbage collection, point the decoder variable to something else, for exampleNone, when you are done using it:importaedatdecoder=aedat.Decoder("/path/to/file.aedat")# do something with decoderdecoder=NoneInstall from sourceLocal build (first run).python3-mvenv.venvsource.venv/bin/activate
pipinstall--upgradepip
pipinstallmaturinnumpy
maturindevelop# or maturin develop --release to build with optimizationsLocal build (subsequent runs).source.venv/bin/activate
maturindevelop# or maturin develop --release to build with optimizationsAfter changing any of the files inframebuffers, one must run:flatc--rust-osrc/flatbuffers/*.fbsTo format the code, run:cargofmtPublishBump the version number inCargo.tomlandpyproject.toml.Create a new release on GitHub.