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

rescue data ADU done!

parent 4c380fbb
Branches
No related tags found
No related merge requests found
......@@ -101,7 +101,11 @@ class HP4155a(object):
self.inst.write("*WAI")
def show_variables(self):
return self.inst.query(":DATA:CAT?")
query = self.inst.query(":DATA:CAT?")
query = query.replace('\n',',')
var_list = query.split(',')
var_list.pop() #remove empty string
return var_list
#-----------------------------------------------------------sweep functions---------------------------------------------------------------
def smu_disable(self,number:int):
......
%% Cell type:code id:643903f9-9dc6-4563-b389-9ffc6ed601d7 tags:
``` python
import hp4155a
import pandas as pd
import numpy as np
import tkinter as tk
from datetime import datetime
from tkinter import filedialog
```
%% Cell type:code id:82c9534e-4125-4c99-bca0-d763a3ec4f00 tags:
``` python
device = hp4155a.HP4155a('GPIB0::17::INSTR')
```
%% Cell type:code id:e062d8a6-6b24-49e6-b88c-d59060ac46c1 tags:
``` python
variables = device.show_variables()
```
%% Cell type:code id:dd600907-ab15-440f-93fa-f0d3a1c19651 tags:
``` python
values = {}
for variable in variables:
try:
current_values = device.return_values(variable)
if len(current_values)>1: # There are also some constants
values[variable] = current_values
except:
print(f"No Values for variable {variable}")
df = pd.DataFrame(values)
```
%% Cell type:code id:87309758-aea7-418d-8dfa-024f827330ce tags:
``` python
del device
```
%% Cell type:code id:62e77124-db55-4208-b008-d69379de6407 tags:
``` python
for col in df.columns.values.tolist():
df.loc[abs(df[col]) > 1e30, col] = np.nan
```
%% Cell type:code id:d64a276f-544c-436e-a948-0e3519e12e74 tags:
``` python
# Prepare to save to file
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
```
%% Cell type:code id:b1dfe94d-96ca-432c-b180-cf581dcf3c41 tags:
``` python
date = datetime.now().strftime('%d_%m_%Y_%H_%M_%S')
```
%% Cell type:code id:404b28c8-d14c-41cc-91da-097647338d32 tags:
``` python
filename = "Rescue_Data_ADU_"+date +".txt"
```
%% Cell type:code id:268dd9f8-1092-41d5-aca5-668ecf5c38d6 tags:
``` python
file=create_file(filename)
df.to_csv(file,sep=" ",mode='w',na_rep = 'NaN')
print("Data saved to file successfully")
```
%% Output
Data saved to file successfully
%% Cell type:code id:00854758-b6e6-459c-8329-92bedc2c3f72 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment