def __init__(self, parent=None, paramfile=None, paramdictname=None):
        super(Paradigm, self).__init__(parent)

        #self.setStyleSheet(stylesheets.styleCompact)

        # -- Read settings --
        smServerType = rigsettings.STATE_MACHINE_TYPE
        #smServerType = 'dummy'

        # -- Module for saving data --
        self.saveData = savedata.SaveData(rigsettings.DATA_DIR)

        # -- Sides plot --
        sidesplot.set_pg_colors(self)
        self.mySidesPlot = sidesplot.SidesPlot(nTrials=80)

        # -- Create an empty state matrix --
        self.sm = statematrix.StateMatrix(inputs=rigsettings.INPUTS,
                                          outputs=rigsettings.OUTPUTS,
                                          readystate='ready_next_trial')

        # -- Add parameters --
        self.params = paramgui.Container()
        self.params['experimenter'] = paramgui.StringParam(
            'Experimenter', value='santiago', group='Session info')
        self.params['subject'] = paramgui.StringParam('Subject',
                                                      value='saja000',
                                                      group='Session info')
        sessionInfo = self.params.layout_group('Session info')

        self.params['stimulusDuration'] = paramgui.NumericParam(
            'Stim duration', value=0.2, group='Timing parameters')
        self.params['rewardDuration'] = paramgui.NumericParam(
            'Reward duration', value=0.05, group='Timing parameters')
        timingParams = self.params.layout_group('Timing parameters')

        # -- Load parameters from a file --
        #self.params.from_file('params_008.py','saja002') ### DEBUG
        self.params.from_file(paramfile, paramdictname)

        # -- Create dispatcher --
        self.dispatcherModel = dispatcher.Dispatcher(serverType=smServerType,
                                                     interval=0.3)
        self.dispatcherView = dispatcher.DispatcherGUI(
            model=self.dispatcherModel)

        # -- Manual control of outputs --
        self.manualControl = manualcontrol.ManualControl(
            self.dispatcherModel.statemachine)

        # -- Add graphical widgets to main window --
        centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QVBoxLayout()
        layoutTop = QtGui.QVBoxLayout()
        layoutBottom = QtGui.QHBoxLayout()
        layoutCol1 = QtGui.QVBoxLayout()
        layoutCol2 = QtGui.QVBoxLayout()

        layoutMain.addLayout(layoutTop)
        #layoutMain.addStretch()
        layoutMain.addSpacing(0)
        layoutMain.addLayout(layoutBottom)

        layoutTop.addWidget(self.mySidesPlot)

        layoutBottom.addLayout(layoutCol1)
        layoutBottom.addLayout(layoutCol2)

        layoutCol1.addWidget(self.saveData)
        layoutCol1.addWidget(sessionInfo)
        layoutCol1.addWidget(self.dispatcherView)

        layoutCol2.addWidget(timingParams)
        layoutCol2.addWidget(self.manualControl)

        centralWidget.setLayout(layoutMain)
        self.setCentralWidget(centralWidget)

        # -- Center in screen --
        self.center_in_screen()

        # -- Add variables for storing results --
        maxNtrials = 4000
        self.results = arraycontainer.Container()
        self.results.labels['rewardSide'] = {'left': 0, 'right': 1}
        self.results['rewardSide'] = np.random.randint(2, size=maxNtrials)
        self.results.labels['choice'] = {'left': 0, 'right': 1, 'none': 2}
        self.results['choice'] = np.empty(maxNtrials, dtype=int)
        self.results.labels['outcome'] = {
            'correct': 1,
            'error': 0,
            'invalid': 2
        }
        self.results['outcome'] = np.empty(maxNtrials, dtype=int)
        self.results['timeTrialStart'] = np.empty(maxNtrials, dtype=float)
        self.results['timeCenterIn'] = np.empty(maxNtrials, dtype=float)
        self.results['timeCenterOut'] = np.empty(maxNtrials, dtype=float)
        self.results['timeSideIn'] = np.empty(maxNtrials, dtype=float)

        # --- Create state matrix ---
        #self.set_state_matrix() ################# ?????????????

        # -- Connect signals from dispatcher --
        self.dispatcherModel.prepareNextTrial.connect(self.prepare_next_trial)
        ###self.dispatcherModel.startNewTrial.connect(self.start_new_trial)
        self.dispatcherModel.timerTic.connect(self.timer_tic)

        # -- Connect messenger --
        self.messagebar = messenger.Messenger()
        self.messagebar.timedMessage.connect(self.show_message)
        #self.messagebar.timedMessage.emit('Created window')
        self.messagebar.collect('Created window')

        # -- Connect signals to messenger
        self.saveData.logMessage.connect(self.messagebar.collect)
        self.dispatcherModel.logMessage.connect(self.messagebar.collect)

        # -- Connect other signals --
        self.saveData.buttonSaveData.clicked.connect(self.save_to_file)

        # -- Prepare first trial --
        self.prepare_next_trial(0)
示例#2
0
    def __init__(self, parent=None, paramfile=None, paramdictname=None):
        super(NoiseCalibration, self).__init__(parent)

        self.name = 'noisecalibration'
        self.soundServer = self.initialize_sound()

        # -- Add graphical widgets to main window --
        self.centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QHBoxLayout()
        layoutRight = QtGui.QVBoxLayout()

        self.soundControlL = SoundControl(self.soundServer,
                                          channel=0,
                                          channelName='left')
        self.soundControlR = SoundControl(self.soundServer,
                                          channel=1,
                                          channelName='right')

        self.saveButton = SaveButton([self.soundControlL, self.soundControlR])

        soundTargetIntensityLabel = QtGui.QLabel('Target intensity [dB-SPL]')
        self.soundTargetIntensity = QtGui.QLineEdit()
        self.soundTargetIntensity.setText(str(DEFAULT_INTENSITY))
        self.soundTargetIntensity.setEnabled(False)
        computerSoundLevelLabel = QtGui.QLabel('Computer sound level [%]')
        self.computerSoundLevel = QtGui.QLineEdit()
        self.computerSoundLevel.setText(str(rigsettings.SOUND_VOLUME_LEVEL))
        self.computerSoundLevel.setEnabled(False)

        #TODO: Implement loading, probably not plotting though
        # self.loadButton = LoadButton([self.soundControlL,self.soundControlR])
        # self.plotButton = PlotButton([self.soundControlL,self.soundControlR])

        layoutRight.addWidget(self.saveButton)

        layoutRight.addWidget(soundTargetIntensityLabel)
        layoutRight.addWidget(self.soundTargetIntensity)
        layoutRight.addWidget(computerSoundLevelLabel)
        layoutRight.addWidget(self.computerSoundLevel)

        # layoutRight.addWidget(self.loadButton)
        # layoutRight.addWidget(self.plotButton)
        layoutRight.addStretch()

        layoutMain.addWidget(self.soundControlL)
        layoutMain.addWidget(VerticalLine())
        layoutMain.addWidget(self.soundControlR)
        layoutMain.addWidget(VerticalLine())
        layoutMain.addLayout(layoutRight)

        self.centralWidget.setLayout(layoutMain)
        self.setCentralWidget(self.centralWidget)

        # -- Center in screen --
        self._center_in_screen()

        # -- Add variables storing results --
        #self.results = arraycontainer.Container()

        # -- Connect messenger --
        self.messagebar = messenger.Messenger()
        self.messagebar.timedMessage.connect(self._show_message)
        self.messagebar.collect('Created window')

        # -- Connect signals to messenger
        #TODO: enable saving and uncomment below
        self.saveButton.logMessage.connect(self.messagebar.collect)
示例#3
0
    def __init__(self, parent=None):
        super(Protocol, self).__init__(parent)

        # -- Read settings --
        smhost = rigsettings.STATE_MACHINE_SERVER

        # -- Add widgets --
        centralWidget = QtGui.QWidget()
        self.dispatcher = dispatcher.Dispatcher(host=smhost,
                                                interval=0.3,
                                                connectnow=True,
                                                dummy=True)
        self.saveData = savedata.SaveData()
        self.evplot = eventsplot.EventsPlot(xlim=[0, 4])
        self.manualControl = manualcontrol.ManualControl(self.dispatcher)

        # -- Parameters --
        self.params = paramgui.Container()

        self.params['experimenter'] = paramgui.StringParam(
            'Experimenter',
            value='santiago',
            group='Session info',
            history=False)
        self.params['animal'] = paramgui.StringParam('Animal',
                                                     value='saja000',
                                                     group='Session info',
                                                     history=False)

        self.params['soundDuration'] = paramgui.NumericParam('Sound Duration',
                                                             value=0.1,
                                                             group='Sound')
        self.params['irrelevantParam1'] = paramgui.NumericParam('Irrelevant 1',
                                                                value=0,
                                                                group='Sound')
        self.params['irrelevantParam2'] = paramgui.NumericParam('Irrelevant 2',
                                                                value=0,
                                                                group='Sound')
        self.params['chooseNumber'] = paramgui.MenuParam(
            'MenuParam', ('One', 'Two', 'Three'), group='Sound')
        self.params['anotherNumber'] = paramgui.MenuParam(
            'AnotherParam', ('VerLongOne', 'VerLongTwo', 'VerLongThree'),
            group='Sound')
        for ind in range(6):
            self.params['par%d' % ind] = paramgui.NumericParam(
                'Param%d' % ind, value=1.0 * (ind + 1), group='OtherParams')

        groupSessionInfo = self.params.layoutGroup('Session info')
        groupSound = self.params.layoutGroup('Sound')
        groupOther = self.params.layoutGroup('OtherParams')

        layoutMain = QtGui.QVBoxLayout()
        layoutTop = QtGui.QVBoxLayout()
        layoutBottom = QtGui.QHBoxLayout()
        layoutCol0 = QtGui.QVBoxLayout()
        layoutCol1 = QtGui.QVBoxLayout()
        layoutCol2 = QtGui.QVBoxLayout()

        layoutMain.addLayout(layoutTop)
        layoutMain.addStretch()
        layoutMain.addLayout(layoutBottom)

        layoutTop.addWidget(self.evplot)
        layoutBottom.addLayout(layoutCol0)
        layoutBottom.addLayout(layoutCol1)
        layoutBottom.addLayout(layoutCol2)

        layoutCol0.addWidget(self.saveData)
        layoutCol0.addWidget(groupSessionInfo)
        layoutCol0.addWidget(self.dispatcher)
        layoutCol1.addWidget(self.manualControl)
        layoutCol1.addWidget(groupSound)
        layoutCol2.addWidget(groupOther)

        centralWidget.setLayout(layoutMain)
        self.setCentralWidget(centralWidget)

        # --- Create state matrix ---
        self.sm = statematrix.StateMatrix(readystate=('ready_next_trial', 1))
        self.setStateMatrix()

        # -- Setup events plot --
        #self.evplot.setStatesColor(np.random.rand(6))
        '''
        statesColor = [ [255,0,0],[0,255,0],[0,0,255],\
                        [255,255,0],[255,0,255],[0,255,255] ]  
        self.evplot.setStatesColor(statesColor)
        '''
        statesColorDict = {
            'wait_for_cpoke': [127, 127, 255],
            'play_target': [255, 255, 0],
            'wait_for_apoke': [191, 191, 255],
            'reward': [0, 255, 0],
            'punish': [255, 0, 0],
            'ready_next_trial': [0, 0, 0]
        }
        self.evplot.setStatesColor(statesColorDict, self.sm.getStatesDict())

        # -- Connect signals from dispatcher --
        self.connect(self.dispatcher, QtCore.SIGNAL('PrepareNextTrial'),
                     self.prepareNextTrial)
        self.connect(self.dispatcher, QtCore.SIGNAL('StartNewTrial'),
                     self.startNewTrial)
        self.connect(self.dispatcher, QtCore.SIGNAL('TimerTic'), self.timerTic)

        self.connect(self.saveData.buttonSaveData, QtCore.SIGNAL('clicked()'),
                     self.fileSave)

        # -- Connect messenger --
        self.mymess = messenger.Messenger()
        self.connect(self.mymess.emitter, QtCore.SIGNAL('NewMessage'),
                     self.showMessage)
        self.mymess.send('Created window')
示例#4
0
    def __init__(self, parent=None, paramfile=None, paramdictname=None):
        super(Paradigm2AFC, self).__init__(parent)

        self.name = '2afc'
        smServerType = rigsettings.STATE_MACHINE_TYPE

        # -- Sides plot --
        sidesplot.set_pg_colors(self)
        self.mySidesPlot = sidesplot.SidesPlot(nTrials=120)

        # -- Module for saving data --
        self.saveData = savedata.SaveData(rigsettings.DATA_DIR, remotedir=rigsettings.REMOTE_DIR)

        # -- Create an empty state matrix --
        self.sm = statematrix.StateMatrix(inputs=rigsettings.INPUTS,
                                          outputs=rigsettings.OUTPUTS,
                                          readystate='readyForNextTrial')

        # -- Add parameters --
        self.params = paramgui.Container()
        self.params['trainer'] = paramgui.StringParam('Trainer (initials)',
                                                      value='',
                                                      group='Session info')
        self.params['experimenter'] = paramgui.StringParam('Experimenter',
                                                           value='experimenter',
                                                           group='Session info')
        self.params['subject'] = paramgui.StringParam('Subject',value='subject',
                                                      group='Session info')
        self.sessionInfo = self.params.layout_group('Session info')

        # -- Create dispatcher --
        self.dispatcherModel = dispatcher.Dispatcher(serverType=smServerType,interval=0.1)
        self.dispatcherView = dispatcher.DispatcherGUI(model=self.dispatcherModel)
 
        # -- Connect to sound server and define sounds --
        # FINISH

        # -- Manual control of outputs --
        self.manualControl = manualcontrol.ManualControl(self.dispatcherModel.statemachine)

        # -- Add graphical widgets to main window --
        self.centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QVBoxLayout()
        layoutTop = QtGui.QVBoxLayout()
        layoutBottom = QtGui.QHBoxLayout()
        layoutCol1 = QtGui.QVBoxLayout()
        layoutCol2 = QtGui.QVBoxLayout()

        
        layoutMain.addLayout(layoutTop)
        #layoutMain.addStretch()
        layoutMain.addSpacing(0)
        layoutMain.addLayout(layoutBottom)

        layoutTop.addWidget(self.mySidesPlot)

        layoutBottom.addLayout(layoutCol1)
        layoutBottom.addLayout(layoutCol2)

        layoutCol1.addWidget(self.saveData)
        layoutCol1.addWidget(self.sessionInfo)
        layoutCol1.addWidget(self.dispatcherView)
        
        layoutCol2.addWidget(self.manualControl)
        layoutCol2.addStretch()

        self.centralWidget.setLayout(layoutMain)
        self.setCentralWidget(self.centralWidget)

        # -- Center in screen --
        self._center_in_screen()

        # -- Add variables storing results --
        self.results = arraycontainer.Container()

        # -- Connect signals from dispatcher --
        self.dispatcherModel.prepareNextTrial.connect(self.prepare_next_trial)
        self.dispatcherModel.timerTic.connect(self._timer_tic)

        # -- Connect messenger --
        self.messagebar = messenger.Messenger()
        self.messagebar.timedMessage.connect(self._show_message)
        self.messagebar.collect('Created window')

        # -- Connect signals to messenger
        self.saveData.logMessage.connect(self.messagebar.collect)
        self.dispatcherModel.logMessage.connect(self.messagebar.collect)

        # -- Connect other signals --
        self.saveData.buttonSaveData.clicked.connect(self.save_to_file)
示例#5
0
    def __init__(self, parent=None, paramfile=None, paramdictname=None):
        super(SpeakerCalibration, self).__init__(parent)

        self.name = 'speakercalibration'
        self.soundServer = self.initialize_sound()

        # -- Add graphical widgets to main window --
        self.centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QHBoxLayout()
        layoutRight = QtGui.QVBoxLayout()
               
        self.soundControlL = SoundControl(self.soundServer, channel=0, channelName='left')
        self.soundControlR = SoundControl(self.soundServer, channel=1, channelName='right')

        self.saveButton = SaveButton([self.soundControlL,self.soundControlR])
        soundTypeLabel = QtGui.QLabel('Sound type')
        self.soundTypeMenu = QtGui.QComboBox()
        self.soundTypeList = ['sine','chord']
        self.soundTypeMenu.addItems(self.soundTypeList)
        self.soundTypeMenu.activated.connect(self.change_sound_type)
        soundTargetIntensityLabel = QtGui.QLabel('Target intensity [dB-SPL]')
        self.soundTargetIntensity = QtGui.QLineEdit()
        self.soundTargetIntensity.setText(str(DEFAULT_INTENSITY))
        self.soundTargetIntensity.setEnabled(False)
        computerSoundLevelLabel = QtGui.QLabel('Computer sound level [%]')
        self.computerSoundLevel = QtGui.QLineEdit()
        self.computerSoundLevel.setText(str(rigsettings.SOUND_VOLUME_LEVEL))
        self.computerSoundLevel.setEnabled(False)
        self.loadButton = LoadButton([self.soundControlL,self.soundControlR])
        self.plotButton = PlotButton([self.soundControlL,self.soundControlR])
        

        layoutRight.addWidget(self.saveButton)
        layoutRight.addWidget(soundTypeLabel)
        layoutRight.addWidget(self.soundTypeMenu)
        layoutRight.addWidget(soundTargetIntensityLabel)
        layoutRight.addWidget(self.soundTargetIntensity)
        layoutRight.addWidget(computerSoundLevelLabel)
        layoutRight.addWidget(self.computerSoundLevel)
        layoutRight.addWidget(self.loadButton)
        layoutRight.addWidget(self.plotButton)
        layoutRight.addStretch()

        layoutMain.addWidget(self.soundControlL)
        layoutMain.addWidget(VerticalLine())
        layoutMain.addWidget(self.soundControlR)
        layoutMain.addWidget(VerticalLine())
        layoutMain.addLayout(layoutRight)
        

        self.centralWidget.setLayout(layoutMain)
        self.setCentralWidget(self.centralWidget)

        # -- Center in screen --
        self._center_in_screen()

        # -- Add variables storing results --
        #self.results = arraycontainer.Container()

        # -- Connect messenger --
        self.messagebar = messenger.Messenger()
        self.messagebar.timedMessage.connect(self._show_message)
        self.messagebar.collect('Created window')

        # -- Connect signals to messenger
        self.saveButton.logMessage.connect(self.messagebar.collect)
    def __init__(self,
                 parent=None,
                 paramfile=None,
                 paramdictname=None,
                 dummy=False):
        super(WaterCalibration, self).__init__(parent)

        self.name = '2afc'

        # -- Read settings --
        if dummy:
            smServerType = 'dummy'
        else:
            smServerType = rigsettings.STATE_MACHINE_TYPE

        # -- Module for saving data --
        self.saveData = savedata.SaveData(rigsettings.DATA_DIR)

        # -- Create an empty state matrix --
        self.sm = statematrix.StateMatrix(inputs=rigsettings.INPUTS,
                                          outputs=rigsettings.OUTPUTS,
                                          readystate='readyForNextTrial')

        # -- Add parameters --
        self.params = paramgui.Container()
        '''
        self.params['experimenter'] = paramgui.StringParam('Experimenter',
                                                           value='experimenter',
                                                           group='Session info')
        self.params['subject'] = paramgui.StringParam('Subject',value='subject',
                                                      group='Session info')
        self.sessionInfo = self.params.layout_group('Session info')
        '''

        self.params['timeWaterValveL'] = paramgui.NumericParam(
            'Time valve left', value=0.04, units='s', group='Valves times')
        #self.params['timeWaterValveC'] = paramgui.NumericParam('Time valve center',value=0.04,
        #                                                       units='s',group='Valves times')
        self.params['timeWaterValveR'] = paramgui.NumericParam(
            'Time valve right', value=0.04, units='s', group='Valves times')
        valvesTimes = self.params.layout_group('Valves times')

        self.params['waterVolumeL'] = paramgui.NumericParam(
            'Water volume left', value=0, units='ml', group='Water volume')
        #self.params['waterVolumeC'] = paramgui.NumericParam('Water volume center',value=0,
        #                                                       units='ml',group='Water volume')
        self.params['waterVolumeR'] = paramgui.NumericParam(
            'Water volume right', value=0, units='ml', group='Water volume')
        waterVolume = self.params.layout_group('Water volume')

        self.params['offTime'] = paramgui.NumericParam('Time between',
                                                       value=0.5,
                                                       units='s',
                                                       group='Schedule')
        self.params['nDeliveries'] = paramgui.NumericParam('N deliveries',
                                                           value=2,
                                                           units='',
                                                           group='Schedule')
        self.params['nDelivered'] = paramgui.NumericParam('N delivered',
                                                          value=0,
                                                          units='',
                                                          group='Schedule')
        self.params['nDelivered'].set_enabled(False)
        schedule = self.params.layout_group('Schedule')

        # -- Create dispatcher --
        self.dispatcherModel = dispatcher.Dispatcher(serverType=smServerType,
                                                     interval=0.1)
        self.dispatcherView = dispatcher.DispatcherGUI(
            model=self.dispatcherModel)

        # -- Manual control of outputs --
        self.manualControl = manualcontrol.ManualControl(
            self.dispatcherModel.statemachine)

        # -- Add graphical widgets to main window --
        self.centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QHBoxLayout()
        layoutCol1 = QtGui.QVBoxLayout()
        layoutCol2 = QtGui.QVBoxLayout()
        layoutCol3 = QtGui.QVBoxLayout()

        layoutCol1.addWidget(self.saveData)
        #layoutCol1.addWidget(self.sessionInfo)
        layoutCol1.addWidget(self.dispatcherView)

        layoutCol2.addWidget(valvesTimes)
        layoutCol2.addStretch()
        layoutCol2.addWidget(self.manualControl)

        layoutCol3.addWidget(waterVolume)
        layoutCol3.addStretch()
        layoutCol3.addWidget(schedule)

        layoutMain.addLayout(layoutCol1)
        layoutMain.addLayout(layoutCol2)
        layoutMain.addLayout(layoutCol3)

        self.centralWidget.setLayout(layoutMain)
        self.setCentralWidget(self.centralWidget)

        # -- Add variables storing results --
        self.results = arraycontainer.Container()

        # -- Connect signals from dispatcher --
        self.dispatcherModel.prepareNextTrial.connect(self.prepare_next_trial)
        self.dispatcherModel.timerTic.connect(self._timer_tic)

        # -- Connect messenger --
        self.messagebar = messenger.Messenger()
        self.messagebar.timedMessage.connect(self._show_message)
        self.messagebar.collect('Created window')

        # -- Connect signals to messenger
        self.saveData.logMessage.connect(self.messagebar.collect)
        self.dispatcherModel.logMessage.connect(self.messagebar.collect)

        # -- Connect other signals --
        self.saveData.buttonSaveData.clicked.connect(self.save_to_file)

        # -- Center in screen --
        paramgui.center_in_screen(self)