Skip to content

Commit

Permalink
Merge pull request #107 from The-Motor-Unit/test-decomp
Browse files Browse the repository at this point in the history
test: final decomp test + minor comment edits
  • Loading branch information
danfke authored Jun 29, 2022
2 parents 54d6d0b + cbeb19c commit d4471c0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
20 changes: 19 additions & 1 deletion tests/test_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

# Note: Fixtures are special pytest objects calld into individual tests,
# Note: Fixtures are special pytest objects called into individual tests,
# they are useful when data is required to test a function


Expand Down Expand Up @@ -442,3 +442,21 @@ def test_silhouette_score():
assert np.isclose(
sil, sil_by_hand
), "Inter and intra distances incorrectly calculated."

def test_decomposition():
"""
Run unit test on decomposition function from EMGdecomPy.
"""
# load data
gl_10 = loadmat("data/raw/GL_10.mat")
raw = gl_10["SIG"]

decompose = emg.decomposition.decomposition(raw, M=3, R=2)
keys = list(decompose.keys())

assert type(decompose) == dict, "Incorrect object returned."
assert keys == ['B', 'MUPulses', 'SIL', 'PNR'], "Incorrect keys returned."
assert type(decompose['B']) == np.ndarray, "Incorrect datatype returned in B key."
assert type(decompose['MUPulses']) == np.ndarray, "Incorrect datatype returned in MUPulses key."
assert type(decompose['SIL']) == np.ndarray, "Incorrect datatype returned in B key."
assert type(decompose['PNR']) == np.ndarray, "Incorrect datatype returned in PNR key."
19 changes: 19 additions & 0 deletions tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from emgdecompy import preprocessing as emg
import numpy as np
from scipy import linalg
from scipy.io import loadmat

# Test script for all functions defined in src/preprocessing.py

Expand Down Expand Up @@ -182,6 +183,24 @@ def test_flatten_signal():

# Test that empty channel has been removed
assert (m * n) != flat.shape[0], "Empty array not removed"

def test_butter_bandpass_filter():
"""
Run unit test on butter_bandpass_filter function from EMGdecomPy.
"""

gl_10 = loadmat("data/raw/GL_10.mat")
raw = gl_10["SIG"]

# select two channels from raw data
data = raw[1, 1:3]

d = emg.flatten_signal(data)
x = emg.butter_bandpass_filter(d)

assert type(x) == np.ndarray, "Incorrect datatype returned."
assert x.shape == d.shape, "Incorrect shape returned."



def test_center_matrix():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import panel
import pytest

# Note: Fixtures are special PyTest objects calld into individual tests,
# Note: Fixtures are special PyTest objects called into individual tests,
# they are useful when data is repeatedly required to test functions


Expand Down

0 comments on commit d4471c0

Please sign in to comment.