Skip to content

Commit

Permalink
fix ridge threshold batch processing
Browse files Browse the repository at this point in the history
  • Loading branch information
gregor committed Aug 13, 2020
1 parent 008efaa commit 4a92131
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#### Version 0.8.17

- Fixed crashes during batch analysis with thresholded ridges
- Warning and on-the-fly interpolation of non-contiguous missing values (NaNs)

#### Version 0.8.16
Expand Down
13 changes: 9 additions & 4 deletions pyboat/ensemble_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,29 @@ def average_power_distribution(ridge_results, signal_ids = None, exclude_coi = F
'''

powers = []
ids = []

if signal_ids is None:
signal_ids = np.arange( len(ridge_results) )

assert len(signal_ids) == len(ridge_results)

# collect the time-averaged powers
for rd in ridge_results:
for rd,_id in zip(ridge_results, signal_ids):

if exclude_coi:
# take only ridge power outside of COI
i_left, i_right = find_COI_crossing(rd)
mpower= (rd.power[i_left : i_right]).mean()
mpower= (rd.power[i_left : i_right]).mean()
else:
mpower= rd.power.mean()
powers.append( mpower )

# can happen if ridge exclusively inside COI
if not np.isnan(mpower):
powers.append( mpower )
ids.append(_id)

powers_series = pd.Series(index = signal_ids, data = powers)
powers_series = pd.Series(index = ids, data = powers)

# sort by power, descending
powers_series.sort_values(
Expand Down
31 changes: 25 additions & 6 deletions pyboat/ui/batch_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,20 @@ def run_batch(self):
# for each signal and the signal_id as key
ridge_results = self.do_the_loop()

# check for empty ridge_results
if not ridge_results:
self.NoResults = MessageWindow('All ridges below threshold.. no results!','No results')
return



# compute the time-averaged powers
if self.cb_power_dis.isChecked() or self.cb_sorted_powers.isChecked():

powers_series = em.average_power_distribution(ridge_results.values(),
ridge_results.keys(),
exclude_coi = True)

print(powers_series)
# sort by power, descending
powers_series.sort_values(
ascending = False,
Expand Down Expand Up @@ -357,6 +363,8 @@ def do_the_loop(self):
'''

EmptyRidge = 0

if self.export_options.isChecked():
OutPath = self.get_OutPath()
if OutPath is None:
Expand Down Expand Up @@ -415,8 +423,12 @@ def do_the_loop(self):
tvec,
power_thresh,
smoothing_wsize = rsmooth)
ridge_results[signal_id] = (ridge_data)


if ridge_data.empty:
EmptyRidge += 1
else:
ridge_results[signal_id] = ridge_data

# -- Save out individual results --

if self.cb_specs.isChecked():
Expand All @@ -435,22 +447,29 @@ def do_the_loop(self):
plt.savefig(fname)
plt.close()

if self.cb_readout_plots.isChecked():
if self.cb_readout_plots.isChecked() and not ridge_data.empty:

pl.plot_readout(ridge_data)
fname = f'{OutPath}/{signal_id}_readout.png'
if self.debug:
print(f'Plotting and saving {signal_id} to {fname}')
plt.savefig(fname)
plt.close()

if self.cb_readout.isChecked():
if self.cb_readout.isChecked() and not ridge_data.empty:

fname = f'{OutPath}/{signal_id}_readout.csv'
if self.debug:
print(f'Saving ridge reatout to {fname}')
ridge_data.to_csv(fname, sep = ',', float_format = '%.3f', index = False)

self.progress.setValue(i)


if EmptyRidge > 0:
self.NoRidges = MessageWindow(
f'{EmptyRidge} ridge readouts entirely below threshold..',
'Discarded ridges')

return ridge_results


Expand Down

0 comments on commit 4a92131

Please sign in to comment.