Newer
Older
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
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
# Solo levanto algunos experimentos
ALL_FILES = """000002068-LaserPowerCalibration.h5"""
#carpeta pc nico labo escritorio:
#C:\Users\Usuario\Documents\artiq\artiq_experiments\artiq_master\results\2021-07-14\16
for i, fname in enumerate(ALL_FILES.split()):
print(i)
print(fname)
data = h5py.File(fname, '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.
Calibration_amps = np.array(data['datasets']['Calibration_amps'])
Calibration_freqs = np.array(data['datasets']['Calibration_freqs'])
PD_UV_counts = np.array(data['datasets']['PD_UV_counts'])
#%%
#for i in range(len(measurements)):
# SumaTotal[i%len(freqs)] = SumaTotal[i%len(freqs)] + measurements[i]
len_amps = len(Calibration_amps)
len_freqs = int(len(Calibration_freqs)/len_amps)
freqs = Calibration_freqs[0:len_freqs]
n = len(freqs)
PD_split = np.matrix([PD_UV_counts[i * n:(i + 1) * n] for i in range((len(PD_UV_counts) + n - 1) // n )])
PD_T = np.transpose(PD_split)
plt.figure()
for i in range(len(PD_split)):
plt.plot([f*1e-6 for f in freqs], np.array(PD_split[i])[0], 'o')
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Voltaje fotodiodo (V)')
plt.title('Láser UV')
i = 10
plt.figure()
plt.plot(np.array(PD_T[i][0])[0], Calibration_amps, 'o', label=f"Freq: {round(freqs[i]*1e-6, 3)} MHz")
plt.ylabel('Amplitud Artiq')
plt.xlabel("Voltaje fotodiodo (V)")
plt.legend()
#%%
def RemoveZeros(calib, freqs):
i, j = 0, 1
new_calib = calib
while i < len(calib):
if new_calib[0] == 0:
new_calib = new_calib[1:]
i = i + 1
else:
init_len = len(new_calib)
final_calib = new_calib
while j < init_len:
if final_calib[-1] == 0:
final_calib = final_calib[:-1]
j = j + 1
else:
if j == 1:
return (i, j), freqs[i:], final_calib
else:
return (i, j), freqs[i:-j+1], final_calib
lista = [0, 1, 0, 1, 0, 0, 1, 1, 0, 0]
freqs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
tupla, new_freqs, calib = RemoveZeros(lista, freqs)
print(new_freqs)
print(calib)
#%%
i = 15
interpolations = []
for i in range(len(PD_T)):
PD = np.array(PD_T[i][0])[0]
amps = Calibration_amps
f = interpolate.interp1d(PD, amps, kind='quadratic')
g = interpolate.interp1d(amps, PD, kind='quadratic')
xs = np.arange(min(PD), max(PD), 1e-4)
interpolations.append(f)
interpolations_g.append(g)
Calibration_PD_value = 0.2
Calibs = []
for fi in interpolations:
try:
Calibs.append(float(fi(Calibration_PD_value)))
except:
Calibs.append(0)
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot([f*1e-6 for f in freqs], Calibs, 'o', label='Amplitudes a setear')
EffectivePD = []
for i in range(len(Calibs)):
try:
EffectivePD.append(interpolations_g[i](Calibs[i]))
except:
EffectivePD.append(0)
ax2.plot([f*1e-6 for f in freqs], EffectivePD, 'ro', label='Potencia')
ax1.set_xlabel('Frecuencia (MHz)')
ax1.set_ylabel('Amplitudes')
ax2.set_ylabel('Potencia PD (V)')
fig.legend()
h = interpolate.interp1d(freqs, Calibs, kind='quadratic')
xs2 = np.arange(min(freqs), max(freqs), 1e5)
plt.figure()
plt.plot(freqs, Calibs, 'o')
plt.plot(xs2, h(xs2))