custom start & end + small math fixes

master
michael 2021-07-23 11:03:43 -07:00
parent 8f4f868c85
commit 22b7fe7333
4 changed files with 222 additions and 117 deletions

34
app.py
View File

@ -17,8 +17,6 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
super(AppWindow, self).__init__()
self.setupUi(self)
# Signals
# Graphing actions
self.csv_selected.connect(self.raw_data_graph.plot)
@ -58,6 +56,10 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
mem['v_data'] = data.transpose()[2]
except IndexError:
display_warning('No voltage column detected. VThreshold algo will not work.')
self.groups_graph.clear()
self.tau_graph.clear()
self.graph_tabs.setCurrentIndex(0)
self.csv_selected.emit()
@ -68,6 +70,26 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# Inputs
def switch_grouping_algo():
algo = self.combo_grouping_algo.currentIndex()
self.grouping_config_area.setCurrentIndex(algo)
self.combo_grouping_algo.currentIndexChanged.connect(switch_grouping_algo)
def set_start_time():
if self.check_custom_start.isChecked():
self.spin_start_time.setDisabled(False)
else:
self.spin_start_time.setDisabled(True)
self.check_custom_start.stateChanged.connect(set_start_time)
def set_end_time():
if self.check_custom_end.isChecked():
self.spin_end_time.setDisabled(False)
else:
# mem['end_time'] = self.spin_end_time.value()
self.spin_end_time.setDisabled(True)
self.check_custom_end.stateChanged.connect(set_end_time)
def init_correlate():
groups_raw = None
algo = self.combo_grouping_algo.currentIndex()
@ -76,14 +98,20 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
display_error('VThreshold not yet implemented.')
return
elif algo == 1:
try:
groups_raw = crds_calc.spaced_groups(
mem['x_data'],
mem['y_data'],
self.spin_group_len.value(),
self.spin_min_peakheight.value(),
self.spin_min_peakprominence.value(),
self.spin_moving_average_denom.value()
self.spin_moving_average_denom.value(),
mirrored=False if self.check_skip_groups.checkState() == 0 else True,
start=self.spin_start_time.value() if self.check_custom_start.isChecked() else None,
end=self.spin_end_time.value() if self.check_custom_end.isChecked() else None
)
except (ValueError, TypeError):
display_error('Failed to correlate. This could be because no groups are being detected.')
mem['groups_correlated'] = crds_calc.correlate_groups(groups_raw)
self.correlation_complete.emit()

View File

@ -8,7 +8,10 @@ def spaced_groups(
group_len: float,
peak_minheight: float,
peak_prominence: float,
sma_denom: int
sma_denom: int,
mirrored: bool=True,
start=None,
end=None
):
"""
Use SpacedGroups algo to separate groups
@ -32,7 +35,21 @@ def spaced_groups(
def isolate_group(i):
i_min = i - t2i_range(group_len)
i_max = i + t2i_range(group_len)
return y_data.tolist()[i_min:i_max]
# NOTE: Groups that are too short just get left out. Too bad!
group = y_data.tolist()[i_min:i_max]
return group
# Check if custom start & end values are set
if not end == None:
stop_ind = t2i(end)
x_data = x_data[:stop_ind]
y_data = y_data[:stop_ind]
if not start == None:
start_ind = t2i(start)
x_data = x_data[start_ind:]
y_data = y_data[start_ind:]
# Detect peaks w/ averaged data
x_data_av = np.delete(x_data, [range(int(sma_denom / 2))])
@ -51,10 +68,8 @@ def spaced_groups(
for i in range(len(peaks)):
item = peaks[i]
next_item = 0
prev_item = item-10
try:
next_item = peaks[i+1]
prev_item = peaks[i-1]
except:
pass
@ -75,15 +90,23 @@ def spaced_groups(
# Isolate group data
groups_raw = [] # NOTE: Only contains every other group
groups_raw = []
for p in peaks_init:
if mirrored:
if peaks_init.index(p) % 2 == 0:
groups_raw.append(isolate_group(t2i(p)))
else:
pass
else:
groups_raw.append(isolate_group(t2i(p)))
for i in groups_raw:
if len(i) == 0:
groups_raw.remove(i)
return groups_raw
def correlate_groups(groups_raw):
"""
Overlay groups using `scipy.correlate`.
@ -95,7 +118,7 @@ def correlate_groups(groups_raw):
group_base = np.array(groups_raw[0])
groups_adjusted = [group_base]
for x in groups_raw[1:len(groups_raw)-1]:
for x in groups_raw[1:]:
# calculate how much to shift
corr = correlate(group_base, np.array(x))
shift = corr.tolist().index(max(corr))

View File

@ -58,7 +58,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>651</width>
<width>811</width>
<height>531</height>
</rect>
</property>
@ -73,20 +73,50 @@
<rect>
<x>0</x>
<y>0</y>
<width>651</width>
<width>601</width>
<height>531</height>
</rect>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>600</x>
<y>10</y>
<width>211</width>
<height>161</height>
</rect>
</property>
<property name="title">
<string>Time constant output</string>
</property>
<widget class="QTextBrowser" name="tau_output">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>191</width>
<height>131</height>
</rect>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</widget>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<y>10</y>
<width>241</width>
<height>111</height>
<height>231</height>
</rect>
</property>
<property name="font">
@ -99,13 +129,13 @@
<property name="title">
<string>Grouping Config</string>
</property>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QStackedWidget" name="grouping_config_area">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>221</width>
<height>31</height>
<height>91</height>
</rect>
</property>
<property name="currentIndex">
@ -118,7 +148,7 @@
<x>0</x>
<y>0</y>
<width>221</width>
<height>22</height>
<height>91</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_4">
@ -148,8 +178,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>211</width>
<height>22</height>
<width>221</width>
<height>103</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -170,6 +200,54 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Min peak height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spin_min_peakheight">
<property name="decimals">
<number>6</number>
</property>
<property name="value">
<double>0.000400000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Min peak prominence</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spin_min_peakprominence">
<property name="decimals">
<number>6</number>
</property>
<property name="value">
<double>0.001200000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Moving average size</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spin_moving_average_denom">
<property name="value">
<number>20</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -198,7 +276,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<y>200</y>
<width>221</width>
<height>20</height>
</rect>
@ -210,12 +288,64 @@
<bool>true</bool>
</property>
</widget>
<widget class="QWidget" name="formLayoutWidget_5">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>233</width>
<height>51</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="check_custom_start">
<property name="text">
<string>Custom Start Time</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spin_start_time">
<property name="enabled">
<bool>false</bool>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-99.989999999999995</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="check_custom_end">
<property name="text">
<string>Custom End Time</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spin_end_time">
<property name="enabled">
<bool>false</bool>
</property>
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-99.989999999999995</double>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QPushButton" name="correlate_button">
<property name="geometry">
<rect>
<x>60</x>
<y>240</y>
<x>50</x>
<y>250</y>
<width>151</width>
<height>28</height>
</rect>
@ -236,7 +366,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<y>350</y>
<width>241</width>
<height>181</height>
</rect>
@ -320,7 +450,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>530</y>
<y>540</y>
<width>151</width>
<height>28</height>
</rect>
@ -341,7 +471,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<y>290</y>
<width>241</width>
<height>51</height>
</rect>
@ -392,86 +522,6 @@
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_5">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>241</width>
<height>101</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Peak Detection Config</string>
</property>
<widget class="QWidget" name="formLayoutWidget_5">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>221</width>
<height>76</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Min peak height</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spin_min_peakheight">
<property name="decimals">
<number>6</number>
</property>
<property name="value">
<double>0.000400000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Min peak prominence</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spin_min_peakprominence">
<property name="decimals">
<number>6</number>
</property>
<property name="value">
<double>0.001200000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Moving average size</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spin_moving_average_denom">
<property name="value">
<number>20</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
@ -479,7 +529,7 @@
<x>0</x>
<y>0</y>
<width>1091</width>
<height>26</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View File

@ -41,6 +41,10 @@ class BaseGraph(QtWidgets.QWidget):
self.canv.draw()
print("attempted plot")
def clear(self):
self.canv.axes.clear()
self.canv.draw()
class RawDataGraph(BaseGraph):
pass