genepy3d.objext package#
Module contents#
Submodules#
genepy3d.objext.simpletracks module#
Methods for working with tracks.
Functions:
|
Merge tracks. |
Classes:
|
A simple track object. |
- genepy3d.objext.simpletracks.merge(tracklst)[source]#
Merge tracks. They must be placed in the increasing order of times.
- Parameters:
tracklst (array of SimpleTrack) – a list of SimpleTrack objects.
- Returns:
A merged SimpleTrack object.
- class genepy3d.objext.simpletracks.SimpleTrack(coors, t)[source]#
Bases:
CurveA simple track object.
It’s simple because it has no division or merge. We can consider it as a Curve object with time attribute.
Work in 3D but also support 2D tracks. Please check the documentation of each function to see if it supports 2D.
- coors#
array of points. See
Curvefor more detail.- Type:
array | tuple
- time#
array of time.
- Type:
numeric
Examples
import numpy as np from genepy3d.objext.simpletracks import SimpleTrack # Create SimpleTrack from array of points and time coors = np.array([[1,2,3],[1,2,3],[1,2,3]]) t = np.array([1,2,3]) track = SimpleTrack(coors,t)
Methods:
Compute the difference between two consecutive times.
split(max_gap)Split track if the gap between two consecutive times is larger than max_gap.
convolve_gaussian(sigma[, mo, kerlen])Overlay convolve_gaussian() of Curve object.
denoise([sigma_step, max_iter, return_sigma])Override the denoise() from Curve.
resample(dt[, spline_order, ...])The track is resampled by the new time step.
is_moving(num_neighbor, displ_tol)Check if the object is moving at each point.
Velocity at every point of the track.
Acceleration at every point of the track.
Mean square displacement.
filter_by_time_interval(duration[, t_begin])Filter the track starting from a t_begin and with a given duration.
filter_by_distance(d[, t_begin])Filter from a time t_begin, a subtrack that is inside a distance d.
filter_by_length(l[, t_begin, tolerance])Filter the track starting from a t_begin having a given length l.
- compute_time_gap()[source]#
Compute the difference between two consecutive times.
Work in 3D and 2D.
- Returns:
Array of time gap whose i element is the time gap between (ti, ti-1).
Notes
The first element has no time gap and is set as np.nan.
- split(max_gap)[source]#
Split track if the gap between two consecutive times is larger than max_gap.
Work in 3D and 2D.
- Parameters:
max_gap (float) – maximual gap allowed between two consecutive times.
- Returns:
List of subtracks.
Examples
import numpy as np from genepy3d.objext.simpletracks import SimpleTrack # Create SimpleTrack from array of points and time coors = np.array([[0,0,0],[1,1,1],[2,2,2],[1,1,1],[0,0,0]]) t = np.array([0,1,2,10,11]) track = SimpleTrack(coors,t) subtracks = track.split(max_gap=5) # the track is splitted in two tracks.
- convolve_gaussian(sigma, mo='nearest', kerlen=4)[source]#
Overlay convolve_gaussian() of Curve object.
See more details of this function in
Curveclass.Work in 3D and 2D.
- Returns:
SimpleTrack object.
- denoise(sigma_step=0.25, max_iter=None, return_sigma=False)[source]#
Override the denoise() from Curve.
Details see
Curve.denoise().
- resample(dt, spline_order=1, return_old_indices=False, return_interp_param=False)[source]#
The track is resampled by the new time step.
Work in 3D and 2D.
- Parameters:
dt (float|int) – resampled time step.
spline_order (int) – degree of spline interpolation.
return_old_indices (bool) – if True, return the indices of new sampled time array correspond to the old time array.
return_interp_param (bool) – if True, return spline parameters.
- Returns:
Resampled SimpleTrack object.
Examples
import numpy as np from genepy3d.objext.simpletracks import SimpleTrack # Create SimpleTrack from array of points and time coors = np.array([[0,0,0],[1,1,1],[2,2,2],[1,1,1],[0,0,0]]) t = np.array([0,1,2,10,11]) track = SimpleTrack(coors,t) track_new = track.resample(dt=1) # resample with time step = 1
- is_moving(num_neighbor, displ_tol)[source]#
Check if the object is moving at each point.
Work in 3D and 2D.
- Parameters:
num_neighbor (int) – number of neighbor frames. The frames are used to check the movement at a frame n are [n-k,n-k-1,…,n,…,n+k-1,n+k], where k is the number of neighbors frames.
displ_tol (float) – if the displacement between neighbor points is larger than this value, then it’s considered as no moving.
- Returns:
Array of boolean with 0 = no moving, 1 = moving.
- compute_velocity()[source]#
Velocity at every point of the track.
Work in 3D and 2D.
- Returns:
Array of velocities.
Notes
The first point has no velocity and is set as np.nan
- compute_acceleration()[source]#
Acceleration at every point of the track.
Work in 3D and 2D.
- Returns:
Array of acceleration.
Notes
The first two points have no acceleration and are set as np.nan
- compute_msd()[source]#
Mean square displacement.
Adapt from this post: https://colab.research.google.com/github/kaityo256/zenn-content/blob/main/articles/msd_fft_python/msd_fft_python.ipynb#scrollTo=z7KpcUd8ddZ2
Work in 3D and 2D.
- Returns:
Array of MSD.
- filter_by_time_interval(duration, t_begin=None)[source]#
Filter the track starting from a t_begin and with a given duration.
If t_begin is None, then the first time point is taken. Otherwise, the time point corresponding to the lower bound of the t_begin is chosen.
When computing the time point corresponding to the duration, it’s the time point corresponds to the upper bound of (t_begin + duration).
Work in 3D and 2D.
- Parameters:
duration (numeric, list) – duration starting from t_begin.
t_begin (numeric) – time begin, if None, then take the first time point.
- Returns:
A subtrack.
Notes
Duration can be a single value or a list of durations. If the latter one is provided, then return the track with the maximal duration from the list.
- filter_by_distance(d, t_begin=None)[source]#
Filter from a time t_begin, a subtrack that is inside a distance d.
If t_begin is None, then the first time point is taken. Otherwise, the time point corresponding to the lower bound of the t_begin is chosen.
Assuming the track intersects the ball B with center given by the position p at the time t_begin and with radius d. The function returns a subtrack starting from p and end at the first position intersecting the ball.
Work in 3D and 2D.
- Parameters:
d (numeric) – a distance.
t_begin (numeric) – time begin, if None, then take the first time point.
- Returns:
A subtrack.
Notes
The function only returns the portion starting from the time t_begin. All the time points within the ball but before t_begin are not counted. It must have a least 1 position intersecting the ball. Otherwise it returns None.
- filter_by_length(l, t_begin=None, tolerance=0.5)[source]#
Filter the track starting from a t_begin having a given length l.
If t_begin is None, then the first time point is taken. Otherwise, the time point corresponding to the lower bound of the t_begin is chosen.
Work in 3D and 2D.
- Parameters:
l (numeric) – a length.
t_begin (numeric) – time begin, if None, then take the first time point.
tolerance (numeric) – allow to accept the result if it is within [l-tolerance,l+tolerance]. This make faster search given provided error.
- Returns:
A subtrack.