py2ls 0.1.7.7__py3-none-any.whl → 0.1.7.9__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.
@@ -139,7 +139,7 @@ def filter_bandpass(data=None, ord=4, freq_range=[11, 16], fs=1000):
139
139
  def moving_average(data, window_size):
140
140
  return convolve1d(data, np.ones(window_size) / window_size)
141
141
 
142
- def detect_cross(data, thr=0):
142
+ def detect_cross(data, thr=0, match=True,full_cycle=False):
143
143
  if isinstance(data, list):
144
144
  data = np.array(data)
145
145
  if data.ndim == 1:
@@ -148,25 +148,31 @@ def detect_cross(data, thr=0):
148
148
  data = data.T
149
149
  else:
150
150
  raise ValueError("Input data must have two dimensions.")
151
-
152
- thr_cross = np.sign(data[:, np.newaxis] - thr)
153
- falling_before = np.where((thr_cross[:-1] == 1) & (thr_cross[1:] == -1))[0] #+ 1
154
- rising_before = np.where((thr_cross[:-1] == -1) & (thr_cross[1:] == 1))[0]
155
- falling_before = falling_before.tolist()
156
- rising_before = rising_before.tolist()
157
- if rising_before and falling_before:
158
- if rising_before[0] < falling_before[0]:
159
- if len(rising_before) > len(falling_before):
160
- rising_before.pop(0)
161
- else:
162
- falling_before.pop(0)
163
- if len(rising_before) > len(falling_before):
164
- rising_before.pop(0)
165
- if rising_before and falling_before:
151
+ if full_cycle:
152
+ thr_cross = np.sign(data[:, np.newaxis] - thr)
153
+ falling_before = np.where((thr_cross[:-1] == 1) & (thr_cross[1:] == -1))[0] #+ 1
154
+ rising_before = np.where((thr_cross[:-1] == -1) & (thr_cross[1:] == 1))[0]
155
+ falling_before = falling_before.tolist()
156
+ rising_before = rising_before.tolist()
157
+ if rising_before and falling_before:
158
+ if rising_before[0] < falling_before[0]:
159
+ if len(rising_before) > len(falling_before):
160
+ rising_before.pop(0)
161
+ else:
162
+ falling_before.pop(0)
163
+ if len(rising_before) > len(falling_before):
164
+ rising_before.pop(0)
166
165
  return rising_before, falling_before
167
166
  else:
168
167
  signal_shifted = data - thr
169
- return np.where(np.diff(np.sign(signal_shifted)))[0]
168
+ signal_sign = np.sign(signal_shifted)
169
+ sign_diff = np.diff(signal_sign)
170
+ rising_before, falling_before=np.where(sign_diff > 0)[0],np.where(sign_diff < 0)[0]
171
+ if match:
172
+ # make sure they are matched
173
+ min_length = min(len(rising_before), len(falling_before))
174
+ rising_before, falling_before=rising_before[:min_length], falling_before[:min_length]
175
+ return rising_before, falling_before
170
176
  ## debug
171
177
  # a = np.sin(np.arange(0, 10 * np.pi, np.pi / 100))
172
178
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.7.7
3
+ Version: 0.1.7.9
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -138,10 +138,10 @@ py2ls/ips.py,sha256=KkrkGAF0VQ-N0rH4FQFLyP-C-skY6EPpeO8t_5RngWw,88519
138
138
  py2ls/netfinder.py,sha256=MY_0TQY_zaRBZ6wfR4RxNCGrU93HFmDVDRRy1EXl75o,47566
139
139
  py2ls/plot.py,sha256=8_33-1wpkGZrDUuvRBfTPUi_BRKdf1njoR725OLSLSY,48579
140
140
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
141
- py2ls/sleep_events_detectors.py,sha256=Y0cbM1yHbIxIYEnFICZSHmQWO31nZGZUMcH07kTbiQ4,51697
141
+ py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
142
142
  py2ls/stats.py,sha256=Wd9yCKQ_61QD29WMEgMuEcreFxF91NmlPW65iWT2B5w,39041
143
143
  py2ls/translator.py,sha256=bc5FB-wqC4TtQz9gyCP1mE38HqNRJ_pmuRIgKnAlMzM,30581
144
144
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
145
- py2ls-0.1.7.7.dist-info/METADATA,sha256=x7zPhd_n4VHVZQmjLcZaa6525qNXyWoM6YTDOUDeqmw,20017
146
- py2ls-0.1.7.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
- py2ls-0.1.7.7.dist-info/RECORD,,
145
+ py2ls-0.1.7.9.dist-info/METADATA,sha256=aeI1PAS5UHFiY3iBnfrw7VS7_y5Q8AS7chRBQgMMmxE,20017
146
+ py2ls-0.1.7.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
+ py2ls-0.1.7.9.dist-info/RECORD,,