Commit f5253e0b authored by Yan's avatar Yan
Browse files

Redone annotation, removed scipy dependency.

parent af41f521
......@@ -5,8 +5,9 @@ from matplotlib.figure import Figure
from matplotlib.widgets import SpanSelector
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from rawFin2 import load_raw
from scipy.signal import find_peaks
#from rawFin2 import load_raw
from rawParse import load_raw
#from scipy.signal import find_peaks
import sys
import matplotlib
import numpy as np
......@@ -100,12 +101,19 @@ def pick_times(x_min, x_max, mpl_spectrum, data_set, mpl_chromatogram, an, ms_s)
spectrum_plot(spectrum, ms['x'], ms['y'], an)
mpl_chromatogram.clear()
chrom_plot(mpl_chromatogram, data_set['chrom_dat'][0, :], data_set['chrom_dat'][1, :])
mpl_chromatogram.plot(data_set['chrom_dat'][0, start_scan:end_scan], data_set['chrom_dat'][1, start_scan:end_scan], 'b.')
mpl_chromatogram.plot(data_set['chrom_dat'][0, start_scan:end_scan],
data_set['chrom_dat'][1, start_scan:end_scan],
'b.')
def populate(mpl_chromatogram, mpl_spectrum, data_set, time_sel, an, ms_s):
an.clear()
def update_span_selector(chrom, spec, d_set, ms_spec):
time_selector = SpanSelector(chrom, lambda x_min, x_max: pick_times(x_min, x_max, spec, d_set, chrom, an, ms_spec), 'horizontal', useblit=True, rectprops=dict(alpha=0.15, facecolor='purple'), button=3)
time_selector = SpanSelector(chrom,
lambda x_min, x_max: pick_times(x_min, x_max, spec, d_set, chrom, an, ms_spec),
'horizontal',
useblit=True,
rectprops=dict(alpha=0.15, facecolor='purple'),
button=3)
return time_selector
mpl_spectrum.clear()
mpl_chromatogram.clear()
......@@ -117,35 +125,51 @@ def populate(mpl_chromatogram, mpl_spectrum, data_set, time_sel, an, ms_s):
mpl_chromatogram.figure.canvas.draw()
mpl_spectrum.figure.canvas.draw()
def ann_spec(ms_spec, mass, intensity, an):
def sub_peaks(peakz, x_value, y_value, x, y):
gp=[]
sp=[]
for g in peakz:
if gp == [] or (abs(max(y_value[gp]) - y_value[g]) * 10 < y and abs(x_value[gp[np.argmax(y_value[gp])]] - x_value[g]) * 20 < x):
gp.append(g)
else:
sp.append(gp[np.argmax(y_value[gp])])
gp = [g]
if g == peakz[-1]:
sp.append(gp[np.argmax(y_value[gp])])
return sp
def ann_spec(ms_spec, mass, intensity, an, ann_limit=0.01):
def sub_peaks(peakz, x_value, y_value, x, y, coef_x=10, coef_y=10):
sp = sorted(peakz,
key=lambda h: y_value[h],
reverse=True)
sub=[]
rx = x/coef_x
ry = y/coef_y
for g in sp:
add = True
yv = y_value[g]
xv = x_value[g]
for u in sub:
if abs(yv - y_value[u]) < ry and abs(xv - x_value[u]) < rx:
add = False
if add:
sub.append(g)
return sub
borders=ms_spec.get_xlim()
start = np.argmax(mass>borders[0])
end = np.argmax(mass>borders[1])
if end == 0:
end = np.argmax(mass)
peaks = find_peaks(intensity[start:end], height=ms_spec.get_ylim()[1] / 100)
peaks = peaks[0] + start
s_peaks = sub_peaks(peaks, mass, intensity, ms_spec.get_xlim()[1] - ms_spec.get_xlim()[0], ms_spec.get_ylim()[1] - ms_spec.get_ylim()[0])
wstart = np.argmax(mass>borders[0])
wend = np.argmax(mass>borders[1])
if wend == 0:
wend = np.argmax(mass)
#peaks = find_peaks(intensity[wstart:wend], height=ms_spec.get_ylim()[1] / 100)
peaks = []
l = ms_spec.get_ylim()[1] * ann_limit
q = intensity
for i,j in enumerate(q[wstart:wend], start=wstart):
#wend selects the first element which not to include.
#Thus q[i+1] always exists as it points to that last element.
if j > l and j > q[i-1] and j > q[i+1]:
peaks.append(i)
s_peaks = sub_peaks(peaks, mass, intensity,
ms_spec.get_xlim()[1] - ms_spec.get_xlim()[0],
ms_spec.get_ylim()[1] - ms_spec.get_ylim()[0])
for j in an:
j.remove()
an.clear()
for i in s_peaks:
an.append(ms_spec.annotate('{0:.2f}'.format(mass[i]), xy=(mass[i], intensity[i]), textcoords='data'))
an.append(ms_spec.annotate('{0:.2f}'.format(mass[i]),
xy=(mass[i], intensity[i]),
textcoords='data'))
def spectrum_plot(spc, mass, intensity, an):
spc.plot(mass, intensity)
......
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