Loading example data#

This example shows how to use the loader functions to load example data.

Laboratory data#

We provide a small subset of the TVS dataset of the Mobilise-D project as example data. The data only contains a small number of participants and only two (instead of the ten) laboratory tests of each participant. The data is stored in the examples/data folder of the repository in the Mobilise-D matlab format [1].

Dataset Class#

We provide a LabExampleDataset class to load the example data. This is the easiest way to access the example data and allows you to select and iterate over the data in an easy way.

from mobgap.data import LabExampleDataset

example_data = LabExampleDataset()

You can select the data you want using the get_subset method.

LabExampleDataset [6 groups/rows]

cohort participant_id time_measure test trial
0 HA 001 TimeMeasure1 Test5 Trial1
1 HA 001 TimeMeasure1 Test5 Trial2
2 HA 001 TimeMeasure1 Test11 Trial1
3 HA 002 TimeMeasure1 Test5 Trial1
4 HA 002 TimeMeasure1 Test5 Trial2
5 HA 002 TimeMeasure1 Test11 Trial1


Once you selected only a single row of the dataset (either by repeated get_subset or by iteration), you can load the actual data.

single_test = ha_example_data.get_subset(participant_id="002", test="Test5", trial="Trial2")
single_test

LabExampleDataset [1 groups/rows]

cohort participant_id time_measure test trial
0 HA 002 TimeMeasure1 Test5 Trial2


The raw IMU data:

acc_x acc_y acc_z gyr_x gyr_y gyr_z
time
2020-08-21 10:30:50.479000092+00:00 9.260327 0.031613 -2.605737 -0.1608 0.2119 -0.3052
2020-08-21 10:30:50.489000082+00:00 9.271626 0.018003 -2.595759 -0.2712 -0.0757 -0.4693
2020-08-21 10:30:50.499000072+00:00 9.275198 0.040968 -2.617954 0.1157 -0.0892 -0.2648
2020-08-21 10:30:50.509000063+00:00 9.265379 0.046116 -2.616274 -0.0091 -0.2005 -0.3278
2020-08-21 10:30:50.519000052+00:00 9.270444 0.070599 -2.586713 0.0524 -0.2733 -0.0965
... ... ... ... ... ... ...
2020-08-21 10:30:58.239000082+00:00 9.165407 0.123421 -2.804246 1.1903 0.7700 0.2111
2020-08-21 10:30:58.249000072+00:00 9.149437 0.103341 -2.766177 1.3227 0.9281 0.4836
2020-08-21 10:30:58.259000063+00:00 9.156892 0.093647 -2.780554 0.9306 1.3176 0.1052
2020-08-21 10:30:58.269000053+00:00 9.128226 0.076377 -2.787705 0.7761 1.6184 0.1962
2020-08-21 10:30:58.279000044+00:00 9.141961 0.075063 -2.800354 0.8296 1.6837 0.4381

781 rows × 6 columns



import matplotlib.pyplot as plt

imu_data.filter(like="gyr").plot()
plt.show()
01 loading example data

Test-level metadata:

single_test.metadata
MobilisedMetadata(start_date_time_iso='2020-08-21T12:30:50.479+02:00', time_zone='Europe/Berlin', sampling_rate_hz=100.0, reference_sampling_rate_hz=None)

Participant-level metadata:

single_test.participant_metadata
{'Height': 175.0, 'Weight': 82.0, 'SensorHeight': 108.0, 'Handedness': 'R', 'FootSize': 26.4, 'WalkingAid_01': 0.0, 'INDIP_DataUsed': 'All', 'SensorType_SU': 'MM+', 'SensorAttachment_SU': 'Body-Worn'}

You can also load the reference system data, by specifying the reference_system argument. All parameters related to the reference systems have a trailing underscore.

example_data_with_reference = LabExampleDataset(reference_system="Stereophoto")
single_trial_with_reference = example_data_with_reference.get_subset(
    cohort="HA", participant_id="002", test="Test5", trial="Trial2"
)
single_trial_with_reference.raw_reference_parameters_
{'lwb': [{'Start': 2.28, 'End': 5.39, 'StrideFrequency': 49.36164888953828, 'Cadence': 98.72329777907656, 'Duration': 3.11, 'Length': 4.113706815831932, 'LengthFeet': 3.990970590722213, 'WalkingSpeed': 1.3727010349957065, 'AverageStrideLength': 1.6696087035787461, 'NumberStrides': 4.0, 'TerminationReason': 'Pause', 'Break_Start': array([], dtype=float64), 'Break_End': array([], dtype=float64), 'Break_Number': array([], dtype=float64), 'Break_Duration': array([], dtype=float64), 'Turning_Flag': 0.0, 'Turn_Start': array([], dtype=float64), 'Turn_End': array([], dtype=float64), 'Turn_Duration': array([], dtype=float64), 'Turn_Number': array([], dtype=float64), 'Turn_Angle': array([], dtype=float64), 'Turn_NumberStrides': array([], dtype=float64), 'Turn_AngularVelocity': array([], dtype=float64), 'Turn_PeakAngularVelocity': array([], dtype=float64), 'Turn_MeanAngularVelocity': array([], dtype=float64), 'Turn_Length': array([], dtype=float64), 'Stride_Duration': array([1.28, 1.18, 1.16, 1.25]), 'Stride_Length': array([1.6130588 , 1.59518995, 1.65295507, 1.81723099]), 'Stride_Height': array([ 0.00258984,  0.0019533 , -0.00603833, -0.01509003]), 'Stride_Speed': array([1.26020219, 1.35185589, 1.42496127, 1.45378479]), 'Stride_TrunkElevationChange': array([0.015336  , 0.00167007, 0.00736727, 0.03591326]), 'Stance_Duration': array([0.85, 0.74, 0.75, 0.73]), 'Swing_Duration': array([0.43, 0.44, 0.41, 0.52]), 'SingleSupport_Duration': array([ nan, 0.87, 0.85, 0.93]), 'DoubleSupport_Duration': array([ nan, 0.31, 0.31, 0.32]), 'Stance_Length': array([0.22870683, 0.20503215, 0.2409645 , 0.24516186]), 'Swing_Length': array([1.37562656, 1.38826616, 1.40289499, 1.56628489]), 'Stance_Speed': array([0.26906685, 0.27707047, 0.32128599, 0.33583817]), 'Swing_Speed': array([3.19913153, 3.15515037, 3.42169511, 3.01208632]), 'SingleSupport_Length': array([], dtype=float64), 'DoubleSupport_Length': array([], dtype=float64), 'SingleSupport_Speed': array([], dtype=float64), 'DoubleSupport_Speed': array([], dtype=float64), 'Stride_InitialContacts': array([[2.28, 3.56],
       [2.96, 4.14],
       [3.56, 4.72],
       [4.14, 5.39]]), 'InitialContact_Event': array([2.28, 2.96, 3.56, 4.14, 4.72, 5.39]), 'InitialContact_LeftRight': array(['Left', 'Right', 'Left', 'Right', 'Left', 'Right'], dtype=object), 'FinalContact_Event': array([3.13, 3.7 , 4.31, 4.87]), 'FinalContact_LeftRight': array(['Left', 'Right', 'Left', 'Right'], dtype=object), 'Step_Duration': array([0.68, 0.6 , 0.58, 0.58, 0.67]), 'Step_Length': array([0.78400307, 0.79455085, 0.78468028, 0.83038434, 0.92008828]), 'Step_Length_Feet': array([0.79563927, 0.81137347, 0.78349089, 0.87076342, 0.95103785]), 'Step_Speed': array([1.15294569, 1.32425142, 1.35289704, 1.43169713, 1.37326609]), 'Step_TrunkElevationChange': array([0.00490894, 0.01042706, 0.01209712, 0.01946439, 0.01644887])}], 'wb': [{'Start': 2.28, 'End': 5.39, 'StrideFrequency': 49.36164888953828, 'Cadence': 98.72329777907656, 'Duration': 3.11, 'Length': 4.113706815831932, 'LengthFeet': 3.990970590722213, 'WalkingSpeed': 1.3727010349957065, 'AverageStrideLength': 1.6696087035787461, 'NumberStrides': 4.0, 'TerminationReason': 'Pause', 'Break_Start': array([], dtype=float64), 'Break_End': array([], dtype=float64), 'Break_Number': array([], dtype=float64), 'Break_Duration': array([], dtype=float64), 'Turning_Flag': 0.0, 'Turn_Start': array([], dtype=float64), 'Turn_End': array([], dtype=float64), 'Turn_Duration': array([], dtype=float64), 'Turn_Number': array([], dtype=float64), 'Turn_Angle': array([], dtype=float64), 'Turn_NumberStrides': array([], dtype=float64), 'Turn_AngularVelocity': array([], dtype=float64), 'Turn_PeakAngularVelocity': array([], dtype=float64), 'Turn_MeanAngularVelocity': array([], dtype=float64), 'Turn_Length': array([], dtype=float64), 'Turning_SharpTurn_Flag': array([], dtype=float64), 'Incline_Start': array([], dtype=float64), 'Incline_End': array([], dtype=float64), 'Incline_Duration': array([], dtype=float64), 'Incline_Number': array([], dtype=float64), 'Incline_NumberStrides': array([], dtype=float64), 'Incline_PositiveElevation': array([], dtype=float64), 'Incline_NegativeElevation': array([], dtype=float64), 'Stride_Duration': array([1.28, 1.18, 1.16, 1.25]), 'Stride_Length': array([1.6130588 , 1.59518995, 1.65295507, 1.81723099]), 'Stride_Height': array([ 0.00258984,  0.0019533 , -0.00603833, -0.01509003]), 'Stride_Speed': array([1.26020219, 1.35185589, 1.42496127, 1.45378479]), 'Stride_TrunkElevationChange': array([0.015336  , 0.00167007, 0.00736727, 0.03591326]), 'Stance_Duration': array([0.85, 0.74, 0.75, 0.73]), 'Swing_Duration': array([0.43, 0.44, 0.41, 0.52]), 'SingleSupport_Duration': array([ nan, 0.87, 0.85, 0.93]), 'DoubleSupport_Duration': array([ nan, 0.31, 0.31, 0.32]), 'Stance_Length': array([0.22870683, 0.20503215, 0.2409645 , 0.24516186]), 'Swing_Length': array([1.37562656, 1.38826616, 1.40289499, 1.56628489]), 'Stance_Speed': array([0.26906685, 0.27707047, 0.32128599, 0.33583817]), 'Swing_Speed': array([3.19913153, 3.15515037, 3.42169511, 3.01208632]), 'SingleSupport_Length': array([], dtype=float64), 'DoubleSupport_Length': array([], dtype=float64), 'SingleSupport_Speed': array([], dtype=float64), 'DoubleSupport_Speed': array([], dtype=float64), 'Stride_InitialContacts': array([[2.28, 3.56],
       [2.96, 4.14],
       [3.56, 4.72],
       [4.14, 5.39]]), 'InitialContact_Event': array([2.28, 2.96, 3.56, 4.14, 4.72, 5.39]), 'InitialContact_LeftRight': array(['Left', 'Right', 'Left', 'Right', 'Left', 'Right'], dtype=object), 'FinalContact_Event': array([3.13, 3.7 , 4.31, 4.87]), 'FinalContact_LeftRight': array(['Left', 'Right', 'Left', 'Right'], dtype=object), 'Step_Duration': array([0.68, 0.6 , 0.58, 0.58, 0.67]), 'Step_Length': array([0.78400307, 0.79455085, 0.78468028, 0.83038434, 0.92008828]), 'Step_Length_Feet': array([0.79563927, 0.81137347, 0.78349089, 0.87076342, 0.95103785]), 'Step_Speed': array([1.15294569, 1.32425142, 1.35289704, 1.43169713, 1.37326609]), 'Step_TrunkElevationChange': array([0.00490894, 0.01042706, 0.01209712, 0.01946439, 0.01644887])}]}

The data you can see above is the “raw” reference data. Including both the information for walking bouts and level-walking bouts. To access the data in format that can be directly compared to the output of the mobgap algorithms or used as input to algorithms further down the processing pipeline, you can use the reference_parameters_ attribute. If the data is extracted from the normal walking bouts or the level walking bouts is controlled by the reference_para_level parameter of the Dataset class (default is wb).

ref_paras = single_trial_with_reference.reference_parameters_

This attribute contains the data for the outputs of the various steps of the processing pipeline.

start end n_strides duration_s length_m avg_speed_mps avg_cadence_spm avg_stride_length_m termination_reason
wb_id
1 227 539 4 3.11 4.113707 1.372701 98.723298 1.669609 Pause


ic lr_label
wb_id step_id
1 0 227 left
1 295 right
2 355 left
3 413 right
4 471 left
5 538 right


start end duration_s angle_deg
wb_id turn_id


start end duration_s length_m speed_mps stance_time_s swing_time_s lr_label
wb_id s_id
1 0 227 356 1.28 1.613059 1.260202 0.85 0.43 left
1 295 414 1.18 1.595190 1.351856 0.74 0.44 right
2 355 472 1.16 1.652955 1.424961 0.75 0.41 left
3 413 539 1.25 1.817231 1.453785 0.73 0.52 right


Functional interface#

We can get the local path to the example data using get_all_lab_example_data_paths and then use load_mobilised_matlab_format to load the data.

[('HA', '001'), ('HA', '002'), ('MS', '001')]

Then we can select the participant we want to load.

Calling the loader function without any further arguments, will load the “SU” (normal lower-back sensor) only. The returned dictionary contains the test names as keys and the loaded data as MobilisedTestData objects. This allows for easy access to the data and metadata without traversing a nested data structure.

test_list = list(data.keys())
test_list
[('TimeMeasure1', 'Test5', 'Trial1'), ('TimeMeasure1', 'Test5', 'Trial2'), ('TimeMeasure1', 'Test11', 'Trial1')]

We can access the data of a single test by using the test name as key.

acc_x acc_y acc_z gyr_x gyr_y gyr_z
time
2020-08-21 10:50:00.388000011+00:00 9.506652 0.014721 -1.251681 0.7467 0.0411 -0.2598
2020-08-21 10:50:00.398000002+00:00 9.508550 -0.003995 -1.255758 0.7143 -0.2051 -0.2739
2020-08-21 10:50:00.407999992+00:00 9.522865 0.010142 -1.287486 0.5649 -0.0735 -0.4197
2020-08-21 10:50:00.417999983+00:00 9.509657 0.024649 -1.293958 0.3432 -0.0719 -0.2773
2020-08-21 10:50:00.427999973+00:00 9.498548 0.053690 -1.239242 0.2914 -0.0606 -0.3616
... ... ... ... ... ... ...
2020-08-21 10:52:40.177999973+00:00 9.561574 0.635956 0.264192 -0.1136 -0.9987 -0.4929
2020-08-21 10:52:40.187999964+00:00 9.588995 0.647659 0.269060 0.4132 -1.2662 -0.5346
2020-08-21 10:52:40.197999954+00:00 9.613343 0.659560 0.249716 0.5845 -1.0722 -0.2816
2020-08-21 10:52:40.207999945+00:00 9.617620 0.654173 0.214529 0.2529 -1.1498 -0.5514
2020-08-21 10:52:40.217999935+00:00 9.605131 0.654354 0.212877 0.2313 -1.6593 -0.4748

15984 rows × 6 columns



We can also access the metadata of the test.

MobilisedMetadata(start_date_time_iso='2020-08-21T12:50:00.388+02:00', time_zone='Europe/Berlin', sampling_rate_hz=100.0, reference_sampling_rate_hz=None)

To load reference data as well, we can use the reference_system argument. Note, that we don’t have a way to load the raw data of the reference system. We only load the calculated parameters.

The available reference systems will depend on the data.

The returned MobilisedTestData objects now contain the reference parameters.

And metadata about the reference system is available as well.

100.0

To parse the reference data into better data structures, we can use the parse_reference_parameters function.

They have the same structure the reference parameters of the Dataset class.

ReferenceData(wb_list=       start   end  ...  avg_stride_length_m  termination_reason
wb_id               ...
1        485  1131  ...             0.747408               Pause
2       1746  3554  ...             0.463619               Pause
3       6083  7708  ...             0.809791               Pause

[3 rows x 9 columns], ic_list=                 ic lr_label
wb_id step_id
1     0         485    right
      1         553     left
      2         619    right
      3         692     left
      4         742    right
      5         779     left
      6         862    right
      8        1016    right
      10       1130    right
2     11       1746    right
      12       1768     left
      13       1874     left
      14       2005    right
      15       2120     left
      16       2196    right
      18       2399    right
      19       2489     left
      20       2655    right
      21       2675     left
      22       2752     left
      23       2880    right
      25       3068    right
      26       3139     left
      27       3199    right
      28       3289     left
      30       3426     left
      32       3553     left
3     33       6083     left
      34       6151    right
      35       6199     left
      36       6277    right
      37       6358     left
      38       6425    right
      39       6480     left
      40       6534    right
      41       6630     left
      42       6758    right
      43       6785     left
      44       6847    right
      45       6919     left
      46       6985    right
      47       7065     left
      48       7112    right
      49       7228    right
      51       7476    right
      53       7707    right, turn_parameters=               start    end  duration_s   angle_deg
wb_id turn_id
1.0   0         5.22  10.49        4.27 -135.426119
3.0   1        61.32  64.90        2.58 -147.071110
      2        68.82  72.22        2.40  149.190550, stride_parameters=            start   end  duration_s  ...  stance_time_s  swing_time_s  lr_label
wb_id s_id                           ...
1     0       485   620        1.34  ...           0.88          0.46     right
      1       553   693        1.39  ...           0.84          0.55      left
      2       619   743        1.23  ...           0.86          0.37     right
      3       692   780         NaN  ...            NaN           NaN      left
      4       742   863        1.20  ...            NaN           NaN     right
      6       862  1017        1.54  ...           1.15          0.39     right
      8      1016  1131        1.14  ...           0.56          0.58     right
2     9      1746  2006        2.59  ...           1.43          1.16     right
      10     1768  1875         NaN  ...            NaN           NaN      left
      11     1874  2121        2.46  ...           1.07          1.39      left
      12     2005  2197        1.91  ...           1.30          0.61     right
      14     2196  2400        2.03  ...           1.40          0.63     right
      16     2399  2656        2.56  ...           1.18          1.38     right
      17     2489  2676         NaN  ...            NaN           NaN      left
      18     2655  2881        2.25  ...           0.91          1.34     right
      19     2675  2753        0.77  ...           0.16          0.61      left
      21     2880  3069        1.88  ...           1.13          0.75     right
      23     3068  3200        1.31  ...           1.00          0.31     right
      24     3139  3290        1.50  ...           0.65          0.85      left
      26     3289  3427        1.37  ...            NaN           NaN      left
      28     3426  3554        1.27  ...           0.91          0.36      left
3     29     6083  6200        1.16  ...           0.84          0.32      left
      30     6151  6278         NaN  ...            NaN           NaN     right
      31     6199  6359        1.59  ...           0.83          0.76      left
      32     6277  6426        1.48  ...           0.89          0.59     right
      33     6358  6481        1.22  ...           0.45          0.77      left
      34     6425  6535        1.09  ...           0.71          0.38     right
      35     6480  6631        1.50  ...           1.28          0.22      left
      36     6534  6759        2.24  ...           1.14          1.10     right
      37     6630  6786        1.55  ...           0.99          0.56      left
      38     6758  6848        0.89  ...           0.44          0.45     right
      39     6785  6920        1.34  ...           0.78          0.56      left
      40     6847  6986        1.38  ...           0.89          0.49     right
      41     6919  7066        1.46  ...           0.83          0.63      left
      42     6985  7113        1.27  ...           0.87          0.40     right
      44     7112  7229         NaN  ...            NaN           NaN     right
      45     7228  7477        2.48  ...           1.97          0.51     right
      47     7476  7708        2.31  ...           1.03          1.28     right

[38 rows x 8 columns])

Total running time of the script: (0 minutes 3.903 seconds)

Estimated memory usage: 20 MB

Gallery generated by Sphinx-Gallery