Пример #1
0
def run_multipart_sweep(ri,
                        length_seconds=0,
                        state=None,
                        description='',
                        num_tones_read_at_once=32,
                        verbose=False,
                        **kwargs):
    num_tones = ri.tone_bins.shape[1]
    num_steps = num_tones // num_tones_read_at_once
    if num_steps == 0:
        num_steps = 1
    indices_to_read = range(num_tones)
    parts = []
    for step in range(num_steps):
        if verbose:
            print("running sweep step {} of {}.".format(step, num_steps))
        parts.append(
            run_loaded_sweep(ri,
                             length_seconds=length_seconds,
                             state=state,
                             description=description,
                             bin_indices=indices_to_read[step::num_steps],
                             **kwargs))
    stream_arrays = core.MeasurementList()
    for part in parts:
        stream_arrays.extend(list(part.stream_arrays))
    return basic.SweepArray(stream_arrays,
                            state=state,
                            description=description)
Пример #2
0
def run_sweep(ri,
              tone_banks,
              num_tone_samples,
              length_seconds=0,
              state=None,
              description='',
              verbose=False,
              wait_for_sync=0.1,
              **kwargs):
    """
    Return a SweepArray acquired using the given tone banks.

    Parameters
    ----------
    ri : RoachInterface
        An instance of a subclass.
    tone_banks : iterable of ndarray (float)
        An iterable of arrays (or a 2-D array) of frequencies to use for the sweep.
    num_tone_samples : int
        The number of samples in the playback buffer; must be a power of two.
    length_seconds : float
        The duration of each data stream; the default of 0 means the minimum unit of data that can be read out in the
        current configuration.
    state : dict
        The non-roach state to pass to the SweepArray.
    description : str
        A human-readable description of the measurement.
    verbose : bool
        If true, print progress messages.
    wait_for_sync : float
        Sleep for this time in seconds to let the ROACH sync finish.
    kwargs
        Keyword arguments passed to ri.get_measurement().

    Returns
    -------
    SweepArray
    """
    stream_arrays = core.MeasurementList()
    if verbose:
        print("Measuring bank")
    for n, tone_bank in enumerate(tone_banks):
        if verbose:
            print n,
            sys.stdout.flush()
        ri.set_tone_freqs(tone_bank, nsamp=num_tone_samples)
        ri.select_fft_bins(np.arange(tone_bank.size))
        # we wait a bit here to let the roach2 sync catch up.  figuring this out still.
        time.sleep(wait_for_sync)
        stream_arrays.append(
            ri.get_measurement(num_seconds=length_seconds, **kwargs))
    return basic.SweepArray(stream_arrays,
                            state=state,
                            description=description)
Пример #3
0
def run_loaded_sweep(ri,
                     length_seconds=0,
                     state=None,
                     description='',
                     tone_bank_indices=None,
                     bin_indices=None,
                     verbose=False,
                     **kwargs):
    """
    Return a SweepArray acquired using previously-loaded tones.

    Parameters
    ----------
    ri : RoachInterface
        An instance of a subclass.
    length_seconds : float
        The duration of each data stream; the default of 0 means the minimum unit of data that can be read out in the
        current configuration.
    state : dict
        The non-roach state to pass to the SweepArray.
    description : str
        A human-readable description of the measurement.
    tone_bank_indices : numpy.ndarray[int]
        The indices of the tone banks to use in the sweep; the default is to use all existing.
    bin_indices : numpy.ndarray[int]
        The indices of the filterbank bins to read out; the default is to read out all bins.
    verbose : bool
        If true, print progress messages.
    kwargs
        Keyword arguments passed to ri.get_measurement().

    Returns
    -------
    SweepArray
    """
    if tone_bank_indices is None:
        tone_bank_indices = np.arange(ri.tone_bins.shape[0])
    if bin_indices is None:
        bin_indices = np.arange(ri.tone_bins.shape[1])
    stream_arrays = core.MeasurementList()
    if verbose:
        print "Measuring bank:",
    for tone_bank_index in tone_bank_indices:
        if verbose:
            print tone_bank_index,
            sys.stdout.flush()
        ri.select_bank(tone_bank_index)
        ri.select_fft_bins(bin_indices)
        stream_arrays.append(
            ri.get_measurement(num_seconds=length_seconds, **kwargs))
    return basic.SweepArray(stream_arrays,
                            state=state,
                            description=description)
Пример #4
0
offset_frequency = np.linspace(10, 200, 16)
num_tone_samples = 2**15
dac_attenuation = 62  # The maximum
lo_frequency = 3000

# Hardware
conditioner = analog.HeterodyneMarkII()
hw = hardware.Hardware(conditioner)
ri = hardware_tools.r1_with_mk2()
ri.initialize(use_config=False)
ri.set_dac_attenuator(dac_attenuation)
ri.set_lo(lomhz=lo_frequency)
ri.set_tone_freqs(freqs=lo_frequency + offset_frequency,
                  nsamp=num_tone_samples)
ri.select_fft_bins(np.arange(offset_frequency.size))
assert np.all(ri.lo_valon.get_phase_locks())

# Acquire
sweep = basic.SweepArray(core.IOList(), description="T_c measurement")
name = 'sweep'
npd = acquire.new_npy_directory(suffix='Tc')
npd.write(sweep, name)
try:
    while True:
        sweep.stream_arrays.append(
            ri.get_measurement(num_seconds=length_seconds, state=hw.state()))
        sleep(wait)
finally:
    npd.close()
    print("Wrote {}".format(npd.root_path))
Пример #5
0
print("Using {} simultaneous tones spanning {:.1f} MHz.".format(num_tones, 1e-6 * f_block))
f_center_MHz = 1e-6 * np.arange(f_start, f_stop, f_block)
print("Block center frequencies in MHz: {}".format(', '.join(['{:.1f}'.format(f) for f in f_center_MHz])))
f_lo_offset_MHz = 1e-6 * (np.arange(-f_tone / 2, f_tone / 2, f_lo_resolution) - f_minimum)
# This order covers the entire band then comes back to fill in the gaps.
f_lo_MHz = (f_center_MHz[np.newaxis, :] + f_lo_offset_MHz[:, np.newaxis]).flatten()
n_minimum = np.ceil(f_minimum / f_roach_resolution)
step = np.floor(f_tone / f_roach_resolution)
n_baseband = n_minimum + step * np.arange(num_tones)
f_baseband_MHz = 1e-6 * n_baseband * f_roach_resolution

# State
state = {'cryostat': 'hpd',
         'canceling_magnet': {'orientation': 'up',
                              'distance_from_base_mm': 25}}

# Acquire
ri.set_tone_baseband_freqs(freqs=f_baseband_MHz, nsamp=num_tone_samples)
ri.select_fft_bins(np.arange(f_baseband_MHz.size))
sweep = basic.SweepArray(core.IOList(), state=state, description=acquire.script_code())
ncf = new_nc_file(suffix='lo_scan')
ncf.write(sweep)
try:
    for f_lo in make_iterable(f_lo_MHz):
        ri.set_lo(lomhz=f_lo, chan_spacing=1e-6 * f_lo_resolution)
        sweep.stream_arrays.append(ri.get_measurement(num_seconds=stream_seconds, state=state))
finally:
    ncf.close()
    print("Wrote {}".format(ncf.root_path))
    print("Elapsed time {:.0f} minutes.".format((time.time() - tic) / 60))
Пример #6
0
fft_gains = [6, 7, 8, 9]
tone_sample_exponent = 15
length_seconds = 0.1
wait = 10

# Hardware
conditioner = analog.Baseband()
shield = hardware.Thing(name='magnetic_shield_bucket', state={})
hw = hardware.Hardware(conditioner, shield)
ri = r2baseband.Roach2Baseband(roachip=ROACH2_IP, adc_valon=ROACH2_VALON)
ri.set_modulation_output('high')
ri.set_tone_freqs(freqs=frequency, nsamp=2**tone_sample_exponent)

# Run
sweeps = [
    basic.SweepArray(core.IOList(),
                     description="T_c {:.1f} dB".format(attenuation))
    for attenuation in attenuations
]
ncf = acquire.new_nc_file(suffix='Tc')
for sweep in sweeps:
    ncf.write(sweep)
try:
    while True:
        for sweep, attenuation, fft_gain in zip(sweeps, attenuations,
                                                fft_gains):
            ri.set_fft_gain(fft_gain)
            ri.set_dac_attenuator(attenuation)
            sweep.stream_arrays.append(
                ri.get_measurement(num_seconds=length_seconds,
                                   state=hw.state()))
            time.sleep(wait)