예제 #1
0
def test_partial_corr():
    dataf = msd.random_traj_dataset()
    msds = msd.all_msds2(dataf, frames=100)
    feat = ft.calculate_features(msds)
    pcorr = pca.partial_corr(feat)
    npt.assert_equal(24.0, np.round(np.sum(pcorr), 1))

    dataf = msd.random_traj_dataset(nparts=10)
    msds = msd.all_msds2(dataf, frames=100)
    feat = ft.calculate_features(msds)
    pcorr = pca.partial_corr(feat)
    npt.assert_equal(47.9, np.round(np.sum(pcorr), 1))

    dataf = msd.random_traj_dataset(nparts=10, seed=9)
    msds = msd.all_msds2(dataf, frames=100)
    feat = ft.calculate_features(msds)
    pcorr = pca.partial_corr(feat)
    npt.assert_equal(33.4, np.round(np.sum(pcorr), 1))

    dataf = msd.random_traj_dataset(nparts=10, nframes=40, seed=9)
    msds = msd.all_msds2(dataf, frames=40)
    feat = ft.calculate_features(msds)
    pcorr = pca.partial_corr(feat)
    npt.assert_equal(17.4, np.round(np.sum(pcorr), 1))

    dataf = msd.random_traj_dataset(nparts=10,
                                    nframes=40,
                                    ndist=(3, 5),
                                    seed=9)
    msds = msd.all_msds2(dataf, frames=40)
    feat = ft.calculate_features(msds)
    pcorr = pca.partial_corr(feat)
    npt.assert_equal(35.7, np.round(np.sum(pcorr), 1))
예제 #2
0
def test_kmo():
    dataf = msd.random_traj_dataset(nparts=10, ndist=(1, 1), seed=3)
    msds = msd.all_msds2(dataf, frames=100)
    feat = ft.calculate_features(msds)
    dataset = feat.drop(['frames', 'Track_ID'], axis=1)
    corrmatrix = np.corrcoef(dataset.transpose())
    npt.assert_equal(np.round(np.sum(corrmatrix), 1), 7.3)
예제 #3
0
def test_pca_analysis():
    dataf = msd.random_traj_dataset(nparts=10, ndist=(2, 6))
    msds = msd.all_msds2(dataf, frames=100)
    feat = ft.calculate_features(msds)
    pcadataset = pca.pca_analysis(feat,
                                  dropcols=['frames', 'Track_ID'],
                                  n_components=5)

    npt.assert_equal(np.round(np.sum(pcadataset.components.values), 3), 0.400)
예제 #4
0
def test_plot_particles_in_frame():
    prefix = 'test'
    msd_file = 'msd_{}.csv'.format(prefix)
    ft_file = 'features_{}.csv'.format(prefix)

    dataf = msd.random_traj_dataset(nparts=10, ndist=(1, 1), seed=3)
    msds = msd.all_msds2(dataf, frames=100)
    msds.to_csv(msd_file)
    feat = ft.calculate_features(msds)
    feat.to_csv(ft_file)

    hm.plot_particles_in_frame(prefix, x_range=100, y_range=20, upload=False)
    assert os.path.isfile('in_frame_{}.png'.format(prefix))
예제 #5
0
def test_plot_trajectories():
    prefix = 'test'
    msd_file = 'msd_{}.csv'.format(prefix)
    ft_file = 'features_{}.csv'.format(prefix)

    dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3)
    msds = msd.all_msds2(dataf, frames=100)
    msds.to_csv(msd_file)
    feat = ft.calculate_features(msds)
    feat.to_csv(ft_file)

    hm.plot_trajectories(prefix, resolution=520, rows=1, cols=1, upload=False)
    assert os.path.isfile('traj_{}.png'.format(prefix))
예제 #6
0
def test_plot_histogram():
    prefix = 'test'
    msd_file = 'msd_{}.csv'.format(prefix)
    ft_file = 'features_{}.csv'.format(prefix)

    dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3)
    msds = msd.all_msds2(dataf, frames=100)
    msds.to_csv(msd_file)
    feat = ft.calculate_features(msds)
    feat.to_csv(ft_file)
    
    hm.plot_histogram(prefix, fps=1, umppx=1, frames=100, frame_interval=5, frame_range=5, y_range=10, upload=False)
    assert os.path.isfile('hist_{}.png'.format(prefix))
예제 #7
0
def test_plot_individual_msds():
    prefix = 'test'
    msd_file = 'msd_{}.csv'.format(prefix)
    ft_file = 'features_{}.csv'.format(prefix)

    dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3)
    msds = msd.all_msds2(dataf, frames=100)
    msds.to_csv(msd_file)
    feat = ft.calculate_features(msds)
    feat.to_csv(ft_file)

    geomean, gSEM = hm.plot_individual_msds(prefix, umppx=1, fps=1, y_range=400, alpha=0.3, upload=False)
    npt.assert_equal(332.8, np.round(np.sum(geomean), 1))
    npt.assert_equal(33.1, np.round(np.sum(gSEM), 1))
예제 #8
0
def test_voronoi_finite_polygons_2d():
    prefix = 'test'
    msd_file = 'msd_{}.csv'.format(prefix)
    ft_file = 'features_{}.csv'.format(prefix)

    dataf = msd.random_traj_dataset(nparts=30, ndist=(1, 1), seed=3)
    msds = msd.all_msds2(dataf, frames=100)
    msds.to_csv(msd_file)
    feat = ft.calculate_features(msds)
    feat.to_csv(ft_file)

    xs = feat['X'].astype(int)
    ys = feat['Y'].astype(int)
    points = np.zeros((xs.shape[0], 2))
    points[:, 0] = xs
    points[:, 1] = ys

    vor = Voronoi(points)
    regions, vertices = hm.voronoi_finite_polygons_2d(vor)

    npt.assert_equal(243.8, np.round(np.mean(vertices), 1))
예제 #9
0
def test_random_traj_dataset():
    di = {
        'Frame': [float(i) for i in [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]],
        'Track_ID': [float(i) for i in [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]],
        'X':
        np.array([
            1., 1.93045975532, 1.0, 1.0, 1.0, 0.0, 0.288183500979,
            0.576367001958, 0.864550502937, 0.864550502937
        ]),
        'Y':
        np.array([
            1., 1., 1., 0.06954024468115816, 1.0, 4.0, 4.0, 4.0, 4.0,
            4.288183500978857
        ]),
        'Quality': [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
        'SN_Ratio': [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
        'Mean_Intensity': [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
    }
    cols = ['Frame', 'Track_ID', 'X', 'Y']
    dfi = pd.DataFrame(data=di)[cols]

    pdt.assert_frame_equal(
        dfi,
        msd.random_traj_dataset(nframes=5, nparts=2, fsize=(0, 5))[cols])
예제 #10
0
def test_random_traj_dataset():
    di = {
        'Frame': [float(i) for i in [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]],
        'Track_ID': [float(i) for i in [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]],
        'X':
        np.array([
            1., 1., 1., 1.93045976, 1.93045976, 0., -0.2881835, 0., 0.,
            0.2881835
        ]),
        'Y':
        np.array([
            1., 0.06954024, -0.86091951, -0.86091951, 0.06954024, 4., 4., 4.,
            4.2881835, 4.2881835
        ]),
        'Quality': [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
        'SN_Ratio': [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
        'Mean_Intensity': [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
    }
    cols = ['Frame', 'Track_ID', 'X', 'Y']
    dfi = pd.DataFrame(data=di)[cols]

    pdt.assert_frame_equal(
        dfi,
        msd.random_traj_dataset(nframes=5, nparts=2, fsize=(0, 5))[cols])