예제 #1
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
예제 #2
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
예제 #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_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
    ri.set_lo(lo)
    for atten in attenlist:
        hittite.off()
        print "setting attenuator to", atten
        ri.set_dac_attenuator(atten)

        nsamp = 2**16
        step = 1
        nstep = 32
        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 = []
예제 #6
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
예제 #7
0
def mmw_source_power_step(f_initial_off,
                          f_initial_on,
                          attenuations,
                          f_mmw_source=0,
                          suffix="mmw",
                          hittite_power=0,
                          long_stream_time=30,
                          modulated_stream_time=4,
                          coarse_exponent=19,
                          fine_exponent=21,
                          modulation_rate_integer=7):
    if f_mmw_source:
        from kid_readout.equipment import hittite_controller

        frequency_multiplication_factor = 12
        hittite = hittite_controller.hittiteController()
        hittite.set_power(hittite_power)  # in dBm
        hittite.set_freq(f_mmw_source /
                         frequency_multiplication_factor)  # in Hz
        hittite.on()

    lockin = lockin_controller.lockinController()
    print(lockin.get_idn())

    roach = baseband.RoachBaseband()

    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

    while True:
        f_source_modulation = roach.set_modulation_output(
            modulation_rate_integer)
        print(
            "\nSet source modulation frequency to {:.1f} Hz. Check the lock-in."
            .format(f_source_modulation))
        try:
            mmw_attenuator_turns = float(
                raw_input(
                    "Enter the value to which both attenuators are set, or hit Enter to stop recording data: "
                ))
        except ValueError:
            break

        start_time = time.time()
        df = data_file.DataFile(suffix=suffix)
        df.nc.mmw_atten_turns = (mmw_attenuator_turns, mmw_attenuator_turns)
        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 with the source off and a modulated stream at the fit
        # source-off resonances.
        sweeps.prepare_sweep(roach, f_initial_off, f_coarse_offset,
                             n_coarse_samples)
        coarse_sweep_off, stream_mod_off = mmw_source_sweep_and_stream(
            df, roach, lockin, modulated_stream_time, False, f_mmw_source,
            'high', modulation_rate_integer, modulation_rate_integer)
        f_coarse_fit_off = np.array(
            [r.f_0 for r in fit_sweep_data(coarse_sweep_off)])
        print("Source off: coarse - initial [Hz]: " + ', '.join([
            '{:.0f}'.format(1e6 * diff)
            for diff in f_coarse_fit_off - f_initial_off
        ]))

        # At the lowest readout power, record a fine sweep and long stream with the source off.
        sweeps.prepare_sweep(roach, f_coarse_fit_off, f_fine_offset,
                             n_fine_samples)
        fine_sweep_off, stream_off = mmw_source_sweep_and_stream(
            df, roach, lockin, long_stream_time, False, f_mmw_source, 'high',
            'high', modulation_rate_integer)
        f_fine_fit_off = np.array(
            [r.f_0 for r in fit_sweep_data(fine_sweep_off)])
        print("Source off: fine - coarse [Hz]: " + ', '.join([
            '{:.0f}'.format(1e6 * diff)
            for diff in f_fine_fit_off - f_coarse_fit_off
        ]))

        # At the lowest readout power, record a coarse sweep with the source on and a modulated stream at the fit
        # source-on resonances.
        sweeps.prepare_sweep(roach, f_initial_on, f_coarse_offset,
                             n_coarse_samples)
        coarse_sweep_on, stream_mod_on = mmw_source_sweep_and_stream(
            df, roach, lockin, modulated_stream_time, False, f_mmw_source,
            'low', modulation_rate_integer, modulation_rate_integer)
        f_coarse_fit_on = np.array(
            [r.f_0 for r in fit_sweep_data(coarse_sweep_on)])
        print("Source on: coarse - initial [Hz]: " + ', '.join([
            '{:.0f}'.format(1e6 * diff)
            for diff in f_coarse_fit_on - f_initial_on
        ]))

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

        for k, attenuation in enumerate(attenuations):
            print(
                "\nSource-on measurement {} of {}: DAC attenuator at {:.1f} dB."
                .format(k + 1, len(attenuations), attenuation))
            roach.set_dac_attenuator(attenuation)
            fine_sweep_on, stream = mmw_source_sweep_and_stream(
                df,
                roach,
                lockin,
                long_stream_time,
                k > 0,  # overwrite after the first.
                f_mmw_source,
                'low',
                'low',
                modulation_rate_integer)
            f_fine_fit_on = [r.f_0 for r in fit_sweep_data(fine_sweep_on)]
            print("Source on: fine - coarse [Hz]: " + ', '.join([
                '{:.0f}'.format(1e6 * diff)
                for diff in f_fine_fit_on - f_coarse_fit_on
            ]))

        df.close()
        print("Completed in {:.0f} minutes: {}".format(
            (time.time() - start_time) / 60, df.filename))

    # Clean up.
    if f_mmw_source:
        hittite.off()
        hittite.disconnect()
예제 #8
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))
    while True:
        temp = get_all_temperature_data()[1][-1]
        print "mk stage at", temp
        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)
예제 #10
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))
예제 #11
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
예제 #12
0
def mmw_source_power_step(f_initial_off, f_initial_on, attenuations, f_mmw_source=0, suffix="mmw", hittite_power=0,
                          long_stream_time=30,
                          modulated_stream_time=4, coarse_exponent=19, fine_exponent=21, modulation_rate_integer=7):
    if f_mmw_source:
        from kid_readout.equipment import hittite_controller

        frequency_multiplication_factor = 12
        hittite = hittite_controller.hittiteController()
        hittite.set_power(hittite_power)  # in dBm
        hittite.set_freq(f_mmw_source / frequency_multiplication_factor)  # in Hz
        hittite.on()

    lockin = lockin_controller.lockinController()
    print(lockin.get_idn())

    roach = baseband.RoachBaseband()

    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

    while True:
        f_source_modulation = roach.set_modulation_output(modulation_rate_integer)
        print("\nSet source modulation frequency to {:.1f} Hz. Check the lock-in.".format(f_source_modulation))
        try:
            mmw_attenuator_turns = float(
                raw_input("Enter the value to which both attenuators are set, or hit Enter to stop recording data: "))
        except ValueError:
            break

        start_time = time.time()
        df = data_file.DataFile(suffix=suffix)
        df.nc.mmw_atten_turns = (mmw_attenuator_turns, mmw_attenuator_turns)
        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 with the source off and a modulated stream at the fit
        # source-off resonances.
        sweeps.prepare_sweep(roach, f_initial_off, f_coarse_offset, n_coarse_samples)
        coarse_sweep_off, stream_mod_off = mmw_source_sweep_and_stream(df, roach, lockin, modulated_stream_time,
                                                                       False,
                                                                       f_mmw_source, 'high',
                                                                       modulation_rate_integer,
                                                                       modulation_rate_integer)
        f_coarse_fit_off = np.array([r.f_0 for r in fit_sweep_data(coarse_sweep_off)])
        print("Source off: coarse - initial [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff)
                                                                 for diff in f_coarse_fit_off - f_initial_off]))

        # At the lowest readout power, record a fine sweep and long stream with the source off.
        sweeps.prepare_sweep(roach, f_coarse_fit_off, f_fine_offset, n_fine_samples)
        fine_sweep_off, stream_off = mmw_source_sweep_and_stream(df, roach, lockin, long_stream_time, False,
                                                                 f_mmw_source, 'high', 'high',
                                                                 modulation_rate_integer)
        f_fine_fit_off = np.array([r.f_0 for r in fit_sweep_data(fine_sweep_off)])
        print("Source off: fine - coarse [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff)
                                                              for diff in f_fine_fit_off - f_coarse_fit_off]))

        # At the lowest readout power, record a coarse sweep with the source on and a modulated stream at the fit
        # source-on resonances.
        sweeps.prepare_sweep(roach, f_initial_on, f_coarse_offset, n_coarse_samples)
        coarse_sweep_on, stream_mod_on = mmw_source_sweep_and_stream(df, roach, lockin, modulated_stream_time,
                                                                     False,
                                                                     f_mmw_source,
                                                                     'low', modulation_rate_integer,
                                                                     modulation_rate_integer)
        f_coarse_fit_on = np.array([r.f_0 for r in fit_sweep_data(coarse_sweep_on)])
        print("Source on: coarse - initial [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff)
                                                                for diff in f_coarse_fit_on - f_initial_on]))

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

        for k, attenuation in enumerate(attenuations):
            print("\nSource-on measurement {} of {}: DAC attenuator at {:.1f} dB.".format(k + 1, len(attenuations),
                                                                                          attenuation))
            roach.set_dac_attenuator(attenuation)
            fine_sweep_on, stream = mmw_source_sweep_and_stream(df, roach, lockin, long_stream_time,
                                                                k > 0,  # overwrite after the first.
                                                                f_mmw_source, 'low', 'low',
                                                                modulation_rate_integer)
            f_fine_fit_on = [r.f_0 for r in fit_sweep_data(fine_sweep_on)]
            print("Source on: fine - coarse [Hz]: " + ', '.join(['{:.0f}'.format(1e6 * diff)
                                                                 for diff in f_fine_fit_on - f_coarse_fit_on]))

        df.close()
        print("Completed in {:.0f} minutes: {}".format((time.time() - start_time) / 60, df.filename))

    # Clean up.
    if f_mmw_source:
        hittite.off()
        hittite.disconnect()