Encendido_AOM_UV.py 3.57 KB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul  7 16:12:04 2021

@author: oem
"""

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.optimize import curve_fit
from scipy.special import factorial
from scipy.stats import poisson

# Solo levanto algunos experimentos
ALL_FILES_SP = """000001556-SingleLine.h5
000001558-SingleLine.h5
000001559-SingleLine.h5
000001560-SingleLine.h5"""

#000001514-SingleLine.h5 #este tiene amplitud 0.08 que es muy poquito

BINW = 1e-9
T0 = 0.0e-6

os.chdir('/home/oem/Documentos/Doctorado/Artiq/Repositorio/artiq_experiments/artiq_master/results/2021-07-05/16')

fig0, ax0 = plt.subplots()
#ax1_b = ax1_a.twinx()

for i, fname in enumerate(ALL_FILES_SP.split()):
    if i == 3:
        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.
        laser_UV_amp = data['datasets']['laser_UV_amp']
        laser_UV_freq = data['datasets']['laser_UV_freq']
        counts = np.array(data['datasets']['counts'])
        bines = np.arange(counts.min(), counts.max()+BINW, BINW)
        
        heigs, binsf  = np.histogram(counts, bines[bines>T0])
        
        times = [t*1e6 for t in binsf[:-1]]
        
        #ax0.step([t*1e6 for t in binsf[:-1]], heigs, label=f"AMP: {laser_UV_amp}", where='mid', color='blue', lw=1, alpha=0.4)
        ax0.plot(times, heigs, 'o-', color='blue', lw=1)
        #ax0.set_xlim(0.95, 1.2)
        ti = 1.045
        tf = 1.1
        #ax0.axvline(ti, color='red', linestyle='dashed', linewidth=2)
        #ax0.axvline(tf, color='red', linestyle='dashed', linewidth=2)
        ax0.set_title(f'UV AOM on, 5 M meds, bin {int(BINW*1e9)} ns, turning on: {round((tf-ti)*1000)} ns')
        ax0.set_xlabel('Time (us)')
        ax0.set_ylabel('Counts')
        ax0.grid()

#%%

"""
Ahora veo el comportamiento estadistico de oscuridad y del laser prendido a ver si es poissoniano
"""

def fit_function(k, lamb):
    '''poisson function, parameter lamb is the fit parameter'''
    return poisson.pmf(k, lamb)


binw = 1

counts_UVoff = heigs[0:int(0.45*len(heigs))]
counts_UVon = heigs[int(0.55*len(heigs)):]

N = len(counts_UVoff)

mediaoff = np.mean(counts_UVoff)
mediaon = np.mean(counts_UVon)

binesoff = np.arange(counts_UVoff.min(), counts_UVoff.max()+binw, binw)
bineson = np.arange(counts_UVon.min(), counts_UVon.max()+binw, binw)

heigsoff, binsoff = np.histogram(counts_UVoff, binesoff)
heigson, binson = np.histogram(counts_UVon, bineson)


#plt.figure()
#plt.plot(binsoff[:-1], heigsoff, 'o-', bineson[:-1], heigson, 'o-')


"""
#Puedo ajustar con poissoniana o directamente plotearle una

parametersoff, cov_matrixoff = curve_fit(fit_function, binsoff[:-1], heigsoff/sum(heigsoff))
parameterson, cov_matrixon = curve_fit(fit_function, binson[:-1], heigson/sum(heigson))
"""

xoff = binsoff[:-1]
xon = binson[:-1]

plt.figure()
plt.plot(binsoff[:-1], heigsoff/sum(heigsoff), 'ko', label='Laser UV off')
plt.plot(xoff, [fit_function(k, np.mean(counts_UVoff)) for k in xoff], 'r', lw=3)
plt.plot(binson[:-1], heigson/sum(heigson), 'bo', label='Laser UV on')
plt.plot(xon,[fit_function(k, np.mean(counts_UVon)) for k in xon], 'r', lw=3)
plt.xlabel('Counts')
plt.ylabel('Occurrences')
plt.title(f'Bin: {binw} ns, {N} measurements, no ions')
plt.legend()