def get_full_errors(f_data,z_data,a,alpha,delay,results): ''' calculates the statistical error for all variables "results" is the dictionary returned by the circlefit routine returns a dictionary with the errors and None if something went wrong ''' fr,absQc,Qr,phi0 = results["fr"], results["absQc"], results["Qr"], results["phi0"] p= fr,absQc,Qr,phi0,delay,a,alpha chi_square, cov = rt.get_cov(rt.residuals_notch_full,f_data,z_data,p) errors = None if cov!=None: errors = [np.sqrt(cov[i][i]) for i in range(len(cov))] fr_err,absQc_err,Qr_err,phi0_err, delay_err, a_err, alpha_err = errors #calc Qi with error prop (sum the squares of the variances and covariaces) dQr = 1./((1./Qr-1./absQc)**2*Qr**2) dabsQc = - 1./((1./Qr-1./absQc)**2*absQc**2) Qi_no_corr_err = np.sqrt((dQr**2*cov[2][2]) + (dabsQc**2*cov[1][1])+(2*dQr*dabsQc*cov[2][1])) #calc Qi dia corr with error prop dQr = 1/((1/Qr-np.cos(phi0)/absQc)**2 *Qr**2) dabsQc = -np.cos(phi0)/((1/Qr-np.cos(phi0)/absQc)**2 *absQc**2) dphi0 = -np.sin(phi0)/((1/Qr-np.cos(phi0)/absQc)**2 *absQc) err1 = ( (dQr**2*cov[2][2]) + (dabsQc**2*cov[1][1]) + (dphi0**2*cov[3][3]) ) err2 = ( dQr*dabsQc*cov[2][1] + dQr*dphi0*cov[2][3] + dabsQc*dphi0*cov[1][3] ) Qi_dia_corr_err = np.sqrt(err1+2*err2) errors = {"phi0_err":phi0_err, "Qr_err":Qr_err, "absQc_err":absQc_err, "fr_err":fr_err,"chi_square":chi_square,"Qi_no_corr_err":Qi_no_corr_err,"Qi_dia_corr_err": Qi_dia_corr_err, "a_err":a_err,"alpha_err":alpha_err,"delay_err":delay_err} else: print "WARNING: Error calculation failed!" return errors
def transmissionfit(f_data,z_data,fr,Qr): #not tested ''' phasefit enhanced by circlefit method ''' xc, yc, r0 = rt.fit_circle(z_data) zc = np.complex(xc,yc) fitparams = rt.phase_fit_nooffset(f_data,rt.center(z_data,zc),Qr,fr) Qr, fr = fitparams[0] results = {"Qr":Qr,"fr":fr} p = fr, Qr chi_square, cov = rt.get_cov(rt.residuals_transm_ideal,f_data,z_data,p) if cov!=None: errors = [np.sqrt(cov[i][i]) for i in range(len(cov))] results.update({"fr_err":errors[0],"Qr_err":errors[1],"chi_square":chi_square}) return results