Skip to content

Commit 4be3668

Browse files
committed
update examples
1 parent 83fc2d2 commit 4be3668

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

findpeaks/examples.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,60 @@
99
import matplotlib.pyplot as plt
1010
# from findpeaks import findpeaks
1111

12+
# %%
13+
14+
import matplotlib.pyplot as plt
15+
# Import library
16+
from findpeaks import findpeaks
17+
# Initialize
18+
fp = findpeaks(method='topology')
19+
# Example 1d-vector
20+
X = fp.import_example('1dpeaks')
21+
22+
# Plot
23+
# plt.figure(figsize=(15, 8), dpi=100)
24+
# plt.plot(X)
25+
# plt.grid(True)
26+
# plt.xlabel('Time')
27+
# plt.ylabel('Value')
28+
29+
# Fit topology method on the 1D vector
30+
results = fp.fit(X)
31+
# Plot the results
32+
fp.plot_persistence(figsize=(25,8))
33+
34+
35+
36+
# %%
37+
import numpy as np
38+
from scipy.ndimage import gaussian_filter
39+
from findpeaks import findpeaks
40+
rng = np.random.default_rng(42)
41+
x = rng.normal(size=(50, 50))
42+
x = gaussian_filter(x, sigma=10.)
43+
# peak and valley
44+
fp = findpeaks(method="topology", whitelist=['peak', 'valley'], denoise=None)
45+
results = fp.fit(x)
46+
47+
fp.plot(figsize=(25, 15), figure_order='horizontal', marker='x')
48+
# fp.plot_persistence()
49+
# fp.plot_mesh()
50+
51+
# %%
52+
53+
# Import library
54+
from findpeaks import findpeaks
55+
# Initializatie
56+
fp = findpeaks(scale=True, denoise=None, togray=True, imsize=(300, 300))
57+
# Import image example
58+
img = fp.import_example('2dpeaks_image')
59+
# Fit
60+
results = fp.fit(img)
61+
# Tens of thousands of peaks are detected at this point.
62+
fp.plot(figure_order='horizontal', text=False)
63+
# fp.plot_mesh()
64+
65+
1266
# %%
1367
# =============================================================================
1468
# Issue with numpy > 1.26.4
@@ -57,7 +111,7 @@
57111
X = [10,11,9,23,21,11,45,20,11,12]
58112
fp = findpeaks(method="topology", lookahead=1, verbose='info')
59113
results = fp.fit(X)
60-
ax = fp.plot()
114+
ax = fp.plot(text=True)
61115
ax = fp.plot_persistence()
62116

63117
# fp.check_logger(verbose='info')
@@ -204,7 +258,7 @@
204258
# %%
205259
from findpeaks import findpeaks
206260
path = r'https://erdogant.github.io/datasets/images/complex_peaks.png'
207-
fp = findpeaks(method='topology', whitelist='peak', denoise='lee_enhanced', params={'window': 5}, verbose='debug')
261+
fp = findpeaks(method='topology', whitelist='peak', denoise='lee_enhanced', params={'window': 5})
208262
X = fp.imread(path)
209263
results = fp.fit(X)
210264
ax = fp.plot_persistence()

0 commit comments

Comments
 (0)