color to dsc curves in tg
This commit is contained in:
parent
a8a7e75501
commit
f74dd982ba
@ -1,3 +1,8 @@
|
|||||||
|
from itertools import cycle
|
||||||
|
|
||||||
|
from pyqtgraph import mkPen, mkBrush
|
||||||
|
|
||||||
|
from nmreval.lib.colors import Tab10
|
||||||
from ..Qt import QtWidgets, QtCore
|
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
|
||||||
@ -11,11 +16,10 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self._management = management
|
self._management = management
|
||||||
|
self._colors = cycle(Tab10)
|
||||||
|
|
||||||
self._plots = {}
|
self._dsc = {}
|
||||||
self._tg_baselines = {}
|
self._tg_baselines = {}
|
||||||
self.dsc = []
|
|
||||||
|
|
||||||
self.limits = RegionItem(), RegionItem()
|
self.limits = RegionItem(), RegionItem()
|
||||||
for lim in self.limits:
|
for lim in self.limits:
|
||||||
self.graphicsView.addItem(lim)
|
self.graphicsView.addItem(lim)
|
||||||
@ -28,45 +32,61 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
# s.valuesChanged.connect(self.management.shift_scale)
|
# s.valuesChanged.connect(self.management.shift_scale)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.dsc = []
|
|
||||||
self.listWidget.clear()
|
self.listWidget.clear()
|
||||||
for v in self._plots.values():
|
for plot, data in self._dsc.values():
|
||||||
self.graphicsView.removeItem(v)
|
self.graphicsView.removeItem(plot)
|
||||||
self._plots = {}
|
self._dsc = {}
|
||||||
|
|
||||||
for v in self._tg_baselines.values():
|
for v in self._tg_baselines.values():
|
||||||
self.graphicsView.removeItem(v)
|
self.graphicsView.removeItem(v)
|
||||||
self._tg_baselines = {}
|
self._tg_baselines = {}
|
||||||
|
|
||||||
def add_sets(self):
|
def add_sets(self):
|
||||||
for key, name in self._management.active_sets:
|
min_x = 10_000_000
|
||||||
data = self._management.data[key]
|
max_x = -10_000_000
|
||||||
if isinstance(data.data, DSC):
|
for (key, name), c in zip(self._management.active_sets, self._colors):
|
||||||
self.dsc.append(data)
|
data = self._management[key].data
|
||||||
else:
|
if not isinstance(data, DSC):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
min_x = min(min_x, data.x.min())
|
||||||
|
max_x = max(max_x, data.x.max())
|
||||||
|
|
||||||
item = QtWidgets.QListWidgetItem(name)
|
item = QtWidgets.QListWidgetItem(name)
|
||||||
item.setData(QtCore.Qt.UserRole, key)
|
item.setData(QtCore.Qt.UserRole, key)
|
||||||
|
item.setForeground(mkBrush(c.rgb()))
|
||||||
self.listWidget.addItem(item)
|
self.listWidget.addItem(item)
|
||||||
|
|
||||||
plot = PlotItem(x=data.x, y=data.y)
|
plot = PlotItem(x=data.x, y=data.y, pen=mkPen(c.rgb()))
|
||||||
self.graphicsView.addItem(plot)
|
self.graphicsView.addItem(plot)
|
||||||
self._plots[key] = plot
|
self._dsc[key] = (plot, data)
|
||||||
|
|
||||||
|
dist = max_x - min_x
|
||||||
|
self.limits[0].setRegion((min_x, min_x+0.1*dist))
|
||||||
|
self.limits[1].setRegion((max_x-0.1*dist, max_x))
|
||||||
|
|
||||||
@QtCore.pyqtSlot(name='on_pushButton_clicked')
|
@QtCore.pyqtSlot(name='on_pushButton_clicked')
|
||||||
def calc_tg(self):
|
def calc_tg(self):
|
||||||
|
for v in self._tg_baselines.values():
|
||||||
|
self.graphicsView.removeItem(v)
|
||||||
|
self._tg_baselines = {}
|
||||||
|
|
||||||
baselines = tuple(lim.getRegion() for lim in self.limits)
|
baselines = tuple(lim.getRegion() for lim in self.limits)
|
||||||
if baselines[0][0] > baselines[1][0]:
|
if baselines[0][0] > baselines[1][0]:
|
||||||
baselines = baselines[1], baselines[0]
|
baselines = baselines[1], baselines[0]
|
||||||
|
|
||||||
for idx in range(self.listWidget.count()):
|
for idx in range(self.listWidget.count()):
|
||||||
key = self.listWidget.item(idx).data(QtCore.Qt.UserRole)
|
item = self.listWidget.item(idx)
|
||||||
tg_results, glass, liquid, tangent = self._management[key].data.glass_transition(*baselines)
|
key = item.data(QtCore.Qt.UserRole)
|
||||||
|
color = item.foreground()
|
||||||
|
print(color)
|
||||||
|
_, data = self._dsc[key]
|
||||||
|
tg_results, glass, liquid, tangent = data.glass_transition(*baselines)
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for line in (glass, liquid, tangent):
|
for line in (glass, liquid, tangent):
|
||||||
plt = PlotItem(line[:, 0], line[:, 1])
|
plt = PlotItem(line[:, 0], line[:, 1])
|
||||||
|
plt.set_line(style=2, color=color.color())
|
||||||
self.graphicsView.addItem(plt)
|
self.graphicsView.addItem(plt)
|
||||||
lines.append(plt)
|
lines.append(plt)
|
||||||
self._tg_baselines[key] = lines
|
self._tg_baselines[key] = lines
|
||||||
|
Loading…
Reference in New Issue
Block a user