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

TLM-CTLM programming part 1

parent a3dbc804
No related branches found
No related tags found
No related merge requests found
import ipywidgets as widgets
from ipywidgets import GridspecLayout,Layout
from IPython.display import clear_output
import sys
sys.path.insert(0, '..') #append parent directory
#import hp4155a
import tkinter as tk
from tkinter import filedialog
import tkinter.messagebox
import matplotlib.pyplot as plt
# Interface to collect information about the sample
def sample_interface():
width = "90%"
height = "auto"
style = {'description_width': 'initial'}
sample = GridspecLayout(6,3)
sample[0,0] = widgets.Label("Sample Information")
sample[0,0].style.font_weight = 'bold'
#iterate over the first two columns
for i in range(1,6,2):
sample[i:i+2,0]= widgets.Text(layout=Layout(height=height, width=width),style = style)
sample[1:3,0].description = "Processing Number:"
sample[3:5,0].description = "Sample Series:"
sample[5:7,0].description = "Field:"
#measurement information in the next columns
sample[1:3,1]= widgets.Dropdown(options=["TLM","CTLM"],value ='TLM',layout=Layout(height=height, width='60%'),description="Type:") #TLM or CTLM
sample[3:5,1]= widgets.BoundedIntText(value=50,min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width=width),description="Contactlength(um):",style = style)
sample[5:7,1]= widgets.BoundedIntText(value=100,min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width='60%'),description="Width(um):",style = style)
# distannces is the 3rd column
sample[0,2] = widgets.Label("Distances(um)")
sample[0,2].style.font_weight = 'bold'
distances = [5,10,15,20,50]
for i,distance in enumerate(distances):
sample[i+1,2]= widgets.BoundedIntText(value=int(distance),min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width="60%"),description=f"d{i+1}:",style = style)
def on_type_change(change):
if change['new'] =="TLM":
sample[3:5,1].value = 50
sample[3:5,1].description = 'Contanctlength(um)'
else:
sample[3:5,1].value = 55
sample[3:5,1].description = 'Innen Radius(um)'
sample[1:3,1].observe(on_type_change, names='value')
display(sample)
sample_dict = {
'processing_number':sample[1:3,0],
'sample_series':sample[3:5,0],
'field':sample[5:7,0],
'type':sample[1:3,1],
'length':sample[3:5,1],
'width':sample[5:7,1],
'd1':sample[1,2],
'd2':sample[2,2],
'd3':sample[3,2],
'd4':sample[4,2],
'd5':sample[5,2]
}
return sample_dict
#function to get interface from measurement parameters
def parameters_interface():
width = "60%"
height = "auto"
style = {'description_width': 'initial'}
parameters_title=widgets.Label("I(SMU3)",layout=Layout(height=height, width='50%'))
parameters_title.style.font_weight='bold'
parameters = GridspecLayout(4,3)
#start value
parameters[0,0]=widgets.Label("start",layout=Layout(height=height, width=width))
parameters[1,0]=widgets.BoundedFloatText(value=-50e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width))
#compliance value
parameters[2,0] = widgets.Label("compliance",layout=Layout(height=height, width=width))
parameters[3,0] = widgets.BoundedFloatText(value=10,min=-100,max=100,step=1,layout=Layout(height=height, width=width))
#stop value
parameters[0,1]=widgets.Label("stop",layout=Layout(height=height, width=width))
parameters[1,1]=widgets.BoundedFloatText(value=50e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width))
#hysterisis
parameters[2,1]= widgets.Label("hysterisis",layout=Layout(height=height, width=width))
parameters[3,1]=widgets.Dropdown(options=['SINGle','DOUBle'],value='SINGle',layout=Layout(height=height, width=width))
#step
parameters[0,2] = widgets.Label("step",layout=Layout(height=height, width=width))
parameters[1,2] = widgets.BoundedFloatText(value=1e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width))
#integration time
parameters[2,2]=widgets.Label("Integration Time",layout=Layout(height=height, width=width))
parameters[3,2]= widgets.Dropdown(options=["SHORt","MEDium","LONG"],value="MEDium",layout=Layout(height=height, width=width))
display(parameters_title)
display(parameters)
parameters_dict = {
'start':parameters[1,0],
'comp':parameters[3,0],
'stop':parameters[1,1],
'hyst':parameters[3,1],
'step':parameters[1,2],
'integration':parameters[3,2]
}
return parameters_dict
#functions for the widgets enabling and disabling
def add_widgets_to_list(source_dictionary,target_list):
for widget in source_dictionary.values():
target_list.append(widget)
def change_state(widgets_list):
for widget in widgets_list:
widget.disabled = not widget.disabled
def enable_widgets(widgets_list):
for widget in widgets_list:
widget.disabled = False
def disable_widgets(widgets_list):
for widget in widgets_list:
widget.disabled = True
#check if start stop and step are correct
def check_values(start,stop,step):
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 abs(step.value) > abs(stop.value-start.value) or step.value==0:#invalid parameter setting
valid = False
tkinter.messagebox.showerror(message="Invalid parameter setting!")
if start.value<stop.value and step.value<0: #change polarity
step.value =(-1)*step.value
elif start.value>stop.value and step.value>0:
step.value = (-1)*step.value
else:
pass
return valid
\ No newline at end of file
%% Cell type:code id:bae2efc8-f5a2-447c-9d68-77e9bdc1e3b6 tags: %% Cell type:code id:bae2efc8-f5a2-447c-9d68-77e9bdc1e3b6 tags:
``` python ``` python
import ipywidgets as widgets import ipywidgets as widgets
from ipywidgets import GridspecLayout,Layout from ipywidgets import GridspecLayout,Layout
from IPython.display import clear_output from IPython.display import clear_output
import sys import sys
``` ```
%% Cell type:code id:6c4f922a-9f73-438a-a13c-45dbcdf95081 tags: %% Cell type:code id:6c4f922a-9f73-438a-a13c-45dbcdf95081 tags:
``` python ``` python
def sample(): def sample():
width = "90%" width = "90%"
height = "auto" height = "auto"
style = {'description_width': 'initial'} style = {'description_width': 'initial'}
sample = GridspecLayout(6,3) sample = GridspecLayout(6,3)
sample[0,0] = widgets.Label("Sample Information") sample[0,0] = widgets.Label("Sample Information")
sample[0,0].style.font_weight = 'bold' sample[0,0].style.font_weight = 'bold'
#iterate over the first two columns #iterate over the first two columns
for i in range(1,6,2): for i in range(1,6,2):
sample[i:i+2,0]= widgets.Text(layout=Layout(height=height, width=width),style = style) sample[i:i+2,0]= widgets.Text(layout=Layout(height=height, width=width),style = style)
sample[1:3,0].description = "Processing Number:" sample[1:3,0].description = "Processing Number:"
sample[3:5,0].description = "Sample Series:" sample[3:5,0].description = "Sample Series:"
sample[5:7,0].description = "Field:" sample[5:7,0].description = "Field:"
#measurement information in the next columns #measurement information in the next columns
sample[1:3,1]= widgets.Dropdown(options=["TLM","CTLM"],value ='TLM',layout=Layout(height=height, width='60%'),description="Type:") #TLM or CTLM sample[1:3,1]= widgets.Dropdown(options=["TLM","CTLM"],value ='TLM',layout=Layout(height=height, width='60%'),description="Type:") #TLM or CTLM
sample[3:5,1]= widgets.BoundedIntText(value=50,min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width=width),description="Contactlength / Innen radius(um):",style = style) sample[3:5,1]= widgets.BoundedIntText(value=50,min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width=width),description="Contactlength(um):",style = style)
sample[5:7,1]= widgets.BoundedIntText(value=100,min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width='60%'),description="Width(um):",style = style) sample[5:7,1]= widgets.BoundedIntText(value=100,min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width='60%'),description="Width(um):",style = style)
# distannces is the 3rd column # distannces is the 3rd column
sample[0,2] = widgets.Label("Distances(um)") sample[0,2] = widgets.Label("Distances(um)")
sample[0,2].style.font_weight = 'bold' sample[0,2].style.font_weight = 'bold'
distances = [5,10,15,20,50] distances = [5,10,15,20,50]
for i,distance in enumerate(distances): for i,distance in enumerate(distances):
sample[i+1,2]= widgets.BoundedIntText(value=int(distance),min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width="60%"),description=f"d{i+1}:",style = style) sample[i+1,2]= widgets.BoundedIntText(value=int(distance),min=1,max=sys.maxsize,step=1,layout=Layout(height=height, width="60%"),description=f"d{i+1}:",style = style)
def on_type_change(change): def on_type_change(change):
if change['new'] =="TLM": if change['new'] =="TLM":
sample[3:5,1].value = 50 sample[3:5,1].value = 50
sample[3:5,1].description = 'Contanctlength(um)'
else: else:
sample[3:5,1].value = 55 sample[3:5,1].value = 55
sample[3:5,1].description = 'Innen Radius(um)'
sample[1:3,1].observe(on_type_change, names='value') sample[1:3,1].observe(on_type_change, names='value')
display(sample) display(sample)
return sample return sample
``` ```
%% Cell type:code id:95bc631f-5e6c-43a2-850b-d28cccf0d2f3 tags: %% Cell type:code id:95bc631f-5e6c-43a2-850b-d28cccf0d2f3 tags:
``` python ``` python
sample() sample()
``` ```
%% Output %% Output
GridspecLayout(children=(Label(value='Sample Information', layout=Layout(grid_area='widget001'), style=LabelSt… GridspecLayout(children=(Label(value='Sample Information', layout=Layout(grid_area='widget001'), style=LabelSt…
%% Cell type:code id:ed11abb2-fe63-4d03-902a-c93e723200b8 tags: %% Cell type:code id:ed11abb2-fe63-4d03-902a-c93e723200b8 tags:
``` python ``` python
def parameters(): def parameters():
width = "60%" width = "60%"
height = "auto" height = "auto"
style = {'description_width': 'initial'} style = {'description_width': 'initial'}
parameters_title=widgets.Label("I(SMU3)",layout=Layout(height=height, width='50%')) parameters_title=widgets.Label("I(SMU3)",layout=Layout(height=height, width='50%'))
parameters_title.style.font_weight='bold' parameters_title.style.font_weight='bold'
parameters = GridspecLayout(4,3) parameters = GridspecLayout(4,3)
#start value #start value
parameters[0,0]=widgets.Label("start",layout=Layout(height=height, width=width)) parameters[0,0]=widgets.Label("start",layout=Layout(height=height, width=width))
parameters[1,0]=widgets.BoundedFloatText(value=-50e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width)) parameters[1,0]=widgets.BoundedFloatText(value=-50e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width))
#compliance value #compliance value
parameters[2,0] = widgets.Label("compliance",layout=Layout(height=height, width=width)) parameters[2,0] = widgets.Label("compliance",layout=Layout(height=height, width=width))
parameters[3,0] = widgets.BoundedFloatText(value=10,min=-100,max=100,step=1,layout=Layout(height=height, width=width)) parameters[3,0] = widgets.BoundedFloatText(value=10,min=-100,max=100,step=1,layout=Layout(height=height, width=width))
#stop value #stop value
parameters[0,1]=widgets.Label("stop",layout=Layout(height=height, width=width)) parameters[0,1]=widgets.Label("stop",layout=Layout(height=height, width=width))
parameters[1,1]=widgets.BoundedFloatText(value=50e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width)) parameters[1,1]=widgets.BoundedFloatText(value=50e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width))
#hysterisis #hysterisis
parameters[2,1]= widgets.Label("hysterisis",layout=Layout(height=height, width=width)) parameters[2,1]= widgets.Label("hysterisis",layout=Layout(height=height, width=width))
parameters[3,1]=widgets.Dropdown(options=['SINGle','DOUBle'],value='SINGle',layout=Layout(height=height, width=width)) parameters[3,1]=widgets.Dropdown(options=['SINGle','DOUBle'],value='SINGle',layout=Layout(height=height, width=width))
#step #step
parameters[0,2] = widgets.Label("step",layout=Layout(height=height, width=width)) parameters[0,2] = widgets.Label("step",layout=Layout(height=height, width=width))
parameters[1,2] = widgets.BoundedFloatText(value=1e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width)) parameters[1,2] = widgets.BoundedFloatText(value=1e-3,min=-0.1,max=0.1,step=1e-3,layout=Layout(height=height, width=width))
#integration time #integration time
parameters[2,2]=widgets.Label("Integration Time",layout=Layout(height=height, width=width)) parameters[2,2]=widgets.Label("Integration Time",layout=Layout(height=height, width=width))
parameters[3,2]= widgets.Dropdown(options=["SHORt","MEDium","LONG"],value="MEDium",layout=Layout(height=height, width=width)) parameters[3,2]= widgets.Dropdown(options=["SHORt","MEDium","LONG"],value="MEDium",layout=Layout(height=height, width=width))
display(parameters_title) display(parameters_title)
display(parameters) display(parameters)
return parameters return parameters
``` ```
%% Cell type:code id:d67a0dd4-2ffb-4624-b4ad-5bc3182fcbf1 tags: %% Cell type:code id:d67a0dd4-2ffb-4624-b4ad-5bc3182fcbf1 tags:
``` python ``` python
parameters() parameters()
``` ```
%% Output %% Output
GridspecLayout(children=(Label(value='start', layout=Layout(grid_area='widget001', height='auto', width='60%')… GridspecLayout(children=(Label(value='start', layout=Layout(grid_area='widget001', height='auto', width='60%')…
%% Cell type:code id:81442809-b623-4cce-bd09-127c19ac4423 tags: %% Cell type:code id:81442809-b623-4cce-bd09-127c19ac4423 tags:
``` python ``` python
#series #series
sample() sample()
print() print()
parameters() parameters()
``` ```
%% Output %% Output
GridspecLayout(children=(Label(value='start', layout=Layout(grid_area='widget001', height='auto', width='60%')… GridspecLayout(children=(Label(value='start', layout=Layout(grid_area='widget001', height='auto', width='60%')…
%% Cell type:code id:01be6736-68c1-42b7-a192-19af4f762b42 tags: %% Cell type:code id:01be6736-68c1-42b7-a192-19af4f762b42 tags:
``` python ``` python
#tabular interface #tabular interface
children = [sample(),parameters()] children = [sample(),parameters()]
titles = ["Sample Information","Measurement Parameters"] titles = ["Sample Information","Measurement Parameters"]
tab = widgets.Tab() tab = widgets.Tab()
tab.children = children tab.children = children
tab.titles = titles tab.titles = titles
display(tab) display(tab)
``` ```
%% Output %% Output
Displays children each on a separate accordion tab.
%% Cell type:code id:6e8583d9-1425-491c-b41b-1de6e0b32586 tags: %% Cell type:code id:6e8583d9-1425-491c-b41b-1de6e0b32586 tags:
``` python ``` python
``` ```
......
from help import *
#the interface
sample = sample_interface()
print()
parameters = parameters_interface()
print()
#the buttons
print('Controls')
start_button = widgets.Button(description="Start NEW!")
repeat_button = widgets.Button(description="repeat last")
continue_button = widgets.Button(description="save+continue")
exit_button = widgets.Button(description='exit/abort')
control_buttons = widgets.HBox([start_button,repeat_button,continue_button,exit_button])
display(control_buttons)
print()
print("Save Parameters in .ini file")
export_ini_button = widgets.Button(description = 'Export as ini')
import_ini_button = widgets.Button(description='Import from ini')
ini_buttons = widgets.HBox([import_ini_button,export_ini_button])
output = widgets.Output()
display(ini_buttons,output)
#connect to the device
#device = hp4155a.HP4155a('GPIB0::17::INSTR')
#create the lists for controlling the interactivty
input_fields = []
add_widgets_to_list(sample,input_fields)
add_widgets_to_list(parameters,input_fields)
all_buttons =[start_button,repeat_button,continue_button,exit_button,import_ini_button,export_ini_button]
first_time_buttons= [repeat_button,continue_button,exit_button]
disable_widgets(first_time_buttons)
#connect to the device
device = hp4155a.HP4155a('GPIB0::17::INSTR')
#initalize counter
counter = -1
#initialize figure
fig,ax = plt.subplots()
#initialze global variables for removing the plots and saving results later
curve = 0
V=0
I=0
#initialize smus (empty)
smu1 = device.smu_dict()
smu2 = device.smu_dict()
smu3 = device.smu_dict()
smu4 = device.smu_dict()
var1 = device.var1_dict()
smu1.update(vname = 'V1',iname ='I1',mode='COMM',func='CONS')
smu2.update(vname = 'V2',iname = 'I2',mode='I',func='CONS')
smu3.update(vname ='V3',iname='I3',mode='I',func='VAR1')
smu4.update(vname ='V4',iname ='I4',mode='I',func='CONS')
#update the dictionaries of the constant smus
const_parameters = device.cons_smu_dict()
const_parameters.update(value=0,comp = 10)
smu2.update(cons=const_parameters)
smu4.update(cons = const_parameters)
def on_start_button_clicked(b):
#disable all widgets
disable_widgets(input_fields)
disable_widgets(all_buttons)
fig.clear()
#check if values are correct
valid = check_values(start=parameters['start'].value,stop=parameters['stop'].value)
if valid == True:
#load parameters,exexute measurement and plot results
#first increase counter
counter = 0
#load parameters
#update the dictionary var1
var1.update(
mode = 1
)
pass
%% Cell type:code id:1850827a-0811-4a03-9ea4-68a99e240de4 tags:
``` python
%run tlm-ctlm.py
```
%% Output
Controls
Save Parameters in .ini file
%% Cell type:code id:c17b5d9b-d644-45d3-9be1-78fd5d2b80ea tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment