In [13]:
%pylab


Using matplotlib backend: MacOSX
Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['norm', 'cond', 'power']
`%pylab --no-import-all` prevents importing * from pylab and numpy

In [14]:
cd /Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM


/Users/miguel_daal/Documents/Projects/Python_Res_Fit/KAM

In [15]:
import KAM

In [16]:
reload(KAM)


Out[16]:
<module 'KAM' from 'KAM.pyc'>

In [17]:
run -i Load_Datasets.py

In [18]:
#data extraction conditions for  power sweeps
#condition = ['Q>0','Q>0','Pr<-64','Q>0', 'Pr<-68','Q>0','Q<200000', 'Q>50000', 'Pr<-60','Q>0','Q>0']
condition = ['Q>0','Q>0','Pr<-65','Q>0', 'Pr<-68','Q>0','Q<210000', 'Pr<-45', 'Pr<-60','Q>0','Q>0']
for sweep in xrange(len(Power_Sweeps)):
    Power_Sweeps[sweep].metadata.condition = condition[sweep]

In [19]:
Power_Sweeps.sort(key = lambda w: w.metadata.width) #sort power sweep list so that narrowest resonator is first and widest is last

In [20]:
fig = plt.figure( figsize=(5.5, 4.5), dpi=100)
ax = fig.add_subplot(111)
sweep = Run45aP
index = 0; line1 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-100 dBm Probe Power', linewidth=3,linestyle= '-')
index = 8; line2 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-72 dBm Probe Power', linewidth=3,linestyle= '-')
index = 11; line3 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-66 dBm Probe Power', linewidth=3,linestyle= '-')
#index = 18; line4 = ax.plot(sweep.Sweep_Array['Frequencies'][index]/1e6,20*np.log10(np.abs(sweep.Sweep_Array['S21'][index])), label = '-52 dBm Probe Power', linewidth=3,linestyle= '-')
ax.set_xlabel('Frequency [MHz]',color = 'k')
#ax.xaxis.get_major_formatter().set_powerlimits((0, 1))
ax.ticklabel_format(axis='x', style='plain', scilimits=(0,0),useOffset=False)
ax.xaxis.set_major_locator(plt.LinearLocator(5))
ax.set_ylabel('$|S_{21}|$ [dB]', color='k')
ax.set_title('Trsansmission Around Resonance at Different Powers: \n\n 64 $\mu m$ wide Al microstrip on Nb ground plane', fontsize=9)
ax.legend(loc = 'best', fontsize=9)
ax.grid()
plt.subplots_adjust(left=.15, bottom=.15, right=None, top=.85)

plt.show()
#fig.savefig('Transmission_at_Different_Powers', dpi = 300, transparency  = True)

In [91]:
fig = plt.figure( figsize=(5, 5), dpi=100)
ax = fig.add_subplot(111)
norm = mpl.colors.Normalize(vmin=0, vmax=len(Power_Sweeps))
scalarMap = cm.ScalarMappable(norm=norm, cmap='jet')





for sweep in xrange(len(Power_Sweeps)):
    Pr = Power_Sweeps[sweep].Sweep_Array['Preadout_dB'] 
    Qc = Power_Sweeps[sweep].Sweep_Array['Qc']
    Q =  Power_Sweeps[sweep].Sweep_Array['Q']
    Fr =  Power_Sweeps[sweep].Sweep_Array['Fr']
    Qi = 1.0/((1.0/Q)-(1.0/Qc))
    R = Q/Qc
    E = np.power(10,(Pr-10)/20)*Qc/(2*np.pi*Fr)
    F = Qc/(2*np.pi*Fr)
    #condition = [Pr<-64,Q>0, Pr<-68,Q>0,Q<200000, Q>50000, Pr<-60,Q>0,Q>0]
    
    #condition = ['Pr<-64','Q>0', 'Pr<-68','Q>0','Q<200000', 'Q>50000', 'Pr<-60','Q>0','Q>0']
    #line = ax.plot(np.extract(condition[sweep],Pr),np.extract(condition[sweep],Qi), color = scalarMap.to_rgba(sweep), label = str(Power_Sweeps[sweep].metadata.width)+ '$\mu m$ width', linewidth=3,linestyle= '-', marker = 'x' )
    cond = eval(Power_Sweeps[sweep].metadata.condition)
    xdict = dict(zip(Pr,arange(Pr.size)))
    #xdict = dict(zip(E,arange(E.size)))
    x = np.extract(cond,Pr)
    y = np.extract(cond,F)
    line = ax.plot(x,y, color = scalarMap.to_rgba(sweep), label = str(Power_Sweeps[sweep].metadata.width)+ '$\mu m$; Run '+ Power_Sweeps[sweep].metadata.Run, linewidth=3,linestyle= '-', marker = '.', markerfacecolor = 'k' )
    for i,j in zip(x,y):
        if mod(xdict[i],4) == 0:
            ax.annotate(str(xdict[i]),xy=(i,j), size = 5, rotation = 90,xytext=(i,j))
    
ax.legend(loc = 'best', fontsize=8,scatterpoints =1, numpoints = 1, labelspacing = .1)
#ax.set_ylim((-50000.0, 400000.0))
#ax.set_ylim((0.0, 600000.0)) #for Qc
ax.set_xlim((-118.0, -20.0))
ax.ticklabel_format(axis='y', style='sci',useOffset=False)
ax.set_ylabel('Internal Quality Factor, $Q_i$', color='k')
ax.set_xlabel('Probe Power [dBm]', color='k')
ax.set_title('Effect of Probe Power on\nInternal Quality Factor')
plt.subplots_adjust(left=.2, bottom=None, right=None, top=None)
ax.tick_params(axis='y', labelsize=9)
ax.tick_params(axis='x', labelsize=9)
ax.grid()
plt.show()
#fig.savefig('Probe_Power_Versus_Qi_Dec9',dpi=300, transparency  = True)

In [22]:
fig = plt.figure( figsize=(5, 5), dpi=100)
ax = fig.add_subplot(111)
norm = mpl.colors.Normalize(vmin=0, vmax=len(Power_Sweeps))
scalarMap = cm.ScalarMappable(norm=norm, cmap='jet')

widths = np.array([2,4,8,16,32,64,128,256])
Z3 = np.array([85.77,67.82,50.176,33.82,21.24,12.72,7.18,3.58])
Z3_dict = dict(zip(widths,Z3))
Z1 = np.array([52.10,52.10,52.10,52.10,52.10,52.10,52.10,52.10])
Z1_dict = dict(zip(widths,Z1))
Eeff = np.array([4.196,3.8148,3.2517,2.6174,2.09048,1.7018,1.4482,1.2773])
Eeff_dict = dict(zip(widths,Eeff))
del(Z3,Z1,Eeff)

for sweep in xrange(len(Power_Sweeps)):#[Power_Sweeps[5],Power_Sweeps[8],Power_Sweeps[1], Power_Sweeps[7]]:#Power_Sweeps:
    Pr = Power_Sweeps[sweep].Sweep_Array['Preadout_dB'] 
    Qc = Power_Sweeps[sweep].Sweep_Array['Qc']
    Q =  Power_Sweeps[sweep].Sweep_Array['Q']
    Fr =  Power_Sweeps[sweep].Sweep_Array['Fr']
    Z3 = Z3_dict[Power_Sweeps[sweep].metadata.width]
    Z1 = Z1_dict[Power_Sweeps[sweep].metadata.width]
    Qi = 1.0/((1.0/Q)-(1.0/Qc[0]))
    
    #condition = [Pr<-64,Q>0, Pr<-68,Q>0,Q<200000, Q>50000, Pr<-60,Q>0,Q>0]
    

    I_middle = (1/np.pi)*np.power(10,(Pr-10)/20)*Qi*Qc[0]/((Qi-Qc[0])*np.sqrt(Z3*Z1))
    cond = eval(Power_Sweeps[sweep].metadata.condition)
    #line = ax.plot(np.extract(condition[sweep],Pr),np.extract(condition[sweep],Qi), label = Power_Sweeps[sweep].metadata.Run + ' '+Power_Sweeps[sweep].metadata.Sensor +' ' +Power_Sweeps[sweep].metadata.Ground_Plane, linewidth=3,linestyle= '-', marker = 'x' )
    line = ax.plot(np.extract(cond,Pr),np.extract(cond,I_middle), color = scalarMap.to_rgba(sweep), label = str(Power_Sweeps[sweep].metadata.width)+ '$\mu m$ width', linewidth=3,linestyle= '-', marker = 'x' )
ax.legend(loc = 'best', fontsize=9,scatterpoints =1, numpoints = 1, labelspacing = .1)

#ax.set_ylim((0.0, 600000.0)) #for Qc
ax.set_xlim((-118.0, -20.0))
ax.ticklabel_format(axis='y', style='sci')
ax.set_ylabel('Current', color='k')
ax.set_xlabel('Probe Power [dBm]', color='k')
ax.set_title('Effect of Probe Power on\n Internal Max Resonator Current')
plt.subplots_adjust(left=.2, bottom=None, right=None, top=None)
ax.tick_params(axis='y', labelsize=9)
ax.tick_params(axis='x', labelsize=9)
ax.grid()
plt.show()
#fig.savefig('Probe_Power_Versus_Qi',dpi = 300 ,transparency  = True)

In [23]:
#plot fractional freq shift for runs 51a and 48b, 32um resonators

fig = plt.figure( figsize=(5, 5), dpi=100)
ax = fig.add_subplot(111)
norm = mpl.colors.Normalize(vmin=0, vmax=len(Power_Sweeps))
scalarMap = cm.ScalarMappable(norm=norm, cmap='jet')
power = -55.
swp = Run51aTP; line = ax.plot( np.extract(swp.Sweep_Array['Pinput_dB'] == power,swp.Sweep_Array['Temperature']), np.extract(swp.Sweep_Array['Pinput_dB'] == power,(swp.Sweep_Array['Fr']-swp.Sweep_Array['Fr'][0])/swp.Sweep_Array['Fr'][0]) , color = 'r', label = swp.metadata.Run + ': '+str(swp.metadata.width)+ '$\mu m$ width', linewidth=3,linestyle= '-', marker = 'x' )
swp = Run48bTP; line = ax.plot( np.extract(swp.Sweep_Array['Pinput_dB'] == power,swp.Sweep_Array['Temperature']), np.extract(swp.Sweep_Array['Pinput_dB'] == power,(swp.Sweep_Array['Fr']-swp.Sweep_Array['Fr'][0])/swp.Sweep_Array['Fr'][0]) , color = 'r', label = swp.metadata.Run + ':'+str(swp.metadata.width)+ '$\mu m$ width', linewidth=3,linestyle= '--', marker = 'x' )
power = -59.
#swp = Run44bTP; line = ax.plot( np.extract(swp.Sweep_Array['Pinput_dB'] == power,swp.Sweep_Array['Temperature']), np.extract(swp.Sweep_Array['Pinput_dB'] == power,(swp.Sweep_Array['Fr']-swp.Sweep_Array['Fr'][0])/swp.Sweep_Array['Fr'][0]) , color = 'g', label = swp.metadata.Run + ': '+str(swp.metadata.width)+ '$\mu m$ width', linewidth=3,linestyle= ':', marker = 'x' )

ax.legend(loc = 'best', fontsize=9,scatterpoints =1, numpoints = 1, labelspacing = .1)

ax.ticklabel_format(axis='y', style='sci')
ax.set_ylabel('$\delta F_r / F_r$', color='k')
ax.set_xlabel('Temperature [K]', color='k')
ax.set_title('Fractional Frequency Shift with Temperature')
plt.subplots_adjust(left=.2, bottom=None, right=None, top=None)
ax.tick_params(axis='y', labelsize=9)
ax.tick_params(axis='x', labelsize=9)
ax.grid()
plt.show()
#fig.savefig('Fractional_Freq_Shift_Temp_Reading_Improvement', dpi = 300,transparency  = True)

In [24]:
power = -55.
Temp = np.extract(swp.Sweep_Array['Pinput_dB'] == power,swp.Sweep_Array['Temperature'])
dF = np.extract(swp.Sweep_Array['Pinput_dB'] == power,(swp.Sweep_Array['Fr']-swp.Sweep_Array['Fr'][0])/swp.Sweep_Array['Fr'][0])

In [86]:
ax.plot?

In [89]:
fig = plt.figure( figsize=(5, 5), dpi=100)
ax = fig.add_subplot(111)

Z0 = 52.1
Zc = np.complex(0,6000)

Qc_func = lambda Zr: np.pi*np.square(np.abs((0.5*Z0+Zc+Zr)/np.sqrt(1.0*Z0*Zr)))
#Qc_func = lambda Zr: np.pi*np.square(np.abs((Zr)/np.sqrt(1.0*Z0*Zr)))
z = np.linspace(0,1000000,num = 100000)
line = ax.semilogx(z,Qc_func(3.58-np.complex(0,1)*z))
line = ax.semilogx(z,Qc_func(3.58+z))
ax.grid()
plt.show()

In [77]:
Qc_func(3.58)


Out[77]:
606376.2942415633

In [ ]: