diff --git a/hp4155/Diode/diode.py b/hp4155/Diode/diode.py index 02b77f207823bf7b50452d17687b1c686c7d88c7..a2bd3a0c569e0810008ceebce0eb1e6e4f52d6fa 100644 --- a/hp4155/Diode/diode.py +++ b/hp4155/Diode/diode.py @@ -6,7 +6,7 @@ import hp4155a from interface import * from help import * -sample = sample_information_interface() +sample,save_plot_button = sample_information_interface() parameters =parameters_interface() button = widgets.Button(description ='Start Measurement') output = widgets.Output() @@ -17,10 +17,13 @@ all_widgets = [button] add_widgets_to_list(sample,all_widgets) add_widgets_to_list(parameters,all_widgets) +fig = None + device = hp4155a.HP4155a('GPIB0::17::INSTR') setup(device) def on_button_clicked(b): with output: + global fig,file clear_output(wait = True) change_state(all_widgets) area=circle_area(sample['radius'].value) @@ -28,12 +31,44 @@ def on_button_clicked(b): valid = check_values(parameters) if valid == True: values = measure(parameters,area,device) - plot_results(values['VS'],values['ABSNOR']) + fig=plot_results(values['VS'],values['ABSNOR']) filename = f"DIODE_{sample['field'].value}.txt" file = create_file(filename) save_to_file(values,sample,parameters,file) change_state(all_widgets) + save_plot_button.disabled = False + +def on_save_plot_button_clicked(b): + with output: + global fig + save_plot_button.disabled = True + change_state(all_widgets) + + filename = f"DIODE_{sample['field'].value}.png" + root = tk.Tk() + root.withdraw() + root.lift() #show window above all other applications + + root.attributes("-topmost", True)#window stays above all other applications + + file = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("Portable Network Graphics","*.png")],title = "Save Plot",initialfile =filename) + + #check if the file path is correct(.txt) + while file.endswith(".png") == False: + #open again filedialog with error message box + answer = tk.messagebox.askyesno(message = "Do you want file operation?") + if answer == True: + file = None + break + file = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("Portable Network Graphics","*.png")],title = "Save Plot",initialfile =filename) + root.destroy() + + if file != None: + fig.savefig(file) + print("Plot Saved Succesfully!") + + change_state(all_widgets) button.on_click(on_button_clicked) - \ No newline at end of file +save_plot_button.on_click(on_save_plot_button_clicked) \ No newline at end of file diff --git a/hp4155/Diode/diode_interface.ipynb b/hp4155/Diode/diode_interface.ipynb index 4e326b4ef9a01e2488a5ea8dc1288d864ed65e63..36b70e047b189b878d62bc8207edf72c41aeefc4 100644 --- a/hp4155/Diode/diode_interface.ipynb +++ b/hp4155/Diode/diode_interface.ipynb @@ -9,7 +9,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e240e0c8ffbf46e28c3f4a9c954fd971", + "model_id": "399e5292f4d947f5b42b6090af57b70d", "version_major": 2, "version_minor": 0 }, @@ -23,7 +23,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "df23c398ef974cbb815bcfba6c3684b2", + "model_id": "7eb1e9d92b4b4801b28229fe7fafc543", "version_major": 2, "version_minor": 0 }, @@ -37,7 +37,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "12b3fe62f6e54596b9d1d0c268f39f80", + "model_id": "68855659a4894faf99c50de161203cef", "version_major": 2, "version_minor": 0 }, @@ -51,7 +51,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "8da3f84d650a44b09fc82b78738b3320", + "model_id": "072519b84c6e4ff399c113b531f0e368", "version_major": 2, "version_minor": 0 }, @@ -64,7 +64,6 @@ } ], "source": [ - "%matplotlib widget\n", "%run diode.py" ] }, diff --git a/hp4155/Diode/lib/help.py b/hp4155/Diode/lib/help.py index 7328986de3be6e7455cd8261669178d9733a777a..6ab3e8455f4a4f0d1133abb9c70bdbe54ad79d96 100644 --- a/hp4155/Diode/lib/help.py +++ b/hp4155/Diode/lib/help.py @@ -38,7 +38,10 @@ def create_file(filename): #check if the file path is correct(.txt) while file.endswith(".txt") == False: #open again filedialog with error message box - tk.messagebox.showerror(message='invalid filename!') + answer = tk.messagebox.askyesno(message = "Do you want file operation?") + if answer == True: + file = None + break file = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files","*.txt")],title = "save results path",initialfile =filename) root.destroy() return file @@ -161,42 +164,47 @@ def measure(parameters,area,device): values = dict([(variable,device.return_values(variable)) for variable in variables_list]) return values -#look at the tool def plot_results(x,y): fig, ax1 = plt.subplots() color = 'tab:red' - ax1.set_xlabel('V/V') - ax1.set_ylabel('$I/A/{cm}^2$', color = color) + ax1.set_xlabel('Voltage (V)') + ax1.set_ylabel('Current density $(A/{cm}^2)$') ax1.set_yscale('log') ax1.plot(x,y, color = color) - ax1.tick_params(axis ='y', labelcolor = color) + + ax1.grid(True,linestyle = '--',axis = 'y',color ="k",linewidth = 0.5) + ax1.axvline(linestyle='--',color = 'k',linewidth =0.5) fig.suptitle('Diode Plot', fontweight ="bold") fig.tight_layout() - fig.show() #interactve Figures + + display(fig) + + return fig #also for file def save_to_file(values,sample,parameters,file): - with open(file,'w') as f: - date = str(datetime.today().replace(microsecond=0)) - f.write(f"Diode Measurement at {date}"+"\n") - f.write(f"Series:{sample['processing_number'].value}"+"\n") - f.write(f"Sample:{sample['sample'].value}"+"\n") - f.write(f"Field:{sample['field'].value}"+"\n") - f.write(f"Radius/um:{sample['radius'].value}"+"\n\n") - - f.write('Parameters\n') - f.write(f"V from {parameters['start'].value}V to {parameters['stop'].value}V with step {parameters['step'].value}V"+"\n") - f.write(f"I Compliance/A:{parameters['comp'].value}"+"\n") - f.write(f"Integration Time:{parameters['integration'].value}"+"\n") - - f.write("\nResults\n") - - #create pandas dataframe - df = pd.DataFrame(values) - #df =df.drop(columns=['ABSNOR']) - df =df.rename(columns={'VS':'VS/V','IS':'IRAW/A','ABSRAW':'ABSRAW/A','INORM':'INORM/A/CM^2','ABSNOR':'ABSNOR/A/CM^2'}) - - df.to_csv(file,sep= " ",mode = 'a') \ No newline at end of file + if file != None: + with open(file,'w') as f: + date = str(datetime.today().replace(microsecond=0)) + f.write(f"Diode Measurement at {date}"+"\n") + f.write(f"Series:{sample['processing_number'].value}"+"\n") + f.write(f"Sample:{sample['sample'].value}"+"\n") + f.write(f"Field:{sample['field'].value}"+"\n") + f.write(f"Radius/um:{sample['radius'].value}"+"\n\n") + + f.write('Parameters\n') + f.write(f"V from {parameters['start'].value}V to {parameters['stop'].value}V with step {parameters['step'].value}V"+"\n") + f.write(f"I Compliance/A:{parameters['comp'].value}"+"\n") + f.write(f"Integration Time:{parameters['integration'].value}"+"\n") + + f.write("\nResults\n") + + #create pandas dataframe + df = pd.DataFrame(values) + #df =df.drop(columns=['ABSNOR']) + df =df.rename(columns={'VS':'VS/V','IS':'IRAW/A','ABSRAW':'ABSRAW/A','INORM':'INORM/A/CM^2','ABSNOR':'ABSNOR/A/CM^2'}) + + df.to_csv(file,sep= " ",mode = 'a') \ No newline at end of file diff --git a/hp4155/Diode/lib/interface.py b/hp4155/Diode/lib/interface.py index 1c7dab12203199ddd26035497a1e1a886be19904..09dde829bd10d567664ef371e67db3dee1a88a30 100644 --- a/hp4155/Diode/lib/interface.py +++ b/hp4155/Diode/lib/interface.py @@ -1,6 +1,6 @@ import ipywidgets as widgets from ipywidgets import GridspecLayout,Layout -from IPython.display import clear_output +from IPython.display import clear_output,display import sys import os @@ -58,7 +58,7 @@ def sample_information_interface(): for i in range(3): for j in range(2): if i ==2 and j == 1: - #information_grid[i,j]=widgets.Dropdown(options=['mA/mm','uA/um'],value='mA/mm',layout=Layout(height=height, width=width))#mind the gap + information_grid[i,j]=widgets.Button(description = "Save Plot",disabled = True)#mind the gap pass elif i == 2 and j == 0: #look at the tool for diode area information_grid[i,j]=widgets.BoundedFloatText( @@ -113,5 +113,6 @@ def sample_information_interface(): 'field': information_grid[0,1], 'radius': information_grid[2,0], } + save_plot_button = information_grid[2,1] - return information + return information,save_plot_button