Show the versions of all the software that is installed into the virutalenv.
%matplotlib inline
import os
import pandas
import numpy as np
from numpy import deg2rad
from matplotlib.pyplot import rcParams
from gaitanalysis import gait, controlid, motek
from dtk import process
import sys
sys.path.append('../src')
import utils
PATHS = utils.config_paths()
Obinna provided me with some normal walking data. We exported the data from the D-Flow Motion Capture Module and included the HMB outputs. D-Flow sets missing values from HBM data to 0.000000
in the CSV file so I replace them with NA
when loading. I also set the resulting data frame's index to the TimeStamp
column.
obinna = pandas.read_csv(os.path.join(PATHS['raw_data_dir'], 'T001', 'mocap-001.txt'),
delimiter='\t', index_col="TimeStamp", na_values='0.000000')
obinna.interpolate(method='index', inplace=True)
The data frame has quite a few time series which are all floats except for the FrameNumber
column which is an integer.
obinna
FrameNumber | LHEAD.PosX | LHEAD.PosY | LHEAD.PosZ | THEAD.PosX | THEAD.PosY | THEAD.PosZ | RHEAD.PosX | RHEAD.PosY | RHEAD.PosZ | ... | LFootPronation.Pow | RToeFlexion.Ang | RToeFlexion.Mom | RToeFlexion.Pow | LToeFlexion.Ang | LToeFlexion.Mom | LToeFlexion.Pow | HBM.COM.X | HBM.COM.Y | HBM.COM.Z | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
TimeStamp | |||||||||||||||||||||
534.133513 | 1505 | -0.132270 | 1.801454 | -0.109339 | -0.033648 | 1.877124 | -0.079078 | 0.068643 | 1.811719 | -0.079664 | ... | 2.065873 | -46.975441 | NaN | NaN | -39.368320 | NaN | NaN | -0.014530 | 1.053222 | 0.001445 |
534.143432 | 1506 | -0.133878 | 1.802301 | -0.110094 | -0.035053 | 1.877750 | -0.079742 | 0.066475 | 1.812262 | -0.079780 | ... | 3.383072 | -50.029976 | NaN | NaN | -37.450680 | NaN | NaN | -0.016157 | 1.053047 | 0.000089 |
534.153492 | 1507 | -0.135803 | 1.803772 | -0.112392 | -0.036993 | 1.878395 | -0.079790 | 0.064971 | 1.813441 | -0.078906 | ... | 4.533013 | -52.151505 | NaN | NaN | -34.989468 | NaN | NaN | -0.017747 | 1.053069 | -0.001315 |
534.163440 | 1508 | -0.137673 | 1.804514 | -0.111986 | -0.038249 | 1.879466 | -0.079769 | 0.063120 | 1.814527 | -0.078551 | ... | 5.676908 | -52.940426 | NaN | NaN | -32.301228 | NaN | NaN | -0.019305 | 1.053289 | -0.002729 |
534.173667 | 1509 | -0.139050 | 1.805609 | -0.112472 | -0.040130 | 1.881146 | -0.079801 | 0.062041 | 1.815377 | -0.077297 | ... | 5.926370 | -52.130554 | NaN | NaN | -29.346273 | NaN | NaN | -0.020829 | 1.053700 | -0.004117 |
534.183657 | 1510 | -0.139708 | 1.806518 | -0.112732 | -0.042013 | 1.882077 | -0.080077 | 0.060523 | 1.816613 | -0.077110 | ... | 4.459104 | -49.897892 | NaN | NaN | -26.453875 | NaN | NaN | -0.022315 | 1.054292 | -0.005445 |
534.193694 | 1511 | -0.141454 | 1.807322 | -0.112297 | -0.042503 | 1.882891 | -0.080069 | 0.058857 | 1.818532 | -0.077116 | ... | 2.974851 | -46.771679 | NaN | NaN | -23.841812 | NaN | NaN | -0.023763 | 1.055050 | -0.006681 |
534.203663 | 1512 | -0.142636 | 1.808365 | -0.113005 | -0.044488 | 1.884405 | -0.080009 | 0.057965 | 1.819803 | -0.076936 | ... | 2.182817 | -43.236565 | NaN | NaN | -21.202551 | NaN | NaN | -0.025164 | 1.055957 | -0.007800 |
534.213693 | 1513 | -0.143685 | 1.809031 | -0.113113 | -0.045947 | 1.885674 | -0.080392 | 0.056863 | 1.821177 | -0.076052 | ... | 1.854993 | -39.684643 | NaN | NaN | -18.382496 | NaN | NaN | -0.026514 | 1.057007 | -0.008782 |
534.223640 | 1514 | -0.143985 | 1.809994 | -0.113110 | -0.046508 | 1.887131 | -0.080580 | 0.055989 | 1.823080 | -0.074953 | ... | 1.599045 | -36.405174 | NaN | NaN | -15.448208 | NaN | NaN | -0.027805 | 1.058193 | -0.009624 |
534.233744 | 1515 | -0.144588 | 1.811345 | -0.113157 | -0.046900 | 1.888166 | -0.080202 | 0.055429 | 1.824419 | -0.074824 | ... | 1.180318 | -33.498482 | NaN | NaN | -12.492783 | NaN | NaN | -0.029026 | 1.059506 | -0.010328 |
534.243690 | 1516 | -0.145197 | 1.811921 | -0.112521 | -0.048058 | 1.889150 | -0.080480 | 0.055031 | 1.825913 | -0.074124 | ... | 0.965360 | -30.991793 | NaN | NaN | -9.659924 | NaN | NaN | -0.030168 | 1.060929 | -0.010896 |
534.253640 | 1517 | -0.145517 | 1.812781 | -0.112328 | -0.048858 | 1.890182 | -0.079658 | 0.054279 | 1.826865 | -0.073447 | ... | 0.930330 | -28.922611 | NaN | NaN | -7.054570 | NaN | NaN | -0.031227 | 1.062439 | -0.011329 |
534.263661 | 1518 | -0.145848 | 1.813747 | -0.112466 | -0.049118 | 1.891092 | -0.079216 | 0.054142 | 1.828067 | -0.072090 | ... | 0.720214 | -27.278940 | NaN | NaN | -4.669940 | NaN | NaN | -0.032196 | 1.064009 | -0.011634 |
534.273497 | 1519 | -0.143298 | 1.814136 | -0.113542 | -0.049237 | 1.892126 | -0.079119 | 0.054025 | 1.828738 | -0.071170 | ... | 0.412252 | -25.979029 | NaN | NaN | -2.455390 | NaN | NaN | -0.033071 | 1.065621 | -0.011822 |
534.283495 | 1520 | -0.143277 | 1.814736 | -0.112973 | -0.049289 | 1.892783 | -0.078266 | 0.053771 | 1.829103 | -0.070089 | ... | 0.234231 | -24.996931 | NaN | NaN | -0.341246 | NaN | NaN | -0.033848 | 1.067254 | -0.011906 |
534.293643 | 1521 | -0.143238 | 1.815121 | -0.112337 | -0.049020 | 1.893551 | -0.077707 | 0.053830 | 1.829711 | -0.068561 | ... | 0.113300 | -24.366146 | NaN | NaN | 1.728542 | NaN | NaN | -0.034531 | 1.068885 | -0.011886 |
534.303642 | 1522 | -0.142581 | 1.815544 | -0.112299 | -0.048954 | 1.893701 | -0.077583 | 0.053847 | 1.830178 | -0.067981 | ... | -0.097379 | -24.068581 | NaN | NaN | 3.671178 | NaN | NaN | -0.035132 | 1.070490 | -0.011765 |
534.313709 | 1523 | -0.142515 | 1.815684 | -0.111864 | -0.048337 | 1.894145 | -0.076873 | 0.053989 | 1.830355 | -0.066361 | ... | -0.232566 | -24.000193 | NaN | NaN | 5.378886 | NaN | NaN | -0.035662 | 1.072049 | -0.011555 |
534.323697 | 1524 | -0.142215 | 1.815694 | -0.110875 | -0.047747 | 1.894457 | -0.075647 | 0.054427 | 1.830587 | -0.064879 | ... | -0.377381 | -24.078394 | NaN | NaN | 6.823772 | NaN | NaN | -0.036130 | 1.073539 | -0.011263 |
534.333423 | 1525 | -0.141278 | 1.816072 | -0.110652 | -0.047259 | 1.894362 | -0.074738 | 0.055059 | 1.830601 | -0.064468 | ... | -0.693644 | -24.277405 | NaN | NaN | 7.996513 | NaN | NaN | -0.036537 | 1.074939 | -0.010880 |
534.343719 | 1526 | -0.140918 | 1.816006 | -0.110396 | -0.046574 | 1.894471 | -0.074743 | 0.055621 | 1.829965 | -0.062918 | ... | -0.958761 | -24.471704 | NaN | NaN | 8.942541 | NaN | NaN | -0.036882 | 1.076233 | -0.010399 |
534.353681 | 1527 | -0.139926 | 1.815831 | -0.109601 | -0.045448 | 1.894531 | -0.074109 | 0.055796 | 1.830107 | -0.061574 | ... | -1.146872 | -24.558933 | NaN | NaN | 9.710622 | NaN | NaN | -0.037175 | 1.077406 | -0.009822 |
534.363493 | 1528 | -0.139096 | 1.816058 | -0.109017 | -0.044800 | 1.894454 | -0.073711 | 0.056570 | 1.829703 | -0.060905 | ... | -1.273337 | -24.577999 | NaN | NaN | 10.271618 | NaN | NaN | -0.037416 | 1.078449 | -0.009155 |
534.373649 | 1529 | -0.138265 | 1.815972 | -0.108664 | -0.044239 | 1.894178 | -0.073165 | 0.057456 | 1.829331 | -0.059610 | ... | -1.183985 | -24.528011 | NaN | NaN | 10.613199 | NaN | NaN | -0.037607 | 1.079350 | -0.008400 |
534.383530 | 1530 | -0.137640 | 1.815984 | -0.108724 | -0.043590 | 1.893796 | -0.072359 | 0.058234 | 1.829058 | -0.058395 | ... | -0.708953 | -24.351715 | NaN | NaN | 10.795732 | NaN | NaN | -0.037755 | 1.080099 | -0.007556 |
534.393686 | 1531 | -0.136145 | 1.815438 | -0.108581 | -0.042212 | 1.893394 | -0.071490 | 0.058906 | 1.828231 | -0.057492 | ... | -0.216560 | -24.042589 | NaN | NaN | 10.861400 | NaN | NaN | -0.037860 | 1.080690 | -0.006633 |
534.403480 | 1532 | -0.135189 | 1.815102 | -0.107230 | -0.041250 | 1.893008 | -0.070969 | 0.059599 | 1.827781 | -0.056504 | ... | 0.202771 | -23.660881 | NaN | NaN | 10.798417 | NaN | NaN | -0.037917 | 1.081122 | -0.005640 |
534.413413 | 1533 | -0.134256 | 1.814230 | -0.106162 | -0.040538 | 1.892240 | -0.069989 | 0.060727 | 1.827022 | -0.055097 | ... | 0.557149 | -23.244177 | NaN | NaN | 10.608053 | NaN | NaN | -0.037921 | 1.081394 | -0.004585 |
534.423518 | 1534 | -0.133807 | 1.813996 | -0.105780 | -0.039747 | 1.891335 | -0.068912 | 0.061392 | 1.826060 | -0.053835 | ... | 0.624595 | -22.741602 | NaN | NaN | 10.305191 | NaN | NaN | -0.037873 | 1.081501 | -0.003468 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
589.422392 | 7034 | -0.110434 | 1.812354 | -0.189596 | -0.016302 | 1.881904 | -0.137912 | 0.087572 | 1.819738 | -0.144660 | ... | -0.220533 | -56.841766 | NaN | NaN | -6.304430 | NaN | NaN | 0.003900 | 1.048431 | -0.128751 |
589.432394 | 7035 | -0.111860 | 1.813508 | -0.189268 | -0.017174 | 1.883068 | -0.137643 | 0.086072 | 1.821065 | -0.143971 | ... | -0.391485 | -56.047276 | NaN | NaN | -5.680514 | NaN | NaN | 0.002323 | 1.049092 | -0.130223 |
589.442406 | 7036 | -0.112725 | 1.814326 | -0.189260 | -0.018626 | 1.883885 | -0.137256 | 0.085081 | 1.822367 | -0.143879 | ... | -0.813999 | -53.603996 | NaN | NaN | -5.942255 | NaN | NaN | 0.000756 | 1.049870 | -0.131638 |
589.452389 | 7037 | -0.113964 | 1.815681 | -0.188951 | -0.019876 | 1.885726 | -0.137810 | 0.084114 | 1.824068 | -0.144031 | ... | -1.381959 | -50.001862 | NaN | NaN | -7.264087 | NaN | NaN | -0.000800 | 1.050750 | -0.132969 |
589.462386 | 7038 | -0.114789 | 1.817424 | -0.189346 | -0.021066 | 1.886915 | -0.138083 | 0.082920 | 1.825405 | -0.143763 | ... | -2.487700 | -45.847130 | NaN | NaN | -9.638927 | NaN | NaN | -0.002338 | 1.051722 | -0.134189 |
589.472410 | 7039 | -0.116014 | 1.818156 | -0.189532 | -0.022269 | 1.888030 | -0.137838 | 0.081777 | 1.826894 | -0.143771 | ... | -4.440155 | -41.612053 | NaN | NaN | -12.961330 | NaN | NaN | -0.003848 | 1.052783 | -0.135279 |
589.482401 | 7040 | -0.116818 | 1.819201 | -0.189215 | -0.023223 | 1.889504 | -0.137754 | 0.080816 | 1.828097 | -0.144067 | ... | -6.727804 | -37.650047 | NaN | NaN | -17.088379 | NaN | NaN | -0.005323 | 1.053928 | -0.136228 |
589.492367 | 7041 | -0.117887 | 1.820205 | -0.189482 | -0.023975 | 1.890619 | -0.137587 | 0.080025 | 1.829252 | -0.143554 | ... | -9.000084 | -34.113041 | NaN | NaN | -21.853935 | NaN | NaN | -0.006748 | 1.055155 | -0.137031 |
589.502350 | 7042 | -0.118487 | 1.821558 | -0.189068 | -0.025096 | 1.891718 | -0.137650 | 0.079119 | 1.830706 | -0.142989 | ... | -7.654738 | -31.072878 | NaN | NaN | -26.119356 | NaN | NaN | -0.008101 | 1.056459 | -0.137699 |
589.512359 | 7043 | -0.119351 | 1.821862 | -0.189261 | -0.026175 | 1.893000 | -0.137785 | 0.078221 | 1.831785 | -0.142519 | ... | -1.922539 | -28.575809 | NaN | NaN | -28.083235 | NaN | NaN | -0.009354 | 1.057827 | -0.138254 |
589.522299 | 7044 | -0.120080 | 1.822899 | -0.188888 | -0.026986 | 1.894378 | -0.137797 | 0.077643 | 1.833155 | -0.142681 | ... | 2.181922 | -26.579165 | NaN | NaN | -27.428308 | NaN | NaN | -0.010499 | 1.059250 | -0.138709 |
589.532387 | 7045 | -0.120606 | 1.824318 | -0.189311 | -0.027115 | 1.894928 | -0.137815 | 0.077199 | 1.833911 | -0.142289 | ... | 3.926579 | -25.072380 | NaN | NaN | -24.990438 | NaN | NaN | -0.011547 | 1.060720 | -0.139064 |
589.542390 | 7046 | -0.120962 | 1.825099 | -0.189862 | -0.028191 | 1.895954 | -0.137854 | 0.076647 | 1.834778 | -0.141514 | ... | 4.191561 | -24.012852 | NaN | NaN | -21.390352 | NaN | NaN | -0.012507 | 1.062227 | -0.139316 |
589.552448 | 7047 | -0.121881 | 1.826217 | -0.189706 | -0.028472 | 1.896871 | -0.137213 | 0.076112 | 1.835791 | -0.141235 | ... | 3.464185 | -23.296999 | NaN | NaN | -17.039520 | NaN | NaN | -0.013388 | 1.063762 | -0.139469 |
589.562408 | 7048 | -0.122375 | 1.826946 | -0.189425 | -0.028817 | 1.897697 | -0.137450 | 0.075786 | 1.836474 | -0.141028 | ... | 2.430488 | -22.865902 | NaN | NaN | -12.384034 | NaN | NaN | -0.014194 | 1.065308 | -0.139531 |
589.572394 | 7049 | -0.122455 | 1.827309 | -0.189343 | -0.029146 | 1.898285 | -0.137196 | 0.075489 | 1.837110 | -0.140653 | ... | 1.963694 | -22.691011 | NaN | NaN | -7.857075 | NaN | NaN | -0.014933 | 1.066842 | -0.139501 |
589.582305 | 7050 | -0.122641 | 1.827561 | -0.188961 | -0.029615 | 1.898856 | -0.136883 | 0.075117 | 1.837551 | -0.140264 | ... | 1.962707 | -22.728130 | NaN | NaN | -3.742842 | NaN | NaN | -0.015611 | 1.068345 | -0.139379 |
589.592443 | 7051 | -0.123032 | 1.827980 | -0.189219 | -0.029805 | 1.899140 | -0.136810 | 0.074849 | 1.837922 | -0.140103 | ... | 2.046845 | -22.904570 | NaN | NaN | -0.166500 | NaN | NaN | -0.016236 | 1.069795 | -0.139164 |
589.602331 | 7052 | -0.122736 | 1.828317 | -0.189066 | -0.030102 | 1.899006 | -0.136494 | 0.074649 | 1.838273 | -0.139404 | ... | 2.001647 | -23.141310 | NaN | NaN | 2.895298 | NaN | NaN | -0.016812 | 1.071165 | -0.138854 |
589.612296 | 7053 | -0.123120 | 1.828645 | -0.188663 | -0.030392 | 1.899454 | -0.136414 | 0.074425 | 1.838386 | -0.138607 | ... | 1.922745 | -23.343094 | NaN | NaN | 5.491027 | NaN | NaN | -0.017343 | 1.072436 | -0.138443 |
589.622388 | 7054 | -0.123389 | 1.828841 | -0.188417 | -0.030517 | 1.899539 | -0.136426 | 0.074406 | 1.838534 | -0.138415 | ... | 1.905353 | -23.456013 | NaN | NaN | 7.660960 | NaN | NaN | -0.017838 | 1.073591 | -0.137936 |
589.632403 | 7055 | -0.123163 | 1.829004 | -0.187917 | -0.030430 | 1.899557 | -0.135989 | 0.074260 | 1.838401 | -0.137966 | ... | 1.800728 | -23.357525 | NaN | NaN | 9.420395 | NaN | NaN | -0.018303 | 1.074623 | -0.137339 |
589.642409 | 7056 | -0.122996 | 1.828745 | -0.187454 | -0.030514 | 1.899354 | -0.135156 | 0.074200 | 1.838372 | -0.137471 | ... | 1.693812 | -22.706345 | NaN | NaN | 10.658075 | NaN | NaN | -0.018739 | 1.075529 | -0.136657 |
589.652374 | 7057 | -0.123025 | 1.828621 | -0.187494 | -0.030469 | 1.899106 | -0.134692 | 0.074152 | 1.838053 | -0.136821 | ... | 1.619555 | -21.229019 | NaN | NaN | 11.344160 | NaN | NaN | -0.019139 | 1.076305 | -0.135892 |
589.662424 | 7058 | -0.123245 | 1.828122 | -0.187260 | -0.030598 | 1.898922 | -0.133738 | 0.074043 | 1.837757 | -0.136489 | ... | 1.477949 | -19.278042 | NaN | NaN | 11.628417 | NaN | NaN | -0.019501 | 1.076933 | -0.135047 |
589.672456 | 7059 | -0.123188 | 1.827602 | -0.186850 | -0.030580 | 1.898149 | -0.133114 | 0.073948 | 1.837064 | -0.135561 | ... | 1.428874 | -17.617577 | NaN | NaN | 11.598853 | NaN | NaN | -0.019828 | 1.077383 | -0.134136 |
589.682408 | 7060 | -0.122897 | 1.827016 | -0.186163 | -0.030525 | 1.897675 | -0.132865 | 0.074103 | 1.836449 | -0.134997 | ... | 1.504087 | -16.510597 | NaN | NaN | 11.284647 | NaN | NaN | -0.020115 | 1.077641 | -0.133175 |
589.692394 | 7061 | -0.122882 | 1.826221 | -0.185939 | -0.030243 | 1.896617 | -0.132738 | 0.074387 | 1.835515 | -0.134662 | ... | 1.412131 | -15.751484 | NaN | NaN | 10.748206 | NaN | NaN | -0.020354 | 1.077710 | -0.132171 |
589.702367 | 7062 | -0.121750 | 1.825115 | -0.184070 | -0.029969 | 1.895315 | -0.132254 | 0.074799 | 1.834538 | -0.134112 | ... | 1.255649 | -15.047626 | NaN | NaN | 10.080706 | NaN | NaN | -0.020537 | 1.077600 | -0.131123 |
589.712359 | 7063 | -0.121344 | 1.824303 | -0.184438 | -0.029405 | 1.894667 | -0.131498 | 0.074964 | 1.833500 | -0.133638 | ... | 1.266885 | -14.239575 | NaN | NaN | 9.449660 | NaN | NaN | -0.020659 | 1.077320 | -0.130033 |
5559 rows × 617 columns
For this analysis we are only interested in the vertical ground reaction forces, the joint angles, the joint angular rates, and the joint torques. The D-Flow HBM computations give the angles and the torques. We will compute the rates ourselves. Here is a list of all of the vertical GRF, joint angle, and joint moment data.
[col for col in obinna.columns if col.endswith('.Ang') or col.endswith('ForY') or col.endswith('.Mom')]
['FP1.ForY', 'FP2.ForY', 'PelvisX.Ang', 'PelvisX.Mom', 'PelvisY.Ang', 'PelvisY.Mom', 'PelvisZ.Ang', 'PelvisZ.Mom', 'PelvisYaw.Ang', 'PelvisYaw.Mom', 'PelvisForwardPitch.Ang', 'PelvisForwardPitch.Mom', 'PelvisRightRoll.Ang', 'PelvisRightRoll.Mom', 'TrunkFlexion.Ang', 'TrunkFlexion.Mom', 'TrunkRightBend.Ang', 'TrunkRightBend.Mom', 'TrunkLeftTwist.Ang', 'TrunkLeftTwist.Mom', 'HeadFlexion.Ang', 'HeadFlexion.Mom', 'HeadRightBend.Ang', 'HeadRightBend.Mom', 'HeadLeftTwist.Ang', 'HeadLeftTwist.Mom', 'RShoulderUp.Ang', 'RShoulderUp.Mom', 'LShoulderUp.Ang', 'LShoulderUp.Mom', 'RShoulderForward.Ang', 'RShoulderForward.Mom', 'LShoulderForward.Ang', 'LShoulderForward.Mom', 'RShoulderInward.Ang', 'RShoulderInward.Mom', 'LShoulderInward.Ang', 'LShoulderInward.Mom', 'RShoulderFlexion.Ang', 'RShoulderFlexion.Mom', 'LShoulderFlexion.Ang', 'LShoulderFlexion.Mom', 'RShoulderAbduction.Ang', 'RShoulderAbduction.Mom', 'LShoulderAbduction.Ang', 'LShoulderAbduction.Mom', 'RShoulderInternalRotation.Ang', 'RShoulderInternalRotation.Mom', 'LShoulderInternalRotation.Ang', 'LShoulderInternalRotation.Mom', 'RElbowFlexion.Ang', 'RElbowFlexion.Mom', 'LElbowFlexion.Ang', 'LElbowFlexion.Mom', 'RForeArmPronation.Ang', 'RForeArmPronation.Mom', 'LForeArmPronation.Ang', 'LForeArmPronation.Mom', 'RWristFlexion.Ang', 'RWristFlexion.Mom', 'LWristFlexion.Ang', 'LWristFlexion.Mom', 'RHandAbduction.Ang', 'RHandAbduction.Mom', 'LHandAbduction.Ang', 'LHandAbduction.Mom', 'RHipFlexion.Ang', 'RHipFlexion.Mom', 'LHipFlexion.Ang', 'LHipFlexion.Mom', 'RHipAbduction.Ang', 'RHipAbduction.Mom', 'LHipAbduction.Ang', 'LHipAbduction.Mom', 'RHipInternalRotation.Ang', 'RHipInternalRotation.Mom', 'LHipInternalRotation.Ang', 'LHipInternalRotation.Mom', 'RKneeFlexion.Ang', 'RKneeFlexion.Mom', 'LKneeFlexion.Ang', 'LKneeFlexion.Mom', 'RAnklePlantarFlexion.Ang', 'RAnklePlantarFlexion.Mom', 'LAnklePlantarFlexion.Ang', 'LAnklePlantarFlexion.Mom', 'RFootPronation.Ang', 'RFootPronation.Mom', 'LFootPronation.Ang', 'LFootPronation.Mom', 'RToeFlexion.Ang', 'RToeFlexion.Mom', 'LToeFlexion.Ang', 'LToeFlexion.Mom']
The angles are in degrees, so lets convert them to radians.
for col in obinna.columns:
if col.endswith('.Ang'):
obinna[col] = deg2rad(obinna[col])
The vertical ground reaction forces are stored as variables with the extension .ForY
and the right and left plates are designated by FP2
and FP1
respectively. The following plot shows the right foot vertical ground reaction force in Newtons.
rcParams['figure.figsize'] = 14, 8
obinna['FP2.ForY'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f7c8c03c190>
We will first use the ground reaction forces to find the heel strike and toe off times during gait. I'll select a portion of the data which has suitable GRF profiles for extracting the landmarks.
start = 500
stop = 3500
data = gait.GaitData(obinna.iloc[start:stop].copy())
Now I compute all of the joint angular rates numerically with central differencing.
to_diff = [col for col in obinna.columns if col.endswith('.Ang')]
new_names = [name.split('.')[0] + '.Rate' for name in to_diff]
data.time_derivative(to_diff, new_names)
data.data[new_names]
PelvisX.Rate | PelvisY.Rate | PelvisZ.Rate | PelvisYaw.Rate | PelvisForwardPitch.Rate | PelvisRightRoll.Rate | TrunkFlexion.Rate | TrunkRightBend.Rate | TrunkLeftTwist.Rate | HeadFlexion.Rate | ... | RHipInternalRotation.Rate | LHipInternalRotation.Rate | RKneeFlexion.Rate | LKneeFlexion.Rate | RAnklePlantarFlexion.Rate | LAnklePlantarFlexion.Rate | RFootPronation.Rate | LFootPronation.Rate | RToeFlexion.Rate | LToeFlexion.Rate | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
TimeStamp | |||||||||||||||||||||
539.133881 | 0.150772 | 0.004067 | 0.102778 | 0.552121 | -0.313880 | -0.560728 | 0.739441 | 0.749165 | -1.352188 | 0.744846 | ... | -0.423163 | 0.717820 | -0.275907 | 0.433247 | -1.487446 | -1.134458 | -0.312189 | 0.099003 | -0.192928 | 3.610033 |
539.143890 | 0.160928 | 0.009767 | 0.093144 | 0.505838 | -0.274823 | -0.560336 | 0.693173 | 0.751553 | -1.264465 | 0.726263 | ... | -0.375113 | 0.716841 | -0.776564 | 0.360001 | -1.489845 | -0.999947 | -0.484688 | 0.200675 | -0.040334 | 2.985143 |
539.153929 | 0.170549 | 0.014374 | 0.082798 | 0.459838 | -0.235652 | -0.555664 | 0.647103 | 0.749917 | -1.181869 | 0.700351 | ... | -0.323991 | 0.720383 | -1.273531 | 0.282464 | -1.481764 | -0.874887 | -0.620650 | 0.307396 | 0.130918 | 2.415867 |
539.163913 | 0.178955 | 0.017302 | 0.070936 | 0.408815 | -0.193793 | -0.538489 | 0.598247 | 0.732206 | -1.101582 | 0.658444 | ... | -0.258564 | 0.720492 | -1.764135 | 0.198230 | -1.443396 | -0.768744 | -0.690479 | 0.410975 | 0.325663 | 1.944071 |
539.173887 | 0.190744 | 0.019407 | 0.059362 | 0.358745 | -0.148175 | -0.519258 | 0.553193 | 0.710570 | -1.038914 | 0.618358 | ... | -0.182127 | 0.715549 | -2.302513 | 0.116233 | -1.405452 | -0.708738 | -0.715220 | 0.497662 | 0.486618 | 1.614292 |
539.183359 | 0.197429 | 0.019709 | 0.045226 | 0.296807 | -0.084939 | -0.478501 | 0.474173 | 0.661355 | -0.941312 | 0.556490 | ... | -0.100203 | 0.676440 | -2.789904 | 0.032748 | -1.309441 | -0.655939 | -0.655977 | 0.541498 | 0.551088 | 1.260701 |
539.193338 | 0.198429 | 0.018185 | 0.029573 | 0.233192 | -0.007217 | -0.421657 | 0.362005 | 0.592931 | -0.823555 | 0.484443 | ... | -0.028641 | 0.623191 | -3.176443 | -0.047965 | -1.164453 | -0.588945 | -0.526544 | 0.550545 | 0.594122 | 0.753866 |
539.203378 | 0.199925 | 0.015748 | 0.014679 | 0.181954 | 0.072873 | -0.363103 | 0.245678 | 0.522635 | -0.730849 | 0.427084 | ... | 0.031756 | 0.579831 | -3.556703 | -0.124191 | -1.025162 | -0.530267 | -0.367792 | 0.549529 | 0.704687 | 0.215371 |
539.213772 | 0.206671 | 0.013416 | 0.000550 | 0.142576 | 0.153986 | -0.312493 | 0.137019 | 0.464398 | -0.676672 | 0.390347 | ... | 0.085034 | 0.551432 | -4.063776 | -0.201455 | -0.926712 | -0.499010 | -0.181671 | 0.562505 | 0.886079 | -0.211651 |
539.223469 | 0.207478 | 0.011444 | -0.013507 | 0.100413 | 0.234894 | -0.258014 | 0.017577 | 0.400692 | -0.606138 | 0.349889 | ... | 0.121526 | 0.494230 | -4.475078 | -0.271449 | -0.816792 | -0.464469 | 0.044531 | 0.549869 | 1.144722 | -0.507711 |
539.233942 | 0.206354 | 0.011305 | -0.026519 | 0.058741 | 0.320233 | -0.213516 | -0.114218 | 0.347378 | -0.522428 | 0.319240 | ... | 0.146675 | 0.408000 | -4.777942 | -0.332294 | -0.713385 | -0.449722 | 0.256735 | 0.493948 | 1.630099 | -0.642906 |
539.243898 | 0.213412 | 0.014016 | -0.039252 | 0.022641 | 0.423627 | -0.190963 | -0.262241 | 0.321952 | -0.449838 | 0.316225 | ... | 0.183229 | 0.313809 | -5.163864 | -0.400005 | -0.646520 | -0.481669 | 0.423336 | 0.415559 | 2.436849 | -0.631240 |
539.253891 | 0.213183 | 0.017157 | -0.050315 | -0.002819 | 0.512010 | -0.162450 | -0.403211 | 0.283693 | -0.372969 | 0.315284 | ... | 0.220201 | 0.207110 | -5.385070 | -0.452097 | -0.576615 | -0.515228 | 0.529067 | 0.302805 | 3.078946 | -0.457259 |
539.263928 | 0.209303 | 0.018911 | -0.062615 | -0.007630 | 0.588300 | -0.112064 | -0.530004 | 0.212266 | -0.331448 | 0.313416 | ... | 0.256133 | 0.127058 | -5.715187 | -0.500306 | -0.544402 | -0.545225 | 0.617266 | 0.186492 | 3.191416 | -0.272990 |
539.273928 | 0.207934 | 0.020806 | -0.077989 | 0.005244 | 0.671224 | -0.050982 | -0.658295 | 0.125781 | -0.333365 | 0.312843 | ... | 0.299657 | 0.066938 | -6.277136 | -0.553376 | -0.568105 | -0.575930 | 0.706967 | 0.057501 | 3.029762 | -0.283191 |
539.283377 | 0.199457 | 0.023791 | -0.090748 | 0.033425 | 0.725386 | 0.002668 | -0.754457 | 0.047977 | -0.348361 | 0.301374 | ... | 0.330416 | -0.004414 | -6.609499 | -0.566899 | -0.605916 | -0.583437 | 0.737096 | -0.107685 | 2.733710 | -0.460727 |
539.293321 | 0.183137 | 0.026638 | -0.100232 | 0.086142 | 0.739004 | 0.052905 | -0.802252 | -0.027191 | -0.382885 | 0.278553 | ... | 0.332111 | -0.054443 | -6.671033 | -0.536433 | -0.660021 | -0.567904 | 0.706081 | -0.256169 | 2.160346 | -0.633099 |
539.303321 | 0.168660 | 0.030369 | -0.112451 | 0.164448 | 0.747955 | 0.107066 | -0.837846 | -0.108265 | -0.453761 | 0.255533 | ... | 0.313573 | -0.070425 | -6.835590 | -0.496782 | -0.774232 | -0.562314 | 0.683980 | -0.374151 | 1.481720 | -0.742421 |
539.313352 | 0.152336 | 0.036833 | -0.124700 | 0.241379 | 0.734173 | 0.150850 | -0.841937 | -0.178012 | -0.523756 | 0.225784 | ... | 0.275353 | -0.096281 | -6.912574 | -0.436181 | -0.917272 | -0.565631 | 0.678920 | -0.492983 | 1.026642 | -0.724231 |
539.323356 | 0.134465 | 0.046203 | -0.135236 | 0.306354 | 0.698462 | 0.177436 | -0.815541 | -0.225062 | -0.580258 | 0.190595 | ... | 0.214162 | -0.138993 | -6.827498 | -0.355486 | -1.040596 | -0.569706 | 0.687063 | -0.610325 | 0.855886 | -0.644964 |
539.333433 | 0.114397 | 0.055829 | -0.141228 | 0.365114 | 0.641367 | 0.185750 | -0.760591 | -0.243954 | -0.621143 | 0.153575 | ... | 0.110960 | -0.165452 | -6.464957 | -0.246083 | -1.083726 | -0.562275 | 0.701956 | -0.694404 | 0.672189 | -0.670540 |
539.343934 | 0.098550 | 0.068395 | -0.149885 | 0.430953 | 0.600836 | 0.182885 | -0.723807 | -0.245581 | -0.667158 | 0.124482 | ... | -0.014252 | -0.185855 | -6.170680 | -0.118800 | -1.085736 | -0.581887 | 0.760149 | -0.781797 | 0.356708 | -0.833114 |
539.353936 | 0.087635 | 0.086624 | -0.164598 | 0.505088 | 0.586162 | 0.166760 | -0.716570 | -0.226996 | -0.721286 | 0.096242 | ... | -0.142878 | -0.218125 | -6.017800 | 0.023620 | -1.073117 | -0.635562 | 0.848817 | -0.887232 | -0.050506 | -1.018629 |
539.363435 | 0.073404 | 0.101984 | -0.170530 | 0.544087 | 0.546579 | 0.123710 | -0.678267 | -0.163687 | -0.716930 | 0.058980 | ... | -0.247823 | -0.230179 | -5.446358 | 0.167961 | -0.952599 | -0.641720 | 0.866853 | -0.909389 | -0.508479 | -1.172346 |
539.373326 | 0.056608 | 0.109381 | -0.163898 | 0.537701 | 0.478953 | 0.068952 | -0.605301 | -0.077756 | -0.645604 | 0.022546 | ... | -0.303336 | -0.200709 | -4.488722 | 0.286876 | -0.715454 | -0.568822 | 0.794513 | -0.823835 | -0.989112 | -1.417391 |
539.383922 | 0.044262 | 0.121110 | -0.163228 | 0.541004 | 0.441299 | 0.015951 | -0.571379 | 0.008452 | -0.585128 | -0.004738 | ... | -0.337126 | -0.170797 | -3.743981 | 0.409456 | -0.453149 | -0.499901 | 0.740594 | -0.753196 | -1.544236 | -1.826493 |
539.393907 | 0.034274 | 0.142311 | -0.169458 | 0.552473 | 0.436295 | -0.056231 | -0.585011 | 0.126088 | -0.526225 | -0.023488 | ... | -0.349096 | -0.164505 | -3.157787 | 0.565342 | -0.142579 | -0.455674 | 0.732004 | -0.718334 | -1.998882 | -2.284696 |
539.403358 | 0.021718 | 0.157747 | -0.161861 | 0.512470 | 0.415197 | -0.152404 | -0.582361 | 0.279327 | -0.407962 | -0.031126 | ... | -0.304307 | -0.164575 | -2.371027 | 0.699106 | 0.239291 | -0.377147 | 0.691046 | -0.637774 | -1.986514 | -2.547718 |
539.413350 | 0.007556 | 0.168445 | -0.146465 | 0.455156 | 0.388194 | -0.251853 | -0.573774 | 0.438128 | -0.281475 | -0.030598 | ... | -0.246959 | -0.177652 | -1.638801 | 0.804048 | 0.629368 | -0.274201 | 0.642650 | -0.562286 | -1.816265 | -2.749792 |
539.423367 | -0.008350 | 0.178241 | -0.129488 | 0.406799 | 0.358228 | -0.340091 | -0.562443 | 0.580892 | -0.178258 | -0.026712 | ... | -0.209103 | -0.197756 | -1.073962 | 0.896991 | 0.999224 | -0.156481 | 0.604230 | -0.521376 | -1.770452 | -2.992274 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
568.832779 | -0.086854 | -0.216061 | 0.077546 | 0.542278 | -0.615465 | 1.042222 | 0.831294 | -1.662116 | -1.213044 | -0.516874 | ... | 0.487669 | 0.141276 | 4.866993 | 0.283599 | 6.384958 | -0.698202 | 0.172390 | 0.134296 | 6.829934 | 1.032123 |
568.842797 | -0.057147 | -0.202581 | 0.081217 | 0.491240 | -0.631402 | 0.914712 | 0.932477 | -1.456425 | -1.211154 | -0.565919 | ... | 0.544297 | 0.215675 | 4.617993 | 0.112828 | 6.402966 | -0.553547 | 0.230635 | 0.252702 | 6.287837 | -0.039501 |
568.852847 | -0.027617 | -0.189945 | 0.086070 | 0.478310 | -0.633358 | 0.791173 | 1.005831 | -1.261049 | -1.260163 | -0.588092 | ... | 0.549614 | 0.375698 | 4.346952 | -0.088876 | 6.190570 | -0.268191 | 0.238609 | 0.445280 | 5.557559 | -1.596418 |
568.862824 | -0.000403 | -0.176650 | 0.092154 | 0.496089 | -0.624232 | 0.669028 | 1.048055 | -1.073308 | -1.344025 | -0.574619 | ... | 0.507255 | 0.592684 | 4.041422 | -0.311586 | 5.682470 | 0.103547 | 0.191471 | 0.691499 | 4.735356 | -3.338038 |
568.872822 | 0.023261 | -0.157173 | 0.095547 | 0.520262 | -0.576714 | 0.528870 | 1.011333 | -0.862229 | -1.402155 | -0.505112 | ... | 0.413603 | 0.805947 | 3.589160 | -0.519736 | 4.749933 | 0.491006 | 0.090247 | 0.927827 | 3.764362 | -4.919249 |
568.883406 | 0.045001 | -0.142434 | 0.101418 | 0.577879 | -0.524899 | 0.408227 | 0.961238 | -0.687801 | -1.511086 | -0.427199 | ... | 0.307143 | 1.043219 | 3.241377 | -0.713481 | 3.810174 | 0.875811 | -0.015357 | 1.190729 | 2.938456 | -6.437403 |
568.893358 | 0.064903 | -0.127624 | 0.108629 | 0.648591 | -0.477434 | 0.279008 | 0.912436 | -0.508197 | -1.642909 | -0.348386 | ... | 0.190821 | 1.218799 | 2.944059 | -0.801312 | 2.832772 | 1.052489 | -0.089705 | 1.331302 | 2.249870 | -6.994201 |
568.903396 | 0.077401 | -0.101122 | 0.110309 | 0.668172 | -0.427353 | 0.103554 | 0.839047 | -0.268593 | -1.676911 | -0.257726 | ... | 0.065455 | 1.095043 | 2.529552 | -0.592314 | 1.712748 | 0.593906 | -0.087357 | 0.990719 | 1.608053 | -4.766355 |
568.913425 | 0.086243 | -0.070274 | 0.110917 | 0.663626 | -0.394175 | -0.086111 | 0.781208 | -0.021117 | -1.677422 | -0.173535 | ... | -0.056825 | 0.766104 | 2.122708 | -0.190337 | 0.625216 | -0.305116 | -0.002219 | 0.316853 | 1.084452 | -0.787674 |
568.923387 | 0.094264 | -0.041604 | 0.110712 | 0.655510 | -0.364144 | -0.247795 | 0.726990 | 0.183144 | -1.662543 | -0.097431 | ... | -0.173884 | 0.450156 | 1.709688 | 0.174153 | -0.425669 | -1.111030 | 0.133295 | -0.308599 | 0.695368 | 2.718131 |
568.933373 | 0.101709 | -0.018906 | 0.109085 | 0.648840 | -0.331723 | -0.363125 | 0.672184 | 0.328211 | -1.638922 | -0.034540 | ... | -0.278519 | 0.238805 | 1.288601 | 0.407644 | -1.404815 | -1.621402 | 0.299750 | -0.733232 | 0.432840 | 4.945757 |
568.943435 | 0.109579 | -0.002356 | 0.106672 | 0.645169 | -0.300863 | -0.444584 | 0.625330 | 0.433279 | -1.622314 | 0.010991 | ... | -0.369785 | 0.105242 | 0.879466 | 0.546790 | -2.297049 | -1.928376 | 0.501902 | -1.008389 | 0.253676 | 6.248697 |
568.953377 | 0.121395 | 0.009703 | 0.106006 | 0.652846 | -0.276553 | -0.515559 | 0.597491 | 0.525998 | -1.644708 | 0.042779 | ... | -0.450174 | 0.013248 | 0.483710 | 0.637261 | -3.177597 | -2.150609 | 0.743926 | -1.206039 | 0.143616 | 7.075746 |
568.962733 | 0.125105 | 0.017380 | 0.096593 | 0.602658 | -0.227178 | -0.528477 | 0.521621 | 0.558001 | -1.534054 | 0.062864 | ... | -0.468070 | -0.043846 | 0.046269 | 0.637995 | -3.681224 | -2.109290 | 0.925955 | -1.221629 | 0.055372 | 6.949304 |
568.973370 | 0.129305 | 0.022133 | 0.086620 | 0.543867 | -0.174219 | -0.524053 | 0.443635 | 0.568953 | -1.412801 | 0.075522 | ... | -0.461211 | -0.064786 | -0.372035 | 0.614549 | -3.979018 | -1.984063 | 1.076419 | -1.154896 | 0.035058 | 6.485397 |
568.983426 | 0.147453 | 0.027834 | 0.084086 | 0.525102 | -0.133997 | -0.562304 | 0.405739 | 0.625142 | -1.413956 | 0.090724 | ... | -0.474825 | -0.079682 | -0.837955 | 0.628365 | -4.545346 | -1.994005 | 1.280686 | -1.142144 | 0.291812 | 6.312790 |
568.992716 | 0.155454 | 0.030386 | 0.074099 | 0.453212 | -0.080253 | -0.554943 | 0.332530 | 0.631545 | -1.294432 | 0.098904 | ... | -0.425331 | -0.086642 | -1.262274 | 0.566633 | -4.676410 | -1.830165 | 1.321415 | -1.007141 | 0.810956 | 5.462140 |
569.002781 | 0.152762 | 0.028810 | 0.058842 | 0.349101 | -0.020960 | -0.507467 | 0.236920 | 0.593742 | -1.090633 | 0.098953 | ... | -0.341580 | -0.077028 | -1.600366 | 0.454489 | -4.312404 | -1.552140 | 1.256050 | -0.792407 | 1.056653 | 4.275556 |
569.013369 | 0.165951 | 0.027787 | 0.048483 | 0.284082 | 0.041532 | -0.502766 | 0.161876 | 0.607120 | -1.002793 | 0.102043 | ... | -0.298339 | -0.050148 | -2.119223 | 0.387484 | -4.174564 | -1.420883 | 1.335443 | -0.630991 | 1.034395 | 3.488094 |
569.022793 | 0.180845 | 0.025165 | 0.036241 | 0.222214 | 0.112826 | -0.487254 | 0.081009 | 0.607172 | -0.922438 | 0.095480 | ... | -0.249480 | -0.001446 | -2.677728 | 0.314574 | -3.901714 | -1.274999 | 1.401900 | -0.441055 | 0.949698 | 2.655062 |
569.032747 | 0.178974 | 0.020398 | 0.020120 | 0.145029 | 0.172823 | -0.425117 | -0.003010 | 0.545478 | -0.768431 | 0.072555 | ... | -0.168141 | 0.042844 | -2.973553 | 0.214896 | -3.238561 | -1.046794 | 1.299969 | -0.237877 | 0.841241 | 1.781125 |
569.043376 | 0.192263 | 0.018808 | 0.005571 | 0.083415 | 0.245492 | -0.403976 | -0.083460 | 0.530434 | -0.685085 | 0.054911 | ... | -0.093779 | 0.077784 | -3.518995 | 0.144439 | -2.867372 | -0.959934 | 1.288607 | -0.099289 | 0.845849 | 1.289324 |
569.052749 | 0.205879 | 0.018241 | -0.010108 | 0.026886 | 0.319942 | -0.380060 | -0.164725 | 0.505924 | -0.604300 | 0.038682 | ... | -0.009179 | 0.106055 | -4.071607 | 0.078302 | -2.494216 | -0.889814 | 1.239812 | 0.020419 | 1.015854 | 0.847336 |
569.062761 | 0.200106 | 0.016479 | -0.024256 | -0.014120 | 0.359173 | -0.320940 | -0.220133 | 0.429063 | -0.491297 | 0.018360 | ... | 0.073243 | 0.117051 | -4.163018 | 0.013688 | -1.955738 | -0.747403 | 1.018222 | 0.114937 | 1.415042 | 0.331258 |
569.073382 | 0.205502 | 0.016631 | -0.038767 | -0.041502 | 0.415232 | -0.283840 | -0.282378 | 0.375214 | -0.433384 | 0.003077 | ... | 0.149607 | 0.129485 | -4.446689 | -0.041313 | -1.620672 | -0.660038 | 0.833005 | 0.195347 | 2.033433 | -0.145645 |
569.083411 | 0.214700 | 0.018025 | -0.055097 | -0.058303 | 0.482044 | -0.246908 | -0.354497 | 0.316974 | -0.407863 | -0.006610 | ... | 0.215493 | 0.154041 | -4.933719 | -0.096148 | -1.360194 | -0.589362 | 0.698878 | 0.278497 | 2.396506 | -0.577165 |
569.093439 | 0.215536 | 0.018959 | -0.070862 | -0.059085 | 0.531058 | -0.195064 | -0.412893 | 0.240090 | -0.391864 | -0.015901 | ... | 0.256444 | 0.176163 | -5.380748 | -0.144061 | -1.084395 | -0.514288 | 0.585387 | 0.336135 | 2.244864 | -0.862649 |
569.103401 | 0.219268 | 0.020873 | -0.088260 | -0.057665 | 0.588053 | -0.152405 | -0.479163 | 0.176364 | -0.387764 | -0.021290 | ... | 0.303357 | 0.167810 | -5.936502 | -0.177948 | -0.864658 | -0.483150 | 0.465054 | 0.349136 | 1.960988 | -1.015559 |
569.112887 | 0.216929 | 0.023871 | -0.102888 | -0.056118 | 0.629091 | -0.121913 | -0.535056 | 0.129345 | -0.370059 | -0.020062 | ... | 0.347034 | 0.121293 | -6.262448 | -0.178870 | -0.669194 | -0.477313 | 0.289563 | 0.302237 | 1.711731 | -1.015075 |
569.122730 | 0.208909 | 0.027119 | -0.114074 | -0.051988 | 0.651689 | -0.098348 | -0.574710 | 0.092696 | -0.343738 | -0.017418 | ... | 0.377126 | 0.065277 | -6.365866 | -0.159776 | -0.488944 | -0.476452 | 0.096115 | 0.229928 | 1.517740 | -0.928625 |
3000 rows × 46 columns
The strikes and toe offs can then be computed for this data.
rcParams['figure.figsize'] = 14, 10
right_strikes, left_strikes, right_offs, left_offs = \
data.grf_landmarks('FP2.ForY', 'FP1.ForY', do_plot=True, threshold=28.0)
Now we can section the gait cycle based on the right foot and interpolate at 10 distinct equally spaced points in the gait cycle.
rcParams['figure.figsize'] = 14, 10
right_steps = data.split_at('right', num_samples=15)
data.plot_gait_cycles('FP2.ForY', 'RKneeFlexion.Ang', 'RKneeFlexion.Rate',
'RKneeFlexion.Mom', marker='o')
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85ef0850>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85e66c50>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85de9950>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85d592d0>], dtype=object)
We can see the mean gait cycle easily:
data.plot_gait_cycles('FP2.ForY', 'RKneeFlexion.Ang', 'RKneeFlexion.Rate', 'RKneeFlexion.Mom', mean=True)
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85f79590>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85922c10>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c85966a90>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c8588db10>], dtype=object)
At this point we have the data in the form needed to identify a simple linear controller where we assume the sensors are fed back and subtract from a set point in the walking gait cycle, to give the error in the gait. This error vector is then multiplied by a gain matrix and added to the limit cycle control torques to power the plant in walking.
The following gives the equation that generates the controls given the error in the sensors at a single time step during a single foot step. $t$ here represents the time in the gait cycle, not time across all steps.
$$m_m(t) = m(t)_0 + K(t) s_e(t) = m(t)_0 + K(t) [s_0(t) - s_m(t)]$$Now rearrange the equations such that we have one linear in both the gains, $K(t)$, and in $m^*(t)$:
$$m_m(t) = m(t)_0 + K(t) s_0(t) - K(t) s_m(t) = m^*(t) - K(t) s_m(t)$$Here I specify the hypothesized sensors and controls, and the data to initialized the solver:
sensors = ['RKneeFlexion.Ang',
'RKneeFlexion.Rate',
'RHipFlexion.Ang',
'RHipFlexion.Rate',
'LKneeFlexion.Ang',
'LKneeFlexion.Rate',
'LHipFlexion.Ang',
'LHipFlexion.Rate']
controls = ['RKneeFlexion.Mom',
'RHipFlexion.Mom',
'LKneeFlexion.Mom',
'LHipFlexion.Mom']
solver = controlid.SimpleControlSolver(right_steps, sensors, controls)
Now we can solve the linear system for the gains at each time step and the $m^*(t)$:
gains, controls_star, variance, gain_var, controls_star_var, estimated_controls = solver.solve()
gains.shape
(15, 4, 8)
The following plot shows the identified gains as a function of the percentage of the gait cycle. The rows correspond to the controller outputs and the columns to the measured sensors. The shaded region depicts the standard deviation in the estimates.
axes = solver.plot_gains(gains, gain_var)
The variance in the fit is:
variance
array([ 20.18781651])
And the following plot shows the measured controls at each point in the gain cycle (blue line) and the controller generated controls given the measured sensors (green dots). The error bars on the green dots show the variance in the fit.
rcParams['figure.figsize'] = 14, 14
axes = solver.plot_estimated_vs_measure_controls(estimated_controls, variance)
To get an idea of how each of the controller inputs affects the outputs I plot the contribution from each sensor error and gain to the different controls. To do this I make the assumption that the commanded angles and rates of the joints are the mean over a set of steps.
$$s_0(t) = \bar{s}(t)$$Then I can solve for $m_0(t)$:
$$m_0(t) = m(t) - K(t) [\bar{s}(t) - s(t)]$$And the contribution of $K(t) [\bar{s}(t) - s(t)]$ to each of the controls $m(t)$ can be computed:
$$m_1(t) = m_{0_1}(t) + K_{11} s_{e_1} + \ldots + + K_{1p} s_{e_p}$$I plot the contributions from each sensor error and the nominal moments as stacked bar charts to get an idea of the contributions at each step. The first four steps are shown.
The line plots below the bar charts show the same contributions but as a mean with respect to the step. Notice that the mean of the controller contributions is zero. This seems odd to me and believe it is an artifact of assuming the nominal sensors to be the mean of the sensors over the steps.
I was expecting to see patterns in the controller behavior across the steps but if the majority of the control moments are due to $m_0(t)$ then the controller is just responsible for applying any moments due to deviations from $m_0(t)$.
solver.plot_control_contributions(estimated_controls)
gain_inclusion_matrix = np.ones((len(controls), len(sensors))).astype(bool)
gain_inclusion_matrix[2:, :4] = False
gain_inclusion_matrix[:2, 4:] = False
gain_inclusion_matrix
array([[ True, True, True, True, False, False, False, False], [ True, True, True, True, False, False, False, False], [False, False, False, False, True, True, True, True], [False, False, False, False, True, True, True, True]], dtype=bool)
gains, controls_star, variance, gain_var, controls_star_var, estimated_controls = \
solver.solve(gain_inclusion_matrix=gain_inclusion_matrix)
rcParams['figure.figsize'] = 14, 10
axes = solver.plot_gains(gains, gain_var)
rcParams['figure.figsize'] = 14, 14
axes = solver.plot_estimated_vs_measure_controls(estimated_controls, variance)
rcParams['figure.figsize'] = 14, 14
solver.plot_control_contributions(estimated_controls)
gain_inclusion_matrix = np.zeros((len(controls), len(sensors))).astype(bool)
gain_inclusion_matrix[0, :2] = True
gain_inclusion_matrix[1, 2:4] = True
gain_inclusion_matrix[2, 4:6] = True
gain_inclusion_matrix[3, 6:8] = True
gain_inclusion_matrix
array([[ True, True, False, False, False, False, False, False], [False, False, True, True, False, False, False, False], [False, False, False, False, True, True, False, False], [False, False, False, False, False, False, True, True]], dtype=bool)
gains, controls_star, variance, gain_var, controls_star_var, estimated_controls = \
solver.solve(gain_inclusion_matrix=gain_inclusion_matrix)
rcParams['figure.figsize'] = 14, 10
axes = solver.plot_gains(gains, gain_var)
rcParams['figure.figsize'] = 14, 14
axes = solver.plot_estimated_vs_measure_controls(estimated_controls, variance)
Ton also gave me some data he collected for subject doing normal walking. Here is explanation:
Here is some data that was collected for a paper which is about to be published. Proofs and supplementary documentation are >attached.
This is from a 77 kg male, 30 seconds of walking preceded by 1 second of standing. The treadmill speed increases gradually >in the beginning, at t=6.0 it is at its final constant speed to best to ignore anything that happens before that time.
The dof file contains the generalized coordinates, dofvel the generalized velocities. The jointmoment file the corresponding >generalized forces. First line has the names of the generalized coordinates. The grf file has the ground reaction forces, >which you would use to determine where you are in the gait cycle (from heelstrike to heelstrike).
CAREN_Trial04.txt is the raw data (mocap and force plate). You could actually load that file in D-Flow to produce the >variables that are on the other files, if you wanted to.
I'll do the same analysis I did for the previous data but limit everything to the right leg because the left leg force plate measurements are botched.
tdir = os.path.join(PATHS['raw_data_dir'], 'T002')
coordinates = pandas.read_csv(os.path.join(tdir, 'CAREN_Trial04_dof.txt'), delimiter='\t', index_col="TimeStamp")
speeds = pandas.read_csv(os.path.join(tdir, 'CAREN_Trial04_dofvel.txt'), delimiter='\t', index_col="TimeStamp")
generalized_forces = pandas.read_csv(os.path.join(tdir, 'CAREN_Trial04_jointmoment.txt'), delimiter='\t', index_col="TimeStamp")
ground_reaction_forces = pandas.read_csv(os.path.join(tdir, 'CAREN_Trial04_grf.txt'), delimiter='\t', index_col="TimeStamp")
raw_data = pandas.read_csv(os.path.join(tdir, 'CAREN_Trial04.txt'), delimiter='\t', index_col="TimeStamp")
Load in the separate data files and rename the columns to reflate the type of data so they can be merged into one big data frame.
coordinates.columns = [name + '.Ang' for name in coordinates.columns]
speeds.columns = [name + '.Rate' for name in speeds.columns]
generalized_forces.columns = [name + '.Mom' for name in generalized_forces.columns]
all_data = coordinates.join(speeds).join(generalized_forces).join(ground_reaction_forces)
Take the data after 15 seconds to avoid the error in the right force plate data.
data = gait.GaitData(all_data[all_data.index > 15.0])
rcParams['figure.figsize'] = 14, 10
right_strikes, left_strikes, right_offs, left_offs = \
data.grf_landmarks('RFy','LFy', do_plot=True, threshold=5.0)
right_steps = data.split_at('right', num_samples=15)
axes = data.plot_gait_cycles('RFy', 'RKneeFlexion.Ang', 'RKneeFlexion.Rate', 'RKneeFlexion.Mom', marker='o')
axes = data.plot_gait_cycles('RFy', 'RKneeFlexion.Ang', 'RKneeFlexion.Rate', 'RKneeFlexion.Mom', mean=True)
sensors = ['RKneeFlexion.Ang',
'RKneeFlexion.Rate',
'RHipFlexion.Ang',
'RHipFlexion.Rate']
controls = ['RKneeFlexion.Mom',
'RHipFlexion.Mom']
solver = controlid.SimpleControlSolver(right_steps, sensors, controls)
gains, controls, variance, gain_var, control_var, estimated_controls = solver.solve()
variance
array([ 8.97262812])
It is interesting to note that the gains here are of a very different scale than the previous data.
rcParams['figure.figsize'] = 14, 10
axes = solver.plot_gains(gains, gain_var)
solver.plot_estimated_vs_measure_controls(estimated_controls, variance)
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f7c7c805850>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c84fc0f10>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c853a2210>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f7c845bf3d0>], dtype=object)
rcParams['figure.figsize'] = 14, 14
solver.plot_control_contributions(estimated_controls)
!git rev-parse HEAD
6af0c229bb0a9edf78f8489d5f0efe02d5685a57
!git --git-dir=/home/moorepants/src/GaitAnalysisToolKit/.git --work-tree=/home/moorepants/src/GaitAnalysisToolKit rev-parse HEAD
9e80dfdcfe0a14b44e0ebcbadb6e9e827d215c3c
%install_ext http://raw.github.com/jrjohansson/version_information/master/version_information.py
Installed version_information.py. To use it, type: %load_ext version_information
%load_ext version_information
%version_information numpy, scipy, pandas, matplotlib, tables, oct2py, dtk, gaitanalysis
Software | Version |
---|---|
Python | 2.7.9 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] |
IPython | 3.0.0 |
OS | Linux 3.13.0 49 generic x86_64 with debian jessie sid |
numpy | 1.9.2 |
scipy | 0.15.1 |
pandas | 0.16.0 |
matplotlib | 1.4.2 |
tables | 3.1.1 |
oct2py | 3.1.0 |
dtk | 0.4.0 |
gaitanalysis | 0.2.0dev |
Fri Apr 24 10:38:48 2015 PDT |
!conda list
# packages in environment at /home/moorepants/anaconda/envs/gait-direct-id-paper: # backports.ssl-match-hostname 3.4.0.2 <pip> cairo 1.12.18 0 dateutil 2.4.1 py27_0 dynamicisttoolkit 0.4.0 py27_0 fastcache 1.0.2 py27_0 fontconfig 2.11.1 2 freetype 2.4.10 0 gaitanalysistoolkit (/home/moorepants/src/GaitAnalysisToolKit) 0.2.0.dev0 <pip> hdf5 1.8.14 0 ipython 3.0.0 py27_0 ipython-notebook 3.0.0 py27_1 jinja2 2.7.3 py27_1 jsonschema 2.4.0 py27_0 libpng 1.5.13 1 libsodium 0.4.5 0 libxml2 2.9.0 0 markupsafe 0.23 py27_0 matplotlib 1.4.2 np19py27_0 mistune 0.5.1 py27_0 nose 1.3.4 py27_1 numexpr 2.3.1 np19py27_0 numpy 1.9.2 py27_0 oct2py 3.1.0 py27_0 openssl 1.0.1k 1 pandas 0.16.0 np19py27_1 pip 6.1.1 py27_0 pixman 0.26.2 0 ptyprocess 0.4 py27_0 py2cairo 1.10.0 py27_2 pygments 2.0.2 py27_0 pyparsing 2.0.1 py27_0 pyqt 4.10.4 py27_0 pyside 1.2.1 py27_1 pytables 3.1.1 np19py27_2 python 2.7.9 2 python-dateutil 2.4.2 py27_0 pytz 2015.2 py27_0 pyyaml 3.11 py27_0 pyzmq 14.5.0 py27_0 qt 4.8.5 0 readline 6.2 2 scipy 0.15.1 np19py27_0 seaborn 0.5.1 np19py27_0 setuptools 15.0 py27_0 shiboken 1.2.1 py27_0 sip 4.15.5 py27_0 six 1.9.0 py27_0 snakeviz 0.3.1 <pip> sqlite 3.8.4.1 1 ssl_match_hostname 3.4.0.2 py27_0 sympy 0.7.6 py27_0 system 5.8 2 tables 3.1.1 <pip> terminado 0.5 py27_0 tk 8.5.18 0 tornado 4.1 py27_0 yaml 0.1.4 0 zeromq 4.0.4 0 zlib 1.2.8 0
!pip freeze
backports.ssl-match-hostname==3.4.0.2 DynamicistToolKit==0.4.0 fastcache==1.0.2 -e git+git@github.com:csu-hmc/GaitAnalysisToolKit.git@9e80dfdcfe0a14b44e0ebcbadb6e9e827d215c3c#egg=GaitAnalysisToolKit-origin_speedup-inverse-dynamics ipython==3.0.0 Jinja2==2.7.3 jsonschema==2.4.0 MarkupSafe==0.23 matplotlib==1.4.2 mistune==0.5.1 nose==1.3.4 numexpr==2.3.1 numpy==1.9.2 oct2py==3.1.0 pandas==0.16.0 ptyprocess==0.4 Pygments==2.0.2 pyparsing==2.0.1 PySide==1.2.1 python-dateutil==2.4.2 pytz==2015.2 PyYAML==3.11 pyzmq==14.5.0 scipy==0.15.1 seaborn==0.5.1 six==1.9.0 snakeviz==0.3.1 sympy==0.7.6 tables==3.1.1 terminado==0.5 tornado==4.1