Commit 6858949d authored by Nicolas Nunez Barreto's avatar Nicolas Nunez Barreto
Browse files

meds

parent acd9de75
Loading
Loading
Loading
Loading
+1 −1
Changes for artiq_master/last_rid.pyon: 1 added line, 1 removed line.
Original line number Diff line number Diff line
17526
17671
+152
Changes for artiq_master/repository/Tests/loadingions.py: 152 added lines, 0 removed lines.
Original line number Diff line number Diff line
"""
Created on Mon Apr 15 13:47:37 2024

@author: liaf
"""

import numpy as np
from artiq.experiment import *


class InOut(EnvExperiment):
    """
    Test de lectura de TTL y recopilacion de datos
    """
    def build(self):
        self.setattr_device("core")
        self.setattr_device("ccb")
        self.ttl0 = self.get_device("ttl0")
        self.ttl4 = self.get_device("ttl4")
        
        self.setattr_argument(f"t_med",
                             NumberValue(20*ms, unit='ms', scale=ms, min=0.1*ms, max=1000*ms),
                            "Experiment params")
        
        self.setattr_argument("t_exp",
                             NumberValue(200*s, unit='s', scale=s, min=1*s, max=1000*s),
                            "Experiment params")
        
        #self.setattr_argument("N_ions", NumberValue(1, min=1, max=15, ndecimals=0, step=1), "Experiment params")
         
        self.setattr_argument("Measurement_type",
                                  EnumerationValue(["indefinite_time", "finite_time"]),
                              "Scan params")


    def create_datasets(self):
        self.set_dataset('counts', np.zeros(int(self.t_exp/self.t_med),  dtype=int) , broadcast=True, archive=True)
        self.set_dataset('counts_indefinite',np.zeros(1, dtype=int) , broadcast=True, archive=False)
        self.set_dataset('time', np.linspace(0,self.t_exp,int(self.t_exp/self.t_med)), broadcast=True, archive=True)
        #self.set_dataset("N ions", self.N_ions, broadcast=False, archive=True)


        
    @rpc(flags={"async"})
    def create_applets(self):

        self.ccb.issue("create_applet", "test_IR_espectro_fixeddelays",
                        "${python} -m pyLIAF.artiq.applets.plot_xy "
                        "counts "
                        "--x time") #Aca habria que definir bien el vector que se use en el eje x

        self.ccb.issue("create_applet", "test_histogram_realtime",
                        "${python} -m pyLIAF.artiq.applets.histogram "
                        "counts "
                        "--update-delay 0.2")
        
        self.ccb.issue("create_applet", "test_histogram_realtime_indefinite",
                        "${python} -m pyLIAF.artiq.applets.realtime "
                        "400"
                        "counts_indefinite "
                        "--update-delay 0.2")

    @rpc(flags={"async"})
    def record_result(self, x):
        self.ticks.append(x)

    def unload_txt(self, save=False):
        difs = np.diff(self.ticks)
        print('\ntiempo\t diff')
        for i, tick in enumerate(self.ticks[:-1]):
            print(f"{tick:.4f}", end='')
            if i>0:
                print(f"\t {difs[i-1]}")
            else:
                print()

        print(f"\ntotal: {len(self.ticks)}")
        print(f"repetidos: {np.count_nonzero(difs<1e-4)-1}")

        if save:
            np.savetxt('escribo_ticks.dat', self.ticks[:-1])

    @kernel
    def run(self): 
        #Preparamos las variables y los graficos
        self.create_datasets()
        self.create_applets()
        #Se prenden los "canales" a usar
        self.core.reset()
        self.ttl4.output()
        self.ttl0.input()
        self.ttl4.on()
        
        delay(20*ms)  # time for the artiq init.

        for i in range(int(self.t_exp/self.t_med)):
            
            cuentas=self.ttl0.gate_rising(self.t_med)
            cuentas=self.ttl0.count(cuentas)
            self.mutate_dataset('counts',i,cuentas)
            
#            tiempo= self.ttl0.timestamp_mu(self.t_med)
#            print(tiempo)
#            tiempo= self.core.mu_to_seconds(tiempo)
#            self.mutate_dataset('time',i,tiempo)
            

            
            
            
            print(cuentas)
            #print(tiempo)
            
            self.core.break_realtime()
            
            
        #print(self.counts)
        start_time = now_mu()  # Record the start timeself.core.break_realtime()
        self.core.break_realtime()
        #self.core.wait_until_mu(now_mu())
        #stop_time = start_time + self.core.seconds_to_mu(self.t_exp)
#
#        if self.Measurement_type=="indefinite time":
#            while cuentas > 0:
#                #hasta_aca=self.ttl0.gate_rising(self.t_med)
#                #at_mu(self.ttl0.timestamp_mu(hasta_aca))
#                #hasta_aca=self.ttl0.gate_rising(100*ms)
#                #pulsos=self.ttl0.count(hasta_aca)
#                #datos=datos+[pulsos]
#                pulsos=3
#                self.mutate_dataset('counts_indefinite',0,pulsos)
#                #delay(3*ms)
#                #t0 = t_end - self.core.seconds_to_mu(self.t_med)
#                self.core.break_realtime()
#                self.core.wait_until_mu(now_mu())
#              
#        else:
#            for i in range(int(self.t_exp/self.t_med)):
#                print(self.t_med)
#                #hasta_aca=self.ttl0.gate_rising(self.t_med)
#                #hasta_aca=self.ttl0.gate_rising(100*ms)
#                #pulsos=self.ttl0.count(hasta_aca)
#                pulsos=3
#                #datos=datos+[pulsos]
#                self.mutate_dataset('counts',i,pulsos)
#                tiempo= self.ttl0.timestamp_mu(self.t_med)
#                tiempo= self.core.seconds_to_mu(tiempo)
#                self.mutate_dataset('time',i,tiempo)
#                #delay(3*ms)
#                #t0 = t_end - self.core.seconds_to_mu(self.t_med)
#                self.core.break_realtime()
#                self.core.wait_until_mu(now_mu())
+8.8 KiB

File added.

No diff preview for this file type.

+10.9 KiB

File added.

No diff preview for this file type.

+10.9 KiB

File added.

No diff preview for this file type.

Loading