예제 #1
0
    def camtracks_view(self):
        # Creating instance of the live ccd chip thread
        ccdacquire_thread = ccdacquire.CcdAcquireThread(self)

        # If there's no current live ccd view taking place, then start one
        if self.ccdacquiring is False:
            self.ccdacquiring = True
            self.dialog_ccd()
            self.andor.setshutter(1, 1, 0, 0)
            toggle.deactivate_buttons(self, cameraoptions_openimage_stat=True)
            post.status(self, 'Live CCD view...')
            # self.buttonCamtrackView.setText('Stop Live View')

            # Camera parameters for live ccd acquisition
            self.andor.freeinternalmemory()
            self.andor.setreadmode(4)
            self.andor.setacquisitionmode(1)
            self.andor.setexposuretime(self.exposuretime)

            time.sleep(1)

            # Starting live ccd acquisition thread and connecting to plot function
            self.threadpool.start(ccdacquire_thread)
            ccdacquire_thread.signals.dataLiveAcquire.connect(lambda: plot())

            def plot():
                self.winccdlive.ccdliveWin.setImage(self.andor.imagearray)
                QCoreApplication.processEvents()

        elif self.ccdacquiring is True:
            self.ccdacquiring = False
            ccdacquire_thread.stop()
            toggle.activate_buttons(self)
            post.status(self, '')
예제 #2
0
    def hyperacq_start(self):
        # Storing values for hyperspectral acquisition
        self.x_required = int(self.hyperspectralXPix.text())
        self.y_required = int(self.hyperspectralYPix.text())
        self.z_required = int(self.hyperspectralZPix.text())
        self.total_pixels = self.x_required * self.y_required * self.z_required

        xystep_voltage = float(self.hyperspectralXYStep.text()) / 20
        zstep_voltage = float(self.hyperspectralZStep.text()) / 2

        self.exposuretime = float(self.hyperspectralRequiredTime.text())
        self.background_frames = int(self.hyperspectralBackgroundFrames.text())

        # Creating an instance of the hyperspectral acquisition thread
        hyperthread = hyperacquire.HyperAcquireThread(
            self, self.x_required, self.y_required, self.z_required,
            xystep_voltage, zstep_voltage, self.exposuretime,
            self.background_frames)

        # If there's no acquisition taking place, then start one
        if self.hyperacquiring is False:
            self.hyperacquiring = True
            self.andor.setshutter(1, 1, 0, 0)
            toggle.deactivate_buttons(self, hyperacq_start_stat=True)
            post.status(self, 'Hyperspectral acquisition in progress...')
            self.buttonHyperspectralStart.setText(
                'Stop Hyperspectral Acquisition')

            # Camera parameters for hyperspectral acquisition
            self.andor.freeinternalmemory()
            self.andor.setacquisitionmode(1)
            self.andor.setexposuretime(self.exposuretime)

            width = self.width
            self.hyperspectral_data = np.zeros(
                (self.x_required, self.y_required, self.z_required, 2 * width))
            self.imageplot_data = np.zeros((self.x_required, self.y_required))

            time.sleep(1)

            # Starting hyperspectral acquisition thread and connecting to plot and store function
            self.start = time.time()
            self.threadpool.start(hyperthread)
            hyperthread.signals.dataHyperAcquire.connect(self.plot_and_store)
            hyperthread.signals.finishedHyperAcquire.connect(
                self.finished_acquisition)

        elif self.hyperacquiring is True:
            self.hyperacquiring = False
            hyperthread.stop()
            toggle.activate_buttons(self)
            post.status(self, '')
            self.buttonHyperspectralStart.setText(
                'Start Hyperspectral Acquisition')
예제 #3
0
    def main_shutdown(self):
        toggle.deactivate_buttons(self)

        # Saving the event logger contents to a textfile
        now = datetime.datetime.now()
        newpath = 'F:\\SIPCARS\\Data\\Logs\\' + now.strftime('%Y-%m-%d') + '\\'
        if not os.path.exists(newpath):
            os.makedirs(newpath)
        with open(newpath + 'eventlog--' + now.strftime('%H-%M-%S') + '.txt',
                  'w') as eventfile:
            eventfile.write(str(self.eventLogger.toPlainText()))

        # Ensuring all acquiring and temperature loops have been stopped
        self.acquiring = False
        self.gettingtemp = False

        # Turning the shutter off and checking to see if the camera cooler is on
        self.andor.setshutter(1, 2, 0, 0)
        self.andor.iscooleron()
        self.andor.gettemperature()

        # If the cooler is off, proceed to shutdown the camera
        if self.andor.coolerstatus == 0:  # and ui.andor.temperature > -20: # TODO Temp. whilst aligning
            self.andor.shutdown()
            # ui.isoplane.close()

            post.eventlog(self, 'ScanCARS can now be safely closed.')
            post.status(self, 'ScanCARS can now be safely closed.')

        # If the cooler is on, turn it off, wait for temp. to increase to -20C, and then shutdown camera
        else:
            self.andor.gettemperature()
            if self.andor.temperature < -20:
                post.eventlog(
                    self,
                    'Andor: Waiting for camera to return to normal temp...')
            self.andor.cooleroff()
            self.buttonCameratempCooler.setText('Cooler On')
            time.sleep(1)
            while self.andor.temperature < -20:
                time.sleep(3)
                self.andor.gettemperature()
                self.cameratempActualTemp.setText(str(self.andor.temperature))
                QCoreApplication.processEvents()

            self.andor.shutdown()
            # ui.isoplane.close()

            post.eventlog(self, 'ScanCARS can now be safely closed.')
            post.status(self, 'ScanCARS can now be safely closed.')
예제 #4
0
    def main_startacq(self):
        # Creating an instance of the live acquisition thread
        acquirethread = liveacquire.LiveAcquireThread(self)

        # If there's no current live acquisition taking place, then start one
        if self.acquiring is False:
            self.acquiring = True
            self.andor.setshutter(1, 1, 0, 0)
            toggle.deactivate_buttons(self, main_start_acq_stat=True)
            post.status(self, 'Acquiring...')
            self.buttonMainStartAcquisition.setText('Stop Acquisition')

            # Camera parameters from live acquisition
            self.andor.freeinternalmemory()
            self.andor.setacquisitionmode(1)
            self.andor.setexposuretime(self.exposuretime)

            time.sleep(1)

            # Starting live acquisition thread and connecting to plot function
            self.threadpool.start(acquirethread)
            acquirethread.signals.dataLiveAcquire.connect(lambda: plot())

            def plot():
                self.track1plot.setData(self.andor.imagearray[0:self.width -
                                                              1])
                self.track2plot.setData(
                    self.andor.imagearray[self.width:(2 * self.width) - 1])
                self.diffplot.setData(
                    self.andor.imagearray[self.andor.width:
                                          (2 * self.andor.width) - 1] -
                    self.andor.imagearray[0:self.andor.width - 1])

                self.sumdialogplot.setData(
                    self.andor.imagearray[self.width:(2 * self.width) - 1] +
                    self.andor.imagearray[0:self.width - 1])

                self.diffdialogplot.setData(
                    self.andor.imagearray[self.width:(2 * self.width) - 1] -
                    self.andor.imagearray[0:self.width - 1])

                QCoreApplication.processEvents()

        # If there's a live acquisition taking place, then stop it
        elif self.acquiring is True:
            self.acquiring = False
            acquirethread.stop()
            toggle.activate_buttons(self)
            post.status(self, '')
            self.buttonMainStartAcquisition.setText('Start Acquisition')
예제 #5
0
    def initialize_andor(self):
        toggle.deactivate_buttons(self)

        # Storing the positions of the random tracks in an array
        randtrack = np.array([
            int(self.camtrackLower1.text()),
            int(self.camtrackUpper1.text()),
            int(self.camtrackLower2.text()),
            int(self.camtrackUpper2.text())
        ])

        errorinitialize = self.andor.initialize()  # Initializing the detector
        if errorinitialize != 'DRV_SUCCESS':
            post.eventlog(self, 'Andor: Initialize error. ' + errorinitialize)
            return
        self.andor.getdetector()  # Getting information from the detector
        self.andor.setshutter(1, 2, 0, 0)  # Ensuring the shutter is closed
        self.andor.setreadmode(2)  # Setting the read mode to Random Tracks
        self.andor.setrandomtracks(
            2, randtrack)  # Setting the position of the random tracks
        self.andor.setadchannel(1)  # Setting the AD channel
        self.andor.settriggermode(0)  # Setting the trigger mode to 'internal'
        self.andor.sethsspeed(0, 0)  # Setting the horiz. shift speed
        self.andor.setvsspeed(4)  # Setting the verti. shift speed

        self.exposuretime = float(self.spectralRequiredTime.text())
        self.andor.setexposuretime(self.exposuretime)

        # Setting camera to gain mode and setting the initial gain
        gain_to_set = 10
        self.andor.setemccdgainmode(0)
        self.andor.setemccdgain(gain_to_set)
        self.dialGain.setValue(gain_to_set)
        gain_button_text = str(gain_to_set) + ': Update'
        self.buttonGain.setText(gain_button_text)

        time.sleep(2)

        self.andor.dim = self.andor.width * self.andor.randomtracks

        self.andor.getacquisitiontimings()
        self.spectralActualTime.setText(str(round(self.andor.exposure, 3)))

        toggle.activate_buttons(self)
        post.eventlog(self, 'Andor: Successfully initialized.')

        # Starting the temperature thread to monitor the temperature of the camera
        self.gettingtemp = True
        gettemperature = monitortemp.MonitorTemperatureThread(self)
        self.threadpool.start(gettemperature)
예제 #6
0
    def spectralacq_start(self):
        # Creating an instance of the spectral acquisition thread
        frames = int(self.spectralFrames.text())
        darkcount = int(self.spectralBackgroundFrames.text())
        spectralthread = spectralacquire.SpectralAcquireThread(
            self, frames, darkcount)

        # If there's no acquisition taking place, then start one
        if self.spectralacquiring is False:
            self.spectralacquiring = True
            self.andor.setshutter(1, 1, 0, 0)
            toggle.deactivate_buttons(self, spectralacq_start_stat=True)
            post.status(self, 'Spectral acquisition in progress...')
            self.buttonSpectralStart.setText('Stop Spectral Acquisition')

            # Camera parameters for spectral acquisition
            self.andor.freeinternalmemory()
            self.andor.setacquisitionmode(1)
            self.andor.setexposuretime(self.exposuretime)

            self.spectral_data = [0] * frames

            time.sleep(1)

            def plot_and_store(numscan):
                self.spectral_data[numscan] = self.andor.imagearray
                # TODO use spectra_data instead of imagearray following from here
                self.track1plot.setData(self.andor.imagearray[0:self.width -
                                                              1])
                self.track2plot.setData(
                    self.andor.imagearray[self.width:(2 * self.width) - 1])
                self.diffplot.setData(
                    self.andor.imagearray[self.width:(2 * self.width) - 1] -
                    self.andor.imagearray[0:self.width - 1])

                self.progressbar.setValue(
                    (darkcount + numscan + 1) / (darkcount + frames) * 100)

                QCoreApplication.processEvents()

            def finished_acquisition():
                if not self.acquisition_cancelled:
                    # Processing data
                    spectral_data = np.asarray(self.spectral_data)
                    spectral_data = np.transpose(spectral_data)

                    acquired_data = np.mean(spectral_data,
                                            1)  # - np.mean(dark_data, 1)

                    # Plotting the mean spectrum
                    self.track1plot.setData(acquired_data[0:self.width - 1])
                    self.track2plot.setData(
                        acquired_data[self.width:(2 * self.width) - 1])
                    self.diffplot.setData(acquired_data[self.width:
                                                        (2 * self.width) - 1] -
                                          acquired_data[0:self.width - 1])

                    self.previousplot.setData(
                        acquired_data[self.width:(2 * self.width) - 1] -
                        acquired_data[0:self.width - 1])

                    # # Saving the data to file
                    now = datetime.datetime.now()
                    newpath = self.user_directory + '\\' + now.strftime(
                        '%Y-%m-%d') + '\\'
                    if not os.path.exists(newpath):
                        os.makedirs(newpath)
                    filename = QFileDialog.getSaveFileName(caption='File Name',
                                                           filter='H5 (*.h5)',
                                                           directory=newpath)

                    if filename[0]:
                        acqproperties = savetofile.EmptyClass()
                        acqproperties.width = self.andor.width
                        acqproperties.time = self.exposuretime
                        acqproperties.number = frames

                        savetofile.save(spectral_data,
                                        str(filename[0]),
                                        acqproperties,
                                        acqtype='spectral')

                        self.progressbar.setValue(100)
                        post.eventlog(
                            self, 'Spectral acquisition saved.'
                        )  # TODO Print file name saved to as well

                    else:
                        self.progressbar.setValue(100)
                        post.eventlog(self, 'Acquisition aborted.')

                    # Finishing up UI acquisition call
                    self.andor.setshutter(1, 2, 0, 0)
                    post.status(self, '')
                    self.buttonSpectralStart.setText(
                        'Start Spectral Acquisition')
                    self.progressbar.setValue(0)
                    toggle.activate_buttons(self)

                else:
                    # Finishing up UI acquisition call
                    self.andor.setshutter(1, 2, 0, 0)
                    post.status(self, '')
                    self.progressbar.setValue(0)
                    self.acquisition_cancelled = False
                    post.eventlog(self, 'Spectral acquisition aborted.')
                    self.buttonSpectralStart.setText(
                        'Start Spectral Acquisition')
                    toggle.activate_buttons(self)

            # Starting spectral acquisition thread and connecting to plot and store function
            self.threadpool.start(spectralthread)
            spectralthread.signals.dataSpectralAcquire.connect(plot_and_store)
            spectralthread.signals.finishedSpectralAcquire.connect(
                finished_acquisition)

        elif self.spectralacquiring is True:
            self.spectralacquiring = False
            spectralthread.stop()
            toggle.activate_buttons(self)
            post.status(self, '')
            self.buttonSpectralStart.setText('Start Spectral Acquisition')
예제 #7
0
    def run(self):
        toggle.deactivate_buttons(self.gui)

        # Initializing the camera
        messageInitialize = self.gui.cam.Initialize()
        if messageInitialize is not None:
            self.gui.post.eventlog(self.gui, messageInitialize)
            return

        # Setting the shutter
        messageSetShutter = self.gui.cam.SetShutter(1, 2, 0, 0)
        if messageSetShutter is not None:
            self.gui.post.eventlog(self.gui, messageSetShutter)
            return

        # Setting read mode to Random Track and setting track positions
        messageSetReadMode = self.gui.cam.SetReadMode(2)
        if messageSetReadMode is not None:
            self.gui.post.eventlog(self.gui, messageSetReadMode)
            return

        RandomTrackposition = np.array([
            int(self.gui.CameraOptions_track1lower.text()),
            int(self.gui.CameraOptions_track1upper.text()),
            int(self.gui.CameraOptions_track2lower.text()),
            int(self.gui.CameraOptions_track2upper.text())
        ])

        messageSetRandomTrack = self.gui.cam.SetRandomTracks(
            2, RandomTrackposition)
        if messageSetRandomTrack is not None:
            self.gui.post.eventlog(self.gui, messageSetRandomTrack)
            return

        # Getting and setting AD channel
        messageGetNumberADChannels = self.gui.cam.GetNumberADChannels()
        if messageGetNumberADChannels is not None:
            self.gui.post.eventlog(self.gui, messageGetNumberADChannels)
            return

        messageSetADChannel = self.gui.cam.SetADChannel(1)
        if messageSetADChannel is not None:
            self.gui.post.eventlog(self.gui, messageSetADChannel)
            return

        # Setting trigger mode
        messageSetTriggerMode = self.gui.cam.SetTriggerMode(0)
        if messageSetTriggerMode is not None:
            self.gui.post.eventlog(self.gui, messageSetRandomTrack)
            return

        # Getting the detector chip size
        messageGetDetector = self.gui.cam.GetDetector()
        if messageGetDetector is not None:
            self.gui.post.eventlog(self.gui, messageGetDetector)
            return

        # Setting horizontal and vertical shift speeds
        messageSetHSSpeed = self.gui.cam.SetHSSpeed(1, 0)
        if messageSetHSSpeed is not None:
            self.gui.post.eventlog(self.gui, messageSetHSSpeed)
            return

        messageSetVSSpeed = self.gui.cam.SetVSSpeed(3)
        if messageSetVSSpeed is not None:
            self.gui.post.eventlog(self.gui, messageSetVSSpeed)
            return

        toggle.activate_buttons(self.gui)
        self.signals.finished.emit()