def sweep_and_stream(df,
                     roach,
                     n_channels,
                     approximate_stream_length,
                     banks,
                     overwrite_last,
                     transient_wait=10):
    df.log_hw_state(roach)
    fine_sweep = sweeps.do_prepared_sweep(roach,
                                          nchan_per_step=n_channels,
                                          reads_per_step=2,
                                          banks=banks)
    df.add_sweep(fine_sweep)
    df.sync()
    fit_f0s = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep)])
    timestream_frequencies = roach.add_tone_freqs(
        fit_f0s, overwrite_last=overwrite_last)
    roach.select_fft_bins(np.arange(n_channels))
    roach.select_bank(roach.fft_bins.shape[0] - 1)
    roach._sync()
    time.sleep(
        transient_wait
    )  # The above commands create a transient that takes about 5 seconds to decay.
    df.log_hw_state(roach)
    start_time = time.time()
    stream, addresses = roach.get_data_seconds(approximate_stream_length,
                                               pow2=True)
    df.add_timestream_data(stream, roach, start_time)
    df.sync()
    return fit_f0s
def sweep_and_stream(df, roach, n_channels, approximate_stream_length, banks, overwrite_last, transient_wait=10):
    df.log_hw_state(roach)
    fine_sweep = sweeps.do_prepared_sweep(roach, nchan_per_step=n_channels, reads_per_step=2, banks=banks)
    df.add_sweep(fine_sweep)
    df.sync()
    fit_f0s = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep)])
    timestream_frequencies = roach.add_tone_freqs(fit_f0s, overwrite_last=overwrite_last)
    roach.select_fft_bins(np.arange(n_channels))
    roach.select_bank(roach.fft_bins.shape[0]-1)
    roach._sync()
    time.sleep(transient_wait)  # The above commands create a transient that takes about 5 seconds to decay.
    df.log_hw_state(roach)
    start_time = time.time()
    stream, addresses = roach.get_data_seconds(approximate_stream_length, pow2=True)
    df.add_timestream_data(stream, roach, start_time)
    df.sync()
    return fit_f0s
def sweep_and_stream(df,
                     roach,
                     lockin,
                     n_channels,
                     approximate_stream_length,
                     banks,
                     overwrite_last,
                     mmw_source_frequency,
                     mmw_source_modulation_freq,
                     transient_wait=10):
    df.log_hw_state(roach)
    fine_sweep = sweeps.do_prepared_sweep(roach,
                                          nchan_per_step=n_channels,
                                          reads_per_step=2,
                                          banks=banks)
    df.add_sweep(fine_sweep)
    df.sync()
    fit_f0s = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep)])

    timestream_frequencies = roach.add_tone_freqs(
        fit_f0s, overwrite_last=overwrite_last)
    roach.select_fft_bins(np.arange(n_channels))
    roach.select_bank(roach.fft_bins.shape[0] - 1)
    roach._sync()
    time.sleep(
        transient_wait
    )  # The above commands create a transient that takes about 5 seconds to decay.
    df.log_hw_state(roach)
    start_time = time.time()
    stream, addresses = roach.get_data_seconds(approximate_stream_length,
                                               pow2=True)
    x, y, r, theta = lockin.get_data(
    )  # I don't think this will actually work, but maybe it doesn't matter.
    df.add_timestream_data(
        stream,
        roach,
        start_time,
        mmw_source_freq=mmw_source_frequency,
        mmw_source_modulation_freq=mmw_source_modulation_freq,
        zbd_voltage=x)
    df.sync()
    return fit_f0s
def sweep_and_stream(df, roach, lockin, n_channels, approximate_stream_length, banks, overwrite_last,
                     mmw_source_frequency, mmw_source_modulation_freq, transient_wait=10):
    df.log_hw_state(roach)
    fine_sweep = sweeps.do_prepared_sweep(roach, nchan_per_step=n_channels, reads_per_step=2, banks=banks)
    df.add_sweep(fine_sweep)
    df.sync()
    fit_f0s = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep)])

    timestream_frequencies = roach.add_tone_freqs(fit_f0s, overwrite_last=overwrite_last)
    roach.select_fft_bins(np.arange(n_channels))
    roach.select_bank(roach.fft_bins.shape[0]-1)
    roach._sync()
    time.sleep(transient_wait)  # The above commands create a transient that takes about 5 seconds to decay.
    df.log_hw_state(roach)
    start_time = time.time()
    stream, addresses = roach.get_data_seconds(approximate_stream_length, pow2=True)
    x, y, r, theta = lockin.get_data()  # I don't think this will actually work, but maybe it doesn't matter.
    df.add_timestream_data(stream, roach, start_time, mmw_source_freq=mmw_source_frequency,
                           mmw_source_modulation_freq=mmw_source_modulation_freq, zbd_voltage=x)
    df.sync()
    return fit_f0s
            break

    start_time = time.time()
    df = data_file.DataFile(suffix=suffix)
    df.nc.mmw_atten_turns = mmw_atten_turns

    # Take a coarse sweep with the source off at the lowest attenuation to get the approximate resonance frequencies.
    source_off()
    maximum_attenuation = max(attenuations)
    print("Setting DAC attenuator to {:.1f} dB for coarse sweep.".format(maximum_attenuation))
    roach.set_dac_attenuator(maximum_attenuation)
    coarse_measured_frequencies = sweeps.prepare_sweep(roach, f0s, coarse_offset_frequencies, coarse_n_samples)
    df.log_hw_state(roach)
    coarse_sweep = sweeps.do_prepared_sweep(roach, nchan_per_step=f0s.size, reads_per_step=2)
    df.add_sweep(coarse_sweep)
    coarse_resonators = acquire.fit_sweep_data(coarse_sweep)
    coarse_fit_f0s = np.array([r.f_0 for r in coarse_resonators])
    print("coarse - initial [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff) for diff in coarse_fit_f0s - f0s]))

    # Record one stream at the lowest attenuation.
    mmw_source_modulation_freq = source_modulate()
    print("Set source modulation frequency to {:.1f} Hz.".format(mmw_source_modulation_freq))
    modulated_measured_frequencies = roach.set_tone_freqs(coarse_fit_f0s, nsamp=fine_n_samples)
    roach.select_fft_bins(np.arange(f0s.size))
    roach._sync()
    time.sleep(1)
    df.log_hw_state(roach)
    modulated_start_time = time.time()
    modulated_stream, addresses = roach.get_data_seconds(4)
    x, y, r, theta = lockin.get_data()
    df.add_timestream_data(modulated_stream, roach, modulated_start_time, mmw_source_freq=mmw_source_frequency,
    df.nc.mmw_atten_turns = mmw_atten_turns

    # Take a coarse sweep with the source off at the lowest attenuation to get the approximate resonance frequencies.
    source_off()
    maximum_attenuation = max(attenuations)
    print("Setting DAC attenuator to {:.1f} dB for coarse sweep.".format(
        maximum_attenuation))
    roach.set_dac_attenuator(maximum_attenuation)
    coarse_measured_frequencies = sweeps.prepare_sweep(
        roach, f0s, coarse_offset_frequencies, coarse_n_samples)
    df.log_hw_state(roach)
    coarse_sweep = sweeps.do_prepared_sweep(roach,
                                            nchan_per_step=f0s.size,
                                            reads_per_step=2)
    df.add_sweep(coarse_sweep)
    coarse_resonators = acquire.fit_sweep_data(coarse_sweep)
    coarse_fit_f0s = np.array([r.f_0 for r in coarse_resonators])
    print(
        "coarse - initial [Hz]: " + ', '.join(
            ['{:.0f}'.format(1e6 * diff) for diff in coarse_fit_f0s - f0s]))

    # Record one stream at the lowest attenuation.
    mmw_source_modulation_freq = source_modulate()
    print("Set source modulation frequency to {:.1f} Hz.".format(
        mmw_source_modulation_freq))
    modulated_measured_frequencies = roach.set_tone_freqs(coarse_fit_f0s,
                                                          nsamp=fine_n_samples)
    roach.select_fft_bins(np.arange(f0s.size))
    roach._sync()
    time.sleep(1)
    df.log_hw_state(roach)
def main(f_initial, attenuation, stream_time=30, suffix='compressor_noise', coarse_exponent=19, fine_exponent=21,
         modulation_state='high', modulation_rate=7, transient_wait=10, f_mmw_source=0,
         mmw_atten_turns=(np.nan, np.nan),num_streams=1):
    roach = baseband.RoachBaseband()
    roach.set_modulation_output(modulation_state)
    roach.set_dac_attenuator(attenuation)
    df = data_file.DataFile(suffix=suffix)
    df.log_hw_state(roach)

    def prompt():
        raw_input("Turn off the compressor and hit Enter to begin.")

    if modulation_state == 'low':
        lockin = lockin_controller.lockinController()
        df.nc.mmw_atten_turns = mmw_atten_turns

    # Compressor on
    coarse_sweep_on = acquire.sweep(roach, f_initial, coarse_exponent, transient_wait=transient_wait)
    f_coarse_on = np.array([r.f_0 for r in acquire.fit_sweep_data(coarse_sweep_on)])
    print("Compressor on: coarse - initial [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * delta_f)
                                                              for delta_f in f_coarse_on - f_initial]))
    df.log_hw_state(roach)
    fine_sweep_on = acquire.sweep(roach, f_coarse_on, fine_exponent, transient_wait=transient_wait)
    f_fine_on = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep_on)])
    print("Compressor on: fine - coarse [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * delta_f)
                                                              for delta_f in f_fine_on - f_coarse_on]))
    df.add_sweep(fine_sweep_on)
    df.log_hw_state(roach)
    on_start_time = time.time()
    stream_on, address = acquire.timestream(roach, f_fine_on, stream_time, transient_wait=transient_wait)
    if modulation_state == 'low':
        roach.set_modulation_output(modulation_rate)
        time.sleep(5)
        x, y, r, theta = lockin.get_data()
        roach.set_modulation_output('low')
    else:
        x=0
    df.add_timestream_data(stream_on, roach, on_start_time, mmw_source_freq=f_mmw_source, zbd_voltage=x)

    # Compressor off
    print("Preparing fine sweep with compressor off.")
    df.log_hw_state(roach)
    fine_sweep_off = acquire.sweep(roach, f_coarse_on, fine_exponent, transient_wait=transient_wait, run=prompt)
    print("Done with fine sweep. Turn on the compressor.")
    f_fine_off = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep_off)])
    print("off - on [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * delta_f)
                                                              for delta_f in f_fine_off - f_fine_on]))
    df.add_sweep(fine_sweep_off)
    df.log_hw_state(roach)
    off_start_time = time.time()
    stream_off, address = acquire.timestream(roach, f_fine_on, stream_time, transient_wait=transient_wait, run=prompt)
    print("Done with stream. Turn on the compressor.")
    if modulation_state == 'low':
        roach.set_modulation_output(modulation_rate)
        time.sleep(5)
        x, y, r, theta = lockin.get_data()
        roach.set_modulation_output('high')
    else:
        x = np.nan
    df.add_timestream_data(stream_off, roach, off_start_time, mmw_source_freq=f_mmw_source, zbd_voltage=x)

    df.sync()
    df.close()
    print("Wrote {}".format(df.filename))
    if True:
        print "doing coarse sweep"

        coarse_sweep = r2sweeps.do_sweep(
            ri,
            center_freqs=f0binned,
            offsets=offsets,
            nsamp=nsamp,
            nchan_per_step=atonce,
            reads_per_step=2,
        )
        orig_sweep_data = coarse_sweep

        coarse_res = acquire.fit_sweep_data(
            coarse_sweep,
            model=delayed_generic_s21,
            guess=delayed_generic_guess,
            delay_estimate=ri.hardware_delay_estimate)

        coarse_f0 = np.array([res.f_0 for res in coarse_res])

    else:
        coarse_f0 = f0s
    print coarse_f0

    nsamp = 2**21
    step = 1

    offset_bins = np.array([-8, -4, -2, -1, 0, 1, 2, 4])
    offset_bins = np.concatenate(([-40, -20], offset_bins, [20, 40]))
    offsets = offset_bins * 512.0 / nsamp
Beispiel #9
0
def main(f_initial,
         attenuation,
         stream_time=30,
         suffix='compressor_noise',
         coarse_exponent=19,
         fine_exponent=21,
         modulation_state='high',
         modulation_rate=7,
         transient_wait=10,
         f_mmw_source=0,
         mmw_atten_turns=(np.nan, np.nan),
         num_streams=1):
    roach = baseband.RoachBaseband()
    roach.set_modulation_output(modulation_state)
    roach.set_dac_attenuator(attenuation)
    df = data_file.DataFile(suffix=suffix)
    df.log_hw_state(roach)

    def prompt():
        raw_input("Turn off the compressor and hit Enter to begin.")

    if modulation_state == 'low':
        lockin = lockin_controller.lockinController()
        df.nc.mmw_atten_turns = mmw_atten_turns

    # Compressor on
    coarse_sweep_on = acquire.sweep(roach,
                                    f_initial,
                                    coarse_exponent,
                                    transient_wait=transient_wait)
    f_coarse_on = np.array(
        [r.f_0 for r in acquire.fit_sweep_data(coarse_sweep_on)])
    print("Compressor on: coarse - initial [Hz]: " + ', '.join([
        '{:.0f}'.format(1e6 * delta_f) for delta_f in f_coarse_on - f_initial
    ]))
    df.log_hw_state(roach)
    fine_sweep_on = acquire.sweep(roach,
                                  f_coarse_on,
                                  fine_exponent,
                                  transient_wait=transient_wait)
    f_fine_on = np.array(
        [r.f_0 for r in acquire.fit_sweep_data(fine_sweep_on)])
    print("Compressor on: fine - coarse [Hz]: " + ', '.join([
        '{:.0f}'.format(1e6 * delta_f) for delta_f in f_fine_on - f_coarse_on
    ]))
    df.add_sweep(fine_sweep_on)
    df.log_hw_state(roach)
    on_start_time = time.time()
    stream_on, address = acquire.timestream(roach,
                                            f_fine_on,
                                            stream_time,
                                            transient_wait=transient_wait)
    if modulation_state == 'low':
        roach.set_modulation_output(modulation_rate)
        time.sleep(5)
        x, y, r, theta = lockin.get_data()
        roach.set_modulation_output('low')
    else:
        x = 0
    df.add_timestream_data(stream_on,
                           roach,
                           on_start_time,
                           mmw_source_freq=f_mmw_source,
                           zbd_voltage=x)

    # Compressor off
    print("Preparing fine sweep with compressor off.")
    df.log_hw_state(roach)
    fine_sweep_off = acquire.sweep(roach,
                                   f_coarse_on,
                                   fine_exponent,
                                   transient_wait=transient_wait,
                                   run=prompt)
    print("Done with fine sweep. Turn on the compressor.")
    f_fine_off = np.array(
        [r.f_0 for r in acquire.fit_sweep_data(fine_sweep_off)])
    print("off - on [Hz]: " + ', '.join(
        ['{:.0f}'.format(1e6 * delta_f)
         for delta_f in f_fine_off - f_fine_on]))
    df.add_sweep(fine_sweep_off)
    df.log_hw_state(roach)
    off_start_time = time.time()
    stream_off, address = acquire.timestream(roach,
                                             f_fine_on,
                                             stream_time,
                                             transient_wait=transient_wait,
                                             run=prompt)
    print("Done with stream. Turn on the compressor.")
    if modulation_state == 'low':
        roach.set_modulation_output(modulation_rate)
        time.sleep(5)
        x, y, r, theta = lockin.get_data()
        roach.set_modulation_output('high')
    else:
        x = np.nan
    df.add_timestream_data(stream_off,
                           roach,
                           off_start_time,
                           mmw_source_freq=f_mmw_source,
                           zbd_voltage=x)

    df.sync()
    df.close()
    print("Wrote {}".format(df.filename))

f_initial = np.load('/data/readout/resonances/0813f12_130mK_fits.npy')

stream_time=1800
num_streams=2
suffix='long_timestreams_80mK'
coarse_exponent=19
fine_exponent=21

roach = baseband.RoachBaseband()
roach.set_modulation_output('high')
roach.set_dac_attenuator(38)

coarse_sweep_on = acquire.sweep(roach, f_initial, coarse_exponent)
f_fine_on = np.array([r.f_0 for r in acquire.fit_sweep_data(coarse_sweep_on)])


for loop_index,atten in enumerate([40,38,36,34,32]):

    roach.set_dac_attenuator(atten)

    df = data_file.DataFile(suffix=suffix)
    df.log_hw_state(roach)

    if True:#loop_index == 0 :
        fine_sweep_on = acquire.sweep(roach, f_fine_on, fine_exponent, transient_wait=0)
    else:
        fine_sweep_on = sweeps.do_prepared_sweep(roach,nchan_per_step=len(f_initial))
    f_fine_on = np.array([r.f_0 for r in acquire.fit_sweep_data(fine_sweep_on)])
    print("Compressor on: fine - coarse [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * delta_f)
    suffix = "mmw_frequency_sweep_hittite_level_%.3f_dBm" % hittite_power_level

    hittite.set_freq(12.0)
    hittite.on()
    ri.set_modulation_output('high')
    print "setting attenuator to", atten
    ri.set_dac_attenuator(atten)
    orig_sweep_data=None
    if True:
        print "doing coarse sweep"

        coarse_sweep = r2sweeps.do_sweep(ri, center_freqs=f0binned, offsets=offsets,nsamp=nsamp,
                                       nchan_per_step=atonce, reads_per_step=2,)
        orig_sweep_data = coarse_sweep

        coarse_res = acquire.fit_sweep_data(coarse_sweep,model=delayed_generic_s21,guess=delayed_generic_guess,
                                            delay_estimate=ri.hardware_delay_estimate)

        coarse_f0 = np.array([res.f_0 for res in coarse_res])

    else:
        coarse_f0 = f0s
    print coarse_f0

    nsamp = 2 ** 21
    step = 1

    offset_bins = np.array([-8, -4, -2, -1, 0, 1, 2, 4])
    offset_bins = np.concatenate(([-40, -20], offset_bins, [20, 40]))
    offsets = offset_bins * 512.0 / nsamp

    meas_cfs = coarse_f0
from kid_readout.equipment import lockin_controller

f_initial = np.load('/data/readout/resonances/0813f12_130mK_fits.npy')

stream_time = 1800
num_streams = 2
suffix = 'long_timestreams_80mK'
coarse_exponent = 19
fine_exponent = 21

roach = baseband.RoachBaseband()
roach.set_modulation_output('high')
roach.set_dac_attenuator(38)

coarse_sweep_on = acquire.sweep(roach, f_initial, coarse_exponent)
f_fine_on = np.array([r.f_0 for r in acquire.fit_sweep_data(coarse_sweep_on)])

for loop_index, atten in enumerate([40, 38, 36, 34, 32]):

    roach.set_dac_attenuator(atten)

    df = data_file.DataFile(suffix=suffix)
    df.log_hw_state(roach)

    if True:  #loop_index == 0 :
        fine_sweep_on = acquire.sweep(roach,
                                      f_fine_on,
                                      fine_exponent,
                                      transient_wait=0)
    else:
        fine_sweep_on = sweeps.do_prepared_sweep(roach,