master
michael 2021-07-16 09:19:00 -07:00
parent 0e4423209e
commit 9a926dafb2
9 changed files with 1105 additions and 313 deletions

1
.gitignore vendored
View File

@ -139,3 +139,4 @@ cython_debug/
# Local stuff to exclude
.vscode/
mainwin.py

104
app.py
View File

@ -1,14 +1,112 @@
import sys
from PyQt5 import QtGui, QtWidgets, uic
import crds_calc
from pandas import read_csv
from PyQt5 import QtGui, QtWidgets, QtCore
from memdb import mem
from mainwin import Ui_MainWindow
from widgets import BaseGraph
import pathlib
class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
csv_selected = QtCore.pyqtSignal()
correlation_complete = QtCore.pyqtSignal()
fitting_complete = QtCore.pyqtSignal()
class AppWindow(QtWidgets.QMainWindow):
def __init__(self):
super(AppWindow, self).__init__()
uic.loadUi('app.ui', self)
self.setupUi(self)
# Signals
# Graphing actions
self.csv_selected.connect(self.raw_data_graph.plot)
def corr_act():
self.groups_graph.plot()
self.graph_tabs.setCurrentIndex(1)
self.correlation_complete.connect(corr_act)
# Helpers
def display_warning(message: str):
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Warning)
msg.setText("Warning")
msg.setInformativeText(message)
msg.setWindowTitle("Warning")
msg.exec_()
def display_error(message: str):
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText("Error")
msg.setInformativeText(message)
msg.setWindowTitle("Error")
msg.exec_()
def select_csv():
filename, _ = QtWidgets.QFileDialog.getOpenFileName(self)
data = None
try:
data = read_csv(filename, comment="%", delimiter=";").to_numpy()
except:
return
mem['x_data'] = data.transpose()[0]
mem['y_data'] = data.transpose()[1]
try:
mem['v_data'] = data.transpose()[2]
except IndexError:
display_warning('No voltage column detected. VThreshold algo will not work.')
self.csv_selected.emit()
# Universal Actions stuff
self.actionOpen_CSV_File.triggered.connect(select_csv)
self.actionGithub_Repository.triggered.connect(lambda: QtGui.QDesktopServices.openUrl(QtCore.QUrl('https://github.com/turtlebasket/crds_analyze')))
# Inputs
def init_correlate():
groups_raw = None
algo = self.combo_grouping_algo.currentIndex()
try:
if algo == 0:
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()
)
mem['groups_correlated'] = crds_calc.correlate_groups(groups_raw)
self.correlation_complete.emit()
except KeyError:
display_error('Failed to correlate. Did you import a data file & set parameters?')
self.correlate_button.pressed.connect(init_correlate)
# Show equation
pix = QtGui.QPixmap(f"{pathlib.Path(__file__).parent.resolve()}/assets/eq3.png")
item = QtWidgets.QGraphicsPixmapItem(pix)
item.setScale(0.38)
scene = QtWidgets.QGraphicsScene()
scene.addItem(item)
self.equation_view.setScene(scene)
# Show self
self.show()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = AppWindow()
window.show()
sys.exit(app.exec_())

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1091</width>
<height>580</height>
<height>611</height>
</rect>
</property>
<property name="windowTitle">
@ -84,9 +84,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<y>120</y>
<width>241</width>
<height>141</height>
<height>111</height>
</rect>
</property>
<property name="font">
@ -103,9 +103,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<y>50</y>
<width>221</width>
<height>111</height>
<height>31</height>
</rect>
</property>
<property name="currentIndex">
@ -118,7 +118,7 @@
<x>0</x>
<y>0</y>
<width>221</width>
<height>71</height>
<height>21</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_4">
@ -148,8 +148,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>221</width>
<height>103</height>
<width>211</width>
<height>21</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -170,64 +170,52 @@
</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="spin_min_peakheight" 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="spin_min_peakprominence" 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="spin_moving_average_denom" name="spin_moving_average_denom">
<property name="value">
<number>20</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="combo_grouping_algo" name="comboBox">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>221</width>
<height>19</height>
</rect>
</property>
<item>
<property name="text">
<string>VThreshold (Voltage column required)</string>
</property>
</item>
<item>
<property name="text">
<string>SpacedGroups</string>
</property>
</item>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Every other group (MIRRORED)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="correlate_button" name="compute_button">
<property name="geometry">
<rect>
<x>60</x>
<y>220</y>
<y>250</y>
<width>151</width>
<height>28</height>
</rect>
@ -248,9 +236,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>320</y>
<y>350</y>
<width>241</width>
<height>171</height>
<height>181</height>
</rect>
</property>
<property name="font">
@ -267,9 +255,9 @@
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<y>90</y>
<width>221</width>
<height>89</height>
<height>81</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_3">
@ -323,7 +311,7 @@
<x>10</x>
<y>20</y>
<width>221</width>
<height>51</height>
<height>61</height>
</rect>
</property>
</widget>
@ -332,7 +320,7 @@
<property name="geometry">
<rect>
<x>60</x>
<y>500</y>
<y>540</y>
<width>151</width>
<height>28</height>
</rect>
@ -349,51 +337,11 @@
<string>Fit</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>241</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Grouping Algorithm</string>
</property>
<widget class="combo_grouping_algo" name="comboBox">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>221</width>
<height>21</height>
</rect>
</property>
<item>
<property name="text">
<string>VThreshold (V column required)</string>
</property>
</item>
<item>
<property name="text">
<string>SpacedGroups</string>
</property>
</item>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>10</x>
<y>260</y>
<y>290</y>
<width>241</width>
<height>51</height>
</rect>
@ -406,7 +354,7 @@
</font>
</property>
<property name="title">
<string>Peak Isolation Config</string>
<string>Peak Isolation Config (timescale: ticks)</string>
</property>
<property name="checkable">
<bool>false</bool>
@ -424,15 +372,101 @@
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Individual Peak Range</string>
<string>Overlapped Peak Range</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_4">
<widget class="QSpinBox" name="spinBox_4">
<property name="maximum">
<number>100000</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
<property name="value">
<number>5000</number>
</property>
</widget>
</item>
</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>74</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="spin_min_peakheight" 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="spin_min_peakprominence" 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="spin_moving_average_denom" name="spin_moving_average_denom">
<property name="value">
<number>20</number>
</property>
</widget>
</item>
</layout>
@ -445,7 +479,7 @@
<x>0</x>
<y>0</y>
<width>1091</width>
<height>26</height>
<height>21</height>
</rect>
</property>
<widget class="file_menu" name="menuFile">

235
archive/widgets.py Normal file
View File

@ -0,0 +1,235 @@
import numpy as np
from pandas import read_csv
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import crds_calc
import PyQt5
from PyQt5 import QtWidgets, QtCore
from memdb import mem
import pathlib
# Helper functions
class Global(QtWidgets.QWidget):
csv_selected = QtCore.pyqtSignal()
correlation_complete = QtCore.pyqtSignal()
fitting_complete = QtCore.pyqtSignal()
globj = Global()
def display_warning(message: str):
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.warning)
msg.setText("Warning")
msg.setInformativeText(message)
msg.setWindowTitle("Warning")
msg.exec_()
def display_error(message: str):
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText("Error")
msg.setInformativeText(message)
msg.setWindowTitle("Error")
msg.exec_()
# Menu definitions
class file_menu(QtWidgets.QMenu):
def __init__(self, x):
super().__init__(x)
open_csv = QtWidgets.QAction("Open CSV File", self)
open_csv.setShortcut("Ctrl+O")
open_csv.triggered.connect(self.select_csv)
self.addAction(open_csv)
def select_csv(self):
filename, _ = QtWidgets.QFileDialog.getOpenFileName(self)
data = read_csv(filename, comment="%", delimiter=";").to_numpy()
mem['x_data'] = data.transpose()[0]
mem['y_data'] = data.transpose()[1]
try:
mem['v_data'] = data[2].transpose()
except IndexError:
display_error('No voltage column detected. Functionality will be limited.')
globj.csv_selected.emit()
class help_menu(QtWidgets.QMenu):
def __init__(self, x):
super().__init__(x)
visit_repo = QtWidgets.QAction("Go to GitHub Repo", self)
visit_repo.triggered.connect(self.go_to_repo)
self.addAction(visit_repo)
def go_to_repo(self):
PyQt5.QtGui.QDesktopServices.openUrl(QtCore.QUrl('https://github.com/turtlebasket/crds_analyze'))
# Inputs / Parameter boxes
class combo_grouping_algo(QtWidgets.QComboBox):
def change(self):
mem['grouping_algo'] = self.currentIndex()
globj.grouping_algo_changed.emit()
def __init__(self, x):
super().__init__(x)
self.currentIndexChanged.connect(self.change)
class config_area(QtWidgets.QStackedWidget):
def __init__(self, x):
super().__init__(x)
self.setCurrentIndex(0)
globj.grouping_algo_changed.connect(lambda: self.setCurrentIndex(mem['grouping_algo']))
class spin_min_voltage(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['min_voltage'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['min_voltage'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_group_len(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['group_len'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['group_len'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_peak_len(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['peak_len'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['peak_len'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_min_peakheight(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['peak_minheight'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['peak_minheight'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_min_peakprominence(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['peak_prominence'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['peak_prominence'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_moving_average_denom(QtWidgets.QSpinBox):
def changeVal(self, val):
mem['moving_avg_denom'] = int(val)
print(isinstance(val, str))
def __init__(self, x):
super().__init__(x)
mem['moving_avg_denom'] = float(self.value())
self.textChanged.connect(self.changeVal)
class equation_view(QtWidgets.QGraphicsView):
def __init__(self, x):
super().__init__(x)
pix = PyQt5.QtGui.QPixmap(f"{pathlib.Path(__file__).parent.resolve()}/assets/eq3.png")
item = QtWidgets.QGraphicsPixmapItem(pix)
item.setScale(0.38)
scene = QtWidgets.QGraphicsScene()
scene.addItem(item)
self.setScene(scene)
class correlate_button(QtWidgets.QPushButton):
def calc(self):
groups_raw = None
try:
if (mem['grouping_algo'] == 0):
display_error('VThreshold not yet implemented.')
return
elif (mem['grouping_algo'] == 1):
groups_raw = crds_calc.spaced_groups()
mem['groups_correlated'] = crds_calc.correlate_groups(groups_raw)
globj.correlation_complete.emit()
except KeyError:
display_error('Failed to correlate. Did you import a data file & set parameters?')
def __init__(self, x):
super().__init__(x)
self.pressed.connect(self.calc)
class fit_button(QtWidgets.QPushButton):
def fit(self):
print("hi")
def __init__(self, x):
super().__init__(x)
self.pressed.connect(self.fit)
# Graph stuff
class graph_tab(QtWidgets.QTabWidget):
def __init__(self, x):
super().__init__(x)
globj.csv_selected.connect(lambda: self.setCurrentIndex(0))
globj.correlation_complete.connect(lambda: self.setCurrentIndex(1))
globj.fitting_complete.connect(lambda: self.setCurrentIndex(2))
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
fig.tight_layout()
super(MplCanvas, self).__init__(fig)
class base_graph(QtWidgets.QWidget):
"""
Widget with embedded matplotlib graph & navigation toolbar
Reference: https://www.mfitzp.com/tutorials/plotting-matplotlib/
"""
canv = None
def __init__(self, x):
super().__init__(x)
self.canv = MplCanvas(self)
# Example
# canv.axes.plot([0,1,2,3,4], [10,1,20,3,40])
toolbar = NavigationToolbar(self.canv, self)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(self.canv)
self.setLayout(layout)
def plot(self):
self.canv.axes.plot(mem['x_data'], mem['y_data'])
def plot_full(self):
self.canv.axes.clear()
self.plot()
self.canv.draw()
print("attempted plot")
class rawdata_graph(base_graph):
def __init__(self, x):
super().__init__(x)
globj.csv_selected.connect(self.plot_full)
class peaks_graph(base_graph):
def __init__(self, x):
super().__init__(x)
globj.correlation_complete.connect(self.plot_full)
def plot(self):
for i in mem['groups_correlated']:
self.canv.axes.plot(i)
class timeconstant_graph(base_graph):
pass

BIN
assets/eq3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -1,5 +1,6 @@
import numpy as np
from scipy.signal import find_peaks, correlate
from memdb import mem
def spaced_groups(
x_data: np.array,
@ -109,4 +110,21 @@ def correlate_groups(groups_raw):
groups_adjusted.append(x)
return groups_adjusted
return groups_adjusted
def isolate_peaks(
peak_width: int,
groups_adjusted: list,
peak_minheight: int,
peak_prominence: int,
sma_denom: int
):
def moving_average(x, w):
return np.convolve(x, np.ones(w), 'valid') / w
group_peaks = []
for g in groups_adjusted:
y_data_av = moving_average(g, sma_denom)
peak_indices = find_peaks(y_data_av, height=peak_minheight, prominence=peak_prominence) # Get indices of all peaks
group_peaks.append(peak_indices)

5
requirements.txt Normal file
View File

@ -0,0 +1,5 @@
PyQt5
pandas
numpy
pyinstaller==4.4
sqlitedict

591
ui/mainwin.ui Normal file
View File

@ -0,0 +1,591 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1091</width>
<height>611</height>
</rect>
</property>
<property name="windowTitle">
<string>CRDS Scanalyzer</string>
</property>
<property name="styleSheet">
<string notr="true">QGroupBox: {font-style: bold; font-size: 8px }</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="graph_tabs">
<property name="geometry">
<rect>
<x>260</x>
<y>0</y>
<width>821</width>
<height>561</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="raw_data">
<attribute name="title">
<string>Raw Data</string>
</attribute>
<widget class="RawDataGraph" name="raw_data_graph" native="true">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>811</width>
<height>531</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="groups">
<attribute name="title">
<string>Groups</string>
</attribute>
<widget class="PeaksGraph" name="groups_graph" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>651</width>
<height>531</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="time_constant">
<attribute name="title">
<string>Time Constant</string>
</attribute>
<widget class="TimeConstantGraph" name="tau_graph" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>651</width>
<height>531</height>
</rect>
</property>
</widget>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>241</width>
<height>111</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Grouping Config</string>
</property>
<widget class="QStackedWidget" name="stackedWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>221</width>
<height>31</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<widget class="QWidget" name="formLayoutWidget_4">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>221</width>
<height>22</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Minimum voltage out</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spin_min_voltage">
<property name="decimals">
<number>6</number>
</property>
<property name="value">
<double>0.001000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="page_2">
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>211</width>
<height>22</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Estimated pass time</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spin_group_len">
<property name="decimals">
<number>6</number>
</property>
<property name="value">
<double>0.000600000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QComboBox" name="combo_grouping_algo">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>221</width>
<height>19</height>
</rect>
</property>
<item>
<property name="text">
<string>VThreshold (Voltage column required)</string>
</property>
</item>
<item>
<property name="text">
<string>SpacedGroups</string>
</property>
</item>
</widget>
<widget class="QCheckBox" name="check_skip_groups">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>221</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Every other group (MIRRORED)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QPushButton" name="correlate_button">
<property name="geometry">
<rect>
<x>60</x>
<y>240</y>
<width>151</width>
<height>28</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>-1</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">* {font-size: 13px}</string>
</property>
<property name="text">
<string>Correlate</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<width>241</width>
<height>181</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Initial Fit Config</string>
</property>
<widget class="QWidget" name="formLayoutWidget_3">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>221</width>
<height>83</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="2" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>τ value</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_2">
<property name="decimals">
<number>6</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>y0 value</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="decimals">
<number>6</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>a value</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_3">
<property name="decimals">
<number>6</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QGraphicsView" name="equation_view">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>221</width>
<height>61</height>
</rect>
</property>
</widget>
</widget>
<widget class="QPushButton" name="fit_button">
<property name="geometry">
<rect>
<x>60</x>
<y>530</y>
<width>151</width>
<height>28</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>-1</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">* {font-size: 13px}</string>
</property>
<property name="text">
<string>Fit</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>241</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="title">
<string>Peak Isolation Config (timescale: ticks)</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<widget class="QWidget" name="formLayoutWidget_2">
<property name="geometry">
<rect>
<x>9</x>
<y>20</y>
<width>221</width>
<height>25</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Overlapped Peak Range</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spin_peak_overlap">
<property name="maximum">
<number>100000</number>
</property>
<property name="singleStep">
<number>100</number>
</property>
<property name="value">
<number>5000</number>
</property>
</widget>
</item>
</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">
<rect>
<x>0</x>
<y>0</y>
<width>1091</width>
<height>26</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen_CSV_File"/>
<addaction name="actionOpen_MATLAB_File"/>
<addaction name="separator"/>
<addaction name="actionExport_Binary"/>
<addaction name="separator"/>
<addaction name="actionQuit_2"/>
</widget>
<widget class="QMenu" name="menuhelp">
<property name="title">
<string>Help</string>
</property>
<addaction name="actionGithub_Repository"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuhelp"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionOpen_CSV">
<property name="text">
<string>Open CSV File</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>Quit</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>Export</string>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
</action>
<action name="actionGithub_repository">
<property name="text">
<string>GitHub Repo</string>
</property>
</action>
<action name="actionOpen_LabView_Binary">
<property name="text">
<string>Open LabView File</string>
</property>
</action>
<action name="actionOpen_CSV_File">
<property name="text">
<string>Open CSV File</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</action>
<action name="actionQuit_2">
<property name="text">
<string>Quit</string>
</property>
</action>
<action name="actionExport_Binary">
<property name="text">
<string>Export Binary</string>
</property>
</action>
<action name="actionOpen_MATLAB_File">
<property name="text">
<string>Open LabView Data</string>
</property>
</action>
<action name="actionGithub_Repository">
<property name="text">
<string>Github Repository</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>RawDataGraph</class>
<extends>QWidget</extends>
<header>widgets</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PeaksGraph</class>
<extends>QWidget</extends>
<header>widgets</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TimeConstantGraph</class>
<extends>QWidget</extends>
<header>widgets</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,192 +1,9 @@
import numpy as np
from pandas import read_csv
from PyQt5 import QtWidgets
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import crds_calc
import PyQt5
from PyQt5 import QtWidgets, QtCore
from memdb import mem
import pathlib
# Helper functions
def display_warning(message: str):
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.warning)
msg.setText("Warning")
msg.setInformativeText(message)
msg.setWindowTitle("Warning")
msg.exec_()
def display_error(message: str):
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText("Error")
msg.setInformativeText(message)
msg.setWindowTitle("Error")
msg.exec_()
# Create global object to send signals
class Global(QtWidgets.QWidget):
grouping_algo_changed = QtCore.pyqtSignal()
csv_selected = QtCore.pyqtSignal()
correlation_complete = QtCore.pyqtSignal()
fitting_complete = QtCore.pyqtSignal()
globj = Global()
# Menu definitions
class file_menu(QtWidgets.QMenu):
def __init__(self, x):
super().__init__(x)
open_csv = QtWidgets.QAction("Open CSV File", self)
open_csv.setShortcut("Ctrl+O")
open_csv.triggered.connect(self.select_csv)
self.addAction(open_csv)
def select_csv(self):
filename, _ = QtWidgets.QFileDialog.getOpenFileName(self)
data = read_csv(filename, comment="%", delimiter=";").to_numpy()
mem['x_data'] = data.transpose()[0]
mem['y_data'] = data.transpose()[1]
try:
mem['v_data'] = data[2].transpose()
except IndexError:
display_error('No voltage column detected. Functionality will be limited.')
globj.csv_selected.emit()
class help_menu(QtWidgets.QMenu):
def __init__(self, x):
super().__init__(x)
visit_repo = QtWidgets.QAction("Go to GitHub Repo", self)
visit_repo.triggered.connect(self.go_to_repo)
self.addAction(visit_repo)
def go_to_repo(self):
PyQt5.QtGui.QDesktopServices.openUrl(QtCore.QUrl('https://github.com/turtlebasket/crds_analyze'))
# Inputs / Parameter boxes
class combo_grouping_algo(QtWidgets.QComboBox):
def change(self):
mem['grouping_algo'] = self.currentIndex()
globj.grouping_algo_changed.emit()
def __init__(self, x):
super().__init__(x)
self.currentIndexChanged.connect(self.change)
class config_area(QtWidgets.QStackedWidget):
def __init__(self, x):
super().__init__(x)
self.setCurrentIndex(0)
globj.grouping_algo_changed.connect(lambda: self.setCurrentIndex(mem['grouping_algo']))
class spin_min_voltage(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['min_voltage'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['min_voltage'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_group_len(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['group_len'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['group_len'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_peak_len(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['peak_len'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['peak_len'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_min_peakheight(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['peak_minheight'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['peak_minheight'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_min_peakprominence(QtWidgets.QDoubleSpinBox):
def changeVal(self, val):
mem['peak_prominence'] = float(val)
def __init__(self, x):
super().__init__(x)
mem['peak_prominence'] = float(self.value())
self.textChanged.connect(self.changeVal)
class spin_moving_average_denom(QtWidgets.QSpinBox):
def changeVal(self, val):
mem['moving_avg_denom'] = int(val)
print(isinstance(val, str))
def __init__(self, x):
super().__init__(x)
mem['moving_avg_denom'] = float(self.value())
self.textChanged.connect(self.changeVal)
class equation_view(QtWidgets.QGraphicsView):
def __init__(self, x):
super().__init__(x)
pix = PyQt5.QtGui.QPixmap(f"{pathlib.Path(__file__).parent.resolve()}/assets/eq2.png")
item = QtWidgets.QGraphicsPixmapItem(pix)
item.setScale(0.15)
scene = QtWidgets.QGraphicsScene()
scene.addItem(item)
self.setScene(scene)
class correlate_button(QtWidgets.QPushButton):
def calc(self):
groups_raw = None
try:
if (mem['grouping_algo'] == 0):
display_error('VThreshold not yet implemented.')
elif (mem['grouping_algo'] == 1):
groups_raw = crds_calc.spaced_groups(
mem['x_data'],
mem['y_data'],
mem['group_len'],
mem['peak_minheight'],
mem['peak_prominence'],
mem['moving_avg_denom']
)
mem['groups_correlated'] = crds_calc.correlate_groups(groups_raw)
globj.correlation_complete.emit()
except KeyError:
display_error('Failed to correlate. Did you import a data file & set parameters?')
def __init__(self, x):
super().__init__(x)
self.pressed.connect(self.calc)
class fit_button(QtWidgets.QPushButton):
def fit(self):
print("hi")
def __init__(self, x):
super().__init__(x)
self.pressed.connect(self.fit)
# Graph stuff
class graph_tab(QtWidgets.QTabWidget):
def __init__(self, x):
super().__init__(x)
globj.csv_selected.connect(lambda: self.setCurrentIndex(0))
globj.correlation_complete.connect(lambda: self.setCurrentIndex(1))
globj.fitting_complete.connect(lambda: self.setCurrentIndex(2))
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
@ -195,7 +12,7 @@ class MplCanvas(FigureCanvasQTAgg):
fig.tight_layout()
super(MplCanvas, self).__init__(fig)
class base_graph(QtWidgets.QWidget):
class BaseGraph(QtWidgets.QWidget):
"""
Widget with embedded matplotlib graph & navigation toolbar
@ -215,29 +32,22 @@ class base_graph(QtWidgets.QWidget):
layout.addWidget(self.canv)
self.setLayout(layout)
def plot(self):
def plot_data(self):
self.canv.axes.plot(mem['x_data'], mem['y_data'])
def plot_full(self):
def plot(self):
self.canv.axes.clear()
self.plot()
self.plot_data()
self.canv.draw()
print("attempted plot")
class rawdata_graph(base_graph):
def __init__(self, x):
super().__init__(x)
globj.csv_selected.connect(self.plot_full)
class RawDataGraph(BaseGraph):
pass
class peaks_graph(base_graph):
def __init__(self, x):
super().__init__(x)
globj.correlation_complete.connect(self.plot_full)
def plot(self):
class PeaksGraph(BaseGraph):
def plot_data(self):
for i in mem['groups_correlated']:
self.canv.axes.plot(i)
class timeconstant_graph(base_graph):
pass
class TimeConstantGraph(BaseGraph):
pass # no modifications thus far