Commit 4a921319 authored by Gregor Moenke's avatar Gregor Moenke

fix ridge threshold batch processing

parent 008efaa6
#### 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
......
......@@ -38,6 +38,7 @@ 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) )
......@@ -45,17 +46,21 @@ def average_power_distribution(ridge_results, signal_ids = None, exclude_coi = F
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(
......
......@@ -202,6 +202,13 @@ class BatchProcessWindow(QWidget):
# 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():
......@@ -209,7 +216,6 @@ class BatchProcessWindow(QWidget):
ridge_results.keys(),
exclude_coi = True)
print(powers_series)
# sort by power, descending
powers_series.sort_values(
ascending = False,
......@@ -357,6 +363,8 @@ class BatchProcessWindow(QWidget):
'''
EmptyRidge = 0
if self.export_options.isChecked():
OutPath = self.get_OutPath()
if OutPath is None:
......@@ -415,8 +423,12 @@ class BatchProcessWindow(QWidget):
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():
......@@ -435,7 +447,8 @@ class BatchProcessWindow(QWidget):
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:
......@@ -443,14 +456,20 @@ class BatchProcessWindow(QWidget):
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment