Skip to content
Snippets Groups Projects
Commit 972afc41 authored by Alexandros Asonitis's avatar Alexandros Asonitis
Browse files

removed filechooser from main memristor script and raised the limitations

parent 59f553e3
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ import matplotlib.pyplot as plt
import tkinter as tk
from tkinter import filedialog
import tkinter.messagebox
import numpy as np
from IPython.display import display, clear_output
......@@ -155,7 +156,7 @@ def create_data_frame(x,y):
header = ['V(V)','ABSV(V)',"I(A)",'ABSI(A)',"R(Ohm)"]
data = {header[0]:x,header[1]:np.absolute(x),header[2]:y,header[3]:np.absolute(y),header[4]:np.divide(x,y)}
df = pd.DataFrame(data)
print(df)
#print(df)
return df
def decode_ini(process,ini_file):
......@@ -210,6 +211,9 @@ def initialize_tkinter(sample_series,field,DUT):
#open dialog and hide the main window
root = tk.Tk()
root.withdraw()
root.lift() #show window above all other applications
root.attributes("-topmost", True)#window stays above all other applications
file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files","*.txt")],title = "save results path",initialfile = f'{DUT.value}_Memristor.txt')
......@@ -229,5 +233,26 @@ def initialize_tkinter(sample_series,field,DUT):
#return the file path
return file_path
#a check values function
def check_values(step,set_voltage,reset_voltage):
valid = True
root = tk.Tk()
root.withdraw()
root.lift() #show window above all other applications
root.attributes("-topmost", True)#window stays above all other applications
if step > abs(set_voltage) or step > abs(reset_voltage):#invalid parameter setting
valid = False
tkinter.messagebox.showerror(message="Invalid parameter setting(step>voltage)")
#now if the set-reset voltages have the same polarity show a warning
if set_voltage*reset_voltage>0:
valid = tk.messagebox.askokcancel(message="Set-Reset voltages have the same polarity. Continue?")
root.destroy()
return valid
\ No newline at end of file
......@@ -70,7 +70,7 @@ number = widgets.BoundedIntText(value=1,min=1,max=sys.maxsize,step=1,description
#parameter boxes
Vset=widgets.BoundedFloatText(
value=1,
min=0,
min=-200,
max=200,
step=0.1,
description='Voltage(V):',
......@@ -89,7 +89,7 @@ CC_vset=widgets.BoundedFloatText(
Vreset=widgets.BoundedFloatText(
value=-1,
min=-200,
max=0,
max=200,
step=0.1,
description='Voltage(V):',
)
......@@ -137,162 +137,106 @@ parameters = [Vset,CC_vset,Vreset,CC_vreset,step,integration_time,number]
#device.disable_vmu(1)
#device.disable_vmu(2)
#a function for checking the values of the parameters
""" the above is what happens when the programm starts all the rest have to be written into button trigger functions
""" the above is what happens when the programm starts all the rest have to be written into button trigger functions"""
def on_set_button_clicked(b):
nonlocal Vset,CC_vset,step,integration_time,device,first,DUT,sample_series,field,file_path,ini_file,file
global first,file_path
with output:
#disable buttons
set.disabled = True
reset.disabled=True
full.disabled =True
number.disabled =True
change_state(buttons)
change_state(parameters)
clear_output()
#during first button press
if first == True:
sample_series.disabled = True
field.disabled = True
DUT.disabled = True
sampling.disabled = True
#get ini file,and path from filechooser and open a new file
if fc.selected!=None:
ini_file = fc.selected
print(f"read parameters from ini:{ini_file}")
if pc.selected!=None:
file_path = pc.selected
print(f"save results in:{file_path}")
file = initialize_file(sample_series,field,DUT,file_path)
change_state(information)#disable all widgets that are relevant about the information of the sample
file_path = initialize_tkinter(sample_series,field,DUT)
first = False
try:
#decode ini file
Vset,CC_vset,integration_time,step=decode_ini('SET',ini_file)
#check values
valid = check_values(step.value,Vset.value,Vreset.value)
if valid == True:
#execute measurement,plot results and save them
V12,I12 = sweep(0,Vset,step,CC_vset,integration_time,device)
V12,I12 = sweep(0,Vset.value,step.value,CC_vset.value,integration_time.value,device)
plot_sweep(V12,I12,'SET')
df = create_data_frame(V12,I12)
print(df)
title = f"SET Memristor:"+"\n\n"+f"Set Voltage={Vset}V"+"\n"+f"current compliance={CC_vset}A"+"\n"
write_to_file(file,title,df)
#enable buttons
set.disabled = False
reset.disabled=False
full.disabled =False
number.disabled=False
write_to_file(file_path,title,df)
except Exception as e:
print(e)
print('please ensure that all parameters are correct')
set.disabled = False
reset.disabled=False
full.disabled =False
number.disabled=False
else:
print("Please Try again!")
change_state(buttons)
change_state(parameters)
def on_reset_button_clicked(b):
nonlocal Vreset,CC_vreset,step,integration_time,device,first,DUT,sample_series,field,file_path,ini_file,file
global first,file_path
with output:
set.disabled = True
reset.disabled=True
full.disabled =True
number.disabled=True
change_state(buttons)
change_state(parameters)
clear_output()
#during first button press
if first == True:
#disable checkboxes, text fields etc.
sample_series.disabled = True
field.disabled = True
DUT.disabled = True
sampling.disabled = True
#get ini file,and path from filechooser and open a new file
if fc.selected!=None:
ini_file = fc.selected
print(f"read parameters from ini:{ini_file}")
if pc.selected!=None:
file_path = pc.selected
print(f"save results in:{file_path}")
file = initialize_file(sample_series,field,DUT,file_path)
change_state(information)
file_path= initialize_file(sample_series,field,DUT)
first = False #set first to false irrelvant if it is in the if statement or not
try:
#decode ini file
Vreset,CC_vreset,integration_time,step=decode_ini('RESET',ini_file)
#check values
valid = check_values(step.value,Vset.value,Vreset.value)
if valid == True:
#execute measurement,plot results and save them
V34,I34 = sweep(0,Vreset,step,CC_vreset,integration_time,device)
V34,I34 = sweep(0,Vreset.value,step.value,CC_vreset.value,integration_time.value,device)
plot_sweep(V34,I34,'RESET')
df = create_data_frame(V34,I34)
print(df)
title =f"RESET Memristor:"+"\n\n"+f"Reset Voltage={Vreset}V"+"\n"+f"current compliance={CC_vreset}A"+"\n"
write_to_file(file,title,df)
#enable buttons
set.disabled = False
reset.disabled=False
full.disabled =False
number.disabled=False
except Exception as e:
print(e)
print('please ensure that all parameters are correct')
set.disabled = False
reset.disabled=False
full.disabled =False
number.disabled=False
write_to_file(file_path,title,df)
else:
print("Please Try again!")
change_state(buttons)
change_state(parameters)
def on_full_button_clicked(b):
nonlocal Vset,CC_vset,step,integration_time,device,first,DUT,sample_series,field,file_path,ini_file,file,Vreset,CC_vreset,number
global first,file_path
with output:
change_state(buttons)
change_state(parameters)
#disable buttons
set.disabled = True
reset.disabled=True
full.disabled =True
number.disabled=True
clear_output()
#during first button press
if first == True:
#disable checkboxes, text fields etc.
sample_series.disabled = True
field.disabled = True
DUT.disabled = True
sampling.disabled = True
#get ini file,and path from filechooser and open a new file
if fc.selected!=None:
ini_file = fc.selected
print(f"read parameters from ini:{ini_file}")
if pc.selected!=None:
file_path = pc.selected
print(f"save results in:{file_path}")
file = initialize_file(sample_series,field,DUT,file_path)
first = False
try:
#decode ini
Vreset,CC_vreset,integration_time,step=decode_ini('RESET',ini_file)
Vset,CC_vset,integration_time,step=decode_ini('SET',ini_file)
change_state(information)
file_path= initialize_file(sample_series,field,DUT)
first = False #set first to false irrelvant if it is in the if statement or not
with open(file,'a') as f:
#check values
valid = check_values(step.value,Vset.value,Vreset.value)
if valid == True:
with open(file_path,'a') as f:
f.write(f"{number.value} full sweeps with parameters:")
f.write("\n")
f.write(f"Set Voltage = {Vset}V")
f.write(f"Set Voltage = {Vset.value}V")
f.write("\n")
f.write(f"Current compliance set = {CC_vset}")
f.write(f"Current compliance set = {CC_vset.value}A")
f.write("\n")
f.write(f"Reset Voltage = {Vreset}V")
f.write(f"Reset Voltage = {Vreset.value}V")
f.write("\n")
f.write(f"Current compliance reset = {CC_vreset}")
f.write(f"Current compliance reset = {CC_vreset.value}A")
f.write("\n\n")
......@@ -314,8 +258,8 @@ parameters = [Vset,CC_vset,Vreset,CC_vreset,step,integration_time,number]
add_hotkey("esc",break_loop)
#execute number of measurements
for i in range(number.value):
V12,I12 = sweep(0,Vset,step,CC_vset,integration_time,device) #set
V34,I34 = sweep(0,Vreset,step,CC_vreset,integration_time,device) #reset
V12,I12 = sweep(0,Vset.value,step.value,CC_vset.value,integration_time.value,device) #set
V34,I34 = sweep(0,Vreset.value,step.value,CC_vreset.value,integration_time.value,device) #reset
#butterfly curve
V=np.concatenate((V12,V34))
......@@ -350,42 +294,13 @@ parameters = [Vset,CC_vset,Vreset,CC_vreset,step,integration_time,number]
remove_hotkey('esc')
stop = False
else:
print('Please Try again!')
set.disabled = False
reset.disabled=False
full.disabled =False
number.disabled=False
except Exception as e:
print(e)
print('please ensure that all parameters are correct')
set.disabled = False
reset.disabled=False
full.disabled =False
number.disabled=False
#link buttons with functions
set.on_click(on_set_button_clicked)
reset.on_click(on_reset_button_clicked)
full.on_click(on_full_button_clicked)
"""
%% Cell type:code id:33f299ef-2302-4e0a-b45f-291460d944c6 tags:
``` python
%run memristor.py
```
%% Output
%% Cell type:code id:2fc85780-0e32-4b77-9de5-684c87f55a6b tags:
``` python
#file_path = initialize_tkinter(sample_series,field,DUT)
```
%% Cell type:code id:dcd920ad-e15c-4297-b12d-01e96f4a89e0 tags:
``` python
#print(file_path)
```
%% Cell type:code id:4952f0fc-4d0e-4508-b241-7f7905fc2b21 tags:
``` python
```
......
%% Cell type:code id:28f8535b-e458-4c47-81c0-e7aa84e8133e tags:
``` python
import tkinter as tk
import tkinter.messagebox
```
%% Cell type:code id:388e7750-f089-4b3d-86fd-90109f23e811 tags:
``` python
root = tk.Tk()
root.withdraw()
root.lift() #show window above all other applications
root.attributes("-topmost", True)#window stays above all other applications
ok=tkinter.messagebox.showerror(message="Hi")
```
%% Cell type:code id:f78dab1b-35ab-4d4d-a131-97af50ab8c81 tags:
``` python
print(ok)
```
%% Output
ok
%% Cell type:code id:943bb22d-c7ef-492e-a885-99d146320365 tags:
``` python
ok = False
```
%% Cell type:code id:81723f8a-28cb-4a03-91fc-71839acdf6bb tags:
``` python
print(ok)
```
%% Output
False
%% Cell type:code id:de224e51-3021-4a2d-89ff-2bc81e273f49 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment