From 319221be7173ab424a75aa2ed681513cab463b2f Mon Sep 17 00:00:00 2001 From: erdogant Date: Mon, 13 Jan 2025 23:31:26 +0100 Subject: [PATCH] some checks --- findpeaks/__init__.py | 2 +- findpeaks/findpeaks.py | 22 +++++++++++++++++++--- findpeaks/tests/test_findpeaks.py | 7 +++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/findpeaks/__init__.py b/findpeaks/__init__.py index 39ed1c6..5e17baf 100644 --- a/findpeaks/__init__.py +++ b/findpeaks/__init__.py @@ -24,7 +24,7 @@ __author__ = 'Erdogan Tasksen' __email__ = 'erdogant@gmail.com' -__version__ = '2.6.5' +__version__ = '2.6.6' # module level doc-string __doc__ = """ diff --git a/findpeaks/findpeaks.py b/findpeaks/findpeaks.py index 71a3755..7f006a2 100644 --- a/findpeaks/findpeaks.py +++ b/findpeaks/findpeaks.py @@ -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 @@ -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'] @@ -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 @@ -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'] @@ -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 @@ -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 @@ -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 diff --git a/findpeaks/tests/test_findpeaks.py b/findpeaks/tests/test_findpeaks.py index cfe23ed..391721f 100644 --- a/findpeaks/tests/test_findpeaks.py +++ b/findpeaks/tests/test_findpeaks.py @@ -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] @@ -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 @@ -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')