MdaG
September 22nd, 2006, 05:48 PM
Hi!
I have a set of data representing positions relative time on the xy-plane. What I want to do is remove the positions reached with a high velocity (dx = x[t] - x[t - 1] > tol -> remove x[t-1]).
This is my attempt, but it's way too slow. Is there some way to speed it up without resorting to a C module?
samples is a list of 2-element lists with len = 64000 ([[x0,y0],[x1,y1],[x2,y2],[x3,y3]...]).
def remove_saccades(samples, tol):
"""Remove data corresponding to saccades defined by tol"""
remove_sample = samples.remove
old_sample = samples[0]
for sample in samples:
dx = sample[0] - old_sample[0]
dy = sample[1] - old_sample[1]
old_sample = sample
if abs(dx) > tol or abs(dy) > tol:
remove_sample(sample)
I also want to remove duplicate samples that lies in sequence. How can I do that. I don't want to remove them all, but if we got four identical samples in a row like [2, 5], [2, 5], [2, 5], [2, 5], then I want to remove three of them. That is I'm only interested in removing those that lie in a row. It doesn't matter if we got 25 [2, 5] in there somewhere as long as they don't lie in sequence.
This is my current attempt, but it doesn't work correctly:
def remove_duplicates(samples):
old_sample = None
remove_sample = samples.remove
for sample in samples:
if sample == old_sample:
remove_sample(sample)
old_sample = sample
Any thoughts?
I have a set of data representing positions relative time on the xy-plane. What I want to do is remove the positions reached with a high velocity (dx = x[t] - x[t - 1] > tol -> remove x[t-1]).
This is my attempt, but it's way too slow. Is there some way to speed it up without resorting to a C module?
samples is a list of 2-element lists with len = 64000 ([[x0,y0],[x1,y1],[x2,y2],[x3,y3]...]).
def remove_saccades(samples, tol):
"""Remove data corresponding to saccades defined by tol"""
remove_sample = samples.remove
old_sample = samples[0]
for sample in samples:
dx = sample[0] - old_sample[0]
dy = sample[1] - old_sample[1]
old_sample = sample
if abs(dx) > tol or abs(dy) > tol:
remove_sample(sample)
I also want to remove duplicate samples that lies in sequence. How can I do that. I don't want to remove them all, but if we got four identical samples in a row like [2, 5], [2, 5], [2, 5], [2, 5], then I want to remove three of them. That is I'm only interested in removing those that lie in a row. It doesn't matter if we got 25 [2, 5] in there somewhere as long as they don't lie in sequence.
This is my current attempt, but it doesn't work correctly:
def remove_duplicates(samples):
old_sample = None
remove_sample = samples.remove
for sample in samples:
if sample == old_sample:
remove_sample(sample)
old_sample = sample
Any thoughts?