Example #1
0
    def get_stair_ranges(self, side="R"):


        if side == "R":
            m = self.vicon.markers.get_marker("RTOE")
        else:
            m = self.vicon.markers.get_marker("LTOE")

        z = []
        for i in xrange(len(m)):
            z.append(m[i].z)

        N = 10
        z = utilities.smooth(map(int, z), 5)
        z = np.convolve(z, np.ones((N,)) / N, mode='valid')

        max_peakind = np.diff(np.sign(np.diff(z))).flatten()  # the one liner
        max_peakind = np.pad(max_peakind, (1, 1), 'constant', constant_values=(0, 0))
        max_peakind = [index for index, value in enumerate(max_peakind) if value == -2]
        secound_step = max_peakind[-1]
        first_step = max_peakind[-2]

        index = secound_step
        while z[index] != z[index + 1]:
            print index
            index += 1
        final_index = index

        index = first_step
        while z[index] != z[index - 1]:
            index -= 1
        start_index = index
        # plt.plot(z)
        return (start_index, final_index)
Example #2
0
def compare_walking_moments(files, list_of_index):
    """
      Plots the joint angle during walking
      :param files: sting of file name
      :param list_of_index: which traj to use
      """
    fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
    fig.suptitle('Walking Joint Angles', fontsize=20)
    resample = 100000

    # find resample length to use
    for file, i in zip(files, list_of_index):
        trial = ViconGaitingTrial.ViconGaitingTrial(vicon_file=file)
        joints = trial.vicon.get_model_output().get_right_leg().hip.angle
        sample = len(joints)
        resample = min(resample, sample)

    # grab all the trajs and resample
    for file, i in zip(files, list_of_index):
        trial = ViconGaitingTrial.ViconGaitingTrial(vicon_file=file)
        joints = trial.get_joint_trajectories()
        hip = signal.resample(
            trial.vicon.get_model_output().get_right_leg().hip.moment,
            resample)
        knee = signal.resample(
            trial.vicon.get_model_output().get_right_leg().knee.moment,
            resample)
        ankle = signal.resample(
            trial.vicon.get_model_output().get_right_leg().ankle.moment,
            resample)
        ax1.plot(utilities.smooth(hip, 10))
        ax2.plot(utilities.smooth(knee, 10))
        ax3.plot(utilities.smooth(ankle, 10))

    font_size = 25
    ax1.set_ylabel("Nmm/Kg", fontsize=font_size)
    ax2.set_ylabel("Nmm/Kg", fontsize=font_size)
    ax3.set_ylabel("Nmm/Kg", fontsize=font_size)
    ax1.set_title("Hip", fontsize=font_size)
    ax2.set_title("Knee", fontsize=font_size)
    ax3.set_title("Ankle", fontsize=font_size)
    plt.xlabel("Gait %", fontsize=font_size)

    plt.show()
Example #3
0
def compare_stair_moments(files, side, legend):
    resample = 100000
    fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
    fig.suptitle('Stair Joint Moments', fontsize=20)

    resample = 1000000000

    indiecs = {}
    for file, s in zip(files, side):
        trial = ViconGaitingTrial.ViconGaitingTrial(file)
        rn = trial.get_stair_ranges(s)
        indiecs[file] = rn
        resample = min(resample, rn[1] - rn[0])

    for file, s in zip(files, side):
        trial = ViconGaitingTrial.ViconGaitingTrial(vicon_file=file)
        if s == "R":
            joints = trial.vicon.get_model_output().right_leg()
        else:
            joints = trial.vicon.get_model_output().left_leg()
        rn = indiecs[file]
        hip = signal.resample(joints.hip.angle.x[rn[0]:rn[1]], resample)
        knee = signal.resample(joints.knee.angle.x[rn[0]:rn[1]], resample)
        ankle = signal.resample(joints.ankle.angle.x[rn[0]:rn[1]], resample)
        ax1.plot(utilities.smooth(hip,10))
        ax2.plot( utilities.smooth(knee,10))
        ax3.plot(utilities.smooth(ankle,10))

    #plt.legend(legend)
    font_size = 25
    ax1.set_ylabel("Nmm/kg", fontsize=font_size)
    ax2.set_ylabel("Nmm/kg", fontsize=font_size)
    ax3.set_ylabel("Nmm/Kg", fontsize=font_size)
    ax1.set_title("Hip", fontsize=font_size)
    ax2.set_title("Knee", fontsize=font_size)
    ax3.set_title("Ankle", fontsize=font_size)
    plt.xlabel("Gait %", fontsize=font_size)

    plt.show()