Exemple #1
0
def make_runfile(output_dir, row_len=60, num_rows=60, data_rate=60,
                 num_rows_reported=60):
    """
    Make the runfile
    """
    #S.log('Making pysmurf object')
    S = pysmurf.SmurfControl(cfg_file=os.path.join(os.path.dirname(__file__), 
        '..', 'cfg_files' , cfg_filename), smurf_cmd_mode=True, setup=False)

    S.log('Making Runfile')
    
    # 20181119 dB, modified to use the correct format runfile.
    #with open(os.path.join(os.path.dirname(__file__),"runfile/runfile_template.txt")) as f:
    with open(os.path.join(os.path.dirname(__file__),
        "runfile/runfile.default.bicep53")) as f:
        lines = f.readlines()
        line_holder = []
        for l in lines:
            # A bunch of replacements
            if "ctime=<replace>" in l:
                timestamp = S.get_timestamp()
                S.log('Adding ctime {}'.format(timestamp))
                l = l.replace("ctime=<replace>", "ctime={}".format(timestamp))
            elif "Date:<replace>" in l:
                time_string = time.strftime("%a %b %d %H:%M:%S %Y", 
                    time.localtime())
                S.log('Adding date {}'.format(time_string))
                l = l.replace('Date:<replace>', "Date: {}".format(time_string))
            elif "row_len : <replace>" in l:
                S.log("Adding row_len {}".format(row_len))
                l = l.replace('row_len : <replace>', 
                    'row_len : {}'.format(row_len))
            elif "num_rows : <replace>" in l:
                S.log("Adding num_rows {}".format(num_rows))
                l = l.replace('num_rows : <replace>', 
                    'num_rows : {}'.format(num_rows))
            elif "num_rows_reported : <replace>" in l:
                S.log("Adding num_rows_reported {}".format(num_rows_reported))
                l = l.replace('num_rows_reported : <replace>', 
                    'num_rows_reported : {}'.format(num_rows_reported))
            elif "data_rate : <replace>" in l:
                S.log("Adding data_rate {}".format(data_rate))
                l = l.replace('data_rate : <replace>', 
                    'data_rate : {}'.format(data_rate))
            line_holder.append(l)
            
    full_path = os.path.join(output_dir, 
        'smurf_status_{}.txt'.format(S.get_timestamp()))

    #20181119 mod by dB to dump content of runfile, not path of runfile
    #print(full_path)
    for line in line_holder:
        print(line)
    with open(full_path, "w") as f1:
        f1.writelines(line_holder)

    S.log("Writing to {}".format(full_path))
    sys.stdout.writelines(line_holder)
import os
import pysmurf
import matplotlib.pylab as plt
import numpy as np
import sys

config_file_path = '/data/pysmurf_cfg/'

slot = int(sys.argv[1])
epics_prefix = 'smurf_server_s%d' % slot

if slot == 5:
    config_file = 'experiment_fp29_srv03_dspv3_cc02-03.cfg'
else:
    assert False, "There isn't a SMuRF carrier in slot %d right now!" % slot

config_file = os.path.join(config_file_path, config_file)

S = pysmurf.SmurfControl(epics_root=epics_prefix,
                         cfg_file=config_file,
                         setup=False,
                         make_logfile=False)
import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt
import os
import seaborn as sns
import glob
import pysmurf

datadir = '/data/smurf_data/20190216/1550347814/outputs'
datafile = os.path.join(datadir, '1550349384.dat')

S = pysmurf.SmurfControl(make_logfile=False,
                         epics_root='test_epics',
                         cfg_file='/usr/local/controls/Applications/'+\
                             'smurf/pysmurf/pysmurf/cfg_files/'+\
                             'experiment_fp28_smurfsrv04.cfg',
                         no_dir=True)

t, d, m = S.read_stream_data(datafile)

# Extract useful values
_, filename = os.path.split(datafile)
timestamp = filename.split('.')[0]

# Channels with IV curves
ivch = np.array([
    16, 32, 64, 165, 171, 179, 197, 203, 213, 222, 256, 389, 395, 398, 415,
    421, 427, 447
])
d = d[m[2][ivch]]
Exemple #4
0
import pysmurf
import numpy as np
import matplotlib.pyplot as plt

S = pysmurf.SmurfControl(setup=False,
                         cfg_file='/usr/local/controls/Applications/smurf/pysmurf/pysmurf/cfg_files/experiment_kx_mapodaq.cfg',make_logfile=False)

tones = np.arange(5,16)
freq = 5193.799997711181
resp = np.zeros((len(tones), 201), dtype=complex)

for i, t in enumerate(tones):
    print('Tone {}'.format(t))
    f, resp[i], eta = S.eta_estimator(2, freq, t, f_sweep_half=.3,
                              df_sweep=.003)

fig, ax = plt.subplots(3, sharex=True, figsize=(5,8))
cm = plt.get_cmap('viridis')
for i, t in enumerate(tones):
    color = cm(i/len(tones))
    ax[0].plot(f, np.abs(resp[i]), color=color, label='{:02}'.format(t))
    ax[1].plot(f, np.real(resp[i]), color=color)
    ax[2].plot(f, np.imag(resp[i]), color=color)

ax[0].legend(loc='upper left', ncol=2)
ax[0].set_ylabel('Abs')
ax[1].set_ylabel('Real')
ax[2].set_ylabel('Imag')
ax[2].set_xlabel('Freq [MHz]')
plt.tight_layout()
import pysmurf
import matplotlib.pyplot as plt
import scipy.signal as signal
import numpy as np
import os

plt.ioff()

config_file = '/usr/local/src/pysmurf/cfg_files/experiment_fp28_docker.cfg'
S = pysmurf.SmurfControl(make_logfile=False,
                         epics_root='test_epics2',
                         cfg_file=config_file,
                         offline=True)

datadir = '/data/smurf_data/20190418/1555618703/outputs/'
plotdir = datadir.replace('outputs', 'plots')

#filename = '1555622545.dat'
filename = '1555628193.dat'
fn = filename.split('.')[0]

datafile = os.path.join(datadir, filename)

t, d, m = S.read_stream_data(datafile, n_samp=10000)
_, n_res = np.shape(np.where(m != -1))

d *= S.pA_per_phi0 / (2 * np.pi)  # phase to pA

# Take SVD
u, s, vh = S.noise_svd(d, m)
Exemple #6
0
import pysmurf

S = pysmurf.SmurfControl(make_logfile=False,setup=False,epics_root='test_epics2',cfg_file='/usr/local/controls/Applications/smurf/pysmurf/pysmurf/cfg_files/experiment_fp29_smurfsrv04.cfg')
Exemple #7
0
import pysmurf
import numpy as np
import matplotlib.pyplot as plt

S = pysmurf.SmurfControl(make_logfile=False, setup=True)

S.set_noise_select(3, 1, write_log=True)
S.get_noise_select(3, write_log=True)

n_sample = 2**19
n = 4

dat = np.zeros((n, n_sample), dtype=complex)
for i in np.arange(n):
    dat[i] = S.read_adc_data(band, n_samples, hw_trigger=True)
    time.sleep(.5)

S.set_noise_select(3, 0, write_log=True)
S.get_noise_select(3, write_log=True)

fig, ax = plt.subplots(1)
end = 250
for i in np.arange(n):
    ax.plot(dat[n, :end])

plt.show()
Exemple #8
0
import numpy as np
import pysmurf
import matplotlib.pyplot as plt

# datafile = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180921/1537561706/outputs/1537562122.dat'
# datafile = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180921/1537569911/outputs/1537569951.dat'
datafile = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180924/1537818448/outputs/1537818492.dat'
data_dir = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180924/1537818448/outputs/'
S = pysmurf.SmurfControl(make_logfile=False, setup=False, data_dir=data_dir)

print('Loading data')
timestamp, I, Q = S.read_stream_data(datafile)

# ch = 0
# chs = np.array([0, 16, 32, 64, 139, 147, 179, 203, 245, 288, 395, 398, 415,
#     427, 447, 459])
chs = np.array([16])
# chs = np.arange(16)

bias = np.arange(19.9, 0, -.1)

ivs = {}
ivs['bias'] = bias
for ch in chs:
    phase = S.iq_to_phase(I[ch], Q[ch]) * 1.443

    print('Running IV analysis')
    r, rn, idx = S.analyze_slow_iv(bias,
                                   phase,
                                   make_plot=True,
                                   show_plot=True,
Exemple #9
0
    # Extract inputs
    args = parser.parse_args()

    offline = args.offline

    # Check for too many commands
    n_cmds = (args.log is not None) + args.tes_bias + args.slow_iv + \
        args.plc + args.tune + args.start_acq + args.stop_acq + \
        args.last_tune + (args.use_tune is not None) + args.overbias_tes + \
        args.bias_bump + args.soft_reset + args.make_runfile + args.setup + \
        args.flux_ramp_off + args.all_off + args.check_lock + args.status
    if n_cmds > 1:
        sys.exit(0)

    S = pysmurf.SmurfControl(cfg_file=os.path.join(os.path.dirname(__file__), 
        '..', 'cfg_files' , cfg_filename), smurf_cmd_mode=True, setup=False, 
        offline=offline)

    if args.log is not None:
        S.log(args.log)

    ### Tuning related commands ###
    if args.last_tune:
        S.log('Loading in last tuning')
        S.tune(last_tune=True, make_plot=args.tune_make_plot)

    if args.use_tune is not None:
        S.log('Loading old tune from file: {}'.format(args.use_tune))
        S.tune(tune_file = args.use_tune, make_plot=args.tune_make_plot)

    if args.tune:
Exemple #10
0
import matplotlib

matplotlib.use('Agg')

import pysmurf
import numpy as np
import time
import sys

## instead of takedebugdata try relaunch PyRogue, then loopFilterOutputArray, which is
## the integral tracking term with lmsEnable[1..3]=0

S = pysmurf.SmurfControl(
    make_logfile=False,
    setup=False,
    epics_root='smurf_server_s5',
    cfg_file=
    '/home/cryo/docker/pysmurf/hb-devel-dspv2/pysmurf/cfg_files/experiment_fp29_smurfsrv03_noExtRef_hbOnlyBay0.cfg'
)

#######
hbInBay0 = False
bands = [2, 3]
Npts = 3
bias = None
#wait_time=.05
wait_time = 1.
#bias_low=-0.432
#bias_high=0.432
bias_low = -0.8
bias_high = 0.8
Exemple #11
0
import scipy.io as sio
import os
import sys
sys.path.append('../../../../')
import pysmurf
import numpy as np

S = pysmurf.SmurfControl(epics_root='mitch_epics')

test_filedir = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180819/'+ \
 '1534700282'

eta = np.ravel(
    sio.loadmat(os.path.join(test_filedir,
                             '1534700282mitch_epics_etaOut.mat'))['etaOut'])

# for i in np.arange(len(eta))
for i in np.arange(150, 155):
    resp = np.ravel(eta[i][3])
    freq = np.ravel(eta[i][4])

    if len(resp) > 0:
        I, Q, r, resid, eta_est = S.estimate_eta_parameter(freq, resp)
        print(I)
        print(Q)
        print(r)
        S.plot_eta_estimate(freq, resp, Ic=I, Qc=Q, r=r, eta=eta_est)
Exemple #12
0
import struct
import numpy as np
import sys
sys.path.append('../../../../')
import pysmurf

# dat_fullpath = '/data/cpu-b000-hp01/cryo_data/data2/20180912/1536771265/'+\
# 	'outputs/1536771308.dat'
# 	# 'outputs/1536771308.dat'

dat_fullpath = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180912/1536762729.dat'

# with open(dat_fullpath, mode='rb') as file: # b is important -> binary
#     fileContent = file.read()

# n = int(len(fileContent)/4)
# print(n)
# x = np.zeros(n, dtype=int)
# for i in np.arange(n):
# 	# print(fileContent[i*8:(i+1)*8])
# 	# print(int.from_bytes(fileContent[i*8:(i+1)*8], byteorder='little'))
# 	x[i] = int.from_bytes(fileContent[i*4:(i+1)*4], byteorder='little')

S = pysmurf.SmurfControl()
S.initialize(cfg_file='/home/cryo/pysmurf/cfg_files/experiment_fp28.cfg',
             make_logfile=False,
             output_dir_only=True)

I, Q = S.read_stream_data(dat_fullpath, 0)
Exemple #13
0
import pysmurf
import numpy as np
import time
import sys

## instead of takedebugdata try relaunch PyRogue, then loopFilterOutputArray, which is 
## the integral tracking term with lmsEnable[1..3]=0

S = pysmurf.SmurfControl(make_logfile=False,setup=False,epics_root='smurf_server',cfg_file='/data/pysmurf_cfg/experiment_pc002_smurfsrv08_noExtRef.cfg')

#######
bias=None
wait_time=.0
#bias_low=-0.432
#bias_high=0.432
bias_low=-0.45
bias_high=0.45
bias_step=.0015
quiet=True

if bias is None:
    bias = np.arange(bias_low, bias_high, bias_step)

S.log('Staring to flux ramp.', S.LOG_USER)

sys.stdout.write('\rSetting flux ramp bias low at {:4.3f} V\033[K'.format(bias_low))
S.set_fixed_flux_ramp_bias(bias_low,debug=True,do_config=True)

try:
    while True:
        for b in bias:
Exemple #14
0
import numpy as np
import pysmurf
import matplotlib.pyplot as plt


# datafile = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180921/1537561706/outputs/1537562122.dat'
# datafile = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180921/1537569911/outputs/1537569951.dat'
datafile = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180924/1537818448/outputs/1537818492.dat'
data_dir = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180924/1537818448/outputs/'
S = pysmurf.SmurfControl(make_logfile=False, output_dir_only=True, 
    data_dir=data_dir)

print('Loading data')
timestamp, I, Q = S.read_stream_data(datafile)

# ch = 0
# chs = np.array([0, 16, 32, 64, 139, 147, 179, 203, 245, 288, 395, 398, 415, 
#     427, 447, 459])
chs = np.array([16])
# chs = np.arange(16)

bias = np.arange(19.9, 0, -.1)

ivs = {}
ivs['bias'] = bias
for ch in chs:
    phase = S.iq_to_phase(I[ch], Q[ch]) * 1.443

    print('Running IV analysis')
    r, rn = S.analyze_slow_iv(bias, phase, make_plot=True, 
        show_plot=True, save_plot=True, band=3, channel=ch, 
Exemple #15
0
import sys
sys.path.append('/home/cryo/')
import pysmurf
import time

epics_root = 'dev_epics'
sd = epics_root + ':AMCc:FpgaTopLevel:AppTop:AppCore:StreamReg:StreamData[{}]'

S = pysmurf.SmurfControl(setup=False,
                         epics_root=epics_root,
                         make_logfile=False)

ch = 0
step_size = 2**6
a = -2**15

S._caput(sd.format(ch), 0, write_log=True)
while True:
    write_log = False
    if a % (step_size * 100) == 0:
        write_log = True
    S._caput(sd.format(ch), a, write_log=write_log)
    a += step_size
    time.sleep(.02)
    if a > 2**15:
        a = -2**15
import numpy as np
import pysmurf
import glob
import os

filedir = '/home/common/data/cpu-b000-hp01/cryo_data/data2/20180926/'+\
    '1538008791/outputs'
# filenames = ['1537924144.dat', '1537924208.dat']
bias = np.arange(6, 3 - .5, -.5)

filenames = np.sort(glob.glob(os.path.join(filedir, "*.dat")))
filenames = filenames[-len(bias):]

S = pysmurf.SmurfControl(setup=False, make_logfile=False)

# bias = np.array([8, 7.8])
datafile = np.array([os.path.join(filedir, x) for x in filenames])

print(bias)
print(datafile)

S.analyze_noise_vs_bias(
    bias,
    datafile,
    channel=np.array([0, 16, 32, 64, 139, 147, 179, 203, 395, 415, 427, 459]),
    band=3,
    fs=4.0E3)