def grp_plotter(activity_df, col_name, pdf_file_path, grp_c, plot_directives, section): with PdfPages(pdf_file_path) as grp_pdf: for name, plot_dir in plot_directives.items(): fig = plt.figure() ax = fig.subplots() ind_lines = [] ind_leg_entries = [] avg_lines = [] avg_entries = [] quat_avg_lines = [] quat_avg_entries = [] for grp, grp_df in activity_df.groupby(col_name): ind_plotter_fnc = partial(ind_plotter_color_spec, c=grp_c[grp][0]) ind_traj_plot_lines, agg_lines, quat_mean_lines = summary_plotter( grp_df['traj_interp'], plot_dir.traj, section[0], section[1], section[2], section[3], plot_dir.decomp_method, plot_dir.sub_rot, ax, ind_plotter_fnc, grp_c[grp][1], grp_c[grp][2]) ind_lines.append(ind_traj_plot_lines.iloc[0][0]) ind_leg_entries.append(grp) avg_lines.append(agg_lines[0]) avg_entries.append(grp + r' Mean$\pm$SE') if quat_mean_lines is not None: quat_avg_lines.append(quat_mean_lines[0]) quat_avg_entries.append(grp + ' Mean(Quat)') ax.legend(ind_lines, ind_leg_entries, handlelength=0.75, handletextpad=0.25, columnspacing=0.5, loc='lower right') ax.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) style_axes(ax, 'Humerothoracic Elevation (Deg)', plot_dir.y_label) fig.tight_layout() fig.suptitle(plot_dir.title) if quat_avg_lines: fig.legend(avg_lines + quat_avg_lines, avg_entries + quat_avg_entries, loc='lower left', handlelength=0.75, handletextpad=0.25, ncol=2) else: fig.legend(avg_lines, avg_entries, loc='lower left', handlelength=0.75, handletextpad=0.25) grp_pdf.savefig(fig) fig.clf() plt.close(fig)
#%% color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'erar': 0, 'era90': 1} x = np.arange(0, 100 + params.dtheta_fine, params.dtheta_fine) init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) axs = fig.subplots(3, 2) # style axes, add x and y labels for i in range(3): for j in range(2): style_axes(axs[i, j], 'Motion Completion (%)' if i == 2 else None, 'Rotation (deg)' if j == 0 else None) axs[i, j].yaxis.set_major_locator(plticker.MultipleLocator(10)) # plot leg_mean = [] max_pos = 140 for idx, (activity, activity_df) in enumerate( db_er_endpts.groupby('Activity', observed=True)): st_contribs = np.stack(activity_df['st_contribs_interp'], axis=0) gh_contribs = np.stack(activity_df['gh_contribs_interp'], axis=0) trajs_st_elev = st_contribs[:, :, 1] trajs_gh_elev = gh_contribs[:, :, 1] trajs_st_axial = st_contribs[:, :, 2] trajs_gh_axial = gh_contribs[:, :, 2]
db_elev['traj_interp'].apply(add_st_induced, args=[st_induced_axial_rot_fha]) #%% color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig_plane = plt.figure(figsize=(190 / 25.4, 230 / 25.4)) axs_plane = fig_plane.subplots(4, 2) # style axes, add x and y labels style_axes(axs_plane[0, 0], None, 'Axial Rotation (Deg)') style_axes(axs_plane[1, 0], None, 'Axial Rotation (Deg)') style_axes(axs_plane[2, 0], None, 'Axial Rotation (Deg)') style_axes(axs_plane[3, 0], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') style_axes(axs_plane[0, 1], None, 'SPM{F}') style_axes(axs_plane[1, 1], None, 'SPM{F}') style_axes(axs_plane[2, 1], None, 'SPM{F}') style_axes(axs_plane[3, 1], 'Humerothoracic Elevation (Deg)', 'SPM{F}') all_traj_induced = np.stack(db_elev_equal['traj_interp'].apply( extract_sub_rot_norm, args=['st', 'common_fine_up', 'induced_axial_rot', 3, 'up']), axis=0) all_traj_induced_x = np.stack(db_elev_equal['traj_interp'].apply( extract_sub_rot_norm,
act_row = {'ca': 0, 'sa': 1, 'fe': 2} init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) gs = fig.add_gridspec(6, 2) axs_elev = [ fig.add_subplot(gs[:2, 0]), fig.add_subplot(gs[2:4, 0]), fig.add_subplot(gs[4:6, 0]) ] axs_er = [fig.add_subplot(gs[:3, 1]), fig.add_subplot(gs[3:6, 1])] for i in range(3): style_axes(axs_elev[i], 'GH Axial Rotation (Deg)' if i == 2 else None, 'ST Axial Rotation (Deg)') for i in range(2): style_axes(axs_er[i], 'GH Axial Rotation (Deg)' if i == 1 else None, 'ST Axial Rotation (Deg)') # plot elevation leg_elev_mean = [] r_loc = [(10, -19), (20, -12), (19, 16)] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): traj_st = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['st', 'common_fine_up', 'contribs', 2, 'up']), axis=0) traj_gh = np.stack(activity_df['traj_interp'].apply(
x_er = np.arange(0, 100 + params.dtheta_fine, params.dtheta_fine) init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) gs = fig.add_gridspec(6, 2) axs_elev = [ fig.add_subplot(gs[:2, 0]), fig.add_subplot(gs[2:4, 0]), fig.add_subplot(gs[4:6, 0]) ] axs_er = [fig.add_subplot(gs[:3, 1]), fig.add_subplot(gs[3:6, 1])] for i in range(3): style_axes(axs_elev[i], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'ST Axial Rotation (Deg)') for i in range(2): style_axes(axs_er[i], 'Motion Completion (%)' if i == 1 else None, 'ST Axial Rotation (Deg)') # plot elevation leg_elev_mean = [] spm_y = {'ca': 2, 'sa': 4, 'fe': 21} for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): lt35_df = activity_df[activity_df['age_group'] == '<35'] gt45_df = activity_df[activity_df['age_group'] == '>45'] traj_st_lt35 = np.stack(lt35_df['traj_interp'].apply(
color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig_axial = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_axial = fig_axial.subplots(3, 2) fig_norm = plt.figure(figsize=(120 / 25.4, 190 / 25.4)) ax_norm = fig_norm.subplots(3, 1) for ax in ax_norm: ax.axhline(0.05, ls='--', color='grey') style_axes(ax, 'Humerothoracic Elevation (Deg)', 'p-value') # style axes, add x and y labels style_axes(axs_axial[0, 0], None, 'Induced Axial Rotation (Deg)') style_axes(axs_axial[1, 0], None, 'Induced Axial Rotation (Deg)') style_axes(axs_axial[2, 0], 'Humerothoracic Elevation (Deg)', 'Induced Axial Rotation (Deg)') style_axes(axs_axial[0, 1], None, 'SPM{t}') style_axes(axs_axial[1, 1], None, 'SPM{t}') style_axes(axs_axial[2, 1], 'Humerothoracic Elevation (Deg)', 'SPM{t}') # plot leg_patch_mean = [] leg_patch_t = [] alpha_patch = [] for idx, (activity, activity_df) in enumerate(
plot_utils.init_graphing(params.backend) plt.close('all') x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine fig_st = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_st = fig_st.subplots(3, 2) fig_gh = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_gh = fig_gh.subplots(3, 2) st_lims = [(-5, 50), (-5, 50), (-5, 50)] gh_lims = [(-10, 95), (0, 90), (-10, 95)] for i in range(3): for j in range(2): style_axes(axs_st[i, j], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Elevation (deg)' if j == 0 else None) style_axes(axs_gh[i, j], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Elevation (deg)' if j == 0 else None) axs_st[i, j].set_ylim(st_lims[i][0], st_lims[i][1]) axs_gh[i, j].set_ylim(gh_lims[i][0], gh_lims[i][1]) axs_gh[i, j].yaxis.set_major_locator( plticker.MultipleLocator(base=10.0)) axs_st[i, j].yaxis.set_major_locator( plticker.MultipleLocator(base=10.0)) leg_mean_st = [] leg_mean_gh = [] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)):
params.torso_def + ('_' + params.scap_lateral) + '.pdf') with PdfPages(pdf_file_path) as activity_pdf: for trial_name, df_row in activity_df.iterrows(): st_traj = df_row['traj_interp'].st gh_traj = df_row['traj_interp'].gh up_down = df_row['up_down_analysis'] start_idx = up_down.max_run_up_start_idx end_idx = up_down.max_run_up_end_idx sec = slice(start_idx, end_idx + 1) fig = plt.figure() ax = fig.subplots() ax.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax, 'HT Elevation Angle', 'Rotation (deg)') ht_elev = np.rad2deg(-df_row['ht'].euler.ht_isb[sec, 1]) st_poe_plt = ax.plot(ht_elev, np.rad2deg(st_traj.contribs[sec, 0]), label='ST PoE') st_elev_plt = ax.plot(ht_elev, -np.rad2deg(st_traj.contribs[sec, 1]), label='ST Elev') st_axial_plt = ax.plot(ht_elev, np.rad2deg(st_traj.contribs[sec, 2]), label='ST Axial') ax.plot(ht_elev, np.rad2deg(gh_traj.contribs[sec, 0]), '--',
plot_dir.decomp_method, plot_dir.sub_rot, ax, ind_plotter, 'black', 'red') if quat_mean_lines: ax.legend([agg_lines.lines[0], quat_mean_lines[0]], [r'Mean$\pm$SE', 'Mean(Quat)'], loc='lower right', handlelength=0.75, handletextpad=0.25) else: ax.legend([agg_lines.lines[0]], [r'Mean$\pm$SE'], loc='lower right', handlelength=0.75, handletextpad=0.25) ax.xaxis.set_major_locator( plticker.MultipleLocator(base=10.0)) style_axes(ax, 'Humerothoracic Elevation (Deg)', plot_dir.y_label) fig.tight_layout() fig.subplots_adjust(bottom=0.2) fig.suptitle(plot_dir.title) fig.legend(ncol=10, handlelength=0.75, handletextpad=0.25, columnspacing=0.5, loc='lower left', fontsize=8) activity_pdf.savefig(fig) fig.clf() plt.close(fig) # plot by gender pdf_file_path = output_path / (activity + '_' + params.torso_def +
db_elev = db.loc[db['Trial_Name'].str.contains('_CA_|_SA_|_FE_')].copy() prepare_db(db_elev, params.torso_def, params.scap_lateral, params.dtheta_fine, params.dtheta_coarse, [params.min_elev, params.max_elev]) db_elev['traj_interp'].apply(add_st_gh_contrib) #%% x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine contrib_axes = ['PoE', 'Elevation', 'Axial'] plt.rcParams['axes.prop_cycle'] = plt.cycler('color', plt.cm.tab20c.colors) plot_utils.init_graphing(params.backend) plt.close('all') for activity, activity_df in db_elev.groupby('Activity', observed=True): fig_gh = plt.figure() ax_gh = fig_gh.subplots() ax_gh.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax_gh, 'HT Elevation Angle', 'Alignment (deg)') fig_st = plt.figure() ax_st = fig_st.subplots() ax_st.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax_st, 'HT Elevation Angle', 'Alignment (deg)') for trial_name, df_row in activity_df.iterrows(): age_grp = df_row['age_group'] ht = df_row['ht'] st = df_row['st'] gh = df_row['gh'] up_down = df_row['up_down_analysis'] start_idx = up_down.max_run_up_start_idx end_idx = up_down.max_run_up_end_idx sec = slice(start_idx, end_idx + 1)
args=[st_induced_axial_rot_fha]) #%% color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig_axial = plt.figure(figsize=(90 / 25.4, 210 / 25.4)) axs_axial = fig_axial.subplots(3, 1) # style axes, add x and y labels style_axes(axs_axial[0], None, 'Induced Axial Rotation (Deg)') style_axes(axs_axial[1], None, 'Induced Axial Rotation (Deg)') style_axes(axs_axial[2], 'Humerothoracic Elevation (Deg)', 'Induced Axial Rotation (Deg)') # plot leg_patch_mean = [] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): all_traj_induced = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['st', 'common_fine_up', 'induced_axial_rot', 3, 'up']), axis=0) all_traj_induced_x = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['st', 'common_fine_up', 'induced_axial_rot', 0, 'up']),
infer_params = {'force_iterations': True} alpha = 0.05 color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} plot_utils.init_graphing(params.backend) plt.close('all') x = np.arange(0, 100 + 0.25, 0.25) fig = plt.figure(figsize=(110 / 25.4, 190 / 25.4), dpi=params.dpi) axs = fig.subplots(3, 1) for i in range(3): style_axes(axs[i], 'Motion Completion (%)' if i == 2 else None, 'SHR') axs[i].set_ylim(0, 12) leg_mean = [] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): old_shr = np.stack(activity_df['old_shr_interp'], axis=0) new_shr = np.stack(activity_df['new_shr_interp'], axis=0) # means and standard deviations old_shr_mean = np.mean(old_shr, axis=0) new_shr_mean = np.mean(new_shr, axis=0) old_shr_sd = np.std(old_shr, ddof=1, axis=0) new_shr_sd = np.std(new_shr, ddof=1, axis=0)
start_idx = db_row.up_down_analysis.max_run_up_start_idx end_idx = db_row.up_down_analysis.max_run_up_end_idx + 1 sec = slice(start_idx, end_idx) ht_elev = -np.rad2deg(db_row['ht'].euler.ht_isb[sec, 1]) for seg in ['ht', 'gh']: euler_int = db_row[seg + '_contribs_euler_rates'] euler = db_row[seg].euler.yxy_intrinsic fig = plt.figure(figsize=(120 / 25.4, 190 / 25.4)) axs = fig.subplots(3, 1) y_labels = ['Plane of Elevation', 'Elevation', 'Axial Rotation'] for i in range(3): style_axes(axs[i], seg.upper() + ' Elevation (Deg)' if i == 2 else None, y_labels[i]) elev_lns = [] poe_lns = [] axial_lns = [] poe_ln = axs[0].plot(ht_elev, np.rad2deg(euler[sec, 0])) elev_ln = axs[1].plot(ht_elev, np.rad2deg(euler[sec, 1])) axial_ln = axs[2].plot(ht_elev, np.rad2deg(db_row[seg].true_axial_rot[sec])) poe_int_ln = axs[0].plot(ht_elev, np.rad2deg(euler[0, 0] + euler_int[sec, 0]), '--', dashes=(5, 10))
color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) axs = fig.subplots(3, 2) # style axes, add x and y labels for i in range(3): for j in range(2): style_axes(axs[i, j], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Motion Allocation (%)' if j == 0 else None) axs[i, j].yaxis.set_major_locator(plticker.MultipleLocator(10)) axs[i, j].set_ylim(0, 100) # plot max_pos = 140 leg_mean = [] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): trajs_st_elev = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['st', 'common_fine_up', 'contribs', 1, 'up']), axis=0) trajs_gh_elev = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm,
db_elev['traj_interp'].apply(add_st_gh_contrib) #%% color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 90 / 25.4)) axs = fig.subplots(1, 3) for i in range(3): style_axes(axs[i], 'Humerothoracic Elevation (deg)', 'PoE (deg)' if i == 0 else 'ST Axial Rotation (deg)') # # set axes limits # ax_limits = [(20, 70), (-40, 50)] # for i in range(3): # for j in range(2): # axs[i, j].set_ylim(ax_limits[j][0], ax_limits[j][1]) # axs[i, j].yaxis.set_major_locator(ticker.MultipleLocator(10)) # style_axes(axs[i, j], 'Humerothoracic Elevation (Deg)' if i == 2 else None, # 'ReProtraction (Deg)' if j == 0 else 'PoE (Deg)') # plot max_pos = 140 leg_mean = [] for act_idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)):
fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) gs = fig.add_gridspec(2, 6) axs_elev = [ fig.add_subplot(gs[0, :2]), fig.add_subplot(gs[0, 2:4]), fig.add_subplot(gs[0, 4:6]) ] y_labels = [ 'GH PoE (deg)', 'ST-contributed Axial Rotation (deg)', 'ST-contributed Axial Rotation (deg)' ] for i in range(3): style_axes( axs_elev[i], 'Mean GH PoE (deg)' if i == 2 else 'Humerothoracic Elevation (deg)', y_labels[i]) if i == 0: axs_elev[i].set_ylim(-40, 38) else: axs_elev[i].set_ylim(-35, 30) # plot max_pos = 140 leg_mean = [] poes = [] st_axials = [] r_loc = [(-10, -25), (30, 10), (10, -5)] for act_idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): traj_poe = np.stack(activity_df['traj_interp'].apply( extract_sub_rot,
gh_poe_per = (np.abs(gh_poe) / gh_total) * 100 gh_elev_per = (np.abs(gh_elev) / gh_total) * 100 gh_axial_per = (np.abs(gh_axial) / gh_total) * 100 st_poe_per = (np.abs(st_poe) / st_total) * 100 st_elev_per = (np.abs(st_elev) / st_total) * 100 st_axial_per = (np.abs(st_axial) / st_total) * 100 gh_array = [np.abs(gh_poe_per), gh_elev_per, gh_axial_per] st_array = [np.abs(st_poe_per), st_elev_per, st_axial_per] for axis_idx, contrib_axis in enumerate(contrib_axes): fig_gh = plt.figure() ax_gh = fig_gh.subplots() ax_gh.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax_gh, 'HT Elevation Angle', 'Percentage (%)') fig_st = plt.figure() ax_st = fig_st.subplots() ax_st.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax_st, 'HT Elevation Angle', 'Percentage (%)') for trial_idx, (trial_name, age_grp) in enumerate(zip(activity_df['Trial_Name'], activity_df['age_group'])): ax_gh.plot(x, gh_array[axis_idx][trial_idx], label='_'.join(trial_name.split('_')[0:2])) ax_st.plot(x, st_array[axis_idx][trial_idx], label='_'.join(trial_name.split('_')[0:2])) ax_gh.plot(x, np.mean(gh_array[axis_idx], axis=0), color='k', label='Mean') ax_st.plot(x, np.mean(st_array[axis_idx], axis=0), color='k', label='Mean') fig_gh.tight_layout() fig_gh.subplots_adjust(bottom=0.2)
params.scap_lateral, params.dtheta_fine, params.dtheta_coarse, [params.min_elev, params.max_elev], should_clean=False) (db['up_min_ht'], db['up_max_ht'], db['down_min_ht'], db['down_max_ht']) = zip( *(db['up_down_analysis'].apply(extract_up_down_min_max))) plot_utils.init_graphing(params.backend) plot_dirs = [['ht', 'ht_isb', 'HT'], ['gh', 'gh_isb', 'GH'], ['st', 'st_isb', 'ST']] for plot_dir in plot_dirs: traj = db.loc['U35_002_SA_t01', plot_dir[0]] traj_euler = getattr(traj, 'euler') fig = plt.figure(figsize=(14, 7), tight_layout=True) ax = fig.subplots(2, 3) for i in range(3): ax[0, i].plot(np.rad2deg(getattr(traj_euler, plot_dir[1])[:, i])) ax[1, i].plot(traj.pos[:, i]) if i == 0: plot_utils.style_axes(ax[0, i], None, 'Orientation (deg)') plot_utils.style_axes(ax[1, i], 'Frame Index (Zero-Based)', 'Position (mm)') else: plot_utils.style_axes(ax[0, i], None, None) plot_utils.style_axes(ax[1, i], 'Frame Index (Zero-Based)', None) fig.suptitle(plot_dir[2]) plot_utils.make_interactive() plt.show()
yticks = [np.arange(0, 13, 2), np.arange(0, 16, 5), np.arange(-1, 3.1, 1)] ylim = [(0, 12), (0, 18), (-1.5, 3.5)] for i in range(3): axs_axial_twin[i] = axs_axial[i, 0].twinx() axs_axial_twin[i].set_yticks(yticks[i]) style_axes_add_right(axs_axial_twin[i], 'Axial Rotation SHR') axs_axial_twin[i].axhline(axial_shr_dash[i], ls='--', color='grey') axs_axial_twin[i].set_ylim(ylim[i][0], ylim[i][1]) axs_axial[i, 0].set_zorder(1) axs_axial[i, 0].patch.set_visible(False) axs_axial_twin[i].yaxis.set_tick_params(direction='in', width=2, pad=3) # style axes, add x and y labels for i in range(3): style_axes(axs_axial[i, 0], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Axial Rotation (Deg)') axs_axial[i, 1].yaxis.set_label_position('right') axs_axial[i, 1].yaxis.tick_right() style_axes_right(axs_axial[i, 1], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'SPM{t}') axs_axial[i, 1].yaxis.set_tick_params(direction='in', width=2, pad=3) fig_norm = plt.figure(figsize=(120 / 25.4, 190 / 25.4)) ax_norm = fig_norm.subplots(3, 1) for ax in ax_norm: ax.axhline(0.05, ls='--', color='grey') style_axes(ax, 'Humerothoracic Elevation (Deg)', 'p-value') # plot
x_er = np.arange(0, 100 + params.dtheta_fine, params.dtheta_fine) init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) gs = fig.add_gridspec(6, 2) axs_elev = [ fig.add_subplot(gs[:2, 0]), fig.add_subplot(gs[2:4, 0]), fig.add_subplot(gs[4:6, 0]) ] axs_er = [fig.add_subplot(gs[:3, 1]), fig.add_subplot(gs[3:6, 1])] for i in range(3): style_axes(axs_elev[i], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'PoE Contribution (Deg)') for i in range(2): style_axes(axs_er[i], 'Motion Completion (%)' if i == 1 else None, 'PoE Contribution (Deg)') # plot elevation leg_elev_mean = [] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): traj_st = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['st', 'common_fine_up', 'contribs', 0, 'up']), axis=0) traj_gh = np.stack(activity_df['traj_interp'].apply(
x = np.arange(0, 100 + params.dtheta_fine, params.dtheta_fine) alpha = 0.05 color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] plot_utils.init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs = fig.subplots(2, 3) for row_idx, row in enumerate(axs): for col_idx, ax in enumerate(row): ax.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) ax.yaxis.set_major_locator(plticker.MultipleLocator(base=5.0)) x_label = 'Percent Complete (%)' if row_idx == 1 else None y_label = 'Axial Rotation (Deg)' if col_idx == 0 else None style_axes(ax, x_label, y_label) mean_lns = [] for idx_act, (activity, activity_df) in enumerate( db_er_endpts.groupby('Activity', observed=True)): lt35_df = activity_df[activity_df['age_group'] == '<35'] gt45_df = activity_df[activity_df['age_group'] == '>45'] traj_ht_lt35 = np.stack(lt35_df['ht_true_axial'], axis=0) traj_ht_gt45 = np.stack(gt45_df['ht_true_axial'], axis=0) traj_st_lt35 = np.stack(lt35_df['st_induced_total'], axis=0) traj_st_gt45 = np.stack(gt45_df['st_induced_total'], axis=0) traj_gh_lt35 = np.stack(lt35_df['gh_true_axial'], axis=0) traj_gh_gt45 = np.stack(gt45_df['gh_true_axial'], axis=0)
#%% x = np.arange(0, 100 + params.dtheta_fine, params.dtheta_fine) # we need more colors to encompass all subjects than the default color scale offers plt.rcParams['axes.prop_cycle'] = plt.cycler('color', plt.cm.tab20c.colors) plot_utils.init_graphing(params.backend) plt.close('all') for activity, activity_df in db_er.groupby('Activity', observed=True): # overall pdf_file_path = output_path / (activity + '_' + params.torso_def + ('_' + params.scap_lateral) + '.pdf') with PdfPages(pdf_file_path) as activity_pdf: for dir_name, plot_directive in plot_directives.items(): fig = plt.figure() ax = fig.subplots() ax.xaxis.set_major_locator(plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax, 'Percent Completion (%)', plot_directive.y_label) for trial_name, interp_data in zip(activity_df['Trial_Name'], activity_df[dir_name]): ax.plot(x, np.rad2deg(interp_data), label='_'.join(trial_name.split('_')[0:2])) fig.tight_layout() fig.subplots_adjust(bottom=0.2) fig.suptitle(activity + ' ' + plot_directive.title) fig.legend(ncol=10, handlelength=0.75, handletextpad=0.25, columnspacing=0.5, loc='lower left', fontsize=8) activity_pdf.savefig(fig)
plt.rcParams['axes.prop_cycle'] = plt.cycler('color', plt.cm.tab20c.colors) plot_utils.init_graphing(params.backend) plt.close('all') for activity, activity_df in db_er.groupby('Activity', observed=True): # overall pdf_file_path = output_path / ('contribs_' + activity + '_' + params.torso_def + ('_' + params.scap_lateral) + '.pdf') with PdfPages(pdf_file_path) as activity_pdf: for joint in joints: for dim_idx, plot_dir in plot_dirs.items(): fig = plt.figure() ax = fig.subplots() ax.xaxis.set_major_locator( plticker.MultipleLocator(base=10.0)) plot_utils.style_axes(ax, 'Percent Completion (%)', 'Rotation (deg)') for trial_name, interp_data in zip( activity_df['Trial_Name'], activity_df[joint + '_contribs_interp']): ax.plot(x, np.rad2deg(interp_data[:, dim_idx]), label='_'.join(trial_name.split('_')[0:2])) fig.tight_layout() fig.subplots_adjust(bottom=0.2) fig.suptitle(joint.upper() + ' ' + plot_dir) fig.legend(ncol=10, handlelength=0.75, handletextpad=0.25, columnspacing=0.5, loc='lower left', fontsize=8)
colors = {'ca': 1, 'sa': 2, 'fe': 0} x_elev = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 100 / 25.4), dpi=params.dpi) axs_elev = fig.subplots(1, 3) y_labels = [ 'GH PoE (deg)', 'ST-contributed Axial Rotation (deg)', 'ST-contributed Axial Rotation (deg)' ] for i in range(3): style_axes( axs_elev[i], 'Mean GH PoE (deg)' if i == 2 else 'Humerothoracic Elevation (deg)', y_labels[i]) if i == 0: axs_elev[i].set_ylim(-40, 38) else: axs_elev[i].set_ylim(-35, 30) # plot max_pos = 140 leg_mean = [] poes = [] st_axials = [] r_loc = [(-10, -25), (30, 10), (10, -5)] for act_idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): traj_poe = np.stack(activity_df['traj_interp'].apply( extract_sub_rot,
alpha = 0.05 color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} plot_utils.init_graphing(params.backend) plt.close('all') x = np.arange(0, 100 + 0.25, 0.25) fig = plt.figure(figsize=(110 / 25.4, 190 / 25.4)) axs = fig.subplots(3, 1) for i in range(3): style_axes(axs[i], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Elevation (deg)') axs[i].set_ylim(0, 12) leg_mean = [] for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): old_shr = np.stack(activity_df['old_shr_interp'], axis=0) new_shr = np.stack(activity_df['new_shr_interp'], axis=0) # means and standard deviations old_shr_mean = np.mean(old_shr, axis=0) new_shr_mean = np.mean(new_shr, axis=0) old_shr_sd = np.std(old_shr, ddof=1, axis=0) new_shr_sd = np.std(new_shr, ddof=1, axis=0)
alpha = 0.05 color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'erar': 0, 'era90': 1} x = np.arange(0, 100 + params.dtheta_fine, params.dtheta_fine) init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) axs = fig.subplots(2, 2) # style axes, add x and y labels for i in range(2): for j in range(2): style_axes(axs[i, j], 'Motion Completion (%)' if i == 1 else None, 'Motion Allocation (%)' if j == 0 else None) axs[i, j].yaxis.set_major_locator(plticker.MultipleLocator(10)) axs[i, j].set_ylim(0, 100) # plot max_pos = 140 leg_mean = [] # leg_patch_t = [] # alpha_patch = [] for idx, (activity, activity_df) in enumerate( db_er_endpts.groupby('Activity', observed=True)): st_contribs = np.stack(activity_df['st_contribs_interp'], axis=0) gh_contribs = np.stack(activity_df['gh_contribs_interp'], axis=0) trajs_st_elev = st_contribs[:, 1:, 1] trajs_gh_elev = gh_contribs[:, 1:, 1]
x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs = fig.subplots(3, 3) # set axes limits ax_limits = [(-35, 10), (-40, 20), (-20, 40)] for i in range(3): for j in range(3): axs[i, j].set_ylim(ax_limits[i][0], ax_limits[i][1]) axs[i, j].yaxis.set_major_locator(ticker.MultipleLocator(10)) style_axes(axs[i, j], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Axial Rotation (Deg)' if j == 0 else None) # plot leg_mean = [] for act_idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): f_df = activity_df[activity_df['Gender'] == 'F'] m_df = activity_df[activity_df['Gender'] == 'M'] all_traj_ht_f = np.stack(f_df['traj_interp'].apply( extract_sub_rot_norm, args=['ht', 'common_fine_up', 'true_axial_rot', None, 'up']), axis=0) all_traj_gh_f = np.stack(f_df['traj_interp'].apply( extract_sub_rot_norm,
act_row = {'ca': 0, 'sa': 1, 'fe': 2} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs = fig.subplots(3, 2) # set axes limits ax_limits = [(20, 70), (-40, 50)] for i in range(3): for j in range(2): axs[i, j].set_ylim(ax_limits[j][0], ax_limits[j][1]) axs[i, j].yaxis.set_major_locator(ticker.MultipleLocator(10)) style_axes(axs[i, j], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'ReProtraction (Deg)' if j == 0 else 'PoE (Deg)') # plot leg_mean = [] for act_idx, (activity, activity_df) in enumerate(db_elev.groupby('Activity', observed=True)): db = db[~db['Trial_Name'].str.contains('|'.join(params.excluded_trials))] lt35_df = activity_df[activity_df['age_group'] == '<35'] gt45_df = activity_df[activity_df['age_group'] == '>45'] all_traj_repro_lt35 = np.stack(lt35_df['traj_interp'].apply( extract_sub_rot, args=['st', 'common_fine_up', 'euler.st_isb', 0]), axis=0) all_traj_poe_lt35 = np.stack(lt35_df['traj_interp'].apply( extract_sub_rot, args=['gh', 'common_fine_up', 'euler.gh_isb', 0]), axis=0) all_traj_repro_gt45 = np.stack(gt45_df['traj_interp'].apply( extract_sub_rot, args=['st', 'common_fine_up', 'euler.st_isb', 0]), axis=0)