Transitorios_03.py 8.99 KB
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

os.chdir('/home/nico/Documents/artiq_experiments/analisis/plots/20230523_transitorioshighpower/')
# Solo levanto algunos experimentos
SP_files = [12221, 12222, 12223, 12224]

Random_files = [8749]

def expo(T, tau, N0, C):
    global T0
    return N0*np.exp(-(T-T0)/tau) + C

def pow_from_amp(amp):
    """Paso de amplitud urukul a potencia medida por Nico"""
    # Forma altamente ineficiente de hacer esto, pero me salio asi
    amplitudes_UV = np.flip(np.array([0.08, 0.10, 0.12, 0.14, 0.16, 0.18, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30]))
    assert amp in amplitudes_UV
    potencias_UV = np.flip(np.array([4, 10, 19, 32, 49, 71, 96, 125, 155, 183, 208, 229]))
    return potencias_UV[np.where(amplitudes_UV == amp)][0]


def SP_Bkgr_builder(amp_in, amp_fin, derivadainicio, derivadafin, longbins):
    CalibCurve = []
    j=0
    while j<longbins:
        if j<=derivadainicio:
            CalibCurve.append(amp_in)
        elif j>=derivadainicio and j<=derivadafin:
            pendiente=(amp_fin-amp_in)/(derivadafin-derivadainicio)
            CalibCurve.append(amp_in+pendiente*(j-derivadainicio))
        else:
            CalibCurve.append(amp_fin)
        j=j+1
    return CalibCurve

    

"""
plt.plot(amplitudes_UV, potencias_UV, 'ko-', lw=0.2)
plt.xlabel("Amplitud Urukul")
plt.ylabel("Potencia /uW")
plt.grid()
"""
#%%

BINW = 1e-9
T0 = -0.4e-6

SP_Heigths = []
SP_Bins = []

for i, fname in enumerate(SP_files):
    #print(i)
    #print(fname)
    data = h5py.File('Data/SP/0000'+str(fname)+'-SingleLine.h5', 'r')
    counts = np.array(data['datasets']['counts'])
    bines = np.arange(counts.min(), counts.max()+BINW, BINW)

    heigs, binsf  = np.histogram(counts, bines[bines>T0])
    
    SP_Heigths.append(heigs)
    SP_Bins.append(binsf)
    

#%%
"""
Vectores de amplitudes y potencias
"""

UVampVec = [0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26]
UVpotVec = [4, 6, 12, 17, 26, 36, 48, 77, 112, 151, 190, 226, 255, 279]

IRampVec = [0.10, 0.12, 0.14, 0.16, 0.18, 0.2, 0.22, 0.24, 0.26, 0.2, 0.08]


#%%

from scipy.optimize import curve_fit

RefBins = [t*1e6 for t in SP_Bins[0][:-1]]

plt.figure()
for Height in [SP_Heigths[3]]:
    print(Height)
    plt.plot(RefBins, Height,'o')
    
plt.xlim(0.15, 0.5)

#%%

"""
Esto mira las curvas SP y les hace ajustes exponenciales a la ultima parte para plotear
el tiempo caracteristico
"""


"""
Primer detuning
"""

Taus = []
Amps = []
Offsets = []

ErrorTaus = []


popt_vec = []
pcov_vec = []

plt.figure()
for j in range(len(SP_Heigths)):
#for j in [12]:
    print(j)
    #BackgroundVector = SP_Bkgr_builder(np.mean(SP_Heigths[j][0:50]),np.mean(SP_Heigths[j][-50:]),59,67,965)
    
    #CorrectedSP_Height = [SP_Heigths[j][k]-BackgroundVector[k] for k in range(len(BackgroundVector))]
    
    CorrectedSP_Height = SP_Heigths[j]
    
    if j==3:
        popt, pcov = curve_fit(expo, RefBins[90:], CorrectedSP_Height[90:], p0=(5, 1000, 100))
        popt_vec.append(popt)
        pcov_vec.append(pcov)
        plt.plot(RefBins, CorrectedSP_Height)
        plt.plot(RefBins[90:], [expo(r, *popt) for r in RefBins][90:])
        Taus.append(popt[0])
        Amps.append(popt[1])
        Offsets.append(popt[2])
        ErrorTaus.append(np.sqrt(pcov)[0][0])
        print(Taus)        
#%%
plt.figure()
plt.plot(UVpotVec[:-5], Taus[:-6],'o', markersize=10, color='purple')
#plt.errorbar(UVpotVec[:-5], Taus[:-6], yerr=1e1*np.array(ErrorTaus[:-6]), fmt='.', capsize=2, markersize=2)
plt.xlabel('UV power (mW)', fontsize=15)
plt.ylabel('Characteristic time (us)', fontsize=15)
plt.ylim(-0.1,3)
plt.grid()


#%%
plt.figure()
plt.plot(UVpotVec, Amps,'o')
plt.xlabel('UV power (mW)')
plt.ylabel('Characteristic time (us)')

plt.figure()
plt.plot(UVpotVec, Offsets,'o')


#%%
"""
FIGURA PAPER SP CON AJUSTES
"""

import matplotlib
import seaborn as sns

matplotlib.rcParams['mathtext.fontset'] = 'stix'
matplotlib.rcParams['font.family'] = 'STIXGeneral'
plt.style.use('seaborn-bright')
plt.rcParams.update({
    "text.usetex": False,
})

plt.figure()
plt.plot(Stat_Bins[0][:-1], Stat_Heigths[0])

#plot figuras papers

colors1=sns.color_palette("rocket", 10)
colors2=sns.color_palette("mako", 10)
color2 = colors2[1]
color3 = colors2[4]
color1 = colors2[8]


#plt.figure(figsize = (3.8,2.8))
#plt.plot(RefBins, )




#%%

"""
Esto mira las curvas SP y les hace ajustes exponenciales a la ultima parte para plotear
el tiempo caracteristico
"""


"""
Segundo detuning
"""

RefBins = [t*1e6 for t in SP_Bins_v2[0][:-1]]

bkgrvec = Calib_Bins[3][:-1]

Taus_v2 = []
Amps_v2 = []
Offsets_v2 = []

ErrorTaus_v2 = []


popt_vec_v2 = []
pcov_vec_v2 = []


ki = 80 

selectedj = [2,5,10]
t0 = -0.2

plt.figure()
for j in range(len(SP_Heigths_v2)):
#for j in [1]:
    if j in selectedj:
        #BackgroundVector = SP_Bkgr_builder(np.mean(SP_Heigths_v2[j][0:50]),np.mean(SP_Heigths_v2[j][-50:]),59,67,965)
        
        #CorrectedSP_Height_v2 = [SP_Heigths_v2[j][k]-BackgroundVector[k] for k in range(len(BackgroundVector))]
        
        CorrectedSP_Height_v2 = SP_Heigths_v2[j]
        
        popt, pcov = curve_fit(expo, RefBins[ki:], CorrectedSP_Height_v2[ki:], p0=(5, 1000, 100), bounds=((0, 0, 0), (50, 1e5, 1e5)))
        popt_vec_v2.append(popt)
        pcov_vec_v2.append(pcov)
        plt.plot([r+t0 for r in RefBins], CorrectedSP_Height_v2)
        plt.plot([r+t0 for r in RefBins[ki:]], [expo(r, *popt) for r in RefBins][ki:])
        
        print(popt[0])
        
        print(pcov[0][0])
        
        Taus_v2.append(popt[0])
        Amps_v2.append(popt[1])
        Offsets_v2.append(popt[2])
        ErrorTaus_v2.append(np.sqrt(pcov)[0][0])
    
plt.xlim(-0.2,2)

#%%

plt.figure()
plt.plot(UVpotVec, Taus_v2,'o')
plt.xlabel('UV power (mW)')
plt.ylabel('Characteristic time (us)')

plt.figure()
plt.plot(UVpotVec, Amps_v2,'o')
plt.xlabel('UV power (mW)')
plt.ylabel('Characteristic time (us)')

plt.figure()
plt.plot(UVpotVec, Offsets_v2,'o')

#%%
"""
FIGURA PAPER
"""
import matplotlib
import seaborn as sns

matplotlib.rcParams['mathtext.fontset'] = 'stix'
matplotlib.rcParams['font.family'] = 'STIXGeneral'
plt.style.use('seaborn-bright')
plt.rcParams.update({
    "text.usetex": False,
})

jselected = [1, 5, 12]

t0=0.18


s1 = 0
s2 = 700
s3 = 2*s2

kini = 75

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

color3 = colors[0]
color2 = colors[3]
color1 = colors[8]


plt.figure(figsize=(3.5,3))
plt.plot([f*1e6-t0 for f in SP_Bins[jselected[0]][:-1]], [s+s1 for s in SP_Heigths[jselected[0]]],color=color1,alpha=0.7)
plt.plot([r-t0 for r in RefBins[kini:]], [expo(r, *popt_vec[jselected[0]])+s1 for r in RefBins[kini:]],color=color1)
plt.plot([f*1e6-t0 for f in SP_Bins[jselected[0]][:-1]], [s+s2 for s in SP_Heigths[jselected[1]]],color=color2,alpha=0.7)
plt.plot([r-t0 for r in RefBins[kini:]], [expo(r, *popt_vec[jselected[1]])+s2 for r in RefBins[kini:]],color=color2)
plt.plot([f*1e6-t0 for f in SP_Bins[jselected[0]][:-1]], [s+s3 for s in SP_Heigths[jselected[2]]],color=color3,alpha=0.7)
plt.plot([r-t0 for r in RefBins[kini:]], [expo(r, *popt_vec[jselected[2]])+s3 for r in RefBins[kini:]],color=color3)
plt.xlim(-0.3,2)
plt.xlabel('Time (us)', fontname='STIXGeneral', fontsize=14)
plt.ylabel('Counts', fontname='STIXGeneral', fontsize=14)
plt.xticks([0, 0.5, 1, 1.5, 2], fontsize=12)
plt.yticks([0, 1000, 2000, 3000, 4000], fontsize=12)
plt.grid()
plt.savefig('fig3_01.pdf')
plt.savefig('fig3_01.svg')


        #%%

"""
VEMOS UNA DP CON POTENCIA ALTA A VER SI DA LO QUE TIENE QUE DAR EL ANCHO DE LINEA
"""

BinsIRhigh = [t*1e6 for t in DP_Bins[-1][:-1]]
HeightsIRhigh = DP_Heigths[-1]


from scipy.optimize import curve_fit

def expo(T, tau, N0, C, T0):
    return N0*np.exp(-(T-T0)/tau) + C

popt_IR, pcov_IR = curve_fit(expo, BinsIRhigh[int(0.1*len(BinsIRhigh)):], HeightsIRhigh[int(0.1*len(BinsIRhigh)):], p0=(5, 100, 200, 1))

plt.figure()
plt.plot(BinsIRhigh, HeightsIRhigh)
plt.plot(BinsIRhigh, [expo(r, *popt_IR) for r in BinsIRhigh])

tauIR = popt_IR[0]
print(tauIR)


#%%

"""
VEMOS UNA SP CON POTENCIA ALTA A VER SI DA LO QUE TIENE QUE DAR EL ANCHO DE LINEA
"""

# k=5
# BinsUVhigh = [t*1e6 for t in Long_Bins[k][:-1]]
# HeightsUVhigh = Long_Heigths[k]


k=-3

BinsUVhigh = [t*1e6 for t in SP_Bins[k][:-1]]
HeightsUVhigh = SP_Heigths[k]


from scipy.optimize import curve_fit

def expo(T, tau, N0, C, T0):
    return N0*np.exp(-(T-T0)/tau) + C

initi=0.10

popt_UV, pcov_UV = curve_fit(expo, BinsUVhigh[int(initi*len(BinsUVhigh)):], HeightsUVhigh[int(initi*len(BinsUVhigh)):], p0=(1, 1000, 1800, 1), bounds=((0,0,0,0),(20, 1e7, 1e5, 1e3)))

plt.figure()
plt.plot(BinsUVhigh, HeightsUVhigh,linewidth=4)
plt.plot(BinsUVhigh[80:], [expo(r, *popt_UV) for r in BinsUVhigh][80:], color='fuchsia', linewidth=3, label='Exponential fit')
#plt.plot(BinsUVhigh[int(initi*len(BinsUVhigh))], HeightsUVhigh[int(initi*len(BinsUVhigh))],'o',markersize=5)
#plt.ylim(-1000,20000)
plt.grid()
plt.xlabel(r'Time ($\mu$s)', fontsize=15)
plt.ylabel('Counts', fontsize=15)
plt.xlim(-0.5, 5)
plt.legend(fontsize=15)

tauUV = popt_UV[0]
print(tauUV)