From 84d588cf80066da5418e8e42156de7f11466b4f2 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 19 Jun 2023 17:50:36 +0200 Subject: [PATCH] work on export --- src/gui_qt/dsc/glass_dialog.py | 36 +++++++++++++------ src/gui_qt/main/mainwindow.py | 1 + src/gui_qt/main/management.py | 16 +++++++++ src/nmreval/data/dsc.py | 18 ++++++---- src/{ => resources}/pkm.vogel.nmreval.desktop | 0 5 files changed, 54 insertions(+), 17 deletions(-) rename src/{ => resources}/pkm.vogel.nmreval.desktop (100%) diff --git a/src/gui_qt/dsc/glass_dialog.py b/src/gui_qt/dsc/glass_dialog.py index 1ce2242..f35119e 100644 --- a/src/gui_qt/dsc/glass_dialog.py +++ b/src/gui_qt/dsc/glass_dialog.py @@ -10,10 +10,12 @@ from ..Qt import QtWidgets, QtCore from .._py.tnmh_dialog import Ui_Dialog from ..lib.pg_objects import PlotItem, RegionItem -from nmreval.data import DSC +from nmreval.data import DSC, Points class TgCalculator(QtWidgets.QDialog, Ui_Dialog): + newTg = QtCore.pyqtSignal(dict, dict, str) + def __init__(self, management, parent=None): super().__init__(parent=parent) @@ -25,6 +27,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self._plots = {} self._tg_value = {} self._fit = {} + self._lines = {} self._hodge = { '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), @@ -48,7 +51,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self.listWidget.itemClicked.connect(self.show_tg_values) 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): self.clear() @@ -65,11 +68,13 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self.graphicsView_2.removeItem(val) for plt in self._hodge.values(): - plt.setData(x=[], y=[]) + plt[0].setData(x=[], y=[]) + plt[1] = None self._dsc = {} self._plots = {} self._tg_value = {} + self._lines = {} self._fit = {} def add_sets(self): @@ -145,9 +150,10 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): data, _ = self._dsc[key] tg_results, glass, liquid, tangent = data.glass_transition(*baselines) + self._lines[key] = (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) @@ -249,6 +255,8 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): data = tau_hodge(*array(m).T) plot.setData(data.x, data.y) + self._hodge[tg_type] = (plot, data) + def close(self) -> bool: self.clear() return super().close() @@ -259,13 +267,19 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): else: graph_id = self.new_graph_tau_combo.currentData() - print(graph_id) - ret_dic = {} - for key, tg in self._tg_value.items(): - plts = self._plots[key] - ret_dic[key] = (tg, plts[1].getData(), plts[2].getData(), plts[3].getData(), plts[4].getData()) + tgx = [x for x, y in tg.values()] + 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) - pprint.pprint(self._hodge) + ret_dic2 = {} + for k, (_, v) in self._hodge.items(): + ret_dic2[k] = v + + self.newTg.emit(ret_dic, ret_dic2, graph_id) + self.close() diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 7409c8a..502f2a6 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -1095,6 +1095,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): def show_tg_dialog(self): if self._tg_dialog is None: self._tg_dialog = TgCalculator(self.management, parent=self) + self._tg_dialog.newTg.connect(self.management.addTg) else: self._tg_dialog() self._tg_dialog.show() diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 44b0693..27d7d75 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -775,6 +775,22 @@ class UpperManagement(QtCore.QObject): 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) def smooth_data(self, npoints, param_kwargs): _active = self.graphs[self.current_graph].active diff --git a/src/nmreval/data/dsc.py b/src/nmreval/data/dsc.py index 383a2e0..9bd3afd 100644 --- a/src/nmreval/data/dsc.py +++ b/src/nmreval/data/dsc.py @@ -27,6 +27,8 @@ class DSC(Points): _yerr = np.asarray(kwargs['y_err']).reshape(np.asarray(x).shape) 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) 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]) 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) 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]))) 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]), 'mid': (x[midpoint], y[midpoint]), 'end': (x[end], liquid_baseline[end]), '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 diff --git a/src/pkm.vogel.nmreval.desktop b/src/resources/pkm.vogel.nmreval.desktop similarity index 100% rename from src/pkm.vogel.nmreval.desktop rename to src/resources/pkm.vogel.nmreval.desktop