Table of Contents

Logging and Analysis

This article covers how data from the device is logged to disk, and how to read and plot the logged data with harp-python.

Log Data

Data from the device is logged by the DeviceDataWriter operator in the Harp device pattern, which saves raw data from all device registers in the Harp binary format to the folder set in its Path property:

Harp Device Pattern

While the workflow is running, registers are logged as the device produces messages (events and command echoes). Two properties of the Device operator are also important for logging:

  • DumpRegisters - Enabled by default, this property logs a read of every register when the device initializes, capturing the initial state of the device at the start of the experiment.
  • Heartbeat - Disabled by default, enable it to regularly log the device's hardware timestamp. The Behavior board's own 1 kHz AnalogData stream can perform the same function while it is enabled.
Warning

The register dump can be used as an approximate start time for the workflow or experiment, but keep in mind that other devices in the workflow may initialize at a different time.

Analyze Data

The harp-python library imports data stored in the Harp binary format as pandas DataFrames, which can then be analyzed with any pandas compatible plotting or analysis library.

The following example demonstrates how to read and plot data from the DigitalInputState register.

Note

This example requires a Python environment with harp-python and matplotlib installed.

# Import the dependencies
import harp
import matplotlib.pyplot as plt

# Create a device object by loading the saved folder
device = harp.create_reader("./Data/Behavior.harp")

# Read data from a specific register
digital_input_state_df = device.DigitalInputState.read()

# Inspect DataFrame
print(digital_input_state_df.head())

# Plot the poke beam states over time
digital_input_state_df.plot()
plt.show()


Last updated with:
Hardware v2.1
Firmware v3.3
Bonsai Package v0.2