Skip to content

Commit

Permalink
Merge pull request #269 from gokulbnr/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
biphasic authored Oct 17, 2023
2 parents 2626e31 + 0f605ec commit c0fa3f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
12 changes: 12 additions & 0 deletions test/test_data/sample_aedat_header.aedat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!AER-DAT2.0
# This is a raw AE data file - do not edit
# Data format is int32 address, int32 timestamp (8 bytes total), repeated for each event
# Timestamps tick: 1 us
# Creation date: Fri Sep 22 14:06:27 AEST 2023
# Creation time: System.currentTimeMillis() 1695355587880
# User name: <UserName>
# Hostname: <HostName>
# AEChip: eu.seebetter.ini.chips.davis.Davis346red
#Start of Preferences for this AEChip (search for "End of Preferences" to find end of this block)
#<?xml version="1.0" encoding="UTF-8" standalone="no"?>
#<!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
10 changes: 5 additions & 5 deletions test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@


def test_read_aedat_header():
data_version, data_start = tonic.io.read_aedat_header_from_file(
"test/test_data/sample.aedat4"
data_version, data_start, start_timestamp = tonic.io.read_aedat_header_from_file(
"test/test_data/sample_aedat_header.aedat"
)

assert data_version == 4
assert data_start == 14
assert data_version == 2
assert start_timestamp == 1695355587880


def test_read_aedat_events():
data_version, data_start = tonic.io.read_aedat_header_from_file(
data_version, data_start, start_timestamp = tonic.io.read_aedat_header_from_file(
"test/test_data/sample.aedat4"
)
events = tonic.io.get_aer_events_from_file(
Expand Down
10 changes: 7 additions & 3 deletions tonic/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def read_davis_346(filename):
events: numpy structured array of events
"""
data_version, data_start = read_aedat_header_from_file(filename)
data_version, data_start, start_timestamp = read_aedat_header_from_file(filename)
all_events = get_aer_events_from_file(filename, data_version, data_start)
all_addr = all_events["address"]
t = all_events["timeStamp"]
Expand All @@ -167,7 +167,7 @@ def read_davis_346(filename):

xytp = make_structured_array(x, y, t, p)
shape = (346, 260)
return shape, xytp
return shape, start_timestamp, xytp


def read_dvs_346mini(filename):
Expand Down Expand Up @@ -241,23 +241,27 @@ def read_aedat_header_from_file(filename):
Returns:
data_version (float): The version of the .aedat file
data_start (int): The start index of the data
start_timestamp (int): The start absolute system timestamp in micro-seconds
"""
filename = os.path.expanduser(filename)
assert os.path.isfile(filename), f"The .aedat file '{filename}' does not exist."
f = open(filename, "rb")
count = 1
is_comment = "#" in str(f.read(count))

start_timestamp = None
while is_comment:
# Read the rest of the line
head = str(f.readline())
if "!AER-DAT" in head:
data_version = float(head[head.find("!AER-DAT") + 8 : -5])
elif "Creation time:" in head:
start_timestamp = int(head.split()[4].split("\\")[0])
is_comment = "#" in str(f.read(1))
count += 1
data_start = f.seek(-1, 1)
f.close()
return data_version, data_start
return data_version, data_start, start_timestamp


def get_aer_events_from_file(filename, data_version, data_start):
Expand Down

0 comments on commit c0fa3f1

Please sign in to comment.