biomechzoo 0.5.1__py3-none-any.whl → 0.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of biomechzoo might be problematic. Click here for more details.

@@ -1,2 +1,51 @@
1
- def movement_onset():
2
- raise NotImplementedError
1
+ def movement_onset(yd, constant, etype=etype):
2
+ """
3
+ Extracts movement onset based on the average and standard deviation of a sliding window
4
+ Standard thresholds for running are mean_thresh=1.2, std_thresh=0.2. For walking mean_thresh=0.6, std_thresh=0.2.
5
+
6
+ yd: 1d array of the vector
7
+ constants: [sample_frequency, mean_thresh, std_thresh]
8
+ """
9
+ acc_mag = yd.copy()
10
+
11
+ # ----extract the constants----
12
+ fs = constant[0]
13
+ mean_thresh = constant[1]
14
+ std_thresh = constant[2]
15
+
16
+ # ----sliding window features----
17
+ features = []
18
+ timestamps = []
19
+ window_size = 2 * fs # windows van 2 seconds
20
+ step_size = 1 * fs # with an overlap of 1 seconds
21
+
22
+ for start in range(0, len(acc_mag) - window_size, step_size):
23
+ segment = acc_mag[start:start + window_size]
24
+ mean_val = segment.mean()
25
+ std_val = segment.std()
26
+ # entropy = -np.sum((segment / np.sum(segment)) * np.log2(segment / np.sum(segment) + 1e-12))
27
+ timestamps.append(start)
28
+ features.append((mean_val, std_val))
29
+
30
+ features = np.array(features)
31
+ timestamps = np.array(timestamps)
32
+
33
+ # ----Check already moving else find start----
34
+ initial_window = features[:5] # First few seconds
35
+ if np.all(initial_window[:, 0] > mean_thresh) and np.all(initial_window[:, 1] > std_thresh):
36
+ print("already moving")
37
+ if etype == 'movement_offset':
38
+ index = 0
39
+ else:
40
+ # features, timestamps = self.sliding_window_features(acc_mag)
41
+ movement_flags = (features[:, 0] > mean_thresh) & (features[:, 1] > std_thresh)
42
+ index = None
43
+ for i in range(len(movement_flags) - int(min_duration * self.fs / 50)):
44
+ if np.all(movement_flags[i:i + int(min_duration * self.fs / 50)]):
45
+ index = i
46
+ break
47
+
48
+ if etype == 'movement_offset':
49
+ index = len(yd) - end_time
50
+
51
+ return timestamps[index] if index is not None else timestamps[0]
biomechzoo/biomechzoo.py CHANGED
@@ -2,7 +2,7 @@ import os
2
2
  import inspect
3
3
  import time
4
4
 
5
- from biomechzoo.imu.tilt_algoirthm import tilt_algorithm_data
5
+ from biomechzoo.imu.tilt_algorithm import tilt_algorithm_data
6
6
  from biomechzoo.utils.engine import engine # assumes this returns .zoo files in folder
7
7
  from biomechzoo.utils.zload import zload
8
8
  from biomechzoo.utils.zsave import zsave
@@ -136,6 +136,8 @@ class BiomechZoo:
136
136
  def parquet2zoo(self, out_folder=None, inplace=None):
137
137
  raise NotImplementedError('Use table2zoo instead')
138
138
 
139
+ def rectify(self):
140
+ raise NotImplementedError
139
141
  def tilt_algorithm(self, chname_avert, chname_medlat, chname_antpost, out_folder=None, inplace=False):
140
142
  """ tilt correction for acceleration data """
141
143
  start_time = time.time()
@@ -1,6 +1,7 @@
1
1
  import numpy as np
2
2
  import copy
3
3
  import warnings
4
+ from scipy.signal import find_peaks
4
5
  from biomechzoo.utils.peak_sign import peak_sign
5
6
  from biomechzoo.biomech_ops.movement_onset import movement_onset
6
7
 
@@ -42,16 +43,16 @@ def addevent_data(data, channels, ename, etype, constant=None):
42
43
  elif etype == 'rom':
43
44
  eyd = float(np.max(yd) - np.min(yd))
44
45
  exd = 0 # dummy index (like MATLAB version)
45
- elif etype == 'max_stance':
46
+ elif etype == 'first peak':
46
47
  # special event for gait and running
47
- exd = max_stance(yd)
48
- eyd = float(yd[exd])
48
+ exd = find_first_peak(yd, constant)
49
49
  eyd = float(yd[exd])
50
50
  elif etype == 'movement_onset':
51
- exd = movement_onset(yd, constant)
51
+ exd = movement_onset(yd, constant, etype=etype)
52
52
  eyd = yd[exd]
53
53
  elif etype == 'movement_offset':
54
- exd = movement_onset(yd,constant)
54
+ yd2 = yd[::-1].copy() # Reverse the time series.
55
+ exd = movement_onset(yd2, constant, etype=etype)
55
56
  eyd = yd[exd]
56
57
  elif etype in ['fs_fp', 'fo_fp']:
57
58
  # --- Handle constant ---
@@ -99,7 +100,17 @@ def addevent_data(data, channels, ename, etype, constant=None):
99
100
 
100
101
  return data_new
101
102
 
102
- def max_stance(yd):
103
- """ extracts max from first 40% of the gait cycle"""
104
- raise NotImplementedError
103
+ def find_first_peak(yd, constant):
104
+ """ extracts first peak from a series of 2 peaks """
105
+ # Find peaks above threshold
106
+ peaks, _ = find_peaks(yd, height=constant)
107
+
108
+ if len(peaks) == 0:
109
+ raise ValueError('No peaks found')
110
+ elif len(peaks) == 1:
111
+ raise ValueError('Only 1 peak found')
112
+ else:
113
+ # Take the first valid peak
114
+ exd = peaks[0]
115
+
105
116
  return exd
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: biomechzoo
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Python implementation of the biomechZoo toolbox
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/mcgillmotionlab/biomechzoo
@@ -1,13 +1,13 @@
1
1
  __init__.py,sha256=Uy3ykqw4l_lZKiUWSUFPRZpkZajYUfZLBaQLVhKzxdI,772
2
2
  biomechzoo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  biomechzoo/__main__.py,sha256=hSMHN1Rxn2367fSGTLHoOQ4_pocZw0IWI7HFxl-74oY,88
4
- biomechzoo/biomechzoo.py,sha256=3PviTE-zv0TVp3pYayL2ZrMopj5LJtcSLjwxEsGMtxw,22515
4
+ biomechzoo/biomechzoo.py,sha256=Dma-eZNCud0pSD-OjNkAVlMrynOCysCQwUQXMS3GcQk,22572
5
5
  biomechzoo/biomech_ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  biomechzoo/biomech_ops/continuous_relative_phase_data.py,sha256=RePbt6zyOI1iv74CWhxSrunIokTFYVfFmFnoW51781E,1300
7
7
  biomechzoo/biomech_ops/continuous_relative_phase_line.py,sha256=Fa1LFRuPlmGPLQLvln6HVnJy3zMSm9z5YeooHmTu0lc,1365
8
8
  biomechzoo/biomech_ops/filter_data.py,sha256=Q9knW23Ft_WeWVCBjaIQ5GkKU0NYV4SdGiDZV8Fm-hM,1805
9
9
  biomechzoo/biomech_ops/filter_line.py,sha256=XKUdRsxU5AO1gSldnwp3qNzsUUL8qpOpAMyQbEMo5uI,2600
10
- biomechzoo/biomech_ops/movement_onset.py,sha256=3VAoOp01P08BKMaOZW3CwbMdoSMOufDaoMkWeYRcPmo,51
10
+ biomechzoo/biomech_ops/movement_onset.py,sha256=qKeNiVTDra_0wjjPTLfP_Gtoyz5cbHD2F_EDxOxo1oQ,1961
11
11
  biomechzoo/biomech_ops/normalize_data.py,sha256=ESdXeUkKdd0WpjP6FW2EYrOAd7NKWkX1JWUNn1SzDB4,1335
12
12
  biomechzoo/biomech_ops/normalize_line.py,sha256=KUE8gEkIolA-VDFCdUuaskk-waO8jjJ20ZMZaS8Qha8,854
13
13
  biomechzoo/biomech_ops/phase_angle_data.py,sha256=_ekUBW2v3iC4UawcDL38ZZLYJmQsAmyqA61Q6_AMtmQ,1435
@@ -17,7 +17,7 @@ biomechzoo/conversion/c3d2zoo_data.py,sha256=28JCj1Jpn7zsv2HjQdzH2F30jnGMwzmbBwY
17
17
  biomechzoo/conversion/mvnx2zoo_data.py,sha256=uMAZ4pNSSZ7NToW1WnawrXeVP8D-xE3dNDnooPvALE4,3545
18
18
  biomechzoo/conversion/opencap2zoo_data.py,sha256=n4bLsrJI0wTSzG5bgJcmxj1dp2plnUKFNRzcTIbmV1o,608
19
19
  biomechzoo/conversion/table2zoo_data.py,sha256=rAP7OrKbVrb50NHJ6h8fgoMntV87-t9wT2xQ30AD96I,3330
20
- biomechzoo/imu/tilt_algoirthm.py,sha256=PYVErXHeY-Wgi0aXCQxDodohTDzirRXo8BEW3_Pskqo,4312
20
+ biomechzoo/imu/tilt_algorithm.py,sha256=PYVErXHeY-Wgi0aXCQxDodohTDzirRXo8BEW3_Pskqo,4312
21
21
  biomechzoo/mvn/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  biomechzoo/mvn/load_mvnx.py,sha256=B4VGuidQ-5G_5E1t5vpU51Nb_Lu85_EOS_FmGZYjfX8,22499
23
23
  biomechzoo/mvn/main_mvnx.py,sha256=e1LasJQ9icyzjWnRCEcAWQq_-L13-mIzf7PzYA3QYDg,2394
@@ -26,7 +26,7 @@ biomechzoo/mvn/mvnx_file_accessor.py,sha256=Gk2vKq9v_gPbnOS_12zgeJehjFz7v3ClTnN2
26
26
  biomechzoo/processing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  biomechzoo/processing/add_channel_data.py,sha256=U1xLLBSnyJeeDWzgmHSxOz1hyguzuuDXxQCQ8IFoZkw,1955
28
28
  biomechzoo/processing/addchannel_data.py,sha256=rmnnlMRVkoMlQCR-nRg1jjh-hzMDt37Sx9fAmocrpqA,1953
29
- biomechzoo/processing/addevent_data.py,sha256=Z7vsHqhsn8byw4d9atinjGpvglwj6tu38uqZfXVvluQ,3573
29
+ biomechzoo/processing/addevent_data.py,sha256=GGzXSGNNpZFTEMh0l3awqeBf5jHaCdV84K2Nwjuhqkk,3955
30
30
  biomechzoo/processing/explodechannel_data.py,sha256=ceyXfcCmeNqj4p0zCksVdrnmsYR4t-JHLIyv3JlfNpU,2484
31
31
  biomechzoo/processing/partition_data.py,sha256=4wuKrnMmRMNobymYwZ0WuRvNGsvkhThZ2ZhoSkkhntg,1741
32
32
  biomechzoo/processing/removechannel_data.py,sha256=uO7jjuHapRr2CGLsrvYQ1eJLvb1y_8KR6Ct4M6TPALA,1740
@@ -47,9 +47,9 @@ biomechzoo/utils/version.py,sha256=JIXDUuOcaJiZv9ruMP6PtWvJBh4sP0D5kAvlqPiZK_I,1
47
47
  biomechzoo/utils/zload.py,sha256=_qmbQpiEwUNRcB86aS6dHiytOrz1ZXJVjYkk8h5fg8s,2039
48
48
  biomechzoo/utils/zplot.py,sha256=WVA8aCy1Pqy_bo_HXab9AmW-cBd8J8MPX2LAOd6dznU,1512
49
49
  biomechzoo/utils/zsave.py,sha256=wnRNuDxQc8bwCji4UrfoGjYrSZmka4eaDxQ5rMa78pE,1759
50
- biomechzoo-0.5.1.dist-info/licenses/LICENSE,sha256=Fsz62nrgRORre3A1wNXUDISaHoostodMvocRPDdXc9w,1076
51
- biomechzoo-0.5.1.dist-info/METADATA,sha256=Jp2p2d6SsnirRpmQjUb91GyEX9sY5fRGG4jfVqRvwPA,1579
52
- biomechzoo-0.5.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
- biomechzoo-0.5.1.dist-info/entry_points.txt,sha256=VdryUUiwwvx0WZxrgmMrsyfe5Z1jtyaxdXOi0zWHOqk,41
54
- biomechzoo-0.5.1.dist-info/top_level.txt,sha256=nJEtuEZ9UPoN3EOR-BJ6myevEu7B5quWsWhaM_YeQpw,20
55
- biomechzoo-0.5.1.dist-info/RECORD,,
50
+ biomechzoo-0.5.2.dist-info/licenses/LICENSE,sha256=Fsz62nrgRORre3A1wNXUDISaHoostodMvocRPDdXc9w,1076
51
+ biomechzoo-0.5.2.dist-info/METADATA,sha256=_2N7nddOIeDuoVCCXsD8aEggf84O21RBstPq4h3k7pM,1579
52
+ biomechzoo-0.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
+ biomechzoo-0.5.2.dist-info/entry_points.txt,sha256=VdryUUiwwvx0WZxrgmMrsyfe5Z1jtyaxdXOi0zWHOqk,41
54
+ biomechzoo-0.5.2.dist-info/top_level.txt,sha256=nJEtuEZ9UPoN3EOR-BJ6myevEu7B5quWsWhaM_YeQpw,20
55
+ biomechzoo-0.5.2.dist-info/RECORD,,
File without changes