diff --git a/hp4155/MESA/lib/MESA_SMU_configuration.png b/hp4155/MESA/lib/MESA_SMU_configuration.png new file mode 100644 index 0000000000000000000000000000000000000000..35315592b545ba5bfffee902100f0d3180b379d0 Binary files /dev/null and b/hp4155/MESA/lib/MESA_SMU_configuration.png differ diff --git a/hp4155/MESA/lib/help.py b/hp4155/MESA/lib/help.py new file mode 100644 index 0000000000000000000000000000000000000000..2d2f444da92cb03f291b64be687996303d28fb55 --- /dev/null +++ b/hp4155/MESA/lib/help.py @@ -0,0 +1,187 @@ +import matplotlib.pyplot as plt +import numpy as np +import time +from datetime import datetime + +import tkinter as tk +from tkinter import filedialog +import tkinter.messagebox + +import pandas as pd + +def normalization_factor(width): + factor = 10**6/width + return factor + +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 + +#saving functions : save parameters and dataframe to txt +def create_file(filename): + 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=".txt", filetypes=[("Text files","*.txt")],title = "save results path",initialfile =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!') + file = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files","*.txt")],title = "save results path",initialfile =filename) + root.destroy() + return file + + +def check_values(parameters): + 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 + + #get better variable names + start = parameters['start'] + stop = parameters['stop'] + step = parameters['step'] + + #check values + 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 + + root.destroy() + return valid + +#Setup The device for mesa measurement +def setup(device): + device.reset() + + #setup sweep measurement mode + device.measurement_mode('SWE') + + #disable all irrelevant units + device.disable_not_smu() + + #disable smu 2 and 4 + device.smu_disable(2) + device.smu_disable(4) + +def measure(parameters,norm,device): + #delete user functions + device.del_user_functions() + + smu1 = device.smu_dict() + smu1.update(vname ='VGND',iname = 'IGND',mode = 'COMM',func='CONS') + + smu3 = device.smu_dict() + smu3.update(vname='V',iname='I',mode ='V',func='VAR1') + + device.setup_smu(1,smu1) + device.setup_smu(3,smu3) + + #define user functions + device.user_function('Imm','mA/mm',f'I*{norm}') + device.user_function('ABSImm','mA/mm','ABS(Imm)') + + var1 = device.var1_dict() + var1.update( + mode = parameters['hyst'].value, + start = parameters['start'].value, + stop = parameters['stop'].value, + step = parameters['step'].value, + comp = parameters['comp'].value, + pcomp = 0 + ) + + device.setup_var1(var1) + device.integration_time(parameters['integration'].value) + + + #display + device.display_variable('X','V') + device.display_variable('Y1','ABSImm') + + device.axis_scale('Y1','LOG') + + if parameters['start'].value < parameters['stop'].value: + device.display_variable_min_max('X','MIN',parameters['start'].value) + device.display_variable_min_max('X','MAX',parameters['stop'].value) + + else: + device.display_variable_min_max('X','MAX',parameters['start'].value) + device.display_variable_min_max('X','MIN',parameters['stop'].value) + + if parameters['comp'].value !=0: + device.display_variable_min_max('Y1','MIN',0) + device.display_variable_min_max('Y1','MAX',abs(parameters['comp'].value)*norm) + + + variables_list = ['V','I','Imm','ABSImm'] + device.variables_to_save(variables_list) + + device.single_measurement() + while device.operation_completed() == False: + pass + + device.autoscaling() + + values = dict([(variable,device.return_values(variable)) for variable in variables_list]) + return values + +def plot_results(x,y): + fig, ax1 = plt.subplots() + + color = 'tab:red' + ax1.set_xlabel('V/V') + ax1.set_ylabel('I/mA/mm', color = color) + ax1.set_yscale('log') + + ax1.plot(x,y, color = color) + ax1.tick_params(axis ='y', labelcolor = color) + + fig.suptitle('MESA Plot', fontweight ="bold") + fig.tight_layout() + fig.show() #interactve Figures + +def save_to_file(values,sample,parameters,file): + with open(file,'w') as f: + date = str(datetime.today().replace(microsecond=0)) + f.write(f"Mesa 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"Width/um:{sample['width'].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=['ABSImm']) + df = df.rename(columns={'V':'V/V','I':'I/A','Imm':'Imm/mA/mm'}) + + df.to_csv(file,sep= " ",mode = 'a') \ No newline at end of file diff --git a/hp4155/MESA/lib/interface.py b/hp4155/MESA/lib/interface.py new file mode 100644 index 0000000000000000000000000000000000000000..91362f409452a67b08edf344a4658fd6d627b28a --- /dev/null +++ b/hp4155/MESA/lib/interface.py @@ -0,0 +1,119 @@ +import ipywidgets as widgets +from ipywidgets import GridspecLayout,Layout +from IPython.display import clear_output +import sys +import os + +width = "50%" +height = 'auto' +style = {'description_width': 'initial'} +floatbox_width = "80%" + +def parameters_interface(): + grid = GridspecLayout(5,4) + grid[0,:]=widgets.Label("V (SMU3)",layout=Layout(height='auto', width='auto')) + grid[0,:].style.font_weight='bold' + + + #first line + grid[1,0]=widgets.Label("Start(V)",layout=Layout(height='auto', width='auto')) + grid[1,1]=widgets.Label("Step(V)",layout=Layout(height='auto', width='auto')) + grid[1,2]=widgets.Label("Stop(V)",layout=Layout(height='auto', width='auto')) + + #second line + grid[2,0]=widgets.BoundedFloatText(value=0,min=-100,max=100,step=1,layout=Layout(height='auto', width=floatbox_width)) + grid[2,1]=widgets.BoundedFloatText(value=0.5,min=-200,max=200,step=1,layout=Layout(height='auto', width=floatbox_width)) + grid[2,2]=widgets.BoundedFloatText(value=100,min=-100,max=100,step=1,layout=Layout(height='auto', width=floatbox_width)) + + #third line + grid[3,0]=widgets.Label("Compliance(A)",layout=Layout(height='auto', width='auto')) + grid[3,1] =widgets.Label("Integration Time",layout=Layout(height='auto', width='auto'))#mind the gap + grid[3,2] =widgets.Label("Hysterisis",layout=Layout(height='auto', width='auto'))#mind the gap + + #fourth line + grid[4,0]=widgets.BoundedFloatText(value=0.02,min=-0.1,max=0.1,step=0.01,layout=Layout(height='auto', width=floatbox_width)) + grid[4,1]=widgets.Dropdown(options=["SHORt","MEDium","LONG"],value="MEDium",style =style,layout=Layout(height='auto', width=floatbox_width)) + grid[4,2]=widgets.Dropdown(options=['SINGle','DOUBle'],value='SINGle',layout=Layout(height='auto', width=floatbox_width))#mind the gap + + parameters = { + 'start': grid[2,0], + 'step': grid[2,1], + 'stop': grid[2,2], + 'comp': grid[4,0], + 'hyst':grid[4,2], + 'integration':grid[4,1] + } + + + display(grid) + return parameters + + +def sample_information_interface(): + width = '90%' + sample_information=widgets.Label("Sample Information",layout=Layout(height=height, width='50%')) + sample_information.style.font_weight='bold' + information_grid=GridspecLayout(3,2) + + 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 + pass + elif i == 2 and j == 0: + information_grid[i,j]=widgets.BoundedFloatText( + value=100, + min=1e-3, + max=sys.float_info.max,step=1, + layout=Layout(height=height, width=width) + ) + else: + information_grid[i,j]=widgets.Text(layout=Layout(height=height, width=width)) + + information_grid[0,0].description = "Processing-Nr:" + information_grid[1,0].description = "Sample:" + information_grid[2,0].description = "Device Width(um):" + information_grid[0,1].description = "Field(XYY):" + information_grid[1,1].description = "Device:" + information_grid[1,1].disabled = True + #information_grid[2,1].description = "Normalization:" + + for i in range(3): + for j in range(2): + try: + information_grid[i,j].style = style + except: + pass + + image_title = widgets.Label("SMU Configuration",layout=Layout(height=height, width='50%')) + image_title.style.font_weight='bold' + + filename = os.getcwd()+r"\lib\MESA_SMU_configuration.png" + #print(filename) + + file = open(filename, "rb") + image = file.read() + image_widget =widgets.Image( + value = image, + format='png', + width='auto', + height='auto', + ) + + #display(widgets.HBox([sample_information,image_title])) + #display(widgets.HBox([information_grid,image_widget])) + vbox1 =widgets.VBox([sample_information,information_grid]) + vbox2 =widgets.VBox([image_title,image_widget]) + + display(widgets.HBox([vbox1,vbox2])) + + information = { + 'processing_number': information_grid[0,0], + 'sample' : information_grid[1,0], + 'field': information_grid[0,1], + #'device':information_grid[1,1], + 'width': information_grid[2,0], + } + + return information + \ No newline at end of file diff --git a/hp4155/MESA/mesa.py b/hp4155/MESA/mesa.py new file mode 100644 index 0000000000000000000000000000000000000000..b28f51258d1b9d4cf02679d2e0e9b605480db997 --- /dev/null +++ b/hp4155/MESA/mesa.py @@ -0,0 +1,39 @@ +import sys +sys.path.insert(0, './lib') +sys.path.insert(0, '..') #append parent directory + +import hp4155a +from interface import * +from help import * + +sample = sample_information_interface() +parameters =parameters_interface() +button = widgets.Button(description ='Start Measurement') +output = widgets.Output() + +display(button,output) + +all_widgets = [button] +add_widgets_to_list(sample,all_widgets) +add_widgets_to_list(parameters,all_widgets) + +device = hp4155a.HP4155a('GPIB0::17::INSTR') +setup(device) +def on_button_clicked(b): + with output: + clear_output(wait = True) + change_state(all_widgets) + norm=normalization_factor(sample['width'].value) + + valid = check_values(parameters) + if valid == True: + values = measure(parameters,norm,device) + plot_results(values['V'],values['ABSImm']) + filename = f"MESA_ISO_{sample['field'].value}.txt" + file = create_file(filename) + save_to_file(values,sample,parameters,file) + + change_state(all_widgets) + +button.on_click(on_button_clicked) + \ No newline at end of file diff --git a/hp4155/MESA/mesa_interface.ipynb b/hp4155/MESA/mesa_interface.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..45d6413aabb40c141ea00d1f0e025c6e8437b2e0 --- /dev/null +++ b/hp4155/MESA/mesa_interface.ipynb @@ -0,0 +1,101 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "1b607685-438c-466e-9671-140ae6c8d9f9", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1e8f68e7a1a44930b5f8aa7274a71bd1", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "HBox(children=(VBox(children=(Label(value='Sample Information', layout=Layout(height='auto', width='50%'), sty…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "59dc533f8cc2493597699a3a72882bbf", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "GridspecLayout(children=(Label(value='V (SMU3)', layout=Layout(grid_area='widget001', height='auto', width='au…" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b79166daed814a348b6538ae9102b66c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Button(description='Start Measurement', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "68d3460573264361a55153b8c1f43020", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib widget\n", + "%run mesa.py" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c62885a4-1186-4770-937f-fc8b5c484b98", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}