def test_read_analogs( usecols, shape_val, first_last_val, mean_val, median_val, sum_val, nans_val, extension, ): if extension == "csv": data = Analogs.from_csv(**analogs_csv_kwargs, usecols=usecols) decimal = 0 elif extension == "c3d": data = Analogs.from_c3d(MARKERS_ANALOGS_C3D, prefix_delimiter=".", usecols=usecols) decimal = 4 else: raise ValueError("wrong extension provided") if usecols and isinstance(usecols[0], str): np.testing.assert_array_equal(x=data.channel, y=usecols) is_expected_array( data, shape_val, first_last_val, mean_val, median_val, sum_val, nans_val, decimal=decimal, )
def test_csv_trailing_columns(): last_column_to_remove = 5 ref = Analogs.from_csv( **analogs_csv_kwargs).channel[:-last_column_to_remove] without_last_columns = Analogs.from_csv( **analogs_csv_kwargs, trailing_columns=last_column_to_remove).channel np.testing.assert_array_equal(x=ref, y=without_last_columns)
def test_proc_filters(): freq = ANALOGS_DATA.rate order = 2 is_expected_array( ANALOGS_DATA.meca.low_pass(order=order, cutoff=5, freq=freq), **EXPECTED_VALUES[32], ) is_expected_array( ANALOGS_DATA.meca.low_pass(order=order, cutoff=5), **EXPECTED_VALUES[32], ) is_expected_array( ANALOGS_DATA.meca.high_pass(order=order, cutoff=100), **EXPECTED_VALUES[33], ) is_expected_array( ANALOGS_DATA.meca.band_pass(order=order, cutoff=[10, 200]), **EXPECTED_VALUES[34], ) is_expected_array( ANALOGS_DATA.meca.band_stop(order=order, cutoff=[40, 60]), **EXPECTED_VALUES[35], ) freq = MARKERS_DATA.rate is_expected_array( MARKERS_DATA.meca.low_pass(freq=freq, order=order, cutoff=5), **EXPECTED_VALUES[36], ) is_expected_array( MARKERS_DATA.meca.low_pass(order=order, cutoff=5), **EXPECTED_VALUES[36], ) is_expected_array( MARKERS_DATA.meca.high_pass(order=order, cutoff=10), **EXPECTED_VALUES[37], ) is_expected_array( MARKERS_DATA.meca.band_pass(order=order, cutoff=[1, 10]), **EXPECTED_VALUES[38], ) is_expected_array( MARKERS_DATA.meca.band_stop(order=order, cutoff=[5, 6]), **EXPECTED_VALUES[39], ) with pytest.raises(ValueError): Analogs.from_random_data().meca.band_stop(order=order, cutoff=[5, 6])
def test_analogs_creation(): dims = ("channel", "time") array = Analogs() np.testing.assert_array_equal(x=array, y=xr.DataArray()) assert array.dims == dims array = Analogs(ANALOGS_DATA.values) is_expected_array(array, **EXPECTED_VALUES[56]) size = 10, 100 array = Analogs.from_random_data(size=size) assert array.shape == size assert array.dims == dims with pytest.raises(ValueError): Analogs(MARKERS_DATA)
def test_csv_without_header(): is_expected_array( Analogs.from_csv(ANALOGS_CSV, first_row=5, first_column=2), **EXPECTED_VALUES[59], ) is_expected_array( Markers.from_csv(MARKERS_CSV_WITHOUT_HEADER, first_column=2), **EXPECTED_VALUES[58], )
def test_read_catch_error( usecols, extension, ): with pytest.raises(IndexError): Markers.from_csv(MARKERS_CSV) if extension == "csv": with pytest.raises(ValueError): Analogs.from_csv(**analogs_csv_kwargs, usecols=usecols) with pytest.raises(ValueError): Markers.from_csv(**markers_csv_kwargs, usecols=usecols) elif extension == "c3d": with pytest.raises(ValueError): Analogs.from_c3d(MARKERS_ANALOGS_C3D, usecols=usecols) reader = getattr(Markers, f"from_{extension}") with pytest.raises(ValueError): reader(MARKERS_ANALOGS_C3D, usecols=usecols)
def test_read_xlsx(): is_expected_array( Markers.from_excel(**{ **markers_csv_kwargs, **dict(filename=MARKERS_XLSX) }), **EXPECTED_VALUES[60], ) is_expected_array( Analogs.from_excel(**{ **analogs_csv_kwargs, **dict(filename=ANALOGS_XLSX) }), **EXPECTED_VALUES[61], )
def test_csv_edge_cases(): time_with_rate = Analogs.from_csv(**analogs_csv_kwargs, attrs={ "rate": 2000 }).time assert time_with_rate[-1] == 5.7995 time_column_with_id = Analogs.from_csv(**analogs_csv_kwargs, time_column="Frame") time_column_with_name = Analogs.from_csv(**analogs_csv_kwargs, time_column=0) np.testing.assert_array_equal(time_column_with_id.time, time_column_with_name.time) np.testing.assert_array_equal(time_column_with_id, time_column_with_name) with pytest.raises(ValueError): Analogs.from_csv(**analogs_csv_kwargs, time_column=[20.0]) assert Analogs.from_csv(**analogs_csv_kwargs, prefix_delimiter="G", suffix_delimiter="M").shape == (38, 11600)
MARKERS_CSV = DATA_FOLDER / "markers.csv" MARKERS_ANALOGS_C3D = DATA_FOLDER / "markers_analogs.c3d" ANALOGS_CSV = DATA_FOLDER / "analogs.csv" MARKERS_CSV_WITHOUT_HEADER = DATA_FOLDER / "markers_without_header.csv" MARKERS_XLSX = DATA_FOLDER / "markers.xlsx" MARKERS_TRC = DATA_FOLDER / "markers.trc" ANALOGS_XLSX = DATA_FOLDER / "analogs.xlsx" ANALOGS_STO = DATA_FOLDER / "inverse_dyn.sto" ANALOGS_MOT = DATA_FOLDER / "inverse_kin.mot" EXPECTED_VALUES_CSV = DATA_FOLDER / "is_expected_array_val.csv" MARKERS_DATA = Markers.from_c3d( MARKERS_ANALOGS_C3D, usecols=["CLAV_post", "PSISl", "STERr", "CLAV_post"], prefix_delimiter=":", ) ANALOGS_DATA = Analogs.from_c3d( MARKERS_ANALOGS_C3D, usecols=["EMG1", "EMG10", "EMG11", "EMG12"], prefix_delimiter=".", ) EXPECTED_VALUES = pd.read_csv( EXPECTED_VALUES_CSV, index_col=[0], converters={ "shape_val": eval, "first_last_val": eval }, ).to_dict("index")
# --- EMG --- # muscles_names = [ "pect.IM EMG7", "deltpost.EMG3", "triceps.EMG5", "deltant.EMG1", "deltmed.EMG2", "ssp.EMG8", "isp.EMG9", "subs.EMG10", "biceps.EMG4", "uptrap.EMG6", ] a = Analogs.from_c3d(data_path, usecols=muscles_names) emg_rate = int(a.rate) emg = ( a.meca.band_pass(order=4, cutoff=[10, 425]).meca.center().meca.abs().meca.low_pass( order=4, cutoff=5, freq=a.rate) # .meca.normalize() ) # emg.plot(x="time", col="channel", col_wrap=3) # plt.show() # emg.meca.to_matlab("EMG_flex3.mat") # --- Markers --- # markers_full_names = [ "XIPH", "STER", "STERback", "CLAV_SC", "CLAV_AC", "SCAP_CP", "SCAP_AA", "SCAP_TS", "SCAP_IA", "DELT", "ARMl", "EPICl", "EPICm", "LARM_ant",
def test_read_mot(): is_expected_array(Analogs.from_mot(ANALOGS_MOT), **EXPECTED_VALUES[63])
def test_read_sto(): is_expected_array(Analogs.from_sto(ANALOGS_STO), **EXPECTED_VALUES[62]) with pytest.raises(IndexError): Analogs.from_sto(ANALOGS_CSV)