Jul-25-2018, 01:01 AM
Hello everyone
Can someone help me with the following:
I have a code with three buttons, two buttons read a data spectrum and find the number of peaks of each. Each function that is called returns the number of peaks.
A third button should verify a comparison between these two data that are returned (number of peaks in each spectrum). However I do not know how to set the parameters to the function when it must be invoked from the third button.
Will someone have a similar code?
This is the code
def load_ctrl():
path=StringVar()
filename = tkFileDialog.askopenfilename(initialdir = "/home/pi/Desktop/Programas",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*")))
shift = open("XAcetominofeno.txt") #XCiprofloxacino, XAcetominofeno
path=filename
c1 = shift.read()
d1 = c1.split()
datos1 = []
for i in d1:
datos1.append(float(i))
intensity = open(path)
c2 = intensity.read()
d2 = c2.split()
datos2 = []
for i in d2:
datos2.append(float(i))
#---------------DETECCION DE PICOS------------------------------
indexes1 = scipy.signal.find_peaks_cwt(datos2, np.arange(3, 5),
max_distances=np.arange(2, 5)*10)
indexes1 = np.array(indexes1) - 1
length_a=len(indexes1)
dx=[]
dy=[]
plt.figure('Raman spectrum')
plt.xlim(100,1800)
plt.axes()
plt.grid()
plt.xlabel('Raman Shift (cm-1)')
plt.ylabel('Intnesity (a.u)')
plt.plot(datos1, datos2,'r-')
for j in range(length_a):
a=indexes1[j]
dx=datos1[a]
dy=datos2[a]
plt.plot(dx, dy,'b*')
plt.show()
return length_a
#----------DEFINIENDO FUNCIONES DE DRUG TEST-------------
def load_drug():
pathx=StringVar()
filenamex = tkFileDialog.askopenfilename(initialdir = "/home/pi/Desktop/Programas",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*")))
shift = open("XCiprofloxacino.txt") #XCiprofloxacino, XAcetominofeno
pathx=filenamex
c1 = shift.read()
d1 = c1.split()
datos11 = []
for i in d1:
datos11.append(float(i))
intensity = open(pathx)
c2 = intensity.read()
d2 = c2.split()
datos22 = []
for i in d2:
datos22.append(float(i))
#---------------DETECCION DE PICOS------------------------------
indexes2 = scipy.signal.find_peaks_cwt(datos22, np.arange(3, 5),
max_distances=np.arange(2, 5)*10)
indexes2 = np.array(indexes2) - 1
length_b=len(indexes2)
dx=[]
dy=[]
plt.figure('Raman spectrum')
plt.xlim(100,1800)
plt.axes()
plt.grid()
plt.xlabel('Raman Shift (cm-1)')
plt.ylabel('Intnesity (a.u)')
plt.plot(datos11, datos22,'b-')
for k in range(length_b):
a=indexes2[k]
dx=datos11[a]
dy=datos22[a]
plt.plot(dx, dy,'r*')
plt.show()
return length_b
#----------DEFINIENDO FUNCIONES DE TEST------------------
def test_drug(v,length_a,length_b):
if length_a>length_b:
print "NO PASS"
msge=Label(v,text="NO PASS",fg="red",height=2,font="Helvetica 14 bold").place(x=40,y=312)
else:
print "PASS"
msge=Label(v,text="PASS",fg="green",height=2,font="Helvetica 14 bold").place(x=48,y=312)
return
#-------------------DEFINIENDO BOTONES-------------------
loadctrl=Button(v,text="Load Reference",font=buttom_p,fg="black",height=2,width=12,command=load_ctrl).place(x=16,y=90)
loadsample=Button(v,text="Drug test",font=buttom_p,fg="black",height=2,width=12, command=load_drug).place(x=16,y=143)
sampletest=Button(v,text="Test",font=buttom_p,fg="black",height=2,width=12, command=lambda:test_drug(v,21,5)).place(x=16,y=195)
start=Button(v,text="Initialize",font=buttom_p,fg="black",height=2,width=12,command=set_globalvar).place(x=16,y=248)
exit=Button(v,text="Exit",font=exit_p,fg="red",height=3,width=10, command=v.quit).place(x=18,y=360)
v.mainloop()
Can someone help me with the following:
I have a code with three buttons, two buttons read a data spectrum and find the number of peaks of each. Each function that is called returns the number of peaks.
A third button should verify a comparison between these two data that are returned (number of peaks in each spectrum). However I do not know how to set the parameters to the function when it must be invoked from the third button.
Will someone have a similar code?
This is the code
def load_ctrl():
path=StringVar()
filename = tkFileDialog.askopenfilename(initialdir = "/home/pi/Desktop/Programas",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*")))
shift = open("XAcetominofeno.txt") #XCiprofloxacino, XAcetominofeno
path=filename
c1 = shift.read()
d1 = c1.split()
datos1 = []
for i in d1:
datos1.append(float(i))
intensity = open(path)
c2 = intensity.read()
d2 = c2.split()
datos2 = []
for i in d2:
datos2.append(float(i))
#---------------DETECCION DE PICOS------------------------------
indexes1 = scipy.signal.find_peaks_cwt(datos2, np.arange(3, 5),
max_distances=np.arange(2, 5)*10)
indexes1 = np.array(indexes1) - 1
length_a=len(indexes1)
dx=[]
dy=[]
plt.figure('Raman spectrum')
plt.xlim(100,1800)
plt.axes()
plt.grid()
plt.xlabel('Raman Shift (cm-1)')
plt.ylabel('Intnesity (a.u)')
plt.plot(datos1, datos2,'r-')
for j in range(length_a):
a=indexes1[j]
dx=datos1[a]
dy=datos2[a]
plt.plot(dx, dy,'b*')
plt.show()
return length_a
#----------DEFINIENDO FUNCIONES DE DRUG TEST-------------
def load_drug():
pathx=StringVar()
filenamex = tkFileDialog.askopenfilename(initialdir = "/home/pi/Desktop/Programas",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*")))
shift = open("XCiprofloxacino.txt") #XCiprofloxacino, XAcetominofeno
pathx=filenamex
c1 = shift.read()
d1 = c1.split()
datos11 = []
for i in d1:
datos11.append(float(i))
intensity = open(pathx)
c2 = intensity.read()
d2 = c2.split()
datos22 = []
for i in d2:
datos22.append(float(i))
#---------------DETECCION DE PICOS------------------------------
indexes2 = scipy.signal.find_peaks_cwt(datos22, np.arange(3, 5),
max_distances=np.arange(2, 5)*10)
indexes2 = np.array(indexes2) - 1
length_b=len(indexes2)
dx=[]
dy=[]
plt.figure('Raman spectrum')
plt.xlim(100,1800)
plt.axes()
plt.grid()
plt.xlabel('Raman Shift (cm-1)')
plt.ylabel('Intnesity (a.u)')
plt.plot(datos11, datos22,'b-')
for k in range(length_b):
a=indexes2[k]
dx=datos11[a]
dy=datos22[a]
plt.plot(dx, dy,'r*')
plt.show()
return length_b
#----------DEFINIENDO FUNCIONES DE TEST------------------
def test_drug(v,length_a,length_b):
if length_a>length_b:
print "NO PASS"
msge=Label(v,text="NO PASS",fg="red",height=2,font="Helvetica 14 bold").place(x=40,y=312)
else:
print "PASS"
msge=Label(v,text="PASS",fg="green",height=2,font="Helvetica 14 bold").place(x=48,y=312)
return
#-------------------DEFINIENDO BOTONES-------------------
loadctrl=Button(v,text="Load Reference",font=buttom_p,fg="black",height=2,width=12,command=load_ctrl).place(x=16,y=90)
loadsample=Button(v,text="Drug test",font=buttom_p,fg="black",height=2,width=12, command=load_drug).place(x=16,y=143)
sampletest=Button(v,text="Test",font=buttom_p,fg="black",height=2,width=12, command=lambda:test_drug(v,21,5)).place(x=16,y=195)
start=Button(v,text="Initialize",font=buttom_p,fg="black",height=2,width=12,command=set_globalvar).place(x=16,y=248)
exit=Button(v,text="Exit",font=exit_p,fg="red",height=3,width=10, command=v.quit).place(x=18,y=360)
v.mainloop()