1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
81
82
83
84
85
86
87
88
89
90
91
92
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
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
251
252
253
254
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 de una resonancia oscura DD multiples veces a lo largo de una noche para ver estabilidad de B
"""
#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/20231212_Bstability/Data/')
CPT_FILES = """000016432-IR_Scan_withcal_optimized
000016433-IR_Scan_withcal_optimized
000016434-IR_Scan_withcal_optimized
000016435-IR_Scan_withcal_optimized
000016436-IR_Scan_withcal_optimized
000016437-IR_Scan_withcal_optimized
000016438-IR_Scan_withcal_optimized
000016439-IR_Scan_withcal_optimized
000016440-IR_Scan_withcal_optimized
000016441-IR_Scan_withcal_optimized
000016442-IR_Scan_withcal_optimized
000016443-IR_Scan_withcal_optimized
"""
CALIB_FILES = """000016430-IR_Scan_withcal_optimized"""
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()))
print(SeeKeys(CPT_FILES))
#carpeta pc nico labo escritorio:
#C:\Users\Usuario\Documents\artiq\artiq_experiments\analisis\plots\20211101_CPT_DosLaseres_v03\Data
Counts = []
Freqs = []
CalibCounts = []
CalibFreqs = []
AmpTisa = []
UVCPTAmp = []
No_measures = []
Voltages = []
for i, fname in enumerate(CPT_FILES.split()):
print(str(i) + ' - ' + fname)
#print(fname)
data = h5py.File(fname+'.h5', 'r') # Leo el h5: Recordar que nuestros datos estan en 'datasets'
# Aca hago algo repugnante para poder levantar los strings que dejamos
# que además tenian un error de tipeo al final. Esto no deberá ser necesario
# cuando se solucione el error este del guardado.
Freqs.append(np.array(data['datasets']['IR1_Frequencies']))
Counts.append(np.array(data['datasets']['data_array']))
#AmpTisa.append(np.array(data['datasets']['TISA_CPT_amp']))
UVCPTAmp.append(np.array(data['datasets']['UV_CPT_amp']))
No_measures.append(np.array(data['datasets']['no_measures']))
Voltages.append(np.array(data['datasets']['scanning_voltages']))
for i, fname in enumerate(CALIB_FILES.split()):
print(str(i) + ' - ' + fname)
data = h5py.File(fname+'.h5', 'r') # Leo el h5: Recordar que nuestros datos estan en 'datasets'
CalibFreqs.append(np.array(data['datasets']['IR1_Frequencies']))
CalibCounts.append(np.array(data['datasets']['counts_spectrum']))
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
CountsSplit = []
k=0
for k in range(len(Counts)):
CountsSplit.append(Split(Counts[k],len(Freqs[k])))
#%%
from scipy.optimize import curve_fit
def lorentzian(x,A,B,x0,g,C):
return 2*(A/np.pi)*g/(g**2 + 4*(x-x0)**2)+B+C*(x-x0)
Freqscal = [2*f*1e-6 for f in CalibFreqs[0]]
Countscal = CalibCounts[0]
popt_dr1, pcov_dr1 = curve_fit(lorentzian,Freqscal[37:47],Countscal[37:47],p0=(-1000,1000,436,1,1))
popt_dr2, pcov_dr2 = curve_fit(lorentzian,Freqscal[90:120],Countscal[90:120],p0=(-1000,1000,443,1,1))
DeltaFreqs = popt_dr2[2]-popt_dr1[2]
ZeroFrequency = 0.5*(popt_dr2[2]+popt_dr1[2])
plt.figure()
plt.plot(Freqscal,Countscal,'o')
plt.plot(Freqscal,lorentzian(Freqscal,*popt_dr1))
plt.plot(Freqscal,lorentzian(Freqscal,*popt_dr2))
plt.axvline(ZeroFrequency)
print(DeltaFreqs)
"""
Estas cuentas estan en el cuaderno SMILE MORE WORRY LESS pag 25.
La resonancia de la izquierda esta a (-4/5)*u. La de la derecha esta a (4/5)*u.
Por ende la diferencia es (8/5)*u.
Definimos u como 1.4 MHz/G * B. Entonces Despejamos B facilmente.
"""
ub = 9.27e-24
h = 6.63e-34
u = 1e-6*(ub/h)*1e-4 #en unidades de MHz/G
MagneticField = DeltaFreqs/((8/5)*u)
print(f'Magnetic field: {MagneticField}')
#%%
"""
Ploteo la cpt de referencia / plotting the reference CPT
"""
freqs = [2*f*1e-6 for f in Freqs[0]]
def lorentzian(x,A,B,x0,g,C):
return 2*(A/np.pi)*g/(g**2 + 4*(x-x0)**2)+B+C*(x-x0)
ii_plot = 11
jj_plot = 0
ii_problematic = []
jj_problematic = []
Centers = []
Widths = []
test = []
for ii in range(len(CountsSplit)):
for jj in range(len(CountsSplit[0])):
# print(ii)
# print(jj)
try:
if ii==2 and jj==11:
popt_lorentz, pcov_lorentz = curve_fit(lorentzian, freqs[:-10], CountsSplit[ii][jj][:-10],p0=(-1000,1000,436,1,1))
elif ii==2 and jj==12:
popt_lorentz, pcov_lorentz = curve_fit(lorentzian, freqs[40:], CountsSplit[ii][jj][40:],p0=(-1000,1000,436,1,1))
elif ii==4 and jj==1:
popt_lorentz, pcov_lorentz = curve_fit(lorentzian, freqs[:-86], CountsSplit[ii][jj][:-86],p0=(-1000,1000,436,1,1))
elif ii==4 and jj==2:
popt_lorentz = [0,0,0,0,0]
elif ii==4 and jj==7:
popt_lorentz = [0,0,0,0,0]
elif ii==4 and jj==12:
popt_lorentz = [0,0,0,0,0]
elif ii==4 and jj==13:
popt_lorentz = [0,0,0,0,0]
elif ii==4 and jj==14:
popt_lorentz = [0,0,0,0,0]
elif ii==11 and jj==2:
popt_lorentz = [0,0,0,0,0]
elif ii==11 and jj==3:
popt_lorentz = [0,0,0,0,0]
else:
popt_lorentz, pcov_lorentz = curve_fit(lorentzian, freqs, CountsSplit[ii][jj],p0=(-1000,1000,436,1,1))
if popt_lorentz[2]>435.95 or popt_lorentz[2]<435.8:
if popt_lorentz[2]==0:
pass
else:
ii_problematic.append(ii)
jj_problematic.append(jj)
except:
popt_lorentz=[0,0,0,0]
if ii == ii_plot and jj == jj_plot:
test.append(popt_lorentz)
Centers.append(popt_lorentz[2])
Widths.append(popt_lorentz[3])
prob = 4
print(ii_problematic[prob])
print(jj_problematic[prob])
kk=-83
plt.figure()
plt.plot(freqs, CountsSplit[ii_problematic[prob]][jj_problematic[prob]])
plt.plot(freqs[kk], CountsSplit[ii_problematic[prob]][jj_problematic[prob]][kk],'o',markersize=10)
plt.plot(freqs,lorentzian(freqs,*test[0]))
#%%
"""
Usando que la DR de la izquierda esta a (-4/5)u, donde u = 1.4 MHz/G * B,
despejo y convierto la posicion de esa resonancia a campo magnetico
"""
def ConvertFreqsToMagneticField(f,zerofreq,u):
return np.abs(f-zerofreq)*(5/4)/(1.4)
lentotal = len(CountsSplit)*len(CountsSplit[0])
medtime=4/60
timevec = np.linspace(0,medtime*lentotal, lentotal)
plt.figure()
plt.plot(timevec[4:],ConvertFreqsToMagneticField(Centers,ZeroFrequency,u)[4:],'o')
plt.ylim(3.670,3.730)
plt.xlabel('Time (h)')
plt.ylabel('Magnetic field (G)')
plt.figure()
plt.plot(timevec[4:],[100*c/3.718 for c in ConvertFreqsToMagneticField(Centers,ZeroFrequency,u)][4:],'o')
plt.ylim(98.5,100.1)
plt.xlabel('Time (h)')
plt.ylabel('Magnetic field variation (percent)')