Event Detection

To detect gait events Gaitalytics currently only supports a marker based function based on Zeni et al.[1] paper. Further it provides helping functions to find errors in the detected gait events and store the events into an existing c3d file.

Detection

Gaitalytics provides a function to detect the gait events in a c3d file gaitalytics.api.load_c3d_trial(). Following snipped illustrates the usage of the detection function:

from gaitalytics import api

config = api.load_config("./config.yaml")
trial = api.load_c3d_trial("./example.c3d", config)
events = api.detect_events(trial, config)

Note

The detection function is based on the assumption that the markers are correctly placed on the body. Through the configuration users can map the correct marker names to the internal marker names.

Following internal markers are used for the detection: l_heel, r_heel, l_toe, r_toe, sacrum or l_post_hip and r_post_hip.

The function returns a pandas[2] DataFrame with the following columns:

Column

Data

Description

time

float

Time in seconds

label

string

Event label (either ‘Foot Strike’ or ‘Foot Off’)

context

string

Context of the event (either ‘Left’ or ‘Right’)

icon_id

int

Icon ID of the event (either 1 or 2)

Hint

The marker-based function is uses on a peak detection to find the gait events. It allows to fine-tune the detection by changing the threshold and the minimum distance between two events through kwargs. Look here for more information: gaitalytics.events.MarkerEventDetection

Checking

The function gaitalytics.api.check_events() can be used to check the detected events for errors in the sequence. To check the detected events for errors the following function can be used:

from gaitalytics import api

events = api.detect_events(trial)
try:
    api.check_events(events)
except ValueError as e:
    print(f"Event errors {e}")

The function will check the sequence of the detected events and raise an error if the sequence is not correct.

Hint

The ValueError will contain the error message which will help to identify the time range of the error.

Storing

Using the gaitalytics.api.write_events_to_c3d() function the detected events can be stored into the c3d file. The function can be used as follows:

from gaitalytics import api

events = api.detect_events(trial)
api.write_events_to_c3d("./example.c3d", events, './example_with_events.c3d')

The function will reload the example.c3d file and store the detected events into the new file example_with_events.c3d. Alternatively the function can be used to store the events into the existing c3d file.

from gaitalytics import api

events = api.detect_events(trial)
api.write_events_to_c3d("./example.c3d", events, './example.c3d')

Note

Gaitalytics allows to directly store the events in the existing gaitalytics.model.Trial object. Nevertheless it is recommended to manually check and correct the events before continuing with the processing pipeline.

References