Commit 7dbca9a5 authored by Yan's avatar Yan
Browse files

export ZCE button working.

parent a48d39a6
......@@ -252,7 +252,7 @@ def open_file(chrom_plot, spc, d_set, ms_s, fn, chrom_s):
def export(mass_spec, chrom_spec, fn):
"""exports the chromatogram into the .dat file format"""
"""exports the spectrum into the .dat file format"""
if fn[0] is None:
QtWidgets.QMessageBox.warning(
main_window, "Export spectrum",
......@@ -310,22 +310,65 @@ def pop_zce(zcespec, gradspect, data_set, widget, zce_d, zgrad_d,
climb = np.argsort(zgrad_d['y'][:maxarg])
fall = np.argsort(zgrad_d['y'][maxarg:]) + maxarg
halfmax = np.max(zgrad_d['y']) / 2
fwhm_d = dict(y=[halfmax, halfmax], x=[
zgrad_d['fwhm_y'] = [halfmax, halfmax]
zgrad_d['fwhm_x'] = [
np.interp(halfmax, zgrad_d['y'][climb], zgrad_d['x'][climb]),
np.interp(halfmax, zgrad_d['y'][fall], zgrad_d['x'][fall])])
np.interp(halfmax, zgrad_d['y'][fall], zgrad_d['x'][fall])]
zgrad_d['fwhm'] = zgrad_d['fwhm_x'][1] - zgrad_d['fwhm_x'][0]
gradspect.plot(fwhm_d['x'], fwhm_d['y'], "#880088")
gradspect.plot(zgrad_d['fwhm_x'], zgrad_d['fwhm_y'], "#880088")
textfield.setText("ZCE = {:.2f}\nFWHM = {:.2f}\nCenter(HM) = {:.2f}".
format(zgrad_d['gmax'], fwhm_d['x'][1] - fwhm_d['x'][0], np.mean(fwhm_d['x'])))
gradspect.annotate(' FWHM = {:.2f}'.format(fwhm_d['x'][1]-fwhm_d['x'][0]),
xy=(fwhm_d['x'][1], fwhm_d['y'][1]))
textfield.setText(
"ZCE = {:.2f}\nFWHM = {:.2f}\nCenter(HM) = {:.2f}".format(
zgrad_d['gmax'], zgrad_d['fwhm'],
np.mean(zgrad_d['fwhm_x'])))
gradspect.annotate(' FWHM = {:.2f}'.format(zgrad_d['fwhm']),
xy=(zgrad_d['fwhm_x'][1], zgrad_d['fwhm_y'][1]))
gradspect.annotate('{:.2f}'.format(zgrad_d['gmax']),
xy=(zgrad_d['x'][maxarg], zgrad_d['y'][maxarg]))
zcespec.figure.canvas.draw()
widget.show()
def exp_zce(zce_spec, zcegrad_spec, fn, widget):
"""export the ZCE graph into the .dat file format"""
if fn[0] is None:
QtWidgets.QMessageBox.warning(
main_window, "Export ZCE spectrum",
"Nothing to export, cancelling request")
return
exp_f_name = QtWidgets.QFileDialog.getSaveFileName(
caption="Export ZCE spectrum",
filter="dat table format (*.dat)")[0]
if exp_f_name is not '':
# fix for Qt5 "Feature"
if exp_f_name[-4:] != '.dat':
exp_f_name = exp_f_name + ".dat"
if os.path.isfile(exp_f_name):
quest = QtWidgets.QMessageBox.warning(
main_window, "Export spectrum",
"{} already exists.\n Do you want to replace it?"
.format(os.path.basename(exp_f_name)),
QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
if(hex(quest)) == "0x10000":
return
expf = open(exp_f_name, 'w')
expf.write("mass ion_count ion_count_gradient fwhm_x fwhm_y\n"
"m/z\n"
"{} zce={} fwhm={} hmcenter={}\n".format(
os.path.basename(fn[0]), zcegrad_spec['gmax'],
zcegrad_spec['fwhm'],
np.mean(zcegrad_spec['fwhm_x'])))
for i in range(len(zce_spec['x'])):
fwhm = ["",""]
if i <= 1:
fwhm = [zcegrad_spec['fwhm_x'][i],
zcegrad_spec['fwhm_y'][i]]
expf.write("{} {} {} {} {}\n".format(
zce_spec['x'][i], zce_spec['y'][i], zcegrad_spec['y'][i],
fwhm[0], fwhm[1]))
expf.close()
if __name__ == "__main__":
# ds for data_set, ms for mass_spec_dataset, chrom for chrom_dataset
......@@ -374,7 +417,8 @@ if __name__ == "__main__":
zce = dict(x=[0], y=[0], line=None, name="",
xlabel="Voltage (V)", ylabel="ion count")
zcegrad = dict(x=[0], y=[0], c_ymin=-0.1, line=None, name="",
xlabel="", ylabel="ion count gradient", gmax=None)
xlabel="", ylabel="ion count gradient", gmax=None,
fwhm_x=None,fwhm_y=None, fwhm=None)
zce_graph = Figure(figsize=(5, 2), dpi=100)
zce_graph.patch.set_facecolor("None")
zce_spect = zce_graph.add_subplot(111, facecolor=(1, 1, 1, 0.8))
......@@ -388,6 +432,7 @@ if __name__ == "__main__":
pan_factory(zce_spect_grad, zcegrad)
zce_export = QtWidgets.QPushButton("Export ZCE")
zce_export.clicked.connect(lambda: exp_zce(zce,zcegrad,filename, zce_widget))
zce_help = QtWidgets.QPushButton("Help")
zce_close = QtWidgets.QPushButton("Close")
......
Supports Markdown
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