Trajectory¶
-
class
particle_tracker_one_d.
Trajectory
(pixel_width=1)[source]¶ Object that describes a trajectory. With functions for checking if the trajectory describes real diffusion, convenient plotting and calculations of diffusion coefficients.
Parameters: - pixel_width: float
Defines the length one pixel corresponds to. This value will be used when calculating diffusion coefficients. Default is 1.
Attributes: - pixel_width
- particle_positions: np.array
Numpy array with all particle positions in the trajectory on the form np.array((nParticles,), dtype=[(‘frame_index’, np.int16), (‘time’, np.float32),(‘position’, np.int16),(‘zeroth_order_moment’, np.float32),(‘second_order_moment’, np.float32)])
Methods
calculate_diffusion_coefficient_from_mean_square_displacement_function
([…])Fits a straight line to the mean square displacement function and calculates the diffusion coefficient from the gradient of the line. calculate_diffusion_coefficient_using_covariance_based_estimator
([R])Unbiased estimator of the diffusion coefficient. calculate_mean_square_displacement_function
()Calculate the average squared displacements for different time steps. overlaps_with
(trajectory)Check if the trajectories overlaps plot_trajectory
([x, y, ax])Plots the trajectory using the frame index and the particle position in pixels. plot_velocity_auto_correlation
([ax])Plots the particle velocity auto correlation function which can be used for examining if the trajectory describes free diffusion. split
(trajectory)If two trajectories overlaps, this function will split them into three or more non overlapping trajectories. -
calculate_diffusion_coefficient_from_mean_square_displacement_function
(fit_range=None)[source]¶ Fits a straight line to the mean square displacement function and calculates the diffusion coefficient from the gradient of the line. The mean squared displacement of the particle position is proportional to \(2Dt\) where \(D\) is the diffusion coefficient and \(t\) is the time.
- fit_range: list, None (default)
- Define the range of the fit, the data for the fit will be time[fit_range[0]:fit_range[1]` and mean_squared_displacement[fit_range[0]:fit_range[1]].
Returns: - diffusion_coefficient: float
error: float
-
calculate_diffusion_coefficient_using_covariance_based_estimator
(R=None)[source]¶ Unbiased estimator of the diffusion coefficient. More info at https://www.nature.com/articles/nmeth.2904. If the motion blur coefficient is entered a variance estimate is also calculated.
R: float, motion blur coefficient
Returns: - diffusion_coefficient: float
variance_estimate: float
-
calculate_mean_square_displacement_function
()[source]¶ Calculate the average squared displacements for different time steps.
Returns: - time: np.array
The time corresponding to the mean squared displacements.
- msd: np.array
The mean squared displacements of the trajectory.
-
density
¶ - float:
- How dense the trajectory is in time. Returns self.length/(self.particle_positions[‘frame_index’][-1]-self.particle_positions[‘frame_index’][0]).
-
length
¶ - int:
- The length of the trajectory. Returns self.particle_postions.shape[0]
-
overlaps_with
(trajectory)[source]¶ Check if the trajectories overlaps
trajectory: Trajectory to compare with. If both trajectories has any identical elements will return true otherwise false.
Returns: - bool
-
plot_trajectory
(x='frame_index', y='position', ax=None, **kwargs)[source]¶ Plots the trajectory using the frame index and the particle position in pixels.
- x: str
- ‘frame_index’, ‘time’, ‘position’ (default), ‘zeroth_order_moment’, ‘second_order_moment’ choose the x-axis value
- y: str
- ‘frame_index’ (default), ‘time’, ‘position’, ‘zeroth_order_moment’, ‘second_order_moment’ choose the y-axis value
- ax: matplotlib axes instance
- The axes which you want the frames to plotted on. If none is provided a new instance will be created.
- **kwargs:
- Plot settings, any settings which can be used in matplotlib.pyplot.plot method.
Returns: - matplotlib axes instance
Returns the axes input argument or creates and returns a new instance of a matplotlib axes object.
-
plot_velocity_auto_correlation
(ax=None, **kwargs)[source]¶ Plots the particle velocity auto correlation function which can be used for examining if the trajectory describes free diffusion.
- ax: matplotlib axes instance
- The axes which you want the frames to plotted on. If none is provided a new instance will be created.
- **kwargs:
- Plot settings, any settings which can be used in matplotlib.pyplot.plot method.
Returns: - matplotlib axes instance
Returns the axes input argument or creates and returns a new instance of a matplotlib axes object.
-
split
(trajectory)[source]¶ If two trajectories overlaps, this function will split them into three or more non overlapping trajectories.
trajectory:
Returns: - list
Returns a list with the new trajectories
-
velocities
¶ - np.array:
- The velocities the particle moves at.