def find_amp90_scaling(self,
                           scales=0.5,
                           N_steps=[5, 9],
                           max_n=100,
                           close_fig=True,
                           verbose=False,
                           MC=None,
                           update=True,
                           take_fit_I=False):
        '''
        Finds the scaling factor of pi/2 pulses w.r.t pi pulses using a rabi
        type with each pi pulse replaced by 2 pi/2 pulses.

        If scales is an array it starts by fitting a cos to a Rabi experiment
        to get an initial guess for the amplitude.

        This experiment is only useful after carefully calibrating the pi pulse
        using flipping sequences.
        '''
        if MC is None:
            MC = self.MC
        if np.size(scales) != 1:
            self.measure_rabi_amp90(scales=scales, n=1, MC=MC, analyze=False)
            a = ma.Rabi_Analysis(close_fig=close_fig)
            if take_fit_I:
                scale = abs(a.fit_res[0].params['period'].value) / 2
            else:
                if (a.fit_res[0].params['period'].stderr <=
                        a.fit_res[1].params['period'].stderr):
                    scale = abs(a.fit_res[0].params['period'].value) / 2
                else:
                    scale = abs(a.fit_res[1].params['period'].value) / 2
        else:
            scale = scales
        if verbose:
            print('Initial scaling factor:', scale, '\n')

        for n in N_steps:
            if n > max_n:
                break
            else:
                scale_span = 0.3 * scale / n
                scales = np.linspace(scale - scale_span, scale + scale_span,
                                     15)
                self.measure_rabi_amp90(scales, n=n, MC=MC, analyze=False)
                a = ma.Rabi_parabola_analysis(close_fig=close_fig)
                if take_fit_I:
                    scale = a.fit_res[0].params['x0'].value
                else:
                    if (a.fit_res[0].params['x0'].stderr <=
                            a.fit_res[1].params['x0'].stderr):
                        scale = a.fit_res[0].params['x0'].value
                    else:
                        scale = a.fit_res[1].params['x0'].value
                if verbose:
                    print('Founcaleitude', scale, '\n')
        if update:
            self.amp90_scale(scale)
            print("should be updated")
            print(scale)
    def find_pulse_amplitude(self,
                             amps=np.linspace(-.5, .5, 31),
                             N_steps=[3, 7, 13, 17],
                             max_n=18,
                             close_fig=True,
                             verbose=False,
                             MC=None,
                             update=True,
                             take_fit_I=False):
        '''
        Finds the pulse-amplitude using a Rabi experiment.
        Fine tunes by doing a Rabi around the optimum with an odd
        multiple of pulses.

        Args:
            amps: (array or float) amplitudes of the first Rabi if an array,
                if a float is specified it will be treated as an estimate
                for the amplitude to be found.
            N_steps: (list of int) number of pulses used in the fine tuning
            max_n: (int) break of if N> max_n
        '''
        if MC is None:
            MC = self.MC.get_instr()
        if np.size(amps) != 1:
            ampl = self.calibrate_pulse_amplitude_coarse(amps=amps,
                                                         close_fig=close_fig,
                                                         verbose=verbose,
                                                         MC=MC,
                                                         update=update,
                                                         take_fit_I=take_fit_I)
        else:
            ampl = amps
        if verbose:
            print('Initial Amplitude:', ampl, '\n')

        for n in N_steps:
            if n > max_n:
                break
            else:
                old_amp = ampl
                ampl_span = 0.5 * ampl / n
                amps = np.linspace(ampl - ampl_span, ampl + ampl_span, 15)
                self.measure_rabi(amps, n=n, MC=MC, analyze=False)
                a = ma.Rabi_parabola_analysis(close_fig=close_fig)
                # Decide which quadrature to take by comparing the contrast
                if take_fit_I:
                    ampl = a.fit_res[0].params['x0'].value
                elif (np.abs(
                        max(a.measured_values[0]) -
                        min(a.measured_values[0]))) > (np.abs(
                            max(a.measured_values[1]) -
                            min(a.measured_values[1]))):
                    ampl = a.fit_res[0].params['x0'].value
                else:
                    ampl = a.fit_res[1].params['x0'].value
                if not min(amps) < ampl < max(amps):
                    ampl_span *= 2
                    amps = np.linspace(old_amp - ampl_span,
                                       old_amp + ampl_span, 15)
                    self.measure_rabi(amps, n=n, MC=MC, analyze=False)
                    a = ma.Rabi_parabola_analysis(close_fig=close_fig)
                    # Decide which quadrature to take by comparing the contrast
                    if take_fit_I:
                        ampl = a.fit_res[0].params['x0'].value
                    elif (np.abs(
                            max(a.measured_values[0]) -
                            min(a.measured_values[0]))) > (np.abs(
                                max(a.measured_values[1]) -
                                min(a.measured_values[1]))):
                        ampl = a.fit_res[0].params['x0'].value
                    else:
                        ampl = a.fit_res[1].params['x0'].value
                if verbose:
                    print('Found amplitude', ampl, '\n')
        if update:
            self.Q_amp180.set(ampl)
        return ampl