Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make examples great again #77

Merged
merged 3 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/signal_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
MARKERS_ANALOGS_C3D = DATA_FOLDER / 'markers_analogs.c3d'

# read an emg from a c3d file
a = Analogs3d.from_c3d(MARKERS_ANALOGS_C3D, names=['EMG1'])
a = Analogs3d.from_c3d(MARKERS_ANALOGS_C3D, names=['Delt_ant.EMG1'])
a.plot()
plt.show()

Expand Down Expand Up @@ -238,7 +238,7 @@
two_norm = Analogs3d(two_norm.reshape(1, 1, -1))

# threshold = mean during the first second
idx = two_norm[0, 0, :].detect_onset(
idx = two_norm.detect_onset(
threshold=np.nanmean(two_norm[..., :int(b.get_rate)]),
above=int(b.get_rate) / 2,
below=3,
Expand Down
12 changes: 7 additions & 5 deletions pyomeca/frame_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,12 @@ def detect_onset(self, threshold=0, above=1, below=0, threshold2=None, above2=1)
idx : np.ndarray
onset events
"""
if self.ndim > 1:
raise ValueError(f'detect_onset works only for vector (ndim < 2). Your data have {self.ndim} dimensions.')
self[np.isnan(self)] = -np.inf
idx = np.argwhere(self >= threshold).ravel()
if self.ndim != 3:
raise ValueError(f'detect_onset works only for vector (ndim == 3). Your data have {self.ndim} dimensions.')
if self.shape[0] != 1 or self.shape[1] != 1:
raise ValueError(f'detect_onset works on a single time-dependent value for instance: self[i, j, :].')
self[0, 0, np.squeeze(np.isnan(self))] = -np.inf
idx = np.argwhere(np.squeeze(self >= threshold)).ravel()

if np.any(idx):
# initial & final indexes of almost continuous data
Expand All @@ -996,7 +998,7 @@ def detect_onset(self, threshold=0, above=1, below=0, threshold2=None, above2=1)
# minimum amplitude of above2 values in x
ic = np.ones(idx.shape[0], dtype=bool)
for irow in range(idx.shape[0]):
if np.count_nonzero(self[idx[irow, 0]: idx[irow, 1] + 1] >= threshold2) < above2:
if np.count_nonzero(self[0, 0, idx[irow, 0]: idx[irow, 1] + 1] >= threshold2) < above2:
ic[irow] = False
idx = idx[ic, :]

Expand Down