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

TLM-CTLM programming part 4 (files)

parent 711b29a3
Branches
No related tags found
No related merge requests found
......@@ -12,6 +12,10 @@ import tkinter.messagebox
import time
import matplotlib.pyplot as plt
import os
from datetime import datetime
import pandas as pd
# Interface to collect information about the sample
def sample_interface():
......@@ -245,3 +249,54 @@ def information_box(information):
#display meaagebox
tkinter.messagebox.showinfo(message=information)
root.destroy()
#check if a folder is writable
def check_writable(folder):
filename = "test.txt"
file = os.path.join(folder,filename)
#protection against removing existing file in python
i=1
while os.path.exists(file):
filename=f"test{i}.txt"
file = os.path.join(folder,filename)
try:
with open(file,'a'):
writable = True
os.remove(file)
except:
writable = False
information_box(f"{folder} is not writable!")
return writable
#choose directory for saving the results
def choose_folder():
root = tk.Tk()
root.withdraw()
root.lift() #show window above all other applications
root.attributes("-topmost", True)#window stays above all other applications
#choose nonemty folder
folder = tk.filedialog.askdirectory()
while folder == '':
folder = tk.filedialog.askdirectory()
#check if writable in a while loop
writable=check_writable(folder)
while writable == False:
#choose a correct folder
folder = tk.filedialog.askdirectory()
while folder == '':
folder = tk.filedialog.askdirectory()
#check writable if not repeat
writable=check_writable(folder)
root.destroy()
return folder
......@@ -51,6 +51,7 @@ curve = 0
V=0
I=0
distances = []
folder = None
#initialize smus (empty)
smu1 = device.smu_dict()
......@@ -74,28 +75,31 @@ smu4.update(CONS=const_parameters)
def on_start_button_clicked(b):
with output:
global V,I,curve,distances,counter
global V,I,curve,distances,counter,folder
clear_output(wait = True)
#disable all widgets
disable_widgets(input_fields)
disable_widgets(all_buttons)
#clear the figure
ax.cla()
#check if values are correct
valid = check_values(start=parameters['start'],stop=parameters['stop'],step=parameters['step'])
if valid == True:
#load parameters,exexute measurement and plot results
#clear the figure
ax.cla()
#first reset counter
counter= 0
#retrive distances
distances = [sample[f"d{i}"].value for i in range(1,6)]
#choose folder
folder = choose_folder()
#load parameters
#update the dictionary var1
var1.update(
......@@ -152,12 +156,53 @@ def on_repeat_button_clicked(b):
def on_continue_button_clicked(b):
with output:
global V,I,curve,counter
global V,I,curve,counter,folder
change_state(first_time_buttons)
clear_output(wait = True)
#save results(counter = 0,1,2,3,4)
# fstrings are problematic extract values
field =sample["field"].value
type = sample["type"].value
date = str(datetime.today().replace(microsecond=0))
processing_number = sample["processing_number"].value
sample_series = sample["sample_series"].value
length = sample["length"].value
width = sample["width"].value
start = parameters["start"].value
stop = parameters["stop"].value
step = parameters["step"].value
comp = parameters["comp"].value
integration = parameters["integration"].value
filename = f"{field}_{type}_{counter+1}.txt"
path = os.path.join(folder,filename)
#check if filename exists
i = 1
while os.path.exists(path):
filename = f"{field}_{type}_{counter+1}({i}).txt"
path= os.path.join(folder,filename)
i=i+1
#write to file
title_sample = f"{type} Measurement at {date}"+"\n"+f"Processing Number:{processing_number}"+"\n"+f"Sample Series:{sample_series}"+"\n"+f"Field:{field}"+"\n"+f"Contanctlength|Innen Radius/um:{length}"+"\n"+f"Width/um:{width}"+"\n"+f"Distance/um:{distances[counter]}"+"\n\n"
title_parameters = f"Current/A:{start} to {stop} with step {step}"+"\n"+f"Compliance/V:{comp}"+"\n"+f"Integration Time:{integration}"+"\n\n"
#create the dataframe
header = ['V / V', 'I / A']
data = {header[0]:V,header[1]:I}
df = pd.DataFrame(data)
with open(path,"w") as f:
f.write(title_sample)
f.write(title_parameters)
f.write(df.to_string())
#increase counter
counter = counter +1 # this is the value before the next measurement starts
......
%% Cell type:code id:1850827a-0811-4a03-9ea4-68a99e240de4 tags:
``` python
%matplotlib widget
%run tlm-ctlm.py
```
%% Output
Controls
Save Parameters in .ini file
%% Cell type:code id:bea7cae7-2f79-4bcf-88f9-d9b50f7881ad tags:
%% Cell type:code id:27c5a82a-9d84-4698-be8f-17fb15457fe3 tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment