def test_detect_noise(): movement = { 't': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3]) } movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 2, 1) # Check if function produces the correct outputs noise = path_diversity.detect_noise(movement, paths, 120, 1) noise = list(noise) assert noise == [0, 1, 1, 0] movement = { 't': pd.Series([0., 2., 4., 7.], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3]) } movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 4, 1) # Check if function produces the correct outputs noise = path_diversity.detect_noise(movement, paths, 120, 1) noise = list(noise) assert noise == [0, 0, 0, 0]
def test_smooth_noise(): movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = smooth_noise.smooth_noise(movement, paths, 120, 1) assert len(smoothed) == 3 movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = smooth_noise.smooth_noise(movement, paths, 120, 1) assert smoothed['y'][1] == 0.5 movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = smooth_noise.smooth_noise(movement, paths, 120, 1) assert smoothed['x'][1] == 0.05 movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = smooth_noise.smooth_noise(movement, paths, 120, 1) assert smoothed['t'][1] == 0.03
def test_smooth_noise(): movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = path_diversity.smooth_noise(movement, paths, 120, 1) assert len(smoothed) == 3 movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = path_diversity.smooth_noise(movement, paths, 120, 1) assert smoothed['y'][1] == 0.5 movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = path_diversity.smooth_noise(movement, paths, 120, 1) assert smoothed['x'][1] == 0.05 movement = {'t': pd.Series([0., 0.02, 0.04, 0.06], index=[0, 1, 2, 3]), 'x': pd.Series([0., 0., 0.1, 0.2], index=[0, 1, 2, 3]), 'y': pd.Series([0., 1., 0., 1.], index=[0, 1, 2, 3]), 'isHB': pd.Series(['No', 'No', 'No', 'No'], index=[0, 1, 2, 3])} movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 1, 1) # Check if function produces the correct outputs. smoothed = path_diversity.smooth_noise(movement, paths, 120, 1) assert smoothed['t'][1] == 0.03
def test_filter_path_input(): movement = data.load_movement(0, 0, 0) paths = path_diversity.path_index(movement, 1, 1) # checking functions raise the correct errors # input negative number with pytest.raises(ValueError) as excinfo: path_diversity.filter_path(movement, paths, -1) assert excinfo.value.args[0] == "Input values need to be positive" # input zeros with pytest.raises(ValueError) as excinfo: path_diversity.filter_path(movement, paths, 0) assert excinfo.value.args[0] == "Input values need to be positive"
def test_path(): movement = { 't': pd.Series([0.5, 0.6, 1.0, 2.5, 2.6, 2.7, 4.0, 4.5, 5.0, 6.0, 8.0, 8.5, 10.0]), 'x': pd.Series([1.42, 1.96, 1.79, 1.85, 1.80, 1.98, 1.19, 1.30, 1.85, 1.86, 1.90, 1.76, 1.65]), 'y': pd.Series([1.67, 1.60, 1.13, 1.95, 1.65, 1.11, 1.71, 1.37, 1.88, 1.97, 1.11, 1.15, 1.38]) } movement = pd.DataFrame(movement) # Checking functions output the correct path paths = path_diversity.path_index(movement, 1, 1) assert paths == [[0, 2], [3, 5], [6, 8]]
def test_filter_path(): movement = { 't': pd.Series([0.5, 0.6, 1.0, 2.5, 2.6, 2.7, 4.0, 4.5, 5.0, 6.0, 8.0, 8.5, 10.0]), 'x': pd.Series([1.42, 1.96, 1.79, 1.85, 1.80, 1.98, 1.19, 1.30, 1.85, 1.86, 1.90, 1.76, 1.65]), 'y': pd.Series([1.67, 1.60, 1.13, 1.95, 1.65, 1.11, 1.71, 1.37, 1.88, 1.97, 1.11, 1.15, 1.38]) } movement = pd.DataFrame(movement) paths = path_diversity.path_index(movement, 1, 1) # Checking functions output the correct path pass_paths = path_diversity.filter_path(movement, paths, 1) assert pass_paths == [[6, 8]]
def test_detect_noise_input(): movement = data.load_movement(0, 0, 0) paths = path_diversity.path_index(movement, 1, 1) # Check if function raises the correct type of errors. # Input negative angle_threshold with pytest.raises(ValueError) as excinfo: path_diversity.detect_noise(movement, paths, -1, 1) assert excinfo.value.args[0] == "Input values need to be positive" # Input negative delta_t with pytest.raises(ValueError) as excinfo: path_diversity.detect_noise(movement, paths, 1, -1) assert excinfo.value.args[0] == "Input values need to be positive" # Input zero angle_threshold with pytest.raises(ValueError) as excinfo: path_diversity.detect_noise(movement, paths, 0, 1) assert excinfo.value.args[0] == "Input values need to be positive" # Input zero delta_t with pytest.raises(ValueError) as excinfo: path_diversity.detect_noise(movement, paths, 1, 0) assert excinfo.value.args[0] == "Input values need to be positive"
def test_path_input(): movement = data.load_movement(0, 0, 0) # checking functions raise the correct errors # input negative number with pytest.raises(ValueError) as excinfo: path_index(movement, -1, -1) assert excinfo.value.args[0] == "Input values need to be positive" # input zeros with pytest.raises(ValueError) as excinfo: path_index(movement, 0, 0) assert excinfo.value.args[0] == "Input values need to be positive" # min_path_length cannot be floating number with pytest.raises(TypeError) as excinfo: path_index(movement, 1, 1.5) assert excinfo.value.args[0] == "min_path_length needs to be integer"
def test_path(): movement = data.load_movement(0, 0, 0) # Checking functions output the correct path paths = path_index(movement, 1, 1) assert paths[:5] == [[22, 53], [55, 59], [67, 89], [91, 95], [96, 114]]
import numpy as np import matplotlib.pyplot as plt from mousestyles.data import load_movement from mousestyles.path_diversity import path_index movement = load_movement(0, 0, 0) paths = path_index(movement, 1, 1) xlim = [-16.25, 3.75] ylim = [1.0, 43.0] for sep in paths: path = movement[sep[0]:sep[1] + 1] plt.plot(path['x'], path['y'], 'b', linewidth=1, alpha=.1) plt.xlabel('x-coordinate') plt.xlim(xlim[0], xlim[1]) plt.ylabel('y-coordinate') plt.ylim(ylim[0], ylim[1]) plt.title("Example of path plot") plt.show()
def test_filter_path(): movement = data.load_movement(0, 0, 0) paths = path_index(movement, 1, 1) # Checking functions output the correct path pass_paths = filter_path.filter_paths(movement, paths, 20) assert pass_paths == [[3082, 3181], [30835, 30970], [31346, 31557]]