Skip to content
Snippets Groups Projects
Commit 1601b305 authored by JupyterHub User's avatar JupyterHub User
Browse files

tlm-ctlm measurement done

setup,plots,export pandas dataframe  to txt and csv
parent 2d9e2635
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,10 @@ import matplotlib.pyplot as plt ...@@ -5,6 +5,10 @@ import matplotlib.pyplot as plt
import pandas as pd import pandas as pd
from datetime import datetime from datetime import datetime
import os import os
from sklearn.linear_model import LinearRegression
import sys
import numpy as np
from IPython.display import display, clear_output
def I_V_Measurement(start,stop,step): def I_V_Measurement(start,stop,step):
...@@ -61,9 +65,10 @@ def I_V_Measurement(start,stop,step): ...@@ -61,9 +65,10 @@ def I_V_Measurement(start,stop,step):
print(df) print(df)
#exporting the data frame in an excel file #exporting the data frame in an excel file
file_name ="\results.csv" file_name ="results.csv"
path = "C:\Users\user\Desktop" path = r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
directory = os.path.join(cwd,file_name) #r"C:\Users\user\Desktop"
directory = os.path.join(path,file_name)
df.to_csv(directory) df.to_csv(directory)
del device del device
...@@ -141,7 +146,7 @@ def stress_sampling(V2_stress=10,V3_stress=3,stress_time=30,V2_sampling=10,V3_sa ...@@ -141,7 +146,7 @@ def stress_sampling(V2_stress=10,V3_stress=3,stress_time=30,V2_sampling=10,V3_sa
#prepare full measurement #prepare full measurement
def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),comp=10,distances=(5,10,15,25,45),time='MED'): def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),comp=10,distances=(5,10,15,25,45),time='MED',innen=0):
#connect to the device #connect to the device
device = module.HP4155a('GPIB0::17::INSTR') device = module.HP4155a('GPIB0::17::INSTR')
...@@ -153,6 +158,10 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -153,6 +158,10 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
plt.ylabel('Current(A)') plt.ylabel('Current(A)')
plt.title("CTLM plot") plt.title("CTLM plot")
#lists for appending all data values
ctlm_voltage = []
ctlm_current = []
ctlm_resistance = []
#execute five measurements #execute five measurements
for j in range(len(distances)): for j in range(len(distances)):
...@@ -161,6 +170,11 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -161,6 +170,11 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
device.inst.write(":PAGE:MEAS") device.inst.write(":PAGE:MEAS")
device.inst.write(":PAGE:CHAN:MODE SWEEP") #go to sweep page and prepare sweep measurement device.inst.write(":PAGE:CHAN:MODE SWEEP") #go to sweep page and prepare sweep measurement
#vsus and vmus are disabled
device.disable_vsu(1)
device.disable_vsu(2)
device.disable_vmu(1)
device.disable_vmu(2)
#smu1 is constant and common #smu1 is constant and common
device.smu_mode_meas(1,'COMM') device.smu_mode_meas(1,'COMM')
device.smu_function_sweep(1,'CONS') device.smu_function_sweep(1,'CONS')
...@@ -168,6 +182,7 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -168,6 +182,7 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
#smu2 is constant and I #smu2 is constant and I
device.smu_mode_meas(2,'I') device.smu_mode_meas(2,'I')
device.smu_function_sweep(2,'CONS') device.smu_function_sweep(2,'CONS')
device.cons_smu_value(2,0)
#smu3 is var1 and I #smu3 is var1 and I
device.smu_mode_meas(3,'I') device.smu_mode_meas(3,'I')
...@@ -176,6 +191,7 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -176,6 +191,7 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
#smu4 is constant and I #smu4 is constant and I
device.smu_mode_meas(4,'I') device.smu_mode_meas(4,'I')
device.smu_function_sweep(4,'CONS') device.smu_function_sweep(4,'CONS')
device.cons_smu_value(4,0)
#select compliance of smu3 #select compliance of smu3
device.comp('VAR1',comp) device.comp('VAR1',comp)
...@@ -186,6 +202,14 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -186,6 +202,14 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
# smu1 is common and compliance is automatically set to maximum # smu1 is common and compliance is automatically set to maximum
#define user functions
device.user_function('I','A','I3')
print(device.error())
device.user_function('V','V','V4-V2')
print(device.error())
device.user_function('R','OHM','DIFF(V,I)')
print(device.error())
#integration time #integration time
device.integration_time(time) device.integration_time(time)
...@@ -202,15 +226,22 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -202,15 +226,22 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
voltage_values = device.return_data('V3') voltage_values = device.return_data('V3')
current_values = device.return_data('I3') current_values = device.return_data('I3')
voltage = device.return_data('V')
print(voltage_values)
print(current_values)
resistance_values=[] ctlm_voltage.append(voltage_values)
ctlm_current.append(current_values)
for i in range(len(voltage_values)):
pass
#resistance_values.append(voltage_values[i]/current_values[i])
#plot results of the single measurement #plot results of the single measurement
plt.plot(voltage_values,current_values,label=f"distance={distances[j]}") #plt.plot(voltage_values,current_values,label=f"distance={distances[j]}")
plt.plot(voltage_values,current_values,label='ausgangvoltage')
plt.legend()
plt.show()
plt.figure()
plt.plot(voltage,current_values,label='Eingangsvoltage')
plt.legend()
plt.show()
#save measurement as txt file #save measurement as txt file
#add title to the results #add title to the results
...@@ -220,14 +251,18 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -220,14 +251,18 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
df = pd.DataFrame(data) df = pd.DataFrame(data)
print(df) print(df)
file_name = field_name+"_CTLM_"+str(j+1)+"_"+date+".txt" file_name = field_name+"_CTLM_"+str(j+1)+".txt"
cwd = os.getcwd() path =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
path = os.path.join(cwd,file_name) directory = os.path.join(path,file_name)
#export DataFrame to text file (keep header row and index column) #export DataFrame to text file (keep header row and index column)
#f=open(path, 'a') f=open(directory, 'a')
#f.write('title\n') f.write('title\n')
#df_string = df.to_string() df_string = df.to_string()
#f.write(df_string) f.write(df_string)
#plot diagramm
#plt.legend()
#plt.show()
#wait for confirmation from user after a measurement is done #wait for confirmation from user after a measurement is done
while True: while True:
...@@ -236,7 +271,189 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -236,7 +271,189 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
break break
#close the connection and plot all the diagramms #close the connection and plot all the diagramms
plt.legend()
plt.show()
del device del device
#tlm/ctlm final part
def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),comp=10,distances=(5,10,15,25,45),time='MED',innen=0):
#connect to the device
device = module.HP4155a('GPIB0::17::INSTR')
date = str(datetime.today().replace(microsecond=0))
#initialize figure
fig, (ax1, ax2) = plt.subplots(2,sharex=True,figsize=(8,6)) #the plots share the same x axis
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)')
#repeat five times
for j in range(len(distances)):
#setup
device.reset()
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')
device.display_variable_min_max('X','MIN',-10)
device.display_variable_min_max('X','MAX',10)
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)
#start measurement
device.single_measurement()
while device.operation_completed() == False:
pass
#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 txt
#check tlm or ctlm
if(innen==0):
#specify path and file_name
file_name = field_name+"_TLM_"+str(j+1)+".txt"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".txt"
path= os.path.join(location,file_name)
i=i+1
else:
#specify path and file_name
file_name = field_name+"_CTLM_"+str(j+1)+".txt"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".txt"
path= os.path.join(location,file_name)
i=i+1
title = "measured field:"+field_name+"\ndistance:"+str(distances[j])+"\nI:"+str(start)+"A to "+str(stop)+"A with step:"+str(step)+"\n"
f=open(path, 'a')
f.write(title)
df_string = df.to_string()
f.write(df_string)
f.close()
#export to csv for evaluataion
if(innen==0):
#specify path and file_name
file_name = field_name+"_TLM_"+str(j+1)+".csv"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".csv"
path= os.path.join(location,file_name)
i=i+1
else:
#specify path and file_name
file_name = field_name+"_CTLM_"+str(j+1)+".csv"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".csv"
path= os.path.join(location,file_name)
i=i+1
df.to_csv(path)
# give user confirmation to do the next measurement
while True:
answer=input("Press enter to continue or anything else to stop the programm:")
if answer=="":
break
else:
sys.exit()
This diff is collapsed.
...@@ -8,6 +8,7 @@ import os ...@@ -8,6 +8,7 @@ import os
from sklearn.linear_model import LinearRegression from sklearn.linear_model import LinearRegression
import sys import sys
import numpy as np import numpy as np
from IPython.display import display, clear_output
def I_V_Measurement(start,stop,step): def I_V_Measurement(start,stop,step):
...@@ -206,7 +207,7 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com ...@@ -206,7 +207,7 @@ def ctlm(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3),com
print(device.error()) print(device.error())
device.user_function('V','V','V4-V2') device.user_function('V','V','V4-V2')
print(device.error()) print(device.error())
device.user_function('R','OHM','V/I') device.user_function('R','OHM','DIFF(V,I)')
print(device.error()) print(device.error())
#integration time #integration time
...@@ -278,12 +279,9 @@ def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3 ...@@ -278,12 +279,9 @@ def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3
#connect to the device #connect to the device
device = module.HP4155a('GPIB0::17::INSTR') device = module.HP4155a('GPIB0::17::INSTR')
date = str(datetime.today().replace(microsecond=0)) date = str(datetime.today().replace(microsecond=0))
voltage=[]
current=[]
restistance=[]
#initialize figure #initialize figure
fig, (ax1, ax2) = plt.subplots(2,sharex=True) #the plots share the same x axis fig, (ax1, ax2) = plt.subplots(2,sharex=True,figsize=(8,6)) #the plots share the same x axis
fig.suptitle('CTLM plot') fig.suptitle('CTLM plot')
ax1.set_title('I(V)') ax1.set_title('I(V)')
ax1.set(xlabel='Voltage(V)',ylabel='Current(A)') ax1.set(xlabel='Voltage(V)',ylabel='Current(A)')
...@@ -331,7 +329,7 @@ def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3 ...@@ -331,7 +329,7 @@ def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3
#define user functions #define user functions
device.user_function('I','A','I3') device.user_function('I','A','I3')
device.user_function('V','V','V4-V2') device.user_function('V','V','V4-V2')
device.user_function('R','OHM','V/I') device.user_function('R','OHM','DIFF(V,I)')
device.user_function('VS','V','V3') device.user_function('VS','V','V3')
...@@ -371,42 +369,91 @@ def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3 ...@@ -371,42 +369,91 @@ def tlm_final(field_name ='M00',start=-50*10**(-3),stop=50*10**(-3),step=10**(-3
if R[i]>10**6: if R[i]>10**6:
R[i]=float('NAN') R[i]=float('NAN')
#plot data # plot the results
ax1.plot(V) 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 txt
#check tlm or ctlm
if(innen==0):
#specify path and file_name
file_name = field_name+"_TLM_"+str(j+1)+".txt"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".txt"
path= os.path.join(location,file_name)
i=i+1
else:
#specify path and file_name
file_name = field_name+"_CTLM_"+str(j+1)+".txt"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".txt"
path= os.path.join(location,file_name)
i=i+1
title = "measured field:"+field_name+"\ndistance:"+str(distances[j])+"\nI:"+str(start)+"A to "+str(stop)+"A with step:"+str(step)+"\nDate:"+date+"\n"
f=open(path, 'a')
f.write(title)
df_string = df.to_string()
f.write(df_string)
f.close()
#export to csv for evaluataion
if(innen==0):
#specify path and file_name
file_name = field_name+"_TLM_"+str(j+1)+".csv"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".csv"
path= os.path.join(location,file_name)
i=i+1
else:
#specify path and file_name
file_name = field_name+"_CTLM_"+str(j+1)+".csv"
location =r"\\fileserver.cst.rwth-aachen.de\public\Datentransfer\Asonitis, Alexandros"
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)+".csv"
path= os.path.join(location,file_name)
i=i+1
df.to_csv(path)
# give user confirmation to do the next measurement
while True:
answer=input("Press enter to continue or anything else to stop the programm:")
if answer=="":
break
else:
sys.exit()
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
File moved
File moved
This diff is collapsed.
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.11.4" "version": "3.9.7"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment