Exemple #1
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)
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)
    def test_example_velocities_are_correctly_differentiated(self):

        v = np.array([[1., 1, 1], [2, 2, 2], [3, 3, 3], [5, 5, 5], [7, 7, 7], [10, 10, 10]])
        dt = 0.1
        a_correct = np.array([[1., 1, 1], [1, 1, 1], [1.5, 1.5, 1.5], [2, 2, 2], [2.5, 2.5, 2.5], [3, 3, 3]]) / dt

        np.testing.assert_array_almost_equal(kinematics.acceleration(v, dt), a_correct)
Exemple #4
0
    def test_example_velocities_are_correctly_differentiated(self):

        v = np.array([[1., 1, 1], [2, 2, 2], [3, 3, 3], [5, 5, 5], [7, 7, 7],
                      [10, 10, 10]])
        dt = 0.1
        a_correct = np.array([[1., 1, 1], [1, 1, 1], [1.5, 1.5, 1.5],
                              [2, 2, 2], [2.5, 2.5, 2.5], [3, 3, 3]]) / dt

        np.testing.assert_array_almost_equal(kinematics.acceleration(v, dt),
                                             a_correct)
# In[ ]:

def acceleration(xForce, yForce, zForce, mass):
    xAccel = float(xForce) / float(mass)
    yAccel = float(yForce) / float(mass)
    zAccel = float(zForce) / float(mass)
    
    return (xAccel, yAccel, zAccel)


# #### Q. What will this do?

# In[ ]:

acceleration(10, 20, 30, 5)

I put eKinetic and acceleration in a module called kinematics.py using a text editor.

Now, try the module in an IPython session:
# In[ ]:

# remember that this line overwrites the local definition
# because it has the same name as above!

from kinematics import eKinetic, acceleration

mass = 100
velocity = 10
xForce = 10
yForce = 20