Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
labcode
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CST
labcode
Commits
5ea8648e
Commit
5ea8648e
authored
3 months ago
by
Alexandros Asonitis
Browse files
Options
Downloads
Patches
Plain Diff
Rescue data Availaible
parent
974bf4ee
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hp4155/hp4155a.py
+5
-1
5 additions, 1 deletion
hp4155/hp4155a.py
hp4155/rescue_data.ipynb
+175
-0
175 additions, 0 deletions
hp4155/rescue_data.ipynb
with
180 additions
and
1 deletion
hp4155/hp4155a.py
+
5
−
1
View file @
5ea8648e
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
hp4155/rescue_data.ipynb
0 → 100644
+
175
−
0
View file @
5ea8648e
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "643903f9-9dc6-4563-b389-9ffc6ed601d7",
"metadata": {},
"outputs": [],
"source": [
"import hp4155a\n",
"import pandas as pd\n",
"import numpy as np\n",
"import tkinter as tk\n",
"from datetime import datetime\n",
"from tkinter import filedialog"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "82c9534e-4125-4c99-bca0-d763a3ec4f00",
"metadata": {},
"outputs": [],
"source": [
"device = hp4155a.HP4155a('GPIB0::17::INSTR')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e062d8a6-6b24-49e6-b88c-d59060ac46c1",
"metadata": {},
"outputs": [],
"source": [
"variables = device.show_variables()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "dd600907-ab15-440f-93fa-f0d3a1c19651",
"metadata": {},
"outputs": [],
"source": [
"values = {}\n",
"for variable in variables:\n",
" try:\n",
" current_values = device.return_values(variable)\n",
" if len(current_values)>1: # There are also some constants\n",
" values[variable] = current_values\n",
" except:\n",
" print(f\"No Values for variable {variable}\")\n",
"\n",
"df = pd.DataFrame(values)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "87309758-aea7-418d-8dfa-024f827330ce",
"metadata": {},
"outputs": [],
"source": [
"del device"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "62e77124-db55-4208-b008-d69379de6407",
"metadata": {},
"outputs": [],
"source": [
"for col in df.columns.values.tolist():\n",
" df.loc[abs(df[col]) > 1e30, col] = np.nan"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "d64a276f-544c-436e-a948-0e3519e12e74",
"metadata": {},
"outputs": [],
"source": [
"# Prepare to save to file\n",
"def create_file(filename):\n",
" root = tk.Tk()\n",
" root.withdraw()\n",
" root.lift() #show window above all other applications\n",
"\n",
" root.attributes(\"-topmost\", True)#window stays above all other applications\n",
"\n",
" file = filedialog.asksaveasfilename(defaultextension=\".txt\", filetypes=[(\"Text files\",\"*.txt\")],title = \"save results path\",initialfile =filename)\n",
"\n",
" #check if the file path is correct(.txt)\n",
" while file.endswith(\".txt\") == False:\n",
" #open again filedialog with error message box\n",
" tk.messagebox.showerror(message='invalid filename!')\n",
" file = filedialog.asksaveasfilename(defaultextension=\".txt\", filetypes=[(\"Text files\",\"*.txt\")],title = \"save results path\",initialfile =filename)\n",
" root.destroy()\n",
" return file"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b1dfe94d-96ca-432c-b180-cf581dcf3c41",
"metadata": {},
"outputs": [],
"source": [
"date = datetime.now().strftime('%d_%m_%Y_%H_%M_%S') "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "404b28c8-d14c-41cc-91da-097647338d32",
"metadata": {},
"outputs": [],
"source": [
"filename = \"Rescue_Data_ADU_\"+date +\".txt\""
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "268dd9f8-1092-41d5-aca5-668ecf5c38d6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data saved to file successfully\n"
]
}
],
"source": [
"file=create_file(filename)\n",
"df.to_csv(file,sep=\" \",mode='w',na_rep = 'NaN')\n",
"\n",
"print(\"Data saved to file successfully\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "00854758-b6e6-459c-8329-92bedc2c3f72",
"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
}
%% 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
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment