def get_fit_from_peak(self, lowerLimit, upperLimit, NumPointsSmoothing=1, silent=False, MakeFig=True, show_fig=True):
        """
        Finds approximate values for the peaks central frequency, height, 
        and FWHM by looking for the heighest peak in the frequency range defined 
        by the input arguments. It then uses the central frequency as the trapping 
        frequency, peak height to approximate the A value and the FWHM to an approximate
        the Gamma (damping) value.

        Parameters
        ----------
        lowerLimit : float
            The lower frequency limit of the range in which it looks for a peak
        upperLimit : float
            The higher frequency limit of the range in which it looks for a peak
        NumPointsSmoothing : float
            The number of points of moving-average smoothing it applies before fitting the 
            peak.
        Silent : bool, optional
            Whether it prints the values fitted or is silent.
        show_fig : bool, optional
            Whether it makes and shows the figure object or not.

        Returns
        -------
        OmegaTrap : ufloat
            Trapping frequency
        A : ufloat
            A parameter
        Gamma : ufloat
            Gamma, the damping parameter
        """
        lowerIndex = _np.where(self.freqs ==
            take_closest(self.freqs, lowerLimit))[0][0]
        upperIndex = _np.where(self.freqs ==
            take_closest(self.freqs, upperLimit))[0][0]

        if lowerIndex == upperIndex:
            _warnings.warn("range is too small, returning NaN", UserWarning)
            val = _uncertainties.ufloat(_np.NaN, _np.NaN)
            return val, val, val, val, val

        MaxPSD = max(self.PSD[lowerIndex:upperIndex])

        centralIndex = _np.where(self.PSD == MaxPSD)[0][0]
        CentralFreq = self.freqs[centralIndex]

        approx_A = MaxPSD * 1e16  # 1e16 was calibrated for a number of saves to be approximately the correct conversion factor between the height of the PSD and the A factor in the fitting

        MinPSD = min(self.PSD[lowerIndex:upperIndex])

        # need to get this on log scale
        HalfMax = MinPSD + (MaxPSD - MinPSD) / 2

        try:
            LeftSideOfPeakIndex = _np.where(self.PSD ==
                                            take_closest(self.PSD[lowerIndex:centralIndex], HalfMax))[0][0]
            LeftSideOfPeak = self.freqs[LeftSideOfPeakIndex]
        except IndexError:
            _warnings.warn("range is too small, returning NaN", UserWarning)
            val = _uncertainties.ufloat(_np.NaN, _np.NaN)
            return val, val, val, val, val

        try:
            RightSideOfPeakIndex = _np.where(self.PSD ==
                                             take_closest(self.PSD[centralIndex:upperIndex], HalfMax))[0][0]
            RightSideOfPeak = self.freqs[RightSideOfPeakIndex]
        except IndexError:
            _warnings.warn("range is too small, returning NaN", UserWarning)
            val = _uncertainties.ufloat(_np.NaN, _np.NaN)
            return val, val, val, val, val

        FWHM = RightSideOfPeak - LeftSideOfPeak

        approx_Gamma = FWHM/4
        try:
            A, OmegaTrap, Gamma, fig, ax \
                = self.get_fit(CentralFreq,
                               (upperLimit-lowerLimit)/2, 
                               A_Initial=approx_A,
                               Gamma_Initial=approx_Gamma,
                               silent=silent,
                               MakeFig=MakeFig,
                               show_fig=show_fig)
        except (TypeError, ValueError) as e: 
            _warnings.warn("range is too small to fit, returning NaN", UserWarning)
            val = _uncertainties.ufloat(_np.NaN, _np.NaN)
            return val, val, val, val, val
        OmegaTrap = self.OmegaTrap
        A = self.A
        Gamma = self.Gamma

        omegaArray = 2 * pi * \
            self.freqs[LeftSideOfPeakIndex:RightSideOfPeakIndex]
        PSDArray = self.PSD[LeftSideOfPeakIndex:RightSideOfPeakIndex]

        return OmegaTrap, A, Gamma, fig, ax
def get_fit_from_peak ( self , lowerLimit , upperLimit , NumPointsSmoothing = 1 , silent = False , MakeFig = True , show_fig = True ) : lowerIndex = _np . where ( self . freqs == take_closest ( self . freqs , lowerLimit ) ) [ 0 ] [ 0 ] upperIndex = _np . where ( self . freqs == take_closest ( self . freqs , upperLimit ) ) [ 0 ] [ 0 ] if lowerIndex == upperIndex : _warnings . warn ( "range is too small, returning NaN" , UserWarning ) val = _uncertainties . ufloat ( _np . NaN , _np . NaN ) return val , val , val , val , val MaxPSD = max ( self . PSD [ lowerIndex : upperIndex ] ) centralIndex = _np . where ( self . PSD == MaxPSD ) [ 0 ] [ 0 ] CentralFreq = self . freqs [ centralIndex ] approx_A = MaxPSD * 1e16 MinPSD = min ( self . PSD [ lowerIndex : upperIndex ] ) HalfMax = MinPSD + ( MaxPSD - MinPSD ) / 2 try : LeftSideOfPeakIndex = _np . where ( self . PSD == take_closest ( self . PSD [ lowerIndex : centralIndex ] , HalfMax ) ) [ 0 ] [ 0 ] LeftSideOfPeak = self . freqs [ LeftSideOfPeakIndex ] except IndexError : _warnings . warn ( "range is too small, returning NaN" , UserWarning ) val = _uncertainties . ufloat ( _np . NaN , _np . NaN ) return val , val , val , val , val try : RightSideOfPeakIndex = _np . where ( self . PSD == take_closest ( self . PSD [ centralIndex : upperIndex ] , HalfMax ) ) [ 0 ] [ 0 ] RightSideOfPeak = self . freqs [ RightSideOfPeakIndex ] except IndexError : _warnings . warn ( "range is too small, returning NaN" , UserWarning ) val = _uncertainties . ufloat ( _np . NaN , _np . NaN ) return val , val , val , val , val FWHM = RightSideOfPeak - LeftSideOfPeak approx_Gamma = FWHM / 4 try : A , OmegaTrap , Gamma , fig , ax = self . get_fit ( CentralFreq , ( upperLimit - lowerLimit ) / 2 , A_Initial = approx_A , Gamma_Initial = approx_Gamma , silent = silent , MakeFig = MakeFig , show_fig = show_fig ) except ( TypeError , ValueError ) as e : _warnings . warn ( "range is too small to fit, returning NaN" , UserWarning ) val = _uncertainties . ufloat ( _np . NaN , _np . NaN ) return val , val , val , val , val OmegaTrap = self . OmegaTrap A = self . A Gamma = self . Gamma omegaArray = 2 * pi * self . freqs [ LeftSideOfPeakIndex : RightSideOfPeakIndex ] PSDArray = self . PSD [ LeftSideOfPeakIndex : RightSideOfPeakIndex ] return OmegaTrap , A , Gamma , fig , ax
Finds approximate values for the peaks central frequency, height, 
        and FWHM by looking for the heighest peak in the frequency range defined 
        by the input arguments. It then uses the central frequency as the trapping 
        frequency, peak height to approximate the A value and the FWHM to an approximate
        the Gamma (damping) value.

        Parameters
        ----------
        lowerLimit : float
            The lower frequency limit of the range in which it looks for a peak
        upperLimit : float
            The higher frequency limit of the range in which it looks for a peak
        NumPointsSmoothing : float
            The number of points of moving-average smoothing it applies before fitting the 
            peak.
        Silent : bool, optional
            Whether it prints the values fitted or is silent.
        show_fig : bool, optional
            Whether it makes and shows the figure object or not.

        Returns
        -------
        OmegaTrap : ufloat
            Trapping frequency
        A : ufloat
            A parameter
        Gamma : ufloat
            Gamma, the damping parameter