brain_diffusion.msd

brain_diffusion.msd

brain_diffusion.msd.MSD_iteration(folder, name, cut=1, totvids=1, conversion=(1, 1, 1))[source]

Arranges trajectory xy data into numpy arrays of dimensions frames x particles

folder : string
Directory containing datasets to be analyzed.
name : string

Base name of files to be analzed. The code has a very specific naming convenction, and requires files to be of the structure:

Traj_{}_{}.csv.format(name, video_number)

where name is the base name of the files and video number is the number associated with the video. Numbers must begin at 1 and increase in units of 1.

cut : integer
Minimum number of frames for a trajectory to be included in the final dataset. Trajectories in the csv file with less datasets will be cut out.
totvids : integer
Total number of csv files to be compiled in the dataset.
conversion: list of floats or integers
Contains the frames per second associated with the video, the xy pixel resolution, and the z-stack depth respectively. Currently the code discards z information.
total1 : integer
Total number of particles contained in all csv files being analyzed.
frames : integer
Total number of frames in the video.
x_m : numpy array of dimensions frames x particles
Contains x coordinates of all trajectories in all csv files being analyzed. If a particle isn’t present in a frame, then it is filled in with a 0.
y_m : numpy array of dimensions frames x particles
Similar to x_m with y coordinates.
xs_m : numpy array of dimensions frames x particles
Contains x coordinates of all trajectories in all csv files being analyzed. Trajectories have been shifted such that all trajectories begin at frame 0.
ys_m : numpy array of dimensions frames x particles
Similar to xs_m with y coordinates.
>>> n = 6
>>> p = 2
>>> df = np.zeros((p*n, 12))
>>> for i in range(1, p+1):
        df[(i-1)*n:i*n, 0] = np.ones(n) + i - 1
        df[(i-1)*n:i*n, 1] = np.ones(n) + i - 1
        df[(i-1)*n:i*n, 2] = np.linspace(0, 10, n) + 2 + i
        df[(i-1)*n:i*n, 3] = np.linspace(0, 10, n) + i
        df[(i-1)*n:i*n, 4] = np.linspace(0, 10, n) + 3 + i
        df[(i-1)*n:i*n, 5] = np.zeros(n)
        df[(i-1)*n:i*n, 6:12] = np.zeros((n, 6))
>>> np.savetxt("../Traj_test_data_1.tif.csv", df, delimiter=",")
>>> folder = '../'
>>> name = 'test_data'
>>> MSD_iteration(folder, name)
brain_diffusion.msd.fillin2(data)[source]

Fills in blanks in an input trajectory dataset.

data : numpy array
Must have 5 columns containing in order Track ID, frames, x coordinates, y coordinates, and z coordinates. Must contain a single Track ID, no more. Frames must be in ascending order.
filledin : numpy array
Numpy array of size frames x 5 containing Track ID, frames, x coordinates, y coordinates, and z coordinates. Frames are filled in using a carryover method (no regression performed).
>>> n = 6
>>> df = np.zeros((6, 5))
>>> df[:, 0] = np.ones(6)
>>> df[:, 1] = np.linspace(0, 100, 6)
>>> df[:, 2] = np.linspace(0, 100, 6)
>>> df[:, 3] = np.linspace(0, 100, 6)
>>> df[:, 4] = np.zeros(6)
>>> fillin2(df)
array([[  1.,   0.,   0.,   0.,   0.],
       [  1.,   1.,   0.,   0.,   0.],
       [  1.,   2.,   2.,   2.,   0.],
       [  1.,   3.,   2.,   2.,   0.],
       [  1.,   4.,   4.,   4.,   0.],
       [  1.,   5.,   4.,   4.,   0.],
       [  1.,   6.,   6.,   6.,   0.],
       [  1.,   7.,   6.,   6.,   0.],
       [  1.,   8.,   8.,   8.,   0.],
       [  1.,   9.,   8.,   8.,   0.],
       [  1.,  10.,  10.,  10.,   0.]])
brain_diffusion.msd.vectorized_MMSD_calcs(frames, total1, xs_m, ys_m)[source]

Calculates the geometrically averaged mean squared displacement of the input trajectories.

frames : integer
Total number of frames in the video. Output from MSD_iteration
total1 : integer
Total number of particles contained in all csv files being analyzed. Output from MSD_iteration.
xs_m : numpy array of dimensions frames x particles
Contains x coordinates of all trajectories in all csv files being analyzed. Trajectories have been shifted such that all trajectories begin at frame 0. Output from MSD_iteration.
ys_m : numpy array of dimensions frames x particles
Similar to xs_m with y coordinates. Output from MSD_iteration.
geoM2xy : frames x 1 numpy.ndarray of float64s
Average of the log 2D MSDs of input xy data.
gSEM : frames x 1 numpy.ndarray of float64s
Standard error of the log 2D MSDs of input xy data.
SM1x : frames x total1 numpy.ndarray of float64s
x component of the 2D MSD of input xy data for each trajectory.
SM1y : frames x total1 numpy.ndarray of float64s
y component of the 2D MSD of input xy data for each trajectory.
SM2xy : frames x total1 numpy.ndarray of float64s
2D MSDs of input xy data for each trajectory.
>>> n = 6
>>> p = 2
>>> df = np.zeros((p*n, 12))
>>> for i in range(1, p+1):
        df[(i-1)*n:i*n, 0] = np.ones(n) + i - 1
        df[(i-1)*n:i*n, 1] = np.ones(n) + i - 1
        df[(i-1)*n:i*n, 2] = np.linspace(0, 10, n) + 2 + i
        df[(i-1)*n:i*n, 3] = np.linspace(0, 10, n) + i
        df[(i-1)*n:i*n, 4] = np.linspace(0, 10, n) + 3 + i
        df[(i-1)*n:i*n, 5] = np.zeros(n)
        df[(i-1)*n:i*n, 6:12] = np.zeros((n, 6))
>>> np.savetxt("../Traj_test_data_1.tif.csv", df, delimiter=",")
>>> folder = '../'
>>> name = 'test_data'
>>> cut = 1
>>> totvids = 1
>>> conversion = (1, 1, 1)
>>> total1, frames, xs_m, ys_m, x_m, y_m = MSD_iteration(folder, name)
>>> vectorized_MMSD_calcs(frames, total1, xs_m, ys_m)
(array([ 0.        ,  1.38629436,  2.07944154,  2.99573227,  3.4657359 ,
         3.95124372,  4.27666612,  4.60517019,  4.85203026,  5.09986643,
         5.29831737,  0.        ,  0.        ,  0.        ]),
 array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]),
 array([[   0.,    0.],
        [   2.,    2.],
        [   4.,    4.],
        [  10.,   10.],
        [  16.,   16.],
        [  26.,   26.],
        [  36.,   36.],
        [  50.,   50.],
        [  64.,   64.],
        [  82.,   82.],
        [ 100.,  100.],
        [   0.,    0.],
        [   0.,    0.],
        [   0.,    0.]]),
 array([[   0.,    0.],
        [   2.,    2.],
        [   4.,    4.],
        [  10.,   10.],
        [  16.,   16.],
        [  26.,   26.],
        [  36.,   36.],
        [  50.,   50.],
        [  64.,   64.],
        [  82.,   82.],
        [ 100.,  100.],
        [   0.,    0.],
        [   0.,    0.],
        [   0.,    0.]]),
 array([[   0.,    0.],
        [   4.,    4.],
        [   8.,    8.],
        [  20.,   20.],
        [  32.,   32.],
        [  52.,   52.],
        [  72.,   72.],
        [ 100.,  100.],
        [ 128.,  128.],
        [ 164.,  164.],
        [ 200.,  200.],
        [   0.,    0.],
        [   0.,    0.],
        [   0.,    0.]]))