Skip to content

Commit

Permalink
some fixes because column names were mistakenly changed
Browse files Browse the repository at this point in the history
  • Loading branch information
erdogant committed Jan 13, 2025
1 parent 51dd666 commit fbaf233
Showing 1 changed file with 16 additions and 39 deletions.
55 changes: 16 additions & 39 deletions findpeaks/findpeaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,28 +380,21 @@ def _store1d(self, X, Xraw, xs, result):
dfint['valley'] = False
dfint['peak'] = False
if result['peakdetect']['min_peaks_s'] is not None:
dfint.iloc[
result["topology"]["min_peaks_s"][:, 0].astype(int),
dfint.columns.get_loc("valley")] = True
dfint.loc[result['peakdetect']['min_peaks_s'][:, 0].astype(int), 'peak'] = True
if result['peakdetect']['max_peaks_s'] is not None:
dfint.iloc[
result["topology"]["max_peaks_s"][:, 0].astype(int),
dfint.columns.get_loc("peak")] = True
dfint.loc[result['peakdetect']['max_peaks_s'][:, 0].astype(int), 'peak'] = True
elif self.method == 'topology':
# Topology
dfint['labx'] = result['topology']['labx_s']
dfint['rank'] = result['Xranked']
dfint['score'] = result['Xdetect']
dfint['valley'] = False
dfint['peak'] = False

if result['topology']['min_peaks_s'] is not None:
df.iloc[
result["topology"]["min_peaks"][:, 0].astype(int),
df.columns.get_loc("valley")] = True
dfint.loc[result['topology']['min_peaks_s'][:, 0].astype(int), 'valley'] = True
if result['topology']['max_peaks_s'] is not None:
df.iloc[
result["topology"]["max_peaks"][:, 0].astype(int),
df.columns.get_loc("peak")] = True
dfint.loc[result['topology']['max_peaks_s'][:, 0].astype(int), 'peak'] = True

results['persistence'] = result['persistence']
results['Xdetect'] = result['Xdetect']
Expand Down Expand Up @@ -433,43 +426,29 @@ def _store1d(self, X, Xraw, xs, result):
df['valley'] = False
df['peak'] = False
if result['peakdetect']['min_peaks'] is not None:

df.iloc[
result['peakdetect']['min_peaks'][:, 0].astype(int),
df.columns.get_loc('valley')] = True
df.loc[result['peakdetect']['min_peaks'][:, 0].astype(int), 'valley'] = True
if result['peakdetect']['max_peaks'] is not None:
df.iloc[
result['peakdetect']['max_peaks'][:, 0].astype(int),
df.columns.get_loc('peak')] = True
df.loc[result['peakdetect']['max_peaks'][:, 0].astype(int), 'peak'] = True
elif self.method == 'topology':
# Topology
df['x'] = result['topology']['xs']
df['labx'] = result['topology']['labx']
df['valley'] = False
df['peak'] = False
if result['topology']['min_peaks'] is not None:
df.iloc[result['topology']['min_peaks'][:, 0].astype(int),
df.columns.get_loc('valley')] = True
df.loc[result['topology']['min_peaks'][:, 0].astype(int), 'valley'] = True
if result['topology']['max_peaks'] is not None:
df.iloc[result['topology']['max_peaks'][:, 0].astype(int),
df.columns.get_loc('peak')] = True
df.loc[result['topology']['max_peaks'][:, 0].astype(int), 'peak'] = True

# Store the score and ranking
df['rank'] = 0
df['score'] = 0

df.iloc[
result['topology']['max_peaks'][:, 0].astype(int), df.columns.get_loc('rank')
] = dfint.iloc[
result['topology']['max_peaks_s'][:, 0].astype(int),
dfint.columns.get_loc('rank'),
].values
df.iloc[
result['topology']['max_peaks'][:, 0].astype(int), df.columns.get_loc('score')
] = dfint.iloc[
result['topology']['max_peaks_s'][:, 0].astype(int),
dfint.columns.get_loc('score'),
].values
df.loc[result['topology']['max_peaks'][:, 0].astype(int), 'rank'] = dfint.loc[
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'].loc[df['peak']] = dfint['rank'].loc[dfint['peak']].values
# df['score'].loc[df['peak']] = dfint['score'].loc[dfint['peak']].values
if self.method == 'caerus':
Expand All @@ -479,11 +458,9 @@ def _store1d(self, X, Xraw, xs, result):
df['valley'] = False
df['peak'] = False
if result['caerus']['min_peaks'] is not None:
df.iloc[result['caerus']['min_peaks'][:, 0].astype(int),
df.columns.get_loc('peak')] = True
df.loc[result['caerus']['min_peaks'][:, 0].astype(int), 'valley'] = True
if result['caerus']['max_peaks'] is not None:
df.iloc[result['caerus']['max_peaks'][:, 0].astype(int),
df.columns.get_loc('peak')] = True
df.loc[result['caerus']['max_peaks'][:, 0].astype(int), 'peak'] = True

# Store in results
results['df'] = df
Expand Down

0 comments on commit fbaf233

Please sign in to comment.