Skip to content

Formatting/Linter Changes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*.mat

dist
build
build
MANIFEST
3 changes: 0 additions & 3 deletions MANIFEST

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# python-aer-lib
Set of functions to read AER data freely in python (aedat extention)
Set of functions and classes to read Address Event Representation data freely in python (aedat extention)

## Install

Expand All @@ -9,6 +9,6 @@ Dependencies (all via pip)
- matplotlib
- Pillow

`pip install git+git://github.com/darioml/pAER-python-aer-lib`
`pip install git+git://github.com/bio-modelling/py-aer`

***Coming to PyPI soon***
85 changes: 52 additions & 33 deletions examples/all_four_directions.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,70 @@
import paer
"""Load data from four directions in separate files"""

from __future__ import print_function
import numpy as np
import pyaer

base_dir = '/path/to/some/dir/'
file1 = 'left_to_right_1.aedat'
file2 = 'right_to_left_1.aedat'
file3 = 'top_to_bottom_1.aedat'
file4 = 'bottom_to_top_1.aedat'
BASE_DIR = '/path/to/some/dir/'
FILE1 = 'left_to_right_1.aedat'
FILE2 = 'right_to_left_1.aedat'
FILE3 = 'top_to_bottom_1.aedat'
FILE4 = 'bottom_to_top_1.aedat'

# Each ball movement should be .5s long
animation_time = 0.2
ANIMATION_TIME = 0.2

# 3,280 events per second for 16*16 is reasonable
# for ball movement (might be even too high!)
NUM_EVENTS_P_S = 3280


# 3,280 events per second for 16*16 is reasonable for ball movement (might be even too high!)
num_events_p_s = 3280
def get_data(file, min, max, animation_time=ANIMATION_TIME,
num_events=NUM_EVENTS_P_S*ANIMATION_TIME, offset=0):
"""
Helper function to read a file.

# Helper function to read a file. Given (min,max) which are data ranges for extraction, this will return a cropped and
# suitably sparse output.
def get_data(file, min, max, animation_time=animation_time, num_events=num_events_p_s*animation_time, offset=0):
aefile = paer.aefile(file, max_events=max+1)
aedata = paer.aedata(aefile)
print 'Points: %i, Time: %0.2f. Sparsity: %i' % (len(aefile.data), (aefile.timestamp[-1]-aefile.timestamp[0])/1000000,
np.floor(len(aefile.data)/num_events))
Given (min,max) which are data ranges for extraction, this will return a
cropped and suitable sparse output.
"""
aefile = pyaer.AEFile(file, max_events=max+1)
aedata = pyaer.AEData(aefile)
print("Points: {}, Time: {:0.2f}, Sparsity: {}".format(
len(aefile.data),
(aefile.timestamp[-1] - aefile.timestamp[0]) / 1000000,
np.floor(len(aefile.data)/num_events)))

sparse = aedata[min:max].make_sparse(np.floor(len(aefile.data)/num_events))

actual_time = (sparse.ts[-1]-sparse.ts[0])/1000000
scale = actual_time/animation_time
sparse.ts = (offset * 1000000) + np.round((sparse.ts-sparse.ts[0])/scale)
# print sparse_ts[0], sparse_ts[-1], sparse_ts[-1]-sparse_ts[0], (sparse_ts[-1]-sparse_ts[0])/1000000
sparse.ts = ((offset * 1000000) +
np.round((sparse.timestamp - sparse.timestamp[0]) / scale))

return sparse

# Loop through all files - indexes are extrapolated.
d1 = get_data(file1, 300000, 750000, offset=0*animation_time)
d2 = get_data(file2, 300000, 600000, offset=1*animation_time)
d3 = get_data(file3, 85000, 140000, offset=2*animation_time)
d4 = get_data(file4, 65200, 131800, offset=3*animation_time)

# Need to pre-load a file, to get the correct headers when writing!
lib = paer.aefile(file1, max_events=1)
def main():
"""Entry point of example"""
# Loop through all files - indexes are extrapolated.
data1 = get_data(FILE1, 300000, 750000, offset=0*ANIMATION_TIME)
data2 = get_data(FILE2, 300000, 600000, offset=1*ANIMATION_TIME)
data3 = get_data(FILE3, 85000, 140000, offset=2*ANIMATION_TIME)
data4 = get_data(FILE4, 65200, 131800, offset=3*ANIMATION_TIME)

# Need to pre-load a file, to get the correct headers when writing!
lib = pyaer.AEFile(FILE1, max_events=1)

final = pyaer.concatenate((data1, data2, data3, data4))
final_16 = final.downsample((16, 16))

lib.save(final, 'test.aedat')
lib.save(final_16, 'test_16.aedat')

final = paer.concatenate( (d1,d2,d3,d4) )
final_16 = final.downsample((16,16))
data1.save_to_mat('test_1.mat')
data2.save_to_mat('test_2.mat')
data3.save_to_mat('test_3.mat')
data4.save_to_mat('test_4.mat')

lib.save(final, 'test.aedat')
lib.save(final_16, 'test_16.aedat')

d1.save_to_mat('test_1.mat')
d2.save_to_mat('test_2.mat')
d3.save_to_mat('test_3.mat')
d4.save_to_mat('test_4.mat')
if __name__ == '__main__':
main()
16 changes: 12 additions & 4 deletions examples/animate_dvs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import paer
"""Example of DVS animation"""

data = paer.aedata(paer.aefile('/path/to/left_to_right_1.aedat', max_events=1000000))
import pyaer

data = data.make_sparse(64).downsample((16,16))
data.interactive_animation(step=1000,limits=(0,16))

def main():
"""Entry point of animation example"""
data = pyaer.AEData(pyaer.AEFile('/path/to/left_to_right_1.aedat',
max_events=1000000))
data = data.make_sparse(64).downsample((16, 16))
data.interactive_animation(step=1000, limits=(0, 16))

if __name__ == '__main__':
main()
23 changes: 16 additions & 7 deletions examples/downsampling.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import paer
"""Example of downsampling AEData from file"""

file = '/path/to/left_to_right_1.aedat'
import pyaer

lib = paer.aefile(file, max_events=750001)
data = paer.aedata(lib)
FILE = '/path/to/left_to_right_1.aedat'

sparse = data[300000:750000].make_sparse(64).downsample((16,16))

sparse.save_to_mat('downsample_left_to_right_1_1.mat')
lib.save(sparse, 'downsample_left_to_right_1_1.aedat')
def main():
"""Entry point of downsampling example"""

lib = pyaer.AEFile(FILE, max_events=750001)
data = pyaer.AEData(lib)

sparse = data[300000:750000].make_sparse(64).downsample((16, 16))

sparse.save_to_mat('downsample_left_to_right_1_1.mat')
lib.save(sparse, 'downsample_left_to_right_1_1.aedat')

if __name__ == '__main__':
main()
23 changes: 16 additions & 7 deletions examples/make_pngs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
"""Example to create PNG files from data"""

from os import listdir
from os.path import isfile, join
import paer
import pyaer

MYPATH = '/path/to/fyp-aedata-matlab'
ONLYFILES = [f for f in listdir(MYPATH)
if isfile(join(MYPATH, f)) and f.endswith('.aedat')]

mypath = '/path/to/fyp-aedata-matlab'
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) and f.endswith('.aedat')]

for file in onlyfiles:
ae = paer.aefile('path/to/fyp-aedata-matlab/' + str(file))
aed= paer.aedata(ae).downsample((16,16))
def main():
"""Entry point of PNG file example"""

paer.create_pngs(aed, '16x16_' + str(file) + '_',path='testing_something',step=3000, dim=(16,16))
for _file in ONLYFILES:
aef = pyaer.AEFile('path/to/fyp-aedata-matlab/' + str(_file))
aed = pyaer.AEData(aef).downsample((16, 16))

pyaer.create_pngs(aed, '16x16_' + str(_file) + '_',
path='testing_something', step=3000, dim=(16, 16))

if __name__ == '__main__':
main()
Loading