import numpy as np
from matplotlib import pyplot as plt
from scipy.optimize import curve_fit
from scipy.signal import find_peaks
import os
import sympy as sp
def myLine(x, m, q):
return m*x + q
err_t = 3*10**(-2)
err_t
0.03
%matplotlib inline
ppp = np.array([1,0,3,2,5,4])
vectRange1 = np.array([range(0,8),range(0,6),range(0, 25),range(0,10),range(0,16),range(0,14)])[ppp]
vectRange2 = np.array([range(11,18),range(8,15),range(32, 50),range(13,21),range(20,30),range(18,27)])[ppp]
cnt = 0
lstBias = []
q1 = [] ; q2 =[] ; err_q1 = [] ; err_q2 = []
ymid =[]
xmid =[]
for i,e in enumerate(os.scandir(".\stairCase")):
if e.name.split(".")[-1] != "txt": continue
# if e.name.split("_")[2] != "new": continue
lstBias.append(e.name.split("_")[1])
cond1 = vectRange1[cnt]
cond = vectRange2[cnt]
cnt+=1
x,y = np.loadtxt(e.path, unpack=True, skiprows=8)
err = np.sqrt(y)/err_t
def myLine(x, q):
return 0*x+ q
fig, ax = plt.subplots(figsize=(12,5))
ax.set_title(f"{e.name}", fontsize = 16)
ax.errorbar(x,y, yerr= err, marker='.' ,linestyle = '',color = 'b', label='dati')
popt1, optcov1 = curve_fit(myLine, x[cond1], y[cond1], p0 = None , sigma= err[cond1], absolute_sigma = True)
y_new1 = myLine(x,*popt1)
# ax.plot(x[cond1],y[cond1],'*')
ax.plot(x[cond1],y_new1[cond1],'g', label='fit primo plateau' , lw=2)
q1.append(popt1)
err_q1.append(np.sqrt(optcov1[0]))
popt2, optcov2 = curve_fit(myLine, x[cond], y[cond], p0 = None , sigma= err[cond], absolute_sigma = True)
y_new = myLine(x,*popt2)
# ax.plot(x[cond],y[cond],'*')
ax.plot(x[cond],y_new[cond],'r', label='fit secondo plateau' ,lw = 2)
q2.append(popt2)
err_q2.append(np.sqrt(optcov2[0]))
if e.name.split("_")[1] == "55.5":
ax.plot(21,143964.444 ,'og', ms=10, label='metà primo plateau')
ax.plot(35, 11255.556,'ok', ms=10, label='metà prima discesa')
ax.plot(49,5066.667 ,'or', ms=10, label='metà secondo plateau ')
ax.plot(63, 622.22,'oy', ms=10, label='metà seconda discesa')
ax.legend(fontsize = 14, loc = 'lower left')
else:
ax.legend(fontsize = 14)
#ax.plot(x[47],y[47],'*k', ms = 20)
xmid.append(x)
ymid.append(y)
# mid1 = np.array([x[7],x[9],x[12],x[30],x[16],x[18]] )
# mid2 = np.array([x[15],x[20],x[24],x[65],x[32],x[35]] )
ax.set_xlabel("Soglia [mV]", fontsize = 14)
ax.set_ylabel("Frequenza [Hz]", fontsize = 14)
ax.set_yscale("log")
ax.grid()
plt.show()
xmid = np.array(xmid)
ymid = np.array(ymid)
lstBias = np.array(lstBias)
print(q1,q2)
C:\Users\steca\AppData\Local\Temp\ipykernel_14348\3402772083.py:5: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. vectRange1 = np.array([range(0,8),range(0,6),range(0, 25),range(0,10),range(0,16),range(0,14)])[ppp] C:\Users\steca\AppData\Local\Temp\ipykernel_14348\3402772083.py:7: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. vectRange2 = np.array([range(11,18),range(8,15),range(32, 50),range(13,21),range(20,30),range(18,27)])[ppp]
[array([92490.72569686]), array([114284.76629643]), array([133825.99787807]), array([145179.33569986]), array([170776.65467074]), array([193191.63849948])] [array([916.60441275]), array([1924.4509064]), array([3652.81611557]), array([5539.93118729]), array([8880.80944765]), array([12569.84095587])]
C:\Users\steca\AppData\Local\Temp\ipykernel_14348\3402772083.py:76: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. xmid = np.array(xmid) C:\Users\steca\AppData\Local\Temp\ipykernel_14348\3402772083.py:77: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. ymid = np.array(ymid)
q1 = np.array(q1)
q2 = np.array(q2)
err_q1 = np.array(err_q1)/1e3
err_q1 = err_q1.flatten()
bias = np.arange(54,57,0.5)
q1 = np.sort(q1, axis=None)/1e3
q2 = np.sort(q2, axis=None)/1e3
err_q2 = np.array(err_q2)/1e3
err_q2 = err_q2.flatten()
xmid= np.array(xmid)
# Da runnare solo una volta perché c'è sovrascrittura dei vettori
print(q1,q2)
[ 92.4907257 114.2847663 133.82599788 145.1793357 170.77665467 193.1916385 ] [ 0.91660441 1.92445091 3.65281612 5.53993119 8.88080945 12.56984096]
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('DCR vs Bias', fontsize = 16)
ax.errorbar(bias,q1, err_q1, marker='*' ,linestyle = '',color = 'b')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("DCR [kHz]", fontsize = 14)
ax.grid()
plt.show()
r = q2 / q1
err_r = np.sqrt( (err_q2/q1)**2 + (q2*err_q1/q1**2)**2 )
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('Cross-talk vs Bias', fontsize = 16)
ax.errorbar(bias,r*100, err_r*100, marker='*' ,linestyle = '',color = 'b')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("OCT [%]", fontsize = 14)
ax.grid()
plt.show()
q1
array([ 92.4907257 , 114.2847663 , 133.82599788, 145.1793357 , 170.77665467, 193.1916385 ])
# X della discesa
xmid1 = np.array((19, 23, 29, 35, 37, 41))
xmid2 = np.array((35, 45, 53, 63, 69, 75))
delta = xmid2 - xmid1
x05 = xmid1 - delta/2
x15 = xmid1 + delta/2
y05 = []
y15 = []
for i in range(len(xmid)):
tmpBool = xmid[i] >= x05[i]
tmpy = ymid[i][tmpBool][0]
y05.append(tmpy)
tmpBool = xmid[i] >= x15[i]
tmpy = ymid[i][tmpBool][0]
y15.append(tmpy)
y05 = np.array(y05)
y15 = np.array(y15)
rapporto = y15/y05
err_y15 = np.sqrt(y15)/err_t
err_y05 = np.sqrt(y05)/err_t
err_rapporto = np.sqrt( (err_y15/y05)**2 + (y15*err_y05/y05**2)**2 )
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('Cross-talk vs Bias', fontsize = 16)
ax.errorbar(bias,rapporto*100, err_rapporto*100, marker='*' ,linestyle = '',color = 'b', label = 'rapporto tra valori dei plateau')
# ax.errorbar(bias,r*100, err_r*100, marker='o' ,linestyle = '',color = 'r',label = 'rapporto tra fit')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("OCT [%]", fontsize = 14)
ax.grid()
# ax.legend()
plt.show()
err_rapporto = np.sqrt( (err_y15/y05)**2 + (y15*err_y05/y05**2)**2 )
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('Cross-talk vs Bias', fontsize = 16)
# ax.errorbar(bias,rapporto*100, err_rapporto*100, marker='*' ,linestyle = '',color = 'b', label = 'rapporto tra valori dei plateau')
ax.errorbar(bias,r*100, err_r*100, marker='o' ,linestyle = '',color = 'r',label = 'rapporto tra fit')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("OCT [%]", fontsize = 14)
ax.grid()
# ax.legend()
plt.show()
err_rapporto = np.sqrt( (err_y15/y05)**2 + (y15*err_y05/y05**2)**2 )
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('Cross-talk vs Bias', fontsize = 16)
ax.errorbar(bias,rapporto*100, err_rapporto*100, marker='*' ,linestyle = '',color = 'b', label = 'rapporto tra valori dei plateau')
ax.errorbar(bias,r*100, err_r*100, marker='o' ,linestyle = '',color = 'r',label = 'rapporto tra fit')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("OCT [%]", fontsize = 14)
ax.grid()
ax.legend(loc=2, fontsize = 14)
plt.show()
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('DCR vs Bias', fontsize = 16)
# ax.errorbar(bias,y05/1000,err_y05/1000, marker='*' ,linestyle = '',color = 'b')
ax.errorbar(bias,q1, err_q1, marker='o' ,linestyle = '',color = 'r')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("DCR [kHz]", fontsize = 14)
ax.grid()
plt.show()
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('DCR vs Bias', fontsize = 16)
ax.errorbar(bias,y05/1000,err_y05/1000, marker='*' ,linestyle = '',color = 'b')
# ax.errorbar(bias,q1, err_q1, marker='o' ,linestyle = '',color = 'r')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("DCR [kHz]", fontsize = 14)
ax.grid()
plt.show()
fig, ax = plt.subplots()#figsize=(13,8))
ax.set_title('DCR vs Bias', fontsize = 16)
ax.errorbar(bias,y05/1000,err_y05/1000, marker='*' ,linestyle = '',color = 'b', label='DCR dai valori di plateau')
ax.errorbar(bias,q1, err_q1, marker='o' ,linestyle = '',color = 'r', label = 'DCR da valori di fit')
ax.set_xlabel("V bias [V]", fontsize = 14)
ax.set_ylabel("DCR [kHz]", fontsize = 14)
ax.grid()
ax.legend(fontsize = 14)
plt.show()
xmid1 = np.array([xmid[0][7], xmid[1][9], xmid[2][30], xmid[3][12], xmid[4][18], xmid[5][16] ])
xmid2 = np.array([xmid[0][20], xmid[1][15], xmid[2][57],xmid[3][24], xmid[4][35], xmid[5][32] ])
print(xmid1, xmid2)
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) Input In [9], in <cell line: 2>() 1 xmid1 = np.array([xmid[0][7], xmid[1][9], xmid[2][30], xmid[3][12], xmid[4][18], xmid[5][16] ]) ----> 2 xmid2 = np.array([xmid[0][20], xmid[1][15], xmid[2][57],xmid[3][24], xmid[4][35], xmid[5][32] ]) 4 print(xmid1, xmid2) IndexError: index 57 is out of bounds for axis 0 with size 48
xmid1 = np.array([xmid[0][7], xmid[1][9], xmid[2][30], xmid[3][12], xmid[4][18], xmid[5][16] ])
xmid2 = np.array([xmid[0][20], xmid[1][15], xmid[2][57],xmid[3][24], xmid[4][35], xmid[5][32] ])
# x_15 = (xmid2 + xmid1) / 2
# x_05 = x_15 - xmid1
delta = xmid2 - xmid1
x_15 = xmid1 + delta/2
x_05 = xmid1 - delta/2
print(x_05,x_15)
idx1 = np.array([xmid[0][3],xmid[1][3],xmid[2][7],xmid[3][4],xmid[4][5],xmid[5][6]] )
idx2 = np.array([xmid[0][11],xmid[1][14],xmid[2][36],xmid[3][22],xmid[4][24],xmid[5][26]])
# y1 = ymid[0][int(idx1[0])]
# print(y1,idx1)
y1 = []
y2 = []
# for i in range(idx1.size):
# y1.append(ymid[i][int(idx1[i])])
# # for i in range(idx2.size):
# # y2.append(ymid[i][int(idx2[i])])
# # y1 = np.array(y1) ; y2 = np.array(y2)
# print(y1)
i=0
myBool = xmid[i] >= x_15[i]
pippo = ymid[i][myBool][0]
pippo
myBool
ymid[i][myBool][0]
pippoLst = []
for i in range(6):
myBool = xmid[i] >= x_05[i]
pippo = ymid[i][myBool][0]
pippoLst.append(pippo)
pippoLst = np.array(pippoLst)
pippoLst1 = []
for i in range(6):
myBool = xmid[i] >= x_15[i]
pippo = ymid[i][myBool][0]
pippoLst1.append(pippo)
pippoLst1 = np.array(pippoLst1)
pippoLst1
perm = np.argsort(lstBias)
pippoOrdinato1 = pippoLst1[perm]
pippoOrdinato1
x_15[1]
perm = np.argsort(lstBias)
pippoOrdinato = pippoLst[perm]
pippoOrdinato
lstBias[perm]
perm
lstBias