MeasurementMetric Class

The MeasurementMetric class is designed to quantify the difference between two Measurement objects. This is particularly useful for comparing a recorded movement against a reference movement.

__init__(self, first, second)

  • first (Measurement): The first measurement to compare.
  • second (Measurement): The second measurement to compare.

Properties

The class provides several properties that calculate different aspects of the difference between the two measurements:

  • alpha_metric: The sum of absolute differences between the alpha angles.
  • beta_metric: The sum of absolute differences between the beta angles.
  • orientation_metric: The sum of absolute differences between the normalized accelerometer vectors.
  • lateral_metric: The absolute difference in the lateral component of the orientation.
  • sagital_metric: The absolute difference in the sagittal component of the orientation.
  • forward_metric: A measure of how much the first measurement is bent forward compared to the second.
  • backward_metric: A measure of how much the first measurement is bent backward compared to the second.
  • metric: A composite metric that combines the alpha, beta, and orientation metrics into a single value.

Usage Example

from flexlib.models.flex_reader import FlexReader
from flexlib.models.measurement_metric import MeasurementMetric

# Load two recordings to compare
recording1 = FlexReader.parse('recording1.csv')
recording2 = FlexReader.parse('recording2.csv')

# Compare the first measurement of each recording
metric = MeasurementMetric(recording1.measurements[0], recording2.measurements[0])

print(f"Overall difference metric: {metric.metric}")
print(f"Difference in alpha angles: {metric.alpha_metric}")

# You can iterate through two recordings and compare them frame by frame
total_diff = 0
for m1, m2 in zip(recording1.measurements, recording2.measurements):
    total_diff += MeasurementMetric(m1, m2).metric

print(f"Total difference over recordings: {total_diff}")