diff --git a/app.py b/app.py
index 0394d58..e690a7d 100644
--- a/app.py
+++ b/app.py
@@ -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:
- 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()
- )
+ 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(),
+ 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()
diff --git a/crds_calc.py b/crds_calc.py
index bafcd0f..d269e93 100644
--- a/crds_calc.py
+++ b/crds_calc.py
@@ -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,8 +35,22 @@ 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))])
x_data_av = np.delete(x_data_av, [range(len(x_data)-int((sma_denom / 2) - 1), len(x_data_av))])
@@ -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 peaks_init.index(p) % 2 == 0:
- groups_raw.append(isolate_group(t2i(p)))
+ if mirrored:
+ if peaks_init.index(p) % 2 == 0:
+ groups_raw.append(isolate_group(t2i(p)))
+ else:
+ pass
else:
- pass
-
+ 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))
diff --git a/ui/mainwin.ui b/ui/mainwin.ui
index 65708e3..1f0df04 100644
--- a/ui/mainwin.ui
+++ b/ui/mainwin.ui
@@ -58,7 +58,7 @@
0
0
- 651
+ 811
531
@@ -73,20 +73,50 @@
0
0
- 651
+ 601
531
+
+
+
+ 600
+ 10
+ 211
+ 161
+
+
+
+ Time constant output
+
+
+
+
+ 10
+ 20
+ 191
+ 131
+
+
+
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;">
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html>
+
+
+
10
- 120
+ 10
241
- 111
+ 231
@@ -99,13 +129,13 @@
Grouping Config
-
+
10
50
221
- 31
+ 91
@@ -118,7 +148,7 @@
0
0
221
- 22
+ 91
@@ -148,8 +178,8 @@
0
0
- 211
- 22
+ 221
+ 103
@@ -170,6 +200,54 @@
+ -
+
+
+ Min peak height
+
+
+
+ -
+
+
+ 6
+
+
+ 0.000400000000000
+
+
+
+ -
+
+
+ Min peak prominence
+
+
+
+ -
+
+
+ 6
+
+
+ 0.001200000000000
+
+
+
+ -
+
+
+ Moving average size
+
+
+
+ -
+
+
+ 20
+
+
+
@@ -198,7 +276,7 @@
10
- 80
+ 200
221
20
@@ -210,12 +288,64 @@
true
+
+
+
+ 10
+ 150
+ 233
+ 51
+
+
+
+ -
+
+
+ Custom Start Time
+
+
+
+ -
+
+
+ false
+
+
+ 6
+
+
+ -99.989999999999995
+
+
+
+ -
+
+
+ Custom End Time
+
+
+
+ -
+
+
+ false
+
+
+ 6
+
+
+ -99.989999999999995
+
+
+
+
+
- 60
- 240
+ 50
+ 250
151
28
@@ -236,7 +366,7 @@
10
- 340
+ 350
241
181
@@ -320,7 +450,7 @@
60
- 530
+ 540
151
28
@@ -341,7 +471,7 @@
10
- 280
+ 290
241
51
@@ -392,86 +522,6 @@
-
-
-
- 10
- 10
- 241
- 101
-
-
-
-
- 8
- 75
- true
-
-
-
- Peak Detection Config
-
-
-
-
- 10
- 20
- 221
- 76
-
-
-
- -
-
-
- Min peak height
-
-
-
- -
-
-
- 6
-
-
- 0.000400000000000
-
-
-
- -
-
-
- Min peak prominence
-
-
-
- -
-
-
- 6
-
-
- 0.001200000000000
-
-
-
- -
-
-
- Moving average size
-
-
-
- -
-
-
- 20
-
-
-
-
-
-