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

started minimizing code in the tlm function so it would be easier to programm the buttons

parent 067b8541
Branches
No related tags found
No related merge requests found
''' this is a help python file that uses functions to do the setup of the device which are not useful to be seen in the ctlm
'''
import module
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
import os
from sklearn.linear_model import LinearRegression
import sys
import numpy as np
from IPython.display import display, clear_output
import ipywidgets as widgets
def setup_tlm(start,stop,step,comp,time,device):
device.inst.write(":PAGE:MEAS")
device.inst.write(":PAGE:CHAN:MODE SWEEP") #go to sweep page and prepare sweep measurement
#disable vmus and vsus
device.disable_vsu(1)
device.disable_vsu(2)
device.disable_vmu(1)
device.disable_vmu(2)
#smu1 is constant and common
device.smu_mode_meas(1,'COMM')
device.smu_function_sweep(1,'CONS')
#smu2 is constant and I
device.smu_mode_meas(2,'I')
device.smu_function_sweep(2,'CONS')
device.cons_smu_value(2,0)
#smu3 is var1 and I
device.smu_mode_meas(3,'I')
device.smu_function_sweep(3,'VAR1')
#smu4 is constant and I
device.smu_mode_meas(4,'I')
device.smu_function_sweep(4,'CONS')
device.cons_smu_value(4,0)
#select compliance of smu3
device.comp('VAR1',comp)
#compliance of smu2 and smu4 is 10V
device.const_comp(2,10)
device.const_comp(4,10)
#define user functions
device.user_function('I','A','I3')
device.user_function('V','V','V4-V2')
device.user_function('R','OHM','DIFF(V,I)')
device.user_function('VS','V','V3')
#integration time
device.integration_time(time)
#define start-step-stop
device.start_value_sweep(start)
device.step_sweep(step)
device.stop_value_sweep(stop)
#display variables
device.display_variable('X','V')
device.display_variable('Y1','I')
device.display_variable('Y2','R')
###-----------------------------autoscaling after measurement------------------------------------------------------------------------------
device.display_variable_min_max('X','MIN',-comp)
device.display_variable_min_max('X','MAX', comp)
device.display_variable_min_max('Y1','MIN',start)
device.display_variable_min_max('Y1','MAX',stop)
device.display_variable_min_max('Y2','MIN',0)
device.display_variable_min_max('Y2','MAX',200)
### this function is helpful for exporting csv and txt(which was two loops in the beginnning)
def export(dataframe,filetype,innen,distances,field_name,j,start,stop,step,date):
if filetype==".csv" or filetype==".txt":
#check tlm or ctlm
if innen==0:
#specify path and file_name
file_name = field_name+"_TLM_"+str(j+1)+filetype
location =r"\\FILESERVER\public\Datentransfer\Asonitis, Alexandros\results"
path= os.path.join(location,file_name)
#check if file name exists
i=1
while os.path.exists(path):
file_name = field_name+"_TLM_"+str(j+1)+"_"+str(i)+filetype
path= os.path.join(location,file_name)
i=i+1
else:
#specify path and file_name
file_name = field_name+"_CTLM_"+str(j+1)+filetype
location =r"\\FILESERVER\public\Datentransfer\Asonitis, Alexandros\results"
path= os.path.join(location,file_name)
#check if file name exists
i=1
while os.path.exists(path):
file_name = field_name+"_CTLM_"+str(j+1)+"_"+str(i)+filetype
path= os.path.join(location,file_name)
i=i+1
if filetype==".txt":
title = "measured field:"+field_name+"\nInnen radius:"+str(innen)+"µm \ndistance:"+str(distances[j])+"µm \nI:"+str(start)+"A to "+str(stop)+"A with step:"+str(step)+"\nDate:"+date+"\n"
f=open(path, 'a')
f.write(title)
dataframe_string = dataframe.to_string()
f.write(dataframe_string)
f.close()
else:#csv
dataframe.to_csv(path)
else:
print("Not supported filetype!")
\ No newline at end of file
......@@ -10,6 +10,7 @@ import sys
import numpy as np
from IPython.display import display, clear_output
import ipywidgets as widgets
from help_ctlm import *
def I_V_Measurement(start,stop,step):
......@@ -334,3 +335,73 @@ def tlm_final(innen=0,distances=(5,10,15,25,45),field_name ='M00',start=-50*10**
break
else:
sys.exit()
def tlm_version2(innen=0,distances=(5,10,15,25,45),field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),comp=10,time='MED'):
#connect to the device
device = module.HP4155a('GPIB0::17::INSTR')
device.reset()
date = str(datetime.today().replace(microsecond=0))
#setup device
setup_tlm(start,stop,step,comp,time,device)
#initialize figure
fig, (ax1, ax2) = plt.subplots(2,sharex=True,figsize=(8,6)) #the plots share the same x axis
if innen==0:
fig.suptitle('TLM plot')
else:
fig.suptitle('CTLM plot')
ax1.set_title('I(V)')
ax1.set(xlabel='Voltage(V)',ylabel='Current(A)')
ax2.set_title('R(V)')
ax2.set(xlabel='Voltage(V)',ylabel='Resistance(Ohm)')
j=0
while j<len(distances):
#start measurement
device.single_measurement()
while device.operation_completed() == False:
pass
device.autoscaling()
#return data from the device
V=device.return_data('V')
I=device.return_data('I')
R=device.return_data('R')
# now we have to remove resistance values that R=inf(nan) that means that the current is zero
for i in range(len(R)):
if R[i]>10**6:
R[i]=float('NAN')
# plot the results
ax1.plot(V,I,label=f"distance={distances[j]}")
ax2.plot(V,R,label=f"distance={distances[j]}")
ax1.legend(loc='best')
ax2.legend(loc="best")
clear_output(wait=True)
fig.tight_layout()
display(fig)
#export data frame to csv(for evaluation) and txt
header = ['Voltage(V)', 'Current(A)','Resistance(Ohm)']
data = {header[0]:V,header[1]:I,header[2]:R}
df = pd.DataFrame(data)
print(df)
#export to csv and txt
export(df,".txt",innen,distances,field_name,j,start,stop,step,date)
export(df,".csv",innen,distances,field_name,j,start,stop,step,date)
while True:
answer=input("Press enter to continue or anything else to stop the programm:")
if answer=="":
j=j+1
break
else:
sys.exit()
del device
......@@ -221,3 +221,6 @@ class HP4155a(object):
def autoscaling(self):
self.inst.write(":PAGE:GLIS:SCAL:AUTO ONCE")
def append_measurement(self):
self.inst.write(":PAGE:SCON:APP")
\ No newline at end of file
......@@ -450,7 +450,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.11.4"
}
},
"nbformat": 4,
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment