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


# run from here:
fg = FunctionGenerator()
heater_voltage = 0
fg.set_dc_voltage(heater_voltage)

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

roach = baseband.RoachBaseband()

suffix = "mmw_noise_step_with_load"
mmw_source_frequency = -1.0

f0s = np.load('/home/data2/resonances/2014-12-06_140825_0813f8_fit_16.npy')

coarse_exponent = 19
coarse_n_samples = 2**coarse_exponent
import matplotlib

from kid_readout.roach import baseband

matplotlib.use('agg')
import numpy as np
import time
import sys
from kid_readout.utils import data_file,sweeps
from kid_readout.analysis.resonator import fit_best_resonator
from kid_readout.equipment import hittite_controller
from kid_readout.equipment import lockin_controller
from kid_readout.equipment.agilent_33220 import FunctionGenerator

fg = FunctionGenerator()

hittite = hittite_controller.hittiteController()
lockin = lockin_controller.lockinController()
print lockin.get_idn()

ri = baseband.RoachBaseband()
ri.initialize()
f0s = np.load('/home/gjones/kid_readout/apps/sc5x4_0813f12.npy')
f0s.sort()
f0s = f0s[[0,1,2,3,4,5,6,7,8,9,10,13,14,15,16,17]]  # remove close packed resonators to enable reading out all simultaneously

suffix = "mmwnoise"
mmw_source_modulation_freq = 25.0
mmw_atten_turns = (6.5,6.5)

def source_on():
                                               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


# run from here:
fg = FunctionGenerator()
heater_voltage = 0
fg.set_dc_voltage(heater_voltage)

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

roach = baseband.RoachBaseband()

suffix = "mmw_noise_step_with_load"
mmw_source_frequency = -1.0

f0s = np.load('/home/data2/resonances/2014-12-06_140825_0813f8_fit_16.npy')

coarse_exponent = 19
coarse_n_samples = 2**coarse_exponent
import matplotlib
matplotlib.use('agg')
import numpy as np
import time
import sys
from kid_readout.utils import roach_interface,data_file,sweeps
from kid_readout.analysis.resonator import Resonator
from kid_readout.analysis.resonator import fit_best_resonator
from kid_readout.equipment import hittite_controller
from kid_readout.equipment import lockin_controller
from kid_readout.equipment.agilent_33220 import FunctionGenerator

fg = FunctionGenerator()

hittite = hittite_controller.hittiteController()
lockin = lockin_controller.lockinController()
print lockin.get_idn()

ri = roach_interface.RoachBaseband()
ri.initialize()
f0s = np.load('/home/gjones/kid_readout/apps/sc5x4_0813f12.npy')
f0s.sort()
f0s = f0s[[0,1,2,3,4,5,6,7,8,9,10,13,14,15,16,17]]  # remove close packed resonators to enable reading out all simultaneously

suffix = "mmw"
mmw_source_modulation_freq = 25.0
mmw_atten_turns = (7.0,7.0)

nf = len(f0s)
atonce = 16
if nf % atonce > 0:
import time

import numpy as np

from kid_readout.interactive import *
from kid_readout.measurement import acquire
from kid_readout.roach import r2heterodyne, attenuator, hardware_tools

from equipment.custom import mmwave_source
from equipment.hittite import signal_generator
from equipment.srs import lockin
from kid_readout.equipment.agilent_33220 import FunctionGenerator

logger.setLevel(logging.DEBUG)

fg = FunctionGenerator()
fg.set_load_ohms(1e6)

hittite = signal_generator.Hittite(ipaddr='192.168.0.200')
hittite.set_power(0)
hittite.on()
hittite.set_freq(148e9 / 12.)

lockin = lockin.Lockin(LOCKIN_SERIAL_PORT)
tic = time.time()
print lockin.identification
print time.time() - tic
tic = time.time()
print lockin.fast_state
print time.time() - tic
source = mmwave_source.MMWaveSource()
import matplotlib
from kid_readout.measurement.legacy import sweeps

from kid_readout.roach import baseband

matplotlib.use('agg')
import numpy as np
import time
import sys
from kid_readout.utils import data_file
from kid_readout.analysis.resonator.legacy_resonator import fit_best_resonator
from kid_readout.equipment import hittite_controller
from kid_readout.equipment import lockin_controller
from kid_readout.equipment.agilent_33220 import FunctionGenerator

fg = FunctionGenerator()

hittite = hittite_controller.hittiteController()
lockin = lockin_controller.lockinController()
print lockin.get_idn()

ri = baseband.RoachBaseband()
ri.initialize()
f0s = np.load('/home/gjones/kid_readout/apps/sc5x4_0813f12.npy')
f0s.sort()
f0s = f0s[[
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17
]]  # remove close packed resonators to enable reading out all simultaneously

suffix = "mmw"
mmw_source_modulation_freq = 25.0