Beispiel #1
0
def runExperiment():
    global my_SRS

    #Plotting setup, xs is the frequencies, ys is the average intensities for the signal, bys is avg intensities for background
    style.use("fivethirtyeight")
    fig = plt.figure()
    ax1 = fig.add_subplot(1, 1, 1)
    xs = []
    ys = []
    bys = []

    initPB()

    #initiate RF generator with channel and model type; set amplitude
    my_SRS = SRSctl.initSRS(27, 'SG386')
    SRSctl.setSRS_RFAmplitude(my_SRS, .14, units="Vpp")

    #set test frequency and modulation
    SRSctl.setSRS_Freq(my_SRS, config['START_FREQUENCY'], 'GHz')
    SRSctl.setupSRSmodulation(my_SRS, config['sequence_name'])

    #Get the instruction Array
    instructionArray = PBctl.programPB(config['sequence_name'],
                                       [config['t_AOM']])
    print(instructionArray)

    #Program the PulseBlaster
    status = pb_start_programming(PULSE_PROGRAM)
    for i in range(0, len(instructionArray)):
        PBctl.pb_inst_pbonly(instructionArray[i][0], instructionArray[i][1],
                             instructionArray[i][2], instructionArray[i][3])
    pb_stop_programming()

    #Configure the DAQ
    global task
    task = DAQ.configureDAQ(ESR.Nsamples)

    #turn on the microwave excitation - changed the sequence here, zhao, 02/24/2020
    SRSctl.enableSRS_RFOutput(my_SRS)

    global f
    #Set f to be the start frequency
    f = config['START_FREQUENCY']

    #start the pulse blaster  # you can start pulseblaster at the beginning the experiment and turn it off until everything is done -- Zhao, 6/11/2020
    pb_start()

    #Throw away the first NThrow samples to get the photodiode warmed up
    for i in range(NThrow):
        DAQ.readDAQ(task, ESR.Nsamples * 2, 10)

    #Begin the animation - All of the experiment work is done in the animate function. FuncAnimation runs animate in a loop automatically
    ani = animation.FuncAnimation(
        fig, animate, fargs=(xs, ys, bys), interval=200
    )  ## not sure if this is the best approach. maybe try to use the "frames" variable for this function -- Zhao, 6/11/2020
def runExperiment():
    try:
        config['IQpadding'] = T2.t_min * round(30 * ns / T2.t_min)

        #Plotting setup, xs is the frequencies, ys is the average intensities
        style.use("fivethirtyeight")
        plt.ion()
        fig = plt.figure()
        ax = fig.add_subplot(111)
        xs = []
        ys = []
        bys = []
        line1, = ax.plot(xs, ys, 'b-')

        initPB()

        #initiate RF generator with channel and model type; set amplitude
        my_SRS = SRSctl.initSRS(27, 'SG386')
        SRSctl.setSRS_RFAmplitude(my_SRS, .14, units="Vpp")

        #set test frequency and modulation
        SRSctl.setSRS_Freq(my_SRS, config['MW_FREQ'], 'GHz')
        SRSctl.setupSRSmodulation(my_SRS, 'T2seq')

        instructionArray = []
        for i in np.arange(config['start_tau'],
                           config['end_tau'] + config['step_tau'],
                           config['step_tau']):
            sequenceArgs = [
                i * ns, config['t_AOM'] * ns, config['t_readoutDelay'] * ns,
                config['t_pi'] * ns, config['IQpadding'],
                config['numberOfPiPulses']
            ]
            instructionArray.extend(
                PBctl.programPB(config['sequence_name'], sequenceArgs))
        print(instructionArray)

        status = pb_start_programming(PULSE_PROGRAM)
        for i in range(0, len(instructionArray)):
            PBctl.pb_inst_pbonly(instructionArray[i][0],
                                 instructionArray[i][1],
                                 instructionArray[i][2],
                                 instructionArray[i][3])
        pb_stop_programming()

        #Configure the DAQ
        config['task'], channel = DAQ.configureDAQ(T2.Nsamples)

        #turn on the microwave excitation - changed the sequence here, zhao, 02/24/2020
        SRSctl.enableSRS_RFOutput(my_SRS)

        #Function to close all running tasks
        def closeExp():
            #turn off the microwave excitation
            SRSctl.disableSRS_RFOutput(my_SRS)
            #stop the pulse blaster
            pb_stop()
            #Close the DAQ once we are done
            DAQ.closeDAQTask(config['task'])
            return

        #Function to save data
        def save():
            saved = input("Save plot? y/n")
            if saved == 'y':
                name = input("Enter a filename:")
                plt.savefig(name)
                np.savetxt(name + '.csv', (xs, ys), delimiter=",")
                #task.close()
                sys.exit()
            elif saved == 'n':
                #task.close()
                sys.exit()
            else:
                print('Error, try again')
                save()

        #start the pulse blaster
        pb_start()

        #Throw away the first NThrow samples to get the photodiode warmed up
        for i in range(NThrow):
            DAQ.readDAQ(config['task'], channel, T2.Nsamples * 2, 10)

        for n in np.arange(config['Navg']):
            #For loop to run the experiment and plot
            for f in np.arange(config['start_tau'],
                               config['end_tau'] + config['step_tau'],
                               config['step_tau']):
                #Read from the DAQ
                output = DAQ.readDAQ(config['task'], channel, T2.Nsamples * 2,
                                     config['DAQtimeout'])
                #Average all the samples that we got
                signal = output[0::2]
                background = output[1::2]
                sig_average = np.mean(signal)
                back_average = np.mean(background)
                print('signal', sig_average)
                print('background', back_average)
                #append frequency to x-axis
                xs.append(f)

                #append counts to y-axis
                ys.append(sig_average - back_average)

                #clear the plot
                plt.clf()

                #Plot the variables
                plt.plot(xs, ys)

                #Make the plot look good
                plt.xticks(rotation=45, ha='right')
                plt.subplots_adjust(bottom=0.30)
                plt.title('Photo Counter Readout vs Pulse Duration')
                plt.ylabel('Photodiode Voltage (V)')
                plt.xlabel('Pulse Duration (ns)')

                #Draw the plot, pause is necessary to get it to show up
                plt.draw()
                plt.pause(0.0001)
    except KeyboardInterrupt:
        print('User keyboard interrupt. Quitting...')
        sys.exit()
    finally:
        #Idk if show is necessary, save the plot and close everything
        plt.show()
        closeExp()
        save()
def runExperiment():
	#Array to hold raw data
	data = np.zeros(ESR.Nsamples * 4, dtype=np.float64)

	#Plotting setup, xs is the frequencies, ys is the average intensities 
	style.use("fivethirtyeight")
	plt.ion()
	fig = plt.figure()
	ax = fig.add_subplot(111)
	xs = []
	ys = [] 
	bys = []
	line1, = ax.plot(xs, ys, 'b-')

	initPB()

	#initiate RF generator with channel and model type; set amplitude
	my_SRS = SRSctl.initSRS(27, 'SG386') 
	SRSctl.setSRS_RFAmplitude(my_SRS, .14, units = "Vpp") 

	#set test frequency and modulation
	SRSctl.setSRS_Freq(my_SRS, START_FREQUENCY, 'GHz') 
	SRSctl.setupSRSmodulation(my_SRS, 'ESRseq')

	#Get the instruction Array
	instructionArray = PBctl.programPB(config['sequence_name'], [config['t_AOM']])
	print(instructionArray)

	#Program the PulseBlaster
	status = pb_start_programming(PULSE_PROGRAM)
	for i in range(0, len(instructionArray)):
		PBctl.pb_inst_pbonly(instructionArray[i][0],instructionArray[i][1],instructionArray[i][2],instructionArray[i][3])
	pb_stop_programming()

	#Configure the DAQ
	config['task'], reader = DAQ.configureDAQ(ESR.Nsamples)

	#turn on the microwave excitation - changed the sequence here, zhao, 02/24/2020
	SRSctl.enableSRS_RFOutput(my_SRS) 

	#Function to close all running tasks
	def closeExp():
		#turn off the microwave excitation
		SRSctl.disableSRS_RFOutput(my_SRS) 
		#stop the pulse blaster
		pb_stop()
		#Close the DAQ once we are done
		DAQ.closeDAQTask(config['task'])
		return

	#Function to save data 
	def save():
		saved = input("Save plot? y/n")
		if saved == 'y':
			name = input("Enter a filename:")
			plt.savefig(name)
			np.savetxt(name + '.csv', (xs, ys), delimiter=",")
			#task.close()
			sys.exit()
		elif saved == 'n':
			#task.close()
			sys.exit()
		else:
			print('Error, try again')
			save()

	#start the pulse blaster
	pb_start()

	#Throw away the first NThrow samples to get the photodiode warmed up
	for i in range(NThrow):
		DAQ.readDAQ(reader, ESR.Nsamples * 2, 10, data)

	for n in np.arange(config['Navg']):
		#For loop to run the experiment and plot
		for f in np.arange(config['START_FREQUENCY'], config['END_FREQUENCY'] + config['STEP_FREQUENCY'], config['STEP_FREQUENCY']):
		    #init RF generator with new frequency
		    SRSctl.setSRS_Freq(my_SRS, f, 'GHz')

			#Read from the DAQ
			output = DAQ.readDAQ(reader, ESR.Nsamples * 2, 10, data)
			print(output)
			#Average all the samples that we got
			signal = data[0::2]
			background = data[1::2]
			sig_average = np.mean(signal)
			back_average = np.mean(background)
			print('signal', sig_average)
			print('background', back_average)

			#append frequency to x-axis
		    xs.append(f)

		    #append counts to y-axis
		    ys.append(sig_average - back_average)

		    #clear the plot
		    plt.clf()

		    #Plot the variables
		    plt.plot(xs, ys)

		    #Make the plot look good
		    plt.xticks(rotation=45, ha='right')
		    plt.subplots_adjust(bottom=0.30)
		    plt.title('Photo Counter Readout vs Frequency')
		    plt.ylabel('Photo Count')
		    plt.xlabel('Frequency')

		    #Draw the plot, pause is necessary to get it to show up
		    plt.draw()
		    plt.pause(0.0001)