...
 
Commits (9)
......@@ -13,7 +13,7 @@ from . import zcetools_help
from . import reactivitytools
__version__ = "0.0.20"
__version__ = "0.0.23"
__all__ = ['config', 'datatools', 'docks', 'drltools', 'drltoos_gui', 'filetools',
......
......@@ -44,6 +44,16 @@ class QStatusBarLogger(logging.Handler):
self.trigger.signal.emit()
def show_exception_and_exit(exc_type, exc_value, tb):
if "figure size must be positive finite not" in str(exc_value):
return
import traceback
traceback.print_exception(exc_type, exc_value, tb)
errmsg = "\n".join(traceback.format_exception(exc_type, exc_value, tb))
QtWidgets.QMessageBox.critical(None, "Exception!", errmsg)
sys.exit(-1)
def load_file(parent, augCanvas, update, settings, loadthread, filename=None):
"""populates dataset and plots it"""
directory = augCanvas.filename or settings.value("open_folder")
......@@ -246,6 +256,9 @@ def about(parent):
def main():
# thx to: https://stackoverflow.com/questions/779675/stop-python-from-closing-on-error/781074#781074
sys.excepthook = show_exception_and_exit
app = QtWidgets.QApplication(sys.argv)
loadthread = QtCore.QThread()
......
......@@ -302,7 +302,7 @@ def load_drltables(parent, dataset, drls, drlspectrum):
"Error encountered on line {}.\n"
"Cancelling request.".format(i+1))
return
columns = names, masses, peak_widths, states
columns = [names, masses, peak_widths, states]
[columns.append(i) for i in corrections]
for j, k in enumerate(columns):
if len(rawline) > j:
......
......@@ -6,6 +6,7 @@ from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtPrintSupport
from io import BytesIO
import matplotlib
import numpy as np
import prasopes.datatools as dt
......@@ -18,7 +19,14 @@ import logging
matplotlib.use("Qt5Agg")
logger = logging.getLogger('drlLogger')
logger = logging.getLogger('reactivityLogger')
def key_pressed(event, augCanvas, drls, grph, labels, parselect, coef1, coef2):
print("trigged")
if event.key() == QtCore.Qt.Key_C:
if event.modifiers().__int__() == QtCore.Qt.ControlModifier:
clip_spect_img(augCanvas, drls, grph, labels, parselect, coef1, coef2)
def update_parselect(augCanvas, parselect):
index = parselect.currentIndex()
......@@ -31,6 +39,30 @@ def update_parselect(augCanvas, parselect):
if index <= len(parlist):
parselect.setCurrentIndex(index)
def paint_image(augCanvas, drls, grph, labels, parselect, coef1, coef2):
paintfig = Figure(figsize=(3.5,2), dpi=300)
paintfig.tight_layout()
FigureCanvas(paintfig)
printplot = paintfig.add_subplot(111)
pop_dial(augCanvas, drls, printplot, labels, parselect, coef1, coef2)
printplot.set_xlim(grph.get_xlim())
printplot.set_ylim(grph.get_ylim())
paintfig.canvas.draw()
cache_file = BytesIO()
paintfig.savefig(cache_file)
cache_file.seek(0)
image = QtGui.QImage.fromData(cache_file.read())
return image
def clip_spect_img(augCanvas, drls, grph, labels, parselect, coef1, coef2):
image=paint_image(augCanvas, drls, grph, labels, parselect, coef1, coef2)
QtWidgets.QApplication.clipboard().clear()
[QtWidgets.QApplication.clipboard().setImage(image, i) for i in range(2)]
def pop_dial(augCanvas, drls, graph, labels, parselect, coef1, coef2):
logger.debug("populating reactivity dialog")
# Do not do anything when data set is not populated
......@@ -40,6 +72,8 @@ def pop_dial(augCanvas, drls, graph, labels, parselect, coef1, coef2):
graph.clear()
gt.pop_plot([0], [0], graph, labels)
names, times, intensities = drl.get_daughterset(augCanvas.ds, drls)
colorargs = [row for row in range(drls['dt'].rowCount())
if drls['dt'].cellWidget(row, 0).checkState() == 2]
if len(names) < 2:
return
params = augCanvas.ms['params'][1]
......@@ -53,19 +87,28 @@ def pop_dial(augCanvas, drls, graph, labels, parselect, coef1, coef2):
toavg.append((float(params[i][parselect.currentIndex()])
-coef1.value())*coef2.value())
lastpos = i
elif float(params[i][0]) > time:
elif float(params[i][0]) > time and i > 0:
# i>0 condition to handle possibility of invalid first scan.
# (was observed in-wild on TSQ once)
break
if len(toavg) != 0:
pressures.append([time, np.average(toavg)])
if len(pressures) == 0:
QtWidgets.QMessageBox.critical(None, "No times loaded",
"Did not located any valid parameters.\n"
"It is either start of the acquisition,\n"
"or the timestamps has been corrupted.")
return
nptpressures = np.asarray(pressures).T[0]
goodtimes = np.where([t in nptpressures for t in times])
for i in range(1,len(intensities)):
relint = np.divide(intensities[i], np.clip(np.sum(
intensities, 0), np.finfo(np.float32).eps, None),
dtype=np.float64)
graph.plot(np.asarray(pressures).T[1], relint[goodtimes], label=names[i],
color=(gt.colors[i % len(gt.colors)] / 255), marker=".",
markersize=2, linestyle="None")
graph.plot(np.asarray(pressures).T[1], relint[goodtimes],
label=names[i], color=(gt.colors[
colorargs[i] % len(gt.colors)] / 255), marker=".",
markersize=1, linestyle="None")
graph.autoscale(True)
graph.figure.canvas.draw()
......@@ -88,6 +131,7 @@ def main_window(parent, augCanvas, update_signal, drls):
dial_widget, event, update_fnc)
update_signal.signal.connect(update_fnc)
dial_graph = Figure(figsize=(5, 2), dpi=100, facecolor="None")
dial_graph.tight_layout()
dialspect = dial_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8))
graph_canvas = FigureCanvas(dial_graph)
graph_canvas.setStyleSheet("background-color:transparent;")
......@@ -102,6 +146,16 @@ def main_window(parent, augCanvas, update_signal, drls):
cf.settings().setValue("reactivity/index", x))
formula = QtWidgets.QLabel(
"Formula for the x-axis: (Parameter - a) * b")
xlabelabel = QtWidgets.QLabel("x axis label:")
xlabeldial = QtWidgets.QLineEdit("pressure (mT)")
def changevalue(x):
reactlabels['xlabel'] = x
dialspect.set_xlabel(x)
graph_canvas.draw()
xlabeldial.textChanged.connect(changevalue)
xannlayout = QtWidgets.QHBoxLayout()
[xannlayout.addWidget(i) for i in [xlabelabel, xlabeldial]]
xannlayout.addStretch()
label1 = QtWidgets.QLabel("a: ", alignment=130)
coef1 = QtWidgets.QDoubleSpinBox(
decimals=4, minimum=float("-inf"), maximum=float("inf"))
......@@ -126,8 +180,13 @@ def main_window(parent, augCanvas, update_signal, drls):
for i in [label1, coef1, label2, coef2]:
coef_layout.addWidget(i)
dial_widget.keyPressEvent = lambda event: key_pressed(
event, augCanvas, drls, dialspect, reactlabels, parselect, coef1, coef2)
dial_layout = QtWidgets.QVBoxLayout(dial_widget)
dial_layout.addWidget(graph_canvas)
dial_layout.addWidget(graph_canvas, stretch=1)
dial_layout.addLayout(xannlayout)
dial_layout.addLayout(param_layout)
dial_layout.addWidget(formula)
dial_layout.addLayout(coef_layout)
......
......@@ -101,7 +101,8 @@ def help_msg(pw):
def paint_zcegraph(ds, coff, coffgrad, filename):
paintfig = Figure(figsize=(5, 2), dpi=300, constrained_layout=True)
paintfig = Figure(figsize=(5, 2), dpi=300)
paintfig.tight_layout()
printplot = paintfig.add_subplot(111)
printplot_overlay = printplot.twinx()
FigureCanvas(paintfig)
......