Skip to content
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

Add support for downsampling encoder data #407

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion aeon/io/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from dotmap import DotMap

from aeon import util
from aeon.io.api import chunk_key
from aeon.io.api import chunk, chunk_key
from aeon.io.api import aeon as aeon_time

_SECONDS_PER_TICK = 32e-6
_payloadtypes = {
Expand Down Expand Up @@ -185,6 +186,22 @@ class Encoder(Harp):
def __init__(self, pattern):
super().__init__(pattern, columns=["angle", "intensity"])

def read(self, file, downsample=True):
"""Reads encoder data from the specified Harp binary file, and optionally downsamples
the frequency to 50Hz.
"""
data = super().read(file)
if downsample is True:
# resample requires a DatetimeIndex so we convert early
data.index = aeon_time(data.index)

first_index = data.first_valid_index()
if first_index is not None:
# since data is absolute angular position we decimate by taking first of each bin
chunk_origin = chunk(first_index)
data = data.resample('20ms', origin=chunk_origin).first()
return data
glopesdev marked this conversation as resolved.
Show resolved Hide resolved


class Position(Harp):
"""Extract 2D position tracking data for a specific camera.
Expand Down
Loading