diff --git a/.gitignore b/.gitignore
index cb7d96b..1170f07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -139,4 +139,5 @@ cython_debug/
# Local stuff to exclude
.vscode/
-mainwin.py
\ No newline at end of file
+mainwin.py
+*.sqlite
\ No newline at end of file
diff --git a/app.py b/app.py
index f4fe8da..8093502 100644
--- a/app.py
+++ b/app.py
@@ -6,6 +6,10 @@ from db import mem
from mainwin import Ui_MainWindow
from widgets import BaseGraph
import pathlib
+from re import search as re_search
+from varname.core import nameof
+from hashlib import md5
+from sqlitedict import SqliteDict
class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@@ -13,6 +17,16 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
super(AppWindow, self).__init__()
self.setupUi(self)
+ # Define syncables
+ synced_value_widgets = []
+ synced_check_widgets = []
+ for wname in vars(self):
+ w = vars(self).get(wname)
+ if re_search(r"^spin\_(.*)$", wname) != None:
+ synced_value_widgets.append(w)
+ elif re_search(r"^check\_(.*)$", wname) != None:
+ synced_check_widgets.append(w)
+
# Helpers
def display_warning(message: str):
@@ -40,9 +54,11 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
return
mem['x_data'] = data.transpose()[0]
mem['y_data'] = data.transpose()[1]
- timestep = mem['x_data'][1] - mem['x_data'][0]
+ # timestep = mem['x_data'][1] - mem['x_data'][0]
+ timestep = (mem['x_data'][-1] - mem['x_data'][0]) / len(mem['x_data'])
mem['timestep'] = timestep
self.spin_timestep.setValue(timestep)
+ print(timestep)
self.raw_data_graph.plot() # Graph new stuff
# self.groups_graph.clear() # Clear old stuff
@@ -61,6 +77,37 @@ class AppWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.voltage.setVisible(False)
self.graph_tabs.setCurrentIndex(0)
+ # Load from persistent storage & bind write actions
+
+ # path_hash = md5(filename.encode('utf-8')).hexdigest()
+
+ # def set_value(name, val):
+ # with SqliteDict(f"./db/{path_hash}.sqlite", autocommit=True) as storage:
+ # print(f"Change {name} to {val}.")
+ # storage[name] = val
+ # print(f"Check: {storage[name]}")
+
+ # with SqliteDict(f"./db/{path_hash}.sqlite", autocommit=True) as storage:
+
+ # for w in synced_value_widgets:
+ # name = w.objectName()
+ # try:
+ # w.setValue(bool(storage[name]))
+ # print(f"Loaded {name}.")
+ # except KeyError:
+ # print(f"Failed to load object {name}.")
+ # pass
+ # w.valueChanged.connect(lambda x: set_value(name, x))
+
+ # for w in synced_check_widgets:
+ # name = w.objectName()
+ # try:
+ # w.setChecked(storage[name])
+ # print(f"Loaded {name}.")
+ # except KeyError:
+ # print(f"Failed to load object {name}.")
+ # pass
+ # w.stateChanged.connect(lambda: set_value(name, w.isChecked()))
# Universal Actions stuff
diff --git a/crds_calc.py b/crds_calc.py
index d9d1298..ba80efb 100644
--- a/crds_calc.py
+++ b/crds_calc.py
@@ -1,7 +1,7 @@
import numpy as np
from scipy.signal import find_peaks, correlate
from scipy.optimize import curve_fit
-from memdb import mem
+from db import mem
def minmax(data):
return np.min(data), np.max(data)
@@ -281,6 +281,7 @@ def fit_peaks(
overlayed_peak_row = []
for peak_data in peaks_cut:
x_data = np.arange(len(peak_data)) # just placeholder indices
+ # x_data = np.arange(0, len(peak_data)*mem['timestep'], mem['timestep'])
if not use_advanced:
peak_index = np.argmax(peak_data, axis=0)
else:
@@ -289,7 +290,6 @@ def fit_peaks(
params_guess = (peak_index+shift_over, a, y0, tau)
x_data_target = x_data[peak_index+shift_over:]
peak_data_target = peak_data[peak_index+shift_over:]
- # popt, pcov = curve_fit(exp_func, x_data_target, peak_data_target, bounds=([-np.inf, 0.0, -np.inf, 0.0], np.inf))
popt, pcov = curve_fit(exp_func, x_data_target, peak_data_target, bounds=([-np.inf, 0.0, -np.inf, 0.0], np.inf), p0=params_guess, maxfev=10000000)
equation_row.append({'popt': popt, 'pcov': pcov})
overlayed_peak_row.append(peak_index)
@@ -300,9 +300,9 @@ def fit_peaks(
return equations # list linked with isolated_peaks
-def get_tau_data(equation_data):
+def get_time_constants(equation_data):
"""
- Extracts time constant from all equations (2d array)
+ Extracts time constant from all fit-output equations (2d array)
Returns
-------
@@ -316,6 +316,8 @@ def get_tau_data(equation_data):
for e in r:
tau = e['popt'][3]
row.append(tau)
- equation_data.append(row)
+ tau_data.append(row)
+
+ print(tau_data)
return tau_data
diff --git a/db/.gitkeep b/db/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/requirements.txt b/requirements.txt
index dcd7f91..a7c11b9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,6 @@
PyQt5
pandas
+matplotlib
numpy
pyinstaller==4.4
sqlitedict
diff --git a/screenshots/fit_demo.png b/screenshots/fit_demo.png
new file mode 100644
index 0000000..3ace1ba
Binary files /dev/null and b/screenshots/fit_demo.png differ
diff --git a/ui/mainwin.ui b/ui/mainwin.ui
index a73c6da..cb2e33c 100644
--- a/ui/mainwin.ui
+++ b/ui/mainwin.ui
@@ -78,7 +78,7 @@
6
- -99.989999999999995
+ 0.000000000000000
0.010000000000000