Exercise: Segmenting TimeSeries

7.2.5.4. Exercise: Segmenting TimeSeries#

Using this dataset of kinetic data during wheelchair propulsion:

import kineticstoolkit.lab as ktk

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

Write a code that generates a list of three floats named peak_Mz, that includes the peak moment (Moments[:, 2]) during each of the three first pushes.

Hide code cell content
import numpy as np

# Init the list
peak_Mz = []

# Fill the list
for i_push in range(3):
    # Extract a new TimeSeries that only spans this push
    sub_ts = ts.get_ts_between_events("push", "recovery", i_push, i_push)

    # Calculate the peak moment on this new TimeSeries and happen it to
    # the list
    peak_Mz.append(np.max(sub_ts.data["Moments"][:, 2]))

# Print it!
print(peak_Mz)
[18.65, 16.58, 13.7]