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
#Mediciones barriendo angulo del TISA y viendo kicking de resonancias oscuras
#C:\Users\Usuario\Documents\artiq\artiq_experiments\analisis\plots\20220106_CPT_DosLaseres_v08_TISA_DR\Data
os.chdir('/home/nico/Documents/artiq_experiments/analisis/plots/20230817_RotationalDopplerShift_v5/Data')
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
en este codigo ploteo espectros CPT de resonancias D-D para configuracion +2/+2 y +2/-2 (usando pentaprisma)
"""
def find_nearest(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return idx
def Split(array,n):
length=len(array)/n
splitlist = []
jj = 0
while jj<length:
partial = []
ii = 0
while ii < n:
partial.append(array[jj*n+ii])
ii = ii + 1
splitlist.append(partial)
jj = jj + 1
return splitlist
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()))
Piezo1Counts = []
Piezo1Frequencies = []
PIEZO1_FILES = np.arange(791, 826,1)
for i in PIEZO1_FILES:
#print(str(i) + ' - ' + fname)
data = h5py.File(f'VaryingBeamlocation/Piezo/000014{i}-IR_Scan_withcal_optimized'+'.h5', 'r')
Piezo1Counts.append(np.array(data['datasets']['counts_spectrum']))
Piezo1Frequencies.append(np.array(data['datasets']['IR1_Frequencies']))
Piezo2Counts = []
Piezo2Frequencies = []
PIEZO2_FILES = list(np.arange(834, 841,1))+list(np.arange(842, 872,1))
for i in PIEZO2_FILES:
#print(str(i) + ' - ' + fname)
data = h5py.File(f'VaryingBeamlocation/Piezo2/000014{i}-IR_Scan_withcal_optimized'+'.h5', 'r')
Piezo2Counts.append(np.array(data['datasets']['counts_spectrum']))
Piezo2Frequencies.append(np.array(data['datasets']['IR1_Frequencies']))
def ErrorDRdepth(p, f, b):
ep = np.sqrt(p)
ef = np.sqrt(f)
eb = np.sqrt(b)
derivadap = 1/((f-b)**2)
derivadaf = ((p-b)/((f-b)**2))**2
derivadab = ((p-f)/((f-b)**2))**2
return 1*np.sqrt(derivadap*ep*ep + derivadaf*ef*ef + derivadab*eb*eb)
def Lorentzian( x, A, B, x0, gam,C):
#C=0
return A * gam**2 / ( gam**2 + ( x - x0 )**2) + B - C*(x - x0)
Resonancias DD configuracion -2/-2 colineal variando la ubicacion del ion en los haces
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
TODO EL OAM
"""
palette = sns.color_palette("tab10")
pmlocmedvec = list(np.arange(0,12,1))+[13,12]+list(np.arange(15,len(PIEZO1_FILES),1))
"""
Hay que invertir la 12 con la 13, y la 14 es la misma que la 12, por las dudas
"""
#pmlocmedvec = [21]
idxvecdr = [85,185, 185,182,182,232, 162,162,175,177,217, 217,184,184,188,186,186,195,195,198,195,198,196,192,192,192,178,175,175,170,140,140,190,185]
plt.figure()
bkg = np.min(Piezo1Counts[1])
pmdepthsdr=[]
errorpmdepthsdr=[]
Intensity = []
errorIntensity = []
idxtest = 185
print(idxtest)
jj=0
for med in pmlocmedvec:
print(med)
if med == 21 or med == 22 or med == 23:
pmdepthsdr.append(1-(Piezo1Counts[med][1:][idxvecdr[jj]]-bkg)/(np.mean(Piezo1Counts[med][1:][0:20])-bkg))
errorpmdepthsdr.append(ErrorDRdepth(Piezo1Counts[med][1:][idxvecdr[jj]],np.mean(Piezo1Counts[med][1:][0:20]), bkg))
Intens = np.mean(Piezo1Counts[med][1:][0:10])-bkg
Intensity.append(Intens)
errorIntensity.append(2*np.sqrt(np.mean(Piezo1Counts[med][1:][0:10]))+np.sqrt(bkg))
else:
pmdepthsdr.append(1-(Piezo1Counts[med][1:][idxvecdr[jj]]-bkg)/(np.mean(Piezo1Counts[med][1:][0:20])-bkg))
errorpmdepthsdr.append(ErrorDRdepth(Piezo1Counts[med][1:][idxvecdr[jj]],np.mean(Piezo1Counts[med][1:][0:20]), bkg))
Intens = np.mean(Piezo1Counts[med][1:][0:20])-bkg
Intensity.append(Intens)
errorIntensity.append(2*np.sqrt(np.mean(Piezo1Counts[med][1:][0:20]))+np.sqrt(bkg))
plt.plot([2*f*1e-6 for f in Piezo1Frequencies[med][1:]], [c for c in Piezo1Counts[med][1:]], '-o', markersize=2, alpha=0.7)
plt.plot([2*f*1e-6 for f in Piezo1Frequencies[med][1:]][idxtest], [c for c in Piezo1Counts[med][1:]][idxtest], 'o',markersize=14)
jj=jj+1
# plt.xlabel('Frecuencia (MHz)')
# plt.ylabel('Counts')
# plt.xlim(432, 446.5)
# plt.grid()
# plt.legend()
# #plt.title('Espectros para distintas geometrías')
159
160
161
162
163
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
plt.figure()
plt.errorbar(np.arange(0,len(Intensity),1), [i/np.max(Intensity) for i in Intensity], yerr=[i/np.max(Intensity) for i in errorIntensity], fmt='o',capsize=2, markersize=8)
plt.errorbar(np.arange(0,len(Intensity),1), [p for p in pmdepthsdr], yerr=errorpmdepthsdr, fmt='o',capsize=2, markersize=8)
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.xticks([1,2,3,4,5])
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
#%%
import seaborn as sns
"""
Resonancias DD configuracion +2/-2 colineal variando la ubicacion del ion en los haces
Mismo analisis pero con fiteos
"""
palette = sns.color_palette("tab10")
pmlocmedvec = list(np.arange(0,12,1))+[13,12]+list(np.arange(15,len(PIEZO1_FILES),1))
"""
Hay que invertir la 12 con la 13, y la 14 es la misma que la 12, por las dudas
"""
#pmlocmedvec = [30]
plt.figure()
bkg = np.min(Piezo1Counts[1])
pmdepthsdr=[]
errorpmdepthsdr=[]
Intensity = []
errorIntensity = []
idxtest = 185
print(idxtest)
Gamas = []
ErrorGamas = []
jj=0
for med in pmlocmedvec:
print(med)
Freqs = [2*f*1e-6 for f in Piezo1Frequencies[med][1:]]
Counts = [c for c in Piezo1Counts[med][1:]]
if med==30:
Freqs=Freqs[90:]
Counts=Counts[90:]
popt, pcov = curve_fit(Lorentzian, np.array(Freqs), np.array(Counts), p0=(-200,2100,435.8,0.05,0.1), bounds=((-10000,0,435.5,0,0),(0,1e4, 436.1, 1,1e4)))
else:
popt, pcov = curve_fit(Lorentzian, np.array(Freqs), np.array(Counts), p0=(-200,2100,435.8,0.05,0.1), bounds=((-10000,0,435.5,0,0),(0,1e4, 436.1, 1,1e4)))
pmdepthsdr.append(1-(np.min(Lorentzian(np.array(Freqs),*popt))-bkg)/(popt[1]-bkg))
#pmdepthsdr.append(1-(Piezo1Counts[med][1:][idxvecdr[jj]]-bkg)/(np.mean(Piezo1Counts[med][1:][0:20])-bkg))
#errorpmdepthsdr.append(ErrorDRdepth(Piezo1Counts[med][1:][idxvecdr[jj]],np.mean(Piezo1Counts[med][1:][0:20]), bkg))
errorpmdepthsdr.append(ErrorDRdepth(np.min(Lorentzian(Freqs,*popt)),popt[1], bkg))
Intens = popt[1]
Gamas.append(popt[3])
ErrorGamas.append(np.sqrt(pcov[3,3]))
Intensity.append(Intens)
errorIntensity.append(2*np.sqrt(np.mean(Piezo1Counts[med][1:][0:20]))+np.sqrt(bkg))
plt.plot([2*f*1e-6 for f in Piezo1Frequencies[med][1:]], [c for c in Piezo1Counts[med][1:]], '-o', markersize=2, alpha=0.7)
plt.plot([f*1 for f in Freqs],Lorentzian(Freqs,*popt))
#plt.plot([2*f*1e-6 for f in Piezo1Frequencies[med][1:]][idxtest], [c for c in Piezo1Counts[med][1:]][idxtest], 'o',markersize=14)
jj=jj+1
# plt.xlabel('Frecuencia (MHz)')
# plt.ylabel('Counts')
# plt.xlim(432, 446.5)
# plt.grid()
# plt.legend()
# #plt.title('Espectros para distintas geometrías')
plt.figure()
plt.errorbar(np.arange(0,len(Intensity),1), [i/np.max(Intensity) for i in Intensity], yerr=[i/np.max(Intensity) for i in errorIntensity], fmt='o',capsize=2, markersize=8)
plt.errorbar(np.arange(0,len(Intensity),1), [p for p in pmdepthsdr], yerr=errorpmdepthsdr, fmt='o',capsize=2, markersize=8)
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.xticks([1,2,3,4,5])
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
#%%
import seaborn as sns
"""
Resonancias DD configuracion +2/+2 colineal variando la ubicacion del ion en los haces
TODO EL OAM
272
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
"""
palette = sns.color_palette("tab10")
mmlocmedvec = list(np.arange(0,10,1))+[11,10]+list(np.arange(12,len(PIEZO2_FILES),1))
"""
s
"""
#mmlocmedvec = [18]
#idxvecdr = [126,129,129,129,128,128,216,215,215,215,242,215,162,162,162,162,162,132,138,129,242,182,182,208,205,205,205,181,140,170,140,140,140,138,128,128,126,]
idxvecdr = [126,129,129,129,128,128,216,215,215,215,242,215,162,162,162,162,162,132,132,129,242,182,182,208,205,205,205,181,140,170,140,140,140,138,128,128,126,]
#idxtest = idxvecdr[18]
plt.figure()
bkg = np.min(Piezo2Counts[1])
mmdepthsdr=[]
errormmdepthsdr=[]
Intensity2 = []
errorIntensity2 = []
print(idxtest)
jj=0
for med in mmlocmedvec:
print(med)
mmdepthsdr.append(1-(Piezo2Counts[med][1:][idxvecdr[jj]]-bkg)/(np.mean(Piezo2Counts[med][1:][0:20])-bkg))
errormmdepthsdr.append(ErrorDRdepth(Piezo2Counts[med][1:][idxvecdr[jj]],np.mean(Piezo2Counts[med][1:][0:20]), bkg))
Intens = np.mean(Piezo2Counts[med][1:][0:20])-bkg
Intensity2.append(Intens)
errorIntensity2.append(2*np.sqrt(np.mean(Piezo2Counts[med][1:][0:20]))+np.sqrt(bkg))
plt.plot([2*f*1e-6 for f in Piezo2Frequencies[med][1:]], [c for c in Piezo2Counts[med][1:]], '-o', markersize=2, alpha=0.7)
plt.plot([2*f*1e-6 for f in Piezo2Frequencies[med][1:]][idxtest], [c for c in Piezo2Counts[med][1:]][idxtest], 'o',markersize=14)
jj=jj+1
# plt.xlabel('Frecuencia (MHz)')
# plt.ylabel('Counts')
# plt.xlim(432, 446.5)
# plt.grid()
# plt.legend()
# #plt.title('Espectros para distintas geometrías')
plt.figure()
#plt.errorbar(np.arange(0,len(Intensity2),1), [i/np.max(Intensity2) for i in Intensity2], yerr=[i/np.max(Intensity2) for i in errorIntensity2], fmt='o',capsize=2, markersize=8)
plt.errorbar(np.arange(0,len(Intensity2),1), [p for p in mmdepthsdr], yerr=errormmdepthsdr, fmt='o',capsize=2, markersize=8)
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.xticks([1,2,3,4,5])
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
#%%
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
import seaborn as sns
"""
Resonancias DD configuracion +2/+2 colineal variando la ubicacion del ion en los haces
TODO EL OAM
AHORA CON FITEOS LPM
"""
palette = sns.color_palette("tab10")
mmlocmedvec = list(np.arange(0,10,1))+[11,10]+list(np.arange(12,len(PIEZO2_FILES),1))
"""
s
"""
plotcurvita=1
#mmlocmedvec = [37]
plt.figure()
bkg = np.min(Piezo2Counts[1])
mmdepthsdr=[]
errormmdepthsdr=[]
Intensity2 = []
errorIntensity2 = []
print(idxtest)
jj=0
for med in mmlocmedvec:
print(med)
Freqs = [2*f*1e-6 for f in Piezo2Frequencies[med][1:]]
Counts = [c for c in Piezo2Counts[med][1:]]
if med==18:
popt, pcov = curve_fit(Lorentzian, np.array(Freqs), np.array(Counts), p0=(-200,210,435.8,0.05,0.1), bounds=((-10000,0,435.5,0,0),(0,1e4, 436.1, 1,1e4)))
else:
popt, pcov = curve_fit(Lorentzian, np.array(Freqs), np.array(Counts), p0=(-200,2100,435.8,0.05,0.1), bounds=((-10000,0,435.5,0,0),(0,1e4, 436.1, 1,1e4)))
mmdepthsdr.append(1-(np.min(Lorentzian(np.array(Freqs),*popt))-bkg)/(popt[1]-bkg))
errormmdepthsdr.append(ErrorDRdepth(np.min(Lorentzian(Freqs,*popt)),popt[1], bkg))
Intens = popt[1]
Gamas.append(popt[3])
ErrorGamas.append(np.sqrt(pcov[3,3]))
Intensity2.append(Intens)
errorIntensity.append(2*np.sqrt(np.mean(Piezo2Counts[med][1:][0:20]))+np.sqrt(bkg))
plt.plot([2*f*1e-6 for f in Piezo2Frequencies[med][1:]], [c for c in Piezo2Counts[med][1:]], '-o', markersize=2, alpha=0.7)
plt.plot([f*1 for f in Freqs],Lorentzian(Freqs,*popt))
# plt.plot([2*f*1e-6 for f in Piezo2Frequencies[med][1:]], [c for c in Piezo2Counts[med][1:]], '-o', markersize=2, alpha=0.7)
# plt.plot([2*f*1e-6 for f in Piezo2Frequencies[med][1:]][idxtest], [c for c in Piezo2Counts[med][1:]][idxtest], 'o',markersize=14)
jj=jj+1
# plt.xlabel('Frecuencia (MHz)')
# plt.ylabel('Counts')
# plt.xlim(432, 446.5)
# plt.grid()
# plt.legend()
# #plt.title('Espectros para distintas geometrías')
if plotcurvita:
plt.figure()
#plt.errorbar(np.arange(0,len(Intensity2),1), [i/np.max(Intensity2) for i in Intensity2], yerr=[i/np.max(Intensity2) for i in errorIntensity2], fmt='o',capsize=2, markersize=8)
plt.errorbar(np.arange(0,len(Intensity2),1), [p for p in mmdepthsdr], yerr=errormmdepthsdr, fmt='o',capsize=2, markersize=8)
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.xticks([1,2,3,4,5])
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
#%%
"""
graficos de:
1) intensidad del haz
2) profundidad de las resonancias en caso +2/+2 y en caso +2/-2
"""
import seaborn as sns
paletadenico=sns.color_palette('rocket')
plt.errorbar(np.arange(-16,18,1), [i/np.max(Intensity) for i in Intensity], yerr=[i/np.max(Intensity) for i in errorIntensity], fmt='o',capsize=2, markersize=8,color=paletadenico[1])
#plt.errorbar(np.arange(0,len(Intensity),1), [p for p in pmdepthsdr], yerr=errorpmdepthsdr, fmt='o',capsize=2, markersize=8)
#plt.errorbar(np.arange(0,len(Intensity),1), [p for p in mmdepthsdr[3:]], yerr=[0.5*m for m in errormmdepthsdr[3:]], fmt='o',capsize=2, markersize=8)
plt.xlabel('Distance to center (motor steps)', fontname='STIXgeneral',fontsize=15)
plt.ylabel('Beam intensity', fontname='STIXgeneral',fontsize=15)
plt.xticks([-15,-10,-5,0,5,10,15], fontname='STIXgeneral',fontsize=15)
plt.yticks([0,0.2,0.4,0.6,0.8,1], fontname='STIXgeneral',fontsize=15)
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
plt.tight_layout()
plt.savefig('/home/nico/Nextcloud/Nico/Doctorado/Charlas/2023 Europe/beamintensityradial.pdf')
plt.figure()
#plt.errorbar(np.arange(0,len(Intensity),1), [i/np.max(Intensity) for i in Intensity], yerr=[i/np.max(Intensity) for i in errorIntensity], fmt='o',capsize=2, markersize=8)
plt.errorbar(np.arange(-16,18,1), [p for p in pmdepthsdr], yerr=errorpmdepthsdr, fmt='o',capsize=2, markersize=8,color=paletadenico[3])
plt.errorbar(np.arange(-16,18,1), [p for p in mmdepthsdr[2:-1]], yerr=[1*m for m in errormmdepthsdr[2:-1]], fmt='o',capsize=2, markersize=8,color=paletadenico[0])
plt.xlabel('Distance to center (motor steps)', fontname='STIXgeneral',fontsize=15)
plt.ylabel('DR Relative depth', fontname='STIXgeneral',fontsize=15)
plt.xticks([-15,-10,-5,0,5,10,15], fontname='STIXgeneral',fontsize=15)
plt.yticks([0,0.2,0.4,0.6,0.8,1], fontname='STIXgeneral',fontsize=15)
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
plt.tight_layout()
plt.savefig('/home/nico/Nextcloud/Nico/Doctorado/Charlas/2023 Europe/depthsradial.pdf')
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#%%
"""
Intento ajustar un modelo para la profundidad
"""
def FunctionTarget(x,x0,A):
return (A/(1+(x0/x)**2))**1
lim=10
xvec = np.arange(0,len(Intensity),1)-15.5
xveclong = np.arange(np.min(xvec)-lim, np.max(xvec)+lim,0.01)
popt,pcov=curve_fit(FunctionTarget,xvec,pmdepthsdr)
plt.figure()
plt.errorbar(xvec, pmdepthsdr, yerr=errorpmdepthsdr, fmt='o',capsize=2, markersize=8)
#plt.plot(xveclong,FunctionTarget(xveclong,*popt))
plt.plot(xveclong,FunctionTarget(xveclong,5.93,0.83))
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
print(popt)
#%%
"""
Ahora voy a intentar ajustarlas con una lorentziana que es mejor
"""
import seaborn as sns
"""
Resonancias DD configuracion +2/-2 colineal variando la ubicacion del ion en los haces
TODO EL OAM
"""
def Lorentzian( x, A, B, x0, gam ):
return A * gam**2 / ( gam**2 + ( x - x0 )**2) + B
palette = sns.color_palette("tab10")
pmlocmedvec = list(np.arange(0,12,1))+[13,12]+list(np.arange(15,len(PIEZO1_FILES),1))
"""
Hay que invertir la 12 con la 13, y la 14 es la misma que la 12, por las dudas
"""
#pmlocmedvec = [35]
plt.figure()
bkg = np.min(Piezo1Counts[1])
pmdepthsdr=[]
errorpmdepthsdr=[]
Intensity = []
errorIntensity = []
idxtest = 185
print(idxtest)
jj=0
for med in pmlocmedvec:
Freqs = [2*f*1e-6 for f in Piezo1Frequencies[med][1:]]
Counts = [c for c in Piezo1Counts[med][1:]]
if med==30:
Freqs = Freqs[100:]
Counts = Counts[100:]
popt, pcov = curve_fit(Lorentzian, Freqs, Counts, p0=(-200,2100,435.8,0.05), bounds=((-10000,0,435.7,0),(0,1e4, 436.1, 1)))
else:
popt, pcov = curve_fit(Lorentzian, Freqs, Counts, p0=(-200,2100,435.8,0.05), bounds=((-10000,0,435.5,0),(0,1e4, 436.1, 1)))
pmdepthsdr.append(1-(np.min(Lorentzian(Freqs,*popt))-bkg)/(popt[1]-bkg))
errorpmdepthsdr.append(ErrorDRdepth(np.min(Lorentzian(Freqs,*popt)),popt[1], bkg))
Intens = popt[1]
Intensity.append(Intens)
# errorIntensity.append(2*np.sqrt(np.mean(Piezo1Counts[med][1:][0:20]))+np.sqrt(bkg))
if med in [8,21,25]:
plt.plot([2*f*1e-6 for f in Piezo1Frequencies[med][1:]], [c for c in Piezo1Counts[med][1:]], '-o', markersize=2, alpha=0.7)
plt.plot(Freqs,Lorentzian(Freqs,*popt))
jj=jj+1
# plt.xlabel('Frecuencia (MHz)')
# plt.ylabel('Counts')
plt.xlim(435.2, 436.5)
plt.grid()
# plt.legend()
# #plt.title('Espectros para distintas geometrías')
plt.figure()
plt.plot(np.arange(0,len(Intensity),1), [i/np.max(Intensity) for i in Intensity], '-o',markersize=8)
plt.plot(np.arange(0,len(Intensity),1), [p for p in pmdepthsdr], 'o',markersize=8)
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.xticks([1,2,3,4,5])
#plt.xlim(200,3200)
plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
#%%
"""
Intento ajustar un modelo para la profundidad
"""
def FunctionTarget(x,x0,A):
return (A/(1+(x0/x)**2))**1
lim=10
xvec = np.arange(0,len(Intensity),1)-15.5
xveclong = np.arange(np.min(xvec)-lim, np.max(xvec)+lim,0.01)
popt,pcov=curve_fit(FunctionTarget,xvec,pmdepthsdr)
plt.figure()
plt.errorbar(xvec, pmdepthsdr, yerr=errorpmdepthsdr, fmt='o',capsize=2, markersize=8)
#plt.plot(xveclong,FunctionTarget(xveclong,*popt))
plt.plot(xveclong,FunctionTarget(xveclong,5.93,0.83))
plt.xlabel('Ion position')
plt.ylabel('Intensity / DR Relative depth')
#plt.ylim(-0.1,1.1)
plt.grid()
#plt.axvline(3, color='salmon')
plt.legend()
print(popt)