예제 #1
0
def test_load_bad_file():
    with pytest.raises(AssertionError) as AE:
        pproc = Preprocessor()
        gen = pproc.load_df_from_directory_gen('dir_with_corrupt_file')
        for t in gen:
            print(t)
    assert 'Could not load' in str(AE)
예제 #2
0
def test_remove_baseline_bad_threshold():
    with pytest.raises(AssertionError) as AE:
        pproc = Preprocessor()
        gen = pproc.load_df_from_directory_gen('good_data')
        for t in gen:
            pproc.remove_baseline(t.position_data, threshold=0)
    assert 'Threshold' in str(AE)
예제 #3
0
def test_source_dir_with_bad_file_name():
    with pytest.raises(AssertionError) as AE:
        pproc = Preprocessor()
        gen = pproc.load_df_from_directory_gen('dir_with_bad_file_name')
        for t in gen:
            print(t)
    assert 'No source files' in str(AE)
예제 #4
0
def test_invalid_source_dir():
    with pytest.raises(AssertionError) as AE:
        pproc = Preprocessor()
        gen = pproc.lopad_df_from_directory_gen('$')
        for t in gen:
            print(t)
    assert 'Destination directory does not exist' in str(AE)
예제 #5
0
def test_remove_baseline_empty_df():
    with pytest.raises(AssertionError) as AE:
        pproc = Preprocessor()
        gen = pproc.load_df_from_directory_gen('good_data')
        df = pd.DataFrame()
        for t in gen:
            pproc.remove_baseline(df)
    assert 'No data' in str(AE)
예제 #6
0
def test_data_processing_and_save_csv():
    path_to_raw_data = 'good_data/'
    path_to_trials = 'good_data/csv/'

    pproc = Preprocessor()
    raw_data_gen = pproc.load_df_from_directory_gen(dir_path=path_to_raw_data,
                                                    cols=('x', 'y'))

    for trial in raw_data_gen:
        trial.preprocess(pproc)
        trial.save_df(trial.data, path_to_trials)

    list_of_raws = glob(os.path.join(path_to_raw_data, 'li_*.csv'))
    list_of_results = glob(os.path.join(path_to_trials, '*.csv'))
    assert list_of_raws == list_of_results
예제 #7
0
def test_preprocessor_instance():
    pproc = Preprocessor()
    assert isinstance(pproc, Preprocessor)
예제 #8
0
# -*- coding: utf-8 -*-

from DataProcessing import Preprocessor, Trial

path_to_raw_data = '..\\data\\results\\simonvisual\\1'
path_to_database = '..\\data\\processed_data.mat'
sample_rate = 240  #S/s

pproc = Preprocessor()
raw_data_gen = pproc.load_df_from_directory_gen(dir_path=path_to_raw_data)

for trial in raw_data_gen:
    trial.preprocess(pproc, axes=['x', 'y'])
    pproc.plot(trial.velocity_data[['x', 'y']], mode='pandas')
    pproc.plot(trial.filtered_velocity_data[['x', 'y']], mode='pandas')

    print(1)
    break
예제 #9
0
    # TODO: calculate bounds
    #  bounds_low = [0, 0.1, -50, -50]
    #  bounds_high = [t.max(), t.max()-t.min(), 200, 200]

    popt_vx, pcov_vx = curve_fit(func, t, Vx, p0=guess_vx)
    perr_vx = np.sqrt(np.diag(pcov_vx))

    popt_vy, pcov_vy = curve_fit(func, t, Vy, p0=guess_vy)
    perr_vy = np.sqrt(np.diag(pcov_vy))

    fit_vx = func(t, *popt_vx)
    fit_vy = func(t, *popt_vy)

    return fit_vx, fit_vy, popt_vx, perr_vx, popt_vy, perr_vy

if __name__ == '__main__':
    path_to_raw_data = '..\\data\\results\\simonvisual\\1'
    path_to_trials = '..\\data\\trials'

    pproc = Preprocessor()
    raw_data_gen = pproc.load_df_from_directory_gen(dir_path=path_to_raw_data, cols=('x', 'y'))

    # demo for a single trial:
    for trial in raw_data_gen:
        trial.preprocess(pproc)
        trial.save_df(trial.data, path_to_trials)
        res = optimize_jerk(trial, True)
        print(f'Parameters: {res[1]}')
        print(f'Parameter errors: {res[2]}')
        break