Example #1
0
    def check_acc_difference(self, x, R_cylinder=[]):
        point_list, x_range, z_range = self.__get_plane_position()
        for point in point_list:
            simulated_marker = point[0]

            segment_data = SegmentData(self.__subject_data,
                                       self.__moved_segment)
            walking_data_1_df = segment_data.get_segment_walking_1_data(
                self.__speed)
            test_index = x.index
            R_standing_to_ground = segment_data.get_segment_R()
            marker_cali_matrix = segment_data.get_marker_cali_matrix(
                self.__speed)
            virtual_marker, R_IMU_transform = Processor.get_virtual_marker(
                simulated_marker, walking_data_1_df, marker_cali_matrix,
                R_standing_to_ground)
            # Processor.check_virtual_marker(virtual_marker, walking_data_1_df, self.__moved_segment)  # for check
            acc_IMU = Processor.get_acc(virtual_marker, R_IMU_transform)

            # if it was simulated on cylinder, a rotation around the cylinder surface is necessary
            if len(R_cylinder) != 0:
                acc_IMU = np.matmul(R_cylinder, acc_IMU.T).T

            changed_columns = []
            for acc_name in ['_acc_x', '_acc_y', '_acc_z']:
                column = self.__moved_segment + acc_name
                changed_columns.append(column)
            plt.plot(acc_IMU[:, 0])
            plt.plot(x[changed_columns].as_matrix()[:, 0])
            score = r2_score(acc_IMU[:, 0], x[changed_columns].as_matrix()[:,
                                                                           0])
            plt.title('pelvis, x += ' + str(point[1]) + ', z += ' +
                      str(point[2]) + ', score = ' + str(score))
            plt.show()
Example #2
0
    def __modify_gyr_test(self,
                          simulated_marker,
                          x_train,
                          x_test,
                          R_cylinder=[]):
        segment_data = SegmentData(self.__subject_data, self.__moved_segment)
        walking_data_1_df = segment_data.get_segment_walking_1_data(
            self.__speed)
        train_index = x_train.index
        test_index = x_test.index
        R_standing_to_ground = segment_data.get_segment_R()
        marker_cali_matrix = segment_data.get_marker_cali_matrix(self.__speed)
        virtual_marker, R_IMU_transform = Processor.get_virtual_marker(
            simulated_marker, walking_data_1_df, marker_cali_matrix,
            R_standing_to_ground)
        # Processor.check_virtual_marker(virtual_marker, walking_data_1_df, self.__moved_segment)  # for check
        gyr_IMU = Processor.get_gyr(walking_data_1_df, R_IMU_transform)

        # if it was simulated on cylinder, a rotation around the cylinder surface is necessary
        if len(R_cylinder) != 0:
            gyr_IMU = np.matmul(R_cylinder, gyr_IMU.T).T

        changed_columns = []
        for gyr_name in ['_gyr_x', '_gyr_y', '_gyr_z']:
            column = self.__moved_segment + gyr_name
            changed_columns.append(column)

        gyr_IMU_df = pd.DataFrame(gyr_IMU)
        # x_test is just a quote of the original x_test, deep copy so that no warning will show up
        x_train_changed = x_train.copy()
        x_test_changed = x_test.copy()
        x_train_changed[changed_columns] = gyr_IMU_df.loc[train_index]
        x_test_changed[changed_columns] = gyr_IMU_df.loc[test_index]
        return x_train_changed, x_test_changed
    def __init__(self, segment, axis_name, iterable_object, diameter=None):
        self.__segment = segment
        self.__i_offset = 0

        if axis_name not in ['x', 'y', 'z', 'theta', 'rotation']:
            raise RuntimeError('Wrong axis name.')
        offsets = []
        if axis_name is 'x':
            for item in iterable_object:
                offset = Offset(self.__segment, x_offset=item /
                                1000)  # change millimeter to meter
                offsets.append(offset)
        elif axis_name is 'y':
            for item in iterable_object:
                offset = Offset(self.__segment, y_offset=item /
                                1000)  # change millimeter to meter
                offsets.append(offset)
        elif axis_name is 'z':
            for item in iterable_object:
                offset = Offset(self.__segment, z_offset=item / 1000)
                offsets.append(offset)
        elif axis_name is 'theta':
            if not diameter:
                raise RuntimeError('Missing the cylinder diameter.')
            for item in iterable_object:
                theta_radians = item * np.pi / 180  # change degree to radians
                if segment in ['l_thigh', 'l_shank']:
                    x = diameter / 2 * (1 - np.cos(theta_radians))
                    R_cylinder = Processor.get_cylinder_surface_rotation(
                        theta_radians)
                else:
                    x = -diameter / 2 * (1 - np.cos(theta_radians))
                    R_cylinder = Processor.get_cylinder_surface_rotation(
                        -theta_radians)
                y = diameter / 2 * np.sin(theta_radians)
                offset = Offset(self.__segment,
                                x_offset=x,
                                y_offset=y,
                                theta_offset=item,
                                R=R_cylinder)
                offsets.append(offset)
        elif axis_name is 'rotation':
            for rotation_angle in iterable_object:
                R = Offset.rotation_angle_to_R(rotation_angle)
                offset = Offset(self.__segment,
                                rotation_angle=rotation_angle,
                                R=R)
                offsets.append(offset)
        self.__offsets = offsets
    def __initialize_offset(segment, axis_name, item, diameter=None):
        if axis_name not in ['x', 'y', 'z', 'theta']:
            raise RuntimeError('Wrong axis name.')

        if axis_name is 'x':
            offset = Offset(segment,
                            x_offset=item / 1000)  # change millimeter to meter
        elif axis_name is 'y':
            offset = Offset(segment,
                            y_offset=item / 1000)  # change millimeter to meter
        elif axis_name is 'z':
            offset = Offset(segment, z_offset=item / 1000)
        else:
            if not diameter:
                raise RuntimeError('Missing the cylinder diameter.')
            theta_radians = item * np.pi / 180  # change degree to radians
            R_cylinder = Processor.get_cylinder_surface_rotation(theta_radians)
            x = diameter / 2 * (1 - np.cos(theta_radians))
            y = diameter / 2 * np.sin(theta_radians)
            offset = Offset(segment=segment,
                            x_offset=x,
                            y_offset=y,
                            theta_offset=item,
                            R=R_cylinder)
        return offset
Example #5
0
    def get_xy(self):
        speed = self.__speed
        walking_data_1_df = self.__subject_data.get_walking_1_data(speed)
        # for now we only use walking data 1
        data_len = walking_data_1_df.shape[0]
        # get x
        if self.__gyr_data:
            x = np.zeros([data_len, 48])
        else:
            x = np.zeros([data_len, 24])
        i_segment = 0
        for segment_name in SEGMENT_NAMES:
            segment_data = SegmentData(self.__subject_data, segment_name)
            segment_data_walking_1_df = segment_data.get_segment_walking_1_data(
                speed)
            center_marker = segment_data.get_center_point_mean(speed)
            R_standing_to_ground = segment_data.get_segment_R()
            marker_cali_matrix = segment_data.get_marker_cali_matrix(speed)
            virtual_marker, R_IMU_transform = Processor.get_virtual_marker(
                center_marker, segment_data_walking_1_df, marker_cali_matrix,
                R_standing_to_ground)
            # Processor.check_virtual_marker(virtual_marker, walking_data_1_df, segment_name)    # for check
            acc_IMU = Processor.get_acc(virtual_marker, R_IMU_transform)
            x[:, 3 * i_segment:3 * (i_segment + 1)] = acc_IMU

            if self.__gyr_data:
                gyr_IMU = Processor.get_gyr(segment_data_walking_1_df,
                                            R_IMU_transform)
                x[:, 24 + 3 * i_segment:24 + 3 * (i_segment + 1)] = gyr_IMU

            i_segment += 1
        x = pd.DataFrame(x)
        if self.__gyr_data:
            x.columns = ALL_ACC_GYR_NAMES
        else:
            x.columns = ALL_ACC_NAMES

        # get y
        y = walking_data_1_df[self.__output_names]

        return x, y
Example #6
0
    def __get_cylinder_position(self):
        segment_data = SegmentData(self.__subject_data, self.__moved_segment)
        center_point_mean = segment_data.get_center_point_mean(self.__speed)
        # range are in millimeter
        theta_range, z_range = XYGenerator.get_move_range(self.__moved_segment)
        cylinder_diameter = self.__subject_data.get_cylinder_diameter(
            self.__moved_segment)
        point_list = []
        for theta in theta_range:
            for z in z_range:
                theta_radians = theta * np.pi / 180  # change degree to radians
                R_cylinder = Processor.get_cylinder_surface_rotation(
                    theta_radians)
                x = cylinder_diameter / 2 * (1 - np.cos(theta_radians))
                y = cylinder_diameter / 2 * np.sin(theta_radians)
                point = center_point_mean + np.array(
                    [x, y, z]) / 1000  # change milliter to meter
                point_list.append([point, theta, z, R_cylinder])

        self.__axis_1_range, self.__axis_2_range = theta_range, z_range
        return point_list, theta_range, z_range