예제 #1
0
                                   marker=markers[0], capsize=3)
        axs_elev[cur_row].errorbar(max_pos + 3, st_max_mean, yerr=st_max_sd, color=color_map.colors[1],
                                   marker=markers[1], capsize=3)
        axs_elev[cur_row].errorbar(max_pos - 3, ht_max_mean, yerr=ht_max_sd, color=color_map.colors[2],
                                   marker=markers[2], capsize=3)

        # spm
        if activity.lower() == 'fe':
            st_vs_gh = spm_test(traj_st - traj_gh, 0).inference(alpha, two_tailed=True, **infer_params)
        else:
            st_vs_gh = spm_test(-(traj_st - traj_gh), 0).inference(alpha, two_tailed=True, **infer_params)
        x_sig = sig_filter(st_vs_gh, x_elev)
        axs_elev[cur_row].plot(x_sig, np.repeat(spm_y[activity.lower()], x_sig.size), color='k')

        print('Activity: {}'.format(activity))
        print(extract_sig(st_vs_gh, x_elev))
        print('P-values: ')
        print(output_spm_p(st_vs_gh))
        print('HT Max: {:.2f}'.format(np.abs(ht_max_mean)))
        print('ST Max: {:.2f}'.format(np.abs(st_max_mean)))
        print('GH Max: {:.2f}'.format(np.abs(gh_max_mean)))
        print('Percentage: {:.2f}'.format(st_max_mean / ht_max_mean * 100))

        if idx == 0:
            leg_elev_mean.append(ht_ln[0])
            leg_elev_mean.append(st_ln[0])
            leg_elev_mean.append(gh_ln[0])

    # plot external rotation
    print('\nEXTERNAL ROTATION')
    for idx_act, (activity, activity_df) in enumerate(db_er_endpts.groupby('Activity', observed=True)):
                                   yerr=st_gt45_max_sd,
                                   color=color_map.colors[1],
                                   marker=markers[1],
                                   capsize=3)

        # spm
        lt35_vs_gt45 = spm_test(traj_st_lt35,
                                traj_st_gt45).inference(alpha,
                                                        two_tailed=True,
                                                        **infer_params)
        x_sig = sig_filter(lt35_vs_gt45, x_elev)
        axs_elev[cur_row].plot(x_sig,
                               np.repeat(spm_y[activity.lower()], x_sig.size),
                               color='k')
        print(activity)
        print(extract_sig(lt35_vs_gt45, x_elev))

        if idx == 0:
            leg_elev_mean.append(st_lt35_ln[0])
            leg_elev_mean.append(st_gt45_ln[0])

    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_st_lt35 = np.stack(lt35_df['st_contribs_interp'], axis=0)[:, :, 2]
        traj_st_gt45 = np.stack(gt45_df['st_contribs_interp'], axis=0)[:, :, 2]

        # means and standard deviations
        st_lt35_mean = np.rad2deg(np.mean(traj_st_lt35, axis=0))
예제 #3
0
        true_sd_st = np.rad2deg(np.std(all_traj_true_st, ddof=1, axis=0))

        # spm
        ht_zero = spm_test(all_traj_true_ht, 0).inference(alpha,
                                                          two_tailed=True,
                                                          **infer_params)
        gh_zero = spm_test(all_traj_true_gh, 0).inference(alpha,
                                                          two_tailed=True,
                                                          **infer_params)
        st_zero = spm_test(all_traj_true_st, 0).inference(alpha,
                                                          two_tailed=True,
                                                          **infer_params)

        print('Activity: {}'.format(activity))
        print('HT')
        print(extract_sig(ht_zero, x))
        print('GH')
        print(extract_sig(gh_zero, x))
        print('Min axial rotation: {:.2f} max axial rotation: {:.2f}'.format(
            np.min(true_mean_gh), np.max(true_mean_gh)))
        print('ST')
        print(extract_sig(st_zero, x))

        # plot mean +- sd
        cur_row = act_row[activity.lower()]
        true_gh_ln = mean_sd_plot(
            axs_axial[cur_row, 0], x, true_mean_gh, true_sd_gh,
            dict(color=color_map.colors[0], alpha=0.25, hatch='...'),
            dict(color=color_map.colors[0], marker=markers[0], markevery=20))
        true_st_ln = mean_sd_plot(
            axs_axial[cur_row, 0], x, true_mean_st, true_sd_st,
        induced_x_zero = spm_test(all_traj_induced_x,
                                  0).inference(alpha,
                                               two_tailed=True,
                                               **infer_params)
        induced_y_zero = spm_test(all_traj_induced_y,
                                  0).inference(alpha,
                                               two_tailed=True,
                                               **infer_params)
        induced_z_zero = spm_test(all_traj_induced_z,
                                  0).inference(alpha,
                                               two_tailed=True,
                                               **infer_params)

        print('Activity: {}'.format(activity))
        print('Total')
        print(extract_sig(induced_zero, x))
        print('Max: {:.2f}'.format(np.max(np.absolute(induced_mean))))
        print('LatMed')
        print(extract_sig(induced_x_zero, x))
        print('Max: {:.2f}'.format(np.max(np.absolute(induced_mean_x))))
        print('RePro')
        print(extract_sig(induced_y_zero, x))
        print('Max: {:.2f}'.format(np.max(np.absolute(induced_mean_y))))
        print('Tilt')
        print(extract_sig(induced_z_zero, x))
        print('Max: {:.2f}'.format(np.max(np.absolute(induced_mean_z))))

        # plot mean +- sd
        cur_row = act_row[activity.lower()]
        induced_ln = mean_sd_plot(
            axs_axial[cur_row, 0], x, induced_mean, induced_sd,
예제 #5
0
        # plot spm
        x_sig_euler_add = sig_filter(ht_euler_diff_vs_euler_add, x)
        # x_sig_contribs = sig_filter(ht_euler_diff_vs_contribs, x)
        axs[cur_row].plot(x_sig_euler_add,
                          np.repeat(spm_y[cur_row], x_sig_euler_add.size),
                          color=color_map.colors[0],
                          lw=2)
        # axs[cur_row].plot(x_sig_contribs, np.repeat(spm_y[cur_row] - 1, x_sig_contribs.size),
        #                   color=color_map.colors[1], lw=2)

        # print info
        print(activity)
        print('Euler Diff at Max: {:.2f}'.format(ht_euler_add_max_mean))
        print('Contrib Diff at Max: {:.2f}'.format(ht_contrib_max_mean))
        print('HT Elevation significance:')
        print(extract_sig(ht_euler_diff_vs_euler_add, x))
        print(output_spm_p(ht_euler_diff_vs_euler_add))

        if idx == 0:
            leg_mean.append(ht_euler_add_ln[0])
            leg_mean.append(ht_contribs_ln[0])

    # figure title and legend
    plt.tight_layout(pad=0.25, h_pad=1.5, w_pad=0.5)
    fig.suptitle('Difference from HT elevation',
                 x=0.5,
                 y=0.99,
                 fontweight='bold')
    plt.subplots_adjust(top=0.91)
    leg_left = fig.legend(
        leg_mean, ['ST UR + GH Elevation', 'ST + GH Contrib to Elevation'],
        gh_x_sig = sig_filter(gh_spm, x)
        axs[cur_row, 0].plot(st_x_sig,
                             np.repeat(2, st_x_sig.size),
                             color='k',
                             lw=2)
        axs[cur_row, 1].plot(gh_x_sig,
                             np.repeat(0, gh_x_sig.size),
                             color='k',
                             lw=2)
        print(activity)
        print('Mean Diff at Max ST: {:.2f}'.format(st_contrib_max_mean -
                                                   st_euler_max_mean))
        print('Mean Diff at Max GH: {:.2f}'.format(gh_contrib_max_mean -
                                                   gh_euler_max_mean))
        print('ST HT Elevation angles')
        print(extract_sig(st_spm, x))
        print(output_spm_p(st_spm))
        print('GH HT Elevation angles')
        print(extract_sig(gh_spm, x))
        print(output_spm_p(gh_spm))

        if idx == 0:
            leg_mean.append(st_euler_ln[0])
            leg_mean.append(st_contrib_ln[0])
            leg_mean.append(gh_euler_ln[0])
            leg_mean.append(gh_contrib_ln[0])

    # figure title and legend
    plt.tight_layout(pad=0.25, h_pad=1.5, w_pad=0.5)
    fig.suptitle(
        'Comparison between Euler Angles and\nST/GH Contribution for Measuring Elevation',
예제 #7
0
                               dict(color=color_map.colors[0], marker=markers[0], markevery=20))
        st_f_ln = mean_sd_plot(axs_elev[cur_row], x_elev, st_f_mean, st_f_sd,
                               dict(color=color_map.colors[1], alpha=0.25),
                               dict(color=color_map.colors[1], marker=markers[1], markevery=20))

        axs_elev[cur_row].errorbar(max_pos, st_m_max_mean, yerr=st_m_max_sd, color=color_map.colors[0],
                                   marker=markers[0], capsize=3)
        axs_elev[cur_row].errorbar(max_pos, st_f_max_mean, yerr=st_f_max_sd, color=color_map.colors[1],
                                   marker=markers[1], capsize=3)

        # spm
        m_vs_f = spm_test(traj_st_m, traj_st_f).inference(alpha, two_tailed=True, **infer_params)
        x_sig = sig_filter(m_vs_f, x_elev)
        axs_elev[cur_row].plot(x_sig, np.repeat(spm_y[activity.lower()], x_sig.size), color='k')
        print(activity)
        print(extract_sig(m_vs_f, x_elev))

        if idx == 0:
            leg_elev_mean.append(st_m_ln[0])
            leg_elev_mean.append(st_f_ln[0])

    for idx_act, (activity, activity_df) in enumerate(db_er_endpts.groupby('Activity', observed=True)):
        m_df = activity_df[activity_df['Gender'] == 'M']
        f_df = activity_df[activity_df['Gender'] == 'F']

        traj_st_m = np.stack(m_df['st_contribs_interp'], axis=0)[:, :, 2]
        traj_st_f = np.stack(f_df['st_contribs_interp'], axis=0)[:, :, 2]

        # means and standard deviations
        st_m_mean = np.rad2deg(np.mean(traj_st_m, axis=0))
        st_f_mean = np.rad2deg(np.mean(traj_st_f, axis=0))
            axs[cur_row], x, new_shr_mean, new_shr_sd,
            dict(color=color_map.colors[1], alpha=0.25),
            dict(color=color_map.colors[1], marker=markers[0], markevery=20))

        # plot spm
        x_sig = sig_filter(spm_res, x)
        axs[cur_row].plot(x_sig, np.repeat(12, x_sig.size), color='k', lw=2)

        # print out
        print(activity)
        print('New SHR at 0: {:.2f}'.format(new_shr_mean[0]))
        print('New SHR at 100: {:.2f}'.format(new_shr_mean[-1]))
        print('Old SHR at 0: {:.2f}'.format(old_shr_mean[0]))
        print('Old SHR at 100: {:.2f}'.format(old_shr_mean[-1]))
        print('Motion % significant')
        print(extract_sig(spm_res, x))
        print(output_spm_p(spm_res))

        if idx == 0:
            leg_mean.append(old_shr_ln[0])
            leg_mean.append(new_shr_ln[0])

    # figure title and legend
    plt.tight_layout(pad=0.25, h_pad=1.5, w_pad=0.5)
    fig.suptitle('SHR Comparison', x=0.47, y=0.99, fontweight='bold')
    plt.subplots_adjust(top=0.93)
    leg_left = fig.legend(leg_mean[:2], ['Euler SHR', 'Coordinated SHR'],
                          loc='upper right',
                          bbox_to_anchor=(1, 0.92),
                          ncol=1,
                          handlelength=1.5,
예제 #9
0
            dict(color=color_map.colors[0]))
        repro_t_ln, repro_alpha = spm_plot_alpha(
            axs[idx_act, 1], x[1:], repro_vs_zero,
            dict(color=color_map.colors[1], alpha=0.25),
            dict(color=color_map.colors[1]))
        tilt_t_ln, tilt_alpha = spm_plot_alpha(
            axs[idx_act, 1], x[1:], tilt_vs_zero,
            dict(color=color_map.colors[7], alpha=0.25),
            dict(color=color_map.colors[7]))
        empty_ln = axs[idx_act, 1].plot(np.nan, color='none')

        # print significance
        print('Activity: {}'.format(activity))
        print('Total')
        print('Max Mean: {:.2f}'.format(np.max(np.abs(total_mean))))
        print(extract_sig(total_vs_zero, x))
        print('LatMed')
        print('Max Mean: {:.2f}'.format(np.max(np.abs(latmed_mean))))
        print(extract_sig(latmed_vs_zero, x))
        print('RePro')
        print('Max Mean: {:.2f}'.format(np.max(np.abs(repro_mean))))
        print(extract_sig(repro_vs_zero, x))
        print('Tilt')
        print('Max Mean: {:.2f}'.format(np.max(np.abs(tilt_mean))))
        print(extract_sig(tilt_vs_zero, x))

        if idx_act == 0:
            # legend lines
            mean_lns.append(repro_ln[0])
            mean_lns.append(total_ln[0])
            mean_lns.append(tilt_ln[0])
        x_sig_repro = sig_filter(latmed_vs_repro, x_elev)
        x_sig_tilt = sig_filter(latmed_vs_tilt, x_elev)
        axs_elev[cur_row].plot(x_sig_repro,
                               np.repeat(spm_y[activity.lower()],
                                         x_sig_repro.size),
                               '-',
                               color='k')
        axs_elev[cur_row].plot(x_sig_tilt,
                               np.repeat(spm_y[activity.lower()] - 3,
                                         x_sig_tilt.size),
                               '-',
                               color='k')

        print('Activity: {}'.format(activity))
        print('Repro Sig')
        print(extract_sig(latmed_vs_repro, x_elev))
        print('Tilt Sig')
        print(extract_sig(latmed_vs_tilt, x_elev))
        print('P-values: ')
        print(output_spm_p(latmed_vs_repro))
        print(output_spm_p(latmed_vs_tilt))
        print('LatMed Max Deg: {:.2f}'.format(st_max_mean_x))
        print('Repro Max Deg: {:.2f}'.format(st_max_mean_y))
        print('Tilt Max Deg: {:.2f}'.format(st_max_mean_z))
        print('Total Max Deg: {:.2f}'.format(st_max_mean))
        print('LatMed Max Percentage: {:.2f}'.format(st_max_mean_x /
                                                     st_max_mean * 100))
        print('Repro Max Percentage: {:.2f}'.format(st_max_mean_y /
                                                    st_max_mean * 100))
        print('Tilt Max Percentage: {:.2f}'.format(st_max_mean_z /
                                                   st_max_mean * 100))
    spm_one_way_rm_induced_z = spm1d.stats.anova1rm(all_traj_induced_z, group_rm, subj_rm).inference(alpha=0.05)

    shaded_spm_rm = dict(color=color_map.colors[6], alpha=0.25, hatch='ooo')
    line_spm_rm = dict(color=color_map.colors[7])
    one_way_rm_ln_induced, alpha_ln_induced = spm_plot_alpha(axs_plane[0, 1], x, spm_one_way_rm_induced,
                                                             shaded_spm_rm, line_spm_rm)
    one_way_rm_ln_induced_x, alpha_ln_induced_x = spm_plot_alpha(axs_plane[1, 1], x, spm_one_way_rm_induced_x,
                                                                 shaded_spm_rm, line_spm_rm)
    one_way_rm_ln_induced_y, alpha_ln_induced_y = spm_plot_alpha(axs_plane[2, 1], x, spm_one_way_rm_induced_y,
                                                                 shaded_spm_rm, line_spm_rm)
    one_way_rm_ln_induced_z, alpha_ln_induced_z = spm_plot_alpha(axs_plane[3, 1], x, spm_one_way_rm_induced_z,
                                                                 shaded_spm_rm, line_spm_rm)

    print('Different between planes')
    print('Total')
    print(extract_sig(spm_one_way_rm_induced, x))
    print('MedLat')
    print(extract_sig(spm_one_way_rm_induced_x, x))
    print('Repro')
    print(extract_sig(spm_one_way_rm_induced_y, x))
    print('Tilt')
    print(extract_sig(spm_one_way_rm_induced_z, x))

    mean_lns = []
    activities = []
    t_lns = []
    alpha_lns = []
    for idx, (activity, activity_df) in enumerate(db_elev.groupby('Activity', observed=True)):
        act_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)
        act_all_traj_induced_x = np.stack(activity_df['traj_interp'].apply(