Skip to content

Commit

Permalink
Merge pull request #36 from psychoinformatics-de/bf-35
Browse files Browse the repository at this point in the history
Safeguard against edgecases with only nan velocities
  • Loading branch information
adswa authored Dec 1, 2021
2 parents 66bb48e + 3b1a066 commit 9a06633
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 8 additions & 3 deletions remodnav/clf.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def __init__(self,

def _get_signal_props(self, data):
data = data[~np.isnan(data['vel'])]
if not len(data):
return np.nan, np.nan, np.nan, np.nan
pv = data['vel'].max()
amp = (((data[0]['x'] - data[-1]['x']) ** 2 + \
(data[0]['y'] - data[-1]['y']) ** 2) ** 0.5) * self.px2deg
Expand Down Expand Up @@ -894,13 +896,16 @@ def preproc(
vel = filtered_velocities[-1]
filtered_velocities.append(vel)
velocities = np.array(filtered_velocities)

if not median_filter_length:
# no median filtering, but we need the field in our dict later,
# so we just reuse the original velocities
med_velocities = velocities
# acceleration is change of velocities over the last time unit
acceleration = np.zeros(velocities.shape, velocities.dtype)
acceleration[1:] = (velocities[1:] - velocities[:-1]) * self.sr

arrs = [med_velocities] if median_filter_length else []
names = ['med_vel'] if median_filter_length else []
arrs = [med_velocities]
names = ['med_vel']
arrs.extend([
velocities,
acceleration,
Expand Down
1 change: 0 additions & 1 deletion remodnav/tests/test_preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_preproc():
# 2 deg in 0.1s -> 20deg/s
assert p['vel'][-1] == 20
assert p['accel'][-1] == 200
assert 'med_vel' not in p.dtype.names

data['x'][1] = 200
p = clf.preproc(data.copy(), savgol_length=0, dilate_nan=0)
Expand Down

0 comments on commit 9a06633

Please sign in to comment.