less buggy than before in dsc and t1
This commit is contained in:
parent
dc906972e9
commit
16ccc3eb3d
@ -1,5 +1,6 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pyqtgraph import PlotDataItem
|
from pyqtgraph import PlotDataItem
|
||||||
@ -14,7 +15,7 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
data_read = QtCore.pyqtSignal(list)
|
data_read = QtCore.pyqtSignal(list)
|
||||||
file_ext = ['.txt', '.dsc']
|
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)
|
super().__init__(parent=parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
@ -62,7 +63,13 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
for r in reference:
|
for r in reference:
|
||||||
self.add_reference(ref=r)
|
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.sample = self.calibrator.set_measurement(fname, mode='sample')
|
||||||
self.fname = self.sample.fname
|
self.fname = self.sample.fname
|
||||||
|
|
||||||
@ -95,13 +102,13 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
@QtCore.pyqtSlot(name='on_delempty_button_clicked')
|
@QtCore.pyqtSlot(name='on_delempty_button_clicked')
|
||||||
def remove_empty(self):
|
def remove_empty(self):
|
||||||
self.empty_label.setText('Empty measurement')
|
self.empty_label.setText('No empty measurement')
|
||||||
self.calibrator.empty = None
|
self.calibrator.empty = None
|
||||||
|
|
||||||
self.update_plots()
|
self.update_plots()
|
||||||
|
|
||||||
@QtCore.pyqtSlot(name='on_ref_add_pushButton_clicked')
|
@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:
|
if ref is None:
|
||||||
ref, _ = QtWidgets.QFileDialog.getOpenFileName(directory=str(self.fname.parent))
|
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.calibrator.remove_reference(self.reference_tableWidget.item(idx, 0).data(QtCore.Qt.UserRole))
|
||||||
|
|
||||||
self.reference_tableWidget.removeRow(idx)
|
self.reference_tableWidget.removeRow(idx)
|
||||||
|
|
||||||
print(self.calibrator.reference)
|
|
||||||
|
|
||||||
self.update_plots()
|
self.update_plots()
|
||||||
|
|
||||||
@QtCore.pyqtSlot(QtWidgets.QListWidgetItem, name='on_step_listWidget_itemChanged')
|
@QtCore.pyqtSlot(QtWidgets.QListWidgetItem, name='on_step_listWidget_itemChanged')
|
||||||
@ -153,16 +157,15 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
self.sample_idx = None
|
self.sample_idx = None
|
||||||
self.clear_plots()
|
self.clear_plots()
|
||||||
|
|
||||||
@QtCore.pyqtSlot(QtWidgets.QAbstractButton, name='on_buttonGroup_buttonClicked')
|
def get_data(self, ):
|
||||||
def update_plots(self, _=None):
|
|
||||||
if self.sample_idx is None:
|
if self.sample_idx is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
rate = self.current_run[0]
|
||||||
slope_type = {self.none_radioButton: None,
|
slope_type = {self.none_radioButton: None,
|
||||||
self.isotherm_radioButton: 'iso',
|
self.isotherm_radioButton: 'iso',
|
||||||
self.slope_radioButton: 'curve'}[self.buttonGroup.checkedButton()]
|
self.slope_radioButton: 'curve'}[self.buttonGroup.checkedButton()]
|
||||||
|
|
||||||
rate = self.current_run[0]
|
|
||||||
try:
|
try:
|
||||||
raw_sample, drift_value, sample_data, empty_data, slope = self.calibrator.get_data(self.sample_idx,
|
raw_sample, drift_value, sample_data, empty_data, slope = self.calibrator.get_data(self.sample_idx,
|
||||||
slope=slope_type)
|
slope=slope_type)
|
||||||
@ -170,21 +173,38 @@ class QDSCReader(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
_msg = QtWidgets.QMessageBox.warning(self, 'No rate found', e.args[0])
|
_msg = QtWidgets.QMessageBox.warning(self, 'No rate found', e.args[0])
|
||||||
return
|
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 = []
|
self.calibrator.ref_list = []
|
||||||
for row in range(self.reference_tableWidget.rowCount()):
|
for row in range(self.reference_tableWidget.rowCount()):
|
||||||
self.calibrator.ref_list.append(self.reference_tableWidget.cellWidget(row, 1).get_reference())
|
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)
|
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:
|
if calib_x is not None:
|
||||||
for ref_zoom, onset, grad_points in regions:
|
for ref_zoom, onset, grad_points in regions:
|
||||||
ref_plot = PlotDataItem(x=ref_zoom[0], y=ref_zoom[1])
|
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],
|
self.calib_graph.addItem(PlotDataItem(x=[ref_zoom[0, 0], ref_zoom[0, -1]], y=[0, 0],
|
||||||
pen={'color': 'r', 'dash': (2, 5)}))
|
pen={'color': 'r', 'dash': (2, 5)}))
|
||||||
|
|
||||||
else:
|
self.baseline_sample.setData(x=sample_data[0], y=sample_data[1])
|
||||||
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])
|
|
||||||
|
|
||||||
def clear_plots(self):
|
def clear_plots(self):
|
||||||
for plot in [self.raw_sample, self.baseline_sample, self.empty_sample, self.drift_sample, self.slope_graph]:
|
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()
|
self.calib_graph.clear()
|
||||||
|
|
||||||
def accept(self):
|
def export_data(self, filesave=False, close_after=True):
|
||||||
run_list = []
|
try:
|
||||||
for i in range(self.step_listWidget.count()):
|
sample_data = self.get_data()[0]
|
||||||
if self.step_listWidget.item(i).checkState() == QtCore.Qt.Checked:
|
except TypeError:
|
||||||
run_list.append(i)
|
return
|
||||||
|
|
||||||
if self.baseline_groupBox.isChecked():
|
rate, mode = self.current_run
|
||||||
empty = self.empty
|
new_val = Points(sample_data[0], sample_data[1], value=rate, name=f'{self.fname.stem} {rate} ({mode})')
|
||||||
slope = {self.none_radioButton: None,
|
|
||||||
self.isotherm_radioButton: 'iso',
|
if filesave:
|
||||||
self.slope_radioButton: 'heat'}[self.buttonGroup.checkedButton()]
|
new_val.savetxt(self.fname.with_name(f'{self.fname.stem} {rate}K-min {mode}.dat'.replace(' ', '_')))
|
||||||
else:
|
else:
|
||||||
empty = None
|
self.data_read.emit([new_val])
|
||||||
slope = None
|
|
||||||
|
|
||||||
if self.reference_groupBox.isChecked():
|
if close_after:
|
||||||
calibrations = []
|
super().accept()
|
||||||
for j, ref in enumerate(self.references):
|
|
||||||
calibrations.append((ref, self.reference_tableWidget.cellWidget(j, 1).get_reference()))
|
@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:
|
else:
|
||||||
calibrations = None
|
super().close()
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
class ReferenceComboBox(QtWidgets.QComboBox):
|
class ReferenceComboBox(QtWidgets.QComboBox):
|
||||||
|
@ -163,7 +163,7 @@ class QT1Widget(QtWidgets.QDialog, Ui_t1dialog):
|
|||||||
if self.coupling[idx].choice is not None:
|
if self.coupling[idx].choice is not None:
|
||||||
for (name, kw_name, opts) in self.coupling[idx].choice:
|
for (name, kw_name, opts) in self.coupling[idx].choice:
|
||||||
widgt = SelectionWidget(name, kw_name, opts)
|
widgt = SelectionWidget(name, kw_name, opts)
|
||||||
widgt.comboBox.currentIndexChanged.connect(self.update_coupling)
|
widgt.comboBox.currentIndexChanged.connect(self.update_coupling_parameter)
|
||||||
self.verticalLayout_4.addWidget(widgt)
|
self.verticalLayout_4.addWidget(widgt)
|
||||||
self.cp_parameter.append(widgt)
|
self.cp_parameter.append(widgt)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
from __future__ import annotations
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
try:
|
try:
|
||||||
@ -19,7 +19,7 @@ class DSCSample:
|
|||||||
DSC_RUN_RE = re.compile(r'(\d+)\) DSC')
|
DSC_RUN_RE = re.compile(r'(\d+)\) DSC')
|
||||||
DSC_END_RE = re.compile(r'DSC8[50]00 MANUAL TUNE')
|
DSC_END_RE = re.compile(r'DSC8[50]00 MANUAL TUNE')
|
||||||
|
|
||||||
def __init__(self, fname: Union[str, Path]):
|
def __init__(self, fname: str | Path):
|
||||||
fname = Path(fname)
|
fname = Path(fname)
|
||||||
if fname.exists():
|
if fname.exists():
|
||||||
self.fname = fname
|
self.fname = fname
|
||||||
@ -32,7 +32,7 @@ class DSCSample:
|
|||||||
|
|
||||||
self.read_file(fname)
|
self.read_file(fname)
|
||||||
|
|
||||||
def read_file(self, fname: Union[str, Path]):
|
def read_file(self, fname: str | Path):
|
||||||
fname = Path(fname)
|
fname = Path(fname)
|
||||||
|
|
||||||
# file contains weird deg C character in stupiod ISO encoding
|
# file contains weird deg C character in stupiod ISO encoding
|
||||||
@ -144,7 +144,7 @@ class DSCCalibrator:
|
|||||||
self.ref_list = []
|
self.ref_list = []
|
||||||
|
|
||||||
def set_measurement(self,
|
def set_measurement(self,
|
||||||
fname: Union[str, Path, DSCSample], mode: str = 'sample',
|
fname: str | Path | DSCSample, mode: str = 'sample',
|
||||||
reference: ReferenceValue = Cyclohexane):
|
reference: ReferenceValue = Cyclohexane):
|
||||||
if mode not in ['sample', 'empty', 'reference']:
|
if mode not in ['sample', 'empty', 'reference']:
|
||||||
raise ValueError(f'Unknown mode {mode}, not "sample", "empty", "reference"')
|
raise ValueError(f'Unknown mode {mode}, not "sample", "empty", "reference"')
|
||||||
@ -164,7 +164,7 @@ class DSCCalibrator:
|
|||||||
|
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
def remove_reference(self, fname: Union[str, Path]):
|
def remove_reference(self, fname: str | Path):
|
||||||
fname = Path(fname)
|
fname = Path(fname)
|
||||||
i = None
|
i = None
|
||||||
for i, ref in enumerate(self.reference):
|
for i, ref in enumerate(self.reference):
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
__version__ = '0.1'
|
__version__ = '0.1.1'
|
||||||
__releasename__ = 'Snobilikat'
|
__releasename__ = 'Snobilikat'
|
||||||
|
Loading…
Reference in New Issue
Block a user