예제 #1
0
def record_sweep(roach, center_frequencies, offset_frequencies, attenuation, n_samples, suffix, interactive=False):
    n_channels = center_frequencies.size
    df = data_file.DataFile(suffix=suffix)
    print("Writing data to " + df.filename)
    print("Setting DAC attenuator to {:.1f} dB".format(attenuation))
    roach.set_dac_attenuator(attenuation)
    print("Sweep memory usage is {:.1f} MB of {:.1f} MB capacity.".format(
        memory_usage_bytes(offset_frequencies.shape[0], n_samples) / 2 ** 20, EFFECTIVE_DRAM_CAPACITY / 2 ** 20))

    measured_frequencies = sweeps.prepare_sweep(roach, center_frequencies, offset_frequencies, n_samples)
    roach._sync()
    time.sleep(0.2)
    df.log_hw_state(roach)
    if interactive:
        raw_input("Hit enter to begin recording frequency sweep.")
    else:
        print("Recording frequency sweep.")
    sweep_start_time = time.time()
    sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=n_channels, reads_per_step=8)
    print("Elapsed time {:.0f} seconds. Writing to disk.".format(time.time() - sweep_start_time))
    df.add_sweep(sweep_data)
    df.sync()
    resonators = fit_sweep_data(sweep_data)
    fit_f0s = np.array([r.f_0 for r in resonators])
    print("Initial frequencies in MHz are " + ', '.join(['{:.3f}'.format(f0) for f0 in center_frequencies]))
    print("initial - fit [Hz]: " +
          ', '.join(['{:.0f}'.format(1e6 * delta_f) for delta_f in center_frequencies - fit_f0s]))
    df.nc.close()
    return df.filename, resonators
예제 #2
0
def record_sweeps_on_off(roach, nominal_frequencies, attenuation, n_samples, suffix):
    df = data_file.DataFile(suffix=suffix)
    roach.set_dac_attenuator(attenuation)
    measured_frequencies = roach.set_tone_frequencies(nominal_frequencies, nsamp=n_samples)
    df.log_hw_state(roach)
    raw_input("Hit enter to begin sweep with compressor on.")
    start1 = time.time()
    sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=nominal_frequencies.size, reads_per_step=8)
    print("Sweep completed in {:.0f} seconds.".format(time.time() - start1))
    df.add_sweep(sweep_data)
    df.sync()
    raw_input("Hit enter to begin sweep with compressor off.")
    start2 = time.time()
    sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=nominal_frequencies.size, reads_per_step=8)
    print("Sweep completed in {:.0f} seconds.".format(time.time() - start2))
    df.add_sweep(sweep_data)
    df.sync()
    df.nc.close()
예제 #3
0
def sweep(roach, center_frequencies, sample_exponent, offset_frequencies=None, reads_per_step=2, transient_wait=0,
          run=lambda: None):
    n_samples = 2 ** sample_exponent
    if offset_frequencies is None:
        frequency_resolution = roach.fs / n_samples
        offset_frequencies = frequency_resolution * offset_integers[sample_exponent]
    sweeps.prepare_sweep(roach, center_frequencies, offset_frequencies, n_samples)
    roach._sync()
    time.sleep(transient_wait)
    run()
    sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=len(center_frequencies), reads_per_step=reads_per_step)
    return sweep_data
예제 #4
0
def record_sweeps_on_off(roach, nominal_frequencies, attenuation, n_samples,
                         suffix):
    df = data_file.DataFile(suffix=suffix)
    roach.set_dac_attenuator(attenuation)
    measured_frequencies = roach.set_tone_frequencies(nominal_frequencies,
                                                      nsamp=n_samples)
    df.log_hw_state(roach)
    raw_input("Hit enter to begin sweep with compressor on.")
    start1 = time.time()
    sweep_data = sweeps.do_prepared_sweep(
        roach, nchan_per_step=nominal_frequencies.size, reads_per_step=8)
    print("Sweep completed in {:.0f} seconds.".format(time.time() - start1))
    df.add_sweep(sweep_data)
    df.sync()
    raw_input("Hit enter to begin sweep with compressor off.")
    start2 = time.time()
    sweep_data = sweeps.do_prepared_sweep(
        roach, nchan_per_step=nominal_frequencies.size, reads_per_step=8)
    print("Sweep completed in {:.0f} seconds.".format(time.time() - start2))
    df.add_sweep(sweep_data)
    df.sync()
    df.nc.close()
예제 #5
0
def record_sweep(roach,
                 center_frequencies,
                 offset_frequencies,
                 attenuation,
                 n_samples,
                 suffix,
                 interactive=False):
    n_channels = center_frequencies.size
    df = data_file.DataFile(suffix=suffix)
    print("Writing data to " + df.filename)
    print("Setting DAC attenuator to {:.1f} dB".format(attenuation))
    roach.set_dac_attenuator(attenuation)
    print("Sweep memory usage is {:.1f} MB of {:.1f} MB capacity.".format(
        memory_usage_bytes(offset_frequencies.shape[0], n_samples) / 2**20,
        EFFECTIVE_DRAM_CAPACITY / 2**20))

    measured_frequencies = sweeps.prepare_sweep(roach, center_frequencies,
                                                offset_frequencies, n_samples)
    roach._sync()
    time.sleep(0.2)
    df.log_hw_state(roach)
    if interactive:
        raw_input("Hit enter to begin recording frequency sweep.")
    else:
        print("Recording frequency sweep.")
    sweep_start_time = time.time()
    sweep_data = sweeps.do_prepared_sweep(roach,
                                          nchan_per_step=n_channels,
                                          reads_per_step=8)
    print("Elapsed time {:.0f} seconds. Writing to disk.".format(
        time.time() - sweep_start_time))
    df.add_sweep(sweep_data)
    df.sync()
    resonators = fit_sweep_data(sweep_data)
    fit_f0s = np.array([r.f_0 for r in resonators])
    print("Initial frequencies in MHz are " +
          ', '.join(['{:.3f}'.format(f0) for f0 in center_frequencies]))
    print("initial - fit [Hz]: " + ', '.join([
        '{:.0f}'.format(1e6 * delta_f)
        for delta_f in center_frequencies - fit_f0s
    ]))
    df.nc.close()
    return df.filename, resonators
예제 #6
0
def sweep(roach,
          center_frequencies,
          sample_exponent,
          offset_frequencies=None,
          reads_per_step=2,
          transient_wait=0,
          run=lambda: None):
    n_samples = 2**sample_exponent
    if offset_frequencies is None:
        frequency_resolution = roach.fs / n_samples
        offset_frequencies = frequency_resolution * offset_integers[
            sample_exponent]
    sweeps.prepare_sweep(roach, center_frequencies, offset_frequencies,
                         n_samples)
    roach._sync()
    time.sleep(transient_wait)
    run()
    sweep_data = sweeps.do_prepared_sweep(
        roach,
        nchan_per_step=len(center_frequencies),
        reads_per_step=reads_per_step)
    return sweep_data
예제 #7
0
def mmw_source_sweep_and_stream(df, roach, lockin, approximate_stream_time, overwrite_last, f_mmw_source,
                                sweep_modulation_rate, stream_modulation_rate, measurement_modulation_rate,
                                roach_wait=10, lockin_wait=5, verbose=True):
    f_sweep_modulation = roach.set_modulation_output(sweep_modulation_rate)
    if verbose:
        print("Sweep modulation state {}: frequency {:.2f} Hz.".format(sweep_modulation_rate, f_sweep_modulation))
    df.log_hw_state(roach)
    sweep = sweeps.do_prepared_sweep(roach, nchan_per_step=roach.tone_bins.shape[0], reads_per_step=2)
    df.add_sweep(sweep)
    df.sync()
    f_fit = np.array([r.f_0 for r in fit_sweep_data(sweep)])

    f_measurement_modulation = roach.set_modulation_output(measurement_modulation_rate)
    f_stream_measured = roach.add_tone_freqs(f_fit, overwrite_last=overwrite_last)  # Use this delay for settling
    if verbose:
        print("Stream tone separations [MHz]: {}".format(np.diff(sorted(f_stream_measured))))
    time.sleep(lockin_wait)
    x, y, r, theta = lockin.get_data()
    if verbose:
        print("Lock-in measured {:.4g} V at frequency {:.2f} Hz.".format(x, f_measurement_modulation))

    f_stream_modulation = roach.set_modulation_output(stream_modulation_rate)
    if verbose:
        print("Modulation state {} for {:.0f} second stream: frequency {:.2f} Hz.".format(stream_modulation_rate,
                                                                                          approximate_stream_time,
                                                                                          f_stream_modulation))
    # After 2015-05-05, select_fft_bins is no longer necessary since select_bank now selects FFT bins too.
    roach.select_bank(roach.fft_bins.shape[0] - 1)
    roach._sync()
    time.sleep(roach_wait)  # The above commands somehow 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_time, pow2=True)
    df.add_timestream_data(stream, roach, start_time, mmw_source_freq=f_mmw_source,
                           mmw_source_modulation_freq=f_stream_modulation, zbd_voltage=x)
    df.sync()
    return sweep, stream
        offsets = offset_bins * 512.0 / nsamp

        measured_freqs = sweeps.prepare_sweep(ri,
                                              f0binned,
                                              offsets,
                                              nsamp=nsamp)
        print "loaded waveforms in", (time.time() - start), "seconds"

        delay = -31.3
        print "median delay is ", delay

        df = data_file.DataFile(suffix=suffix)
        df.nc.mmw_atten_turns = mmw_atten_turns
        df.log_hw_state(ri)
        sweep_data = sweeps.do_prepared_sweep(ri,
                                              nchan_per_step=atonce,
                                              reads_per_step=2)
        df.add_sweep(sweep_data)
        meas_cfs = []
        idxs = []
        for m in range(len(f0s)):
            fr, s21, errors = sweep_data.select_by_freq(f0s[m])
            thiscf = f0s[m]
            s21 = s21 * np.exp(2j * np.pi * delay * fr)
            res = fit_best_resonator(
                fr, s21, errors=errors)  #Resonator(fr,s21,errors=errors)
            fmin = fr[np.abs(s21).argmin()]
            print "s21 fmin", fmin, "original guess", thiscf, "this fit", res.f_0
            if use_fmin:
                meas_cfs.append(fmin)
            else:
예제 #9
0
def sweep_fit_timestream(roach,
                         center_frequencies,
                         offset_frequencies,
                         sweep_n_samples,
                         timestream_n_samples,
                         attenuation,
                         suffix,
                         time_in_seconds,
                         interactive=False,
                         coarse_multiplier=3):
    df = data_file.DataFile(suffix=suffix)
    print("Writing data to " + df.filename)
    print("Setting DAC attenuator to {:.1f} dB".format(attenuation))
    roach.set_dac_attenuator(attenuation)
    print("Sweep memory usage is {:.1f} MB of {:.1f} MB capacity.".format(
        memory_usage_bytes(offset_frequencies.shape[0], sweep_n_samples) /
        2**20, EFFECTIVE_DRAM_CAPACITY / 2**20))

    # Do a preliminary sweep to make sure the main sweeps are centered properly.
    sweeps.prepare_sweep(roach, center_frequencies,
                         coarse_multiplier * offset_frequencies,
                         sweep_n_samples)
    roach._sync()
    time.sleep(0.2)
    if interactive:
        raw_input("Hit enter to record preliminary frequency sweep.")
    else:
        print("Recording preliminary frequency sweep.")
    coarse_sweep_data = sweeps.do_prepared_sweep(
        roach, nchan_per_step=center_frequencies.size, reads_per_step=8)
    coarse_resonators = fit_sweep_data(coarse_sweep_data)
    coarse_f0s = np.array([r.f_0 for r in coarse_resonators])
    fine_center_frequencies = round_frequencies(coarse_f0s, roach.fs,
                                                sweep_n_samples)

    # Now do the actual sweep and save it.
    sweeps.prepare_sweep(roach, fine_center_frequencies, offset_frequencies,
                         sweep_n_samples)
    roach._sync()
    time.sleep(0.2)
    df.log_hw_state(roach)
    if interactive:
        raw_input("Hit enter to begin recording frequency sweep.")
    else:
        print("Recording frequency sweep.")
    sweep_start_time = time.time()
    sweep_data = sweeps.do_prepared_sweep(
        roach, nchan_per_step=center_frequencies.size, reads_per_step=8)
    print("Elapsed time {:.0f} seconds. Writing to disk.".format(
        time.time() - sweep_start_time))
    df.add_sweep(sweep_data)
    df.sync()
    resonators = fit_sweep_data(sweep_data)
    fine_f0s = np.array([r.f_0 for r in resonators])
    print("Initial frequencies in MHz are " +
          ', '.join(['{:.3f}'.format(f0) for f0 in center_frequencies]))
    print("initial - fit [Hz]: " + ', '.join([
        '{:.0f}'.format(1e6 * delta_f)
        for delta_f in center_frequencies - fine_f0s
    ]))

    timestream_measured_frequencies = roach.set_tone_frequencies(
        fine_f0s, nsamp=timestream_n_samples)
    roach.select_fft_bins(np.arange(roach.tone_bins.shape[1]))
    roach._sync()
    time.sleep(0.2)
    df.log_hw_state(roach)
    print("measured - fit [Hz]: " + ', '.join([
        '{:.0f}'.format(1e6 * delta_f)
        for delta_f in timestream_measured_frequencies - fine_f0s
    ]))
    # This delay was added because the above lines cause some kind of transient signal that takes about three seconds
    # to decay. This was showing up at the beginning of the timestreams with interactive=False.
    minimum_wait = 5
    wait_start_time = time.time()
    if interactive:
        raw_input(
            "Hit enter to begin recording {:.0f} second timestream.".format(
                time_in_seconds))
    else:
        print("Recording {:.0f} second timestream.".format(time_in_seconds))
    while time.time() - wait_start_time < minimum_wait:
        time.sleep(0.1)
    timestream_start_time = time.time()
    data, address = roach.get_data_seconds(time_in_seconds,
                                           demod=True,
                                           pow2=True)
    print("Elapsed time {:.0f} seconds. Writing to disk.".format(
        time.time() - timestream_start_time))
    df.add_timestream_data(data, roach, timestream_start_time)
    df.sync()
    df.nc.close()
    return df.filename
예제 #10
0
def mmw_source_sweep_and_stream(df,
                                roach,
                                lockin,
                                approximate_stream_time,
                                overwrite_last,
                                f_mmw_source,
                                sweep_modulation_rate,
                                stream_modulation_rate,
                                measurement_modulation_rate,
                                roach_wait=10,
                                lockin_wait=5,
                                verbose=True):
    f_sweep_modulation = roach.set_modulation_output(sweep_modulation_rate)
    if verbose:
        print("Sweep modulation state {}: frequency {:.2f} Hz.".format(
            sweep_modulation_rate, f_sweep_modulation))
    df.log_hw_state(roach)
    sweep = sweeps.do_prepared_sweep(roach,
                                     nchan_per_step=roach.tone_bins.shape[0],
                                     reads_per_step=2)
    df.add_sweep(sweep)
    df.sync()
    f_fit = np.array([r.f_0 for r in fit_sweep_data(sweep)])

    f_measurement_modulation = roach.set_modulation_output(
        measurement_modulation_rate)
    f_stream_measured = roach.add_tone_freqs(
        f_fit, overwrite_last=overwrite_last)  # Use this delay for settling
    if verbose:
        print("Stream tone separations [MHz]: {}".format(
            np.diff(sorted(f_stream_measured))))
    time.sleep(lockin_wait)
    x, y, r, theta = lockin.get_data()
    if verbose:
        print("Lock-in measured {:.4g} V at frequency {:.2f} Hz.".format(
            x, f_measurement_modulation))

    f_stream_modulation = roach.set_modulation_output(stream_modulation_rate)
    if verbose:
        print(
            "Modulation state {} for {:.0f} second stream: frequency {:.2f} Hz."
            .format(stream_modulation_rate, approximate_stream_time,
                    f_stream_modulation))
    # After 2015-05-05, select_fft_bins is no longer necessary since select_bank now selects FFT bins too.
    roach.select_bank(roach.fft_bins.shape[0] - 1)
    roach._sync()
    time.sleep(
        roach_wait
    )  # The above commands somehow 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_time,
                                               pow2=True)
    df.add_timestream_data(stream,
                           roach,
                           start_time,
                           mmw_source_freq=f_mmw_source,
                           mmw_source_modulation_freq=f_stream_modulation,
                           zbd_voltage=x)
    df.sync()
    return sweep, stream
예제 #11
0
def sweeps_and_streams(f_initial,
                       attenuations,
                       suffix='',
                       coarse_exponent=19,
                       fine_exponent=21,
                       long_stream_time=30,
                       short_stream_time=4,
                       roach_wait=10):
    roach = baseband.RoachBaseband()
    f_modulation = roach.set_modulation_output('high')

    n_coarse_samples = 2**coarse_exponent
    n_fine_samples = 2**fine_exponent
    coarse_frequency_resolution = roach.fs / n_coarse_samples
    fine_frequency_resolution = roach.fs / n_fine_samples
    coarse_offset_integers = offset_integers[coarse_exponent]
    fine_offset_integers = offset_integers[fine_exponent]
    f_coarse_offset = coarse_frequency_resolution * coarse_offset_integers
    f_fine_offset = fine_frequency_resolution * fine_offset_integers

    start_time = time.time()
    df = data_file.DataFile(suffix=suffix)
    maximum_attenuation = max(attenuations)
    print(
        "Setting DAC attenuator to maximum requested attenuation of {:.1f} dB."
        .format(maximum_attenuation))
    roach.set_dac_attenuator(maximum_attenuation)

    # At the lowest readout power, record a coarse sweep and a short stream
    sweeps.prepare_sweep(roach, f_initial, f_coarse_offset, n_coarse_samples)
    df.log_hw_state(roach)
    coarse_sweep_data = sweeps.do_prepared_sweep(
        roach, nchan_per_step=roach.tone_bins.shape[0], reads_per_step=2)
    df.add_sweep(coarse_sweep_data)
    df.sync()
    coarse_f_fit = np.array([r.f_0 for r in fit_sweep_data(coarse_sweep_data)])
    print("coarse - initial [Hz]: " + ', '.join(
        ['{:.0f}'.format(1e6 * diff) for diff in coarse_f_fit - f_initial]))
    roach.add_tone_freqs(coarse_f_fit, overwrite_last=True)
    roach.select_bank(roach.fft_bins.shape[0] - 1)
    roach._sync()
    time.sleep(
        roach_wait
    )  # The above commands somehow create a transient that takes about 5 seconds to decay.
    df.log_hw_state(roach)
    stream_start_time = time.time()
    stream, addresses = roach.get_data_seconds(short_stream_time, pow2=True)
    df.add_timestream_data(stream,
                           roach,
                           stream_start_time,
                           mmw_source_modulation_freq=f_modulation)
    df.sync()

    # Use these frequencies for all subsequent sweeps, and add an additional waveform for each stream.
    print("\nSetting fine sweep frequencies.")
    sweeps.prepare_sweep(roach, coarse_f_fit, f_fine_offset, n_fine_samples)

    for k, attenuation in enumerate(attenuations):
        print("\nMeasurement {} of {}: DAC attenuator at {:.1f} dB.".format(
            k + 1, len(attenuations), attenuation))
        roach.set_dac_attenuator(attenuation)
        fine_sweep_data = sweeps.do_prepared_sweep(
            roach, nchan_per_step=roach.tone_bins.shape[0], reads_per_step=2)
        df.add_sweep(fine_sweep_data)
        df.sync()
        fine_f_fit = np.array([r.f_0 for r in fit_sweep_data(fine_sweep_data)])
        print("fine - coarse [Hz]: " + ', '.join([
            '{:.0f}'.format(1e6 * diff) for diff in fine_f_fit - coarse_f_fit
        ]))
        f_stream = roach.add_tone_freqs(
            coarse_f_fit, overwrite_last=k > 0)  # Overwrite after the first
        print("stream detuning [ppm]: " + ', '.join(
            ['{:.0f}'.format(1e6 * x) for x in (f_stream / fine_f_fit - 1)]))
        roach.select_bank(roach.fft_bins.shape[0] - 1)
        roach._sync()
        time.sleep(
            roach_wait
        )  # The above commands somehow create a transient that takes about 5 seconds to decay.
        df.log_hw_state(roach)
        stream_start_time = time.time()
        stream, addresses = roach.get_data_seconds(long_stream_time, pow2=True)
        df.add_timestream_data(stream,
                               roach,
                               stream_start_time,
                               mmw_source_modulation_freq=f_modulation)
        df.sync()

    df.close()
    print("Completed in {:.0f} minutes: {}".format(
        (time.time() - start_time) / 60, df.filename))
        if temp > 0.348:
            break
        time.sleep(300)
    time.sleep(600)
start = time.time()

use_fmin = False
attenlist = [39]
for atten in attenlist:
    hittite.off()
    print "setting attenuator to",atten
    ri.set_dac_attenuator(atten)
    measured_freqs = sweeps.prepare_sweep(ri,f0binned,offsets,nsamp=nsamp)
    print "loaded waveforms in", (time.time()-start),"seconds"
    
    sweep_data = sweeps.do_prepared_sweep(ri, nchan_per_step=atonce, reads_per_step=4)
    orig_sweep_data = sweep_data
    meas_cfs = []
    idxs = []
    delays = []
    for m in range(len(f0s)):
        fr,s21,errors = sweep_data.select_by_freq(f0s[m])
        thiscf = f0s[m]
        res = fit_best_resonator(fr[1:-1],s21[1:-1],errors=errors[1:-1]) #Resonator(fr,s21,errors=errors)
        delay = res.delay
        delays.append(delay)
        s21 = s21*np.exp(2j*np.pi*res.delay*fr)
        res = fit_best_resonator(fr,s21,errors=errors)
        fmin = fr[np.abs(s21).argmin()]
        print "s21 fmin", fmin, "original guess",thiscf,"this fit", res.f_0, "delay",delay,"resid delay",res.delay
        if use_fmin:
            break
        time.sleep(300)
    time.sleep(600)
start = time.time()

use_fmin = False
attenlist = [39]
for atten in attenlist:
    hittite.off()
    print "setting attenuator to", atten
    ri.set_dac_attenuator(atten)
    measured_freqs = sweeps.prepare_sweep(ri, f0binned, offsets, nsamp=nsamp)
    print "loaded waveforms in", (time.time() - start), "seconds"

    sweep_data = sweeps.do_prepared_sweep(ri,
                                          nchan_per_step=atonce,
                                          reads_per_step=4)
    orig_sweep_data = sweep_data
    meas_cfs = []
    idxs = []
    delays = []
    for m in range(len(f0s)):
        fr, s21, errors = sweep_data.select_by_freq(f0s[m])
        thiscf = f0s[m]
        res = fit_best_resonator(
            fr[1:-1], s21[1:-1],
            errors=errors[1:-1])  #Resonator(fr,s21,errors=errors)
        delay = res.delay
        delays.append(delay)
        s21 = s21 * np.exp(2j * np.pi * res.delay * fr)
        res = fit_best_resonator(fr, s21, errors=errors)
        f0binned = np.round(f0s * nsamp / 512.0) * 512.0 / nsamp
        offset_bins = np.arange(-(nstep + 1), (nstep + 1)) * step

        offsets = offset_bins * 512.0 / nsamp

        measured_freqs = sweeps.prepare_sweep(ri, f0binned, offsets, nsamp=nsamp)
        print "loaded waveforms in", (time.time() - start), "seconds"


        delay = -31.3
        print "median delay is ", delay

        df = data_file.DataFile(suffix=suffix)
        df.nc.mmw_atten_turns = mmw_atten_turns
        df.log_hw_state(ri)
        sweep_data = sweeps.do_prepared_sweep(ri, nchan_per_step=atonce, reads_per_step=2)
        df.add_sweep(sweep_data)
        meas_cfs = []
        idxs = []
        for m in range(len(f0s)):
            fr, s21, errors = sweep_data.select_by_freq(f0s[m])
            thiscf = f0s[m]
            s21 = s21 * np.exp(2j * np.pi * delay * fr)
            res = fit_best_resonator(fr, s21, errors=errors)  #Resonator(fr,s21,errors=errors)
            fmin = fr[np.abs(s21).argmin()]
            print "s21 fmin", fmin, "original guess", thiscf, "this fit", res.f_0
            if use_fmin:
                meas_cfs.append(fmin)
            else:
                if abs(res.f_0 - thiscf) > 2:
                    if abs(fmin - thiscf) > 2:
예제 #15
0
def sweeps_and_streams(f_initial, attenuations, suffix='', coarse_exponent=19, fine_exponent=21, long_stream_time=30,
                       short_stream_time=4, roach_wait=10):
    roach = baseband.RoachBaseband()
    f_modulation = roach.set_modulation_output('high')

    n_coarse_samples = 2 ** coarse_exponent
    n_fine_samples = 2 ** fine_exponent
    coarse_frequency_resolution = roach.fs / n_coarse_samples
    fine_frequency_resolution = roach.fs / n_fine_samples
    coarse_offset_integers = offset_integers[coarse_exponent]
    fine_offset_integers = offset_integers[fine_exponent]
    f_coarse_offset = coarse_frequency_resolution * coarse_offset_integers
    f_fine_offset = fine_frequency_resolution * fine_offset_integers

    start_time = time.time()
    df = data_file.DataFile(suffix=suffix)
    maximum_attenuation = max(attenuations)
    print("Setting DAC attenuator to maximum requested attenuation of {:.1f} dB.".format(maximum_attenuation))
    roach.set_dac_attenuator(maximum_attenuation)

    # At the lowest readout power, record a coarse sweep and a short stream
    sweeps.prepare_sweep(roach, f_initial, f_coarse_offset, n_coarse_samples)
    df.log_hw_state(roach)
    coarse_sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=roach.tone_bins.shape[0], reads_per_step=2)
    df.add_sweep(coarse_sweep_data)
    df.sync()
    coarse_f_fit = np.array([r.f_0 for r in fit_sweep_data(coarse_sweep_data)])
    print("coarse - initial [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff) for diff in coarse_f_fit - f_initial]))
    roach.add_tone_freqs(coarse_f_fit, overwrite_last=True)
    roach.select_bank(roach.fft_bins.shape[0] - 1)
    roach._sync()
    time.sleep(roach_wait)  # The above commands somehow create a transient that takes about 5 seconds to decay.
    df.log_hw_state(roach)
    stream_start_time = time.time()
    stream, addresses = roach.get_data_seconds(short_stream_time, pow2=True)
    df.add_timestream_data(stream, roach, stream_start_time, mmw_source_modulation_freq=f_modulation)
    df.sync()

    # Use these frequencies for all subsequent sweeps, and add an additional waveform for each stream.
    print("\nSetting fine sweep frequencies.")
    sweeps.prepare_sweep(roach, coarse_f_fit, f_fine_offset, n_fine_samples)

    for k, attenuation in enumerate(attenuations):
        print("\nMeasurement {} of {}: DAC attenuator at {:.1f} dB.".format(k + 1, len(attenuations), attenuation))
        roach.set_dac_attenuator(attenuation)
        fine_sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=roach.tone_bins.shape[0], reads_per_step=2)
        df.add_sweep(fine_sweep_data)
        df.sync()
        fine_f_fit = np.array([r.f_0 for r in fit_sweep_data(fine_sweep_data)])
        print("fine - coarse [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff) for diff in fine_f_fit - coarse_f_fit]))
        f_stream = roach.add_tone_freqs(coarse_f_fit, overwrite_last=k>0)  # Overwrite after the first
        print("stream detuning [ppm]: " + ', '.join(['{:.0f}'.format(1e6 * x) for x in (f_stream / fine_f_fit - 1)]))
        roach.select_bank(roach.fft_bins.shape[0] - 1)
        roach._sync()
        time.sleep(roach_wait)  # The above commands somehow create a transient that takes about 5 seconds to decay.
        df.log_hw_state(roach)
        stream_start_time = time.time()
        stream, addresses = roach.get_data_seconds(long_stream_time, pow2=True)
        df.add_timestream_data(stream, roach, stream_start_time, mmw_source_modulation_freq=f_modulation)
        df.sync()

    df.close()
    print("Completed in {:.0f} minutes: {}".format((time.time() - start_time) / 60, df.filename))
예제 #16
0
def sweep_fit_timestream(roach, center_frequencies, offset_frequencies, sweep_n_samples, timestream_n_samples,
                         attenuation, suffix,
                         time_in_seconds, interactive=False, coarse_multiplier=3):
    df = data_file.DataFile(suffix=suffix)
    print("Writing data to " + df.filename)
    print("Setting DAC attenuator to {:.1f} dB".format(attenuation))
    roach.set_dac_attenuator(attenuation)
    print("Sweep memory usage is {:.1f} MB of {:.1f} MB capacity.".format(
        memory_usage_bytes(offset_frequencies.shape[0], sweep_n_samples) / 2 ** 20, EFFECTIVE_DRAM_CAPACITY / 2 ** 20))

    # Do a preliminary sweep to make sure the main sweeps are centered properly.
    sweeps.prepare_sweep(roach, center_frequencies, coarse_multiplier * offset_frequencies, sweep_n_samples)
    roach._sync()
    time.sleep(0.2)
    if interactive:
        raw_input("Hit enter to record preliminary frequency sweep.")
    else:
        print("Recording preliminary frequency sweep.")
    coarse_sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=center_frequencies.size, reads_per_step=8)
    coarse_resonators = fit_sweep_data(coarse_sweep_data)
    coarse_f0s = np.array([r.f_0 for r in coarse_resonators])
    fine_center_frequencies = round_frequencies(coarse_f0s, roach.fs, sweep_n_samples)

    # Now do the actual sweep and save it.
    sweeps.prepare_sweep(roach, fine_center_frequencies, offset_frequencies, sweep_n_samples)
    roach._sync()
    time.sleep(0.2)
    df.log_hw_state(roach)
    if interactive:
        raw_input("Hit enter to begin recording frequency sweep.")
    else:
        print("Recording frequency sweep.")
    sweep_start_time = time.time()
    sweep_data = sweeps.do_prepared_sweep(roach, nchan_per_step=center_frequencies.size, reads_per_step=8)
    print("Elapsed time {:.0f} seconds. Writing to disk.".format(time.time() - sweep_start_time))
    df.add_sweep(sweep_data)
    df.sync()
    resonators = fit_sweep_data(sweep_data)
    fine_f0s = np.array([r.f_0 for r in resonators])
    print("Initial frequencies in MHz are " + ', '.join(['{:.3f}'.format(f0) for f0 in center_frequencies]))
    print("initial - fit [Hz]: " +
          ', '.join(['{:.0f}'.format(1e6 * delta_f) for delta_f in center_frequencies - fine_f0s]))

    timestream_measured_frequencies = roach.set_tone_frequencies(fine_f0s, nsamp=timestream_n_samples)
    roach.select_fft_bins(np.arange(roach.tone_bins.shape[1]))
    roach._sync()
    time.sleep(0.2)
    df.log_hw_state(roach)
    print("measured - fit [Hz]: " +
          ', '.join(['{:.0f}'.format(1e6 * delta_f) for delta_f in timestream_measured_frequencies - fine_f0s]))
    # This delay was added because the above lines cause some kind of transient signal that takes about three seconds
    # to decay. This was showing up at the beginning of the timestreams with interactive=False.
    minimum_wait = 5
    wait_start_time = time.time()
    if interactive:
        raw_input("Hit enter to begin recording {:.0f} second timestream.".format(time_in_seconds))
    else:
        print("Recording {:.0f} second timestream.".format(time_in_seconds))
    while time.time() - wait_start_time < minimum_wait:
        time.sleep(0.1)
    timestream_start_time = time.time()
    data, address = roach.get_data_seconds(time_in_seconds, demod=True, pow2=True)
    print("Elapsed time {:.0f} seconds. Writing to disk.".format(time.time() - timestream_start_time))
    df.add_timestream_data(data, roach, timestream_start_time)
    df.sync()
    df.nc.close()
    return df.filename