def flux_par(self): flux_over_flux0 = qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=self.offset, flux_factor=self.flux_factor) Ej = qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) return qdt._get_fq(Ej, qdt.Ec)
def flux_par2(self, offset, flux_factor, Ejmax): set_all_tags(qdt, log=False) flux_o_flux0=qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=offset, flux_factor=flux_factor) Ej=qdt.call_func("Ej", flux_over_flux0=flux_o_flux0, Ejmax=Ejmax) EjdivEc=Ej/qdt.Ec fq_vec=qdt.call_func("fq", Ej=EjdivEc*qdt.Ec) results=[] for fq in fq_vec: def Ba_eqn(x): return x[0]**2+2.0*x[0]*qdt.call_func("calc_Lamb_shift", fqq=x[0])-fq**2 results.append(fsolve(Ba_eqn, fq)) return squeeze(results)/1e9
def magabs_colormesh(): flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=a.yoko, offset=c.offset, flux_factor=c.flux_factor) b.colormesh("magabs", flux_over_flux0, a.frequency*1e-9, a.MagAbs) #b.line_plot("flux_parabola", flux_over_flux0, c.flux_parabola, color="orange", alpha=0.4) #b.set_ylim(4.4e9, 4.5e9) b.xlabel="Yoko (V)" b.ylabel="Frequency (Hz)" b.title="Reflection fluxmap"
def magabs_colormesh(): flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=a.yoko, offset=c.offset, flux_factor=c.flux_factor) b.colormesh("magabs", a.time*1e6, flux_over_flux0, a.MagAbs) #b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) #b.set_ylim(4.4e9, 4.5e9) b.xlabel="Time (us)" b.ylabel="Magnitude (abs)" b.title="Reflection vs time"
def magabs_colormesh(pwi=0): a.pind=pwi flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=a.yoko, offset=c.offset, flux_factor=c.flux_factor) b.colormesh("magabs", a.time*1e6, flux_over_flux0, a.MagAbs) #b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) #b.set_ylim(4.4e9, 4.5e9) b.xlabel="Time (us)" b.ylabel="Magnitude (abs)" b.title="Reflection vs time"
def magabs_colormesh(): flux_over_flux0 = qdt.call_func("flux_over_flux0", voltage=a.yoko, offset=c.offset, flux_factor=c.flux_factor) b.colormesh("magabs", flux_over_flux0, a.frequency * 1e-9, a.MagAbs) #b.line_plot("flux_parabola", flux_over_flux0, c.flux_parabola, color="orange", alpha=0.4) #b.set_ylim(4.4e9, 4.5e9) b.xlabel = "Yoko (V)" b.ylabel = "Frequency (Hz)" b.title = "Reflection fluxmap"
def magabs_colormesh(self, offset=-0.08, flux_factor=0.52, Ejmax=h * 44.0e9, f0=5.35e9, alpha=0.7, pl=None): fq_vec = array([ sqrt(f * (f + alpha * calc_freq_shift(f, qdt.ft, qdt.Np, f0, qdt.epsinf, qdt.W, qdt.Dvv))) for f in self.frequency ]) freq, frq2 = flux_parabola(self.yoko, offset, 0.16, Ejmax, qdt.Ec) pl = Plotter(fig_width=9.0, fig_height=6.0, name="magabs_{}".format(self.name)) pl, pf = colormesh(freq, fq_vec, (self.MagdB.transpose() - self.MagdB[:, 0]).transpose(), plotter=pl) pf.set_clim(-0.3, 0.1) line([min(freq), max(freq)], [min(freq), max(freq)], plotter=pl) flux_o_flux0 = flux_over_flux0(self.yoko, offset, flux_factor) qEj = Ej(Ejmax, flux_o_flux0) EjdivEc = qEj / qdt.Ec ls_fq = qdt.call_func("lamb_shifted_fq", EjdivEc=EjdivEc) ls_fq2 = qdt.call_func("lamb_shifted_fq2", EjdivEc=EjdivEc) frq2 = qdt.call_func("lamb_shifted_anharm", EjdivEc=EjdivEc) / h line(ls_fq, ls_fq2, plotter=pl) #pl.set_xlim(min(self.frequency/1e9), max(self.frequency/1e9)) #pl.set_ylim(min(self.yoko), max(self.yoko)) pl.ylabel = "Yoko (V)" pl.xlabel = "Frequency (GHz)" return pl
def magabs_colormesh(self, offset=-0.08, flux_factor=0.52, Ejmax=h*44.0e9, f0=5.35e9, alpha=0.7, pl=None): fq_vec=array([sqrt(f*(f+alpha*calc_freq_shift(f, qdt.ft, qdt.Np, f0, qdt.epsinf, qdt.W, qdt.Dvv))) for f in self.frequency]) freq, frq2=flux_parabola(self.yoko, offset, 0.16, Ejmax, qdt.Ec) pl=Plotter(fig_width=9.0, fig_height=6.0, name="magabs_{}".format(self.name)) pl, pf=colormesh(freq, fq_vec, (self.MagdB.transpose()-self.MagdB[:, 0]).transpose(), plotter=pl) pf.set_clim(-0.3, 0.1) line([min(freq), max(freq)], [min(freq), max(freq)], plotter=pl) flux_o_flux0=flux_over_flux0(self.yoko, offset, flux_factor) qEj=Ej(Ejmax, flux_o_flux0) EjdivEc=qEj/qdt.Ec ls_fq=qdt.call_func("lamb_shifted_fq", EjdivEc=EjdivEc) ls_fq2=qdt.call_func("lamb_shifted_fq2", EjdivEc=EjdivEc) frq2=qdt.call_func("lamb_shifted_anharm", EjdivEc=EjdivEc)/h line(ls_fq, ls_fq2, plotter=pl) #pl.set_xlim(min(self.frequency/1e9), max(self.frequency/1e9)) #pl.set_ylim(min(self.yoko), max(self.yoko)) pl.ylabel="Yoko (V)" pl.xlabel="Frequency (GHz)" return pl
def flux_par(self, offset, flux_factor, Ejmax): set_all_tags(qdt, log=False) # set_tag(qdt, "EjdivEc", log=False) # set_tag(qdt, "Ej", log=False) # set_tag(qdt, "offset", log=False) # set_tag(qdt, "flux_factor", log=False) flux_o_flux0=qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=offset, flux_factor=flux_factor) Ej=qdt.call_func("Ej", flux_over_flux0=flux_o_flux0, Ejmax=Ejmax) EjdivEc=Ej/qdt.Ec fq=qdt.call_func("fq", Ej=EjdivEc*qdt.Ec) ls=qdt.call_func("calc_Lamb_shift", fqq=fq) return fq/1e9 ls_fq=qdt.call_func("lamb_shifted_fq", EjdivEc=EjdivEc) ls_fq2=qdt.call_func("lamb_shifted_fq2", EjdivEc=EjdivEc) return ls_fq/1e9#, ls_fq2/1e9
def Ba_eqn(x): return x[0]**2+2.0*x[0]*qdt.call_func("calc_Lamb_shift", fqq=x[0])-fq**2
def magabs_cs_fit(): def lorentzian(x,p): return p[2]*(1.0-1.0/(1.0+((x-p[1])/p[0])**2))+p[3] def fano(x, p): return p[2]*(((p[4]*p[0]+x-p[1])**2)/(p[0]**2+(x-p[1])**2))+p[3] def refl_fano(x, p): return p[2]*(1.0-((p[4]*p[0]+x-p[1])**2)/(p[0]**2+(x-p[1])**2))+p[3] def onebounce(x,p): w=2*pi*x k=2.0*pi*x/3488.0 Cc=0.0 D=500.0e-6 D1=300.0e-6 D2=200.0e-6 S12q=((p[4]*p[0]/6.28+(x-p[1])*2*pi)**2)/(p[0]**2+(p[4]*p[0]/6.28+x-p[1])**2) S11q=1.0/(p[0]**2+(p[4]*p[0]/6.28+x-p[1])**2) S11=p[5] return p[2]*absolute(exp(1.0j*k*D)*S12q*(1+exp(2.0j*k*D1)*S11q*S11+exp(2.0j*k*D2)*S11q*S11+ exp(2.0j*k*D)*S11**2*S12q**2)+2.0j*w*Cc*50.0)**2+p[3] def allbounces(x,p): w=2*pi*x k=2.0*pi*x/3488.0 Cc=0.0 D=500.0e-6 D1=300.0e-6 D2=200.0e-6 return p[2]*absolute(exp(1.0j*k*D)*S12q*(-2.0 +1.0/(1.0-exp(2.0j*k*D1)*S11q*S11) +1.0/(1.0- exp(2.0j*k*D2)*S11q*S11) +1.0/(1- exp(2.0j*k*D)*S11**2*S12q**2)) +2.0j*w*Cc*50.0) def residuals(p,y,x): err = y - lorentzian(x,p) return err def residuals2(p,y,x): return y - fano(x,p) def residuals3(p,y,x): return y - refl_fano(x,p) p = [200e6,4.5e9, 0.002, 0.022, 0.1, 0.1] indices=[range(81, 120+1), range(137, 260+1), range(269, 320+1), range(411, 449+1)]#, [490]]#, [186]] indices=[range(len(a.frequency))] widths=[] freqs=[] freq_diffs=[] fanof=[] filt=[] for n in range(len(yok)): myifft=fft.ifft(mag[:,n]) #b.line_plot("ifft", absolute(myifft)) myifft[50:-50]=0.0 #myifft[:20]=0.0 #myifft[-20:]=0.0 filt.append(absolute(fft.fft(myifft))**2) filt=array(filt).transpose() for ind_list in indices: for n in ind_list: pbest = leastsq(residuals3, p, args=(a.MagAbs[n, :], c.flux_parabola[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0:#n % 8==0: bb.scatter_plot("magabs_flux", c.flux_parabola[:]*1e-9, a.MagAbs[n, :], label="{}".format(n), linewidth=0.2, marker_size=0.8) bb.line_plot("lorentzian", c.flux_parabola*1e-9, refl_fano(c.flux_parabola,best_parameters), label="fit {}".format(n), linewidth=0.5) if 1:#absolute(best_parameters[1]-a.frequency[n])<2e8: freqs.append(a.frequency[n]) freq_diffs.append(absolute(best_parameters[1]-a.frequency[n])) widths.append(absolute(best_parameters[0])) fanof.append(absolute(best_parameters[4])) if 1: widths2=[] freqs2=[] freq_diffs2=[] fano2=[] flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=yok, offset=-0.037, flux_factor=0.2925) Ej=qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) flux_par=qdt._get_fq(Ej, qdt.Ec) magabs=absolute(mag)**2 for n in range(len(frq)): pbest = leastsq(residuals2,p,args=(filt[n, :], flux_par[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0:#n==539 or n==554:#n % 10: b.line_plot("magabs_flux", flux_par*1e-9, (magabs[n, :]-best_parameters[3])/best_parameters[2], label="{}".format(n), linewidth=0.2) b.line_plot("lorentzian", flux_par*1e-9, fano(flux_par,best_parameters), label="fit {}".format(n), linewidth=0.5) if 1:#absolute(best_parameters[1]-frq[n])<1.5e8: freqs2.append(frq[n]) freq_diffs2.append(absolute(best_parameters[1]-frq[n])) widths2.append(absolute(best_parameters[0])) fano2.append(absolute(best_parameters[4])) b.line_plot("widths", freqs, widths, label="-110 dBm") b.scatter_plot("widths2", freqs2, widths2, color="red", label="-130 dBm") vf=3488.0 p=[1.0001, 0.5, 0.3, 1.0e-15, 0.001] Np=9 K2=0.048 f0=5.348e9 def fourier(x, p): w=2*pi*x k=2.0*pi*x/3488.0 D=500.0e-6 D1=300.0e-6 D2=200.0e-6 G_f=0.5*Np*K2*f0*(sin(Np*pi*(x-f0)/f0)/(Np*pi*(x-f0)/f0))**2 return G_f*absolute(exp(1.0j*k*D)*p[0]*(1+exp(2.0j*k*D1)*(p[1]+1.0j*p[2])+exp(2.0j*k*D2)*(p[1]+1.0j*p[2])) +2.0j*w*p[3]*50.0)+p[4] #exp(2.0j*k*D)*(p[1]+1.0j*p[2]))+ def resid(p,y,x): #return y - onebounce(x,p) return y - fourier(x,p) #pbest=leastsq(resid, p, args=(absolute(widths2[318:876]), frq[318:876]), full_output=1) #print pbest[0] #b.line_plot("fourier", frq, fourier(frq, pbest[0])) #pi*vf/2*x=D from scipy.signal import lombscargle #lombscargle(freqs2[318:876], widths2[318:876]) #bb.line_plot("fft", #frq[318:876]*fft.fftfreq(len(frq[318:876]), d=frq[1]-frq[0]), #absolute(fft.fft(widths2[318:876]))) frqdiffs=linspace(0.01, 500e6, 1000) #bb.line_plot("ls", frqdiffs, lombscargle(array(freqs2[285:828]), array(widths2[285:828]), frqdiffs )) #bb.line_plot("ls", frqdiffs, lombscargle(array(freqs[318:876]), array(widths[318:876]), frqdiffs)) bb.line_plot("fft2", absolute(fft.ifft(widths2[285:828]))) bb.line_plot("fft", absolute(fft.ifft(widths[285:828]))) bbb=Plotter() #bbb.scatter_plot("wid", freqs2, widths2) myifft=fft.ifft(widths2[285:828]) myifft[12:-12]=0.0 bbb.line_plot("ff", freqs2[285:828], absolute(fft.fft(myifft)))
def flux_par3(self, offset=-0.08, flux_factor=0.52, Ejmax=h*44.0e9, f0=5.35e9, alpha=0.7, pl=None): set_all_tags(qdt, log=False) flux_o_flux0=qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=offset, flux_factor=flux_factor) #print flux_o_flux0-pi/2*trunc(flux_o_flux0/(pi/2.0)) #Ej=qdt.call_func("Ej", flux_over_flux0=flux_o_flux0, Ejmax=Ejmax) #EjdivEc=Ej/qdt.Ec fq_vec=array([sqrt(f*(f+1.0*qdt.call_func("calc_Lamb_shift", fqq=f))) for f in self.frequency]) fq_vec=array([f-qdt.call_func("calc_Lamb_shift", fqq=f) for f in self.frequency]) fq_vec=array([sqrt(f*(f+alpha*calc_freq_shift(f, qdt.ft, qdt.Np, f0, qdt.epsinf, qdt.W, qdt.Dvv))) for f in self.frequency]) Ej=Ej_from_fq(fq_vec, qdt.Ec) flux_d_flux0=arccos(Ej/Ejmax)#-pi/2 flux_d_flux0=append(flux_d_flux0, -arccos(Ej/Ejmax)) flux_d_flux0=append(flux_d_flux0, -arccos(Ej/Ejmax)+pi) flux_d_flux0=append(flux_d_flux0, arccos(Ej/Ejmax)-pi) if pl is not None: volt=voltage_from_flux(flux_d_flux0, offset, flux_factor) freq=s3a4_wg.frequency[:]/1e9 freq=append(freq, freq) #append(freq, append(freq, freq))) freq=append(freq, freq) #freq=append(freq, freq) line(freq, volt, plotter=pl, linewidth=1.0, alpha=0.5) Ejdivh=Ej/h w0=4*Ejdivh*(1-sqrt(1-fq_vec/(2*Ejdivh))) EjdivEc=Ej/qdt.Ec #print -(w0**2)/(8*Ejdivh) ls_fq2=qdt.call_func("lamb_shifted_fq2", EjdivEc=EjdivEc) E0, E1, E2=qdt.call_func("transmon_energy_levels", EjdivEc=EjdivEc, n_energy=3) fq2=(E2-E1)/h f_vec=lamb_shifted_anharm(EjdivEc, qdt.ft, qdt.Np, qdt.f0, qdt.epsinf, qdt.W, qdt.Dvv) print f_vec/h ah=-ls_fq2/2#-fq2) #fq_vec=array([sqrt((f-ah[n])*(f-ah[n]+alpha*calc_freq_shift(f-ah[n], qdt.ft, qdt.Np, f0, qdt.epsinf, qdt.W, qdt.Dvv))) for n, f in enumerate(self.frequency)]) fq_vec=array([f/2-qdt.call_func("calc_Lamb_shift", fqq=f/2) for f in self.frequency]) coup=qdt.call_func("calc_coupling", fqq=self.frequency) print coup volt=array([ voltage_from_flux(arccos(Ej_from_fq(f-f_vec[c]/h/2, qdt.Ec)/Ejmax), offset, flux_factor) for c,f in enumerate(self.frequency)]) #freq=nan_to_num(freq)/1e9 #print freq freq=s3a4_wg.frequency[:]/1e9 #freq=(s3a4_wg.frequency[:]+coup)/1e9 #freq=append(freq, freq) #freq=append(freq, freq) #Ej=Ej_from_fq(fq_vec, f_vec/h) #flux_d_flux0=arccos(Ej/Ejmax)#-pi/2 #flux_d_flux0=append(flux_d_flux0, -arccos(Ej/Ejmax)) #flux_d_flux0=append(flux_d_flux0, -arccos(Ej/Ejmax)+pi) #flux_d_flux0=append(flux_d_flux0, arccos(Ej/Ejmax)-pi) #freq=append(freq, freq) #fq_vec+=f_vec/h/2 #fq2_vec=fq2(Ej, qdt.Ec) #Ej=Ej_from_fq(fq_vec, qdt.Ec) #qdt.call_func("lamb_shifted_fq2", EjdivEc=EjdivEc) #Ej=Ej_from_fq(fq_vec, qdt.Ec) #flux_d_flux0=arccos(Ej/Ejmax)#-pi/2 #flux_d_flux0=append(flux_d_flux0, -arccos(Ej/Ejmax)) #volt=voltage_from_flux(flux_d_flux0, offset, flux_factor) line(freq, volt, plotter=pl, plot_name="second", color="green", linewidth=1.0, alpha=0.5) #flux_d_flux0.append(-) return voltage_from_flux(flux_d_flux0, offset, flux_factor)
def flux_parabola(self): flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=self.yoko, offset=self.offset, flux_factor=self.flux_factor) Ej=qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) return qdt._get_fq(Ej, qdt.Ec)
def flux_parabola(self): return qdt.call_func("flux_parabola", voltage=a.yoko, offset=self.offset, flux_factor=self.flux_factor, Ec=qdt.Ec)
def magabs_cs_fit(): def lorentzian(x,p): return p[2]*(1.0-1.0/(1.0+((x-p[1])/p[0])**2))+p[3] def lorentzian2(x, p): return p[2]*(((p[4]*p[0]+x-p[1])**2)/(p[0]**2+(x-p[1])**2))+p[3] def lorentzian3(x, p): return p[2]*(((p[4]*p[0]/6.28+(x-p[1])*2*pi)**2)/(p[0]**2+(p[4]*p[0]/6.28+x-p[1])**2))+p[3] #return p[2]*(((p[4]*p[0]/6.28+(x-p[1])*2*pi)**2)/(p[0]**2+(p[4]*p[0]/6.28+x-p[1])**2))+p[3] def onebounce(x,p): w=2*pi*x k=2.0*pi*x/3488.0 Cc=0.0 D=500.0e-6 D1=300.0e-6 D2=200.0e-6 S12q=((p[4]*p[0]/6.28+(x-p[1])*2*pi)**2)/(p[0]**2+(p[4]*p[0]/6.28+x-p[1])**2) S11q=1.0/(p[0]**2+(p[4]*p[0]/6.28+x-p[1])**2) S11=p[5] return p[2]*absolute(exp(1.0j*k*D)*S12q*(1+exp(2.0j*k*D1)*S11q*S11+exp(2.0j*k*D2)*S11q*S11+ exp(2.0j*k*D)*S11**2*S12q**2)+2.0j*w*Cc*50.0)**2+p[3] def allbounces(x,p): w=2*pi*x k=2.0*pi*x/3488.0 Cc=0.0 D=500.0e-6 D1=300.0e-6 D2=200.0e-6 return p[2]*absolute(exp(1.0j*k*D)*S12q*(-2.0 +1.0/(1.0-exp(2.0j*k*D1)*S11q*S11) +1.0/(1.0- exp(2.0j*k*D2)*S11q*S11) +1.0/(1- exp(2.0j*k*D)*S11**2*S12q**2)) +2.0j*w*Cc*50.0) def residuals(p,y,x): err = y - lorentzian(x,p) return err def residuals2(p,y,x): return y - lorentzian2(x,p) def residuals3(p,y,x): #return y - onebounce(x,p) return y - lorentzian3(x,p) p = [200e6,4.5e9, 0.002, 0.022, 0.1, 0.1] indices=[range(81, 120+1), range(137, 260+1), range(269, 320+1), range(411, 449+1)]#, [490]]#, [186]] widths=[] freqs=[] freq_diffs=[] fano=[] for ind_list in indices: for n in ind_list: pbest = leastsq(residuals3, p, args=(a.MagAbs[n, :], c.flux_parabola[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0: #n % 10==0: b.scatter_plot("magabs_flux", c.flux_parabola[:]*1e-9, a.MagAbs[n, :], label="{}".format(n), linewidth=0.2, marker_size=0.8) b.line_plot("lorentzian", c.flux_parabola*1e-9, lorentzian3(c.flux_parabola,best_parameters), label="fit {}".format(n), linewidth=0.5) if 1:#absolute(best_parameters[1]-a.frequency[n])<2e8: freqs.append(a.frequency[n]) freq_diffs.append(absolute(best_parameters[1]-a.frequency[n])) widths.append(absolute(best_parameters[0])) fano.append(absolute(best_parameters[4])) if 1: widths2=[] freqs2=[] freq_diffs2=[] fano2=[] flux_over_flux0=qdt.call_func("flux_over_flux0", voltage=yok, offset=-0.037, flux_factor=0.2925) Ej=qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) flux_par=qdt._get_fq(Ej, qdt.Ec) magabs=absolute(mag)**2 for n in range(len(frq)): pbest = leastsq(residuals3,p,args=(magabs[n, :], flux_par[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0:#n==539 or n==554:#n % 10: b.line_plot("magabs_flux", flux_par*1e-9, (magabs[n, :]-best_parameters[3])/best_parameters[2], label="{}".format(n), linewidth=0.2) #b.line_plot("lorentzian", flux_par*1e-9, lorentzian3(flux_par,best_parameters), label="fit {}".format(n), linewidth=0.5) if 1:#absolute(best_parameters[1]-frq[n])<1.5e8: freqs2.append(frq[n]) freq_diffs2.append(absolute(best_parameters[1]-frq[n])) widths2.append(absolute(best_parameters[0])) fano2.append(absolute(best_parameters[4])) b.scatter_plot("widths", freqs, widths, label="-110 dBm") b.scatter_plot("widths2", freqs2, widths2, color="red", label="-130 dBm") vf=3488.0 p=[1.0001, 0.5, 0.3, 1.0e-15, 0.001] Np=9 K2=0.048 f0=5.348e9 def fourier(x, p): w=2*pi*x k=2.0*pi*x/3488.0 D=500.0e-6 D1=300.0e-6 D2=200.0e-6 G_f=0.5*Np*K2*f0*(sin(Np*pi*(x-f0)/f0)/(Np*pi*(x-f0)/f0))**2 return G_f*absolute(exp(1.0j*k*D)*p[0]*(1+exp(2.0j*k*D1)*(p[1]+1.0j*p[2])+exp(2.0j*k*D2)*(p[1]+1.0j*p[2])) +2.0j*w*p[3]*50.0)+p[4] #exp(2.0j*k*D)*(p[1]+1.0j*p[2]))+ def resid(p,y,x): #return y - onebounce(x,p) return y - fourier(x,p) pbest=leastsq(resid, p, args=(absolute(widths2[318:876]), frq[318:876]), full_output=1) print pbest[0] b.line_plot("fourier", frq, fourier(frq, pbest[0])) #pi*vf/2*x=D #b.line_plot("fft", #frq[318:876]*fft.fftfreq(len(frq[318:876]), d=frq[1]-frq[0]), #absolute(fft.fft(widths2[318:876]))) #b.line_plot("fano", freqs, fano) #b.line_plot("fano", freqs2, fano2) #f0=5.37e9 freq=linspace(4e9, 5e9, 1000) #G_f=0.5*Np*K2*f0*(sin(Np*pi*(freq-f0)/f0)/(Np*sin(pi*(freq-f0)/f0)))**2 #b.scatter_plot("freq_test", freqs, freq_diffs) class Fitter3(Operative): base_name="fitter" mult=FloatRange(0.001, 5.0, 0.82).tag(tracking=True) f0=FloatRange(4.0, 6.0, 5.348).tag(tracking=True) offset=FloatRange(0.0, 100.0, 18.0).tag(tracking=True) @tag_Property(plot=True, private=True) def G_f(self): f0=self.f0*1.0e9 return self.offset*1e6+self.mult*0.5*Np*K2*f0*(sin(Np*pi*(freq-f0)/f0)/(Np*pi*(freq-f0)/f0))**2 @observe("f0", "mult", "offset") def update_plot(self, change): if change["type"]=="update": self.get_member("G_f").reset(self) b.plot_dict["G_f"].clt.set_ydata(self.G_f) b.draw() d=Fitter3() b.line_plot("G_f", freq, d.G_f, label="theory")
def magabs_cs_fit(): def lorentzian(x, p): return p[2] * (1.0 - 1.0 / (1.0 + ((x - p[1]) / p[0])**2)) + p[3] def fano(x, p): return p[2] * (((p[4] * p[0] + x - p[1])**2) / (p[0]**2 + (x - p[1])**2)) + p[3] def refl_fano(x, p): return p[2] * (1.0 - ((p[4] * p[0] + x - p[1])**2) / (p[0]**2 + (x - p[1])**2)) + p[3] def onebounce(x, p): w = 2 * pi * x k = 2.0 * pi * x / 3488.0 Cc = 0.0 D = 500.0e-6 D1 = 300.0e-6 D2 = 200.0e-6 S12q = ((p[4] * p[0] / 6.28 + (x - p[1]) * 2 * pi)** 2) / (p[0]**2 + (p[4] * p[0] / 6.28 + x - p[1])**2) S11q = 1.0 / (p[0]**2 + (p[4] * p[0] / 6.28 + x - p[1])**2) S11 = p[5] return p[2] * absolute( exp(1.0j * k * D) * S12q * (1 + exp(2.0j * k * D1) * S11q * S11 + exp(2.0j * k * D2) * S11q * S11 + exp(2.0j * k * D) * S11**2 * S12q**2) + 2.0j * w * Cc * 50.0)**2 + p[3] def allbounces(x, p): w = 2 * pi * x k = 2.0 * pi * x / 3488.0 Cc = 0.0 D = 500.0e-6 D1 = 300.0e-6 D2 = 200.0e-6 return p[2] * absolute( exp(1.0j * k * D) * S12q * (-2.0 + 1.0 / (1.0 - exp(2.0j * k * D1) * S11q * S11) + 1.0 / (1.0 - exp(2.0j * k * D2) * S11q * S11) + 1.0 / (1 - exp(2.0j * k * D) * S11**2 * S12q**2)) + 2.0j * w * Cc * 50.0) def residuals(p, y, x): err = y - lorentzian(x, p) return err def residuals2(p, y, x): return y - fano(x, p) def residuals3(p, y, x): return y - refl_fano(x, p) p = [200e6, 4.5e9, 0.002, 0.022, 0.1, 0.1] indices = [ range(81, 120 + 1), range(137, 260 + 1), range(269, 320 + 1), range(411, 449 + 1) ] #, [490]]#, [186]] indices = [range(len(a.frequency))] widths = [] freqs = [] freq_diffs = [] fanof = [] filt = [] for n in range(len(yok)): myifft = fft.ifft(mag[:, n]) #b.line_plot("ifft", absolute(myifft)) myifft[50:-50] = 0.0 #myifft[:20]=0.0 #myifft[-20:]=0.0 filt.append(absolute(fft.fft(myifft))**2) filt = array(filt).transpose() for ind_list in indices: for n in ind_list: pbest = leastsq(residuals3, p, args=(a.MagAbs[n, :], c.flux_parabola[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0: #n % 8==0: bb.scatter_plot("magabs_flux", c.flux_parabola[:] * 1e-9, a.MagAbs[n, :], label="{}".format(n), linewidth=0.2, marker_size=0.8) bb.line_plot("lorentzian", c.flux_parabola * 1e-9, refl_fano(c.flux_parabola, best_parameters), label="fit {}".format(n), linewidth=0.5) if 1: #absolute(best_parameters[1]-a.frequency[n])<2e8: freqs.append(a.frequency[n]) freq_diffs.append( absolute(best_parameters[1] - a.frequency[n])) widths.append(absolute(best_parameters[0])) fanof.append(absolute(best_parameters[4])) if 1: widths2 = [] freqs2 = [] freq_diffs2 = [] fano2 = [] flux_over_flux0 = qdt.call_func("flux_over_flux0", voltage=yok, offset=-0.037, flux_factor=0.2925) Ej = qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) flux_par = qdt._get_fq(Ej, qdt.Ec) magabs = absolute(mag)**2 for n in range(len(frq)): pbest = leastsq(residuals2, p, args=(filt[n, :], flux_par[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0: #n==539 or n==554:#n % 10: b.line_plot("magabs_flux", flux_par * 1e-9, (magabs[n, :] - best_parameters[3]) / best_parameters[2], label="{}".format(n), linewidth=0.2) b.line_plot("lorentzian", flux_par * 1e-9, fano(flux_par, best_parameters), label="fit {}".format(n), linewidth=0.5) if 1: #absolute(best_parameters[1]-frq[n])<1.5e8: freqs2.append(frq[n]) freq_diffs2.append(absolute(best_parameters[1] - frq[n])) widths2.append(absolute(best_parameters[0])) fano2.append(absolute(best_parameters[4])) b.line_plot("widths", freqs, widths, label="-110 dBm") b.scatter_plot("widths2", freqs2, widths2, color="red", label="-130 dBm") vf = 3488.0 p = [1.0001, 0.5, 0.3, 1.0e-15, 0.001] Np = 9 K2 = 0.048 f0 = 5.348e9 def fourier(x, p): w = 2 * pi * x k = 2.0 * pi * x / 3488.0 D = 500.0e-6 D1 = 300.0e-6 D2 = 200.0e-6 G_f = 0.5 * Np * K2 * f0 * (sin(Np * pi * (x - f0) / f0) / (Np * pi * (x - f0) / f0))**2 return G_f * absolute( exp(1.0j * k * D) * p[0] * (1 + exp(2.0j * k * D1) * (p[1] + 1.0j * p[2]) + exp(2.0j * k * D2) * (p[1] + 1.0j * p[2])) + 2.0j * w * p[3] * 50.0) + p[4] #exp(2.0j*k*D)*(p[1]+1.0j*p[2]))+ def resid(p, y, x): #return y - onebounce(x,p) return y - fourier(x, p) #pbest=leastsq(resid, p, args=(absolute(widths2[318:876]), frq[318:876]), full_output=1) #print pbest[0] #b.line_plot("fourier", frq, fourier(frq, pbest[0])) #pi*vf/2*x=D from scipy.signal import lombscargle #lombscargle(freqs2[318:876], widths2[318:876]) #bb.line_plot("fft", #frq[318:876]*fft.fftfreq(len(frq[318:876]), d=frq[1]-frq[0]), #absolute(fft.fft(widths2[318:876]))) frqdiffs = linspace(0.01, 500e6, 1000) #bb.line_plot("ls", frqdiffs, lombscargle(array(freqs2[285:828]), array(widths2[285:828]), frqdiffs )) #bb.line_plot("ls", frqdiffs, lombscargle(array(freqs[318:876]), array(widths[318:876]), frqdiffs)) bb.line_plot("fft2", absolute(fft.ifft(widths2[285:828]))) bb.line_plot("fft", absolute(fft.ifft(widths[285:828]))) bbb = Plotter() #bbb.scatter_plot("wid", freqs2, widths2) myifft = fft.ifft(widths2[285:828]) myifft[12:-12] = 0.0 bbb.line_plot("ff", freqs2[285:828], absolute(fft.fft(myifft)))
def magabs_cs_fit(): def lorentzian(x, p): return p[2] * (1.0 - 1.0 / (1.0 + ((x - p[1]) / p[0])**2)) + p[3] def fano(x, p): return p[2] * (((p[4] * p[0] + x - p[1])**2) / (p[0]**2 + (x - p[1])**2)) + p[3] def refl_fano(x, p): return p[2] * (1.0 - ((p[4] * p[0] + x - p[1])**2) / (p[0]**2 + (x - p[1])**2)) + p[3] def onebounce(x, p): w = 2 * pi * x k = 2.0 * pi * x / 3488.0 Cc = 0.0 D = 500.0e-6 D1 = 300.0e-6 D2 = 200.0e-6 S12q = ((p[4] * p[0] / 6.28 + (x - p[1]) * 2 * pi)** 2) / (p[0]**2 + (p[4] * p[0] / 6.28 + x - p[1])**2) S11q = 1.0 / (p[0]**2 + (p[4] * p[0] / 6.28 + x - p[1])**2) S11 = p[5] return p[2] * absolute( exp(1.0j * k * D) * S12q * (1 + exp(2.0j * k * D1) * S11q * S11 + exp(2.0j * k * D2) * S11q * S11 + exp(2.0j * k * D) * S11**2 * S12q**2) + 2.0j * w * Cc * 50.0)**2 + p[3] def allbounces(x, p): w = 2 * pi * x k = 2.0 * pi * x / 3488.0 Cc = 0.0 D = 500.0e-6 D1 = 300.0e-6 D2 = 200.0e-6 return p[2] * absolute( exp(1.0j * k * D) * S12q * (-2.0 + 1.0 / (1.0 - exp(2.0j * k * D1) * S11q * S11) + 1.0 / (1.0 - exp(2.0j * k * D2) * S11q * S11) + 1.0 / (1 - exp(2.0j * k * D) * S11**2 * S12q**2)) + 2.0j * w * Cc * 50.0) def residuals(p, y, x): err = y - lorentzian(x, p) return err def residuals2(p, y, x): return y - fano(x, p) def residuals3(p, y, x): return y - refl_fano(x, p) p = [200e6, 4.5e9, 0.002, 0.022, 0.1, 0.1] indices = [ range(81, 120 + 1), range(137, 260 + 1), range(269, 320 + 1), range(411, 449 + 1) ] #, [490]]#, [186]] indices = [range(len(a.frequency))] widths = [] freqs = [] freq_diffs = [] fanof = [] for ind_list in indices: for n in ind_list: pbest = leastsq(residuals3, p, args=(a.MagAbs[n, :], c.flux_parabola[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0: #n % 8==0: bb.scatter_plot("magabs_flux", c.flux_parabola[:] * 1e-9, a.MagAbs[n, :], label="{}".format(n), linewidth=0.2, marker_size=0.8) bb.line_plot("lorentzian", c.flux_parabola * 1e-9, refl_fano(c.flux_parabola, best_parameters), label="fit {}".format(n), linewidth=0.5) if 1: #absolute(best_parameters[1]-a.frequency[n])<2e8: freqs.append(a.frequency[n]) freq_diffs.append( absolute(best_parameters[1] - a.frequency[n])) widths.append(absolute(best_parameters[0])) fanof.append(absolute(best_parameters[4])) if 1: widths2 = [] freqs2 = [] freq_diffs2 = [] fano2 = [] flux_over_flux0 = qdt.call_func("flux_over_flux0", voltage=yok, offset=-0.037, flux_factor=0.2925) Ej = qdt.call_func("Ej", flux_over_flux0=flux_over_flux0) flux_par = qdt._get_fq(Ej, qdt.Ec) magabs = absolute(mag)**2 for n in range(len(frq)): pbest = leastsq(residuals2, p, args=(magabs[n, :], flux_par[:]), full_output=1) best_parameters = pbest[0] print best_parameters if 0: #n==539 or n==554:#n % 10: b.line_plot("magabs_flux", flux_par * 1e-9, (magabs[n, :] - best_parameters[3]) / best_parameters[2], label="{}".format(n), linewidth=0.2) b.line_plot("lorentzian", flux_par * 1e-9, fano(flux_par, best_parameters), label="fit {}".format(n), linewidth=0.5) if 1: #absolute(best_parameters[1]-frq[n])<1.5e8: freqs2.append(frq[n]) freq_diffs2.append(absolute(best_parameters[1] - frq[n])) widths2.append(absolute(best_parameters[0])) fano2.append(absolute(best_parameters[4])) b.line_plot("widths", freqs, widths, label="-110 dBm") b.scatter_plot("widths2", freqs2, widths2, color="red", label="-130 dBm") vf = 3488.0 p = [1.0001, 0.5, 0.3, 1.0e-15, 0.001] Np = 9 K2 = 0.048 f0 = 5.348e9 def fourier(x, p): w = 2 * pi * x k = 2.0 * pi * x / 3488.0 D = 500.0e-6 D1 = 300.0e-6 D2 = 200.0e-6 G_f = 0.5 * Np * K2 * f0 * (sin(Np * pi * (x - f0) / f0) / (Np * pi * (x - f0) / f0))**2 return G_f * absolute( exp(1.0j * k * D) * p[0] * (1 + exp(2.0j * k * D1) * (p[1] + 1.0j * p[2]) + exp(2.0j * k * D2) * (p[1] + 1.0j * p[2])) + 2.0j * w * p[3] * 50.0) + p[4] #exp(2.0j*k*D)*(p[1]+1.0j*p[2]))+ def resid(p, y, x): #return y - onebounce(x,p) return y - fourier(x, p) #pbest=leastsq(resid, p, args=(absolute(widths2[318:876]), frq[318:876]), full_output=1) #print pbest[0] #b.line_plot("fourier", frq, fourier(frq, pbest[0])) #pi*vf/2*x=D from scipy.signal import lombscargle #lombscargle(freqs2[318:876], widths2[318:876]) #bb.line_plot("fft", #frq[318:876]*fft.fftfreq(len(frq[318:876]), d=frq[1]-frq[0]), #absolute(fft.fft(widths2[318:876]))) frqdiffs = linspace(0.01, 500e6, 1000) #bb.line_plot("ls", frqdiffs, lombscargle(array(freqs2[285:828]), array(widths2[285:828]), frqdiffs )) #bb.line_plot("ls", frqdiffs, lombscargle(array(freqs[318:876]), array(widths[318:876]), frqdiffs)) bb.line_plot("fft2", absolute(fft.ifft(widths2[285:828]))) bb.line_plot("fft", absolute(fft.ifft(widths[285:828]))) bbb = Plotter() #bbb.scatter_plot("wid", freqs2, widths2) myifft = fft.ifft(widths2[285:828]) myifft[12:-12] = 0.0 bbb.line_plot("ff", freqs2[285:828], absolute(fft.fft(myifft))) b.line_plot("ff", freqs2[285:828], absolute(fft.fft(myifft))) #bb.line_plot("fft2", absolute(fft.fft(widths[52:155]))) #b.line_plot("fano", freqs, fano) #b.line_plot("fano", freqs2, fano2) #f0=5.37e9 freq = linspace(4e9, 5e9, 1000) #G_f=0.5*Np*K2*f0*(sin(Np*pi*(freq-f0)/f0)/(Np*sin(pi*(freq-f0)/f0)))**2 #b.scatter_plot("freq_test", freqs, freq_diffs) class Fitter3(Operative): base_name = "fitter" mult = FloatRange(0.001, 5.0, 0.82).tag(tracking=True) f0 = FloatRange(4.0, 6.0, 5.348).tag(tracking=True) offset = FloatRange(0.0, 100.0, 18.0).tag(tracking=True) @tag_Property(plot=True, private=True) def G_f(self): f0 = self.f0 * 1.0e9 return self.offset * 1e6 + self.mult * 0.5 * Np * K2 * f0 * ( sin(Np * pi * (freq - f0) / f0) / (Np * pi * (freq - f0) / f0))**2 @observe("f0", "mult", "offset") def update_plot(self, change): if change["type"] == "update": self.get_member("G_f").reset(self) b.plot_dict["G_f"].clt.set_ydata(self.G_f) b.draw() d = Fitter3() b.line_plot("G_f", freq, d.G_f, label="theory")