<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fit_autocorrelation(autocorrelation, time, GammaGuess, TrapFreqGuess=None, method='energy', MakeFig=True, show_fig=True):
 """ Fits exponential relaxation theory to data. Parameters autocorrelation : array array containing autocorrelation to be fitted time : array array containing the time of each point the autocorrelation was evaluated GammaGuess : float The approximate Big Gamma (in radians) to use initially TrapFreqGuess : float The approximate trapping frequency to use initially in Hz. method : string, optional To choose which autocorrelation fit is needed. 'position' : equation 4.20 from Tongcang Li's 2013 thesis (DOI: 10.1007/978-1-4614-6031-2) 'energy' : proper exponential energy correlation decay (DOI: 10.1103/PhysRevE.94.062151) MakeFig : bool, optional Whether to construct and return the figure object showing the fitting. defaults to True show_fig : bool, optional Whether to show the figure object when it has been created. defaults to True Returns ------- ParamsFit - Fitted parameters: 'variance'-method : [Gamma] 'position'-method : [Gamma, AngularTrappingFrequency] ParamsFitErr - Error in fitted parameters: 'varaince'-method : [GammaErr] 'position'-method : [GammaErr, AngularTrappingFrequencyErr] fig : matplotlib.figure.Figure object figure object containing the plot ax : matplotlib.axes.Axes object axes with the data plotted of the: - initial data - final fit """

    datax = time
    datay = autocorrelation

    method = method.lower()
    if method == 'energy':
        p0 = _np.array([GammaGuess])

        Params_Fit, Params_Fit_Err = fit_curvefit(p0,
                                                  datax,
                                                  datay,
                                                  _energy_autocorrelation_fitting_eqn)
        autocorrelation_fit = _energy_autocorrelation_fitting_eqn(_np.arange(0,datax[-1],1e-7),
                                                                  Params_Fit[0])
    elif method == 'position':
        AngTrapFreqGuess = 2 * _np.pi * TrapFreqGuess
        p0 = _np.array([GammaGuess, AngTrapFreqGuess])
        Params_Fit, Params_Fit_Err = fit_curvefit(p0,
                                                  datax,
                                                  datay,
                                                  _position_autocorrelation_fitting_eqn)
        autocorrelation_fit = _position_autocorrelation_fitting_eqn(_np.arange(0,datax[-1],1e-7),
                                                                    Params_Fit[0],
                                                                    Params_Fit[1])
        
    if MakeFig == True:
        fig = _plt.figure(figsize=properties["default_fig_size"])
        ax = fig.add_subplot(111)
        ax.plot(datax*1e6, datay,
                '.', color="darkblue", label="Autocorrelation Data", alpha=0.5)
        ax.plot(_np.arange(0,datax[-1],1e-7)*1e6, autocorrelation_fit,
                color="red", label="fit")
        ax.set_xlim([0,
                     30e6/Params_Fit[0]/(2*_np.pi)])
        legend = ax.legend(loc="best", frameon = 1)
        frame = legend.get_frame()
        frame.set_facecolor('white')
        frame.set_edgecolor('white')
        ax.set_xlabel("time (us)")
        ax.set_ylabel(r"$\left | \frac{\langle x(t)x(t+\tau) \rangle}{\langle x(t)x(t) \rangle} \right |$")
        if show_fig == True:
            _plt.show()
        return Params_Fit, Params_Fit_Err, fig, ax
    else:
        return Params_Fit, Params_Fit_Err, None, None