Commit 26fc5d3f authored by Christian Schneider's avatar Christian Schneider
Browse files

First init

parent 28a202be
...@@ -122,7 +122,7 @@ class SA(object): ...@@ -122,7 +122,7 @@ class SA(object):
f_span=None, BW='auto', points=8001, units='dBm', f_span=None, BW='auto', points=8001, units='dBm',
averages=10, filename=None, autoplot=True, averages=10, filename=None, autoplot=True,
dm_pars=None, log_freq=False, sweep_time='auto', 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 Measure a spectrum. You can specify either f_start and f_stop or
f_center and f_span. f_center and f_span.
...@@ -170,6 +170,7 @@ class SA(object): ...@@ -170,6 +170,7 @@ class SA(object):
# Prepare spectrum # Prepare spectrum
self.instr.prepare_spectrum() self.instr.prepare_spectrum()
# Frequency # Frequency
if f_start is not None: if f_start is not None:
self.instr.f_start(f_start) self.instr.f_start(f_start)
...@@ -200,35 +201,124 @@ class SA(object): ...@@ -200,35 +201,124 @@ class SA(object):
# Wait for device to be ready # Wait for device to be ready
while int(self.instr.com('*OPC')) != 1: while int(self.instr.com('*OPC')) != 1:
time.sleep(0.5) time.sleep(0.01)
# Get sweep_time
st = self.instr.sweep_time()
# Start measurement # Start measurement
self.instr.initiate_data(trace) self.instr.initiate_data(trace)
# Progress bar # Progress bar
time.sleep(1) # time.sleep(1)
# Progress bar currently too slow. Overestimates sweep time. # Progress bar currently too slow. Overestimates sweep time.
#for i in tqdm_notebook(range(averages), unit="Sweep", leave=False): #for i in tqdm_notebook(range(averages), unit="Sweep", leave=False):
# time.sleep(st*1.01) # time.sleep(st*1.01)
# Wait for OPC flag '1' to fetch the data # # Wait for OPC flag '1' to fetch the data
count = 1 # Second counter # count = 1 # Second counter
while True: # while True:
try: # try:
self.instr.com('*OPC') # self.instr.com('*OPC')
except VisaIOError: # except VisaIOError:
print('\rOPC timeout. Waiting 1s and trying again. Retries:'+ # print('\rOPC timeout. Waiting 1s and trying again. Retries:'+
' {}'.format(count), end='', flush=True) # ' {}'.format(count), end='', flush=True)
count += 1 # count += 1
else: # else:
break # 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:
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) freqs, data, info = self.instr.read_data(trace, print_info)
u = info['units'] u = info['units']
data = data_table([freqs, data], data = data_table([freqs, data],
['Frequency (Hz)', 'Spectrum ({})'.format(u)]) ['Frequency (Hz)', 'Spectrum ({})'.format(u)])
...@@ -242,10 +332,7 @@ class SA(object): ...@@ -242,10 +332,7 @@ class SA(object):
sweep_time=self.instr.sweep_time(), sweep_time=self.instr.sweep_time(),
device=self.identify(), device=self.identify(),
**dm_pars) **dm_pars)
# Print changes
if act_bw != BW:
print('Resolution BW changed by device to {:.0f} Hz'.format(act_bw))
# Update database # Update database
update_db(self) update_db(self)
...@@ -278,5 +365,4 @@ class SA(object): ...@@ -278,5 +365,4 @@ class SA(object):
'Points': self.instr.points(), 'Points': self.instr.points(),
'Sweep time': '{:.3e} s'.format(self.instr.sweep_time()), 'Sweep time': '{:.3e} s'.format(self.instr.sweep_time()),
} }
dct.update(self.instr.additionnal_parameters())
return dct return dct
...@@ -247,6 +247,7 @@ class VNA(object): ...@@ -247,6 +247,7 @@ class VNA(object):
except: except:
pass pass
f, v_re, v_im = self.instr.meas_complex(f_range=f_range, f, v_re, v_im = self.instr.meas_complex(f_range=f_range,
npoints=npoints, navg=navg, npoints=npoints, navg=navg,
power=power, Spar=Spar, power=power, Spar=Spar,
...@@ -256,19 +257,25 @@ class VNA(object): ...@@ -256,19 +257,25 @@ class VNA(object):
# Save in datamodule # Save in datamodule
data = data_complex(f, np.array(v_re) + 1j * np.array(v_im)) data = data_complex(f, np.array(v_re) + 1j * np.array(v_im))
data.time_start = time_start data.time_start = time_start
data.time_stop = time.strftime(data.date_format, time.localtime()) data.time_stop = time.strftime(data.date_format, time.localtime())
time_tt = time.time()
if Temp_reading and self.CryoID: if Temp_reading and self.CryoID:
a = SR.SensorReader(self.CryoID,file_path=Temperature_file_path) a = SR.SensorReader(self.CryoID,file_path=Temperature_file_path)
temp_start = a.base_temp() temp_start = a.base_temp()
data.temp_start = temp_start data.temp_start = temp_start
data.temp_stop = a.base_temp() 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, data.insert_par(frange=f_range, npoints=npoints, navg=navg,
power=power, Spar=Spar, BW=BW, power=power, Spar=Spar, BW=BW,
device=self.identify(), device=self.identify(),
**parameters) **parameters)
# Database # Database
if self.db: if self.db:
update_db(self) update_db(self)
...@@ -280,6 +287,94 @@ class VNA(object): ...@@ -280,6 +287,94 @@ class VNA(object):
else: else:
return data 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, def meas_complex_segm(self,
segments, segments,
navg=1, navg=1,
...@@ -365,16 +460,55 @@ class VNA(object): ...@@ -365,16 +460,55 @@ class VNA(object):
return data return data
else: else:
return data 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): def get_current_measurement_cplx(self):
"""Gets current complex measurement data and saves to cplx. datamodule """Gets current complex measurement data and saves to cplx. datamodule
""" """
data = data_complex() data = data_complex()
re = np.asarray(self.instr.trace_read(1)[0], dtype='float') re, im = np.asarray(self.instr.read_complex(), dtype='float')
im = np.asarray(self.instr.trace_read(2)[0], dtype='float')
try: try:
# Try to get frequency range (not supported by E5080) # 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: except:
# If not supported, return zeros for setting later manually # If not supported, return zeros for setting later manually
print("Could not receive frequencies. Set to 0. Please" print("Could not receive frequencies. Set to 0. Please"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment