def go(self):
        if self.liveplot_enabled:
            self.plotter.clear()

        print("Prep Instruments")
        self.readout.set_frequency(self.cfg['readout']['frequency'])
        self.readout.set_power(self.cfg['readout']['power'])
        self.readout.set_ext_pulse(mod=self.cfg['readout']['mod'])

        self.drive.set_frequency(self.cfg['qubit']['frequency'] - self.cfg['pulse_info'][self.pulse_type]['iq_freq'])
        self.drive.set_power(self.cfg[self.expt_cfg_name]['power'])
        self.drive.set_ext_pulse(mod=self.cfg['drive']['mod'])
        self.drive.set_output(True)

        try:
            self.awg.set_amps_offsets(self.cfg['cal']['iq_amps'], self.cfg['cal']['iq_offsets'])
        except:
            print("self.awg not loaded.")

        print("Prep Card")
        adc = Alazar(self.cfg['alazar'])

        heterodyne_carrier_freq = self.cfg['readout']['heterodyne_carrier_freq']
        heterodyne_read_freqs = self.cfg['readout']['heterodyne_read_freq']

        attenpts = arange(self.cfg[self.expt_cfg_name]['atten_start'], self.cfg[self.expt_cfg_name]['atten_stop'], self.cfg[self.expt_cfg_name]['atten_step'])
        freqpts = arange(self.cfg[self.expt_cfg_name]['freq_start'], self.cfg[self.expt_cfg_name]['freq_stop'], self.cfg[self.expt_cfg_name]['freq_step'])
        num_bins = self.cfg[self.expt_cfg_name]['num_bins']

        ss_cos_data_all = zeros((2, len(attenpts), len(freqpts), len(self.expt_pts),
                             self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts))
                            )  # (channel, atten, freq, g/e/(f), average)
        ss_sin_data_all = zeros((2, len(attenpts), len(freqpts), len(self.expt_pts),
                                 self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts))
                                )  # (channel, atten, freq, g/e/(f), average)

        for xx, atten in enumerate(attenpts):
            #self.im.atten.set_attenuator(atten)
            try:
                self.readout_atten.set_attenuator(atten)
            except:
                print("Digital attenuator not loaded.")

            max_contrast_data = zeros((2,len(freqpts)))

            if self.liveplot_enabled:
                self.plotter.clear('max contrast')

            for yy, freq in enumerate(freqpts):
                self.readout.set_frequency(freq-self.cfg['readout']['heterodyne_freq'])
                #self.readout_shifter.set_phase(self.cfg['readout']['start_phase'] , freq)
                self.readout_shifter.set_phase((self.cfg['readout']['start_phase'] + self.cfg['readout']['phase_slope'] * (freq - self.cfg['readout']['frequency']))%360, freq)

                ss_data = zeros((len(self.expt_pts), num_bins))
                sss_data = zeros((len(self.expt_pts), num_bins))

                print("runnning atten no.", xx, ", freq no.", yy)

                single_data1, single_data2, single_record1, single_record2 = \
                    adc.acquire_singleshot_heterodyne_data(self.cfg['readout']['heterodyne_freq'],\
                                                       prep_function=self.awg_prep, start_function=self.awg_run, excise=self.cfg['readout']['window'])

                ss_cos_data_all[0, xx, yy, :, :] = reshape(single_data1[0], (self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts), len(self.expt_pts))).T
                ss_cos_data_all[1, xx, yy, :, :] = reshape(single_data2[0], (self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts), len(self.expt_pts))).T
                ss_sin_data_all[0, xx, yy, :, :] = reshape(single_data1[1], (self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts), len(self.expt_pts))).T
                ss_sin_data_all[1, xx, yy, :, :] = reshape(single_data2[1], (self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts), len(self.expt_pts))).T

                with self.datafile() as f:
                    f.add('ss_cos_data_ch1', ss_cos_data_all[0])
                    f.add('ss_cos_data_ch2', ss_cos_data_all[1])
                    f.add('ss_sin_data_ch1', ss_sin_data_all[0])
                    f.add('ss_sin_data_ch2', ss_sin_data_all[1])
                    f.append_line('single_record1', single_record1)
                    f.append_line('single_record2', single_record2)
                    f.close()

                if self.cfg['readout']['heterodyne_freq']==0:
                    # ch1 cos, ch2 cos
                    ss1 = single_data1[0]
                    ss2 = single_data2[0]
                else:
                    # ch1 cos, ch1 sin
                    ss1 = single_data1[0]
                    ss2 = single_data1[1]

                for kk, ssthis in enumerate([ss1, ss2]):

                    ssthis = reshape(ssthis, (self.cfg['alazar']['recordsPerAcquisition'] / len(self.expt_pts), len(self.expt_pts))).T

                    print('ss i/q ch', str(kk+1), 'max/min =', ssthis.max(), ssthis.min())
                    dist = ssthis.max() - ssthis.min()
                    histo_range = (ssthis.min() - 0.01*dist, ssthis.max() + 0.01*dist)

                    for jj, ss in enumerate(ssthis):
                        sshisto, ssbins = np.histogram(ss, bins=num_bins, range=histo_range)
                        ss_data[jj] += sshisto
                        sss_data[jj] = cumsum(ss_data[[jj]])
                        if self.liveplot_enabled:
                            self.plotter.plot_xy('histogram %d' % jj, ssbins[:-1], ss_data[jj])
                            self.plotter.plot_xy('cum histo %d' % jj, ssbins[:-1], sss_data[jj])

                    max_contrast_data[kk, yy] = abs(((sss_data[0] - sss_data[1]) / ss_data[0].sum())).max()

                    if self.liveplot_enabled:
                        self.plotter.plot_xy('contrast_ch' + str(kk+1), ssbins[:-1], abs(sss_data[0] - sss_data[1]) / ss_data[0].sum())
                        self.plotter.append_xy('max contrast_ch' + str(kk+1), freq, max_contrast_data[kk,yy])

            with self.datafile() as f:
                f.append_pt('atten', atten)
                f.add('attenpts', attenpts)
                f.append_line('freq', freqpts)
                f.append_line('max_contrast_data_ch1', max_contrast_data[0, :])
                f.append_line('max_contrast_data_ch2', max_contrast_data[1, :])
                #f.add('single_record1', single_record1)
                f.close()
    def go(self):
        if self.liveplot_enabled:
            self.plotter.clear()

        print("Prep Instruments")
        self.readout.set_frequency(self.cfg['readout']['frequency'])
        self.readout.set_power(self.cfg['readout']['power'])
        self.readout.set_ext_pulse(mod=self.cfg['readout']['mod'])

        self.drive.set_frequency(
            self.cfg['qubit']['frequency'] -
            self.cfg['pulse_info'][self.pulse_type]['iq_freq'])
        self.drive.set_power(self.cfg[self.expt_cfg_name]['power'])
        self.drive.set_ext_pulse(mod=self.cfg['drive']['mod'])
        self.drive.set_output(True)

        try:
            self.awg.set_amps_offsets(self.cfg['cal']['iq_amps'],
                                      self.cfg['cal']['iq_offsets'])
        except:
            print("self.awg not loaded.")

        print("Prep Card")
        adc = Alazar(self.cfg['alazar'])

        heterodyne_carrier_freq = self.cfg['readout'][
            'heterodyne_carrier_freq']
        heterodyne_read_freqs = self.cfg['readout']['heterodyne_read_freq']

        attenpts = arange(self.cfg[self.expt_cfg_name]['atten_start'],
                          self.cfg[self.expt_cfg_name]['atten_stop'],
                          self.cfg[self.expt_cfg_name]['atten_step'])
        freqpts = arange(self.cfg[self.expt_cfg_name]['freq_start'],
                         self.cfg[self.expt_cfg_name]['freq_stop'],
                         self.cfg[self.expt_cfg_name]['freq_step'])
        num_bins = self.cfg[self.expt_cfg_name]['num_bins']

        ss_cos_data_all = zeros(
            (2, len(attenpts), len(freqpts), len(self.expt_pts),
             self.cfg['alazar']['recordsPerAcquisition'] /
             len(self.expt_pts)))  # (channel, atten, freq, g/e/(f), average)
        ss_sin_data_all = zeros(
            (2, len(attenpts), len(freqpts), len(self.expt_pts),
             self.cfg['alazar']['recordsPerAcquisition'] /
             len(self.expt_pts)))  # (channel, atten, freq, g/e/(f), average)

        for xx, atten in enumerate(attenpts):
            #self.im.atten.set_attenuator(atten)
            try:
                self.readout_atten.set_attenuator(atten)
            except:
                print("Digital attenuator not loaded.")

            max_contrast_data = zeros((2, len(freqpts)))

            if self.liveplot_enabled:
                self.plotter.clear('max contrast')

            for yy, freq in enumerate(freqpts):
                self.readout.set_frequency(
                    freq - self.cfg['readout']['heterodyne_freq'])
                #self.readout_shifter.set_phase(self.cfg['readout']['start_phase'] , freq)
                self.readout_shifter.set_phase(
                    (self.cfg['readout']['start_phase'] +
                     self.cfg['readout']['phase_slope'] *
                     (freq - self.cfg['readout']['frequency'])) % 360, freq)

                ss_data = zeros((len(self.expt_pts), num_bins))
                sss_data = zeros((len(self.expt_pts), num_bins))

                print("runnning atten no.", xx, ", freq no.", yy)

                single_data1, single_data2, single_record1, single_record2 = \
                    adc.acquire_singleshot_heterodyne_data(self.cfg['readout']['heterodyne_freq'],\
                                                       prep_function=self.awg_prep, start_function=self.awg_run, excise=self.cfg['readout']['window'])

                ss_cos_data_all[0, xx, yy, :, :] = reshape(
                    single_data1[0],
                    (self.cfg['alazar']['recordsPerAcquisition'] /
                     len(self.expt_pts), len(self.expt_pts))).T
                ss_cos_data_all[1, xx, yy, :, :] = reshape(
                    single_data2[0],
                    (self.cfg['alazar']['recordsPerAcquisition'] /
                     len(self.expt_pts), len(self.expt_pts))).T
                ss_sin_data_all[0, xx, yy, :, :] = reshape(
                    single_data1[1],
                    (self.cfg['alazar']['recordsPerAcquisition'] /
                     len(self.expt_pts), len(self.expt_pts))).T
                ss_sin_data_all[1, xx, yy, :, :] = reshape(
                    single_data2[1],
                    (self.cfg['alazar']['recordsPerAcquisition'] /
                     len(self.expt_pts), len(self.expt_pts))).T

                with self.datafile() as f:
                    f.add('ss_cos_data_ch1', ss_cos_data_all[0])
                    f.add('ss_cos_data_ch2', ss_cos_data_all[1])
                    f.add('ss_sin_data_ch1', ss_sin_data_all[0])
                    f.add('ss_sin_data_ch2', ss_sin_data_all[1])
                    f.append_line('single_record1', single_record1)
                    f.append_line('single_record2', single_record2)
                    f.close()

                if self.cfg['readout']['heterodyne_freq'] == 0:
                    # ch1 cos, ch2 cos
                    ss1 = single_data1[0]
                    ss2 = single_data2[0]
                else:
                    # ch1 cos, ch1 sin
                    ss1 = single_data1[0]
                    ss2 = single_data1[1]

                for kk, ssthis in enumerate([ss1, ss2]):

                    ssthis = reshape(
                        ssthis, (self.cfg['alazar']['recordsPerAcquisition'] /
                                 len(self.expt_pts), len(self.expt_pts))).T

                    print('ss i/q ch', str(kk + 1), 'max/min =', ssthis.max(),
                          ssthis.min())
                    dist = ssthis.max() - ssthis.min()
                    histo_range = (ssthis.min() - 0.01 * dist,
                                   ssthis.max() + 0.01 * dist)

                    for jj, ss in enumerate(ssthis):
                        sshisto, ssbins = np.histogram(ss,
                                                       bins=num_bins,
                                                       range=histo_range)
                        ss_data[jj] += sshisto
                        sss_data[jj] = cumsum(ss_data[[jj]])
                        if self.liveplot_enabled:
                            self.plotter.plot_xy('histogram %d' % jj,
                                                 ssbins[:-1], ss_data[jj])
                            self.plotter.plot_xy('cum histo %d' % jj,
                                                 ssbins[:-1], sss_data[jj])

                    max_contrast_data[kk, yy] = abs(
                        ((sss_data[0] - sss_data[1]) /
                         ss_data[0].sum())).max()

                    if self.liveplot_enabled:
                        self.plotter.plot_xy(
                            'contrast_ch' + str(kk + 1), ssbins[:-1],
                            abs(sss_data[0] - sss_data[1]) / ss_data[0].sum())
                        self.plotter.append_xy('max contrast_ch' + str(kk + 1),
                                               freq, max_contrast_data[kk, yy])

            with self.datafile() as f:
                f.append_pt('atten', atten)
                f.add('attenpts', attenpts)
                f.append_line('freq', freqpts)
                f.append_line('max_contrast_data_ch1', max_contrast_data[0, :])
                f.append_line('max_contrast_data_ch2', max_contrast_data[1, :])
                #f.add('single_record1', single_record1)
                f.close()