1
|
|
|
import os |
2
|
|
|
import numpy as np |
3
|
|
|
import numpy.testing as npt |
4
|
|
|
from scipy.spatial import Voronoi |
5
|
|
|
import matplotlib as mpl |
6
|
|
|
mpl.use('Agg') |
7
|
|
|
import diff_classifier.msd as msd |
8
|
|
|
import diff_classifier.features as ft |
9
|
|
|
import diff_classifier.heatmaps as hm |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
def test_voronoi_finite_polygons_2d(): |
13
|
|
|
prefix = 'test' |
14
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
15
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
16
|
|
|
|
17
|
|
|
dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3) |
18
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
19
|
|
|
msds.to_csv(msd_file) |
20
|
|
|
feat = ft.calculate_features(msds) |
21
|
|
|
feat.to_csv(ft_file) |
22
|
|
|
|
23
|
|
|
xs = feat['X'].astype(int) |
24
|
|
|
ys = feat['Y'].astype(int) |
25
|
|
|
points = np.zeros((xs.shape[0], 2)) |
26
|
|
|
points[:, 0] = xs |
27
|
|
|
points[:, 1] = ys |
28
|
|
|
|
29
|
|
|
vor = Voronoi(points) |
30
|
|
|
regions, vertices = hm.voronoi_finite_polygons_2d(vor) |
31
|
|
|
|
32
|
|
|
npt.assert_equal(243.8, np.round(np.mean(vertices), 1)) |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def test_plot_heatmap(): |
36
|
|
|
prefix = 'test' |
37
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
38
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
39
|
|
|
|
40
|
|
|
dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3) |
41
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
42
|
|
|
msds.to_csv(msd_file) |
43
|
|
|
feat = ft.calculate_features(msds) |
44
|
|
|
feat.to_csv(ft_file) |
45
|
|
|
|
46
|
|
|
hm.plot_heatmap(prefix, resolution=520, rows=1, cols=1, figsize=(6,5), upload=False) |
47
|
|
|
assert os.path.isfile('hm_asymmetry1_{}.png'.format(prefix)) |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
def test_plot_scatterplot(): |
51
|
|
|
prefix = 'test' |
52
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
53
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
54
|
|
|
|
55
|
|
|
dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3) |
56
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
57
|
|
|
msds.to_csv(msd_file) |
58
|
|
|
feat = ft.calculate_features(msds) |
59
|
|
|
feat.to_csv(ft_file) |
60
|
|
|
|
61
|
|
|
hm.plot_scatterplot(prefix, resolution=400, rows=1, cols=1, dotsize=120, upload=False) |
62
|
|
|
assert os.path.isfile('scatter_asymmetry1_{}.png'.format(prefix)) |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
def test_plot_trajectories(): |
66
|
|
|
prefix = 'test' |
67
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
68
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
69
|
|
|
|
70
|
|
|
dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3) |
71
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
72
|
|
|
msds.to_csv(msd_file) |
73
|
|
|
feat = ft.calculate_features(msds) |
74
|
|
|
feat.to_csv(ft_file) |
75
|
|
|
|
76
|
|
|
hm.plot_trajectories(prefix, resolution=520, rows=1, cols=1, upload=False) |
77
|
|
|
assert os.path.isfile('traj_{}.png'.format(prefix)) |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
def test_plot_histogram(): |
81
|
|
|
prefix = 'test' |
82
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
83
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
84
|
|
|
|
85
|
|
|
dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3) |
86
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
87
|
|
|
msds.to_csv(msd_file) |
88
|
|
|
feat = ft.calculate_features(msds) |
89
|
|
|
feat.to_csv(ft_file) |
90
|
|
|
|
91
|
|
|
hm.plot_histogram(prefix, fps=1, umppx=1, frames=100, frame_interval=5, frame_range=5, y_range=10, upload=False) |
92
|
|
|
assert os.path.isfile('hist_{}.png'.format(prefix)) |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
def test_plot_individual_msds(): |
96
|
|
|
prefix = 'test' |
97
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
98
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
99
|
|
|
|
100
|
|
|
dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3) |
101
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
102
|
|
|
msds.to_csv(msd_file) |
103
|
|
|
feat = ft.calculate_features(msds) |
104
|
|
|
feat.to_csv(ft_file) |
105
|
|
|
|
106
|
|
|
geomean, gSEM = hm.plot_individual_msds(prefix, umppx=1, fps=1, y_range=400, alpha=0.3, upload=False) |
107
|
|
|
npt.assert_almost_equal(339.9, np.round(np.sum(geomean), 1)) |
108
|
|
|
npt.assert_almost_equal(35.3, np.round(np.sum(gSEM), 1)) |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
def test_plot_particles_in_frame(): |
112
|
|
|
prefix = 'test' |
113
|
|
|
msd_file = 'msd_{}.csv'.format(prefix) |
114
|
|
|
ft_file = 'features_{}.csv'.format(prefix) |
115
|
|
|
|
116
|
|
|
dataf = msd.random_traj_dataset(nparts=10, ndist=(1, 1), seed=3) |
117
|
|
|
msds = msd.all_msds2(dataf, frames=100) |
118
|
|
|
msds.to_csv(msd_file) |
119
|
|
|
feat = ft.calculate_features(msds) |
120
|
|
|
feat.to_csv(ft_file) |
121
|
|
|
|
122
|
|
|
hm.plot_particles_in_frame(prefix, x_range=100, y_range=20, upload=False) |
123
|
|
|
assert os.path.isfile('in_frame_{}.png'.format(prefix)) |
124
|
|
|
|