"""
Measure resonators, one at a time, with the readout tone centered in the filterbank bin.
"""
from __future__ import division
import time

import numpy as np

from kid_readout.roach import analog, calculate, hardware_tools, tools
from kid_readout.measurement import acquire, basic
from kid_readout.equipment import hardware, starcryo_temps
from equipment.srs import lockin
from equipment.custom import mmwave_source
from kid_readout.settings import LOCKIN_SERIAL_PORT

acquire.show_settings()
acquire.show_git_status()

import logging
logger = acquire.get_script_logger(__file__, level=logging.DEBUG)

# Parameters
suffix = 'mmw_source'
attenuations = [30]
"""
f_center = 1e6 * np.array([
    2757.5,
    #2778.3,
    #2792.0,
    #2816.0,
    #2872.0,  # low Q
"""
Sweep one tone across its filter bank bin.
"""
import time

import numpy as np

from kid_readout.roach import analog, hardware_tools, tools
from kid_readout.measurement import acquire
from kid_readout.equipment import hardware

acquire.show_settings()
acquire.show_git_status()
logger = acquire.get_script_logger(__file__)

# Parameters
suffix = 'filterbank_bin'
lo_MHz = 2000
baseband_MHz = 100
lo_round_to_MHz = 2.5e-3
dac_attenuation = 0
tones_per_bin_exponent = 3
half_width_in_bins = 3
stream_length_seconds = 0.1
wait = 5

# Hardware
conditioner = analog.HeterodyneMarkII()
hw = hardware.Hardware(conditioner)
ri = hardware_tools.r2h14_with_mk2(initialize=True, use_config=False)
ri.adc_valon.set_ref_select(0)