def four_corner_offsets(upper_left, upper_right, lower_left, lower_right): """ Reads particle and trap positions of four measurements and returns particle-trap offsets. To ensure good results, the positions should roughly form a rectangle. Parameters ========== upper_left : str name of 1st file to open upper_right : str name of 2nd file to open lower_left : str name of 3rd file to open lower_right : str name of 4th file to open Returns ======= points : ndarray_like n-th row stores x-,y-coordinates of n-th trap and x-,y-offset of n-th particle """ points = np.zeros((4, 4)) _, trap_1, traj_1 = plotting.read_file(upper_left, 1) _, trap_2, traj_2 = plotting.read_file(upper_right, 1) _, trap_3, traj_3 = plotting.read_file(lower_left, 1) _, trap_4, traj_4 = plotting.read_file(lower_right, 1) points = four_corner_offsets_calculate(trap_1, trap_2, trap_3, trap_4, traj_1, traj_2, traj_3, traj_4) return points
def test_simulation_calc(self): precalculated_coeffs = (0.0082505622, 0.0082126888) precalculated_means = (0.10855325, 0.0509324) kx_estimate, ky_estimate = sat.SAT2("unit_test.dat", 1000, 0.005, 2.5e-6, 0.5e-6, 2, 1, 1e-6, 1e-6, 0.5e-6, 9.7e-4, 300, 1) np.testing.assert_approx_equal(kx_estimate, precalculated_coeffs[0], 6) # Test to 6 significant digits np.testing.assert_approx_equal(ky_estimate, precalculated_coeffs[1], 6) time, traps, trajectories = plt.read_file("unit_test.dat", 1) _, means = forcecalc.force_calculation(time, trajectories[:, 0:2], traps[:, 0:2], (2.5e-6, 0.5e-6), 300) self.assertTrue( np.allclose(means, precalculated_means, rtol=1e-05, atol=1e-08))
for i in range(num_points): images = pims.ImageSequence(output_folder + "/*.png") features = trackpy.batch(images, 7, minmass=50, invert=False) tracks = trackpy.link_df(features, 15, memory=10) all_traps = [trap_data,[0,0,-1],[0,0,-1],[0,0,-1]] traps = [[all_traps[i][:] for j in range(num_points)]for i in range(4)] tracking.save_tracked_data_pandas(output_folder + "/tracked_data.dat",images, tracks, times, laser_powers, traps) #4: Read .dat file back into the program times,traps,trajectory = plotting.read_file(output_folder + "/tracked_data.dat",1) #5: Calibration, removing offset etc. trap_offsets = offset.single_particle_offset(traps[:,0:2],trajectory[:,::-1]) #should be close to 0 since trap isn't shifted coeffs_estimate,rotation_angle,_ = calibration.calibrate(times,trajectory,0.005) #6: Force analysis print("Trap offsets:", trap_offsets) print("Estimate of trap coefficients:", coeffs_estimate) print("Trap rotation angle", rotation_angle) forces,mean_forces = force_calc.calculate(times,trajectory[:,1::-1],traps[:,0:2],coeffs_estimate,rotation_angle) #7: Create graphs
import os import numpy as np import tweezer.plotting as plt import tweezer.force_calc as forcecalc import tweezer.calibration as cal # Example of unpacking the data, and plotting all plot functios # Get data from drive (under Vzorci/1 static particle) and save it in examples folder #script_dir = os.path.dirname(__file__) # absolute dir the script is in file_name = 'test.dat' # name of the dat file #path = os.path.join(script_dir, file_name) path = file_name particles = 1 time, traps, trajectories = plt.read_file(path, particles) averaging_time = 0.1 for i in range(particles): data = trajectories[:, i * 2:(i + 1) * 2] trap = traps[:, i * 3:(i + 1) * 3] # Example of using trajectory plot plt.trajectory_plot(time, data, averaging_time) # Example of using calibration plots plt.calibration_plots(time, data, averaging_time) # Example of using potential plot plt.potential_plot(time, data, averaging_time) # Calculate forces k_estimated, phi_estimated, center_estimated = cal.calibrate( time, data, averaging_time) f, m = forcecalc.force_calculation(time, data, trap, k_estimated, 300)
time, trap, trajectory = datagen.generate(num_of_points, dt, k_values_1, (0.25, 0.25), (1e-5, 1e-5), 1.6e-6, viscosity, phi_1, center_1, 293, 1, False) # Calculating forces on a single particle f, m = forcecalc.calculate(time, trajectory[:, 0:2], trap[:, 0:2], k_values_1, phi_1) displacements, means, variances = forcecalc.displacement_calculation( trajectory, trap) plt.displacement_plot(time, displacements, means, variances, True) # Plotting the forces plt.force_plot(time, f, m, True) plt.force_plot_radial(time, f, m, True) # Example of calculating force of interaction between a pair of beads and their displacement # here we include a test file from one of the experiments times, traps, trajectories = plt.read_file("data/example_two_particles.dat", 2) traps_slice = np.hstack((traps[:, 0:2], traps[:, 3:5])) forces, means, distances, mean_distance = forcecalc.calculate_axial( times, trajectories[:, 0:4], traps_slice, k_values_1, k_values_2, phi_1, phi_2) plt.force_plot(times, forces, means) plt.force_distance_plot(forces, means, distances, mean_distance, True)
import tweezer.force_calc as forcecalc import tweezer.synth_active_trajectory as sat import tweezer.plotting as plt # Parameters for drawing positions k_values = (2.5e-6, 0.5e-6) # The program first generates simulated motion of a bead moving in an optical trap # and saves it into a file. sat.SAT2("test.dat", 1000, 0.005, k_values[0], k_values[1], 2, 1, 1e-6, 1e-6, 0.5e-6, 9.7e-4, 300, 1) # The file is read back. time, traps, trajectories = plt.read_file("test.dat", 1) # Calculate forces f, m = forcecalc.force_calculation(time, trajectories[:, 0:2], traps[:, 0:2], k_values, 300) # Plot force plt.force_plot(time, f)