forked from MonsieurV/py-findpeaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scipy_argrelextrema.py
44 lines (41 loc) · 1020 Bytes
/
scipy_argrelextrema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal
print('Detect peaks without any filters (maxima).')
indexes = scipy.signal.argrelextrema(
np.array(vector),
comparator=np.greater
)
print('Peaks are: %s' % (indexes[0]))
# To get number of peaks:
# print("{} peaks".format(len(indexes[0])))
plot_peaks(
np.array(vector),
indexes[0],
algorithm='scipy.signal.argrelmax'
)
print('Detect peaks without any filters (minima).')
indexes = scipy.signal.argrelextrema(
np.array(vector),
comparator=np.less
)
print('Peaks are: %s' % (indexes[0]))
plot_peaks(
np.array(vector),
indexes[0],
algorithm='scipy.signal.argrelmax'
)
print('Detect peaks with order (distance) filter.')
indexes = scipy.signal.argrelextrema(
np.array(vector),
comparator=np.greater,
order=2
)
print('Peaks are: %s' % (indexes[0]))
plot_peaks(
np.array(vector),
indexes[0],
mpd=2, algorithm='scipy.signal.argrelmax'
)