def _default_trace_plot(self): tp=Plotter(name=self.name+' trace plot') print self.freq print absolute(self.S21) print shape(self.freq) print shape(self.S21) tp.line_plot('trace_mag S21', self.freq, absolute(self.S21))#S20.0*log10(absolute(self.S21))) return tp
def plotty_func(self, plotter=None, *args, **kwargs): if plotter is None: plotter=Plotter() elif isinstance(plotter, basestring): if plotter in self.agent_dict: plotter=self.agent_dict[plotter] else: plotter=Plotter(name=plotter) return func(self, plotter=plotter, *args, **kwargs)
def _default_trace_plot(self): tp = Plotter(name=self.name + ' trace plot') print self.freq print absolute(self.S21) print shape(self.freq) print shape(self.S21) tp.line_plot('trace_mag S21', self.freq, absolute(self.S21)) #S20.0*log10(absolute(self.S21))) return tp
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")
s = (sm, 1, 1) Magcom = Magvec[:, 0, :] + 1j * Magvec[:, 1, :] Magcom = reshape(Magcom, s, order="F") frequency = linspace(fstart, fstart + fstep * (sm - 1), sm) Magcom = squeeze(Magcom) return frequency, Magcom #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) from numpy import array, log10, fft, exp if __name__ == "__main__": a = Lyzer() frq, yok, mag = a.read_data() c = Fitter() c.yoko = a.yoko[:] b = Plotter() bb = Plotter() #b.colormesh("magabs2", yok, frq, absolute(mag)) #b.line_plot("bg", bgf, bgmc/dB) def magdB_colormesh(): b.colormesh("magdB", a.yoko, a.frequency, a.MagdB) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4e9, 5.85e9) b.xlabel = "Yoko (V)" b.ylabel = "Frequency (Hz)" b.title = "Reflection fluxmap"
fstep=f["Traces"]['RS VNA - S21_t0dt'][0][1] sm=shape(Magvec)[0] s=(sm, 1, 1) Magcom=Magvec[:,0,:]+1j*Magvec[:,1,:] Magcom=reshape(Magcom, s, order="F") frequency=linspace(fstart, fstart+fstep*(sm-1), sm) Magcom=squeeze(Magcom) return frequency, Magcom #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) if __name__=="__main__": a=Lyzer() bgf, bgmc=a.read_data() c=Fitter() c.yoko=a.yoko[:] b=Plotter() #b.line_plot("bg", bgf, bgmc/dB) def magdB_colormesh(): b.colormesh("magdB", a.yoko, a.frequency, a.MagdB) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4e9, 5e9) b.xlabel="Yoko (V)" b.ylabel="Frequency (Hz)" b.title="Reflection fluxmap" def magabs_colormesh(): b.colormesh("magabs", a.yoko, a.frequency, a.MagAbs) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4e9, 5e9) b.xlabel="Yoko (V)" b.ylabel="Frequency (Hz)"
qdt.W = 7.0e-6 qdt.a = 96.0e-9 qdt.eta = 0.5 qdt.flux_factor = 0.302 #0.2945, qdt.voltage = 1.21 qdt.offset = 0.02 qdt.Ec = 0.8e9 * h idt = IDT(material='LiNbYZ', ft="double", Np=81, W=7.0e-6, eta=0.5, a=96.0e-9) if __name__ == "__main__": print get_tag(qdt, "a", "unit") print qdt.latex_table() from taref.plotter.fig_format import Plotter from taref.physics.fundamentals import sinc, sinc_sq b = Plotter() from numpy import linspace, pi, absolute, sqrt, sin freq = linspace(1e9, 10e9, 1000) #qdt.ft="single" #qdt.get_member("mult").reset(qdt) #qdt.get_member("lbda0").reset(qdt) print qdt.f0, qdt.G_f0 if 0: #G_f=(1.0/sqrt(2.0))*0.5*qdt.Np*qdt.K2*qdt.f0*absolute(sinc(qdt.Np*pi*(freq-qdt.f0)/qdt.f0)) #b.line_plot("sinc", freq, G_f, label="sinc/sqrt(2)") #G_f=0.5*qdt.Np*qdt.K2*qdt.f0*absolute(sinc(qdt.Np*pi*(freq-qdt.f0)/qdt.f0)) #b.line_plot("sinc2", freq, G_f, label="sinc") Np = 9 K2 = 0.048 f0 = 2 * 5.45e9
sm = shape(Magvec)[0] s = (sm, 1, 1) Magcom = Magvec[:, 0, :] + 1j * Magvec[:, 1, :] Magcom = reshape(Magcom, s, order="F") frequency = linspace(fstart, fstart + fstep * (sm - 1), sm) Magcom = squeeze(Magcom) return frequency, Magcom #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) if __name__ == "__main__": a = Lyzer() bgf, bgmc = a.read_data() c = Fitter() c.yoko = a.yoko[:] b = Plotter() #b.line_plot("bg", bgf, bgmc/dB) def magdB_colormesh(): b.colormesh("magdB", a.yoko, a.frequency, a.MagdB) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4e9, 5.85e9) b.xlabel = "Yoko (V)" b.ylabel = "Frequency (Hz)" b.title = "Reflection fluxmap" def magabs_colormesh():
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 = [] 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)))
s = (sm, sy[0], sy[2]) print s Magcom = Magvec[:, 0, :] + 1j * Magvec[:, 1, :] Magcom = reshape(Magcom, s, order="F") self.time = linspace(tstart, tstart + tstep * (sm - 1), sm) print shape(Magcom) Magcom = squeeze(Magcom) self.Magcom = Magcom[:] #.transpose() print shape(self.Magcom) #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) a = Lyzer(name="D0317_timedomain") a.read_data() c = Fitter1() b = Plotter() bb = Plotter() b1 = Plotter() def magdB_colormesh(): b.colormesh("magdB", a.time * 1e6, a.yoko, a.MagdB) #b.line_plot("flux_parabola", c.yoko, 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(fi=0): a.f_ind = fi
# def magabstime_colormesh(self, plotter=None): # if plotter is None: # plotter=self.plotter # plotter.colormesh("magabs", self.frequency, self.yoko, self.MagAbsTime) # plotter.xlabel="Time (us)" # plotter.ylabel="Magnitude (abs)" # plotter.title="Reflection vs time" if __name__=="__main__": print get_tag(qdt, "a", "unit") print qdt.latex_table() from taref.plotter.fig_format import Plotter from taref.physics.fundamentals import sinc, sinc_sq,e print e b=Plotter() from numpy import linspace, pi, absolute, sqrt freq=linspace(1e9, 10e9, 1000) #qdt.ft="single" #qdt.get_member("mult").reset(qdt) #qdt.get_member("lbda0").reset(qdt) print qdt.f0, qdt.G_f0 if 0: G_f=(1.0/sqrt(2.0))*0.5*qdt.Np*qdt.K2*qdt.f0*absolute(sinc(qdt.Np*pi*(freq-qdt.f0)/qdt.f0)) b.line_plot("sinc", freq, G_f, label="sinc/sqrt(2)") G_f=0.5*qdt.Np*qdt.K2*qdt.f0*absolute(sinc(qdt.Np*pi*(freq-qdt.f0)/qdt.f0)) b.line_plot("sinc2", freq, G_f, label="sinc") G_f=0.5*qdt.Np*qdt.K2*qdt.f0*sinc_sq(qdt.Np*pi*(freq-qdt.f0)/qdt.f0) b.line_plot("sinc_sq", freq, G_f, label="sinc_sq") b.vline_plot("listen", 4.475e9, alpha=0.3, color="black")
print s Magcom=Magvec[:,0,:]+1j*Magvec[:,1,:] Magcom=reshape(Magcom, s, order="F") self.frequency=linspace(fstart, fstart+fstep*(sm-1), sm) print shape(Magcom) self.Magcom=squeeze(Magcom) #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) if __name__=="__main__": a=Lyzer() a.read_data() print a.comment print a.probe_pwr c=Fitter() c.yoko=a.yoko[:] b=Plotter() def magdB_colormesh(): b.colormesh("magdB", a.yoko, a.frequency, a.MagdB) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4.4e9, 4.5e9) b.plot_dict["magdB"].set_clim(-65, -35) b.xlabel="Yoko (V)" b.ylabel="Frequency (Hz)" b.title="Reflection fluxmap" def magabs_colormesh(): b.colormesh("magabs", a.yoko, a.frequency, 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="Yoko (V)" b.ylabel="Frequency (Hz)"
# return data[0,1,:].astype(float64) # #print pwr # # @tagged_property(unit="GHz", label="Start frequency") # def fstart(self): # return self.rd_hdf.data["Traces"]['Rohde&Schwarz Network Analyzer - S12_t0dt'][0][0] # # @tagged_property(unit="GHz", label="Step frequency") # def fstep(self): # return self.rd_hdf.data["Traces"]['Rohde&Schwarz Network Analyzer - S12_t0dt'][0][1] # # @tagged_property(unit="GHz", label="Frequency") # def freq(self, fstart, fstep, sm): # return linspace(fstart, fstart+fstep*(sm-1), sm) from taref.plotter.fig_format import Plotter a=Lyzer() #a.rd_hdf.read() a.read_data() b=Plotter() #print b.colormap b.colormesh("magabs", a.yoko, a.freq, a.MagAbs) #print b.xyfs, b.clts #print a.Magcom print a.probe_frq, a.probe_pwr print a.yoko.dtype print get_display(a, "probe_pwr") #print locals() #print globals() #print a.sm shower( a, b)#locals_dict=locals()) #read_hdf.show()
#print s #Magcom=Magvec[:,0,:]+1j*Magvec[:,1,:] #Magcom=reshape(Magcom, s, order="F") #self.time=linspace(tstart, tstart+tstep*(sm-1), sm) #print shape(Magcom) #Magcom=squeeze(Magcom) #self.Magcom=Magcom.transpose() #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) a = Lyzer() a.read_data() c = Fitter() c.yoko = a.yoko b = Plotter() def magdB_colormesh(): b.colormesh("magdB", a.yoko, a.pwr, a.MagdB) #b.line_plot("flux_parabola", c.yoko, 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 ReldB_colormesh(): b.colormesh("magdB", c.flux_parabola, a.pwr, a.ReldB) #-amax(a.ReldB)) b.vline_plot("flux_1", c.freq, color="blue", alpha=0.7) b.vline_plot("flux_2", c.freq, color="blue", alpha=0.7)
#qdt.voltage=1.21 #qdt.offset= 0.1195; idt=IDT() idt.material='GaAs' idt.ft="single" idt.Np=125 idt.W=25.0e-6 idt.a=96.0e-9 if __name__=="__main__": print get_tag(qdt, "a", "unit") print qdt.latex_table() from taref.plotter.fig_format import Plotter from taref.physics.fundamentals import sinc, sinc_sq b=Plotter() from numpy import linspace, pi, absolute, sqrt, sin freq=linspace(1e9, 10e9, 1000) #qdt.ft="single" #qdt.get_member("mult").reset(qdt) #qdt.get_member("lbda0").reset(qdt) print qdt.f0, qdt.G_f0 if 0: #G_f=(1.0/sqrt(2.0))*0.5*qdt.Np*qdt.K2*qdt.f0*absolute(sinc(qdt.Np*pi*(freq-qdt.f0)/qdt.f0)) #b.line_plot("sinc", freq, G_f, label="sinc/sqrt(2)") #G_f=0.5*qdt.Np*qdt.K2*qdt.f0*absolute(sinc(qdt.Np*pi*(freq-qdt.f0)/qdt.f0)) #b.line_plot("sinc2", freq, G_f, label="sinc") Np=9 K2=0.048 f0=2*5.45e9
#@tag_Property(display_unit="dB", plot=True) #def MagdB(self): # return self.Magcom[:, :]/dB-mean(self.Magcom[:, 169:171], axis=1, keepdims=True)/dB #@tag_Property(plot=True) #def Phase(self): # return angle(self.Magcom[:, :]-mean(self.Magcom[:, 169:170], axis=1, keepdims=True)) # return absolute(self.Magcom[:, :])**2#-mean(self.Magcom[:, 0:1], axis=1, keepdims=True)) if __name__ == "__main__": a = S1A1_Midpeak() a.read_data() b = Plotter() #a.magabs_colormesh(b) #a.magabsfilt_colormesh(b) bb = Plotter() a.ifft_plot(bb) b1 = Plotter() #a.filt_compare(a.start_ind, b1) b2 = Plotter() #a.filt_compare(a.on_res_ind, b2) b3 = Plotter() #a.plot_widths(b3) a1 = S4A1_Midpeak() a1.read_data() a1.filt_compare(a1.start_ind, b1) a1.filt_compare(a1.on_res_ind, b2) a1.magabs_colormesh(b)
# return data[0,1,:].astype(float64) # #print pwr # # @tagged_property(unit="GHz", label="Start frequency") # def fstart(self): # return self.rd_hdf.data["Traces"]['Rohde&Schwarz Network Analyzer - S12_t0dt'][0][0] # # @tagged_property(unit="GHz", label="Step frequency") # def fstep(self): # return self.rd_hdf.data["Traces"]['Rohde&Schwarz Network Analyzer - S12_t0dt'][0][1] # # @tagged_property(unit="GHz", label="Frequency") # def freq(self, fstart, fstep, sm): # return linspace(fstart, fstart+fstep*(sm-1), sm) from taref.plotter.fig_format import Plotter a = Lyzer() #a.rd_hdf.read() a.read_data() b = Plotter() #print b.colormap b.colormesh("magabs", a.yoko, a.freq, a.MagAbs) #print b.xyfs, b.clts #print a.Magcom print a.probe_frq, a.probe_pwr print a.yoko.dtype print get_display(a, "probe_pwr") #print locals() #print globals() #print a.sm shower(a, b) #locals_dict=locals()) #read_hdf.show()
fstep=f["Traces"]['RS VNA - S21_t0dt'][0][1] sm=shape(Magvec)[0] s=(sm, 1, 1) Magcom=Magvec[:,0,:]+1j*Magvec[:,1,:] Magcom=reshape(Magcom, s, order="F") frequency=linspace(fstart, fstart+fstep*(sm-1), sm) Magcom=squeeze(Magcom) return frequency, Magcom #Magabs=Magcom[:, :, :]-mean(Magcom[:, 197:200, :], axis=1, keepdims=True) if __name__=="__main__": a=Lyzer() bgf, bgmc=a.read_data() c=Fitter() c.yoko=a.yoko[:] b=Plotter() #b.line_plot("bg", bgf, bgmc/dB) def magdB_colormesh(): b.colormesh("magdB", a.yoko, a.frequency, a.MagdB) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4e9, 5.85e9) b.xlabel="Yoko (V)" b.ylabel="Frequency (Hz)" b.title="Reflection fluxmap" def magabs_colormesh(): #b.colormesh("magabs", a.yoko, a.frequency, a.MagAbs) b.line_plot("flux_parabola", c.yoko, c.flux_parabola, color="orange", alpha=0.4) b.set_ylim(4e9, 5.85e9) b.xlabel="Yoko (V)" b.ylabel="Frequency (Hz)"
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")