Load and save csv file implemented
This commit is contained in:
parent
6b414ba99c
commit
67d818cdac
@ -238,6 +238,13 @@ class buildpanel(tk.Frame):
|
|||||||
self.jfsbase_check.config(state=tk.NORMAL)
|
self.jfsbase_check.config(state=tk.NORMAL)
|
||||||
self.jfsbase_transmission.config(state=tk.NORMAL)
|
self.jfsbase_transmission.config(state=tk.NORMAL)
|
||||||
self.jfsbase_absorption.config(state=tk.NORMAL)
|
self.jfsbase_absorption.config(state=tk.NORMAL)
|
||||||
|
def loaddata():
|
||||||
|
self.jf.load_pandas()
|
||||||
|
self.updateplot(CCDplot)
|
||||||
|
self.jfsdark_check.config(state=tk.NORMAL)
|
||||||
|
self.jfsbase_check.config(state=tk.NORMAL)
|
||||||
|
self.jfsbase_transmission.config(state=tk.NORMAL)
|
||||||
|
self.jfsbase_absorption.config(state=tk.NORMAL)
|
||||||
|
|
||||||
self.jfstitel = tk.Label(self, text=' Photometer ')
|
self.jfstitel = tk.Label(self, text=' Photometer ')
|
||||||
#self.jfstitel.config(font=("Courier",0))
|
#self.jfstitel.config(font=("Courier",0))
|
||||||
@ -260,6 +267,8 @@ class buildpanel(tk.Frame):
|
|||||||
self.jfsbase_transmission.grid(row=18,column=4)
|
self.jfsbase_transmission.grid(row=18,column=4)
|
||||||
self.jfspdsave = tk.Button(self,text='save Data',fg="blue", command=self.jf.save_pandas)
|
self.jfspdsave = tk.Button(self,text='save Data',fg="blue", command=self.jf.save_pandas)
|
||||||
self.jfspdsave.grid(row=19,column=4)
|
self.jfspdsave.grid(row=19,column=4)
|
||||||
|
self.jfspdload = tk.Button(self,text='load Data',fg="blue", command=loaddata)
|
||||||
|
self.jfspdload.grid(row=20,column=4)
|
||||||
|
|
||||||
### Callbacks for traces, buttons, etc ###
|
### Callbacks for traces, buttons, etc ###
|
||||||
def callback(self):
|
def callback(self):
|
||||||
@ -348,7 +357,7 @@ class buildpanel(tk.Frame):
|
|||||||
config.pltData16[i] = (config.pltData16[i] / config.pltBaseData16[i])
|
config.pltData16[i] = (config.pltData16[i] / config.pltBaseData16[i])
|
||||||
if (self.jf.abs_trans.get()==1):
|
if (self.jf.abs_trans.get()==1):
|
||||||
config.pltData16 = np.log10(config.pltData16)*-1
|
config.pltData16 = np.log10(config.pltData16)*-1
|
||||||
|
try:
|
||||||
up = np.max(config.pltData16)
|
up = np.max(config.pltData16)
|
||||||
if (self.jf.get_nm_checked()==1):
|
if (self.jf.get_nm_checked()==1):
|
||||||
CCDplot.a.plot(self.jf.get_nm_scale(),config.pltData16)
|
CCDplot.a.plot(self.jf.get_nm_scale(),config.pltData16)
|
||||||
@ -361,6 +370,8 @@ class buildpanel(tk.Frame):
|
|||||||
CCDplot.a.set_xlim([self.jf.baseline_start, self.jf.baseline_end])
|
CCDplot.a.set_xlim([self.jf.baseline_start, self.jf.baseline_end])
|
||||||
CCDplot.a.set_xlabel("Pixelnumber")
|
CCDplot.a.set_xlabel("Pixelnumber")
|
||||||
CCDplot.a.set_ylabel("Intensity")
|
CCDplot.a.set_ylabel("Intensity")
|
||||||
|
except ValueError:
|
||||||
|
messagebox.showerror("By the great otter!","Is there's a problem with the light.\n or disable baseline checkbox")
|
||||||
else:
|
else:
|
||||||
#This subtracts the ADC-pixel from ADC-dark
|
#This subtracts the ADC-pixel from ADC-dark
|
||||||
if (config.datainvert==1):
|
if (config.datainvert==1):
|
||||||
|
|||||||
35
JFSphoto.py
35
JFSphoto.py
@ -7,6 +7,7 @@ import csv
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import config
|
||||||
####################################### object
|
####################################### object
|
||||||
|
|
||||||
class Jfsphoto (object):
|
class Jfsphoto (object):
|
||||||
@ -106,7 +107,7 @@ class Jfsphoto (object):
|
|||||||
return 0
|
return 0
|
||||||
else :
|
else :
|
||||||
self.darkData16 = dark*1.0
|
self.darkData16 = dark*1.0
|
||||||
self.df['darkline']=self.darkData16
|
return 1
|
||||||
|
|
||||||
def get_darkline_checked(self):
|
def get_darkline_checked(self):
|
||||||
return self.darkline_checked.get()
|
return self.darkline_checked.get()
|
||||||
@ -136,7 +137,6 @@ class Jfsphoto (object):
|
|||||||
left = False
|
left = False
|
||||||
self.baseData16[i] = base[i]*1.0
|
self.baseData16[i] = base[i]*1.0
|
||||||
print(self.baseline_start," ",self.baseline_end)
|
print(self.baseline_start," ",self.baseline_end)
|
||||||
self.df['baseline']=self.baseData16
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_baseline_checked(self):
|
def get_baseline_checked(self):
|
||||||
@ -176,20 +176,36 @@ class Jfsphoto (object):
|
|||||||
def set_nm_scale(self):
|
def set_nm_scale(self):
|
||||||
if (self.nm_scale_ok):
|
if (self.nm_scale_ok):
|
||||||
self.nmData16 = np.linspace(self.nm_left,self.nm_right,3694)
|
self.nmData16 = np.linspace(self.nm_left,self.nm_right,3694)
|
||||||
self.df['nmscale']=self.nmData16
|
|
||||||
|
|
||||||
def get_nm_scale(self):
|
def get_nm_scale(self):
|
||||||
self.set_nm_scale()
|
self.set_nm_scale()
|
||||||
return self.nmData16
|
return self.nmData16
|
||||||
|
|
||||||
def add_pandas(self,data):
|
|
||||||
self.df[str(self.pandas_count)] = data
|
|
||||||
##self.pandas_count += 1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def save_pandas(self):
|
def save_pandas(self):
|
||||||
print(self.df.head())
|
filename = filedialog.asksaveasfilename(defaultextension=".csv", title="Save file as")
|
||||||
|
try:
|
||||||
|
self.df['baseline']=self.baseData16
|
||||||
|
self.df['darkline']=self.darkData16
|
||||||
|
self.df['nmscale']=self.nmData16
|
||||||
|
self.df['p1']=config.rxData16
|
||||||
|
self.df.to_csv(filename)
|
||||||
|
except IOError:
|
||||||
|
messagebox.showerror("By the great otter!","There's a problem saving the file.")
|
||||||
|
|
||||||
|
def load_pandas(self):
|
||||||
|
filename = filedialog.askopenfilename(defaultextension=".csv", title="Open file ")
|
||||||
|
try:
|
||||||
|
self.df = pd.read_csv(filename,index_col=0)
|
||||||
|
config.rxData16=self.df['p1']
|
||||||
|
self.do_save_baseline(self.df['baseline'])
|
||||||
|
self.do_save_darkline(self.df['darkline'])
|
||||||
|
self.baseline_checked.set(1)
|
||||||
|
self.darkline_checked.set(1)
|
||||||
|
self.nm_checked.set(1)
|
||||||
|
except IOError:
|
||||||
|
messagebox.showerror("By the great otter!","There's a problem saving the file.")
|
||||||
|
|
||||||
def openfile(self,xx):
|
def openfile(self,xx):
|
||||||
rxData16 = np.zeros(3694, np.uint16)
|
rxData16 = np.zeros(3694, np.uint16)
|
||||||
@ -213,6 +229,7 @@ class Jfsphoto (object):
|
|||||||
self.nm2i = np.argmin(rxData16)
|
self.nm2i = np.argmin(rxData16)
|
||||||
self.tnm2i.set(str(self.nm2i))
|
self.tnm2i.set(str(self.nm2i))
|
||||||
self.checkit()
|
self.checkit()
|
||||||
|
## for testing
|
||||||
self.add_pandas(rxData16)
|
self.add_pandas(rxData16)
|
||||||
except IOError:
|
except IOError:
|
||||||
messagebox.showerror("By the great otter!","There's a problem opening the file.")
|
messagebox.showerror("By the great otter!","There's a problem opening the file.")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user