Commit d2cf80a3 authored by Yan's avatar Yan
Browse files

tofTools - pt2 - not finished

* Got table working somehow
parent 36070663
...@@ -286,6 +286,8 @@ def main(): ...@@ -286,6 +286,8 @@ def main():
zce_logger = logging.getLogger('zcelogger') zce_logger = logging.getLogger('zcelogger')
rxn_logger = logging.getLogger('reactivityLogger') rxn_logger = logging.getLogger('reactivityLogger')
ds_logger = logging.getLogger('dsLogger') ds_logger = logging.getLogger('dsLogger')
toflogger = logging.getLogger('tofLogger')
toflogger.setLevel("DEBUG")
logging.basicConfig() logging.basicConfig()
# p_logger.setLevel("WARN") # p_logger.setLevel("WARN")
p_logger.setLevel("DEBUG") p_logger.setLevel("DEBUG")
......
...@@ -21,6 +21,87 @@ matplotlib.use("Qt5Agg") ...@@ -21,6 +21,87 @@ matplotlib.use("Qt5Agg")
logger = logging.getLogger('tofLogger') logger = logging.getLogger('tofLogger')
settings = cf.settings() settings = cf.settings()
def get_massargs(tab, row, masses):
startm = drl.floatize(tab, row, 3) - (drl.floatize(tab, row, 4) / 2)
endm = drl.floatize(tab, row, 3) + (drl.floatize(tab, row, 4) / 2)
massargs = dt.argsubselect(masses, startm, endm)
return massargs
def update_profile(table, row, dataset):
"""parent table profile spectrum updating procedure"""
logger.debug("updating parent table row {} profile".format(row))
# Dont do anything to graph when the spectrum is not populated
if not dataset:
return
spectrum = table.cellWidget(row, 5).figure.get_axes()[0]
spectrum.clear()
limits = []
spectra = dataset.get_spectra(*[drl.floatize(table, row, i) for i in (1,2)])
for i,spectxy in enumerate(spectra):
massargs = get_massargs(table, row, spectxy[0])
spectrum.plot(spectxy[0], spectxy[1], ':', color='gray')
spectrum.plot(spectxy[0][massargs], spectxy[1][massargs],
color=gt.colors[i % len(gt.colors)]/255)
limits.append((spectxy[0][massargs[[0, -1]]],
max(spectxy[1][massargs])))
widest = np.argmax([abs(lim[0][1]-lim[0][0]) for lim in limits])
xmin, xmax = limits[widest][0]
xex = max((xmax-xmin)*0.25, 0.02)
spectrum.set_xlim(xmin-xex, xmax+xex)
ymax = max(*[lim[1] for lim in limits], 1)
spectrum.set_ylim(ymax*-0.1, ymax*1.2)
spectrum.figure.canvas.draw()
def ionstable_changed(row, col, ds, table):
if col in (1,2,3,4):
update_profile(table, row, ds)
def pop_dial(augCanvas, dialspect, ionstable):
return
def add_row(ds, dialspect, ionstable):
"""add parent ion to the table"""
logger.debug("adding line")
newrow = ionstable.rowCount()
ionstable.blockSignals(True)
ionstable.setRowCount(newrow + 1)
for i in range(5):
ionstable.setItem(newrow, i, QtWidgets.QTableWidgetItem())
if newrow != 0:
val = drl.floatize(ionstable, newrow-1, i)
if i not in (1,2,4):
val = val+1
ionstable.item(newrow, i).setText(str(val))
ion_graph = Figure(figsize=(3, 1.5), dpi=100, facecolor="None")
ion_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8),
position=(-0.01, -0.01, 1.02, 1.02))
graph_canvas = FigureCanvas(ion_graph)
graph_canvas.setStyleSheet("background-color:transparent;")
graph_canvas.setAutoFillBackground(False)
ionstable.setCellWidget(newrow, 5, graph_canvas)
ionstable.blockSignals(False)
ionstable_changed(newrow, 1, ds, ionstable)
return
def remove_rows(ionstable, rows=None):
logger.info("remowing rows")
if not rows:
rows = reversed(list(set(
map(lambda x: x.row(), ionstable.selectedIndexes()))))
[ionstable.removeRow(row) for row in rows]
return
def main_window(parent, augCanvas, update_signal): def main_window(parent, augCanvas, update_signal):
reactlabels = dict(name="", xlabel="$time (??seconds??)\ \\it→$", reactlabels = dict(name="", xlabel="$time (??seconds??)\ \\it→$",
ylabel="$Intensity\ \\it→$") ylabel="$Intensity\ \\it→$")
...@@ -33,12 +114,12 @@ def main_window(parent, augCanvas, update_signal): ...@@ -33,12 +114,12 @@ def main_window(parent, augCanvas, update_signal):
QtWidgets.QDialog.closeEvent(widget, event) QtWidgets.QDialog.closeEvent(widget, event)
def update_fnc(): def update_fnc():
pop_dial(augCanvas, drls, dialspect, reactlabels, parselect) pop_dial(augCanvas, dialspect, ionstable)
dial_widget = QtWidgets.QDialog( dial_widget = QtWidgets.QDialog(
parent, windowTitle='Mobilogram') parent, windowTitle='Mobilogram')
dial_widget.closeEvent = lambda event: onclose( dial_widget.closeEvent = lambda event: onclose(
dial_widget, event, update_fnc) dial_widget, event, ionstable, graph_canvas, cache, update_fnc)
update_signal.signal.connect(update_fnc) update_signal.signal.connect(update_fnc)
if cache == [None, None]: if cache == [None, None]:
...@@ -56,27 +137,37 @@ def main_window(parent, augCanvas, update_signal): ...@@ -56,27 +137,37 @@ def main_window(parent, augCanvas, update_signal):
"Mass (m/z)", "Peak width", "Profile"]) "Mass (m/z)", "Peak width", "Profile"])
else: else:
ionstable = cache[0] ionstable = cache[0]
grpah_canvas = cache[1] graph_canvas = cache[1]
dialspect = graph_canvas.figure.axes[0] dialspect = graph_canvas.figure.axes[0]
pushbtn = QtWidgets.QPushButton("Update") ionstable.itemChanged.connect(lambda item: ionstable_changed(
#pushbtn.clicked.connect(lambda: update_fnc()) item.row(), item.column(), augCanvas.ds, ionstable))
updatebtn = QtWidgets.QPushButton("Update")
updatebtn.clicked.connect(lambda: update_fnc())
addbtn = QtWidgets.QPushButton("Add")
addbtn.clicked.connect(lambda: add_row(
augCanvas.ds, dialspect, ionstable))
rmbtn = QtWidgets.QPushButton("Remove")
rmbtn.clicked.connect(lambda: remove_rows(ionstable))
expbtn = QtWidgets.QPushButton("Export") expbtn = QtWidgets.QPushButton("Export")
"""expbtn.clicked.connect(lambda: export_dial( """expbtn.clicked.connect(lambda: export_dial(
augCanvas, drls, dialspect, reactlabels, parselect))""" augCanvas, drls, dialspect, reactlabels, parselect))"""
buttlayout = QtWidgets.QHBoxLayout() buttlayout = QtWidgets.QHBoxLayout()
buttlayout.addWidget(pushbtn) buttlayout.addWidget(updatebtn)
buttlayout.addStretch()
buttlayout.addWidget(addbtn)
buttlayout.addWidget(rmbtn)
buttlayout.addStretch() buttlayout.addStretch()
buttlayout.addWidget(expbtn) buttlayout.addWidget(expbtn)
#layouts.append(buttlayout)
dial_layout = QtWidgets.QVBoxLayout(dial_widget) dial_layout = QtWidgets.QVBoxLayout(dial_widget)
dial_layout.addWidget(graph_canvas, stretch=1) dial_layout.addWidget(graph_canvas, stretch=1)
dial_layout.addWidget(ionstable) dial_layout.addWidget(ionstable)
dial_layout.addLayout(buttlayout) dial_layout.addLayout(buttlayout)
#[dial_layout.addLayout(i) for i in layouts]
dial_widget.setFocus() dial_widget.setFocus()
dial_widget.show() dial_widget.show()
#update_fnc() update_fnc()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment