Skip to content
UV_spectrums.py 8.24 KiB
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

# Solo levanto algunos experimentos
Calib_Files = """000004263-UV_Scan_withcalib_Haeffner
000004265-UV_Scan_withcalib_Haeffner
000004270-UV_Scan_withcalib_Haeffner
000004273-UV_Scan_withcalib_Haeffner
000004275-UV_Scan_withcalib_Haeffner
000004282-UV_Scan_withcalib_Haeffner
000004301-UV_Scan_withcalib_Haeffner
000004303-UV_Scan_withcalib_Haeffner""" 



#carpeta pc nico labo escritorio:
#C:\Users\Usuario\Documents\artiq\artiq_experiments\analisis\plots\20211013_EspectrosUV\Data

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()))

#%%    

Amps = []
Freqs = []
Counts = []

for i, fname in enumerate(Calib_Files.split()):
    print(SeeKeys(Calib_Files))
    print(i)
    print(fname)
    data = h5py.File(fname+'.h5', 'r') # Leo el h5: Recordar que nuestros datos estan en 'datasets'
    print(list(data['datasets'].keys()))
    Amps.append(np.array(data['datasets']['UV_Amplitudes']))
    Freqs.append(np.array(data['datasets']['UV_Frequencies']))
    Counts.append(np.array(data['datasets']['counts_spectrum']))


#def GetBackground(countsper100ms, )



#%%

def Lorentzian(f, A, gamma, x0):
    return (A/np.pi)*0.5*gamma/(((f-x0)**2)+((0.5*gamma)**2)) + 10 #40 es el piso de ruido estimado

j = 1 #UV_cooling en 90 MHz

UV_cooling = 90

FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]

portion = 0.05

popt, pcov = curve_fit(Lorentzian, FreqsChosen[int(portion*len(FreqsChosen)):], CountsChosen[int(portion*len(FreqsChosen)):])

freqslong = np.arange(min(FreqsChosen)-10, max(FreqsChosen)+10, (FreqsChosen[1]-FreqsChosen[0])*0.01)

plt.figure()
plt.plot(FreqsChosen, CountsChosen, 'o', label='4 uW')
plt.plot(freqslong, Lorentzian(freqslong, *popt), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
plt.legend()

print(f'Ancho medido: {round(popt[1])} MHz') 



#%%

def Lorentzian(f, A, gamma, x0, C):
    return (A/np.pi)*0.5*gamma/(((f-x0)**2)+((0.5*gamma)**2)) + C #40 es el piso de ruido estimado

j = 4 #UV_cooling en 90 MHz

UV_cooling = 90

FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]

portion = 0.05

popt, pcov = curve_fit(Lorentzian, FreqsChosen[int(portion*len(FreqsChosen)):], CountsChosen[int(portion*len(FreqsChosen)):], p0=[1e3, 40, 210, 100])

freqslong = np.arange(min(FreqsChosen)-100, max(FreqsChosen)+100, (FreqsChosen[1]-FreqsChosen[0])*0.01)

plt.figure()
plt.plot(FreqsChosen, CountsChosen, 'o', label='1 uW')
plt.plot(freqslong, Lorentzian(freqslong, *popt), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
plt.axhline(popt[-1])
plt.ylim(50, 1100)
plt.legend()

 

#%% COMPARATIVA DE AMBOS DONDE SE VE QUE UNO ES MAS FINO

def Lorentzian(f, A, gamma, x0):
    return (A/np.pi)*0.5*gamma/(((f-x0)**2)+((0.5*gamma)**2)) + 10 #40 es el piso de ruido estimado

j = 1 #UV_cooling en 90 MHz

UV_cooling = 90

FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]


plt.figure()
plt.plot(FreqsChosen, [c/max(CountsChosen) for c in CountsChosen], 'o', label='4 uW')
#plt.plot(freqslong, Lorentzian(freqslong, *popt), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
plt.legend()

print(f'Ancho medido: {round(popt[1])} MHz') 


j = 4 #UV_cooling en 90 MHz


FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]

#popt, pcov = curve_fit(Lorentzian, FreqsChosen[int(portion*len(FreqsChosen)):], CountsChosen[int(portion*len(FreqsChosen)):])

freqslong = np.arange(min(FreqsChosen)-10, max(FreqsChosen)+10, (FreqsChosen[1]-FreqsChosen[0])*0.01)

#plt.figure()
plt.plot(FreqsChosen, [c/max(CountsChosen) for c in CountsChosen], 'o', label='1 uW')
#plt.plot(freqslong, Lorentzian(freqslong, *popt), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
plt.legend()


#%%

def Lorentzian(f, A, gamma, x0, C):
    return (A/np.pi)*0.5*gamma/(((f-x0)**2)+((0.5*gamma)**2)) + C #40 es el piso de ruido estimado

j = 5 #UV_cooling en 90 MHz

UV_cooling = 90

FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]

portion = 0.6

#popt, pcov = curve_fit(Lorentzian, FreqsChosen[int(portion*len(FreqsChosen)):], CountsChosen[int(portion*len(FreqsChosen)):], p0=[1e3, 40, 210, 100])

popt, pcov = curve_fit(Lorentzian, FreqsChosen[:int(portion*len(FreqsChosen))], CountsChosen[:int(portion*len(FreqsChosen))], p0=[1e3, 40, 210, 100])

freqslong = np.arange(min(FreqsChosen)-10, max(FreqsChosen)+10, (FreqsChosen[1]-FreqsChosen[0])*0.01)

plt.figure()
plt.plot([f-popt[2] for f in FreqsChosen], CountsChosen, 'o', label='1 uW')
plt.plot([f-popt[2] for f in freqslong], Lorentzian(freqslong, *popt), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
plt.axhline(popt[-1])
plt.legend()
print(f'Ancho medido: {round(popt[1])} MHz') 


#%%

def Lorentzian(f, A, gamma, x0, C):
    return (A/np.pi)*0.5*gamma/(((f-x0)**2)+((0.5*gamma)**2)) + C #40 es el piso de ruido estimado

j = 6 #UV_cooling en 90 MHz

UV_cooling = 90

FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]

portion = 1

#popt, pcov = curve_fit(Lorentzian, FreqsChosen[int(portion*len(FreqsChosen)):], CountsChosen[int(portion*len(FreqsChosen)):], p0=[1e3, 40, 210, 100])

popt, pcov = curve_fit(Lorentzian, FreqsChosen[:int(portion*len(FreqsChosen))], CountsChosen[:int(portion*len(FreqsChosen))], p0=[1e3, 40, 210, 100])

freqslong = np.arange(min(FreqsChosen)-10, max(FreqsChosen)+10, (FreqsChosen[1]-FreqsChosen[0])*0.01)

plt.figure()
plt.plot([f-popt[2] for f in FreqsChosen], CountsChosen/max(CountsChosen), 'o', label='2.5 uW')
plt.plot([f-popt[2] for f in freqslong], Lorentzian(freqslong, *popt)/max(CountsChosen), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
#plt.axhline(popt[-1])
plt.legend()
print(f'Ancho medido: {round(popt[1])} MHz') 



def Lorentzian(f, A, gamma, x0):
    return (A/np.pi)*0.5*gamma/(((f-x0)**2)+((0.5*gamma)**2)) + 30 #40 es el piso de ruido estimado

j = 7 #UV_cooling en 90 MHz

UV_cooling = 90

FreqsChosen = [2*f*1e-6 for f in Freqs[j]]
CountsChosen = Counts[j]

portion = 1

#popt, pcov = curve_fit(Lorentzian, FreqsChosen[int(portion*len(FreqsChosen)):], CountsChosen[int(portion*len(FreqsChosen)):], p0=[1e3, 40, 210, 100])

popt, pcov = curve_fit(Lorentzian, FreqsChosen[:int(portion*len(FreqsChosen))], CountsChosen[:int(portion*len(FreqsChosen))], p0=[1e3, 40, 210])

freqslong = np.arange(min(FreqsChosen)-10, max(FreqsChosen)+10, (FreqsChosen[1]-FreqsChosen[0])*0.01)

#plt.figure()
plt.plot([f-popt[2] for f in FreqsChosen], CountsChosen/max(CountsChosen), 'o', label='2.5 uW')
plt.plot([f-popt[2] for f in freqslong], Lorentzian(freqslong, *popt)/max(CountsChosen), label=f'FWHM {round(popt[1])} MHz')
#plt.axvline(popt[2]-22.1, linestyle='--', linewidth=1)
#plt.axvline(popt[2]+22.1, linestyle='--', linewidth=1)
#plt.axvline(2*UV_cooling, linestyle='--', linewidth=1)
plt.xlabel('Frecuencia (MHz)')
plt.ylabel('Cuentas')
#plt.axhline(popt[-1])
plt.legend()
print(f'Ancho medido: {round(popt[1])} MHz')