Skip to content
Transitorios_02.py 11.7 KiB
Newer Older
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
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
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#os.chdir('/home/nico/Documents/artiq_experiments/analisis/plots/20221006_transitoriosv2')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
# Solo levanto algunos experimentos
SP_files = [8445, 8457, 8458, 8459, 8460, 8461, 8462, 8463, 8464, 8465, 8466, 8467, 8468, 8469, 84840, 88040]
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
SP_files_v2 = [8763, 8764, 8765, 8766, 8767, 8768, 8769, 8770, 8771, 8772, 8773, 8774, 8775, 8776]
DP_files = [8472, 8473, 8474, 8475, 8476, 8477, 8478, 8479, 8480, 8481, 8482, 8749]
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
Long_files = ['DP_long', 'SP_long', 'DP_long_v2', 'DP_long_v3', 'DP_long_new', 'SP_long_new']
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
Calib_files = ['Cal_DP_5M', 'Cal_SP_5M', 'Cal_DP_25M', 'Cal_SP_25M']

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
Random_files = [8749]

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
def expo(T, tau, N0, C):
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    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]

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

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

    

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

BINW = 10e-9
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
T0 = -0.4e-6
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

SP_Heigths = []
SP_Bins = []

for i, fname in enumerate(SP_files):
    #print(i)
    #print(fname)
    data = h5py.File('Data/SP/00000'+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)
    
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
SP_Heigths_v2 = []
SP_Bins_v2 = []

for i, fname in enumerate(SP_files_v2):
    #print(i)
    #print(fname)
    data = h5py.File('Data/SP/00000'+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_v2.append(heigs)
    SP_Bins_v2.append(binsf)    

    
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
DP_Heigths = []
DP_Bins = []

for i, fname in enumerate(DP_files):
    #print(i)
    #print(fname)
    data = h5py.File('Data/DP/00000'+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])
    
    DP_Heigths.append(heigs)
    DP_Bins.append(binsf)    


Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
BINW_long = 10e-9
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
T0_long = -0.4e-6
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

Long_Heigths = []
Long_Bins = []

for i, fname in enumerate(Long_files):
    #print(i)
    #print(fname)
    data = h5py.File('Data/Largas/'+str(fname)+'.h5', 'r')
    counts = np.array(data['datasets']['counts'])
    bines = np.arange(counts.min(), counts.max()+BINW_long, BINW_long)

    heigs, binsf  = np.histogram(counts, bines[bines>T0_long])
    
    Long_Heigths.append(heigs)
    Long_Bins.append(binsf) 

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

BINW_calib = 10e-9
T0_calib = -0.4e-6

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
Calib_Heigths = []
Calib_Bins = []

for i, fname in enumerate(Calib_files):
    #print(i)
    #print(fname)
    data = h5py.File('Data/Calibrations/'+str(fname)+'.h5', 'r')
    counts = np.array(data['datasets']['counts'])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    bines = np.arange(counts.min(), counts.max()+BINW_calib, BINW_calib)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    heigs, binsf  = np.histogram(counts, bines[bines>T0_calib])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    
    Calib_Heigths.append(heigs)
    Calib_Bins.append(binsf) 

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
BINW_Random = 10e-9
T0_Random = -0.5e-6


Random_Heigths = []
Random_Bins = []

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

    heigs, binsf  = np.histogram(counts, bines[bines>T0_Random])
    
    Random_Heigths.append(heigs)
    Random_Bins.append(binsf) 
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed


#plt.figure()
#plt.plot([t*1e6 for t in TotalBins[12][:-1]], TotalHeights[12],'o')

#%%
"""
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()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
for Height in SP_Heigths[:-1]:
    print(len(Height))
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    plt.plot(RefBins, Height)
    
plt.xlim(-0.2, 3)

#%%

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
Esto mira las curvas SP y les hace ajustes exponenciales a la ultima parte para plotear
el tiempo caracteristico
"""

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

"""
Primer detuning
"""

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
bkgrvec = Calib_Bins[3][:-1]

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

ErrorTaus = []

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

popt_vec = []
pcov_vec = []

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.figure()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
for j in range(len(SP_Heigths)-1):
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#for j in [12]:
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    print(j)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    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))]
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    
    CorrectedSP_Height = SP_Heigths[j]
    
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    popt, pcov = curve_fit(expo, RefBins[90:], CorrectedSP_Height[90:], p0=(5, 1000, 100))
    popt_vec.append(popt)
    pcov_vec.append(pcov)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    plt.plot(RefBins, CorrectedSP_Height)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    plt.plot(RefBins[90:], [expo(r, *popt) for r in RefBins][90:])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    Taus.append(popt[0])
    Amps.append(popt[1])
    Offsets.append(popt[2])
    ErrorTaus.append(np.sqrt(pcov)[0][0])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
TESIS
"""

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.figure()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
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()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

#%%
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.figure()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.plot(UVpotVec, Amps[:-1],'o')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.xlabel('UV power (mW)')
plt.ylabel('Characteristic time (us)')

plt.figure()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.plot(UVpotVec, Offsets[:-1],'o')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed


#%%
"""
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,
})

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.figure()
plt.plot(Stat_Bins[0][:-1], Stat_Heigths[0])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

#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 = []


Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
selectedj = [2,5,10]
t0 = -0.2

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.figure()
for j in range(len(SP_Heigths_v2)):
#for j in [1]:
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    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])
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
    
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.xlim(-0.2,2)

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#%%

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)')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.figure()
plt.plot(UVpotVec, Offsets_v2,'o')
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#%%
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
TESIS
"""

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
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,
})
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

jselected = [1, 5, 12]

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
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()
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
plt.savefig('fig3_01.pdf')
plt.savefig('fig3_01.svg')

Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
#%%
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
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]
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

from scipy.optimize import curve_fit
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

def expo(T, tau, N0, C, T0):
    return N0*np.exp(-(T-T0)/tau) + C
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

popt_IR, pcov_IR = curve_fit(expo, BinsIRhigh[int(0.1*len(BinsIRhigh)):], HeightsIRhigh[int(0.1*len(BinsIRhigh)):], p0=(5, 100, 200, 1))
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

plt.figure()
plt.plot(BinsIRhigh, HeightsIRhigh)
plt.plot(BinsIRhigh, [expo(r, *popt_IR) for r in BinsIRhigh])
tauIR = popt_IR[0]
print(tauIR)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
VEMOS UNA SP CON POTENCIA ALTA A VER SI DA LO QUE TIENE QUE DAR EL ANCHO DE LINEA
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
"""
# k=5
# BinsUVhigh = [t*1e6 for t in Long_Bins[k][:-1]]
# HeightsUVhigh = Long_Heigths[k]
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

BinsUVhigh = [t*1e6 for t in SP_Bins[k][:-1]]
HeightsUVhigh = SP_Heigths[k]
from scipy.optimize import curve_fit
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed

def expo(T, tau, N0, C, T0):
    return N0*np.exp(-(T-T0)/tau) + C
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)))
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
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)
Nicolas Nunez Barreto's avatar
Nicolas Nunez Barreto committed
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)