def run(self):
        self.save_Settings()
        self.galvoOut = DAQPin(gv.galvoOutPin)
        self.shutterOut = DAQPin(gv.shutterPin)

        self.galvoOut.write(float(self.voltStartBox.get()))
        x1 = int(self.x1Box.get())
        y1 = int(self.y1Box.get())
        x2 = int(self.x2Box.get())
        y2 = int(self.y2Box.get())
        imageParams = [x1, x2, y1, y2]
        binSize = int(self.binSizeBox.get())
        self.camera = Camera(self.cameraVar.get(),
                             float(self.expTimeBox.get()),
                             imageParams=imageParams,
                             bin=binSize)

        self.voltArr = np.linspace(float(self.voltStartBox.get()),
                                   float(self.voltStopBox.get()),
                                   num=int(self.numImagesBox.get()))
        if os.path.isdir(self.folderPath.get()) == False:
            print('-----ERROR-----------')
            print('YOU HAVE ENTERED AN INVALID FOLDERPATH')
        if os.path.isfile(self.folderPath.get() + '\\' + self.fileName.get() +
                          '.png') == True:
            print('--------------ERROR-------')
            print('THERE IS ALREADY A FILE WITH THAT NAME IN THAT FOLDER')
            gv.error_Sound()
            sys.exit()

        plt.close('all')
        if self.ratioVar.get() == True:
            self.sweep_Ratio()
        else:
            self.sweep_Single()
    def aquire_Data(self):
        self.catch_Errors_Aquisition()
        self.save_Settings()
        # #check that there is flow. This is not foolproof because I do not use the dawboard
        if int(float(self.flowRateBox.get())) == 0:
            gv.error_Sound()
            print('FLOW RATE IS ZERO')

        #turn on the nozzle and open the shutter
        gv.begin_Flow_Sound()
        self.make_Flow()
        shutterOut = DAQPin(gv.shutterPin)  #open the shutter contorl pin
        shutterOut.open_Shutter()  #open the shutter
        time.sleep(int(self.nozzleWaitBox.get()))

        # SWEEP
        t = time.time()
        sweeper = Sweeper(self)
        sweeper.sweep()
        print(time.time() - t)

        #turn off the nozzle and close shutter
        shutterOut.close_Shutter()  #close the aperture
        shutterOut.close()  #close the shutter control pin
        self.flowRateBox.delete(0, 'end')
        self.flowRateBox.insert(0, '0')
        self.make_Flow()

        self.save_Fits_Files()
        self.save_Data()
        self.make_Info_File()
Esempio n. 3
0
 def _take_Exposures(self):
     if self.GUI.cameraVarData.get() == 'BOTH':
         resultsDict = {
         }  #this is used to add the images taken concurrently. I use a dictionary so I can keep track of
         #which image belongs to which camera
         T1 = threading.Thread(target=self._take_Exposure_Wrapper,
                               args=(resultsDict, self.cameraNear))
         T2 = threading.Thread(target=self._take_Exposure_Wrapper,
                               args=(resultsDict, self.cameraFar))
         T1.start()
         T2.start()
         T1.join()
         T2.join()
         imgNear = resultsDict['NEAR']
         imgFar = resultsDict['FAR']
         return [imgNear, imgFar]
     elif self.GUI.cameraVarData.get() == 'NEAR':
         imgNear = self.cameraNear.aquire_Image()
         return [imgNear, None]
     elif self.GUI.cameraVarData.get() == 'FAR':
         imgFar = self.cameraFar.aquire_Image()
         return [None, imgFar]
     else:
         gv.error_Sound()
         raise Exception('NO VALID CAMERA NAME PROVIDED')
    def fit_Data(self, x, y):
        print('here')
        #fit the data to get the optimal parameters
        x0Guess = float(self.v0Box.get())
        aGuess = np.max(y) - np.min(y)
        bGuess = np.min(y)
        guess = [x0Guess, aGuess, bGuess, self.sigmaGuess, self.gammaGuess]
        bounds = ([-5, 0, 0, 0, 0], [5, 100000, 100000, .1, .1])
        if bGuess > bounds[1][2] or aGuess > bounds[1][1]:
            print(
                'GUESS VALUES ARE LARGER THAN BOUNDS. SIGNAL STRENGTH IS VERY HIGH'
            )
            gv.error_Sound()
            sys.exit()
        try:
            params, pcov = spo.curve_fit(self.spectral_Profile,
                                         x,
                                         y,
                                         p0=guess,
                                         bounds=bounds)
        except:
            print('FIT FAILED')
            plt.plot(x, y)
            plt.show()
        perr = np.sqrt(np.diag(pcov))

        return params, perr
Esempio n. 5
0
 def catch_Errors(self):
     if self.flowRate <= 0:
         gv.error_Sound()
         raise Exception('The flowrate is zero or invalid!')
     if self.exposure_MilliSeconds < 500:
         gv.error_Sound()
         raise Exception(
             'The camera exposure is too low. Remember you enter it as seconds'
         )
Esempio n. 6
0
 def _take_Exposure_Wrapper(self, resultsDict, camera):
     #wrapper for taking images concurrently.
     if camera.camName == 'NEAR':
         resultsDict['NEAR'] = self.cameraNear.aquire_Image()
     elif camera.camName == 'FAR':
         resultsDict['FAR'] = self.cameraFar.aquire_Image()
     else:
         gv.error_Sound()
         raise Exception('NO VALID CAMERA NAME PROVIDED')
Esempio n. 7
0
 def change_Directory_And_Catch_File_Errors(self):
     imagesFolder = self.runName + 'Folder'
     try:
         os.mkdir(self.path + '\\' + imagesFolder)
     except FileExistsError:
         gv.error_Sound()
         print('That file already exists!!')
         exit()
     except:
         raise Exception('some other file issue')
     os.chdir(self.path + '\\' + imagesFolder)
 def set_Servo_Position(self,deg):
     if self.pinName!=gv.servoPin:
         print("-------------ERROR----------------------------")
         print('YOU CAN ONLY CONTROL THE SERVO THROUGH THE SERVO PIN')
         print("----------------end ERROR-------------")
         gv.error_Sound()
         sys.exit()
     m=.5/90 #ms/degree
     b=1.5 #ms
     width= m*deg+b
     width=width/1e3 #convert to seconds
     sep=20E-3 #pulse seperation, seconds    az CVBNM,.CVBNM
     self.generate_Digital_Pulse_Train(width=width,sep=sep)
Esempio n. 9
0
    def _initialize_Cameras(self):
        binNearX = self.binSizeNear
        binNearY = self.binSizeNear
        binFarX = self.binSizeFarX
        binFarY = self.binSizeFarY
        if binFarX <= 0 and binFarY <= 0:
            raise Exception('Both bin values cannot be zero')
        elif binFarX == 0:
            binFarX = binFarY
        elif binFarY == 0:
            binFarY = binFarX

        if binNearX <= 0 and binNearY <= 0:
            raise Exception('Both bin values cannot be zero')
        elif binNearX == 0:
            binNearX = binNearY
        elif binNearY == 0:
            binNearY = binNearX

        if self.GUI.cameraVarData.get() == 'BOTH':
            self.cameraFar = Camera('FAR',
                                    self.expTimeFar,
                                    self.imageParamFar,
                                    binx=binFarX,
                                    biny=binFarY)
            self.cameraNear = Camera('NEAR',
                                     self.expTimeNear,
                                     self.imageParamNear,
                                     binx=binNearX,
                                     biny=binNearY)
        elif self.GUI.cameraVarData.get() == 'NEAR':
            self.cameraNear = Camera('NEAR',
                                     self.expTimeNear,
                                     self.imageParamNear,
                                     binx=binNearX,
                                     biny=binNearY)
        elif self.GUI.cameraVarData.get() == 'FAR':
            self.cameraFar = Camera('FAR',
                                    self.expTimeFar,
                                    self.imageParamFar,
                                    binx=binFarX,
                                    biny=binFarY)
        else:
            gv.error_Sound()
            raise Exception('NO VALID CAMERA NAME PROVIDED')
    def run(self):
        self.save_Settings()
        self.initialize_Camera()
        if os.path.isdir(self.folderPath.get()) == False:
            print('-----ERROR-----------')
            print('YOU HAVE ENTERED AN INVALID FOLDERPATH')
        if os.path.isfile(self.folderPath.get() + '\\' + self.fileName.get() +
                          '.png') == True:
            print('--------------ERROR-------')
            print('THERE IS ALREADY A FILE WITH THAT NAME IN THAT FOLDER')
            gv.error_Sound()
            sys.exit()

        if self.ratioVar.get() == True:
            self.sweep_With_Shutter()
        else:
            self.sweep_Without_Shutter()
        self.camera.close()
 def generate_Digital_Pulse_Train(self,freq=None,duty=None,width=None,sep=None):
     #provided units must be SI
     if self.pinName!=gv.servoPin:
         print("-------------ERROR----------------------------")
         print('YOU ARE TRYING TO SEND A DIGITAL PULSE THROUGH THE WRONG PIN')
         print("----------------end ERROR-------------")
         gv.error_Sound()
         sys.exit()
     #either freq or duty must not be None, or width and sep must not be None
     error=False
     if freq is not None and width is not None:
         error=True
     if duty is not None and sep is not None:
         error=True
     if freq is None and sep is None:
         error=True
     if duty is None and width is None:
         error=True
     if error==True:
         print("-------------ERROR----------------------------")
         print('YOU CAN ONLY SET PULSE WIDTH AND SEPERATION OR FREQUENCY AND DUTY')
         print("----------------end ERROR-------------")
         gv.error_Sound()
         sys.exit()
     if sep is not None and width is not None:
         if (width<sep)==False:
             print("-------------ERROR----------------------------")
             print('PULSE WIDTH MUST BE LESS THAN SEPERATION')
             print("----------------end ERROR-------------")
             gv.error_Sound()
             sys.exit()
         freq=1/sep
         duty=width/sep
     if self.thread is not None:
         #if the channel and thread is already running it needs to be stopped
         self.thread.join()
         self.daqChannel.stop()
     self.channelObject.co_pulse_duty_cyc=duty
     self.channelObject.co_pulse_freq=freq
     self.thread=threading.Thread(target=self.daqChannel.start())
     self.thread.start()
 def close_Shutter(self):
     if self.type!='digitalOut':
         gv.error_Sound()
         raise Exception('Incorrect pin to control shutter')
     self.write_Low()
Esempio n. 13
0
    def _catch_And_Fix_Errors(self):
        if self.camName != 'FAR' and self.camName != 'NEAR':
            print('---------------ERROR----------------')
            print(
                'NO VALID CAMERA NAME PROVIDED. VALID NAMES ARE \'NEAR\' AND \'FAR\''
            )
            gv.error_Sound()
            sys.exit()

        #make image params integer if not already so
        if self.imageParams is not None:
            for i in range(4):
                self.imageParams[i] = int(self.imageParams[i])

        #binning results cannot conflict
        binError = False
        if self.bin is None and self.binx is None and self.biny is None:
            binError = True
        if self.bin is not None and (self.binx is not None
                                     or self.biny is not None):
            binError = True
        if self.bin is None and (self.binx is None or self.biny is None):
            binError = True
        if self.bin == 0 or self.binx == 0 or self.biny == 0:
            raise Exception("NONE OF THE BIN VALUES CAN BE 0")
        if binError == True:
            print('------------ERROR-------------')
            print('YOU HAVE SET A DISALLOWED BIN CONFIGURATION')
            print(
                'ALLOWED CONFIGURATIONS: bin=value, binx=None,biny=None OR bin=None, binx=value1,biny=value2'
            )
            print('BY DEFAULT ALL ARE NONE AND THEN bin IS THEN SET TO 1')
            sys.exit()
        if self.bin is None and self.binx is None and self.biny is None:
            self.bin = 1
            self.binx = 1
            self.biny = 1
        if self.bin is not None:
            self.binx = self.bin
            self.biny = self.bin

        x1, x2, y1, y2 = self.imageParams
        if self.camName == 'FAR':
            # if self.binx<0 or self.binx>16 or self.biny<0 or self.biny>16:
            #     print('----------ERROR-------------')
            #     print('VALID RANGE OF BINNING FOR FLI CAMERA IS 1 TO 16')
            #     gv.error_Sound()
            #     sys.exit()
            if self.expTime < 50:
                print('----------ERROR-------------')
                print('FLI CAMERA EXPOSURE MUST BE AT LEAST 50 ms')
                gv.error_Sound()
                sys.exit()

        if self.camName == 'NEAR':
            xMax = self.cameraObject.get_width_maximum()
            yMax = self.cameraObject.get_height_maximum()
        if self.camName == 'FAR':
            xMax = 1024
            yMax = 1024

        if x1 < 0 or x2 < 0 or y1 < 0 or y2 < 0:
            print('NO IMAGE DIMENSION VALUES CAN BE NEGATIVE')
            gv.error_Sound()
            sys.exit()
        if x2 > xMax or y2 > yMax:
            print('-------WARNING-----------')
            print(
                'ATTEMPTING TO USE AN IMAGE REGION THAT IS LARGER THAN AVAILABLE SIZE \n'
                'MAXIMUM DIMENSIONS ARE: ' + str(xMax) + ',' + str(yMax))
            print('CONFLICTING DIMENSION WILL BE CHANGED TO MAXIMUM')
            print('-----------END OF WARNING------------')
            gv.warning_Sound()
            if x2 > xMax:
                x2 = xMax
            if y2 > yMax:
                y2 = yMax
        if x2 <= x1 or y2 <= y1:
            print(
                'END OF IMAGE REGION CANNOT BE BEFORE OR AT BEGINNING BEGINNING'
            )
            gv.error_Sound()
            sys.exit()
        if x1 == x2 or y1 == y2:
            raise Exception(
                'IMAGE BOUNDS CANNOT BE THE SAME. X1/=X2 AND Y1/=Y2')

        #make image size and binning line up correctly
        if self.camName == 'NEAR':
            x1New = self.binx * 8 * (x1 // (self.binx * 8))
            x2New = self.binx * 8 * (x2 // (self.binx * 8))
            y1New = self.biny * 8 * (y1 // (self.biny * 8))
            y2New = self.biny * 8 * (y2 // (self.biny * 8))
            if x1New != x1 or x2New != x2 or y1New != y1 or y2New != y2:
                print('----------WARNING-----------')
                print(
                    'Image region for Ximea needs to be both even multiple of 8 as well as an even'
                )
                print('multiple of the bin size. Adusting now.')
                print('Previous value [x1,x2,y1,y2]: ', [x1, x2, y1, y2])
                x1 = x1New
                x2 = x2New
                y1 = y1New
                y2 = y2New
                print('New values are now [x1,x2,y1,y2]: ', [x1, x2, y1, y2])
                print('---------------END OF WARNING---------------')
                gv.warning_Sound()
        elif self.camName == 'FAR':
            x1New = self.binx * (x1 // self.binx)
            x2New = self.binx * (x2 // self.binx)
            y1New = self.biny * (y1 // self.biny)
            y2New = self.biny * (y2 // self.biny)
            if x1New != x1 or x2New != x2 or y1New != y1 or y2New != y2:
                print('----------WARNING-----------')
                print(
                    'Image region needs to be an even multiple of bin size. Adjusting now.'
                )
                print('Previous value [x1,x2,y1,y2]: ', [x1, x2, y1, y2])
                x1 = x1New
                x2 = x2New
                y1 = y1New
                y2 = y2New
                print('New values are now [x1,x2,y1,y2]: ', [x1, x2, y1, y2])
                print('---------------END OF WARNING---------------')
                gv.warning_Sound()
        #after massaging the parameters to work with the binning and other restrictions, it's possible that all value
        #could now equal each other
        if x1 == x2 or y1 == y2:
            print('------------ERROR-------------')
            print(
                'AFTER ADJUSTING IMAGE PARAMETERS TO FIT CONSTRAINTS X OR Y IMAGE DIMENSIONS NOW EQUAL EACH OTHER'
            )
            print(
                'PICK DIFFERENT IMAGE PARAMETERS THAT ARE SEPERATED BY MORE THAN A MULTIPLE OF THE PRODUCT OF '
            )
            print('BIN SIZE AND MINIMUM SEPERATION')
            gv.error_Sound()
            sys.exit()
        self.imageParams = [x1, x2, y1,
                            y2]  #change image params list to corrected values
    def catch_Errors_Analysis(self):
        fileName = self.anlFileNameBox.get()
        folderPath = self.anlFolderPathBox.get()
        try:
            x1 = int(self.x1BoxAnl.get())
            x2 = int(self.x2BoxAnl.get())
            y1 = int(self.y1BoxAnl.get())
            y2 = int(self.y2BoxAnl.get())
        except:
            print('---------ERROR-----------')
            print(
                'YOU MUST ENTER A NON NEGATIVE NUMBER IN THE IMAGE DIMENSION BOX.'
            )
            print(
                'YOU MAY HAVE LEFT THEM BLANK OR ENTER A LETTER, A SPACE, OR SOME OTHER NON NUMBER CHARACTER'
            )
            gv.error_Sound()
            sys.exit()
        if x2 < x1 or y2 < y1:
            print('---------ERROR-------------')
            print('X2 AND Y2 MUST NOT BE SMALLER THAN X1 AND Y1')
            gv.error_Sound()
            sys.exit()
        if x2 == x1 or y1 == y2:
            print('-----------ERROR---------')
            print('X2 AND Y2 CANNOT EQUAL X1 AND Y1')
            gv.error_Sound()
            sys.exit()
        if folderPath == '':
            print('-----ERROR-----------')
            print('YOU HAVENT ENTERED ANYTHING FOR THE FOLDERPATH')
            gv.error_Sound()
            sys.exit()
        if fileName == '':
            print('-----ERROR-----------')
            print('YOU HAVENT ENTERED ANYTHING FOR THE FOLDERPATH')
            gv.error_Sound()
            sys.exit()

        if os.path.isdir(folderPath) == False:
            print('-----ERROR-----------')
            print('YOU HAVE ENTERED AN INVALID FOLDERPATH')
            gv.error_Sound()
            sys.exit()
    def catch_Errors_Aquisition(self):
        #this checks all the boxes that should be numbers to see if they contain a number. If this isn't done here
        #then a less helpful error will be thrown when trying to convert nonsense into a number
        tempList = []
        tempList.append(self.x1NearBox.get())
        tempList.append(self.x2NearBox.get())
        tempList.append(self.y1NearBox.get())
        tempList.append(self.y2NearBox.get())
        tempList.append(self.x1FarBox.get())
        tempList.append(self.x2FarBox.get())
        tempList.append(self.y1FarBox.get())
        tempList.append(self.y2FarBox.get())
        tempList.append(self.expTimeFarBox.get())
        tempList.append(self.expTimeNearBox.get())
        tempList.append(self.expNumBox.get())
        tempList.append(self.binSizeFarBoxX.get())
        tempList.append(self.binSizeFarBoxY.get())
        tempList.append(self.binSizeNearBox.get())
        tempList.append(self.startVoltBox.get())
        tempList.append(self.stopVoltBox.get())
        for item in tempList:
            if item == '':
                print('----------ERROR-------------')
                print(
                    'YOU HAVE NOTHING ENTERED FOR ONE OF THE CAMERA/IMAGE/SCAN PARAMETER BOXS'
                )
                gv.error_Sound()
                sys.exit()
            try:
                float(item)
            except:
                print('----------ERROR-------------')
                print(
                    'YOU HAVE ENTERED SOMETHING OTHER THAN A NUMBER FOR ONE OF THE CAMERA/IMAGE/SCAN PARAMETER BOXS'
                )
                print(
                    'ITS POSSIBLE THAT YOU ENTERED SOMETHING WITH A WEIRD FORMAT ALSO'
                )
                gv.error_Sound()
                sys.exit()
        folderPath = self.dataFolderPathBox.get()
        fileName = self.dataFileNameBox.get()
        if folderPath == '':
            print('-----ERROR-----------')
            print('YOU HAVENT ENTERED ANYTHING FOR THE FOLDERPATH')
            gv.error_Sound()
            sys.exit()
        if fileName == '':
            print('-----ERROR-----------')
            print('YOU HAVENT ENTERED ANYTHING FOR THE FOLDERPATH')
            gv.error_Sound()
            sys.exit()

        if os.path.isdir(folderPath) == False:
            print('-----ERROR-----------')
            print('YOU HAVE ENTERED AN INVALID FOLDERPATH')
            gv.error_Sound()
            sys.exit()

        if os.path.isfile(folderPath + '\\' + fileName + 'Near.fits') == True:
            print('-----ERROR-----------')
            print('YOU ALREADY HAVE A FILE WITH THAT NAME IN THAT FOLDER')
            gv.error_Sound()
            sys.exit()
        if os.path.isfile(folderPath + '\\' + fileName + 'Far.fits') == True:
            print('-----ERROR-----------')
            print('YOU ALREADY HAVE A FILE WITH THAT NAME IN THAT FOLDER')
            gv.error_Sound()
            sys.exit()