Skip to content

Commit

Permalink
Merge pull request #621 from slaclab/find-freq-eta-scan-speedup
Browse files Browse the repository at this point in the history
Find freq eta scan speedup
  • Loading branch information
eyyoung24 authored Mar 24, 2021
2 parents 358a65a + 0f478e4 commit b95a6dc
Show file tree
Hide file tree
Showing 12 changed files with 2,144 additions and 217 deletions.
16 changes: 11 additions & 5 deletions python/pysmurf/client/command/smurf_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
A function that mimics mce_cmd. This allows the user to run specific pysmurf
commands from the command line.
"""
def make_runfile(output_dir, row_len=60, num_rows=60, data_rate=60, num_rows_reported=60):

def make_runfile(output_dir, row_len=60, num_rows=60, data_rate=60,
num_rows_reported=60):
"""
Make the runfile
"""
S = pysmurf.client.SmurfControl(cfg_file=cfg_filename, smurf_cmd_mode=True,
setup=False)
S = pysmurf.client.SmurfControl(cfg_file=cfg_filename, smurf_cmd_mode=True, setup=False)


S.log('Making Runfile')

Expand Down Expand Up @@ -125,11 +127,12 @@ def acq_n_frames(S, n_frames):
data_rate = 200
row_len = 42
num_rows_reported = num_rows

start_acq(S)
make_runfile(S.output_dir, num_rows=num_rows, data_rate=data_rate,
row_len=row_len, num_rows_reported=num_rows_reported)
# sample_rate = 50E6 / num_rows / data_rate / row_len
sample_rate = data_rate
sample_rate = 50E6 / num_rows / data_rate / row_len

wait_time = n_frames / sample_rate
time.sleep(wait_time)
stop_acq(S)
Expand Down Expand Up @@ -197,6 +200,7 @@ def get_port(S, slot):

parser.add_argument('--epics-prefix', help='The epics root',
action='store', default=None, type=str)

# Offline mode
parser.add_argument('--offline', help='For offline debugging',
default=False, action='store_true')
Expand Down Expand Up @@ -333,6 +337,7 @@ def get_port(S, slot):
sys.exit(0)

epics_prefix = args.epics_prefix

S = pysmurf.client.SmurfControl(epics_root=epics_prefix,
cfg_file=cfg_filename, smurf_cmd_mode=True, setup=False,
offline=offline)
Expand Down Expand Up @@ -468,6 +473,7 @@ def get_port(S, slot):
S.log('Starting continuous acquisition')
start_acq(S)
# Don't make runfiles for now. Need to figure out

# make_runfile(S.output_dir, num_rows=args.num_rows,
# data_rate=args.data_rate, row_len=args.row_len,
# num_rows_reported=args.num_rows_reported)
Expand Down
31 changes: 31 additions & 0 deletions python/pysmurf/client/command/smurf_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,37 @@ def get_eta_scan_dwell(self, band, **kwargs):
self._cryo_root(band) + self._eta_scan_dwell_reg,
**kwargs)

_run_serial_find_freq_reg = 'runSerialFindFreq'

def set_run_serial_find_freq(self, band, val, sync_group=True, **kwargs):
"""
Runs the eta scan. Set the channel using set_eta_scan_channel()
Args
----
band : int
The band to eta scan.
val : bool
Start the eta scan.
"""
self._caput(
self._cryo_root(band) + self._run_serial_find_freq_reg,
val, **kwargs)

monitorPV=(
self._cryo_root(band) + self._eta_scan_in_progress_reg)

inProgress = True
if sync_group:
while inProgress:
sg = SyncGroup([monitorPV], timeout=360)
sg.wait()
vals = sg.get_values()
inProgress = (vals[monitorPV] == 1)
self.log(
'serial find freq complete ; etaScanInProgress = ' +
f'{vals[monitorPV]}', self.LOG_USER)

_run_eta_scan_reg = 'runEtaScan'

def set_run_eta_scan(self, band, val, **kwargs):
Expand Down
8 changes: 5 additions & 3 deletions python/pysmurf/client/debug/smurf_iv.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,12 @@ def analyze_iv(self, v_bias, resp, make_plot=True, show_plot=False,
vb_max = np.max(v_bias)
vb_min = np.min(v_bias)
delta_v = float(vb_max - vb_min)/n_ticks
axt.set_xticks(np.arange(ib_min, ib_max+delta, delta))
xticks = np.arange(ib_min, ib_max+delta, delta)[:n_ticks+1]
xticklabels = np.arange(vb_min, vb_max+delta_v, delta_v)[:n_ticks+1]

axt.set_xticks(xticks)
axt.set_xticklabels(
[f'{x:.2f}' for x in
np.arange(vb_min, vb_max+delta_v, delta_v)])
[f'{x:.2f}' for x in xticklabels])
axt.set_xlabel(r'Commanded $V_b$ [V]')

ax_si.plot(i_bias_bin[:-1],si,color=color_meas)
Expand Down
44 changes: 33 additions & 11 deletions python/pysmurf/client/debug/smurf_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

from pysmurf.client.base import SmurfBase
from pysmurf.client.util import tools
from pysmurf.client.util.pub import set_action

class SmurfNoiseMixin(SmurfBase):

@set_action()
def take_noise_psd(self, meas_time,
channel=None, nperseg=2**12,
detrend='constant', fs=None,
Expand Down Expand Up @@ -95,11 +97,11 @@ def take_noise_psd(self, meas_time,
if high_freq is None:
high_freq=np.array([1., 10.])
if datafile is None:
# Take the data if not given as input
datafile = self.take_stream_data(meas_time,
downsample_factor=downsample_factor,
write_log=write_log,
reset_unwrapper=reset_unwrapper,
reset_filter=reset_filter)
downsample_factor=downsample_factor,
write_log=write_log, reset_unwrapper=reset_unwrapper,
reset_filter=reset_filter)
else:
self.log(f'Reading data from {datafile}')

Expand All @@ -114,12 +116,11 @@ def take_noise_psd(self, meas_time,

phase *= self._pA_per_phi0/(2.*np.pi) # phase converted to pA

flux_ramp_freq = self.get_flux_ramp_freq() * 1.0E3
flux_ramp_freq = self.get_flux_ramp_freq() * 1.0E3 # convert to Hz

if fs is None:
if downsample_factor is None:
downsample_factor = self.get_downsample_factor()
# flux ramp rate returns in kHz
fs = flux_ramp_freq/downsample_factor

# Generate downsample transfer function - downsampling is at
Expand All @@ -144,9 +145,12 @@ def take_noise_psd(self, meas_time,
f_knee_list = []
n_list = []

plt.ion()
if not show_plot:
# Live plotting or not
if show_plot:
plt.ion()
else:
plt.ioff()

for c, (b, ch) in enumerate(zip(bands, channels)):
if ch < 0:
continue
Expand Down Expand Up @@ -239,6 +243,8 @@ def take_noise_psd(self, meas_time,
f'_noise_timestream_b{b}_ch{ch:03}{plotname_append}.png'
fig.savefig(os.path.join(self.plot_dir, plot_name),
bbox_inches='tight')
self.pub.register_file(os.path.join(self.plot_dir, plot_name),
'noise_timestream', plot=True)

# Close the individual channel plots - otherwise too many
# plots are brought to screen
Expand All @@ -247,12 +253,20 @@ def take_noise_psd(self, meas_time,
if save_data:
for i, (l, h) in enumerate(zip(low_freq, high_freq)):
save_name = basename+f'_{l:3.2f}_{h:3.2f}.txt'
outfn = os.path.join(self.plot_dir, save_name)
# outfn = os.path.join(self.plot_dir, save_name)
outfn = os.path.join(self.output_dir, save_name)

np.savetxt(outfn, np.c_[res_freqs,noise_floors[i],f_knees])
np.savetxt(outfn, np.c_[res_freqs, noise_floors[i], f_knees])
# Publish the data
self.pub.register_file(outfn, 'noise_timestream', format='txt')

np.save(os.path.join(self.output_dir,
f'{basename}_wl_list'), wl_list)
np.save(os.path.join(self.output_dir,
f'{basename}_f_knee_list'), f_knee_list)
np.save(os.path.join(self.output_dir,
f'{basename}_n_list'), n_list)

if make_summary_plot:
bins = np.arange(0,351,20)
for i, (l, h) in enumerate(zip(low_freq, high_freq)):
Expand All @@ -267,6 +281,10 @@ def take_noise_psd(self, meas_time,
f'{l}_{h}_noise_hist{plotname_append}.png')
plt.savefig(os.path.join(self.plot_dir, plot_name),
bbox_inches='tight')
self.pub.register_file(
os.path.join(self.plot_dir, plot_name),
'noise_hist', plot=True
)
if show_plot:
plt.show()
else:
Expand Down Expand Up @@ -307,14 +325,18 @@ def take_noise_psd(self, meas_time,
plt.savefig(os.path.join(self.plot_dir,
noise_params_hist_fname),
bbox_inches='tight')
self.pub.register_file(
os.path.join(self.plot_dir, noise_params_hist_fname),
'noise_params', plot=True
)

if show_plot:
plt.show()
else:
plt.close()

if return_noise_params:
return datafile, (res_freqs, noise_floors, f_knees)
return datafile, (res_freqs, noise_floors, f_knees, wl_list, f_knee_list, n_list)

else:
return datafile
Expand Down
Loading

0 comments on commit b95a6dc

Please sign in to comment.