Ejemplo n.º 1
0
def write_trigger_sequence(dwell_time, numsteps, tres):
    # the strings needed to make the sequence
    tstartstr = str(int(100 / tres))
    tstopstr = str(int(0.5 * dwell_time / (tres * _ns)))
    greenstopstr = str(int(dwell_time / (tres * _ns)))
    seqfilename = dirPath / 'odmr_trigger.seq'  # filename for sequences
    # create a sequence where measure is on for 1/2 dwell time, and then turns off, but green remains on throughout
    # the adwin will measure till it receives the next positive edge and then latch
    seq = [['Measure', tstartstr, tstopstr],
           ['Green', tstartstr, greenstopstr]]
    # params = {'type':'number','start': 1, 'stepsize': 1, 'steps': steps-1}
    s = Sequence(seq, timeres=tres)
    s.create_sequence()
    # this part here is not necessary in the actual program, I am just using it to check that the above sequence will do
    # what I want it to do
    # tt = np.linspace(0, s.maxend, len(s.c1markerdata))
    # plt.plot(tt, s.wavedata[0, :], 'r-', tt, s.wavedata[1, :], 'b-', tt, s.c1markerdata, 'g--', tt, s.c2markerdata,
    #          'y-')
    # plt.show()
    # this is the section where I actually write the waveform to a file,  to repeat it for numsteps,
    # and then wait to receive a software trigger from the Pc before doing it again
    awgfile = AWGFile(s, timeres=tres, dirpath=dirPath)

    awgfile.write_waveform('trig', 1, s.wavedata[0, :], s.c1markerdata)
    awgfile.write_waveform('trig', 2, s.wavedata[1, :], s.c2markerdata)
    wfmlen = len(s.c2markerdata)

    # first create an empty waveform in channel 1 and 2 but turn on the green laser
    # so that measurements can start after a trigger is received.
    arm_sequence = Sequence([['Green', '0', str(wfmlen)]], timeres=tres)
    arm_sequence.create_sequence()
    awgfile.write_waveform('arm', 1, arm_sequence.wavedata[0, :],
                           arm_sequence.c1markerdata)
    awgfile.write_waveform('arm', 2, arm_sequence.wavedata[1, :],
                           arm_sequence.c2markerdata)

    # now we create a sequence file that will be loaded to the AWG
    try:
        with open(seqfilename, 'wb') as sfile:
            sfile.write(awgfile.seqheader)
            temp_str = 'LINES ' + str(
                2) + '\r\n'  # there are only 2 lines in this file
            sfile.write(temp_str.encode())  # have to convert to binary format
            temp_str = '"arm_1.wfm","arm_2.wfm",0,1,0,0\r\n'  # the arm sequence will be loaded and will keep
            # repeating and wait for the software trigger from the PC
            sfile.write(temp_str.encode())
            # the trig wfm is repeated numsteps
            # 2020-01-04: after lot of experimenting with Arduino code it appears that interrupt of the arduino is
            # unable to accept fast triggers, i.e. it does not work if the triggers have 1 ms spacing, but works if
            # they have 10 ms spacing. So we have decided not to mess with it, and instead simply to use the old
            # arduino code where all timing comes from the arduino itself but require that it takes one trigger from
            # the  AWG to start a scan
            linestr = '"trig_1.wfm","trig_2.wfm",' + str(1) + ',1,0,0\r\n'
            sfile.write(linestr.encode())
            sfile.write(b'JUMP_MODE SOFTWARE\r\n'
                        )  # tells awg to wait for a software trigger
    except (IOError, ValueError) as error:
        # replace these with logger writes, but for now just send any errors to stderr
        sys.stderr.write(sys.exc_info())
        sys.stderr.write(error.message + '\n')
Ejemplo n.º 2
0
def make_seq():
    wfmdir = Path('../../..') / 'arbpulseshape'
    #print(str(wfmdir.resolve()))
    # seq=[['Green', '0', '800'],['S2','900','1700'],['Wave','900','1400','Sech'],['Wave','1400','1800','Gauss'],
    #      ['Wave','1800','2200','Square'],['Wave','2200','2600','Lorentz'],['Wave','2600','3000','Load Wfm', \
    #        wfmdir / 'test4.txt']]
    #seq = [['Green', '0', '1000']]
    #seq = [['Wave', '900', '1400', 'Load Wfm',wfmdir/'test4.txt'],['Green', '1500', '2500']]
    seq = [['Wave', '900+t', '1400+t', 'Gauss'], ['Green', '1500', '2500'],
           ['S2', '500', '1500'], ['Measure', '1500', '1800']]
    # seq = [['Green', '1500', '2500'],
    #         ['S2', '1000', '1500'],['Measure','1500','1800']]
    newparams = {
        'amplitude': 100,
        'pulsewidth': 50,
        'SB freq': 0.01,
        'IQ scale factor': 1.0,
        'phase': 0.0,
        'skew phase': 0.0,
        'num pulses': 1
    }
    s = Sequence(seq, pulseparams=newparams, timeres=1)
    s.create_sequence(dt=10)
    tt = np.linspace(0, s.maxend, len(s.c1markerdata))
    plt.plot(tt, s.wavedata[0, :], 'r-', tt, s.wavedata[1, :], 'b-', tt,
             s.c1markerdata, 'g--', tt, s.c2markerdata, 'y-')
    #plt.plot(tt,s.wavedata[1,:])
    plt.show()
Ejemplo n.º 3
0
 def show_sequence(self):
     try:
         text = self.ui.metadatatextEdit.toPlainText()
         self.convert_text_to_seq(text)
         self.getReady()
         newparams = {
             'amplitude': 1000,
             'pulsewidth': 50,
             'SB freq': 0.01,
             'IQ scale factor': 1.0,
             'phase': 0.0,
             'skew phase': 0.0,
             'num pulses': 1
         }
         s = Sequence(self.seq, pulseparams=newparams, timeres=1)
         s.create_sequence(dt=500)
         tt = np.linspace(0, s.maxend, len(s.c1markerdata))
         plt.plot(tt, s.wavedata[0, :], 'r-', label='I Channel')
         plt.plot(tt, s.wavedata[1, :], 'b-', label='Q Channel')
         plt.plot(tt, s.c1markerdata, 'g-', label='S2+Green')
         plt.plot(tt, s.c2markerdata, 'y-', label='Measure')
         plt.legend()
         plt.show()
     except Exception as e:
         print(e)
Ejemplo n.º 4
0
def make_long_seq():
    seq = 'S2,1e-6,1.05e-6\n'+'Green,100e-6,102e-6\n'+'Measure,100.1e-6,100.4e-6\n'
    newparams = {'amplitude': 100, 'pulsewidth': 50, 'SB freq': 0.01, 'IQ scale factor': 1.0, 'phase': 0.0,
                 'skew phase': 0.0, 'num pulses': 1}
    s = Sequence(seq, pulseparams=newparams, timeres=1)
    s.create_sequence(dt=0)
    tt = np.linspace(0, s.latest_sequence_event, len(s.c1markerdata))
    plt.plot(tt, s.wavedata[0, :], 'r-', tt, s.wavedata[1, :], 'b-', tt, s.c1markerdata, 'g--', tt, s.c2markerdata,
             'y-')
    # plt.plot(tt,s.wavedata[1,:])
    plt.show()
Ejemplo n.º 5
0
def make_long_seq():
    seq = [['S2', '1000', '1050'], ['Green', '100000', '102000'],
           ['Measure', '100100', '100400']]
    newparams = {
        'amplitude': 100,
        'pulsewidth': 50,
        'SB freq': 0.01,
        'IQ scale factor': 1.0,
        'phase': 0.0,
        'skew phase': 0.0,
        'num pulses': 1
    }
    s = Sequence(seq, pulseparams=newparams, timeres=1)
    s.create_sequence(dt=0)
    tt = np.linspace(0, s.maxend, len(s.c1markerdata))
    plt.plot(tt, s.wavedata[0, :], 'r-', tt, s.wavedata[1, :], 'b-', tt,
             s.c1markerdata, 'g--', tt, s.c2markerdata, 'y-')
    # plt.plot(tt,s.wavedata[1,:])
    plt.show()
Ejemplo n.º 6
0
def make_seq():
    wfmdir = Path('../../..') / 'arbpulseshape'
    filestr= 'IQdata.txt'
    print(filestr)
    # print(str(wfmdir.resolve()))
    # seq='Green,0.01e-7,8e-7\nS2,9e-7,1.7e-6\nWave,9e-7,1.4e-6,Sech\nWave,1.4e-6,1.8e-6,Gauss\n' + \
    #      'Wave,1.8e-6,2.2e-6,Square\n'+'Wave,2.2e-6,2.6e-6,Lorentz\nWave,2.6e-6,3e-6,Load Wfm,fname='+filestr
    # seq = 'Wave,2.6e-6,3e-6,Load Wfm,f='+filestr+',amp = 0.4'
    #seq='Wave,2e-6,5e-6,SquareQ'
    #seq = 'Green,0.01e-6,1e-6'
    #seq = 'Wave,1e-7,2e-7,Lorentz,n=4\nWave,4e-7,5e-7,Gauss,amp=0.5,phase=90.0'
    #seq = 'Wave,9e-7,1.4e-6,Gauss\nWave,1e-7,3e-7,Load Wfm,fname='+filestr+'\n'+'Green,1.5e-6,2.5e-6'
    #seq = 'Wave,9e-7,1.4e-6,Gauss\nWave,1e-7,3e-7,Load Wfm'+ '\n' + 'Green,1.5e-6,2.5e-6'
    # seq = 'Wave,9e-7+t,1.4e-6+t,Gauss\n'+'Green,1.5e-6,2.5e-6\n'+'S2,5e-7,1.5e-6\n'+'S2,2e-6,2.5e-6\n' + \
    #         'Green,3e-6, 3.2e-6\n'+'Measure,1.5e-6,1.8e-6'
    # seq = 'Green,0.6e-6,0.7e-6\nWave,1e-6+t,1.5e-6+t,Sech,a=0.5,n=2\nMeasure,1.5e-6+t,1.8e-6+t'
    # seq = 'Green,0.6e-6,0.7e-6\nWave,1e-6+t,1.5e-6+t,SquareI,a=0.5,n=2\nMeasure,1.5e-6+t,1.8e-6+t'
    # seq = 'S1,1e-6,1.01e-6+t\nGreen,1.02e-6+t,4.02e-6+t\nMeasure,1.02e-6+t,1.12e-6+t'
    # seq = 'Wave,1e-6,1.500e-6,Gauss,n=3,phase=0'
    seq = 'RandBench,1e-6,1.500e-6,Gauss,width++,phase=0'

    newparams = {'amplitude': 500.0, 'pulsewidth': 10e-9, 'SB freq': 0, 'IQ scale factor': 1.0, 'phase': 0.0,
                 'skew phase': 0.0, 'num pulses': 1}
    #delay = [8.2e-7,1e-8]   # use this format for delay now and pass it to Sequence object
    s = Sequence(seq,pulseparams=newparams,timeres=0.1)
    s.rb_nevents = 5 # change the truncation length of random scan using this parameter
    s.comp_seq_num=1
    s.create_sequence(dt=0.0e-6)
    tt = np.linspace(0,s.latest_sequence_event,len(s.c1markerdata))*1e9
    #mwsig = s.wavedata[0,:]*np.cos(2*np.pi*1e-2*tt)+ s.wavedata[1,:]*np.sin(2*np.pi*1e-2*tt)
    # plt.plot(tt,s.c1m1,'r-',tt,s.c1m2,'g-')
    plt.plot(tt,s.wavedata[0,:],'r-',tt,s.wavedata[1,:],'b-',tt,s.c1markerdata,'g--',tt,s.c2markerdata,'y-')
    # plt.plot(tt,s.wavedata[0,:],'r--',tt,s.wavedata[1,:],'b--')
    # plt.plot(tt,s.wavedata[0,:],'r-',tt,s.wavedata[1,:],'b-',tt,s.c1markerdata,'g--',tt,s.c2markerdata,'y-')
    #plt.plot(tt,s.wavedata[0,:],'r--',tt,s.wavedata[1,:],'b--')
    #plt.plot(tt,mwsig,'r-')

    #plt.plot(tt,s.wavedata[1,:])
    #print(s.c1markerdata[1700:1750])
    plt.show()
Ejemplo n.º 7
0
def write_list_sequence(tres=1):
    repeat=15
    # the strings needed to make the sequence
    seq = [['S2','1000','1010+t'],['Green','1050+t','4050+t'],['Measure','1080+t','1180+t']]
    delay = [820,10]
    pulseparams = {'amplitude': 0, 'pulsewidth': 20, 'SB freq': 0.00, 'IQ scale factor': 1.0,'phase': 0.0,
                   'skew phase': 0.0, 'num pulses': 1}
    scan = dict([('type', 'time'), ('start', 10), ('stepsize', 10), ('steps', 9)])
    seqlist = SequenceList(sequence=seq, delay=delay, pulseparams=pulseparams, scanparams=scan,timeres=tres)
    # this part here is not necessary in the actual program, I am just using it to check that the above sequence will do
    # what I want it to do
    # tt = np.linspace(0, s.maxend, len(s.c1markerdata))
    # plt.plot(tt, s.wavedata[0, :], 'r-', tt, s.wavedata[1, :], 'b-', tt, s.c1markerdata, 'g--', tt, s.c2markerdata,
    #          'y-')
    # plt.show()
    # this is the section where I actually write the waveform to a file,
    awgfile = AWGFile(ftype='SEQ',timeres=tres,dirpath=dirPath)
    # awgfile.write_sequence(sequences=seqlist,seqfilename="scan.seq", repeat=10000)
    # instead of using the awgfile write_sequence function above, will do it explicitly here to test
    try:
        if not seqlist:
            self.logger.error("Invalid sequence or no sequence object given")
            raise ValueError("Invalid sequencelist  or no sequencelist object given")
        else:
            seqlist.create_sequence_list()
            slist = seqlist.sequencelist  # list of sequences
            wfmlen = len(slist[0].c1markerdata)  # get the length of the waveform in the first sequence
            scanlen = len(slist)

            # first create an empty waveform in channel 1 and 2 but turn on the green laser
            # so that measurements can start after a trigger is received.
            arm_sequence = Sequence([['Green', '0', str(wfmlen)]], timeres=tres)
            arm_sequence.create_sequence()
            awgfile.write_waveform(arm_sequence, 'arm', 1)
            awgfile.write_waveform(arm_sequence, 'arm', 2)
            # create scan.seq file
            try:
                fname = Path(dirPath/ 'scan.seq')
                with open(fname, 'wb') as sfile:
                    sfile.write(awgfile.seqheader)
                    temp_str = 'LINES ' + str(scanlen + 1) + '\r\n'
                    sfile.write(temp_str.encode())  # have to convert to binary format
                    temp_str = '"arm_1.wfm","arm_2.wfm",0,1,0,0\r\n'  # the arm sequence will be loaded and will wait
                    # for trigger
                    sfile.write(temp_str.encode())
                    for i in list(range(scanlen)):
                        # now we take each sequence in the slist arry and write it to a wfm file with the name given by
                        # "i+1_1.wfm and i+1_2.wfm
                        awgfile.write_waveform(slist[i], '' + str(i + 1), 1)
                        awgfile.write_waveform(slist[i], '' + str(i + 1), 2)
                        # the scan.seq file is now updated to execute those 2 wfms for repeat number of times and wait
                        # for a trigger to move to the next point.
                        linestr = '"' + str(i + 1) + '_1.wfm"' + ',' + '"' + str(i + 1) + '_2.wfm"' + ',' + str(repeat) + ',1,0,0\r\n'
                        sfile.write(linestr.encode())
                    sfile.write(
                        b'JUMP_MODE SOFTWARE\r\n')  # tells the AWG that jump trigger is controlled by the computer.
            except (IOError, ValueError) as error:
                # sys.stderr.write(sys.exc_info())
                # sys.stderr.write(error.message+'\n')
                sys.stderr.write(sys.exc_info())
                sys.stderr.write("Error occurred in either file I/O or data conversion:{0}".format(error))
                raise
    except:
        sys.stderr.write(sys.exc_info())
        raise