1
0
forked from IPKM/nmreval

initialize plot at start

This commit is contained in:
Dominik Demuth 2023-06-03 17:04:14 +02:00
parent edc6af2762
commit bec789318d

View File

@ -20,8 +20,9 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
self._colors = cycle(Tab10)
self._dsc = {}
self._tg_baselines = {}
self._tg_value_plot = {}
self._plots = {}
self._tg_value = {}
self.limits = RegionItem(), RegionItem()
for lim in self.limits:
self.graphicsView.addItem(lim)
@ -33,21 +34,13 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
def __call__(self):
self.clear()
self.add_sets()
# s.valuesChanged.connect(self.management.shift_scale)
def clear(self):
self.listWidget.clear()
for plot, data in self._dsc.values():
self.graphicsView.removeItem(plot)
self._dsc = {}
for v in self._tg_baselines.values():
self.graphicsView.removeItem(v)
self._tg_baselines = {}
for v in self._tg_value_plot:
self.graphicsView.removeItem(v)
self._tg_value_plot = []
for plots in self._plots.values():
for val in plots:
self.graphicsView.removeItem(val)
self.graphicsView_2.removeItem(val)
def add_sets(self):
min_x = 10_000_000
@ -61,13 +54,39 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
max_x = max(max_x, data.x.max())
item = QtWidgets.QListWidgetItem(name)
item.setCheckState(QtCore.Qt.Checked)
item.setData(QtCore.Qt.UserRole, key)
item.setForeground(mkBrush(c.rgb()))
self.listWidget.addItem(item)
plot = PlotItem(x=data.x, y=data.y, pen=mkPen(c.rgb()))
self.graphicsView.addItem(plot)
self._dsc[key] = (plot, data)
self._dsc[key] = data
data_plot = PlotItem(x=data.x, y=data.y, pen=mkPen(c.rgb()))
self.graphicsView.addItem(data_plot)
glass = PlotItem()
glass.set_line(style=2, color=c)
self.graphicsView.addItem(glass)
liquid = PlotItem()
liquid.set_line(style=2, color=c)
self.graphicsView.addItem(liquid)
tangent = PlotItem()
tangent.set_line(style=2, color=c)
self.graphicsView.addItem(tangent)
tg_plot = PlotItem(pen=None, symbolBrush=c.rgb(), symbol='o')
self.graphicsView.addItem(tg_plot)
fictive_cp = PlotItem(pen=mkPen(c.rgb()))
self.graphicsView_2.addItem(fictive_cp)
tnmh_fit = PlotItem()
tnmh_fit.set_line(style=2, color=c)
self.graphicsView_2.addItem(tnmh_fit)
self._plots[key] = (data_plot, tg_plot, glass, liquid, tangent, fictive_cp, tnmh_fit)
dist = max_x - min_x
self.limits[0].setRegion((min_x, min_x+0.1*dist))
@ -75,14 +94,6 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
@QtCore.pyqtSlot(name='on_pushButton_clicked')
def calc_tg(self):
for v in self._tg_baselines.values():
for line in v:
self.graphicsView.removeItem(line)
self._tg_baselines = {}
for v in self._tg_value_plot:
self.graphicsView.removeItem(v)
baselines = tuple(lim.getRegion() for lim in self.limits)
if baselines[0][0] > baselines[1][0]:
baselines = baselines[1], baselines[0]
@ -91,22 +102,20 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
item = self.listWidget.item(idx)
key = item.data(QtCore.Qt.UserRole)
color = item.foreground()
_, data = self._dsc[key]
plot = self._plots[key]
data = self._dsc[key]
tg_results, glass, liquid, tangent = data.glass_transition(*baselines)
lines = []
for line in (glass, liquid, tangent):
plt = PlotItem(line[:, 0], line[:, 1])
plt.set_line(style=2, color=color.color())
self.graphicsView.addItem(plt)
lines.append(plt)
self._tg_baselines[key] = lines
tg_plot = PlotItem(array(list(tg_results.values())), pen=None, symbolBrush=color, symbol='o')
self._tg_value_plot[key] = (tg_results, tg_plot)
self.graphicsView.addItem(tg_plot)
for i, line in enumerate((glass, liquid, tangent)):
plot[i+2].setData(x=line[:, 0], y=line[:, 1])
plot[1].setData(array(list(tg_results.values())))
self._tg_value[key] = tg_results
def show_tg_values(self, item):
values, _ = self._tg_value_plot.get(item.data(QtCore.Qt.UserRole), ({}, None))
values = self._tg_value.get(item.data(QtCore.Qt.UserRole))
if values is not None:
self.listWidget_2.clear()
@ -123,23 +132,20 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
for idx in range(self.listWidget.count()):
item = self.listWidget.item(idx)
key = item.data(QtCore.Qt.UserRole)
color = item.foreground()
_, data = self._dsc[key]
plot = self._plots[key]
data = self._dsc[key]
cp, tg = data.get_fictive_cp(*baselines)
plt = PlotItem(cp.x, cp.y)
plt.set_line(color=color.color())
self.graphicsView_2.addItem(plt)
plot[5].setData(cp.x, cp.y)
self._tg_value_plot[key][0]['fictive'] = (tg, 0)
tg_plot = PlotItem(array(list(self._tg_value_plot[key][0].values())), pen=None, symbolBrush=color, symbol='o')
self.graphicsView.addItem(tg_plot)
self._tg_value[key]['fictive'] = (tg, 0)
res = data.calculate_tnmh([100, 0.5, 1, 2e5], *baselines, return_fictive=False)
plt = PlotItem(res.x, res.y)
plot[1].setData(array(list(self._tg_value[key].values())))
res = data.calculate_tnmh([60, 0.5, 1, 2e5], *baselines, return_fictive=False)
print(res.pprint())
plt.set_line(style=2, color=color.color())
self.graphicsView_2.addItem(plt)
plot[-1].setData(res.x, res.y)
def close(self) -> bool:
self.clear()