7.2.4.1. Exercise: Indexing TimeSeries#

Using the following data:

import kineticstoolkit.lab as ktk
import matplotlib.pyplot as plt

ts = ktk.load(ktk.doc.download("kinetics_wheelchair_propulsion_events.ktk.zip"))
ts.plot()
_images/3affa6def59f4dcc067528e44341f1c321bb6e3a9c2f10b359457f8a76d926c2.png

Write a code that counts the number of pushes and recoveries, and that generates the following lists:

push_times  # list[float]: List of times corresponding to each push event
recovery_times  # list[float]: List of times corresponding to each recovery event
Hide code cell content
# Create empty lists
push_times = []
recovery_times = []

# Count the number of pushes/recoveries
n_pushes = ts.count_events("push")
n_recoveries = ts.count_events("recovery")

# Find the push times
for i_push in range(n_pushes):
    index = ts.get_index_at_event("push", occurrence=i_push) 
    push_times.append(ts.time[index])

# Find the recovery times
for i_recovery in range(n_recoveries):
    index = ts.get_index_at_event("recovery", occurrence=i_recovery)
    recovery_times.append(ts.time[index])

# Print it!
print("Push times:", push_times)
print("Recovery times:", recovery_times)
Push times: [8.558333333333334, 10.5, 11.779166666666667, 13.391666666666667, 14.858333333333333]
Recovery times: [9.929166666666667, 11.120833333333334, 12.329166666666667, 13.879166666666666, 15.3]