Example #1
0
def download_and_calc_MSDs(prefix):

    import diff_classifier.aws as aws
    import diff_classifier.utils as ut
    import diff_classifier.msd as msd
    import diff_classifier.features as ft
    import os
    import os.path as op
    import numpy as np
    import numpy.ma as ma
    import pandas as pd

    remote_folder = "01_18_Experiment/{}".format(prefix.split('_')[0])
    local_folder = os.getcwd()
    ires = 512

    for row in range(0, 4):
        for col in range(0, 4):
            filename = "Traj_{}_{}_{}.csv".format(prefix, row, col)
            to_download = remote_folder+'/'+filename
            local_name = local_folder+'/'+filename
            aws.download_s3(to_download, local_name)
            if row==0 and col==0:
                merged = msd.all_msds(ut.csv_to_pd(local_name))
            else:
                to_add = ut.csv_to_pd(local_name)
                to_add['X'] = to_add['X'] + ires*row
                to_add['Y'] = to_add['Y'] + ires*col
                to_add['Track_ID'] = to_add['Track_ID'] + max(merged['Track_ID'])
                merged.append(msd.all_msds(to_add))
            print('Successfully downloaded and calculated MSDs for {}_{}_{}'.format(prefix, row, col))

    merged.to_csv('MSD_{}.csv'.format(prefix))
    print('Saved MSDs as MSD_{}.csv'.format(prefix))
    merged_ft = ft.calculate_features(merged)
    merged_ft.to_csv('features_{}.csv'.format(prefix))
    print('Saved features as features_{}.csv'.format(prefix))
Example #2
0
def test_all_msds():

    d = {
        'Frame': [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
        'Track_ID': [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],
        'X': [5, 6, 7, 8, 9, 1, 2, 3, 4, 5],
        'Y': [6, 7, 8, 9, 10, 2, 3, 4, 5, 6]
    }
    df = pd.DataFrame(data=d)

    di = {
        'Frame': [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
        'Track_ID': [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],
        'X': [5, 6, 7, 8, 9, 1, 2, 3, 4, 5],
        'Y': [6, 7, 8, 9, 10, 2, 3, 4, 5, 6],
        'MSDs': [float(i) for i in [0, 2, 8, 18, 32, 0, 2, 8, 18, 32]],
        'Gauss': [0, 0.25, 0.25, 0.25, 0.25, 0, 0.25, 0.25, 0.25, 0.25]
    }
    cols = ['Frame', 'Track_ID', 'X', 'Y', 'MSDs', 'Gauss']
    dfi = pd.DataFrame(data=di)[cols]

    pdt.assert_frame_equal(dfi, all_msds(df))