#!/usr/bin/env python # coding: utf-8 # The purpose of this notebook is to check whether the data collected while the person is being perturbed actually produces different and/or "better" gains than the data collected while the person is not being perturbed. # In[1]: import sys sys.path.append('../src') # In[2]: from gaitanalysis.gait import plot_gait_cycles from gaitanalysis.controlid import SimpleControlSolver # In[3]: import utils from gait_landmark_settings import settings # In[4]: get_ipython().run_line_magic('matplotlib', 'inline') # In[5]: from IPython.core.pylabtools import figsize figsize(12, 10) # Load the path to the directory with the experimental data. # In[6]: trials_dir = utils.config_paths()['raw_data_dir'] # Show a table of the currently available trials. # In[7]: tables = utils.generate_meta_data_tables(trials_dir) tables['TOP|trial'].sort(['nominal-speed', 'subject-id']).head(50) # Trial #68 had nice clean data, so we'll look at that one. # In[8]: trial_number = '068' # ## Gains identified from normal walking # Here I'll extract the data from both the normal walking periods, i.e. the two 1 minute sections at the beginning and end of the trial. Then section out the steps for each and concantenate the steps to give two minutes of data. # In[9]: trial = utils.Trial('068') # In[10]: trial.prep_data('Normal Walking') # And identify a controller. # In[11]: trial.identify_controller('Normal Walking', 'joint isolated') # In[12]: fig, axes = trial.plot_joint_isolated_gains('Normal Walking', 'joint isolated') # ## Gains identified from perturbed walking # Now let's see what the perturbed walking gives. # In[13]: trial.identify_controller('Longitudinal Perturbation', 'joint isolated') # In[14]: fig, axes = trial.plot_joint_isolated_gains('Longitudinal Perturbation', 'joint isolated') # # Compare Standard Deviations # The difference in the standard deviation of the angles, rates, and torques in the unperturbed gait cycles and the perturbed gait cycles is not that high, especially in the joint angles and rates. # In[15]: variables = ['FP2.ForY', 'Right.Ankle.PlantarFlexion.Moment', 'Right.Knee.Flexion.Rate', 'Right.Hip.Flexion.Angle'] # In[16]: normal_steps = trial.merge_normal_walking() # In[17]: axes = plot_gait_cycles(normal_steps, *variables, mean=False, marker='.') # In[18]: perturbed_steps = trial.gait_data_objs['Longitudinal Perturbation'].gait_cycles axes = plot_gait_cycles(perturbed_steps, *variables, marker='.') # In[19]: axes = plot_gait_cycles(perturbed_steps, *variables, mean=True) axes = plot_gait_cycles(normal_steps, *variables, axes=axes, mean=True, color='red') # In[20]: std_normal = normal_steps.std(axis='items') std_perturbed = perturbed_steps.std(axis='items') # In[21]: mean_normal = normal_steps.mean(axis='items') mean_perturbed = perturbed_steps.mean(axis='items') # This should give a relative percent difference in the standard deviation of the perturbed with respect to the unperturbed # In[22]: (100 * (std_perturbed - std_normal) / mean_normal)[variables] # This is the mean difference in the standard deviations across the gait cycle. # In[23]: (std_perturbed - std_normal)[variables].mean() # # Footer # In[24]: get_ipython().system('git rev-parse HEAD') # In[25]: get_ipython().system('git --git-dir=/home/moorepants/src/GaitAnalysisToolKit/.git --work-tree=/home/moorepants/src/GaitAnalysisToolKit rev-parse HEAD') # In[26]: get_ipython().run_line_magic('install_ext', 'http://raw.github.com/jrjohansson/version_information/master/version_information.py') # In[27]: get_ipython().run_line_magic('load_ext', 'version_information') # In[28]: get_ipython().run_line_magic('version_information', 'numpy, scipy, pandas, matplotlib, tables, oct2py, dtk, gaitanalysis') # In[29]: get_ipython().system('conda list') # In[30]: get_ipython().system('pip freeze')