Skip to content

Commit

Permalink
added an argument for minimum height of the peak (#28)
Browse files Browse the repository at this point in the history
* added height to peak detect args

* fixed a typo

* Update setup.py

changed peakdetect version

* Update setup.py

* added external dependencies

---------

Co-authored-by: arvin <[email protected]>
Co-authored-by: Erdogan <[email protected]>
  • Loading branch information
3 people authored Feb 18, 2024
1 parent 198ad1f commit df6a809
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 215 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/findpeaks.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 30 additions & 36 deletions findpeaks/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
x = rng.normal(size=(50, 50))
x = gaussian_filter(x, sigma=10.)
# peak and valley
fp = findpeaks(method="topology", whitelist=['peak','valley'], denoise=None, verbose=3)
fp = findpeaks(method="topology", whitelist=['peak', 'valley'], denoise=None, verbose=3)
results = fp.fit(x)

fp.plot(figsize=(25, 15), figure_order='horizontal', cmap=plt.cm.hot_r)
Expand All @@ -68,7 +68,7 @@

from findpeaks import findpeaks
path = r'https://user-images.githubusercontent.com/12035402/274193739-cdfd8986-91eb-4211-bef6-ebad041f47ae.png'
fp = findpeaks(method='topology', denoise='lee_sigma', params={'window': 5}, whitelist='peak', limit=5)
fp = findpeaks(method='topology', whitelist='peak', limit=5, denoise='lee_sigma', params={'window': 5})
X = fp.imread(path)
results = fp.fit(X)

Expand Down Expand Up @@ -114,7 +114,7 @@
from findpeaks import findpeaks
X = [1,1,1.1,1,0.9,1,1,1.1,1,0.9,1,1.1,1,1,0.9,1,1,1.1,1,1,1,1,1.1,0.9,1,1.1,1,1,0.9,1,1.1,1,1,1.1,1,0.8,0.9,1,1.2,0.9,1,1,1.1,1.2,1,1.5,1,3,2,5,3,2,1,1,1,0.9,1,1,3,2.6,4,3,3.2,2,1,1,0.8,4,4,2,2.5,1,1,1]

fp = findpeaks(method='peakdetect', lookahead=1, verbose=3, whitelist=['peak', 'valley'], params={'delta': 1})
fp = findpeaks(method='peakdetect', whitelist=['peak', 'valley'], lookahead=1, params={'delta': 1}, verbose=3)
# fp = findpeaks(method='topology')
results = fp.fit(X)
fp.plot()
Expand Down Expand Up @@ -146,11 +146,7 @@
from findpeaks import findpeaks

# Initialize
fp = findpeaks(method='topology',
scale=True,
togray=True,
imsize=(150, 150),
denoise='lee_sigma',
fp = findpeaks(method='topology', imsize=(150, 150), scale=True, togray=True, denoise='lee_sigma',
params={'window': 17})

# Import example image
Expand All @@ -167,7 +163,7 @@
# %% Issue 18:
from findpeaks import findpeaks

fp = findpeaks(method='topology', scale=False, denoise=None, togray=False, imsize=False, params={'window': 15})
fp = findpeaks(method='topology', imsize=False, scale=False, togray=False, denoise=None, params={'window': 15})
X = fp.import_example('2dpeaks')
fp.fit(X)
# fp.plot_mesh(wireframe=False, title='Test', cmap='RdBu', view=(70,5))
Expand All @@ -183,8 +179,8 @@
# %%
from findpeaks import findpeaks
path = r'https://user-images.githubusercontent.com/44827483/221152897-133839bb-7364-492a-921b-c9077ab9930b.png'
fp = findpeaks(method='topology', denoise='lee_enhanced', params={'window':5}, whitelist='peak')
fp = findpeaks(method='topology', denoise='lee_sigma', params={'window':5}, whitelist='peak')
fp = findpeaks(method='topology', whitelist='peak', denoise='lee_enhanced', params={'window': 5})
fp = findpeaks(method='topology', whitelist='peak', denoise='lee_sigma', params={'window': 5})
X = fp.imread(path)
results = fp.fit(X)
fp.plot_persistence()
Expand All @@ -197,7 +193,7 @@
from findpeaks import findpeaks
X = [1,1,1.1,1,0.9,1,1,1.1,1,0.9,1,1.1,1,1,0.9,1,1,1.1,1,1,1,1,1.1,0.9,1,1.1,1,1,0.9,1,1.1,1,1,1.1,1,0.8,0.9,1,1.2,0.9,1,1,1.1,1.2,1,1.5,1,3,2,5,3,2,1,1,1,0.9,1,1,3,2.6,4,3,3.2,2,1,1,0.8,4,4,2,2.5,1,1,1]

fp = findpeaks(method='peakdetect', lookahead=1, verbose=3, whitelist=['peak', 'valley'])
fp = findpeaks(method='peakdetect', whitelist=['peak', 'valley'], lookahead=1, verbose=3)
results = fp.fit(X)
fp.plot()

Expand Down Expand Up @@ -229,7 +225,7 @@
from findpeaks import findpeaks

# Initialize peakdetect
fp1 = findpeaks(method='peakdetect', lookahead=200, whitelist='peak')
fp1 = findpeaks(method='peakdetect', whitelist='peak', lookahead=200)

# Initialize topology
fp2 = findpeaks(method='topology')
Expand Down Expand Up @@ -267,7 +263,7 @@
# %% Issue 13
# https://github.com/erdogant/findpeaks/issues/13
from findpeaks import findpeaks
fp = findpeaks(method="mask", denoise=None, params={'window': 3}, limit=None, verbose=0)
fp = findpeaks(method="mask", limit=None, denoise=None, params={'window': 3}, verbose=0)
X = fp.import_example("2dpeaks_image")
results = fp.fit(X)
fp.plot(figure_order='horizontal')
Expand All @@ -279,7 +275,7 @@
# Data
X = [10,11,9,23,21,11,45,20,11,12]
# Initialize
fp = findpeaks(method='topology', lookahead=1, verbose=0, whitelist=['valley', 'peak'])
fp = findpeaks(method='topology', whitelist=['valley', 'peak'], lookahead=1, verbose=0)
results = fp.fit(X)
fp.plot()
results['df']
Expand Down Expand Up @@ -310,7 +306,7 @@
# x = cv2.imread('C://temp/uISO2.png')
# x = [7193,7539,14310,14364,7414,7353,7557,7184,7188,7550,14330,14414,7480,7400,7582,7205,7140,7546,14356,14462,7533,7426,7618,7224,7192,7550,14371,14494,7558,7436,7634,7231,7172,7556,14390,14545,7616,7491,7669,7260,7123,7557,14404,14590,7671,7532,7698,7281,7172,7578,14396,14624,7703,7555,7718,7283,7214,7597,14407,14659,7729,7574,7742,7280,7219,7599,14414,14702,7764,7594,7743,7284,7217,7604,14414,14729,7794,7604,7740,7283,7233,7655,14430,14782,7853,7647,7779,7306,7207,7663,14444,14831,7895,7676,7808,7326,7292,7673,14427,14848,7889,7653,7769,7313,7330,7711,14433,14883,7909,7654,7772,7322,7343,7732,14442,14934,7969,7706,7807,7341,7315,7735,14450,14987,8043,7771,7837,7360,7330,7759,14458,15032,8083,7791,7857,7386,7364,7790,14464,15063,8106,7804,7859,7397,7364,7799,14474,15097,8161,7838,7873,7413,7374,7803,14468,15139,8212,7858,7891,7432,7391,7836,14478,15181,8258,7900,7927,7462,7405,7840,14459,15195,8278,7932,7950,7476,7389,7849,14454,15224,8321,7965,7978,7494,7470,7860,14445,15230,8322,7972,7979,7497,7430,7895,14454,15267,8344,8006,8020,7518,7420,7898,14440,15276,8332,7996,8015,7516,7482,7918,14410,15265,8332,7988,8005,7519,7536,7956,14404,15279,8339,7998,8026,7539,7523,7949,14410,15289,8329,8005,8047,7564,7501,7945,14403,15283,8329,8009,8049,7562,7533,7970,14392,15283,8321,8017,8068,7577,7515,7980,14409,15297,8319,8031,8078,7600,7508,7967,14396,15286,8331,8047,8072,7590,7582,7967,14362,15257,8336,8041,8072,7583,7650,7956,14344,15229,8318,8015,8060,7580,7570,7945,14342,15223,8314,8015,8059,7599,7529,7966,14355,15229,8321,8041,8085,7628,7578,7959,14352,15212,8322,8048,8089,7632,7546,7932,14332,15181,8306,8055,8078,7615,7494,7943,14325,15160,8291,8057,8069,7616,7547,7962,14296,15126,8253,8031,8053,7606,7646,7953,14239,15066,8203,7985,8015,7570,7539,7955,14249,15057,8196,7989,8031,7602,7447,7967,14276,15059,8191,8024,8069,7646,7532,7942,14258,14998,8145,7994,8046,7633,7543,7932,14220,14927,8073,7949,8011,7594,7491,7943,14190,14869,8019,7919,7992,7583,7505,7897,14183,14822,7985,7907,8007,7593,7470,7858,14176,14778,7940,7889,7991,7584,7478,7823,14152,14706,7876,7857,7960,7567,7549,7832,14111,14618,7783,7795,7915,7526,7456,7792,14132,14556,7723,7756,7910,7515,7336,7745,14149,14517,7669,7719,7881,7503,7309,7725,14143,14448,7587,7676,7840,7476,7350,7701,14117,14364,7496,7624,7798,7432,7295,7653,14114,14298,7440,7572,7746,7394,7282,7643,14100,14236,7350,7527,7704,7368,7296,7626,14081,14174,7284,7491,7688,7345,7217,7588,14086,14110,7205,7440,7655,7310,7174,7557,14086,14038,7139,7387,7613,7283,7209,7512,14081,13995,7087,7351,7578,7274,7178,7472,14078,13950,7029,7318,7549,7255,7110,7441,14066,13878,6954,7259,7489,7222,7076,7420,14076,13839,6896,7223,7485,7225,7127,7390,14050,13784,6831,7186,7469,7187,7013,7332,14083,13760,6783,7164,7458,7183,6996,7308,14078,13712,6725,7128,7417,7170,7024,7302,14077,13676,6668,7081,7392,7135,6996,7283,14071,13635,6613,7034,7363,7121,6940,7247,14067,13593,6553,6998,7349,7102,6892,7258,14098,13599,6539,7006,7384,7119,6894,7222,14086,13558,6483,6972,7346,7096,6920,7193,14064,13510,6437,6926,7301,7050,6937,7191,14053,13506,6422,6914,7295,7047,6928,7176,14060,13499,6393,6894,7292,7056,6855,7155,14077,13482,6384,6899,7281,7061,6861,7159,14069,13479,6372,6881,7266,7057,6935,7164,14063,13461,6334,6857,7253,7047,6935,7140,14047,13443,6303,6828,7218,7027,6897,7114,14054,13439,6296,6822,7200,7030,6801,7123,14090,13475,6316,6861,7245,7069,6763,7123,14087,13484,6316,6870,7268,7087,6961,7130,14023,13420,6250,6812,7202,7032,7013,7148,14022,13406,6231,6804,7201,7025,6947,7131,14057,13437,6247,6835,7236,7053,6806,7094,14081,13461,6263,6848,7262,7070,6828,7101,14059,13453,6250,6822,7240,7070,6870,7118,14054,13451,6256,6817,7249,7073,6882,7106,14045,13464,6253,6827,7237,7063,6925,7101,14028,13443,6243,6817,7216,7047,6954,7111,14036,13458,6254,6831,7224,7050,6924,7091,14038,13461,6253,6837,7221,7054,6868,7082,14049,13474,6257,6828,7214,7051,6866,7107,14052,13495,6271,6838,7231,7069,6866,7121,14046,13510,6284,6858,7243,7086,6868,7107,14023,13503,6260,6851,7216,7070,6976,7097,13991,13465,6223,6817,7162,7037,6980,7117,13999,13479,6244,6822,7191,7044,6827,7093,14059,13534,6302,6867,7234,7099,6831,7094,14064,13540,6302,6854,7217,7102,6876,7114,14052,13551,6290,6858,7231,7108]

fp = findpeaks(method="peakdetect", whitelist=['peak', 'valley'], denoise=None, limit=0, verbose=3)
fp = findpeaks(method="peakdetect", whitelist=['peak', 'valley'], limit=0, denoise=None, verbose=3)
results = fp.fit(x)

# results['df']
Expand All @@ -330,7 +326,7 @@
x = gaussian_filter(x, sigma=10.)

# Search for peaks/valleys with a minimum value of 0
fp = findpeaks(method="topology", denoise=None, limit=0, verbose=3)
fp = findpeaks(method="topology", limit=0, denoise=None, verbose=3)
results = fp.fit(x)

results['persistence']
Expand Down Expand Up @@ -370,7 +366,7 @@
results = fp.fit(X)
fp.plot()

fp = findpeaks(method="caerus", params={'minperc':100}, interpolate=None, verbose=verbose)
fp = findpeaks(method="caerus", interpolate=None, params={'minperc': 100}, verbose=verbose)
# Make fit
results = fp.fit(X)
ax = fp.plot()
Expand All @@ -384,7 +380,7 @@
np.random.seed(200)
X = np.random.randint(200, size=400)

fp = findpeaks(method='topology', interpolate = 10, lookahead = 1, verbose=3)
fp = findpeaks(method='topology', lookahead=1, interpolate=10, verbose=3)
results = fp.fit(X)

fig=fp.plot()
Expand Down Expand Up @@ -414,7 +410,8 @@
# Import image example
img = fp.import_example('2dpeaks_image')
# Initializatie
fp = findpeaks(scale=True, denoise='fastnl', params={'window': 31}, togray=True, imsize=(300,300), whitelist=['peak', 'valley'], verbose=3)
fp = findpeaks(whitelist=['peak', 'valley'], imsize=(300, 300), scale=True, togray=True, denoise='fastnl',
params={'window': 31}, verbose=3)
# Fit
fp.fit(img)
fp.plot()
Expand All @@ -424,14 +421,8 @@
limit = fp.results['persistence'][0:5]['score'].min()
fp.plot(text=True, limit=limit)

fp = findpeaks(scale=True,
denoise='fastnl',
params={'window': 31},
togray=True,
imsize=(300,300),
limit=limit,
whitelist=['peak', 'valley'],
verbose=3)
fp = findpeaks(whitelist=['peak', 'valley'], limit=limit, imsize=(300, 300), scale=True, togray=True, denoise='fastnl',
params={'window': 31}, verbose=3)
fp.fit(img)

fp.results["persistence"]
Expand All @@ -444,7 +435,7 @@

# %%
from findpeaks import findpeaks
fp = findpeaks(method="topology", denoise=None, params={'window': 3}, limit=None, verbose=0)
fp = findpeaks(method="topology", limit=None, denoise=None, params={'window': 3}, verbose=0)
X = fp.import_example("2dpeaks_image")
# X = fp.import_example("2dpeaks")
results = fp.fit(X)
Expand Down Expand Up @@ -478,7 +469,7 @@
for method in methods:
for interpolate in interpolates:
for lookahead in lookaheads:
fp = findpeaks(lookahead=lookahead, interpolate=interpolate, method=method)
fp = findpeaks(method=method, lookahead=lookahead, interpolate=interpolate)
results = fp.fit(X)
# fp.plot()
# fp.plot_persistence()
Expand All @@ -489,7 +480,7 @@
# %%
from findpeaks import findpeaks
X = [10,11,9,23,21,11,45,20,11,12]
fp = findpeaks(lookahead=1, method="topology", verbose=3)
fp = findpeaks(method="topology", lookahead=1, verbose=3)
results = fp.fit(X)
fp.plot()
fp.plot_persistence()
Expand All @@ -506,7 +497,8 @@

for getfilter in filters:
for window in windows:
fp = findpeaks(method='topology', scale=True, denoise=getfilter, params={'window': window}, togray=True, imsize=(300,300), verbose=verbose)
fp = findpeaks(method='topology', imsize=(300, 300), scale=True, togray=True, denoise=getfilter,
params={'window': window}, verbose=verbose)
img = fp.import_example('2dpeaks_image')
results = fp.fit(img)
title = 'Method=' + str(getfilter) + ', window='+str(window)
Expand All @@ -516,7 +508,8 @@
for getfilter in filters:
for window in windows:
for cu in cus:
fp = findpeaks(method='topology', scale=True, denoise=getfilter, params={'window': window, 'cu': cu}, togray=True, imsize=(300,300), verbose=verbose)
fp = findpeaks(method='topology', imsize=(300, 300), scale=True, togray=True, denoise=getfilter,
params={'window': window, 'cu': cu}, verbose=verbose)
img = fp.import_example('2dpeaks_image')
results = fp.fit(img)
title = 'Method=' + str(getfilter) + ', window='+str(window) + ', cu='+str(cu)
Expand Down Expand Up @@ -552,7 +545,7 @@
fp.plot_persistence()

from findpeaks import findpeaks
fp = findpeaks(method='topology', interpolate=10, verbose=3)
fp = findpeaks(method='topology', interpolate=10, verbose=3)
X = fp.import_example('1dpeaks')
fp.fit(X)
fp.plot()
Expand Down Expand Up @@ -585,7 +578,8 @@


# 2dpeaks example with other settings
fp = findpeaks(method='topology', scale=True, denoise='fastnl', params={'window': 31}, togray=True, imsize=(300,300), verbose=3)
fp = findpeaks(method='topology', imsize=(300, 300), scale=True, togray=True, denoise='fastnl', params={'window': 31},
verbose=3)
img = fp.import_example('2dpeaks')
fp.fit(img)
fp.plot()
Expand Down Expand Up @@ -691,7 +685,7 @@


from findpeaks import findpeaks
fp = findpeaks(method='topology', scale=False, denoise='fastnl', togray=True, imsize=False, verbose=3)
fp = findpeaks(method='topology', imsize=False, scale=False, togray=True, denoise='fastnl', verbose=3)
fp.fit(img)
fp.plot_persistence()
fp.plot_mesh(wireframe=False, title='image_lee_enhanced', view=(30,30))
Expand Down
Loading

0 comments on commit df6a809

Please sign in to comment.