res_params.add('j', value= 7e-12,min=7e-12,max=5e-6,vary=False) R.subtract('res',min(R.column('res')),header='res.norm') #subtract off the minimum (residual) to help Kondo fit # do fit, here with leastsq model result = minimize(BG, res_params, args=(R.column('T (K)'), R.column('res.norm'))) # calculate final result final = R.column('res.norm') + result.residual + min(R.column('res')) R.add_column(final,column_header='fit') # write error report report_fit(res_params) ### Print output parameters from fit ### print 'K = ' + format_error(res_params['K'].value,res_params['K'].stderr,latex=True) print 'Dt = ' + format_error(res_params['Dt'].value,res_params['Dt'].stderr,latex=True) print 'rho0 = ' + str(min(R.column('res'))) ### Plot resistivity data ### R.template=SPF.JTBPlotStyle R.figure(1) f=plt.gcf() f.set_size_inches((5.5,3.75),forward=True) # Set for A4 - will make wrapper for this someday R.multiply('res',1e8,replace=False,header='res.plot') #Convert to micro Ohm cm R.multiply('fit',1e8,replace=False,header='fit.plot') R.plot_xy('T (K)','res.plot',linestyle='',linewidth=3,marker='o',markersize=5,label=None) R.plot_xy('T (K)','fit.plot',linestyle='-',linewidth=2,marker='',label=None) R.ylabel = r'$\rho\ (\mu\Omega cm)$'
#params.add('Tk', value= 10,min=5,max=50,vary=True) # do fit, here with leastsq model result = minimize(BG, params, args=(R.column('T (K)'), R.column('res'))) # calculate final result final = R.column('res') + result.residual R.add_column(final,column_header='BG') # write error report report_fit(params) print 'K = '+format_error(params['K'].value,params['K'].stderr,latex=True) print 'Dt = '+format_error(params['Dt'].value,params['Dt'].stderr,latex=True) print 'rho0 = '+format_error(params['rho_0'].value,params['rho_0'].stderr,latex=True) ### GET SCATTERING TIME ### rho = R.interpolate(L.column('T')) tsf = L.column('Lam_Cu')**2*rho[:,2]*1.6e-19*1.81e28 tau = workfile() tau.add_column(L.column('T'),'T (K)') tau.add_column(1/tsf,r'1/$\tau_{sf}$') tau_err = (L.column('Lam_err')/L.column('Lam_Cu'))/tsf tau.add_column(tau_err,'1/t_err') ### FIT SCATTERING TIME ###
# And add it to t t.add_column(m, column_header="$m^2$") # Now we can it a straight line t.setas = "x..y" fit = t.lmfit(Linear, result=True, replace=False, header="Fit") g = t["LinearModel:slope"] gerr = t["LinearModel:slope err"] / g g = np.sqrt(1.0 / g) gerr /= 2.0 l = float(d["Lambda"]) th = l / (2 * g) therr = th * (gerr) t.inset(loc="top right", width=0.5, height=0.4) t.plot_xy(r"Fit", r"$sin^2\theta$", "b-", label="Fit") t.plot_xy(r"$m^2$", r"$sin^2\theta$", "ro", label="Peak Position") t.xlabel = "Fringe $m^2$" t.ylabel = r"$sin^2\theta$" t.title = "" t.legend(loc="upper left") t.draw() pyplot.sca(t.axes[0]) # Get the wavelength from the metadata # Calculate thickness and report pyplot.text( 0.05, 0.05, "Thickness is: {} $\AA$".format(format_error(th, therr, latex=True)), transform=main_fig.axes[0].transAxes, )
#Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0]/2.0))**2, 0,header=r"$sin^2\theta$") # Now create the m^2 order m=np.arange(len(t))+fringe_offset m=m**2 #And add it to t t.add_column(m, column_header='$m^2$') #Now we can it a straight line t.setas="x..y" fit=t.lmfit(Linear,result=True,replace=False,header="Fit") g=t["LinearModel:slope"] gerr=t["LinearModel:slope err"]/g g=np.sqrt(1.0/g) gerr/=2.0 l=float(d['Lambda']) th=l/(2*g) therr=th*(gerr) t.inset(loc="top right",width=0.5,height=0.4) t.plot_xy(r"Fit",r"$sin^2\theta$", 'b-',label="Fit") t.plot_xy(r"$m^2$",r"$sin^2\theta$", 'ro',label="Peak Position") t.xlabel="Fringe $m^2$" t.ylabel=r"$sin^2\theta$" t.title="" t.legend(loc="upper left") t.draw() pyplot.sca(t.axes[0]) # Get the wavelength from the metadata # Calculate thickness and report pyplot.text (0.05,0.05, "Thickness is: {} $\AA$".format(format_error(th,therr,latex=True)), transform=main_fig.axes[0].transAxes)
d.show() #Now convert the angle to sin^2 t.apply(lambda x: np.sin(np.radians(x[0]/2.0))**2, 0,header=r"$sin^2\theta$") # Now create the m^2 order m=np.arange(len(t))+1 m=m**2 #And add it to t t.add_column(m, column_header='$m^2$') #Now we can it a straight line t.setas="x.y" p, pcov=t.curve_fit(linear,result=True,replace=False,header="Fit") g=p[1] gerr=np.sqrt(pcov[1,1])/g g=np.sqrt(1.0/g) gerr/=2.0 l=float(d['Lambda']) th=l/(2*g) therr=th*(gerr) t.inset(loc="top right") t.plot_xy(r"Fit",r"$sin^2\theta$", 'b-') t.plot_xy(r"$m^2$",r"$sin^2\theta$", 'ro') t.xlabel="Fringe $m^2$" t.ylabel=r"$sin^2\theta$" t.title=None t.show() pyplot.sca(t.axes[0]) # Get the wavelength from the metadata # Calculate thickness and report pyplot.text (0.05,0.05, "Thickness is: {} $\AA$".format(format_error(th,therr,latex=True)), transform=main_fig.axes[0].transAxes)
"""Scale data to stitch it together.""" from Stoner import Data from Stoner.Util import format_error import matplotlib.pyplot as plt # Load and plot two sets of data s1 = Data("Stitch-scan1.txt", setas="xy") s2 = Data("Stitch-scan2.txt", setas="xy") s1.plot(label="Set 1") s2.fig = s1.fig s2.plot(label="Set 2") # Stitch scan 2 onto scan 1 s2.stitch(s1) s2.plot(label="Stictched") s2.title = "Stictching Example" # Tidy up the plot by adding annotation fo the stirching co-efficients labels = ["A", "B", "C"] txt = [] lead = r"$x'\rightarrow x+A$" + "\n" + r"$y'=\rightarrow By+C$" + "\n" for l, v, e in zip(labels, s2["Stitching Coefficients"], s2["Stitching Coeffient Errors"]): txt.append(format_error(v, e, latex=True, prefix=l + "=")) plt.text(0.7, 0.65, lead + "\n".join(txt), fontdict={"size": "x-small"}) plt.draw()
rho0 = d.min(r_col)[0] A = rho0 * 40 thetaD = 300.0 d.del_rows(0, lambda x, r: any(isnan(r))) popt, pcov = d.curve_fit( lambda T, thetaD, rho0, A: blochGrueneisen(T, thetaD, rho0, A, 5), xcol=t_col, ycol=r_col, p0=[thetaD, rho0, A]) perr = sqrt(diag(pcov)) labels = [r'\theta_D', r'\rho_0', r'A'] annotation = [ "${}$: {}\n".format(l, format_error(v, e, latex=True)) for l, v, e in zip(labels, popt, perr) ] annotation = "\n".join(annotation) popt = append(popt, 5) T = d.column(t_col) d.add_column(blochGrueneisen(T, *popt), column_header=r"Bloch") d.plot_xy(t_col, [r_col, "Bloch"], ["ro", "b-"], label=["Data", r"$Bloch-Gr\"ueisen Fit$"]) d.xlabel = "Temperature (K)" d.ylabel = "Resistance ($\Omega$)" text(0.05, 0.05, annotation, transform=d.axes[0].transAxes)
print("Initial guesses: {}".format(p0)) d.del_rows(0, lambda x, r: np.any(np.isnan(r))) popt, pcov = d.curve_fit(bg_wrapper, xcol=t_col, ycol=r_col, p0=p0, absolute_sigma=False) perr = np.sqrt(np.diag(pcov)) labels = [r"\theta_D", r"\rho_0", r"A"] units = ["K", r"\Omega m", r"\Omega m"] annotation = [ "${}$: {}\n".format(l, format_error(v, e, latex=True, mode="eng", units=u)) for l, v, e, u in zip(labels, popt, perr, units) ] annotation = "\n".join(annotation) popt = np.append(popt, 5) T = d.column(t_col) d.add_column(blochGrueneisen(T, *popt), header=r"Bloch") d.plot_xy( t_col, [r_col, "Bloch"], ["ro", "b-"], label=["Data", r"$Bloch-Gr\"ueisen Fit$"], ) d.xlabel = "Temperature (K)" d.ylabel = "Resistance ($\Omega$)"
d = Analysis.AnalyseFile(tau.clone) d.del_rows('T (K)',lambda x,y:x<100 and x>230) sc_result = minimize(phonon, sc_params, args=(d.column('T (K)'), d.column(r'1/$\tau_{sf}$'))) # calculate final result sc_final = (d.column(r'1/$\tau_{sf}$')) + sc_result.residual d.add_column(sc_final,column_header='fit') # write error report report_fit(sc_params) e_ph = sc_params['epsilon'].value e_ph_err = sc_params['epsilon'].stderr print r'$\epsilon_ph$ = ' + str(e_ph) + '$\pm$' + str(e_ph_err) print format_error(e_ph,e_ph_err,latex=True) e_imp = sc_params['imp'].value*9.1e-31/(8.45e28*(1.6e-19**2)*params['rho_0'].value) e_imp_err = e_imp*numpy.sqrt((sc_params['imp'].stderr/sc_params['imp'].value)**2 + (params['rho_0'].stderr/params['rho_0'].value)**2) print r'$\epsilon_imp$ = ' + str(e_imp) + '$\pm$' + str(e_imp_err) print format_error(e_imp,e_imp_err,latex=True) ################ PLOT SCATTERING DATA ####################### fit=SP.PlotFile(d.clone) fit.template=SPF.JTBPlotStyle t=SP.PlotFile(tau.clone) t.template=SPF.JTBPlotStyle BG=SP.PlotFile(R.clone) BG.template=SPF.JTBPlotStyle fit.figure()
else: t_col=t_col[0] r_col=d.find_col(r_pat) if len(r_col)!=1: raise KeyError("More than one column that might match temperaature found!") else: r_col=r_col[0] rho0=d.min(r_col)[0] A=rho0*40 thetaD=300.0 d.del_rows(0,lambda x,r:any(isnan(r))) popt,pcov=d.curve_fit(lambda T,thetaD,rho0,A:blochGrueneisen(T,thetaD,rho0,A,5),xcol=t_col,ycol=r_col,p0=[thetaD,rho0,A]) perr=sqrt(diag(pcov)) labels=[r'\theta_D',r'\rho_0',r'A'] annotation=["${}$: {}\n".format(l,format_error(v,e,latex=True)) for l,v,e in zip(labels,popt,perr)] annotation="\n".join(annotation) popt=append(popt,5) T=d.column(t_col) d.add_column(blochGrueneisen(T,*popt),column_header=r"Bloch") d.plot_xy(t_col,[r_col,"Bloch"],["ro","b-"],label=["Data",r"$Bloch-Gr\"ueisen Fit$"]) d.xlabel="Temperature (K)" d.ylabel="Resistance ($\Omega$)" text(0.05,0.05,annotation,transform=d.axes[0].transAxes)
"""Scale data to stitch it together.""" from Stoner import Data from Stoner.Util import format_error import matplotlib.pyplot as plt # Load and plot two sets of data s1 = Data("Stitch-scan1.txt", setas="xy") s2 = Data("Stitch-scan2.txt", setas="xy") s1.plot(label="Set 1") s2.fig = s1.fig s2.plot(label="Set 2") # Stitch scan 2 onto scan 1 s2.stitch(s1) s2.plot(label="Stictched") s2.title = "Stictching Example" # Tidy up the plot by adding annotation fo the stirching co-efficients labels = ["A", "B", "C"] txt = [] lead = r"$x'\rightarrow x+A$" + "\n" + r"$y'=\rightarrow By+C$" + "\n" for l, v, e in zip( labels, s2["Stitching Coefficients"], s2["Stitching Coeffient Errors"] ): txt.append(format_error(v, e, latex=True, prefix=l + "=")) plt.text(0.7, 0.65, lead + "\n".join(txt), fontdict={"size": "x-small"}) plt.draw()