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)
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]) #%% plt.rcParams['axes.prop_cycle'] = plt.cycler('color', plt.cm.tab20c.colors) init_graphing(params.backend) plt.close('all') fig = plt.figure(figsize=(90 / 25.4, 190 / 25.4), dpi=params.dpi) ax = fig.subplots(3, 1) for i in range(3): style_axes(ax[i], 'Humerothoracic Elevation (Deg)' if i == 2 else None, 'Axial Orientation (Deg)') ax[i].xaxis.set_major_locator(ticker.MultipleLocator(base=20.0)) act_row = {'ca': 0, 'sa': 1, 'fe': 2} for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): cur_row = act_row[activity.lower()] _, agg_lines, quat_mean_lines = \ summary_plotter(activity_df['traj_interp'], 'ht', 'ht_ea_up', 'up', 'common_ht_range_coarse', 'common_coarse_up', 'euler.ht_isb', 2, ax[cur_row], ind_plotter, 'black', 'red', error_bars='std', alpha=0.5) # remove the quaternion average line quat_mean_lines[0].remove() del quat_mean_lines[0] make_interactive()
markers = ['^', 'o', 's', '*'] act_order = {'CA': -1, 'SA': 0, 'FE': 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, 230 / 25.4), dpi=params.dpi) axs = fig.subplots(4, 2) # style axes, add x and y labels for i in range(4): for j in range(2): style_axes( axs[i, j], 'Humerothoracic Elevation (Deg)' if i == 3 else None, 'Axial Orientation (deg)' if j == 0 else 'Axial Rotation (Deg)') # set axes limits for i in range(4): axs[i, 1].set_ylim(-45, 55) all_traj_isb_rm = np.stack(db_elev_equal['traj_interp'].apply( extract_sub_rot_norm, args=['gh', 'common_fine_up', 'euler.gh_isb', 2, 'up']), axis=0) all_traj_isb_poe_rm = np.stack(db_elev_equal['traj_interp'].apply( extract_sub_rot_norm, args=['gh', 'common_fine_up', 'euler.gh_isb', 0, 'up']), axis=0)
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, 150 / 25.4), dpi=params.dpi) axs = fig.subplots(2, 2) ax_limits = [(-140, 15), (-110, 30)] 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=25.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) axs[row_idx, col_idx].set_ylim(ax_limits[row_idx][0], ax_limits[row_idx][1]) spm_y = np.array([[13, 13], [27, 27]]) traj_name = 'gh' mean_left_lns = [] mean_right_lns = [] for idx_act, (activity, activity_df) in enumerate( db_er_endpts.groupby('Activity', observed=True)): all_traj_true = np.stack(activity_df[traj_name + '_true'], axis=0) all_traj_isb = np.stack(activity_df[traj_name + '_isb'], axis=0) all_traj_isb_norm = np.stack(activity_df[traj_name + '_isb_norm'], axis=0) all_traj_phadke = np.stack(activity_df[traj_name + '_phadke'], axis=0)
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} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig_diff_hum = plt.figure(figsize=(100 / 25.4, 190 / 25.4)) axs_diff = fig_diff_hum.subplots(3, 1) # style axes, add x and y labels style_axes(axs_diff[0], None, 'Axial Rotation (Deg)') style_axes(axs_diff[1], None, 'Axial Rotation (Deg)') style_axes(axs_diff[2], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') # plot leg_patch_mean = [] for idx, (activity, activity_df) in enumerate(db_elev.groupby('Activity', observed=True)): all_traj_isb = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['gh', 'common_fine_up', 'euler.gh_isb', 2, 'up']), axis=0) all_traj_isb_poe = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['gh', 'common_fine_up', 'euler.gh_isb', 0, 'up']), axis=0) all_traj_true = np.stack(activity_df['traj_interp'].apply( extract_sub_rot_norm, args=['gh', 'common_fine_up', 'true_axial_rot', None, 'up']), axis=0) all_traj_isb_norm = all_traj_isb + all_traj_isb_poe all_traj_isb_max = np.stack(activity_df['traj_interp'].apply(
infer_params = {'force_iterations': True} alpha = 0.05 color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', 'd'] 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_diff = plt.figure(figsize=(190 / 25.4, 190 / 25.4), dpi=params.dpi) axs_diff = fig_diff.subplots(3, 2) # style axes, add x and y labels style_axes(axs_diff[0, 0], None, 'Axial Rotation (Deg)') style_axes(axs_diff[1, 0], None, 'Axial Rotation (Deg)') style_axes(axs_diff[2, 0], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') style_axes(axs_diff[0, 1], None, None) style_axes(axs_diff[1, 1], None, None) style_axes(axs_diff[2, 1], 'Humerothoracic Elevation (Deg)', None) # set axes limits # ax_limits = [(-27, 50), (-30, 42), (-52, 25)] for i in range(3): # axs_diff[i, 0].set_ylim(ax_limits[i][0], ax_limits[i][1]) # axs_diff[i, 1].set_ylim(ax_limits[i][0], ax_limits[i][1]) axs_diff[i, 0].yaxis.set_major_locator(ticker.MultipleLocator(10)) axs_diff[i, 1].yaxis.set_major_locator(ticker.MultipleLocator(10)) axs_diff[0, 1].yaxis.set_major_locator(ticker.MultipleLocator(20))
#%% # plot color_map = plt.get_cmap('Dark2') markers = ['^', 'o', 's', '*'] act_row = {'ca': 0, 'sa': 1, 'fe': 2} ours_ht = db_elev.iloc[0]['traj_interp'].common_ht_range_coarse init_graphing(params.backend) plt.close('all') # ############ EULER ANGLE COMPARISONS FOR GH ################################## fig_std_hum = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_std_hum = fig_std_hum.subplots(3, 2) # style axes, add x and y labels style_axes(axs_std_hum[0, 0], None, 'Elevation/PoE (Deg)') style_axes(axs_std_hum[1, 0], None, 'Elevation/PoE (Deg)') style_axes(axs_std_hum[2, 0], 'Humerothoracic Elevation (Deg)', 'Elevation/PoE (Deg)') style_axes(axs_std_hum[0, 1], None, 'Axial Orientation (Deg)') style_axes(axs_std_hum[1, 1], None, 'Axial Orientation (Deg)') style_axes(axs_std_hum[2, 1], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') # add arrows indicating direction axs_std_hum[0, 0].arrow(20, -40, 0, -40, length_includes_head=True, head_width=2,
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 +
spm_test = spm1d.stats.nonparam.ttest 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} x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') fig_diff0_hum = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_diff0 = fig_diff0_hum.subplots(3, 2) # style axes, add x and y labels style_axes(axs_diff0[0, 0], None, 'Axial Rotation (Deg)') style_axes(axs_diff0[1, 0], None, 'Axial Rotation (Deg)') style_axes(axs_diff0[2, 0], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') style_axes(axs_diff0[0, 1], None, 'SPM{t}') style_axes(axs_diff0[1, 1], None, 'SPM{t}') style_axes(axs_diff0[2, 1], 'Humerothoracic Elevation (Deg)', 'SPM{t}') fig_diff0_dist = plt.figure(figsize=(110 / 25.4, 190 / 25.4)) axs_diff0_dist = fig_diff0_dist.subplots(3, 1) style_axes(axs_diff0_dist[0], None, 'p-value') style_axes(axs_diff0_dist[1], None, 'p-value') style_axes(axs_diff0_dist[2], 'Humerothoracic Elevation (Deg)', 'p-value') # plot leg_patch_mean = []
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()
plot_dir = { 'GH': (get_trajs_gh, get_trajs_gh_start), 'HT': (get_trajs_ht, get_trajs_ht_start), 'ST': (get_trajs_st, get_trajs_st_start) } x = db_elev.iloc[0]['traj_interp'].common_ht_range_fine init_graphing(params.backend) plt.close('all') for traj, traj_fnc in plot_dir.items(): fig_plane = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_plane = fig_plane.subplots(3, 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], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') style_axes(axs_plane[0, 1], None, 'SPM{t}') style_axes(axs_plane[1, 1], None, 'SPM{t}') style_axes(axs_plane[2, 1], 'Humerothoracic Elevation (Deg)', 'SPM{t}') all_traj_isb, all_traj_phadke, all_traj_true = traj_fnc[0](db_elev) all_traj_isb = all_traj_isb - all_traj_isb[:, 0][..., np.newaxis] all_traj_phadke = all_traj_phadke - all_traj_phadke[:, 0][..., np.newaxis] all_traj_true = all_traj_true - all_traj_true[:, 0][..., np.newaxis] group = (db_elev['Activity'].map({ 'CA': 1, 'SA': 2,
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') # plot for idx, (activity, activity_df) in enumerate( db_elev.groupby('Activity', observed=True)): fig_gender = plt.figure(figsize=(190 / 25.4, 190 / 25.4)) axs_gender = fig_gender.subplots(3, 2) # style axes, add x and y labels style_axes(axs_gender[0, 0], None, 'Axial Rotation (Deg)') style_axes(axs_gender[1, 0], None, 'Axial Rotation (Deg)') style_axes(axs_gender[2, 0], 'Humerothoracic Elevation (Deg)', 'Axial Rotation (Deg)') style_axes(axs_gender[0, 1], None, 'SPM{t}') style_axes(axs_gender[1, 1], None, 'SPM{t}') style_axes(axs_gender[2, 1], 'Humerothoracic Elevation (Deg)', 'SPM{t}') activity_df_m = activity_df.loc[activity_df['Gender'] == 'M'] activity_df_f = activity_df.loc[activity_df['Gender'] == 'F'] all_traj_isb_m = np.stack(activity_df_m['traj_interp'].apply( extract_sub_rot, args=['gh', 'common_fine_up', 'euler.gh_isb', 2]), axis=0) all_traj_phadke_m = np.stack(activity_df_m['traj_interp'].apply(
#%% 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)