encoder#

Wheel encoder over USB-serial.

Subclass of mesofield.devices.base.BaseSerialDevice that reads integer click counts (one per line) from an Arduino-style firmware. Emitted payload is the raw click count (int); speed and distance are derived in analysis from the wheel diameter and CPR carried in the device config.

The producer (SerialWorker) writes a CSV; the matching ingest-side parser (WheelEncoder) lives at the bottom of this module so producer and parser sit in the same file. SerialWorker.Parser resolves to WheelEncoder for manifest-driven dispatch.

Constructor preserves the legacy keyword API (serial_port, baud_rate, sample_interval, wheel_diameter, cpr, development_mode) for compatibility with mesofield.hardware.

class mesofield.devices.encoder.SerialWorker[source]#

Bases: BaseSerialDevice

Arduino wheel-encoder device.

__init__(cfg=None, serial_port=None, baud_rate=None, sample_interval=None, wheel_diameter=None, cpr=None, development_mode=None, **kwargs)[source]#
Parameters:
  • cfg (Dict[str, Any] | None)

  • serial_port (str | None)

  • baud_rate (int | None)

  • sample_interval (int | None)

  • wheel_diameter (float | None)

  • cpr (int | None)

  • development_mode (bool | None)

  • kwargs (Any)

Return type:

None

parse_line(line)[source]#

Decode one raw serial line into (payload, ts) or None.

Parameters:

line (bytes)

Return type:

Tuple[int, float | None] | None

Parser#

alias of WheelEncoder

class mesofield.devices.encoder.WheelEncoder[source]#

Bases: TimeseriesSource

Load wheel encoder streams recorded alongside nidaq pulses.

The raw CSV emitted by the behavioral rig contains incremental click counts, elapsed time in seconds, and instantaneous speed estimates. The loader converts this information into a strictly increasing timeline anchored to acquisition start, computes cumulative distance, and exposes rich metadata for downstream alignment against the nidaq-driven master clock.

build_timeseries(path, *, context=None)[source]#

Return (timeline, value, meta).

Parameters:
  • path (Path)

  • context (SourceContext | None)

Return type:

tuple[np.ndarray, pd.DataFrame, dict]