Exemplo n.º 1
0
    def initialize_isoplane(self):
        rm = pyvisa.ResourceManager()
        try:
            # 'ASRL4::INSTR' is the port which the Isoplane is connected to. Change as required.
            self.isoplane = rm.open_resource('ASRL4::INSTR')
            self.isoplane.timeout = 300000
            self.isoplane.baud_rate = 9600

            self.isoplane.read_termination = ' ok\r\n'
            self.isoplane.write_termination = '\r'

            self.finished_grating_query()

            post.eventlog(self, 'Isoplane: Connected.')
            self.buttonGratingState.setText('Turn Off')
            self.buttonGratingState.setStyleSheet('background: #121212')
            self.grating = True

        except pyvisa.errors.VisaIOError as error:
            self.buttonGratingUpdate.setDisabled(True)
            self.buttonGratingState.setDisabled(True)
            self.grating = False
            post.eventlog(
                self,
                'Isoplane: Could not connect. Possibly being used in another process.'
            )
            print(error)
Exemplo n.º 2
0
    def spectralacq_update(self):
        # Storing and setting the acquisition time
        self.exposuretime = float(self.spectralRequiredTime.text())
        self.andor.setexposuretime(self.exposuretime)

        # Updating the actual acquisition time that has been set
        self.andor.getacquisitiontimings()
        self.spectralActualTime.setText(str(round(self.andor.exposure, 3)))
        post.eventlog(
            self,
            'Andor: Exposure time set to ' + str(self.exposuretime) + 's')
Exemplo n.º 3
0
    def grating_state(self):
        if self.grating is True:
            self.isoplane.close()

            post.eventlog(self, 'Isoplane: Disconnected.')
            self.buttonGratingState.setText('Turn On')
            self.buttonGratingState.setStyleSheet('background: #121212')
            self.buttonGratingUpdate.setDisabled(True)
            self.grating = False

        elif self.grating is False:
            self.initialize_isoplane()
Exemplo n.º 4
0
    def closeEvent(self, event):
        # Method to carry out operations upon closing the main window
        self.andor.iscooleron()
        error_setshutter = self.andor.setshutter(1, 2, 0, 0)
        if self.andor.coolerstatus == 1 or error_setshutter == 'DRV_SUCCESS':
            event.ignore()
            post.eventlog(self, 'ScanCARS needs to SHUTDOWN first.')

        else:
            if self.winspecsum.isVisible() or self.winspecdiff.isVisible():
                self.winspecsum.close()
                self.winspecdiff.close()
Exemplo n.º 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)
Exemplo n.º 6
0
    def finished_acquisition(self):
        if not self.acquisition_cancelled:
            finish = time.time()
            # 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.xpixels = self.x_required
                acqproperties.ypixels = self.y_required
                acqproperties.zpixels = self.z_required
                acqproperties.xystep = float(self.hyperspectralXYStep.text())
                acqproperties.zstep = float(self.hyperspectralZStep.text())

                savetofile.save(self.hyperspectral_data,
                                str(filename[0]),
                                acqproperties,
                                acqtype='hyperspectral')

                # TODO progress bar
                post.eventlog(self, 'Hyperspectral acquisition saved')

            else:
                # TODO progress bar
                post.eventlog(self, 'Acquisition aborted.')

            # Finishing up UI acquisition call
            self.andor.setshutter(1, 2, 0, 0)
            post.status(self, '')
            self.buttonHyperspectralStart.setText(
                'Start Hyperspectral Acquisition')
            self.progressbar.setValue(0)
            post.eventlog(
                self,
                'Time taken: ' + str(round(finish - self.start, 1)) + 's')
            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, 'Hyperspectral acquisition aborted.')
            self.buttonHyperspectralStart.setText(
                'Start Hyperspectral Acquisition')
            toggle.activate_buttons(self)
Exemplo n.º 7
0
    def camtracks_update(self):
        # Reading in the required track position values from the gui
        randtrack = np.array([
            int(float(self.camtrackLower1.text())),
            int(float(self.camtrackUpper1.text())),
            int(float(self.camtrackLower2.text())),
            int(float(self.camtrackUpper2.text()))
        ])

        # Setting the random track positions on the camera
        errormessage = self.andor.setrandomtracks(2, randtrack)

        # Checking to make sure that the camera has successfully set the random tracks
        if errormessage != 'DRV_SUCCESS':
            post.eventlog(self,
                          'Andor: SetRandomTracks error. ' + errormessage)

        else:
            post.eventlog(self, 'Andor: Random track positions updated.')
Exemplo n.º 8
0
    def finished_grating_query(self, message=None):
        self.isoplane.clear()
        grating_no = self.isoplane.ask('?GRATING')
        grating_no = int(grating_no[1])

        self.isoplane.clear()
        wavelength_no = self.isoplane.ask('?NM')
        wavelength_no = round(float(wavelength_no[0:-3]))

        if self.grating150.isChecked() and grating_no == 2:
            self.grating600.setChecked(True)

        elif self.grating600.isChecked() and grating_no == 3:
            self.grating150.setChecked(True)

        self.gratingActualWavelength.setText(str(wavelength_no))

        if message is not None:
            post.eventlog(self, message)
Exemplo n.º 9
0
    def grating_update(self):
        post.eventlog(self, 'Isoplane: Updating...')
        self.isoplane.clear()
        grating_no = self.isoplane.ask('?GRATING')
        grating_no = int(grating_no[1])

        self.isoplane.clear()
        wavelength_no = self.isoplane.ask('?NM')
        wavelength_no = round(float(wavelength_no[0:-3]))

        if self.grating150.isChecked() and grating_no == 2:
            setgrating = grating.GratingThread(self.isoplane,
                                               query='grating',
                                               value=3)
            self.threadpool.start(setgrating)
            message = 'Isoplane: Grating set to 150 lines/mm'
            setgrating.signals.finished.connect(
                lambda: self.finished_grating_query(message))

        elif self.grating600.isChecked() and grating_no == 3:
            setgrating = grating.GratingThread(self.isoplane,
                                               query='grating',
                                               value=2)
            self.threadpool.start(setgrating)
            message = 'Isoplane: Grating set to 600 lines/mm'
            setgrating.signals.finished.connect(
                lambda: self.finished_grating_query(message))

        if int(self.gratingRequiredWavelength.text()) != wavelength_no:
            reqwavelength = int(self.gratingRequiredWavelength.text())
            setwavelength = grating.GratingThread(self.isoplane,
                                                  query='wavelength',
                                                  value=reqwavelength)
            self.threadpool.start(setwavelength)
            message = 'Isoplane: Wavelength set to ' + str(
                reqwavelength) + ' nm'
            setwavelength.signals.finished.connect(
                lambda: self.finished_grating_query(message))
Exemplo n.º 10
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.')
Exemplo n.º 11
0
    def cameratemp_cooler(self):
        # Checking to see if the cooler is on or off
        message_iscooleron = self.andor.iscooleron()
        if message_iscooleron != 'DRV_SUCCESS':
            post.eventlog(self,
                          'Andor: IsCoolerOn error. ' + message_iscooleron)

        else:
            if self.andor.coolerstatus == 0:
                # Turning the cooler on and checking to see if it has been turned on
                self.andor.settemperature(
                    int(self.cameratempRequiredTemp.text()))
                self.andor.cooleron()
                self.andor.iscooleron()
                if self.andor.coolerstatus == 1:
                    post.eventlog(self, 'Andor: Cooler on.')
                    self.cameratempActualTemp.setStyleSheet(
                        'background: #4e644e')
                    self.buttonCameratempCooler.setText('Cooler Off')

            elif self.andor.coolerstatus == 1:
                # Turning the cooler off and checking to see if it has been turned off
                self.andor.cooleroff()
                self.andor.iscooleron()
                if self.andor.coolerstatus == 0:
                    post.eventlog(self, 'Andor: Cooler off.')
                    self.cameratempActualTemp.setStyleSheet(
                        'background: #121212')
                    self.buttonCameratempCooler.setText('Cooler On')

            else:
                # Shouldn't expect this to be called, if it is then it's unlikely to be related to the Andor
                post.eventlog(
                    self,
                    'An error has occured. Possibly related to the GUI itself?'
                )
Exemplo n.º 12
0
            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)
Exemplo n.º 13
0
 def gain_update(self):
     dial_value = int(self.dialGain.value())
     self.andor.setemccdgain(dial_value)
     post.eventlog(self, 'Andor: Gain set to ' + str(dial_value))