|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
from pyqtgraph import PlotDataItem
|
|
|
|
@ -14,7 +15,7 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
data_read = QtCore.pyqtSignal(list)
|
|
|
|
|
file_ext = ['.txt', '.dsc']
|
|
|
|
|
|
|
|
|
|
def __init__(self, sample= None, empty=None, reference=None, parent=None):
|
|
|
|
|
def __init__(self, sample=None, empty=None, reference=None, parent=None):
|
|
|
|
|
super().__init__(parent=parent)
|
|
|
|
|
self.setupUi(self)
|
|
|
|
|
|
|
|
|
@ -62,7 +63,13 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
for r in reference:
|
|
|
|
|
self.add_reference(ref=r)
|
|
|
|
|
|
|
|
|
|
def add_sample(self, fname: Union[Path, str]):
|
|
|
|
|
def __call__(self, fname: Path | str):
|
|
|
|
|
self.clear_plots()
|
|
|
|
|
self.add_sample(fname)
|
|
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
def add_sample(self, fname: Path | str):
|
|
|
|
|
self.sample = self.calibrator.set_measurement(fname, mode='sample')
|
|
|
|
|
self.fname = self.sample.fname
|
|
|
|
|
|
|
|
|
@ -95,13 +102,13 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(name='on_delempty_button_clicked')
|
|
|
|
|
def remove_empty(self):
|
|
|
|
|
self.empty_label.setText('Empty measurement')
|
|
|
|
|
self.empty_label.setText('No empty measurement')
|
|
|
|
|
self.calibrator.empty = None
|
|
|
|
|
|
|
|
|
|
self.update_plots()
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(name='on_ref_add_pushButton_clicked')
|
|
|
|
|
def add_reference(self, ref=None):
|
|
|
|
|
def add_reference(self, ref: str | Path = None):
|
|
|
|
|
if ref is None:
|
|
|
|
|
ref, _ = QtWidgets.QFileDialog.getOpenFileName(directory=str(self.fname.parent))
|
|
|
|
|
|
|
|
|
@ -127,9 +134,6 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
self.calibrator.remove_reference(self.reference_tableWidget.item(idx, 0).data(QtCore.Qt.UserRole))
|
|
|
|
|
|
|
|
|
|
self.reference_tableWidget.removeRow(idx)
|
|
|
|
|
|
|
|
|
|
print(self.calibrator.reference)
|
|
|
|
|
|
|
|
|
|
self.update_plots()
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(QtWidgets.QListWidgetItem, name='on_step_listWidget_itemChanged')
|
|
|
|
@ -153,16 +157,15 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
self.sample_idx = None
|
|
|
|
|
self.clear_plots()
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(QtWidgets.QAbstractButton, name='on_buttonGroup_buttonClicked')
|
|
|
|
|
def update_plots(self, _=None):
|
|
|
|
|
def get_data(self, ):
|
|
|
|
|
if self.sample_idx is None:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
rate = self.current_run[0]
|
|
|
|
|
slope_type = {self.none_radioButton: None,
|
|
|
|
|
self.isotherm_radioButton: 'iso',
|
|
|
|
|
self.slope_radioButton: 'curve'}[self.buttonGroup.checkedButton()]
|
|
|
|
|
|
|
|
|
|
rate = self.current_run[0]
|
|
|
|
|
try:
|
|
|
|
|
raw_sample, drift_value, sample_data, empty_data, slope = self.calibrator.get_data(self.sample_idx,
|
|
|
|
|
slope=slope_type)
|
|
|
|
@ -170,21 +173,38 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
_msg = QtWidgets.QMessageBox.warning(self, 'No rate found', e.args[0])
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.raw_sample.setData(x=raw_sample[0], y=raw_sample[1])
|
|
|
|
|
self.drift_sample.setData(x=drift_value[0]/60., y=drift_value[1])
|
|
|
|
|
self.slope_graph.setData(x=slope[0]/60., y=slope[1])
|
|
|
|
|
|
|
|
|
|
if empty_data is not None:
|
|
|
|
|
self.empty_sample.setData(x=empty_data[0], y=empty_data[1])
|
|
|
|
|
|
|
|
|
|
self.calibrator.ref_list = []
|
|
|
|
|
for row in range(self.reference_tableWidget.rowCount()):
|
|
|
|
|
self.calibrator.ref_list.append(self.reference_tableWidget.cellWidget(row, 1).get_reference())
|
|
|
|
|
|
|
|
|
|
self.calib_graph.clear()
|
|
|
|
|
|
|
|
|
|
calib_x, calib_y, regions = self.calibrator.get_calibration(rate)
|
|
|
|
|
|
|
|
|
|
drift_value[0] /= 60.
|
|
|
|
|
slope[0] /= 60.
|
|
|
|
|
|
|
|
|
|
if calib_x is not None:
|
|
|
|
|
sample_data[0] *= calib_x[0]
|
|
|
|
|
sample_data[0] += calib_x[1]
|
|
|
|
|
|
|
|
|
|
if self.cp_checkBox.isChecked():
|
|
|
|
|
sample_data[1] *= calib_y
|
|
|
|
|
|
|
|
|
|
return sample_data, raw_sample, empty_data, drift_value, slope, calib_x, calib_y, regions
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(QtWidgets.QAbstractButton, name='on_buttonGroup_buttonClicked')
|
|
|
|
|
@QtCore.pyqtSlot(int, name='on_cp_checkBox_stateChanged')
|
|
|
|
|
def update_plots(self, _=None):
|
|
|
|
|
sample_data, raw_sample, empty_data, drift_value, slope, calib_x, calib_y, regions = self.get_data()
|
|
|
|
|
|
|
|
|
|
self.raw_sample.setData(x=raw_sample[0], y=raw_sample[1])
|
|
|
|
|
self.drift_sample.setData(x=drift_value[0], y=drift_value[1])
|
|
|
|
|
self.slope_graph.setData(x=slope[0], y=slope[1])
|
|
|
|
|
|
|
|
|
|
if empty_data is not None:
|
|
|
|
|
self.empty_sample.setData(x=empty_data[0], y=empty_data[1])
|
|
|
|
|
|
|
|
|
|
self.calib_graph.clear()
|
|
|
|
|
|
|
|
|
|
if calib_x is not None:
|
|
|
|
|
for ref_zoom, onset, grad_points in regions:
|
|
|
|
|
ref_plot = PlotDataItem(x=ref_zoom[0], y=ref_zoom[1])
|
|
|
|
@ -200,14 +220,7 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
self.calib_graph.addItem(PlotDataItem(x=[ref_zoom[0, 0], ref_zoom[0, -1]], y=[0, 0],
|
|
|
|
|
pen={'color': 'r', 'dash': (2, 5)}))
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
calib_x = [1, 0]
|
|
|
|
|
calib_y = 1
|
|
|
|
|
|
|
|
|
|
if self.cp_checkBox.isChecked():
|
|
|
|
|
self.baseline_sample.setData(x=calib_x[0]*sample_data[0]+calib_x[1], y=calib_y*sample_data[1])
|
|
|
|
|
else:
|
|
|
|
|
self.baseline_sample.setData(x=calib_x[0]*sample_data[0]+calib_x[1], y=sample_data[1])
|
|
|
|
|
self.baseline_sample.setData(x=sample_data[0], y=sample_data[1])
|
|
|
|
|
|
|
|
|
|
def clear_plots(self):
|
|
|
|
|
for plot in [self.raw_sample, self.baseline_sample, self.empty_sample, self.drift_sample, self.slope_graph]:
|
|
|
|
@ -215,38 +228,30 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|
|
|
|
|
|
|
|
|
self.calib_graph.clear()
|
|
|
|
|
|
|
|
|
|
def accept(self):
|
|
|
|
|
run_list = []
|
|
|
|
|
for i in range(self.step_listWidget.count()):
|
|
|
|
|
if self.step_listWidget.item(i).checkState() == QtCore.Qt.Checked:
|
|
|
|
|
run_list.append(i)
|
|
|
|
|
def export_data(self, filesave=False, close_after=True):
|
|
|
|
|
try:
|
|
|
|
|
sample_data = self.get_data()[0]
|
|
|
|
|
except TypeError:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if self.baseline_groupBox.isChecked():
|
|
|
|
|
empty = self.empty
|
|
|
|
|
slope = {self.none_radioButton: None,
|
|
|
|
|
self.isotherm_radioButton: 'iso',
|
|
|
|
|
self.slope_radioButton: 'heat'}[self.buttonGroup.checkedButton()]
|
|
|
|
|
rate, mode = self.current_run
|
|
|
|
|
new_val = Points(sample_data[0], sample_data[1], value=rate, name=f'{self.fname.stem} {rate} ({mode})')
|
|
|
|
|
|
|
|
|
|
if filesave:
|
|
|
|
|
new_val.savetxt(self.fname.with_name(f'{self.fname.stem} {rate}K-min {mode}.dat'.replace(' ', '_')))
|
|
|
|
|
else:
|
|
|
|
|
empty = None
|
|
|
|
|
slope = None
|
|
|
|
|
self.data_read.emit([new_val])
|
|
|
|
|
|
|
|
|
|
if self.reference_groupBox.isChecked():
|
|
|
|
|
calibrations = []
|
|
|
|
|
for j, ref in enumerate(self.references):
|
|
|
|
|
calibrations.append((ref, self.reference_tableWidget.cellWidget(j, 1).get_reference()))
|
|
|
|
|
if close_after:
|
|
|
|
|
super().accept()
|
|
|
|
|
|
|
|
|
|
@QtCore.pyqtSlot(QtWidgets.QAbstractButton, name='on_buttonBox_clicked')
|
|
|
|
|
def button_clicked(self, bttn: QtWidgets.QAbstractButton):
|
|
|
|
|
bttn_value = self.buttonBox.standardButton(bttn)
|
|
|
|
|
if bttn_value in (self.buttonBox.Ok, self.buttonBox.Apply, self.buttonBox.Save):
|
|
|
|
|
self.export_data(filesave=bttn_value==self.buttonBox.Save, close_after=bttn_value==self.buttonBox.Ok)
|
|
|
|
|
else:
|
|
|
|
|
calibrations = None
|
|
|
|
|
|
|
|
|
|
new_vals = []
|
|
|
|
|
|
|
|
|
|
for run in run_list:
|
|
|
|
|
mode, rate, _, _ = self.sample.steps[run]
|
|
|
|
|
xy = self.sample.curve(rate, mode, empty=empty, slope=slope, calibration=calibrations)
|
|
|
|
|
new_vals.append(Points(xy[0], xy[1], value=rate, name=f'{self.fname.stem} {rate} ({mode})'))
|
|
|
|
|
|
|
|
|
|
self.data_read.emit(new_vals)
|
|
|
|
|
|
|
|
|
|
super().accept()
|
|
|
|
|
super().close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReferenceComboBox(QtWidgets.QComboBox):
|
|
|
|
|