Exemplo n.º 1
0
    def test_example_distances_calculated_correctly(self):
        wall_bounds = ((-2, 4), (-1, 3), (-3, 4))

        positions = np.array([[-1., 1, 1], [-2., 1, 1], [-2., 0.5, 1],
                              [-3., 0.25, 1], [-3, -0.5, 1]])

        d_correct = np.array([1, 0, 0, -1, -1])
        d = kinematics.distance_from_wall(positions, wall_bounds)
        np.testing.assert_array_almost_equal(d, d_correct)

        positions = np.array([[0., 0, 0], [1, 0, 5], [1, 0, 0], [0, -2, 0],
                              [0, -2, -3]])

        d_correct = np.array([1., -1, 1, -1, -1])
        d = kinematics.distance_from_wall(positions, wall_bounds)
        np.testing.assert_array_almost_equal(d, d_correct)
Exemplo n.º 2
0
def main():
    # loop over all experiments
    for expt in session.query(models.Experiment):

        print("In experiment '{}'".format(expt.id))

        dt = 1 / expt.sampling_frequency

        for traj in session.query(
                models.Trajectory).filter_by(experiment=expt):

            positions = traj.positions(session)
            velocities = traj.velocities(session)

            # calculate kinematic quantities
            velocities_a = kinematics.norm(velocities)

            accelerations = kinematics.acceleration(velocities, dt)
            accelerations_a = kinematics.norm(accelerations)

            headings = kinematics.heading(velocities)

            angular_velocities = kinematics.angular_velocity(velocities, dt)
            angular_velocities_a = kinematics.norm(angular_velocities)

            angular_accelerations = kinematics.acceleration(
                angular_velocities, dt)
            angular_accelerations_a = kinematics.norm(angular_accelerations)

            distance_from_wall = kinematics.distance_from_wall(
                positions, WALL_BOUNDS)

            # store kinematic quantities in timepoints
            for ctr, tp in enumerate(traj.timepoints(session)):

                tp.velocity_a = velocities_a[ctr]
                tp.acceleration_x, tp.acceleration_y, tp.acceleration_z = accelerations[
                    ctr]
                tp.acceleration_a = accelerations_a[ctr]

                tp.heading_xy, tp.heading_xz, tp.heading_xyz = headings[ctr]

                tp.angular_velocity_x, tp.angular_velocity_y, tp.angular_velocity_z = angular_velocities[
                    ctr]
                tp.angular_velocity_a = angular_velocities_a[ctr]

                tp.angular_acceleration_x, tp.angular_acceleration_y, tp.angular_acceleration_z = angular_accelerations[
                    ctr]
                tp.angular_acceleration_a = angular_accelerations_a[ctr]

                tp.distance_from_wall = distance_from_wall[ctr]

                session.add(tp)

            commit(session)
Exemplo n.º 3
0
    def test_example_distances_calculated_correctly(self):
        wall_bounds = ((-2, 4), (-1, 3), (-3, 4))

        positions = np.array([[-1., 1, 1],
                              [-2., 1, 1],
                              [-2., 0.5, 1],
                              [-3., 0.25, 1],
                              [-3, -0.5, 1]])

        d_correct = np.array([1, 0, 0, -1, -1])
        d = kinematics.distance_from_wall(positions, wall_bounds)
        np.testing.assert_array_almost_equal(d, d_correct)

        positions = np.array([[0., 0, 0],
                              [1, 0, 5],
                              [1, 0, 0],
                              [0, -2, 0],
                              [0, -2, -3]])

        d_correct = np.array([1., -1, 1, -1, -1])
        d = kinematics.distance_from_wall(positions, wall_bounds)
        np.testing.assert_array_almost_equal(d, d_correct)
def main():
    # loop over all experiments
    for expt in session.query(models.Experiment):

        print("In experiment '{}'".format(expt.id))

        dt = 1 / expt.sampling_frequency

        for traj in session.query(models.Trajectory).filter_by(experiment=expt):

            positions = traj.positions(session)
            velocities = traj.velocities(session)

            # calculate kinematic quantities
            velocities_a = kinematics.norm(velocities)

            accelerations = kinematics.acceleration(velocities, dt)
            accelerations_a = kinematics.norm(accelerations)

            headings = kinematics.heading(velocities)

            angular_velocities = kinematics.angular_velocity(velocities, dt)
            angular_velocities_a = kinematics.norm(angular_velocities)

            angular_accelerations = kinematics.acceleration(angular_velocities, dt)
            angular_accelerations_a = kinematics.norm(angular_accelerations)

            distance_from_wall = kinematics.distance_from_wall(positions, WALL_BOUNDS)

            # store kinematic quantities in timepoints
            for ctr, tp in enumerate(traj.timepoints(session)):

                tp.velocity_a = velocities_a[ctr]
                tp.acceleration_x, tp.acceleration_y, tp.acceleration_z = accelerations[ctr]
                tp.acceleration_a = accelerations_a[ctr]

                tp.heading_xy, tp.heading_xz, tp.heading_xyz = headings[ctr]

                tp.angular_velocity_x, tp.angular_velocity_y, tp.angular_velocity_z = angular_velocities[ctr]
                tp.angular_velocity_a = angular_velocities_a[ctr]

                tp.angular_acceleration_x, tp.angular_acceleration_y, tp.angular_acceleration_z = angular_accelerations[ctr]
                tp.angular_acceleration_a = angular_accelerations_a[ctr]

                tp.distance_from_wall = distance_from_wall[ctr]

                session.add(tp)

            commit(session)