Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Experimental Physics
Quantum Circuits
python-repo
Commits
26fc5d3f
Commit
26fc5d3f
authored
Jul 28, 2020
by
Christian Schneider
Browse files
First init
parent
28a202be
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
246 additions
and
26 deletions
+246
-26
Instruments/SA.py
Instruments/SA.py
+108
-22
Instruments/VNA.py
Instruments/VNA.py
+138
-4
No files found.
Instruments/SA.py
View file @
26fc5d3f
...
...
@@ -122,7 +122,7 @@ class SA(object):
f_span
=
None
,
BW
=
'auto'
,
points
=
8001
,
units
=
'dBm'
,
averages
=
10
,
filename
=
None
,
autoplot
=
True
,
dm_pars
=
None
,
log_freq
=
False
,
sweep_time
=
'auto'
,
print_info
=
True
):
print_info
=
True
,
fetch
=
True
):
"""
Measure a spectrum. You can specify either f_start and f_stop or
f_center and f_span.
...
...
@@ -170,6 +170,7 @@ class SA(object):
# Prepare spectrum
self
.
instr
.
prepare_spectrum
()
# Frequency
if
f_start
is
not
None
:
self
.
instr
.
f_start
(
f_start
)
...
...
@@ -200,35 +201,124 @@ class SA(object):
# Wait for device to be ready
while
int
(
self
.
instr
.
com
(
'*OPC'
))
!=
1
:
time
.
sleep
(
0.5
)
# Get sweep_time
st
=
self
.
instr
.
sweep_time
()
time
.
sleep
(
0.01
)
# Start measurement
self
.
instr
.
initiate_data
(
trace
)
# Progress bar
time
.
sleep
(
1
)
#
time.sleep(1)
# Progress bar currently too slow. Overestimates sweep time.
#for i in tqdm_notebook(range(averages), unit="Sweep", leave=False):
# time.sleep(st*1.01)
# Wait for OPC flag '1' to fetch the data
count
=
1
# Second counter
while
True
:
try
:
self
.
instr
.
com
(
'*OPC'
)
except
VisaIOError
:
print
(
'
\r
OPC timeout. Waiting 1s and trying again. Retries:'
+
' {}'
.
format
(
count
),
end
=
''
,
flush
=
True
)
count
+=
1
# # Wait for OPC flag '1' to fetch the data
# count = 1 # Second counter
# while True:
# try:
# self.instr.com('*OPC')
# except VisaIOError:
# print('\rOPC timeout. Waiting 1s and trying again. Retries:'+
# ' {}'.format(count), end='', flush=True)
# count += 1
# else:
# break
sweep_time
=
self
.
instr
.
com
(
'SENS:ACQ:SEC'
)
time
.
sleep
(
sweep_time
*
averages
)
while
self
.
instr
.
com
(
'*OPC'
)
!=
1
:
time
.
sleep
(
0.05
)
act_bw
=
self
.
instr
.
bw_res
()
if
act_bw
!=
BW
:
print
(
'Resolution BW changed by device to {:.0f} Hz'
.
format
(
act_bw
))
if
not
fetch
:
return
freqs
,
data
,
info
=
self
.
instr
.
read_data
(
trace
,
print_info
)
u
=
info
[
'units'
]
data
=
data_table
([
freqs
,
data
],
[
'Frequency (Hz)'
,
'Spectrum ({})'
.
format
(
u
)])
# Add parameters
data
.
insert_par
(
frange
=
[
self
.
instr
.
f_start
(),
self
.
instr
.
f_stop
()],
npoints
=
self
.
instr
.
points
(),
navg
=
self
.
instr
.
averages
(),
BW
=
act_bw
,
sweep_time
=
self
.
instr
.
sweep_time
(),
device
=
self
.
identify
(),
**
dm_pars
)
# Print changes
# Update database
update_db
(
self
)
# Autoplot
if
autoplot
:
display
(
data
.
plot
())
# Save data
if
filename
:
data
.
save
(
filename
)
else
:
break
return
data
def
save_spectrum
(
self
,
filename
=
None
,
autoplot
=
True
,
dm_pars
=
None
,
trace
=
1
,
print_info
=
True
):
"""
This just retrieve the data trace present on the spectrum analyser. The parameters are specified for the data module pars.
Parameters
------------
f_start : float, int
Start frequency in Hz
f_stop : float, int
Stop frequency in Hz
f_center : float, int
Center frequency in Hz
f_span : float, in
Span in Hz
BW : str, float, int
Resolution Bandwidth in Hz
points : int
Number of points. Choose between 801, 1601, 4001, 8001, 16001,
32001, 64001. If other value is entered, it will pick the closest
value
units : str
Units for y axis. Typical values are dBm, dBV or Volt
averages : int
Number of averages
filename : str
Filename for saving data. If no filename is given, the function
returns the datamodule
autoplot : bool
Plot automatically if data is acquired
dm_pars : None, dict
Dictionary with additional parameters for datamodule. E.g. {
'coil_current': 1e-3}
log_freq : bool
Logarithmic scale for frequencies
sweep_time : str, float
Sweep time in seconds
print_info : bool (Just for Tektronix right now)
Print information of the spectrum analayzer
TODO: Multiple traces
"""
if
dm_pars
is
None
:
dm_pars
=
{}
freqs
,
data
,
info
=
self
.
instr
.
read_data
(
trace
,
print_info
)
u
=
info
[
'units'
]
data
=
data_table
([
freqs
,
data
],
[
'Frequency (Hz)'
,
'Spectrum ({})'
.
format
(
u
)])
...
...
@@ -243,9 +333,6 @@ class SA(object):
device
=
self
.
identify
(),
**
dm_pars
)
# Print changes
if
act_bw
!=
BW
:
print
(
'Resolution BW changed by device to {:.0f} Hz'
.
format
(
act_bw
))
# Update database
update_db
(
self
)
...
...
@@ -278,5 +365,4 @@ class SA(object):
'Points'
:
self
.
instr
.
points
(),
'Sweep time'
:
'{:.3e} s'
.
format
(
self
.
instr
.
sweep_time
()),
}
dct
.
update
(
self
.
instr
.
additionnal_parameters
())
return
dct
Instruments/VNA.py
View file @
26fc5d3f
...
...
@@ -247,6 +247,7 @@ class VNA(object):
except
:
pass
f
,
v_re
,
v_im
=
self
.
instr
.
meas_complex
(
f_range
=
f_range
,
npoints
=
npoints
,
navg
=
navg
,
power
=
power
,
Spar
=
Spar
,
...
...
@@ -256,19 +257,25 @@ class VNA(object):
# Save in datamodule
data
=
data_complex
(
f
,
np
.
array
(
v_re
)
+
1j
*
np
.
array
(
v_im
))
data
.
time_start
=
time_start
data
.
time_stop
=
time
.
strftime
(
data
.
date_format
,
time
.
localtime
())
time_tt
=
time
.
time
()
if
Temp_reading
and
self
.
CryoID
:
a
=
SR
.
SensorReader
(
self
.
CryoID
,
file_path
=
Temperature_file_path
)
temp_start
=
a
.
base_temp
()
data
.
temp_start
=
temp_start
data
.
temp_stop
=
a
.
base_temp
()
data
.
load_var
(
f
,
v_re
,
v_im
)
#data.load_var(f, v_re, v_im)
data
.
insert_par
(
frange
=
f_range
,
npoints
=
npoints
,
navg
=
navg
,
power
=
power
,
Spar
=
Spar
,
BW
=
BW
,
device
=
self
.
identify
(),
**
parameters
)
# Database
if
self
.
db
:
update_db
(
self
)
...
...
@@ -280,6 +287,94 @@ class VNA(object):
else
:
return
data
def
meas_complex_avg_noGet
(
self
,
f_range
,
npoints
=
1601
,
navg
=
10
,
power
=-
50
,
Spar
=
'S21'
,
BW
=
1e3
,
autoSave
=
True
,
filename
=
'measurements/measurement.dm'
,
Use_Date
=
True
,
overwrite
=
False
,
Temp_reading
=
True
,
Temperature_file_path
=
'/home/measurement/DataLogging'
'/Fridges/'
,
parameters
=
{},
power_port2
=
False
,
scale
=
"lin"
):
"""VNA Measurement with complex data format.
Automatically save as complex datamodule (Voltages) if not specified
otherwise (autoSave=False).
Parameters
-----------
f_range : [float, float]
Frequency range in GHz. [f_start, f_stop]
npoints : int
Number of Points
navg : int
Number of averages
power : float
VNA output power in dBm
Spar : str
S Parameter to measure. E.g. 'S21'
BW : int
IF Bandwidth in Hz
autoSave : bool
Automatically save data to disk (RECOMMENDED!!)
filename : str
Filepath + Filename. E.g. '/measurements/test'
overwrite : bool
Force override
Temp_reading : bool
Append temperature to datamodule file
Use_Date : bool
Add Date as leading part of filename
parameters : dict
Additional parameters to save in dm
power_port2 : bool
Power excitation on port2
scale : "lin", "log"
Scale for frequencies
Returns
--------
datamodule object
Returns datamodule object if autoSave is set to False
"""
# Initialize datamodule
time_start
=
time
.
strftime
(
'%Y-%m-%d-%H:%M:%S'
,
time
.
localtime
())
time_tt
=
time
.
time
()
# Update monitor values
try
:
pars
=
{
'f_start'
:
'{:.4f} GHz'
.
format
(
f_range
[
0
]),
'f_stop'
:
'{:.4f} GHz'
.
format
(
f_range
[
1
]),
'Power'
:
'{:.0f} dBm'
.
format
(
power
),
'Points'
:
'{:.0f}'
.
format
(
npoints
),
'Averages'
:
'{:.0f}'
.
format
(
navg
),
'Format'
:
'{}'
.
format
(
"REAL"
),
'IF Bandwidth'
:
'{:.2f} kHz'
.
format
(
BW
/
1e3
),
'RF Power'
:
'{}'
.
format
(
"ON"
),
'S-Parameter'
:
'{}'
.
format
(
Spar
),
}
update_db
(
self
,
pars
=
pars
)
except
:
pass
self
.
instr
.
meas_complex_noGet
(
f_range
=
f_range
,
npoints
=
npoints
,
navg
=
navg
,
power
=
power
,
Spar
=
Spar
,
BW
=
BW
,
power_port2
=
power_port2
,
scale
=
scale
)
def
meas_complex_segm
(
self
,
segments
,
navg
=
1
,
...
...
@@ -366,15 +461,54 @@ class VNA(object):
else
:
return
data
def
save_current_measurement_cplx
(
self
,
f_range
,
npoints
=
1601
,
navg
=
10
,
power
=-
50
,
Spar
=
'S21'
,
BW
=
1e3
,
autoSave
=
True
,
filename
=
'measurements/measurement.dm'
,
Use_Date
=
True
,
overwrite
=
False
,
parameters
=
{}):
"""Gets current complex measurement data and saves to cplx. datamodule
"""
data
=
data_complex
()
re
,
im
=
np
.
asarray
(
self
.
instr
.
read_complex
(),
dtype
=
'float'
)
try
:
# Try to get frequency range (not supported by E5080)
x
=
np
.
asarray
(
self
.
instr
.
read_frequencies
(),
dtype
=
'float'
)
except
:
# If not supported, return zeros for setting later manually
print
(
"Could not receive frequencies. Set to 0. Please"
"add manually"
)
x
=
np
.
zeros_like
(
re
)
data
.
x
=
x
/
1e9
data
.
value
=
re
+
1j
*
im
data
.
time_stop
=
time
.
strftime
(
data
.
date_format
,
time
.
localtime
())
data
.
insert_par
(
frange
=
f_range
,
npoints
=
npoints
,
navg
=
navg
,
power
=
power
,
Spar
=
Spar
,
BW
=
BW
,
device
=
self
.
identify
(),
**
parameters
)
if
autoSave
is
True
:
data
.
save
(
filename
,
Use_Date
,
overwrite
)
return
data
else
:
return
data
def
get_current_measurement_cplx
(
self
):
"""Gets current complex measurement data and saves to cplx. datamodule
"""
data
=
data_complex
()
re
=
np
.
asarray
(
self
.
instr
.
trace_read
(
1
)[
0
]
,
dtype
=
'float'
)
im
=
np
.
asarray
(
self
.
instr
.
trace_read
(
2
)[
0
],
dtype
=
'float'
)
re
,
im
=
np
.
asarray
(
self
.
instr
.
read_complex
()
,
dtype
=
'float'
)
try
:
# Try to get frequency range (not supported by E5080)
x
=
np
.
asarray
(
self
.
instr
.
freq_read
(),
dtype
=
'float'
)
x
=
np
.
asarray
(
self
.
instr
.
read_frequencies
(),
dtype
=
'float'
)
except
:
# If not supported, return zeros for setting later manually
print
(
"Could not receive frequencies. Set to 0. Please"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment