示例#1
0
missing_marker_labels = [
    "R.ASIS", "R.Thigh.Rear", "R.Toe.Tip", "R.Shank.Upper", "L.Shank.Upper",
    "L.Thigh.Rear", "L.Toe.Tip"
]

subject_dir = os.path.abspath('../')
results_dir = os.path.join(subject_dir, 'real_time/marker_reconstruction')
original_markers_file = os.path.join(subject_dir, 'experimental_data/task.trc')
reconstructed_markers_file = os.path.join(results_dir,
                                          'reconstructed_markers.sto')

if not (os.path.isfile(original_markers_file)
        and os.path.isfile(reconstructed_markers_file)):
    raise RuntimeError('Required files do not exist.')

original_markers = read_from_storage(original_markers_file)
reconstructed_markers = read_from_storage(reconstructed_markers_file)

# %%

if gait_cycle:
    t0 = 0.6  # right heel strike
    tf = 1.83  # next right heel strike
    original_markers = to_gait_cycle(original_markers, t0, tf)
    reconstructed_markers = to_gait_cycle(reconstructed_markers, t0, tf)

    occlusion_start_perc = 100.0 / (tf - t0) * (occlusion_start_time - t0)
    occlusion_stop_perc = 100.0 / (tf - t0) * (occlusion_start_time +
                                               occlusion_duration - t0)

# %%
示例#2
0
# %%
# data

gait_cycle = True

subject_dir = os.path.abspath('../')
output_dir = os.path.join(subject_dir, 'real_time/inverse_dynamics/')

tau_reference_file = os.path.join(subject_dir,
                                  'inverse_dynamics/task_InverseDynamics.sto')
tau_rt_file = os.path.join(output_dir, 'tau.sto')

# %%
# read data

tau_reference = read_from_storage(tau_reference_file)
tau_rt = read_from_storage(tau_rt_file)

if gait_cycle:
    t0 = 0.6                        # right heel strike
    tf = 1.83                       # next right heel strike
    tau_reference = to_gait_cycle(tau_reference, t0, tf)
    tau_rt = to_gait_cycle(tau_rt, t0, tf)

plot_sto_file(tau_rt_file, tau_rt_file + '.pdf', 3)

# %%
# compare

d_tau_total = []
with PdfPages(output_dir + 'inverse_dynamics_comparison.pdf') as pdf:
ensemble_right = []
ensemble_left = []
for directory in subject_dirs:
    # file path
    ik_file_path = os.path.join(working_dir,
                                directory,
                                'inverse_kinematics/'
                                'task_InverseKinematics.mot')
    c3d_file_path = os.path.join(working_dir,
                                 directory,
                                 'experimental_data/'
                                 'task.c3d')

    # load kinematics
    kinematics_df = read_from_storage(ik_file_path, 0.01, True)

    # extract gait cycle
    right_intervals, left_intervals = extract_gait_cycle_intervals(c3d_file_path)

    # partition trial on interval, normalize and collect into list
    for interval in right_intervals:
        df = kinematics_df[(kinematics_df.time >= interval[0]) &
                           (kinematics_df.time <= interval[1])]
        df_norm = normalize_interpolate_dataframe(df)
        ensemble_right.append(df_norm)

    for interval in left_intervals:
        df = kinematics_df[(kinematics_df.time >= interval[0]) &
                           (kinematics_df.time <= interval[1])]
        df_norm = normalize_interpolate_dataframe(df)
示例#4
0
subject_dir = os.path.abspath('../')
output_dir = os.path.join(subject_dir, 'real_time/muscle_optimization/')

fm_reference_file = os.path.join(
    subject_dir, 'static_optimization/task_StaticOptimization_force.sto')
fm_rt_file = os.path.join(output_dir, 'fm.sto')
am_rt_file = os.path.join(output_dir, 'am.sto')
tauRes_rt_file = os.path.join(output_dir, 'tauRes.sto')

plot_sto_file(am_rt_file, am_rt_file + '.pdf', 3)
plot_sto_file(tauRes_rt_file, tauRes_rt_file + '.pdf', 3)

# %%
# read data

fm_reference = read_from_storage(fm_reference_file)
fm_rt = read_from_storage(fm_rt_file)

if gait_cycle:
    t0 = 0.6  # right heel strike
    tf = 1.83  # next right heel strike
    fm_reference = to_gait_cycle(fm_reference, t0, tf)
    fm_rt = to_gait_cycle(fm_rt, t0, tf)

plot_sto_file(fm_rt_file, fm_rt_file + '.pdf', 3)

# %%
# compare

d_fm_total = []
with PdfPages(output_dir + 'muscle_optimization_comparison.pdf') as pdf:
示例#5
0
# data

gait_cycle = True

subject_dir = os.path.abspath('../')
output_dir = os.path.join(subject_dir, 'real_time/joint_reaction_analysis/')

jr_reference_file = os.path.join(
    subject_dir,
    'joint_reaction_analysis/task_JointReaction_ReactionLoads.sto')
jr_rt_file = os.path.join(output_dir, 'jr.sto')

# %%
# read data

jr_reference = read_from_storage(jr_reference_file)
jr_rt = read_from_storage(jr_rt_file)
# make very small number zero before plotting
jr_reference[jr_reference.abs() < 1e-9] = 0
jr_rt[jr_reference.abs() < 1e-9] = 0

if gait_cycle:
    t0 = 0.6  # right heel strike
    tf = 1.83  # next right heel strike
    jr_reference = to_gait_cycle(jr_reference, t0, tf)
    jr_rt = to_gait_cycle(jr_rt, t0, tf)

plot_sto_file(jr_rt_file, jr_rt_file + '.pdf', 3)

# %%
# compare
示例#6
0
subject_dir = os.path.abspath('../')
results_dir = os.path.join(subject_dir,
                           'real_time/grfm_prediction/force_based/')
experimental_dir = os.path.join(subject_dir, 'experimental_data/')

right_wrench_rt_file = os.path.join(results_dir, 'wrench_right.sto')
left_wrench_rt_file = os.path.join(results_dir, 'wrench_left.sto')
experimental_grfm_file = os.path.join(experimental_dir, 'task_grf.mot')

if not (os.path.isfile(right_wrench_rt_file)
        and os.path.isfile(left_wrench_rt_file)
        and os.path.isfile(experimental_grfm_file)):
    raise RuntimeError('required files do not exist')

# read data
right_wrench = read_from_storage(right_wrench_rt_file).round(10)
left_wrench = read_from_storage(left_wrench_rt_file).round(10)
experimental_grfm = read_from_storage(experimental_grfm_file, True)

# %%

gait_cycle = True
simulation_loops = 2
n = 5  # remove last n rows in experimental_grfm_file
t0 = 0.6
tf = 1.83

r_grf_prefix = 'ground_'
l_grf_prefix = '1_ground_'

# %%
示例#7
0
q_filtered_file = os.path.join(output_dir, folder, 'q_filtered.sto')
q_dot_filtered_file = os.path.join(output_dir, folder, 'qDot_filtered.sto')
q_ddot_filtered_file = os.path.join(output_dir, folder, 'qDDot_filtered.sto')

q_filtered_sp_file = os.path.join(output_dir, 'spatial_filter/q_filtered.sto')
q_dot_filtered_sp_file = os.path.join(output_dir,
                                      'spatial_filter/qDot_filtered.sto')
q_ddot_filtered_sp_file = os.path.join(output_dir,
                                       'spatial_filter/qDDot_filtered.sto')

# %%
# read data

gait_cycle = True

q_reference = read_from_storage(q_reference_file, True)
q_dot_reference = read_from_storage(q_dot_reference_file, True)
q_ddot_reference = read_from_storage(q_ddot_reference_file, True)

q_filtered = read_from_storage(q_filtered_file)
q_dot_filtered = read_from_storage(q_dot_filtered_file)
q_ddot_filtered = read_from_storage(q_ddot_filtered_file)

q_filtered_sp = read_from_storage(q_filtered_sp_file)
q_dot_filtered_sp = read_from_storage(q_dot_filtered_sp_file)
q_ddot_filtered_sp = read_from_storage(q_ddot_filtered_sp_file)

if gait_cycle:
    t0 = 0.6  # right heel strike
    tf = 1.83  # next right heel strike
    q_reference = to_gait_cycle(q_reference, t0, tf)
示例#8
0
absFilePath = os.path.abspath(__file__)
fileDir = os.path.dirname(absFilePath)
parentDir = os.path.dirname(fileDir)

# model file
model_file = os.path.abspath(
    os.path.join(parentDir, 'scale/model_scaled.osim'))
model = opensim.Model(model_file)
state = model.initSystem()
coordinate_set = model.updCoordinateSet()
pelvis = model.updBodySet().get('pelvis')

# model coordinates for this specific motion
inverse_kinematics_file = os.path.abspath(
    os.path.join(parentDir, 'inverse_kinematics/task_InverseKinematics.mot'))
ik_data = read_from_storage(model_file, inverse_kinematics_file)

# this file contains the results from inverse dynamics ignoring the
# ground reaction forces in the calculation.
inverse_dynamics_file = os.path.abspath(
    os.path.join(parentDir, 'inverse_dynamics/task_InverseDynamics.sto'))
id_data = read_from_storage(model_file, inverse_dynamics_file)

# this file contains the results from inverse dynamics ignoring the
# ground reaction forces in the calculation.
markers_file = os.path.abspath(
    os.path.join(parentDir, 'inverse_kinematics/ik_model_marker_locations.sto'))
ik_marker = read_from_storage(model_file, markers_file)

assert(ik_data.shape == id_data.shape)
assert(ik_data.shape[0] == ik_marker.shape[0])
示例#9
0
output_dir = os.path.join(subject_dir, 'real_time/filtering/bw_filter/')

q_reference_file = os.path.join(
    subject_dir, 'residual_reduction_algorithm/task_Kinematics_q.sto')

q_filtered_files = [f for f in os.listdir(output_dir) if f.endswith('.sto')]

for q_filtered_file in q_filtered_files:
    q_filtered_file = os.path.join(output_dir, q_filtered_file)

    # %%
    # read data

    gait_cycle = True

    q_reference = read_from_storage(q_reference_file, True)

    q_filtered = read_from_storage(q_filtered_file)

    # %% reference signal filter parameters

    # get file extension with filter parameters
    s = os.path.basename(os.path.splitext(q_filtered_file)[0]).replace(
        'q_filtered_', '')

    fs = 100  # signal freq
    fc = int(s[s.find('F') + 1:s.rfind('O')])  # target cutoff freq
    filter_order = int(s[s.find('O') + 1:s.rfind('T')])  # filter order

    # filter type
    filter_type_ext = s[s.find('T') + 1:s.rfind('')]
示例#10
0
output_dir = os.path.join(subject_dir, 'pipeline/')

q_reference_file = os.path.join(subject_dir, 'inverse_dynamics/q_filtered.sto')
tau_reference_file = os.path.join(subject_dir, 'inverse_dynamics/tau.sto')
fm_reference_file = os.path.join(subject_dir, 'muscle_optimization/fm.sto')
jr_reference_file = os.path.join(subject_dir, 'joint_reaction_analysis/jr.sto')

q_pipeline_file = os.path.join(output_dir, 'q.sto')
tau_pipeline_file = os.path.join(output_dir, 'tau.sto')
fm_pipeline_file = os.path.join(output_dir, 'fm.sto')
jr_pipeline_file = os.path.join(output_dir, 'jr.sto')

# %%
# read data

q_reference = read_from_storage(q_reference_file)
q_pipeline = read_from_storage(q_pipeline_file)

tau_reference = read_from_storage(tau_reference_file)
tau_pipeline = read_from_storage(tau_pipeline_file)

fm_reference = read_from_storage(fm_reference_file)
fm_pipeline = read_from_storage(fm_pipeline_file)

jr_reference = read_from_storage(jr_reference_file)
jr_pipeline = read_from_storage(jr_pipeline_file)
# make very small number zero before plotting
jr_reference[jr_reference.abs() < 1e-9] = 0
jr_pipeline[jr_pipeline.abs() < 1e-9] = 0

if gait_cycle:
示例#11
0
#
# author: Filip Konstantinos <*****@*****.**>
# %%
import os
import opensim as osim
from utils import read_from_storage
#%%

subject_dir = os.path.abspath('../')
output_dir = os.path.join(subject_dir, 'experimental_data')
trc_file = os.path.join(subject_dir, 'experimental_data/task.trc')

#%%

# load and resample markers at 0.01
df = read_from_storage(trc_file)

# create timeseries table
table = osim.TimeSeriesTable()
table.setColumnLabels(df.columns[1:])
table.addTableMetaDataString('DataRate', '100')
table.addTableMetaDataString('Units', 'mm')

# append data to table
for i in range(df.shape[0]):
    table.appendRow(df.time.values[i], osim.RowVector(df.iloc[i, 1:].values))

# write table to file
osim.TRCFileAdapter.write(table.packVec3(),
                          os.path.join(output_dir, 'task_resampled.trc'))
# %%
# data

gait_cycle = True

subject_dir = os.path.abspath('../')
output_dir = os.path.join(subject_dir, 'real_time/inverse_kinematics/')

q_reference_file = os.path.join(subject_dir,
                                'inverse_kinematics/task_InverseKinematics.mot')
q_rt_file = os.path.join(output_dir, 'q.sto')

# %%
# read data

q_reference = read_from_storage(q_reference_file)
q_rt = read_from_storage(q_rt_file)

if gait_cycle:
    t0 = 0.6                        # right heel strike
    tf = 1.83                       # next right heel strike
    q_reference = to_gait_cycle(q_reference, t0, tf)
    q_rt = to_gait_cycle(q_rt, t0, tf)

plot_sto_file(q_rt_file, q_rt_file + '.pdf', 3)

# %%
# compare

d_q_total = []
with PdfPages(output_dir + 'inverse_kinematics_comparison.pdf') as pdf: