Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jan Zelenka
prasopes
Commits
43a2f24b
Commit
43a2f24b
authored
Aug 28, 2018
by
Yan
Browse files
Merge branch 'master' pt 2/2
parent
7c665cde
Changes
1
Hide whitespace changes
Inline
Side-by-side
prasopes/zcetools.py
0 → 100644
View file @
43a2f24b
import
numpy
as
np
import
prasopes.graphtools
as
gt
import
os.path
from
matplotlib.backends.backend_qt5agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
from
PyQt5
import
QtCore
from
PyQt5
import
QtWidgets
def
pop_dial
(
zcespec
,
gradspect
,
data_set
,
widget
,
coff_d
,
grad_d
,
textfield
,
fn
,
parent
):
if
fn
[
0
]
is
None
:
QtWidgets
.
QMessageBox
.
warning
(
parent
,
"ZCE calculation"
,
"No spectrum opened, cancelling request"
)
return
zcespec
.
clear
()
gradspect
.
clear
()
coff_d
[
'x'
]
=
data_set
[
'masses'
]
-
196
coff_d
[
'y'
]
=
np
.
mean
(
data_set
[
'matrix'
],
axis
=
0
)
grad_d
[
'x'
]
=
coff_d
[
'x'
]
grad_d
[
'y'
]
=
-
np
.
gradient
(
coff_d
[
'y'
])
gt
.
pop_plot
(
zcespec
,
coff_d
)
gt
.
pop_plot
(
gradspect
,
grad_d
)
grad_d
[
'line'
][
0
].
set_color
(
"red"
)
gradspect
.
set_ylim
(
bottom
=
gradspect
.
get_ylim
()[
1
]
*
-
0.1
)
zcespec
.
set_title
(
"COFF"
,
loc
=
"center"
)
maxarg
=
np
.
argmax
(
grad_d
[
'y'
])
grad_d
[
'gmax'
]
=
coff_d
[
'x'
][
maxarg
]
climb
=
np
.
argsort
(
grad_d
[
'y'
][:
maxarg
])
fall
=
np
.
argsort
(
grad_d
[
'y'
][
maxarg
:])
+
maxarg
halfmax
=
np
.
max
(
grad_d
[
'y'
])
/
2
grad_d
[
'fwhm_y'
]
=
[
halfmax
,
halfmax
]
grad_d
[
'fwhm_x'
]
=
[
np
.
interp
(
halfmax
,
grad_d
[
'y'
][
climb
],
grad_d
[
'x'
][
climb
]),
np
.
interp
(
halfmax
,
grad_d
[
'y'
][
fall
],
grad_d
[
'x'
][
fall
])]
grad_d
[
'fwhm'
]
=
grad_d
[
'fwhm_x'
][
1
]
-
grad_d
[
'fwhm_x'
][
0
]
gradspect
.
plot
(
grad_d
[
'fwhm_x'
],
grad_d
[
'fwhm_y'
],
"#880088"
)
textfield
.
setText
(
"ZCE = {:.2f}
\n
FWHM = {:.2f}
\n
Center(HM) = {:.2f}"
.
format
(
grad_d
[
'gmax'
],
grad_d
[
'fwhm'
],
np
.
mean
(
grad_d
[
'fwhm_x'
])))
gradspect
.
annotate
(
' FWHM = {:.2f}'
.
format
(
grad_d
[
'fwhm'
]),
xy
=
(
grad_d
[
'fwhm_x'
][
1
],
grad_d
[
'fwhm_y'
][
1
]))
gradspect
.
annotate
(
'{:.2f}'
.
format
(
grad_d
[
'gmax'
]),
xy
=
(
grad_d
[
'x'
][
maxarg
],
grad_d
[
'y'
][
maxarg
]))
zcespec
.
figure
.
canvas
.
draw
()
widget
.
show
()
def
exp_zce
(
zce_spec
,
zcegrad_spec
,
fn
,
parent
):
"""export the ZCE graph into the .dat file format"""
if
fn
[
0
]
is
None
:
QtWidgets
.
QMessageBox
.
warning
(
parent
,
"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
(
parent
,
"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
()
def
dialog
(
parent
,
ds
,
filename
):
coff
=
dict
(
x
=
[
0
],
y
=
[
0
],
line
=
None
,
name
=
""
,
xlabel
=
"Voltage (V)"
,
ylabel
=
"ion count"
)
coffgrad
=
dict
(
x
=
[
0
],
y
=
[
0
],
c_ymin
=-
0.1
,
line
=
None
,
name
=
""
,
xlabel
=
""
,
ylabel
=
"ion count gradient"
,
gmax
=
None
,
fwhm_x
=
None
,
fwhm_y
=
None
,
fwhm
=
None
)
dial_widget
=
QtWidgets
.
QDialog
(
parent
)
dial_widget
.
setWindowTitle
(
'TSQ zero collision energy calculator'
)
dial_graph
=
Figure
(
figsize
=
(
5
,
2
),
dpi
=
100
)
dial_graph
.
patch
.
set_facecolor
(
"None"
)
coffspect
=
dial_graph
.
add_subplot
(
111
,
facecolor
=
(
1
,
1
,
1
,
0.8
))
coffspect_grad
=
coffspect
.
twinx
()
graph_canvas
=
FigureCanvas
(
dial_graph
)
graph_canvas
.
setStyleSheet
(
"background-color:transparent;"
)
graph_canvas
.
setAutoFillBackground
(
False
)
graph_canvas
.
setFocusPolicy
(
QtCore
.
Qt
.
ClickFocus
)
gt
.
zoom_factory
(
coffspect_grad
,
1.15
,
coffgrad
)
gt
.
pan_factory
(
coffspect_grad
,
coffgrad
)
zce_export
=
QtWidgets
.
QPushButton
(
"Export ZCE"
)
zce_export
.
clicked
.
connect
(
lambda
:
exp_zce
(
coff
,
coffgrad
,
filename
,
parent
))
zce_help
=
QtWidgets
.
QPushButton
(
"Help"
)
close_button
=
QtWidgets
.
QPushButton
(
"Close"
)
close_button
.
clicked
.
connect
(
dial_widget
.
close
)
butt_layout
=
QtWidgets
.
QHBoxLayout
()
butt_layout
.
addWidget
(
zce_help
)
butt_layout
.
addStretch
(
1
)
textfield
=
QtWidgets
.
QLabel
(
coffgrad
[
'gmax'
])
butt_layout
.
addWidget
(
textfield
)
butt_layout
.
addStretch
(
1
)
butt_layout
.
addWidget
(
zce_export
)
butt_layout
.
addWidget
(
close_button
)
dial_layout
=
QtWidgets
.
QVBoxLayout
(
dial_widget
)
dial_layout
.
addWidget
(
graph_canvas
)
dial_layout
.
addLayout
(
butt_layout
)
pop_dial
(
coffspect
,
coffspect_grad
,
ds
,
dial_widget
,
coff
,
coffgrad
,
textfield
,
filename
,
parent
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment