work on export

This commit is contained in:
Dominik Demuth 2023-06-19 17:50:36 +02:00
parent 5b146433f3
commit 84d588cf80
5 changed files with 54 additions and 17 deletions

View File

@ -10,10 +10,12 @@ from ..Qt import QtWidgets, QtCore
from .._py.tnmh_dialog import Ui_Dialog from .._py.tnmh_dialog import Ui_Dialog
from ..lib.pg_objects import PlotItem, RegionItem from ..lib.pg_objects import PlotItem, RegionItem
from nmreval.data import DSC from nmreval.data import DSC, Points
class TgCalculator(QtWidgets.QDialog, Ui_Dialog): class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
newTg = QtCore.pyqtSignal(dict, dict, str)
def __init__(self, management, parent=None): def __init__(self, management, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
@ -25,6 +27,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self._plots = {} self._plots = {}
self._tg_value = {} self._tg_value = {}
self._fit = {} self._fit = {}
self._lines = {}
self._hodge = { self._hodge = {
'onset': (PlotItem(x=[], y=[], pen=None, symbol='o', symbolBrush=Tab10.TabBlue.rgb(), name='Onset'), None), 'onset': (PlotItem(x=[], y=[], pen=None, symbol='o', symbolBrush=Tab10.TabBlue.rgb(), name='Onset'), None),
'mid': (PlotItem(x=[], y=[], pen=None, symbol='s', symbolBrush=Tab10.TabOrange.rgb(), name='Midpoint'), None), 'mid': (PlotItem(x=[], y=[], pen=None, symbol='s', symbolBrush=Tab10.TabOrange.rgb(), name='Midpoint'), None),
@ -48,7 +51,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self.listWidget.itemClicked.connect(self.show_tg_values) self.listWidget.itemClicked.connect(self.show_tg_values)
self.new_graph_tau_combo.setEnabled(False) self.new_graph_tau_combo.setEnabled(False)
self.new_graph_tau_check.stateChanged.connect(lambda state: self.new_graph_tau_combo.setEnabled(bool(state))) self.new_graph_tau_check.stateChanged.connect(lambda state: self.new_graph_tau_combo.setEnabled(not bool(state)))
def __call__(self): def __call__(self):
self.clear() self.clear()
@ -65,11 +68,13 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self.graphicsView_2.removeItem(val) self.graphicsView_2.removeItem(val)
for plt in self._hodge.values(): for plt in self._hodge.values():
plt.setData(x=[], y=[]) plt[0].setData(x=[], y=[])
plt[1] = None
self._dsc = {} self._dsc = {}
self._plots = {} self._plots = {}
self._tg_value = {} self._tg_value = {}
self._lines = {}
self._fit = {} self._fit = {}
def add_sets(self): def add_sets(self):
@ -145,9 +150,10 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
data, _ = self._dsc[key] data, _ = self._dsc[key]
tg_results, glass, liquid, tangent = data.glass_transition(*baselines) tg_results, glass, liquid, tangent = data.glass_transition(*baselines)
self._lines[key] = (glass, liquid, tangent)
for i, line in enumerate((glass, liquid, tangent)): for i, line in enumerate((glass, liquid, tangent)):
plot[i+2].setData(x=line[:, 0], y=line[:, 1]) plot[i+2].setData(x=line.x, y=line.y)
self._tg_value[key].update(tg_results) self._tg_value[key].update(tg_results)
@ -249,6 +255,8 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
data = tau_hodge(*array(m).T) data = tau_hodge(*array(m).T)
plot.setData(data.x, data.y) plot.setData(data.x, data.y)
self._hodge[tg_type] = (plot, data)
def close(self) -> bool: def close(self) -> bool:
self.clear() self.clear()
return super().close() return super().close()
@ -259,13 +267,19 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
else: else:
graph_id = self.new_graph_tau_combo.currentData() graph_id = self.new_graph_tau_combo.currentData()
print(graph_id)
ret_dic = {} ret_dic = {}
for key, tg in self._tg_value.items(): for key, tg in self._tg_value.items():
plts = self._plots[key] tgx = [x for x, y in tg.values()]
ret_dic[key] = (tg, plts[1].getData(), plts[2].getData(), plts[3].getData(), plts[4].getData()) tgy = [y for x, y in tg.values()]
tg_pts = Points(x=tgx, y=tgy, name=self._management[key].name, value=self._management[key].value)
ret_dic[key] = (
tg_pts,
self._lines[key],
)
pprint.pprint(ret_dic) ret_dic2 = {}
pprint.pprint(self._hodge) for k, (_, v) in self._hodge.items():
ret_dic2[k] = v
self.newTg.emit(ret_dic, ret_dic2, graph_id)
self.close()

View File

@ -1095,6 +1095,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
def show_tg_dialog(self): def show_tg_dialog(self):
if self._tg_dialog is None: if self._tg_dialog is None:
self._tg_dialog = TgCalculator(self.management, parent=self) self._tg_dialog = TgCalculator(self.management, parent=self)
self._tg_dialog.newTg.connect(self.management.addTg)
else: else:
self._tg_dialog() self._tg_dialog()
self._tg_dialog.show() self._tg_dialog.show()

View File

@ -775,6 +775,22 @@ class UpperManagement(QtCore.QObject):
self.newData.emit(new_data, self.current_graph) self.newData.emit(new_data, self.current_graph)
@QtCore.pyqtSlot(dict, dict, str)
def addTg(self, dic1: dict, dic2: dict, graph_id: str):
for k, v in dic1.items():
p: ExperimentContainer = self[k]
col = p.plot_real.linecolor
set_id = self.add(v[0], color=col)
self.newData.emit([set_id], self.current_graph)
for line in v[1]:
set_id = self.add(line, color=col)
self.newData.emit([set_id], self.current_graph)
set_id_list = []
for v in dic2.values():
set_id_list.append(self.add(v))
self.newData.emit(set_id_list, '')
@QtCore.pyqtSlot(int, dict) @QtCore.pyqtSlot(int, dict)
def smooth_data(self, npoints, param_kwargs): def smooth_data(self, npoints, param_kwargs):
_active = self.graphs[self.current_graph].active _active = self.graphs[self.current_graph].active

View File

@ -27,6 +27,8 @@ class DSC(Points):
_yerr = np.asarray(kwargs['y_err']).reshape(np.asarray(x).shape) _yerr = np.asarray(kwargs['y_err']).reshape(np.asarray(x).shape)
kwargs['y_err'] = _yerr[unique] kwargs['y_err'] = _yerr[unique]
self.tg = {'onset': np.nan, 'mid': np.nan, 'end': np.nan, 'inflection': np.nan, 'fictive': np.nan}
super().__init__(x, y[unique], **kwargs) super().__init__(x, y[unique], **kwargs)
def get_fictive_cp(self, glass: tuple[float, float], liquid: tuple[float, float]) -> ('DSC', float): def get_fictive_cp(self, glass: tuple[float, float], liquid: tuple[float, float]) -> ('DSC', float):
@ -40,10 +42,6 @@ class DSC(Points):
regress = linregress(region.x[glass_regime], region.y[glass_regime]) regress = linregress(region.x[glass_regime], region.y[glass_regime])
glass_extrapolation = regress.slope * region.x + regress.intercept glass_extrapolation = regress.slope * region.x + regress.intercept
import matplotlib.pyplot as plt
plt.plot(region.x, glass_extrapolation)
liquid_regime = (min_liquid < region.x) & (region.x < max_liquid) liquid_regime = (min_liquid < region.x) & (region.x < max_liquid)
regress2 = linregress(region.x[liquid_regime], region.y[liquid_regime]) regress2 = linregress(region.x[liquid_regime], region.y[liquid_regime])
@ -123,9 +121,17 @@ class DSC(Points):
midpoint = np.argmin(np.abs(y - 0.5 * (liquid_baseline[end] - glass_baseline[onset]))) midpoint = np.argmin(np.abs(y - 0.5 * (liquid_baseline[end] - glass_baseline[onset])))
cut_tangent = np.where((tangent_line > y.min() - 1) & (tangent_line < y.max() + 1)) cut_tangent = np.where((tangent_line > y.min() - 1) & (tangent_line < y.max() + 1))
return { glass = Points(x, glass_baseline, name='Glass baseline', value=self.value)
tangent = Points(x[cut_tangent], tangent_line[cut_tangent], name='Tangent', value=self.value)
liquid = Points(x, liquid_baseline, name='Liquid baseline', value=self.value)
ret_dic = {
'onset': (x[onset], glass_baseline[onset]), 'onset': (x[onset], glass_baseline[onset]),
'mid': (x[midpoint], y[midpoint]), 'mid': (x[midpoint], y[midpoint]),
'end': (x[end], liquid_baseline[end]), 'end': (x[end], liquid_baseline[end]),
'inflection': (x[inflection], y[inflection]), 'inflection': (x[inflection], y[inflection]),
}, np.c_[x, glass_baseline], np.c_[x, liquid_baseline], np.c_[x[cut_tangent], tangent_line[cut_tangent]] }
self.tg.update(ret_dic)
return ret_dic, glass, liquid, tangent