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
coarse_frequency_resolution = roach.fs / coarse_n_samples  # about 1 kHz
coarse_offset_integers = acquire.offset_integers[coarse_exponent] - 32
nstep = 80
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
offsets = np.concatenate(([offsets.min()-20e-3,],offsets,[offsets.max()+20e-3]))

print f0s
print offsets*1e6
print len(f0s)

mmw_freqs = np.linspace(135e9,165e9,2000)
fundamental_freqs = mmw_freqs/12.0


fg.set_dc_voltage(0.0)

if False:
    from kid_readout.utils.parse_srs import get_all_temperature_data
    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:
    )  # 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
coarse_frequency_resolution = roach.fs / coarse_n_samples  # about 1 kHz
coarse_offset_integers = acquire.offset_integers[coarse_exponent] - 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
offsets = np.concatenate(([
    offsets.min() - 20e-3,
], offsets, [offsets.max() + 20e-3]))

print f0s
print offsets * 1e6
print len(f0s)

mmw_freqs = np.linspace(135e9, 165e9, 2000)
fundamental_freqs = mmw_freqs / 12.0

fg.set_dc_voltage(0.0)

if False:
    from kid_readout.equipment.parse_srs import get_all_temperature_data
    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: