def sweep_Without_Shutter(self):
        self.initialize_Scan_And_Plot_Arrays()
        self.initialize_Camera()

        voltList = []
        signalList = []

        gv.begin_Sound(noWait=True)  #beep without waiting after the beep
        self.galvoOut = DAQPin(gv.galvoOutPin)
        #take images 'far' off resonance. This scan is very close to together
        for volt in self.voltOffResArr:
            self.galvoOut.write(volt)  #move the galvo to a new voltage value
            voltList.append(volt)  #record the voltage
            img = self.camera.aquire_Image()  #capture image
            signalList.append(
                np.mean(img))  #add the average of the image's pixels

        for volt in self.voltOnResArr:
            print(volt)
            self.galvoOut.write(volt)  #move the galvo to a new voltage value
            voltList.append(volt)  #record the voltage
            img = self.camera.aquire_Image()  #capture image
            print(np.mean(img))
            signalList.append(
                np.mean(img))  #add the average of the image's pixels
        self.galvoOut.close()  #close and zero the galvo
        self.camera.close()
        self.open_Aperture()  #open the apeture up when done
        gv.finished_Sound(noWait=True)  #beep without waiting after the beep
        voltArr = np.asarray(voltList)
        signalArr = np.asarray(signalList)

        params, perr = self.fit_Data(voltArr, signalArr)
        print(params)

        plt.close('all')
        plt.plot(self.voltPlotArr,
                 self.spectral_Profile(self.voltPlotArr, *params),
                 c='orange',
                 label='fit')
        plt.scatter(voltArr, signalArr, label='data')

        v0 = params[0]
        floor = params[2]
        #now use the v0 above for when the user runs again. This helps compensate for the laser drifting without the user
        #having to
        self.v0Box.delete(0, 'end')  #clear existing number
        self.v0Box.insert(0, str(np.round(v0, 3)))  #insert new number
        plt.axvline(x=v0, c='r', linestyle=':')
        plt.text(v0, floor, np.round(float(v0), 3))
        plt.legend()
        plt.grid()
        plt.title('Height = ' + str(np.round(params[1], 1)) + '+/- ' +
                  str(np.round(perr[1], 1)))

        if self.saveDataVar.get() == True:
            plt.savefig(self.folderPath.get() + '\\' + self.fileName.get() +
                        'Graph.png')
        if self.showPlotVar.get() == True:
            plt.show()
    def sweep_Single(self):
        #self.close_Aperture()

        gv.begin_Sound()
        self.galvoOut.write(self.voltArr[0])
        darkImage = self.take_Dark_Image_Average()
        imageMeanList = []
        imageList = []
        for volt in self.voltArr:
            self.galvoOut.write(volt)
            image = self.camera.aquire_Image()
            imageList.append(image)
            image = image - darkImage * 0
            imageMeanList.append(np.mean(image))
        imageSumArr = np.asarray(imageMeanList)

        self.galvoOut.close()
        self.shutterOut.close()
        self.camera.close()
        gv.finished_Sound()

        numImages = 3
        delta = np.max(imageSumArr) - np.mean(
            (imageSumArr[:numImages] + imageSumArr[-numImages:]) / 2)

        plt.plot(self.voltArr, imageSumArr)
        plt.title('Peak minus first few values= ' + str(np.round(delta, 2)))
        plt.xlabel('Volts')
        plt.ylabel('Pixel counts')
        plt.grid()
        if self.saveDataVar.get() == True:
            print(self.folderPath.get() + '\\' + self.fileName.get() + 'Graph')
            plt.savefig(self.folderPath.get() + '\\' +
                        self.fileName.get())  #save plot
            #now save fits file
            saveImageList = []
            for item in imageList:
                saveImageList.append(np.rot90(np.transpose(item)))
            hdu = fits.PrimaryHDU(
                saveImageList)  #make a Header/Data Unit of images
            hdul = fits.HDUList([hdu])  #list of HDUs to save
            fitsFileName = self.fileName.get() + '.fits'
            try:
                hdul.writeto(self.folderPath.get() + '\\' +
                             fitsFileName)  #now save it
            except:  #fits doesn't let you delete stuff accidently
                print('THAT FILE ALREADY EXISTS. DELETE IT TO OVERWRITE@')

        if self.showPlotVar.get() == True:
            plt.show()
Exemplo n.º 3
0
 def run(self):
     self.change_Directory_And_Catch_File_Errors()
     self.catch_Errors()
     gv.begin_Sound()
     self.make_Flow(0.0)
     self.shutterOut.open_Shutter()
     for volt in self.voltArr:
         print(volt)
         self.galvoOut.write(volt)
         noFlowImage = self.take_No_Flow_Image()
         self.make_Flow(self.flowRate)
         darkImage = self.take_Dark_Image()
         self.wait_To_Flow_After_Dark_Image()
         flowImage = self.take_Flow_Image()
         self.make_Flow(0.0)
         self.wait_To_Stop_Flow_After_Flow_Image()
         absorptionSignalImage = self.construct_Absorption_Signal_Image(
             darkImage, noFlowImage, flowImage)
         self.update_Image_Lists(darkImage, noFlowImage, flowImage,
                                 absorptionSignalImage)
     self.close_Pins()
     self.save_Image_Lists()
     self.make_Info_File()
     gv.finished_Sound()
    def sweep_Ratio(self):
        gv.begin_Sound()
        self.galvoOut.write(self.voltArr[0])

        image1MeanList = []  #shutter open list of image sums
        image2MeanList = []  #shutter closed list of image sums
        image1List = []
        image2List = []

        for volt in self.voltArr:
            self.galvoOut.write(volt)
            #take with shutter open
            self.open_Aperture()
            image1 = self.camera.aquire_Image()
            image1List.append(image1)
            image1MeanList.append(np.mean(image1))

            #take with shutter closed
            self.close_Aperture()
            image2 = self.camera.aquire_Image()
            image2List.append(image2)
            image2MeanList.append(np.mean(image2))

        self.galvoOut.close()
        self.shutterOut.close()
        self.camera.close()
        gv.finished_Sound()

        y1 = np.asarray(image1MeanList)  #shutter open
        y2 = np.asarray(image2MeanList)  #shutter closed

        numImages = 3
        delta1 = np.max(y1) - np.mean((y1[:numImages] + y1[-numImages:]) / 2)
        delta2 = np.max(y2) - np.mean((y2[:numImages] + y2[-numImages:]) / 2)

        ratio = delta1 / delta2
        plt.suptitle('Signal with shutter closed and open')
        plt.title('ratio of peaks of open to close = ' +
                  str(np.round(ratio, 6)))
        plt.plot(self.voltArr,
                 y1,
                 label='open,delta= ' + str(np.round(delta1, 1)))
        plt.plot(self.voltArr,
                 y2,
                 label='close,delta= ' + str(np.round(delta2, 1)))
        plt.xlabel('Volts')
        plt.ylabel('Pixel counts')
        plt.legend()
        plt.grid()

        if self.saveDataVar.get() == True:
            plt.savefig(self.folderPath.get() + '\\' + self.fileName.get() +
                        'Graph.png')
            image1SaveList = []
            image2SaveList = []
            for i in range(len(image1List)):
                image1SaveList.append(np.rot90(np.transpose(image1List[i])))
                image2SaveList.append(np.rot90(np.transpose(image2List[i])))
            hdu1 = fits.PrimaryHDU(
                image1SaveList)  #make a Header/Data Unit of images
            hdul1 = fits.HDUList([hdu1])  #list of HDUs to save
            hdu2 = fits.PrimaryHDU(
                image2SaveList)  #make a Header/Data Unit of images
            hdul2 = fits.HDUList([hdu2])  #list of HDUs to save

            fitsFileName = self.fileName.get()
            try:
                hdul1.writeto(self.folderPath.get() + '\\' + fitsFileName +
                              'ShutterOpen.fits')  #now save it
                hdul2.writeto(self.folderPath.get() + '\\' + fitsFileName +
                              'ShutterClosed.fits')  #now save it
            except:  #fits doesn't let you delete stuff accidently
                print('THAT FILE ALREADY EXISTS. DELETE IT TO OVERWRITE@')

        if self.showPlotVar.get() == True:
            plt.show()
Exemplo n.º 5
0
    def sweep(self):
        #this sweeps the galvo output voltage. There are two arrays, DAQVoltArr and imageVoltArr. DAQVoltArr contains all
        #the voltage values to collect DAQ data at. imageVoltArr contains the values to take iamges at. imageVolt array's
        #range must be less than or equal to DAQVoltArr's range. The loop searchs for which step is next, jumps to that point
        #and then increments the counter.
        self._initialize_Cameras()
        if self.cameraNear is not None:
            for _ in range(10):
                self.cameraNear.aquire_Image()

        i = 0  #counter for DAQVoltArr
        j = 0  #coutner for imageVoltArr
        loop = True
        volt = 0
        tempList = []
        gv.begin_Sound()
        lastImage = False  #this is so that the last image is taken. It will flip from False to True once, and then no more
        #images
        takeImage = False  #wether to take images
        totalSteps = self.DAQVoltArr.shape[0] + self.imageVoltArr.shape[0]

        print('\n \n \n \n')
        print('-----SWEEPING NOW----')
        time.sleep(
            .001
        )  #if you don't wait a little then the progress bar and other messages will get messed up
        #in the terminal because they will try to write on top of each other
        progressBar = tqdm(total=totalSteps)
        while loop == True:
            progressBar.update()
            if i == self.DAQVoltArr.shape[
                    0] - 1 and j == self.imageVoltArr.shape[0] - 1:
                loop = False
                volt = self.DAQVoltArr[i]
                if lastImage == False:  #if the last image occurs at the last DAQ voltage as well
                    takeImage = True
                    lastImage = False
            else:
                if self.DAQVoltArr[i] == self.imageVoltArr[
                        j]:  #if potential next voltages are equal
                    volt = self.DAQVoltArr[i]
                    if i != self.DAQVoltArr.shape[
                            0] - 1:  #don't increment if its at the end!
                        i += 1
                    if j != self.imageVoltArr.shape[
                            0] - 1:  #don't increment if its at the end!
                        j += 1
                        takeImage = True
                elif self.DAQVoltArr[i] < self.imageVoltArr[j]:
                    if i != self.DAQVoltArr.shape[
                            0] - 1:  #don't increment if its at the end!
                        volt = self.DAQVoltArr[i]
                        i += 1
                    else:
                        volt = self.imageVoltArr[i]
                        j += 1
                        takeImage = True
                elif self.imageVoltArr[j] < self.DAQVoltArr[i]:
                    if j != self.imageVoltArr.shape[
                            0] - 1:  #don't increment if its at the end!
                        volt = self.imageVoltArr[j]
                        j += 1
                        takeImage = True
                    elif lastImage == False:  #special case for taking the last image
                        lastImage = True  #Now it won't do this again. The loop will come here from now on, but it won't
                        #do anything but increment the galvo voltage because j!=self.imageVoltArr.shape[0]-1 will be\
                        #false and lastImage==False will be false also
                        volt = self.imageVoltArr[j]
                        takeImage = True
                    else:
                        volt = self.DAQVoltArr[i]
                        i += 1
            self.galvoOut.write(volt)
            tempList.append([volt, self.lithiumRefIn.read(numSamples=1000)])
            if takeImage == True:
                #for i in range(10):
                #    self._take_Exposures()
                #print((time.time()-t)/10)
                self.imageArrList.append(
                    self._take_Exposures()
                )  #the appended object is a list like [imageNear,imageFar]. If
                #there is no camera active for a given image the entry is None
                takeImage = False
        progressBar.close()
        time.sleep(
            .01
        )  #like I said above. Pause to allow the progress bar to finish writting so it doesn't get messed up
        print('-----END OF SWEEP-----')
        self._close_DAQ_Pins()
        self._close_Cameras()
        self.DAQDataArr = np.asarray(tempList)
        gv.finished_Sound()
        #np.savetxt('data1.txt',self.DAQDataArr)
        #y=self.DAQDataArr[:,1]
        #plt.plot(y)
        #plt.show()
        self.GUI.imageArrList = self.imageArrList  #this way if there is a previous list it is overwritten
        self.GUI.DAQDataArr = self.DAQDataArr
    def sweep_With_Shutter(self):
        self.initialize_Scan_And_Plot_Arrays()
        self.initialize_Camera()

        voltList = []  #list to hold voltage values of corresponding images
        signalList1 = []  #list for signal values for apeture open
        signalList2 = []  #list for signal values for apeture open

        gv.begin_Sound(noWait=True)  #beep without waiting after the beep
        self.galvoOut = DAQPin(gv.galvoOutPin)  #open the galvo control pin
        #take images 'far' off resonance. This scan is very close to together
        for volt in self.voltOffResArr:
            print(volt)
            self.galvoOut.write(volt)  #move galvo to new position
            voltList.append(volt)  #record the voltage value

            self.open_Aperture()  #'turn on' the optical pumping
            img = self.camera.aquire_Image()
            signalList1.append(np.mean(img))

            self.close_Aperture()  #'turn off' the optical pumping
            img = self.camera.aquire_Image()
            signalList2.append(np.mean(img))
        #now sweep around the peak near resonance
        for volt in self.voltOnResArr:
            self.galvoOut.write(volt)  #move galvo to new position
            voltList.append(volt)  #record the voltage value

            self.open_Aperture()  #'turn on' the optical pumping
            img = self.camera.aquire_Image()  #capture an image
            signalList1.append(np.mean(img))  #add the average of the pixels

            self.close_Aperture()  #'turn off' the optical pumping
            img = self.camera.aquire_Image()  #capture an image
            signalList2.append(np.mean(img))  #add the average of the pixels

        self.galvoOut.close()  #close and zero the pin
        self.open_Aperture()  #open the shutter up again when done
        gv.finished_Sound(noWait=True)  #beep without waiting after the beep

        #convert lists to arrays
        signalArr1 = np.asarray(signalList1)
        signalArr2 = np.asarray(signalList2)
        voltArr = np.asarray(voltList)

        #fit the data and get the optimal parameters and the error
        params1, perr1 = self.fit_Data(voltArr, signalArr1)
        params2, perr2 = self.fit_Data(voltArr, signalArr2)

        plt.close('all')
        plt.figure(figsize=(13, 8))
        plt.plot(self.voltPlotArr,
                 self.spectral_Profile(self.voltPlotArr, *params1),
                 c='blue',
                 label='fit, opened shutter')
        plt.plot(self.voltPlotArr,
                 self.spectral_Profile(self.voltPlotArr, *params2),
                 c='red',
                 label='fit, closed shutter')
        plt.scatter(voltArr,
                    signalArr1,
                    label='data, opened shutter',
                    c='blue')
        plt.scatter(voltArr,
                    signalArr2,
                    label='data, closed shutter',
                    c='red',
                    marker='x',
                    s=100)

        v0 = (params1[0] + params2[0]
              ) / 2  #Get the center from the average of the two centers
        floor = (params1[1] + params2[1]
                 ) / 2  #get the floor from the average of the two floors
        #now use the v0 above for when the user runs again. This helps compensate for the laser drifting without the user
        #having to
        self.v0Box.delete(0, 'end')  #clear existing number
        self.v0Box.insert(0, str(np.round(v0, 3)))  #insert new number
        plt.axvline(x=v0, c='r', linestyle=':')
        plt.grid()
        plt.text(v0, floor,
                 np.round(float(v0),
                          3))  #TODO: WHY IS THIS NOT WORKING ONLY HERE?

        plt.legend()
        ratio = np.round(params1[1] / params2[1], 2)
        error = np.round(
            ratio * np.sqrt((perr1[1] / params1[1])**2 +
                            (perr2[1] / params2[1])**2), 3)
        plt.suptitle('Ratio of open to close shutter height = ' + str(ratio) +
                     ' +/- ' + str(error))
        plt.title("shutter open= " + str(np.round(params1[1], 2)) + ' +/-' +
                  str(np.round(perr1[1], 1)) + " . shutter closed= " +
                  str(np.round(params2[1], 2)) + ' +/-' +
                  str(np.round(perr2[1], 1)))
        if self.saveDataVar.get() == True:
            plt.savefig(self.folderPath.get() + '\\' + self.fileName.get() +
                        'Graph.png')
        if self.showPlotVar.get() == True:
            plt.show()