Exemplo n.º 1
0
class MainWindow(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        self.setWindowTitle( 'Biofeedback' )

        self.button_start = QPushButton()
        self.button_start.setText("START")
        self.button_stop = QPushButton()
        self.button_stop.setText("STOP")

        layout = QHBoxLayout(self)
        layout.addWidget(self.button_start)
        layout.addWidget(self.button_stop)

        self.connect(self.button_start, SIGNAL("clicked(bool)"), self.start_session)
        self.connect(self.button_stop, SIGNAL("clicked(bool)"), self.stop_session)

        self.setLayout(layout)
        self.setGeometry(300,100,250,100)
        self.show()

        #self.datastorage = DataStorage()
        #settings = {'db_host':'amber','db_user':'******','db_pwd':'dbrootpass','db_dbname':'biodb'}
        #self.datastorage.enableDbStorage(settings)


        self.thread = ConnectionThread()


    def start_session(self):
        self.thread.tsc.clearContainer()

        if VIRTUAL_SERIAL is True:
            self.thread.zephyr_connect.resume()

        #self.datastorage.timeseries = self.thread.tsc
        self.thread.start()
        self.thread.timer.start(1000)

    def stop_session(self):
        self.thread.stop()
        self.store_session()
Exemplo n.º 2
0
class dspAncWidget(dspWidget):
   def __init__(self, name, instanceId, widgetList, dataFunc, inactivityTimeout = True):
      dspWidget.__init__(self, name, instanceId, widgetList, inactivityTimeout = inactivityTimeout)

      self.dataFunc = dataFunc

      self.Fs = 2000

      layout = QGridLayout()
      self.setLayout(layout)

      self.resize(1024, 800)

      self.refPlotW = dspCurveWidget(mode="Freq",title="Reference PCM", show_itemlist=False)
      layout.addWidget(self.refPlotW, 1, 1, 1, 1)
      self.refExitButton = QPushButton("Hide")
      layout.addWidget(self.refExitButton, 1,0,1,1)
      self.connect(self.refExitButton, SIGNAL('clicked()'), self.refExitButtonPressed)

      self.errPlotW = dspCurveWidget(mode="Freq",title="Error Mic PCM", show_itemlist=False)
      layout.addWidget(self.errPlotW, 2, 1, 1, 1)
      self.errExitButton = QPushButton("Hide")
      layout.addWidget(self.errExitButton, 2,0,1,1)
      self.connect(self.errExitButton, SIGNAL('clicked()'), self.errExitButtonPressed)

      self.outPlotW = dspCurveWidget(mode="Freq",title="ANC Output", show_itemlist=False)
      layout.addWidget(self.outPlotW, 3, 1, 1, 1)
      self.outExitButton = QPushButton("Hide")
      layout.addWidget(self.outExitButton, 3,0,1,1)
      self.connect(self.outExitButton, SIGNAL('clicked()'), self.outExitButtonPressed)

      self.coefPlotW = dspCurveWidget(title="ANC Filter", mode="Freq", show_buttons=False, show_itemlist=True)
      self.coefPlotW.customCurve = self.updateFilterCurve
      self.coefPlotW.plotPoints = 1024
      layout.addWidget(self.coefPlotW, 4, 1, 1, 1)
      self.coefExitButton = QPushButton("Hide")
      layout.addWidget(self.coefExitButton, 4,0,1,1)
      self.connect(self.coefExitButton, SIGNAL('clicked()'), self.coefExitButtonPressed)

      #self.samples = QLabel("Samples ")
      #layout.addWidget(self.samples, 2,2)
      #self.samples_label =QLabel("Reference Mic Samples")
      #layout.addWidget(self.samples_label, 2,3,1,1)

            
   def kill(self):
      super(dspAncWidget, self).kill()
      self.coefPlotW.customCurve = None

   def refExitButtonPressed(self):
      if self.refPlotW.isVisible():
         self.refPlotW.hide()
         self.refExitButton.setText("Show")
      else:
         self.refPlotW.show()
         self.refExitButton.setText("Hide")
      
   def errExitButtonPressed(self):
      if self.errPlotW.isVisible():
         self.errPlotW.hide()
         self.errExitButton.setText("Show")
      else:
         self.errPlotW.show()
         self.errExitButton.setText("Hide")

   def outExitButtonPressed(self):
      if self.outPlotW.isVisible():
         self.outPlotW.hide()
         self.outExitButton.setText("Show")
      else:
         self.outPlotW.show()
         self.outExitButton.setText("Hide")

   def coefExitButtonPressed(self):
      if self.coefPlotW.isVisible():
         self.coefPlotW.hide()
         self.coefExitButton.setText("Show")
      else:
         self.coefPlotW.show()
         self.coefExitButton.setText("Hide")

   def update_samples_text(self, new_text):
       self.samples.setText(new_text)
        


   def update(self):
      try:
         anc = self.dataFunc(self.instanceId, self.preferredSamples)
      except RuntimeError:
         return
         
      refData = anc.get("ref")
      refChannels = anc.get("refChannels")
      refSamples = len(refData) / refChannels
      
      #self.update_samples_text(str(refSamples))

      errData = anc.get("err")
      errChannels = anc.get("errChannels")
      errSamples = len(errData) / errChannels

      outData = anc.get("out")
      outChannels = anc.get("outChannels")
      outSamples = len(outData) / outChannels


      wFilterData = anc.get("w")
      wChannels, wSamples = numpy.shape(wFilterData)

      # Conditional to keep backwards compatibility with old SPI logs. 
      Fs = anc.get('Fs') if (anc.get('Fs') != 0) else self.Fs

      self.refPlotW.update(Fs, refChannels, 1, refSamples, refData)
      self.errPlotW.update(Fs, errChannels, 1, errSamples, errData)
      self.outPlotW.update(Fs, outChannels, 1, outSamples, outData)
      self.coefPlotW.update(Fs,  wChannels, 1, 2*self.coefPlotW.plotPoints, wFilterData)
      self.refPlotW.BriefAnalysis.hide()
      self.errPlotW.BriefAnalysis.hide()
      self.outPlotW.BriefAnalysis.hide()
      #self.coefPlotW.BriefAnalysis.hide()
      self.refPlotW.update_box.hide()
      self.errPlotW.update_box.hide()
      self.outPlotW.update_box.hide()
      #self.coefPlotW.update_box.hide()
      self.refPlotW.update_box1.hide()
      self.errPlotW.update_box1.hide()
      self.outPlotW.update_box1.hide()
      #self.coefPlotW.update_box1.hide()
      self.refPlotW.Performance_config.hide()
      self.errPlotW.Performance_config.hide()
      self.outPlotW.Performance_config.hide()
      self.outPlotW.samples_label.hide()
      #self.coefPlotW.Performance_config.hide()
      self.refPlotW.Performance_off.hide()
      self.errPlotW.Performance_off.hide()
      self.outPlotW.Performance_off.hide()
      #self.coefPlotW.Performance_off.hide()



   def updateFilterCurve(self, plot, channel, data):
      channels, samples = numpy.shape(data)
      if (samples > 0 and self.coefPlotW.mode == "Freq"):
         self.coefPlotW.plotPoints = 1024
         w, h = scipy.signal.freqz(data[channel], 1, worN=self.coefPlotW.plotPoints)
         #y = numpy.unwrap(numpy.angle(h))
         y = 20*scipy.log10(numpy.abs(h))
         plot.curves[channel].set_data(plot.x, y)
      else:
         self.coefPlotW.plotPoints = samples/2
         plot.curves[channel].set_data(plot.x, 1000*data[channel])
         self.coefPlotW.spectrogramButton.setEnabled(False)
         self.coefPlotW.triggerButton.setEnabled(False)
         self.coefPlotW.PSDButton.setEnabled(False)
         

   def rescale(self):
      self.refPlotW.rescale()
      self.errPlotW.rescale()
      self.outPlotW.rescale()
      self.coefPlotW.rescale()
Exemplo n.º 3
0
class GreatEyesUi(QSplitter):
    '''
    Handling user interface to manage greateys cameras
    '''
    newPlotData = Signal(object, object)
    message = Signal(object)
    def __init__(self, parent):
        super().__init__(parent)

        self.camera = None
        self.cameraSettings = None
        self.aquireData = False
        self.directory = 'N:/4all/mpsd_drive/xtsfasta/Data'

        layoutWidget = QWidget()
        layout = QGridLayout()
        layoutWidget.setLayout(layout)

        ###############
        # GUI elements
        self.openCamBtn = QPushButton('Connect camera')
        self.startAquBtn = QPushButton('Start aquisiton')
        self.readoutSpeedCombo = QComboBox()
        # this really should not be hard coded but received from dll
        self.readoutSpeedCombo.addItems(["1 MHz", 
            "1.8 MHz",
            "2.3 MHz",
            "2.8 MHz",
            "250 kHz",
            "500 kHz"])
        self.exposureTimeSpin = QSpinBox()
        self.exposureTimeSpin.setRange(1, 1e6)
        self.exposureTimeSpin.setValue(1e3) # default exposure 1s
        self.exposureTimeSpin.setSingleStep(100)
        self.exposureTimeSpin.setSuffix(' ms')
        #self.exposureTimeSpin.setValidator(QIntValidator(1, 2**31)) # ms
        self.binningXCombo = QComboBox()
        self.binningXCombo.addItems(["No binning",
                  "Binning of 2 columns",
                  "Binning of 4 columns",
                  "Binning of 8 columns",
                  "Binning of 16 columns",
                  "Binning of 32 columns",
                  "Binning of 64 columns",
                  "Binning of 128 columns",
                  "Full horizontal binning"])
        self.binningYCombo = QComboBox()
        self.binningYCombo.addItems(["No binning",
                  "Binning of 2 lines",
                  "Binning of 4 lines",
                  "Binning of 8 lines",
                  "Binning of 16 lines",
                  "Binning of 32 lines",
                  "Binning of 64 lines",
                  "Binning of 128 lines",
                  "Binning of 256 lines"])
        self.temperatureSpin = QSpinBox()
        self.temperatureSpin.setRange(-100, 20)
        self.temperatureSpin.setValue(-10)
        self.temperatureSpin.setSuffix('°C')
        self.updateInterSpin = QSpinBox()
        self.updateInterSpin.setRange(1, 3600)
        self.updateInterSpin.setValue(5)
        self.updateInterSpin.setSuffix(' s')
        #self.updateInterSpin.setText("2")
        #self.updateInterEdit.setValidator(QIntValidator(1, 3600))
        self.loi = QSpinBox()
        self.loi.setRange(1, 511) # one pixel less as the camera has
        self.deltaPixels = QSpinBox()
        self.deltaPixels.setRange(0, 256)
        self.autoSave = QCheckBox("Auto save")
        self.getDirectory = QPushButton('Choose Dir')
        self.dirPath = QLineEdit(self.directory)
        self.comment = QPlainTextEdit()

        ##############
        # put elements in layout
        layout.addWidget(self.openCamBtn, 0, 0)
        layout.addWidget(self.startAquBtn, 0, 1)
        layout.addWidget(QLabel('readout speed'), 1, 0)
        layout.addWidget(self.readoutSpeedCombo, 1, 1)
        layout.addWidget(QLabel('exposure time'), 2, 0)
        layout.addWidget(self.exposureTimeSpin, 2, 1)
        layout.addWidget(QLabel('binning X'), 3, 0)
        layout.addWidget(self.binningXCombo, 3, 1)
        layout.addWidget(QLabel('binning Y'), 4, 0)
        layout.addWidget(self.binningYCombo, 4, 1)
        layout.addWidget(QLabel('temperature'), 5, 0)
        layout.addWidget(self.temperatureSpin, 5, 1)
        layout.addWidget(QLabel('update every n-seconds'), 6, 0)
        layout.addWidget(self.updateInterSpin, 6, 1)
        layout.addWidget(QLabel('Pixel of interest'), 7, 0)
        layout.addWidget(self.loi, 7, 1)
        layout.addWidget(QLabel('Δ pixels'), 8, 0)
        layout.addWidget(self.deltaPixels, 8, 1)
        layout.addWidget(self.autoSave, 9, 1)
        layout.addWidget(self.getDirectory, 10, 0)
        layout.addWidget(self.dirPath, 10, 1)
        layout.addWidget(QLabel('Comment:'), 11, 0)
        layout.addWidget(self.comment, 12, 0, 1, 2)
        layout.setRowStretch(13, 10)

        self.addWidget(layoutWidget)


        #################
        # connect elements for functionality
        self.openCamBtn.released.connect(self.__openCam)
        self.getDirectory.released.connect(self.__chooseDir)
        self.temperatureSpin.valueChanged.connect(self.__setTemperature)
        self.exposureTimeSpin.valueChanged.connect(self.__setCamParameter)
        self.readoutSpeedCombo.currentIndexChanged.connect(self.__setCamParameter)
        self.startAquBtn.released.connect(self.__startCurrImageThr)
        
        ################
        # thread for updating position
        self.currImage_thread = QThread() # create the QThread
        self.currImage_thread.start()

        # This causes my_worker.run() to eventually execute in my_thread:
        self.currImage_worker = GenericWorker(self.__getCurrImage)
        self.currImage_worker.moveToThread(self.currImage_thread)
 
        self.startAquBtn.setEnabled(False) 
        self.readoutSpeedCombo.setEnabled(False)
        self.exposureTimeSpin.setEnabled(False)
        self.binningXCombo.setEnabled(False)
        self.binningYCombo.setEnabled(False)
        self.temperatureSpin.setEnabled(False)
        self.updateInterSpin.setEnabled(False)
      


    def __openCam(self):
        self.camera = greatEyes()
        if not self.camera.connected:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Critical)
            msg.setText('Sorry, could not connect to camera :(\n' + 
                    self.camera.status)
            msg.exec_()
            return
        self.openCamBtn.setText('Connected')
        self.message.emit('Camera connected')
        self.openCamBtn.setStyleSheet('QPushButton {color: green;}')

        self.readoutSpeedCombo.setEnabled(True)
        self.exposureTimeSpin.setEnabled(True)
        self.binningXCombo.setEnabled(False)
        self.binningYCombo.setEnabled(False)
        self.temperatureSpin.setEnabled(True)
        self.updateInterSpin.setEnabled(True)

        self.openCamBtn.setEnabled(False)
        self.startAquBtn.setEnabled(True) 

    def __chooseDir(self):
        self.directory = QFileDialog.getExistingDirectory(self,
                "Choose directory",
                self.directory)
        self.dirPath.setText(self.directory)


    def __startCurrImageThr(self):
        if not self.aquireData:
            self.aquireData = True
            self.currImage_worker.start.emit()
            self.startAquBtn.setText('Stop aquisition')
            self.message.emit('Starting aqusition')
        else:
            self.__stopCurrImageThr()
            self.startAquBtn.setText('Start aquisition')
            self.message.emit('Stopping aqusition')
    def __stopCurrImageThr(self):
        self.aquireData = False
        #while(self.currPosThr.isRunning()):
        #    time.sleep(0.03)
    def __getCurrImage(self):
        #from scipy import mgrid
        #import numpy as np
        #X, Y = mgrid[-256:256, -1024:1025]
        i = self.updateInterSpin.value()
        while self.aquireData:
            # seconds over which to record a new image
            imageIntervall = self.updateInterSpin.value()
            # sleep for n seconds to check if intervall was changed
            sleepy = 1
            if i >= imageIntervall:
                # dummy image
                #z = np.exp(-0.5*(X**2+Y**2)/np.random.uniform(30000, 40000))*np.cos(0.1*X+0.1*Y)
                z = self.camera.getImage()
                timeStamp = datetime.datetime.now()
                self.cameraSettings = {
                        'temperature': self.camera.getTemperature(),
                        'exposure_time': self.exposureTimeSpin.value(),
                        'readout_speed': self.readoutSpeedCombo.currentText()
                        'time_stamp': timeStamp}
                self.newPlotData.emit(z, timeStamp)
                i = 0 # restart counter
            i += sleepy
            time.sleep(sleepy)

    def __setTemperature(self, temp):
        self.camera.setTemperture(temp)
        self.message.emit('Temperature set to {:d}°C'.format(temp))

    def __setCamParameter(self, param):
        self.camera.setCameraParameter(
                self.readoutSpeedCombo.currentIndex(), 
                self.exposureTimeSpin.value(), 
                0, 0)
        self.message.emit('Readout: {:s}, Exposure: {:d}, binningX: 0, binningY: 0'.format(self.readoutSpeedCombo.currentText(),
               self.exposureTimeSpin.value()))