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
os.chdir('/home/nico/Documents/artiq_experiments/analisis/plots/20221006_transitoriosv2')
SP_files = [8445, 8457, 8458, 8459, 8460, 8461, 8462, 8463, 8464, 8465, 8466, 8467, 8468, 8469, 84840, 88040]
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]
Long_files = ['DP_long', 'SP_long', 'DP_long_v2', 'DP_long_v3', 'DP_long_new', 'SP_long_new']
Calib_files = ['Cal_DP_5M', 'Cal_SP_5M', 'Cal_DP_25M', 'Cal_SP_25M']
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 = 10e-9
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)
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)
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)
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)
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'])
bines = np.arange(counts.min(), counts.max()+BINW_calib, BINW_calib)
heigs, binsf = np.histogram(counts, bines[bines>T0_calib])
Calib_Heigths.append(heigs)
Calib_Bins.append(binsf)
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)
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#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()
for Height in SP_Heigths:
plt.plot(RefBins, Height)
plt.xlim(-0.2, 3)
#%%
"""
Esto mira las curvas SP y les hace ajustes exponenciales a la ultima parte para plotear
el tiempo caracteristico
"""
bkgrvec = Calib_Bins[3][:-1]
Taus = []
Amps = []
Offsets = []
ErrorTaus = []
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))]
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[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])
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])
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#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 = []
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.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)')
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,
})
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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.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]
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
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.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)