From 557584aad954ba956bf40a5e11405059bfe2f9ea Mon Sep 17 00:00:00 2001 From: jens Date: Wed, 25 Nov 2020 21:03:18 +0100 Subject: [PATCH] nm scale now ok check for missing calibration next --- CCDpanelsetup.py | 66 ++++++++++++++++++++++++++++++++---------------- CCDplots.py | 2 +- JFSphoto.py | 23 +++++++++-------- pyCCDGUI.py | 2 +- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/CCDpanelsetup.py b/CCDpanelsetup.py index f8f3859..02dd216 100644 --- a/CCDpanelsetup.py +++ b/CCDpanelsetup.py @@ -74,7 +74,8 @@ class buildpanel(tk.Frame): self.saveopenfields(save_row, CCDplot) self.updateplotfields(update_row, CCDplot) # - self.jfsAddOns(JFSphoto) + self.jf = JFSphoto + self.jfsAddOns(CCDplot,JFSphoto) @@ -224,14 +225,18 @@ class buildpanel(tk.Frame): # # - def jfsAddOns(self,JFSphoto): - jfs = JFSphoto - self.jfstitel = tk.Label(self, text=' Photometer ',width=20) - self.jfstitel.config(font=("Courier",0)) - self.jfstitel.grid(row=10,column=4) - self.jfs4nm = tk.Button(self,text='Choose Color',fg="darkgreen", command=jfs.test1) - self.jfs4nm.grid(row=20,column=4) + def jfsAddOns(self,CCDplot,JFSphoto): + + self.jfstitel = tk.Label(self, text=' Photometer ') + #self.jfstitel.config(font=("Courier",0)) + self.jfstitel.grid(row=10,column=4,columnspan=2) + self.jfs4cal = tk.Button(self,text='Calibration',fg="blue", command=JFSphoto.do_calibrate) + self.jfs4cal.grid(row=11,column=4) + #self.jfs4nm = tk.Button(self,text='set nm-axis',fg="blue", command=lambda CCDplot=CCDplot,JFSphoto=JFSphoto: self.updateplot_jfs(CCDplot,JFSphoto)) + #self.jfs4nm.grid(row=12,column=4) + self.jfs4nm_check = tk.Checkbutton(self,text="[nm] scale on/off",variable=JFSphoto.nm_checked,command=lambda CCDplot=CCDplot: self.updateplot(CCDplot)) + self.jfs4nm_check.grid(row=13,column=4) ### Callbacks for traces, buttons, etc ### def callback(self): @@ -304,7 +309,9 @@ class buildpanel(tk.Frame): status.set("Device doesn't exist") colr.configure(fg="red") - def updateplot_old(self, CCDplot): + def updateplot_jfs(self, CCDplot,JFSphoto): + # plots data with a nm-scale + # makes the max value visble #This subtracts the ADC-pixel from ADC-dark if (config.datainvert==1): config.pltData16 = (config.rxData16[10]+config.rxData16[11])/2 - config.rxData16 @@ -316,21 +323,22 @@ class buildpanel(tk.Frame): CCDplot.a.clear() #plot intensities if (config.datainvert == 1): - CCDplot.a.plot(config.pltData16) + ## make max visible + up = np.max(config.pltData16) + 50 + CCDplot.a.plot(JFSphoto.get_nm_scale(),config.pltData16) CCDplot.a.set_ylabel("Intensity") - CCDplot.a.axis([0,3694,-10,2250]) + CCDplot.a.axis([JFSphoto.nm_left,JFSphoto.nm_right,-10,up]) else: #plot raw data - CCDplot.a.plot(config.rxData16) + CCDplot.a.plot(JFSphoto.get_nm_scale(),config.rxData16) CCDplot.a.set_ylabel("ADCcount") - CCDplot.a.axis([0,3694,-10,4095]) - CCDplot.a.set_xlabel("Pixelnumber") + CCDplot.a.axis([JFSphoto.nm_left,JFSphoto.nm_right,-10,4095]) + CCDplot.a.set_xlabel("[nm]") CCDplot.canvas.draw() def updateplot(self, CCDplot): #This subtracts the ADC-pixel from ADC-dark - ### jfs print("update plot "+str(config.datainvert)) if (config.datainvert==1): config.pltData16 = (config.rxData16[10]+config.rxData16[11])/2 - config.rxData16 #This subtracts the average difference between even and odd pixels from the even pixels @@ -341,16 +349,30 @@ class buildpanel(tk.Frame): CCDplot.a.clear() #plot intensities if (config.datainvert == 1): - CCDplot.a.plot(config.pltData16) + ## make max visible + up = np.max(config.pltData16) + 50 + if (self.jf.get_nm_checked()==1): + CCDplot.a.plot(self.jf.get_nm_scale(),config.pltData16) + CCDplot.a.axis([self.jf.nm_left,self.jf.nm_right,-10,up]) + CCDplot.a.set_xlabel(" [nm] ") + else: + CCDplot.a.plot(config.pltData16) + CCDplot.a.axis([0,3694,-10,4095]) + CCDplot.a.set_xlabel("Pixelnumber") CCDplot.a.set_ylabel("Intensity") - CCDplot.a.axis([0,3694,-10,2250]) + else: - #plot raw data - CCDplot.a.plot(config.rxData16) + if (self.jf.get_nm_checked()==1): + CCDplot.a.plot(self.jf.get_nm_scale(),config.rxData16) + CCDplot.a.axis([self.jf.nm_left,self.jf.nm_right,-10,4095]) + CCDplot.a.set_xlabel(" [nm] ") + else: + CCDplot.a.plot(config.rxData16) + CCDplot.a.axis([0,3694,-10,4095]) + CCDplot.a.set_xlabel("Pixelnumber") CCDplot.a.set_ylabel("ADCcount") - CCDplot.a.axis([0,3694,-10,4095]) - CCDplot.a.set_xlabel("Pixelnumber") - + #plot raw data + CCDplot.canvas.draw() \ No newline at end of file diff --git a/CCDplots.py b/CCDplots.py index 713baf6..00c2265 100644 --- a/CCDplots.py +++ b/CCDplots.py @@ -37,7 +37,7 @@ from matplotlib.backend_bases import key_press_handler from matplotlib.figure import Figure -class buildplot(tk.Frame): +class buildplot(tk.Frame ): def __init__(self, master): #create canvas self.f = Figure(figsize=(10, 5), dpi=100, tight_layout=True) diff --git a/JFSphoto.py b/JFSphoto.py index bd259d2..32a9dc1 100644 --- a/JFSphoto.py +++ b/JFSphoto.py @@ -22,11 +22,14 @@ class Jfsphoto (object): self.tnm_right = tk.StringVar() self.tnm_step = tk.StringVar() self.nmData16 = np.zeros(3694, np.uint16) + ########## nm scale checkButton default nm-scale is off + self.nm_checked = tk.IntVar() + self.nm_checked.set(0) - def test1(self): + def do_calibrate(self): win = tk.Toplevel() win.geometry("450x200+100+100") - self.lab1 = tk.Label(win, text='please enter filenames and nm of the peaks').grid(row=0,column=0,columnspan=6) + self.lab1 = tk.Label(win, text='Please enter filenames and nm of the peaks').grid(row=0,column=0,columnspan=6) ########## first peak self.tnm = tk.StringVar() self.tnm.set(str(self.nm)) @@ -63,15 +66,12 @@ class Jfsphoto (object): self.bt3.grid(row=4,column=0) self.bt4 = tk.Button(win,text="Load Config",command=self.conf_read).grid(row=4,column=1) self.bt5 = tk.Button(win,text="Save Config",command=self.conf_write).grid(row=4,column=2) - #a=tk.Label(win,text='Hi there') - #a.place(x=10,y=10,width=40,height=25) - #b=tk.Button(win,text='Ok then',command=win.destroy) - #b.place(x=60,y=10,width=60,height=25) - ## modal + ########### dialog modal win.focus_set() win.grab_set() win.wait_window() + def checkit(self): self.nm = int(self.tnm.get()) self.nmi = int(self.tnmi.get()) @@ -89,12 +89,15 @@ class Jfsphoto (object): self.tnm_right.set(str(self.nm_right)) self.tnm_step.set(str(self.nm_step)) + def get_nm_checked(self): + return self.nm_checked.get() def set_nm_scale(self): - if ((self.nm_step > 0) & (self.nm_left > 0)): - for i in range(0,3694): - self.nmData16[i] = self.nm_left + self.nm_step*i + self.nmData16 = np.linspace(self.nm_left,self.nm_right,3694) + def get_nm_scale(self): + self.set_nm_scale() + return self.nmData16 def openfile(self,xx): rxData16 = np.zeros(3694, np.uint16) diff --git a/pyCCDGUI.py b/pyCCDGUI.py index eaf7e46..91f0a00 100644 --- a/pyCCDGUI.py +++ b/pyCCDGUI.py @@ -48,7 +48,7 @@ if __name__ == '__main__': CCDplot = CCDplots.buildplot(root) jfs =Jfsphoto() jfs.conf_read() - panel = CCDpanelsetup.buildpanel(root, CCDplot, SerQueue,jfs) + panel = CCDpanelsetup.buildpanel(root, CCDplot, SerQueue, jfs) panel.grid(row=0, column=2) root.mainloop()