Skip to content
Bvsk_Saturation_Measurements.py 14 KiB
Newer Older
import h5py
import matplotlib.pyplot as plt
import numpy as np
import sys
import re
import ast
from scipy.optimize import curve_fit
import os
from scipy import interpolate

# Solo levanto algunos experimentos
Calib_Files_IR = """000007808-IR_Saturation
000007809-IR_Saturation
000007810-IR_Saturation
000007811-IR_Saturation
000007812-IR_Saturation
000007813-IR_Saturation
000007814-IR_Saturation
000007815-IR_Saturation
000007816-IR_Saturation
000007817-IR_Saturation
000007820-IR_Saturation
000007828-IR_Saturation
000007829-IR_Saturation
000007830-IR_Saturation
000007831-IR_Saturation""" 

os.chdir('/home/nico/Documents/artiq_experiments/analisis/plots/20220527_CPTvariandoB_barriendopotenciaIR/Data')

#carpeta pc nico labo escritorio:
#/home/nico/Documents/artiq_experiments/analisis/plots/20220527_CPTvariandoB_barriendopotenciaIR/Data

def SeeKeys(files):
    for i, fname in enumerate(files.split()):
        data = h5py.File(fname+'.h5', 'r') # Leo el h5: Recordar que nuestros datos estan en 'datasets'
        print(fname)
        print(list(data['datasets'].keys()))

#C:\Users\Usuario\Documents\artiq\artiq_experiments\analisis\plots\20210824_SaturacionTransiciones\Data_IR

IR_meas_amps_vec = []
IR_fluorescence_vec = []


for i, fname in enumerate(Calib_Files_IR.split()):
    print(i)
    #print(fname)
    data = h5py.File(fname+'.h5', 'r') # Leo el h5: Recordar que nuestros datos estan en 'datasets'
    #print(list(data['datasets'].keys()))
    meas = np.array(data['datasets']['measurements_IR_sat'])
    IR_fluorescence_vec.append(meas)
    IR_meas_amps_vec.append(np.array(data['datasets']['IR_amps']))
    

PotenciasIR = [155, 4.8, 5.4, 6.2, 7.1, 8.0, 9.0, 9.9, 11., 12.1, 13.4, 14.6, 16.1, 17.6, 19.2, 20.9, 22.6, 24.5, 26.5, 28.4, 30.6, 32.7, 34.9, 37.1, 39.6, 41.9, 44.3, 46.9, 49.5, 52.1, 54.8, 57.4, 60.1, 63., 65.7, 68.8, 71.6, 74.5, 77., 80., 82.9]

Ivec = [-2.3, -2.2, -2.1, -2, -1.9, -1.8, -1.7, -1.6]

#%%
#background:
    
Background = list(IR_fluorescence_vec[11])+list(IR_fluorescence_vec[12])+list(IR_fluorescence_vec[13])+list(IR_fluorescence_vec[14])
bkgr = int(np.mean(Background))
print(f'El background de la medicion es {bkgr} cuentas por segundo')

#%%

FluovsB = []
jselected = [0, 1, 2, 4, 6, 7, 8, 9]

for j in jselected:
    FluovsB.append(IR_fluorescence_vec[j])

plt.figure()
for j in range(len(jselected)):
    plt.plot(PotenciasIR, [f-bkgr for f in FluovsB[j]], 'o')
    plt.xlim(0, 90)
plt.xlabel('Potencia IR (uW)')
plt.ylabel('Cuentas')

#%%
from scipy.signal import savgol_filter as sf
import seaborn as sns

plt.style.use('seaborn-ticks')

colors=sns.color_palette("rocket", 10)

colorsselected=[colors[8],colors[5],colors[3],colors[0]]

FluovsBshort = []
jselected = [0, 1, 4, 8]

for j in jselected:
    FluovsBshort.append(IR_fluorescence_vec[j])

bkgr2 = np.min([FluovsBshort[0][1],FluovsBshort[1][1],FluovsBshort[2][1],FluovsBshort[3][1]])

#bkgrposta = np.min()

plt.figure(figsize=(3.5, 3))
for j in range(len(jselected)):
    rawcuentas = [f-bkgr2 for f in FluovsBshort[j]]
    cuentas = np.array(rawcuentas[0:3]+list(sf(rawcuentas[3:],7,3)))
    plt.plot(PotenciasIR[1:], cuentas[1:], 'o', color=colorsselected[j], markersize=3.5)
    plt.fill_between(PotenciasIR[1:], cuentas[1:]-np.sqrt(cuentas)[1:], cuentas[1:]+np.sqrt(cuentas)[1:], color=colorsselected[j], alpha=0.4)
    #plt.errorbar(PotenciasIR, cuentas, yerr=1*np.sqrt(cuentas), color='r', fmt='o', capsize=2, markersize=4)
    plt.xlim(0, 90)    
    #plt.ylim(-100,3500)
plt.grid()
plt.xlabel(r'Repump power ($\mu$W)', fontsize=11)
plt.ylabel('Counts', fontsize=11)
plt.tight_layout()
#plt.savefig('/home/nico/Nextcloud/G_liaf/Publicaciones/Work/2022 B vs k race/Figuras/Figuras jpg trabajadas/Barriendopotencia_exp.png',dpi=500)

#%%
# en funcion del campo magnetico ahora

FluovsBtrans = np.transpose(FluovsB)

potsselected = [5, 26, 31, 36]

plt.figure()
for p in potsselected:
    plt.plot(np.flip(np.abs(np.array(Ivec))), np.flip(np.array(FluovsBtrans[p])), 'o')

#%%
#pruebo un suavizado para los datos
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
def FuncTest(r,A,B, det, delta, g):
    return A*(((0.25*g*g+det*det+(2/3)*delta*delta)/(r*r))+6*r*r/(delta*delta))**(-1)+B


from scipy.signal import savgol_filter as sf

FluoSel = IR_fluorescence_vec[0][1:]
PotsSel = PotenciasIR[1:]
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

popt, pcov = curve_fit(FuncTest, PotsSel, FluoSel,p0=(1000,500,0,100,0))
print(popt)
PotsLong = np.arange(0,np.max(PotsSel), 0.1)
#PotsLong = np.arange(np.min(PotsSel),np.max(PotsSel), 0.1)

plt.plot(PotsSel, FluoSel, 'o')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.plot(PotsLong, FuncTest(PotsLong,*popt))
#plt.plot(PotsSel, sf(FluoSel, 13, 3))

#%%
#lo aplico
from scipy.optimize import curve_fit

"""
def LinearLarmortoCurrentCalibrated(I):
    Larmor = 379871*I+1145919
    return Larmor
"""

def LinearLarmortoCurrentCalibrated(I):
    Larmor = 257550*I+667309
    return Larmor


def ConvertLarmortoBfield(u):
    c = 1398190.0452488689
    return u/(2*np.pi)/c

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
def ConvertBfieldtoLarmor(B):
    c = 1398190.0452488689
    return B*(2*np.pi)*c

def ConvertToRabi(kk,gamma):
    return np.sqrt(kk)*gamma

def ConvertToRabiSq(kk,gamma):
    return kk*(gamma**2)

c = 1398190

FluovsB = []
jselected = [0, 1, 2, 4, 6, 7, 8, 9]

Bvec = [ConvertLarmortoBfield(u) for u in LinearLarmortoCurrentCalibrated(np.array(Ivec))]

for j in jselected:
    FluovsB.append(IR_fluorescence_vec[j])

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

# plt.figure()
# for j in range(len(jselected)):
#     plt.plot(PotenciasIR, sf([f-bkgr for f in FluovsB[j]], 13, 3), 'o')
#     plt.xlim(0, 90)
# plt.xlabel('Potencia IR (uW)')
# plt.ylabel('Cuentas')

MaxsFluosExp = []
MaxsPotsExp = []

for k in range(len(jselected)):
    filteredfluo = sf([f-bkgr for f in FluovsB[k]], 13, 3)
    maxfluo = np.max(filteredfluo)
    j=0
    happened=0
    while j<len(filteredfluo):
        try:
            if np.abs(filteredfluo[j]-maxfluo)<10:
                    MaxsFluosExp.append(filteredfluo[j])
                    MaxsPotsExp.append(PotenciasIR[j])
                    break                    
            else:
                j=j+1
        except:
            MaxsFluosExp.append(0)
            MaxsPotsExp.append(0)            

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

# plt.figure()
# plt.plot(Ivec, MaxsPotsExp,'rx')
# plt.xlabel('Corriente bobina (A)')
# plt.ylabel('Potencia umbral (mW)')
# plt.grid()  


#longBvec = np.arange(np.min(Bvec), np.max(Bvec), 0.1*Bvec[1]-0.1*Bvec[0])
longBvec = np.arange(-0.005, 0.033, 0.01*Bvec[1]-0.01*Bvec[0])
def LinearFitPotvsB(b, pendiente):
    #ordenada=0
    return pendiente*b

#popt_expvspot, pcov_expvspot = curve_fit(LinearFitPotvsB, np.array([0]+Bvec), np.array([0]+MaxsPotsExp))
popt_expvspot, pcov_expvspot = curve_fit(LinearFitPotvsB, np.array(Bvec), np.array(MaxsPotsExp))

print(popt_expvspot)
#print(f'Ordenada al origen: {round(popt_expvspot[1],1)} +- {round(np.sqrt(pcov_expvspot[1,1]),1)} mW/G')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
Figura 2b) del paper. Umbral vs campo magnetico con la calibracion y la teoria superpuesta (la teoria sale de threeLevel_2repumps_CPTPlotter.py de Figura CPT Teorica)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
def LinearFitPotvsB(b, pendiente):
    #ordenada=0
    return pendiente*b

#CamposVector2 = np.loadtxt('CamposVector.txt')
#RabiVector2 = np.loadtxt('RabiVector.txt')

propor = LinearFitPotvsB(longBvec, *popt_expvspot)[-1]/RabiVector2[-1] #esto lo cargo con las lineas de antes
#propor = LinearFitPotvsB(longBvec, *popt_expvspot)[-1]/RabiVector[0][-1] #esto viene del threeLevel_2repumps_CPTPlotter.py de Figura CPT Teorica de la carpeta Work (no de Papers)
colores=sns.color_palette("rocket")

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
MeanError = 11139.353180216529

plotFreqFreq = False

plt.figure(figsize=(3.5, 3))
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

if plotFreqFreq == True:
    plt.errorbar([f*1e-6 for f in ConvertBfieldtoLarmor(np.array([b*1e3 for b in Bvec]))], [c*1e-6 for c in ConvertToRabi(MaxsPotsExp/propor, 2*np.pi*1.35e6)], xerr=1e-3*MeanError, yerr=1e-6*ConvertToRabi(yerr0, 2*np.pi*1.35e6)/propor, color=colores[0], fmt="o", markersize=4, zorder=3,  elinewidth=1)
    plt.plot([f*1e-6 for f in ConvertBfieldtoLarmor(CamposVector2)], [c*1e-6 for c in ConvertToRabi(RabiVector2,2*np.pi*1.35e6)], linewidth=1., color=colores[3]) #esto viene del threeLevel_2repumps_CPTPlotter.py de Figura CPT Teorica
    plt.ylabel(r'Rabi Frequency (MHz)', fontsize=12,  fontname='STIXGeneral')

else:
    #plt.errorbar([b*1e3 for b in Bvec], MaxsPotsExp/propor, xerr=1e3*MeanError/(2*np.pi)/c, yerr=yerr0/propor, color=colores[0], fmt="o", markersize=4, zorder=3,  elinewidth=1)
    plt.errorbar([f*1e-6 for f in ConvertBfieldtoLarmor(np.array([b*1e0 for b in Bvec]))], [c*1e-12/((2*np.pi)**2) for c in ConvertToRabiSq(np.array(MaxsPotsExp)/propor, 2*np.pi*1.35e6)], xerr=1e-6*MeanError, yerr=(1e-12/((2*np.pi)**2))*ConvertToRabiSq(yerr0, 2*np.pi*1.35e6)/propor, color=colores[0], fmt="o", markersize=4, zorder=3,  elinewidth=1)
    plt.plot([f*1e-9 for f in ConvertBfieldtoLarmor(CamposVector2)], [r*1e-12/((2*np.pi)**2) for r in ConvertToRabiSq(RabiVector2,2*np.pi*1.35e6)], linestyle='dashed', linewidth=1., color='grey') #esto viene del threeLevel_2repumps_CPTPlotter.py de Figura CPT Teorica
    #plt.ylabel(r'Rabi Frequency Squared (MHz$^2$)', fontsize=12,  fontname='STIXGeneral')
    plt.ylabel(r'$\Omega_{\mathrm{DP}}^2$ (MHz$^2$)', fontsize=12,  fontname='STIXGeneral')


# plt.plot([f*1e-6 for f in ConvertBfieldtoLarmor(np.array([b*1e3 for b in Bvec]))], MaxsPotsExp,"o", color=colores[0], markersize=4, zorder=3)
# plt.ylim(0,80)
# plt.xlim(0,270)
#plt.plot([f*1e-6 for f in ConvertBfieldtoLarmor(CamposVector2)], [c*1e-6 for c in ConvertToRabi(RabiVector2,2*np.pi*1.35e6)], linewidth=1., color=colores[3]) #esto viene del threeLevel_2repumps_CPTPlotter.py de Figura CPT Teorica



plt.xlabel('Larmor Frequency (MHz)', fontsize=12, fontname='STIXGeneral')

plt.xlim(0,0.27)
plt.xticks([0, 0.05, 0.1, 0.15, 0.2, 0.25], fontsize=12,fontname='STIXGeneral')
plt.yticks([0, 1, 2, 3, 4], fontsize=12,fontname='STIXGeneral')
plt.ylim(0,4.1)

plt.grid()
plt.tight_layout()
#plt.savefig('/home/nico/Nextcloud/G_liaf/Publicaciones/Work/2022 B vs k race/Figuras/Figuras jpg trabajadas/umbralvsB_exp.png',dpi=500)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.savefig('/home/nico/Nextcloud/G_liaf/Publicaciones/Papers/2022 B vs K eigenbasis/Figuras_finales/Finalesfinales/Fig2b_v2.pdf')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
Figura 2a) del paper. Curvas de fluorescencia vs potencia del IR
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

from scipy.signal import savgol_filter as sf

# FluoSel = IR_fluorescence_vec[0][1:]
# PotsSel = PotenciasIR[1:]

# popt, pcov = curve_fit(FuncTest, PotsSel, FluoSel,p0=(1000,500,0,100,0))

def find_nearest(array, value):
    array = np.asarray(array)
    idx = (np.abs(array - value)).argmin()
    return idx
from scipy.signal import savgol_filter as sf
import seaborn as sns

plt.style.use('seaborn-ticks')
colors=sns.color_palette("rocket", 10)

colorsselected=[colors[0],colors[3],colors[5],colors[8]]

FluovsBshort = []
#jselected = [0, 1, 4, 8]
jselected = [8, 2, 1, 0]
Bcampos = [b*1e3 for b in Bvec] 
Bfields = [Bcampos[6], Bcampos[2], Bcampos[1], Bcampos[0]]
for j in jselected:
    FluovsBshort.append(IR_fluorescence_vec[j])

#bkgr2 = np.min([FluovsBshort[0][1],FluovsBshort[1][1],FluovsBshort[2][1],FluovsBshort[3][1]])

#bkgrposta = np.min()

PotenciasMaximos_parcial = MaxsPotsExp/propor

PotenciasMaximos = [PotenciasMaximos_parcial[6],PotenciasMaximos_parcial[2],PotenciasMaximos_parcial[1],PotenciasMaximos_parcial[0]]

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
def FuncTest(rsq, A, det, delta, g):
    c=1
    return A*(((0.25*g*g+det*det+(2/3)*delta*delta)/(c*rsq))+6*c*rsq/(delta*delta))**(-1)


smoothen_order = [3,3,3,1]
err = [2,1,1,1]
orden=5
plt.figure(figsize=(3.5, 3))
for j in range(len(jselected)):
    print(j)
    rawcuentas = [f-bkgr for f in FluovsBshort[j]]
    #cuentas = np.array(rawcuentas[0:3]+list(sf(rawcuentas[3:],7,3))) #este va bien
    cuentas = np.array(rawcuentas[0:3]+list(sf(rawcuentas[3:],13,smoothen_order[j]))) #este va bien
    #maximumfluo_index = np.array(cuentas[1:-1]).argmax()
    maximumfluo_index = find_nearest(PotenciasIR[1:-1]/propor, PotenciasMaximos[j])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    
    popt, pcov = curve_fit(FuncTest, PotenciasIR[1:-1]/propor, cuentas[1:-1]/1000, p0=(1e5,1.5,1e-2,3.5e2), bounds=((7e4,1.49,0,3.5e2),(2e5,1.51,1e6,3.501e2)))
    print(popt)
    #[r*1e-12 for r in ConvertToRabiSq(     ,2*np.pi*1.35e6)]
    #PotsLong = np.arange(0*np.min(PotenciasIR[1:-1]/propor), np.max(PotenciasIR[1:-1]/propor),0.01)
    PotsLong = np.arange(0*np.min(PotenciasIR[1:-1]/propor), np.max(PotenciasIR[1:-1]/propor),0.01)
    #plt.plot([(r/((2*np.pi)**2))*1e-12 for r in ConvertToRabiSq(PotsLong,2*np.pi*1.35e6)],FuncTest(np.array(PotsLong),*popt),color=colorsselected[j], linewidth=0.9, zorder=5)
    plt.plot([(r/((2*np.pi)**2))*1e-12 for r in ConvertToRabiSq(PotsLong,2*np.pi*1.35e6)],FuncTest(np.array(PotsLong),*popt),color=colorsselected[j], linestyle=(0,(5,1)), linewidth=0.9, zorder=5)
    plt.plot([(r/((2*np.pi)**2))*1e-12 for r in ConvertToRabiSq(PotenciasIR[1:-1]/propor,2*np.pi*1.35e6)], cuentas[1:-1]/1000, 'o', color=colorsselected[j], markersize=1.5, alpha=0.9, label=fr"$B={int(round(Bfields[j],0))}({err[j]})$"+r" $\mathrm{mG}$",zorder=orden)
    plt.vlines(x=((2*np.pi*1.35e6)**2)*(1e-12/(propor*(((2*np.pi)**2))))*PotenciasIR[1:-1][maximumfluo_index],ymin=0.2,ymax=cuentas[1:-1][maximumfluo_index]/1000,color=colorsselected[j],zorder=1,linewidth=1, linestyle='dotted')
    plt.fill_between([(r/((2*np.pi)**2))*1e-12 for r in ConvertToRabiSq(PotenciasIR[1:-1]/propor,2*np.pi*1.35e6)], (cuentas[1:-1]-1*np.sqrt(cuentas)[1:-1])/1000, (cuentas[1:-1]+1*np.sqrt(cuentas)[1:-1])/1000, color=colorsselected[j], alpha=0.3, zorder=orden)
    orden=orden-1
    
    #plt.errorbar(PotenciasIR, cuentas, yerr=1*np.sqrt(cuentas), color='r', fmt='o', capsize=2, markersize=4)
    #plt.xlim(0, 90)    
    #plt.ylim(-100,3500)

#for pot in MaxsPotsExp/propor:
#    plt.axvline(pot)

plt.grid()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.xlabel(r'$\Omega_{\mathrm{DP}}^2$ (MHz$^2$)', fontsize=12, fontname='STIXGeneral')
#plt.xlabel(r'$\Gamma$', fontsize=12, fontname='STIXGeneral')
plt.ylabel('Fluorescence (kcounts/s)', fontsize=12, fontname='STIXGeneral')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.xticks([0, 1, 2, 3, 4], fontsize=12, fontname='STIXGeneral')
plt.yticks([0,1,2,3], fontsize=12, fontname='STIXGeneral')
plt.ylim(0,3.7)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#plt.xlim(0,2.3)
plt.tight_layout()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#plt.legend(loc='upper left', frameon=True, fontsize=7.6, handletextpad=0.1)
plt.savefig('/home/nico/Nextcloud/G_liaf/Publicaciones/Papers/2022 B vs K eigenbasis/Figuras_finales/Finalesfinales/Fig2a_v2.pdf')