Skip to content

Commit

Permalink
some checks
Browse files Browse the repository at this point in the history
  • Loading branch information
erdogant committed Jan 13, 2025
1 parent 41f0473 commit 319221b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion findpeaks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

__author__ = 'Erdogan Tasksen'
__email__ = 'erdogant@gmail.com'
__version__ = '2.6.5'
__version__ = '2.6.6'

# module level doc-string
__doc__ = """
Expand Down
22 changes: 19 additions & 3 deletions findpeaks/findpeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ def _store1d(self, X, Xraw, xs, result):
dfint['valley'] = False
dfint['peak'] = False
if result['peakdetect']['min_peaks_s'] is not None:
dfint.loc[result['peakdetect']['min_peaks_s'][:, 0].astype(int), 'peak'] = True
# dfint['valley'].iloc[result['peakdetect']['min_peaks_s'][:, 0].astype(int)] = True
dfint.loc[result['peakdetect']['min_peaks_s'][:, 0].astype(int), 'valley'] = True
if result['peakdetect']['max_peaks_s'] is not None:
# dfint['peak'].iloc[result['peakdetect']['max_peaks_s'][:, 0].astype(int)] = True
dfint.loc[result['peakdetect']['max_peaks_s'][:, 0].astype(int), 'peak'] = True
elif self.method == 'topology':
# Topology
Expand All @@ -392,9 +394,11 @@ def _store1d(self, X, Xraw, xs, result):
dfint['peak'] = False

if result['topology']['min_peaks_s'] is not None:
# dfint['valley'].iloc[result['topology']['min_peaks_s'][:, 0].astype(int)] = True
dfint.loc[result['topology']['min_peaks_s'][:, 0].astype(int), 'valley'] = True
if result['topology']['max_peaks_s'] is not None:
dfint.loc[result['topology']['max_peaks_s'][:, 0].astype(int), 'peak'] = True
# dfint['peak'].iloc[result['topology']['max_peaks_s'][:, 0].astype(int)] = True

results['persistence'] = result['persistence']
results['Xdetect'] = result['Xdetect']
Expand All @@ -418,6 +422,7 @@ def _store1d(self, X, Xraw, xs, result):
if self.interpolate is not None:
df = pd.DataFrame()
df['y'] = Xraw

# Store results for method
if self.method == 'peakdetect':
# peakdetect
Expand All @@ -427,8 +432,11 @@ def _store1d(self, X, Xraw, xs, result):
df['peak'] = False
if result['peakdetect']['min_peaks'] is not None:
df.loc[result['peakdetect']['min_peaks'][:, 0].astype(int), 'valley'] = True
# df['valley'].iloc[result['peakdetect']['min_peaks'][:, 0].astype(int)] = True
if result['peakdetect']['max_peaks'] is not None:
df.loc[result['peakdetect']['max_peaks'][:, 0].astype(int), 'peak'] = True
# df['peak'].iloc[result['peakdetect']['max_peaks'][:, 0].astype(int)] = True

elif self.method == 'topology':
# Topology
df['x'] = result['topology']['xs']
Expand All @@ -437,7 +445,9 @@ def _store1d(self, X, Xraw, xs, result):
df['peak'] = False
if result['topology']['min_peaks'] is not None:
df.loc[result['topology']['min_peaks'][:, 0].astype(int), 'valley'] = True
# df['valley'].iloc[result['topology']['min_peaks'][:, 0].astype(int)] = True
if result['topology']['max_peaks'] is not None:
# df['peak'].iloc[result['topology']['max_peaks'][:, 0].astype(int)] = True
df.loc[result['topology']['max_peaks'][:, 0].astype(int), 'peak'] = True

# Store the score and ranking
Expand All @@ -448,6 +458,10 @@ def _store1d(self, X, Xraw, xs, result):
result['topology']['max_peaks_s'][:, 0].astype(int), 'rank'].values
df.loc[result['topology']['max_peaks'][:, 0].astype(int), 'score'] = dfint.loc[
result['topology']['max_peaks_s'][:, 0].astype(int), 'score'].values
# df['rank'].iloc[result['topology']['max_peaks'][:, 0].astype(int)] = dfint['rank'].iloc[
# result['topology']['max_peaks_s'][:, 0].astype(int)].values
# df['score'].iloc[result['topology']['max_peaks'][:, 0].astype(int)] = dfint['score'].iloc[
# result['topology']['max_peaks_s'][:, 0].astype(int)].values

# df['rank'].loc[df['peak']] = dfint['rank'].loc[dfint['peak']].values
# df['score'].loc[df['peak']] = dfint['score'].loc[dfint['peak']].values
Expand All @@ -458,9 +472,11 @@ def _store1d(self, X, Xraw, xs, result):
df['valley'] = False
df['peak'] = False
if result['caerus']['min_peaks'] is not None:
df.loc[result['caerus']['min_peaks'][:, 0].astype(int), 'valley'] = True
df['valley'].iloc[result['caerus']['min_peaks'][:, 0].astype(int)] = True
# df.loc[result['caerus']['min_peaks'][:, 0].astype(int), 'valley'] = True
if result['caerus']['max_peaks'] is not None:
df.loc[result['caerus']['max_peaks'][:, 0].astype(int), 'peak'] = True
df['peak'].iloc[result['caerus']['max_peaks'][:, 0].astype(int)] = True
# df.loc[result['caerus']['max_peaks'][:, 0].astype(int), 'peak'] = True

# Store in results
results['df'] = df
Expand Down
7 changes: 3 additions & 4 deletions findpeaks/tests/test_findpeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_fit(self):
# CHECK RESULTS METHOD TOPOLOGY
assert results['df']['peak'].sum() == 2
assert results['df']['valley'].sum() == 4
fp.plot()

# Run over all combinations and make sure no errors are made
X = [10, 11, 9, 23, 21, 11, 45, 20, 11, 12]
Expand Down Expand Up @@ -168,8 +169,7 @@ def test_denoising(self):
# lee filter
image_lee = findpeaks.stats.lee_filter(img.copy(), win_size=winsize, cu=cu_value)
# lee enhanced filter
image_lee_enhanced = findpeaks.stats.lee_enhanced_filter(img.copy(), win_size=winsize, k=k_value2,
cu=cu_lee_enhanced, cmax=cmax_value)
image_lee_enhanced = findpeaks.stats.lee_enhanced_filter(img.copy(), win_size=winsize, k=k_value2, cu=cu_lee_enhanced, cmax=cmax_value)
# lee sigma filter
image_lee_sigma = findpeaks.stats.lee_sigma_filter(img.copy())
# mean filter
Expand All @@ -188,8 +188,7 @@ def test_denoising(self):
for getfilter in filters:
for window in windows:
for cu in cus:
fp = findpeaks(method='topology', imsize=None, scale=True, togray=True, denoise=getfilter,
params={'window': window, 'cu': cu}, verbose=3)
fp = findpeaks(method='topology', imsize=None, scale=True, togray=True, denoise=getfilter, params={'window': window, 'cu': cu}, verbose=3)
assert fp.fit(img)
# assert fp.plot_mesh(wireframe=False)
# plt.close('all')
Expand Down

0 comments on commit 319221b

Please sign in to comment.