Commit 4733fe7b authored by Nicolas Nunez Barreto's avatar Nicolas Nunez Barreto
Browse files

para muri

parent 2c74777d
Loading
Loading
Loading
Loading
+3 −2
Changes for analisis/plots/20220615_CPTvariandocompensacion/CPT_plotter_20220615.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -293,11 +293,11 @@ def FitEIT_MM_SA(Freqs, offset, DetDoppler, SG, SP, SCALE1, SCALE2, OFFSET, BETA
    #return ScaledFluo1


popt_SA, pcov_SA = curve_fit(FitEIT_MM_SA, FreqsDR, CountsDR, p0=[425, -13, 0.9, 7.5, 4e3, 5e3, 4000, 3.8, 0.8, 0.2e-3, 32e6], bounds=((0, -50, 0, 0, 0, 0, 0, 0,0, 0, 28e6), (1000, 0, 2, 20, 5e6, 5e6, 1e4, 10, 10,20e-3,40e6)))
popt_SA, pcov_SA = curve_fit(FitEIT_MM_SA, FreqsDR, CountsDR, p0=[425, -13, 0.9, 7.5, 4e3, 5e3, 2500, 3.8, 0.8, 0.2e-3, 32e6], bounds=((0, -50, 0, 0, 0, 0, 1500, 0,0, 0, 28e6), (1000, 0, 2, 20, 5e6, 5e6, 6000, 10, 10,20e-3,40e6)))


FittedEITpi_short_SA, Detunings_short_SA = FitEIT_MM_SA(FreqsDR, *popt_SA, plot=True)
freqslong = np.arange(min(FreqsDR), max(FreqsDR)+FreqsDR[1]-FreqsDR[0], 0.1*(FreqsDR[1]-FreqsDR[0]))
freqslong = np.arange(1*min(FreqsDR), 1*max(FreqsDR)+FreqsDR[1]-FreqsDR[0], 0.1*(FreqsDR[1]-FreqsDR[0]))
FittedEITpi_long_SA, Detunings_long_SA = FitEIT_MM_SA(freqslong, *popt_SA, plot=True)

plt.figure()
@@ -306,6 +306,7 @@ plt.plot(Detunings_long_SA, FittedEITpi_long_SA, color='darkolivegreen', linewid
plt.title('2 ion model')
plt.xlabel('Detuning (MHz)')
plt.ylabel('Counts')
plt.xlim(-100,100)
#plt.legend(loc='upper left', fontsize=20)
plt.grid()

+211 −20
Changes for analisis/plots/20231123_CPTconmicromocion3/CPT_plotter_20231123.py: 211 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ CountsSplit_2ions.append(Split(Counts[4],len(Freqs[4])))
Ploteo la cpt de referencia / plotting the reference CPT
"""

jvec = [4] # de la 1 a la 9 vale la pena, despues no
jvec = [2] # de la 1 a la 9 vale la pena, despues no

drs = [390.5, 399.5, 406, 413.5]

@@ -899,6 +899,9 @@ plt.grid()
#%%
"""
AHORA INTENTO SUPER AJUSTES O SEA CON OFFSETXPI Y DETDOPPLER INCLUIDOS

La 0 no ajusta bien incluso con todos los parametros libres
De la 1 a la 11 ajustan bien
"""


@@ -942,8 +945,8 @@ alpha = 0
drivefreq = 2*np.pi*22.135*1e6


SelectedCurveVec = [1,2,3,4,5,6,7,8,9]
#SelectedCurveVec = [9]
SelectedCurveVec = [1,2,3,4,5,6,7,8,9,10,11]
#SelectedCurveVec = [10]

popt_SA_vec = []
pcov_SA_vec = []
@@ -985,7 +988,7 @@ for selectedcurve in SelectedCurveVec:
    alpha = 0
    

    def FitEIT_MM_single(Freqs, offset, DetDoppler, SG, SP, SCALE1, OFFSET, BETA1, TEMP, plot=False):
    def FitEIT_MM_single(Freqs, offset, DetDoppler, SG, SP, SCALE1, OFFSET, BETA1, TEMP, U, plot=False):
    #def FitEIT_MM(freqs, SG, SP, SCALE1, OFFSET, BETA1):
        #BETA = 1.8
        # SG = 0.6
@@ -994,7 +997,7 @@ for selectedcurve in SelectedCurveVec:
    
        freqs = [2*f*1e-6-offset for f in Freqs]
      
        Detunings, Fluorescence1 = PerformExperiment_8levels_MM(SG, SP, gPS, gPD, DetDoppler, u, DopplerLaserLinewidth, ProbeLaserLinewidth, TEMP, alpha, phidoppler, titadoppler, phiprobe, titaprobe,  BETA1, drivefreq, min(freqs), max(freqs)+(freqs[1]-freqs[0]), freqs[1]-freqs[0], circularityprobe=CircPr, plot=False, solvemode=1, detpvec=None)
        Detunings, Fluorescence1 = PerformExperiment_8levels_MM(SG, SP, gPS, gPD, DetDoppler, U, DopplerLaserLinewidth, ProbeLaserLinewidth, TEMP, alpha, phidoppler, titadoppler, phiprobe, titaprobe,  BETA1, drivefreq, min(freqs), max(freqs)+(freqs[1]-freqs[0]), freqs[1]-freqs[0], circularityprobe=CircPr, plot=False, solvemode=1, detpvec=None)
    
        ScaledFluo1 = np.array([f*SCALE1 + OFFSET for f in Fluorescence1])
        if plot:
@@ -1005,7 +1008,7 @@ for selectedcurve in SelectedCurveVec:
    
    do_fit = True
    if do_fit:
        popt_3_SA, pcov_3_SA = curve_fit(FitEIT_MM_single, FreqsDR, CountsDR, p0=[430, -25, 0.9, 6.2, 3e4, 1.34e3, 2, (np.pi**2)*1e-3], bounds=((0, -50, 0, 0, 0, 0, 0, 0), (1000, 0, 2, 20, 5e4, 5e4, 10, (np.pi**2)*10e-3)))
        popt_3_SA, pcov_3_SA = curve_fit(FitEIT_MM_single, FreqsDR, CountsDR, p0=[430, -25, 0.9, 6.2, 3e4, 1.34e3, 2, (np.pi**2)*1e-3, 32e6], bounds=((0, -50, 0, 0, 0, 0, 0, 0, 25e6), (1000, 0, 2, 20, 5e4, 5e4, 10, (np.pi**2)*10e-3, 40e6)))
        
        popt_SA_vec.append(popt_3_SA)
        pcov_SA_vec.append(pcov_3_SA)
@@ -1049,7 +1052,10 @@ Grafico distintas variables que salieron del SUper ajuste
import seaborn as sns
paleta = sns.color_palette("rocket")

voltages_dcA = Voltages[0][1:10]
medfin = 12


voltages_dcA = Voltages[0][1:medfin]

def lineal(x,a,b):
    return a*x+b
@@ -1060,12 +1066,12 @@ def hiperbola(x,a,b,c,x0):
hiperbola_or_linear = True

if hiperbola_or_linear:
    popthip,pcovhip = curve_fit(hiperbola,voltages_dcA,Betas_vec,p0=(100,0.1,1,-0.15))
    popthip,pcovhip = curve_fit(hiperbola,voltages_dcA,Betas_vec[:medfin-1],p0=(100,0.1,1,-0.15))
    
    xhip = np.linspace(-0.23,0.005,200)
    
    plt.figure()
    plt.errorbar(voltages_dcA,Betas_vec,yerr=ErrorBetas_vec,fmt='o',capsize=5,markersize=5,color=paleta[1])
    plt.errorbar(voltages_dcA,Betas_vec[0:medfin-1],yerr=ErrorBetas_vec[:medfin-1],fmt='o',capsize=5,markersize=5,color=paleta[1])
    plt.plot(xhip,hiperbola(xhip,*popthip))
    plt.xlabel('Endcap voltage (V)')
    plt.ylabel('Modulation factor')
@@ -1094,8 +1100,8 @@ else:
print([t*1e3 for t in Temp_vec])

plt.figure()
plt.errorbar(voltages_dcA,[t*1e3 for t in Temp_vec],yerr=[t*1e3 for t in ErrorTemp_vec],fmt='o',capsize=5,markersize=5,color=paleta[3])
plt.axvline(minimum_voltage,linestyle='dashed',color='grey')
plt.errorbar(voltages_dcA,[t*1e3 for t in Temp_vec[:medfin-1]],yerr=[t*1e3 for t in ErrorTemp_vec[:medfin-1]],fmt='o',capsize=5,markersize=5,color=paleta[3])
#plt.axvline(minimum_voltage,linestyle='dashed',color='grey')
plt.axhline(0.538)
plt.xlabel('Endcap voltage (V)')
plt.ylabel('Temperature (mK)')
@@ -1111,12 +1117,12 @@ sino que esta a una distancia d
def hiperbola(x,a,b,c,x0):
    return a*np.sqrt(((x-x0)**2+c**2))+b

popthip,pcovhip = curve_fit(hiperbola,voltages_dcA,Betas_vec,p0=(100,0.1,1,-0.15))
popthip,pcovhip = curve_fit(hiperbola,voltages_dcA,Betas_vec[:10],p0=(100,0.1,1,-0.15))

xhip = np.linspace(-0.23,0.005,200)

plt.figure()
plt.errorbar(voltages_dcA,Betas_vec,yerr=ErrorBetas_vec,fmt='o',capsize=5,markersize=5,color=paleta[1])
plt.errorbar(voltages_dcA,Betas_vec[:10],yerr=ErrorBetas_vec[:10],fmt='o',capsize=5,markersize=5,color=paleta[1])
plt.plot(xhip,hiperbola(xhip,*popthip))
plt.xlabel('Endcap voltage (V)')
plt.ylabel('Modulation factor')
@@ -1126,26 +1132,66 @@ plt.grid()


#%%
from scipy.special import jv


def expo(x,tau,A,B):
    return A*np.exp(x/tau)+B

def cuadratica(x,a,c):
    return a*(x**2)+c

def InverseMicromotionSpectra(beta, A, det, x0, gamma, B):
    ftrap=22.1
    #gamma=30
    P = ((jv(0, beta)**2)/((((det-x0)**2)+(0.5*gamma)**2)**2))*(-2*(det-x0))
    i = 1
    #print(P)
    while i <= 5:
        P = P + (-2*(det-x0))*((jv(i, beta))**2)/(((((det-x0)+i*ftrap)**2)+(0.5*gamma)**2)**2) + (-2*(det-x0))*(((jv(-i, beta))**2)/((((det-x0)-i*ftrap)**2)+(0.5*gamma)**2)**2)
        i = i + 1
        #print(P)
    #return 1/(A*P+B)
    return 1/(A*P+B)


def InverseMicromotionSpectra_raw(beta, A, det, B):
    ftrap=22.1
    gamma=21
    P = ((jv(0, beta)**2)/((((det)**2)+(0.5*gamma)**2)**2))*(-2*(det))
    i = 1
    #print(P)
    while i <= 3:
        P = P + (-2*(det))*((jv(i, beta))**2)/(((((det)+i*ftrap)**2)+(0.5*gamma)**2)**2) + (-2*(det))*(((jv(-i, beta))**2)/((((det)-i*ftrap)**2)+(0.5*gamma)**2)**2)
        i = i + 1
        #print(P)
    return A/P+B


"""
Temperatura vs beta con un aju8ste exponencial 
Temperatura vs beta con un ajuste exponencial 
"""

popt_exp, pcov_exp = curve_fit(expo,Betas_vec,[t*1e3 for t in Temp_vec])
popt_quad, pcov_quad = curve_fit(cuadratica,Betas_vec,[t*1e3 for t in Temp_vec],p0=(1,10))
popt_exp, pcov_exp = curve_fit(expo,Betas_vec[:10],[t*1e3 for t in Temp_vec[:10]])
popt_quad, pcov_quad = curve_fit(cuadratica,Betas_vec[:10],[t*1e3 for t in Temp_vec[:10]],p0=(1,10))
#popt_rho22, pcov_rho22 = curve_fit(InverseMicromotionSpectra,Betas_vec,[t*1e3 for t in Temp_vec],p0=(10,10,-10,1,20)) #esto ajusta muy bien
#popt_rho22, pcov_rho22 = curve_fit(InverseMicromotionSpectra,Betas_vec, [t*1e3 for t in Temp_vec],p0=(-10,-10,10,1,20)) #esto ajusta muy bien
popt_rho22_raw, pcov_rho22_raw = curve_fit(InverseMicromotionSpectra_raw,Betas_vec[:10], [t*1e3 for t in Temp_vec[:10]],p0=(-10, -10, 1)) #esto ajusta muy bien


print(popt_rho22_raw)

betaslong = np.arange(0,2*2.7,0.01)

betaslong = np.arange(0,2.7,0.01)
print(f'Min temp predicted: {InverseMicromotionSpectra_raw(betaslong,*popt_rho22_raw)[100]}')

plt.figure()
plt.errorbar(Betas_vec,[t*1e3 for t in Temp_vec],xerr=ErrorBetas_vec, yerr=[t*1e3 for t in ErrorTemp_vec],fmt='o',capsize=5,markersize=5,color=paleta[3])
plt.plot(betaslong,expo(betaslong,*popt_exp),label='Ajuste exponencial')
plt.plot(betaslong,cuadratica(betaslong,*popt_quad),label='Ajuste cuadratico')
plt.errorbar(Betas_vec[:10],[t*1e3 for t in Temp_vec[:10]],xerr=ErrorBetas_vec[:10], yerr=[t*1e3 for t in ErrorTemp_vec[:10]],fmt='o',capsize=5,markersize=5,color=paleta[3])
#plt.plot(betaslong,expo(betaslong,*popt_exp),label='Ajuste exponencial')
#plt.plot(betaslong,cuadratica(betaslong,*popt_quad),label='Ajuste cuadratico')
#plt.plot(betaslong,InverseMicromotionSpectra(betaslong,*popt_rho22),label='Ajuste cuadratico')
plt.plot(betaslong,InverseMicromotionSpectra_raw(betaslong,*popt_rho22_raw),label='Ajuste cuadratico')

#plt.axvline(minimum_voltage,linestyle='dashed',color='grey')
#plt.axhline(0.538)
plt.xlabel('Modulation factor')
@@ -1779,6 +1825,151 @@ plt.title(f'Corr:{correccion},DetD:{DetDoppler}')
plt.grid()


#%%
"""
AHORA INTENTO SUPER AJUSTES O SEA CON OFFSETXPI Y DETDOPPLER INCLUIDOS
"""


#from EITfit.MM_eightLevel_2repumps_AnalysisFunctions import PerformExperiment_8levels
from scipy.optimize import curve_fit
import time

"""
SUPER AJUSTE (SA)


"""

phidoppler, titadoppler = 0, 90
phirepump, titarepump = 0,  0
phiprobe = 0
titaprobe = 90

Temp = 0.5e-3

sg = 0.544
sp = 4.5
sr = 0
DetRepump = 0


lw = 0.1
DopplerLaserLinewidth, RepumpLaserLinewidth, ProbeLaserLinewidth = lw, lw, lw #ancho de linea de los laseres


u = 32.5e6

#B = (u/(2*np.pi))/c

correccion = 13

#DetDoppler = -11.5-correccion

gPS, gPD, = 2*np.pi*21.58e6, 2*np.pi*1.35e6 
alpha = 0


drivefreq = 2*np.pi*22.135*1e6


#SelectedCurveVec = [1,2,3,4,5,6,7,8,9]
SelectedCurveVec = [0]

# popt_SA_vec = []
# pcov_SA_vec = []
# Detuningsshort_vec = []
# Counts_vec = []
# Detuningslong_vec = []
# FittedCounts_vec = []

# Betas_vec = []
# ErrorBetas_vec = []
# Temp_vec = []
# ErrorTemp_vec = []

# DetuningsUV_vec = []
# ErrorDetuningsUV_vec = []

for selectedcurve in SelectedCurveVec: 

#selectedcurve = 2 #IMPORTANTE: SELECCIONA LA MEDICION

    FreqsDR = Freqs[0]
    CountsDR = CountsSplit[0][selectedcurve]


    if selectedcurve==1:
        CountsDR[100]=0.5*(CountsDR[99]+CountsDR[101])
        CountsDR[105]=0.5*(CountsDR[104]+CountsDR[106])
    if selectedcurve==2:
        CountsDR[67]=0.5*(CountsDR[66]+CountsDR[68])
        CountsDR[71]=0.5*(CountsDR[70]+CountsDR[72])
    if selectedcurve==6:
        CountsDR[1]=0.5*(CountsDR[0]+CountsDR[2])
        CountsDR[76]=0.5*(CountsDR[75]+CountsDR[77])
    if selectedcurve==7:
        CountsDR[117]=0.5*(CountsDR[116]+CountsDR[118])
        
    freqslong = np.arange(min(FreqsDR), max(FreqsDR)+FreqsDR[1]-FreqsDR[0], 0.1*(FreqsDR[1]-FreqsDR[0]))
    CircPr = 1
    alpha = 0
    

    def FitEIT_MM_single(Freqs, offset, DetDoppler, SG, SP, SCALE1, OFFSET, BETA1, TEMP, U, plot=False):
    #def FitEIT_MM(freqs, SG, SP, SCALE1, OFFSET, BETA1):
        #BETA = 1.8
        # SG = 0.6
        # SP = 8.1
        # TEMP = 0.2e-3
    
        freqs = [2*f*1e-6-offset for f in Freqs]
      
        Detunings, Fluorescence1 = PerformExperiment_8levels_MM(SG, SP, gPS, gPD, DetDoppler, U, DopplerLaserLinewidth, ProbeLaserLinewidth, TEMP, alpha, phidoppler, titadoppler, phiprobe, titaprobe,  BETA1, drivefreq, min(freqs), max(freqs)+(freqs[1]-freqs[0]), freqs[1]-freqs[0], circularityprobe=CircPr, plot=False, solvemode=1, detpvec=None)
    
        ScaledFluo1 = np.array([f*SCALE1 + OFFSET for f in Fluorescence1])
        if plot:
            return ScaledFluo1, Detunings
        else:
            return ScaledFluo1
        #return ScaledFluo1
    
    do_fit = True
    if do_fit:
        popt_3_SA, pcov_3_SA = curve_fit(FitEIT_MM_single, FreqsDR, CountsDR, p0=[430, -25, 0.9, 6.2, 3e4, 1.34e3, 2, (np.pi**2)*1e-3, 32e6], bounds=((0, -50, 0, 0, 0, 0, 0, 0, 25e6), (1000, 0, 2, 20, 5e4, 5e4, 10, (np.pi**2)*10e-3, 40e6)))
        
        # popt_SA_vec.append(popt_3_SA)
        # pcov_SA_vec.append(pcov_3_SA)
    
        FittedEITpi_3_SA_short, Detunings_3_SA_short = FitEIT_MM_single(FreqsDR, *popt_3_SA, plot=True)
        freqslong = np.arange(min(FreqsDR), max(FreqsDR)+FreqsDR[1]-FreqsDR[0], 0.1*(FreqsDR[1]-FreqsDR[0]))
        FittedEITpi_3_SA_long, Detunings_3_SA_long = FitEIT_MM_single(freqslong, *popt_3_SA, plot=True)
    
    # DetuningsUV_vec.append(popt_3_SA[1])
    # ErrorDetuningsUV_vec.append(np.sqrt(pcov_3_SA[1,1]))
    
    # Betas_vec.append(popt_3_SA[6])
    # ErrorBetas_vec.append(np.sqrt(pcov_3_SA[6,6]))
    # Temp_vec.append(popt_3_SA[7])
    # ErrorTemp_vec.append(np.sqrt(pcov_3_SA[7,7]))
    
    # Detuningsshort_vec.append(Detunings_3_SA_short)
    # Counts_vec.append(CountsDR)
    # Detuningslong_vec.append(Detunings_3_SA_long)
    # FittedCounts_vec.append(FittedEITpi_3_SA_long)
    
    
    plt.figure()
    plt.errorbar(Detunings_3_SA_short, CountsDR, yerr=2*np.sqrt(CountsDR), fmt='o', color='darkgreen', alpha=0.5, capsize=2, markersize=2)
    plt.plot(Detunings_3_SA_long, FittedEITpi_3_SA_long, color='darkolivegreen', linewidth=3, label=f'med {selectedcurve}')
    #plt.title(f'Sdop: {round(popt[0], 2)}, Spr: {round(popt[1], 2)}, T: {round(popt[2]*1e3, 2)} mK, detDop: {DetDoppler} MHz')
    plt.xlabel('Detuning (MHz)')
    plt.ylabel('Counts')
    plt.legend(loc='upper left', fontsize=20)
    plt.grid()
    
    print(f'listo med {selectedcurve}')
    print(popt_3_SA)