Ejemplo n.º 1
0
    def __init__(self,parent=None, paramfile=None, paramdictname=None):
        super(Paradigm, self).__init__(parent)

         # -- Add parameters --
        self.params['targetDuration'] = paramgui.NumericParam('Target Duration',value=1,
                                                        units='s',group='Timing Parameters')
        timingParams = self.params.layout_group('Timing Parameters')
        
        self.params['targetFrequency'] = paramgui.NumericParam('Target freq',value=2000,decimals=0,
                                                        units='Hz',enabled=True,group='Sound Parameters')
        self.params['targetIntensity'] = paramgui.NumericParam('Intensity',value=50.0,units='dB-SPL',
                                                        enabled=True,group='Sound Parameters')
        soundParams = self.params.layout_group('Sound Parameters')

        # -- 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)

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

        layoutCol1.addWidget(self.saveData)
        layoutCol1.addWidget(self.sessionInfo)
        layoutCol1.addWidget(self.dispatcherView)
        
        layoutCol2.addWidget(timingParams)
        layoutCol2.addWidget(soundParams)
        layoutCol2.addStretch()


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

        '''# -- Add variables for storing results --
        maxNtrials = 4000 # Preallocating space for each vector makes things easier
        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,
                                          'free':3,'nochoice':4,'aftererror':5,'aborted':6}
        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)'''

        # -- Load parameters from a file --
        self.params.from_file(paramfile,paramdictname)
        
        # -- Create sound client --
        self.soundClient = soundclient.SoundClient()
        self.soundClient.start()
Ejemplo n.º 2
0
    def __init__(self, parent=None, paramfile=None, paramdictname=None):

        '''
        Set up the taskontrol core modules, add parameters to the GUI, and
        initialize the sound server.
        '''

        super(Paradigm, self).__init__(parent)

        self.name = 'am_tuning_curve'

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

        # -- Create the speaker calibration object
        self.spkCal = speakercalibration.Calibration(rigsettings.SPEAKER_CALIBRATION_SINE)
        self.noiseCal = speakercalibration.NoiseCalibration(rigsettings.SPEAKER_CALIBRATION_NOISE)

        # -- 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 parameters --
        self.params = paramgui.Container()
        self.params['experimenter'] = paramgui.StringParam('Experimenter',
                                                            value='santiago',
                                                            group='Parameters')
        self.params['subject'] = paramgui.StringParam('Subject',value='test030',
                                                       group='Parameters')
        self.params['minFreq'] = paramgui.NumericParam('Min Frequency (Hz)',
                                                        value=2000,
                                                        group='Parameters')
        self.params['maxFreq'] = paramgui.NumericParam('Max Frequency (Hz)',
                                                        value=40000,
                                                        group='Parameters')
        self.params['numTones'] = paramgui.NumericParam('Number of Frequencies',
                                                         value=16,
                                                         group='Parameters')
        self.params['minInt'] = paramgui.NumericParam('Min Intensity (dB SPL)',
                                                       value=60,
                                                       group='Parameters')
        self.params['maxInt'] = paramgui.NumericParam('Max Intensity (dB SPL)',
                                                       value=60,
                                                       group='Parameters')
        self.params['numInt'] = paramgui.NumericParam('Number of Intensities',
                                                       value=1,
                                                       group='Parameters')
        self.params['stimDur'] = paramgui.NumericParam('Stimulus Duration (s)',
                                                        value=0.01,
                                                        group='Parameters')
        '''
        self.params['isiMin'] = paramgui.NumericParam('Minimum Interstimulus Interval (s)',
                                                       value=1,
                                                       group='Parameters')
        self.params['isiMax'] = paramgui.NumericParam('Maximum Interstimulus Interval',
                                                      value=3,
                                                      group='Parameters')
        '''
        self.params['isiMean'] = paramgui.NumericParam('Interstimulus interval mean (s)',
                                                       value=2,
                                                       group='Parameters')
        self.params['isiHalfRange'] = paramgui.NumericParam('+/-',
                                                      value=1,
                                                      group='Parameters')
        # self.params['noiseAmp'] = paramgui.NumericParam('Amplitude in Noise-Mode',
        #                                                value=0.3,
        #                                                group='Parameters')
        self.params['randomMode'] = paramgui.MenuParam('Presentation Mode',
                                                         ['Ordered','Random'],
                                                         value=1,group='Parameters')
        self.params['stimType'] = paramgui.MenuParam('Stim Type',
                                                         ['Sine','Chord', 'Noise', 'AM', 'Laser', 'LaserTrain', 'Light', 'SineLaser'],
                                                         value=2,group='Parameters')
        self.params['currentFreq'] = paramgui.NumericParam('Current Frequency (Hz)',
                                                            value=0, units='Hz',
                                                            enabled=False,
                                                            group='Parameters')

        self.params['currentIntensity'] = paramgui.NumericParam('Target Intensity',
                                                                 value=0,
                                                                 enabled=False,
                                                                 group='Parameters')
        self.params['currentAmpL'] = paramgui.NumericParam('Current Amplitude - L',value=0,
                                                           enabled=False,
                                                           group='Parameters',
                                                           decimals=4)
        self.params['currentAmpR'] = paramgui.NumericParam('Current Amplitude - R',value=0,
                                                           enabled=False,
                                                           group='Parameters',
                                                           decimals=4)


        self.params['laserOn'] = paramgui.NumericParam('Laser On', value=0, enabled=False,
                                                            group='Parameters')
        self.params['laserProbability'] = paramgui.NumericParam('Laser Probability (s)', value=0,
                                                            group='Parameters')
        self.params['laserDuration'] = paramgui.NumericParam('Laser Duration (s)', value=0,
                                                            group='Parameters')
        self.params['laserOnset'] = paramgui.NumericParam('Laser Onset (s)', value=0,
                                                            group='Parameters')




        timingParams = self.params.layout_group('Parameters')

        # -- Load parameters from a file --
        self.params.from_file(paramfile,paramdictname)


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

        # -- Module for savng the data --

        self.saveData = savedata.SaveData(rigsettings.DATA_DIR,
                                          remotedir=rigsettings.REMOTE_DIR)
        self.saveData.checkInteractive.setChecked(True)

        # -- Add graphical widgets to main window --
        self.centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QHBoxLayout() #Create a main layout and two columns
        layoutCol1 = QtGui.QVBoxLayout()
        layoutCol2 = QtGui.QVBoxLayout()


        layoutMain.addLayout(layoutCol1) #Add the columns to the main layout
        layoutMain.addLayout(layoutCol2)

        layoutCol1.addWidget(self.dispatcherView) #Add the dispatcher to col1
        layoutCol1.addWidget(self.saveData)
        layoutCol1.addWidget(self.manualControl)

        self.clearButton = QtGui.QPushButton('Clear Stim List', self)
        self.clearButton.clicked.connect(self.clear_tone_list)
        layoutCol1.addWidget(self.clearButton)


        layoutCol2.addWidget(timingParams)  #Add the parameter GUI to column 2

        self.centralWidget.setLayout(layoutMain) #Assign the layouts to the main window
        self.setCentralWidget(self.centralWidget)

        # -- Connect signals from dispatcher --

        #prepare_next_trial is sent whenever the dispatcher reaches the end of
        #the current trial.
        self.dispatcherModel.prepareNextTrial.connect(self.prepare_next_trial)

        # -- Connect the save data button --
        self.saveData.buttonSaveData.clicked.connect(self.save_to_file)

        print "Connecting to sound server"
        print '***** FIXME: HARDCODED TIME DELAY TO WAIT FOR SERIAL PORT! *****'
        time.sleep(0.2)
        self.soundClient = soundclient.SoundClient()
        self.soundClient.start()
        #soundFreq = self.params['soundFreq'].get_value()

        # -- Initialize the list of trial parameters --
        self.trialParams = []
        self.soundParamList = []
    def __init__(self, parent=None, paramfile=None, paramdictname=None):
        super(Paradigm, self).__init__(parent)

        # -- Performance dynamics plot --
        performancedynamicsplot.set_pg_colors(self)
        self.myPerformancePlot = performancedynamicsplot.PerformanceDynamicsPlot(
            nTrials=400, winsize=10)

        # -- Add parameters --
        self.params['timeWaterValveL'] = paramgui.NumericParam(
            'Time valve left', value=0.03, units='s', group='Water delivery')
        self.params['timeWaterValveC'] = paramgui.NumericParam(
            'Time valve center', value=0.03, units='s', group='Water delivery')
        self.params['timeWaterValveR'] = paramgui.NumericParam(
            'Time valve right', value=0.03, units='s', group='Water delivery')
        waterDelivery = self.params.layout_group('Water delivery')

        self.params['outcomeMode'] = paramgui.MenuParam(
            'Outcome mode', [
                'sides_direct', 'direct', 'on_next_correct', 'only_if_correct',
                'simulated'
            ],
            value=3,
            group='Choice parameters')
        self.params['antibiasMode'] = paramgui.MenuParam(
            'Anti-bias mode', ['off', 'repeat_mistake'],
            value=0,
            group='Choice parameters')
        choiceParams = self.params.layout_group('Choice parameters')

        self.params['delayToTargetMean'] = paramgui.NumericParam(
            'Mean delay to target',
            value=0.3,
            units='s',
            group='Timing parameters')
        self.params['delayToTargetHalfRange'] = paramgui.NumericParam(
            '+/-', value=0.05, units='s', group='Timing parameters')
        self.params['delayToTarget'] = paramgui.NumericParam(
            'Delay to target',
            value=0.3,
            units='s',
            group='Timing parameters',
            enabled=False,
            decimals=3)
        self.params['targetDuration'] = paramgui.NumericParam(
            'Target duration', value=0.1, units='s', group='Timing parameters')
        self.params['rewardAvailability'] = paramgui.NumericParam(
            'Reward availability',
            value=4,
            units='s',
            group='Timing parameters')
        self.params['punishTimeError'] = paramgui.NumericParam(
            'Punishment (error)',
            value=0,
            units='s',
            group='Timing parameters')
        self.params['punishTimeEarly'] = paramgui.NumericParam(
            'Punishment (early)',
            value=0,
            units='s',
            group='Timing parameters')
        timingParams = self.params.layout_group('Timing parameters')

        self.params['trialsPerBlock'] = paramgui.NumericParam(
            'Trials per block',
            value=300,
            units='trials (0=no-switch)',
            group='Switching parameters')
        self.params['currentBlock'] = paramgui.MenuParam(
            'Current block', ['mid_boundary', 'low_boundary', 'high_boundary'],
            value=0,
            group='Switching parameters')
        switchingParams = self.params.layout_group('Switching parameters')

        self.params['psycurveMode'] = paramgui.MenuParam(
            'PsyCurve Mode', ['off', 'uniform'],
            value=0,
            group='Psychometric parameters')
        self.params['psycurveNfreq'] = paramgui.NumericParam(
            'N frequencies',
            value=8,
            decimals=0,
            group='Psychometric parameters')
        psychometricParams = self.params.layout_group(
            'Psychometric parameters')

        self.params['automationMode'] = paramgui.MenuParam(
            'Automation Mode', ['off', 'increase_delay'],
            value=0,
            group='Automation')
        automationParams = self.params.layout_group('Automation')

        # 5000, 7000, 9800 (until 2014-03-19)
        self.params['highFreq'] = paramgui.NumericParam(
            'High freq', value=16000, units='Hz', group='Sound parameters')
        self.params['midFreq'] = paramgui.NumericParam(
            'Middle freq', value=7000, units='Hz', group='Sound parameters')
        self.params['lowFreq'] = paramgui.NumericParam(
            'Low freq', value=3000, units='Hz', group='Sound parameters')
        self.params['targetFrequency'] = paramgui.NumericParam(
            'Target freq',
            value=0,
            decimals=0,
            units='Hz',
            enabled=False,
            group='Sound parameters')
        self.params['targetIntensityMode'] = paramgui.MenuParam(
            'Intensity mode', ['fixed', 'randMinus20'],
            value=1,
            group='Sound parameters')
        self.params['targetMaxIntensity'] = paramgui.NumericParam(
            'Max intensity',
            value=60,
            units='dB-SPL',
            group='Sound parameters')
        self.params['targetIntensity'] = paramgui.NumericParam(
            'Intensity',
            value=0.0,
            units='dB-SPL',
            enabled=False,
            group='Sound parameters')
        '''
        self.params['targetAmplitudeHigh'] = paramgui.NumericParam('AmplitudeHigh',value=0.0,units='[0-1]',
                                                        enabled=False,decimals=4,group='Sound parameters')
        self.params['targetAmplitudeMid'] = paramgui.NumericParam('AmplitudeMid',value=0.0,units='[0-1]',
                                                        enabled=False,decimals=4,group='Sound parameters')
        self.params['targetAmplitudeLow'] = paramgui.NumericParam('AmplitudeLow',value=0.0,units='[0-1]',
                                                        enabled=False,decimals=4,group='Sound parameters')
        '''
        self.params['targetAmplitude'] = paramgui.NumericParam(
            'Target amplitude',
            value=0.0,
            units='[0-1]',
            enabled=False,
            decimals=4,
            group='Sound parameters')
        self.params['punishSoundAmplitude'] = paramgui.NumericParam(
            'Punish amplitude',
            value=0.01,
            units='[0-1]',
            enabled=False,
            group='Sound parameters')
        '''
        self.params['highFreq'] = paramgui.NumericParam('High freq',value=500,
                                                        units='Hz',group='Sound parameters')
        self.params['midFreq'] = paramgui.NumericParam('Middle freq',value=440,
                                                        units='Hz',group='Sound parameters')
        self.params['lowFreq'] = paramgui.NumericParam('Low freq',value=400,
                                                        units='Hz',group='Sound parameters')
        #4200, 9200, 20200
        '''
        soundParams = self.params.layout_group('Sound parameters')

        self.params['nValid'] = paramgui.NumericParam('N valid',
                                                      value=0,
                                                      units='',
                                                      enabled=False,
                                                      group='Report')
        self.params['nRewarded'] = paramgui.NumericParam('N rewarded',
                                                         value=0,
                                                         units='',
                                                         enabled=False,
                                                         group='Report')
        reportParams = self.params.layout_group('Report')

        #
        self.params['experimenter'].set_value('santiago')
        self.params['subject'].set_value('test')

        # -- 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()
        layoutCol3 = QtGui.QVBoxLayout()
        layoutCol4 = QtGui.QVBoxLayout()

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

        layoutTop.addWidget(self.mySidesPlot)
        layoutTop.addWidget(self.myPerformancePlot)

        layoutBottom.addLayout(layoutCol1)
        layoutBottom.addLayout(layoutCol2)
        layoutBottom.addLayout(layoutCol3)
        layoutBottom.addLayout(layoutCol4)

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

        layoutCol2.addWidget(self.manualControl)
        layoutCol2.addStretch()
        layoutCol2.addWidget(waterDelivery)
        layoutCol2.addStretch()
        layoutCol2.addWidget(choiceParams)
        layoutCol2.addStretch()

        layoutCol3.addWidget(timingParams)
        layoutCol3.addStretch()
        layoutCol3.addWidget(switchingParams)
        layoutCol3.addStretch()
        layoutCol3.addWidget(psychometricParams)
        layoutCol3.addStretch()

        layoutCol4.addWidget(automationParams)
        layoutCol3.addStretch()
        layoutCol4.addWidget(soundParams)
        layoutCol3.addStretch()
        layoutCol4.addWidget(reportParams)
        layoutCol4.addStretch()

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

        # -- Add variables for storing results --
        maxNtrials = 4000  # Preallocating space for each vector makes things easier
        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,
            'free': 3,
            'nochoice': 4,
            'aftererror': 5,
            'aborted': 6
        }
        self.results['outcome'] = np.empty(maxNtrials, dtype=int)
        # Saving as bool creates an 'enum' vector, so I'm saving as 'int'
        self.results['valid'] = np.zeros(maxNtrials,
                                         dtype='int8')  # redundant but useful
        self.results['timeTrialStart'] = np.empty(maxNtrials, dtype=float)
        self.results['timeTarget'] = 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)

        # -- Define first block --
        import datetime
        if (datetime.datetime.now().day % 2):
            self.params['currentBlock'].set_string('low_boundary')
        else:
            self.params['currentBlock'].set_string('high_boundary')

        # -- Load parameters from a file --
        self.params.from_file(paramfile, paramdictname)

        # -- Connect to sound server and define sounds --
        print 'Conecting to soundserver...'
        print '***** XFIXME: HARDCODED TIME DELAY TO WAIT FOR SERIAL PORT! *****'  ### DEBUG
        time.sleep(0.2)
        self.soundClient = soundclient.SoundClient()
        '''
        highFreq = self.params['highFreq'].get_value()
        lowFreq = self.params['lowFreq'].get_value()
        stimDur = self.params['targetDuration'].get_value()
        s1 = {'type':'tone', 'frequency':lowFreq, 'duration':stimDur, 'amplitude':0.01}
        s2 = {'type':'tone', 'frequency':highFreq, 'duration':stimDur, 'amplitude':0.01}
        self.soundClient.set_sound(1,s1)
        self.soundClient.set_sound(2,s2)
        '''

        punishSoundAmplitude = self.params['punishSoundAmplitude'].get_value()
        sNoise = {
            'type': 'noise',
            'duration': 0.5,
            'amplitude': punishSoundAmplitude
        }
        self.punishSoundID = 127
        self.soundClient.set_sound(self.punishSoundID, sNoise)
        self.soundClient.start()
Ejemplo n.º 4
0
    def __init__(self, parent=None, paramfile=None, paramdictname=None):
        '''
        Set up the taskontrol core modules, add parameters to the GUI, and
        initialize the sound server.
        '''

        super(Paradigm, self).__init__(parent)

        self.name = 'bandwidth_am'

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

        # -- Create the speaker calibration objects
        self.noiseCal = speakercalibration.NoiseCalibration(
            rigsettings.SPEAKER_CALIBRATION_NOISE)
        self.toneCal = speakercalibration.Calibration(
            rigsettings.SPEAKER_CALIBRATION_SINE)

        # -- 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 parameters --
        self.params = paramgui.Container()
        self.params['experimenter'] = paramgui.StringParam('Experimenter',
                                                           value='santiago',
                                                           group='Session')
        self.params['subject'] = paramgui.StringParam('Subject',
                                                      value='test030',
                                                      group='Session')

        self.params['charFreq'] = paramgui.NumericParam(
            'Characteristic Frequency (Hz)', value=8000, group='Session')
        self.params['modRate'] = paramgui.NumericParam('Modulation rate',
                                                       value=2.0,
                                                       group='Session')
        sessionParams = self.params.layout_group('Session')

        self.params['minAmp'] = paramgui.NumericParam(
            'Min noise amplitude (dB)', value=40, group='Sound Parameters')
        self.params['maxAmp'] = paramgui.NumericParam(
            'Max noise amplitude (dB)', value=60, group='Sound Parameters')
        self.params['numAmps'] = paramgui.NumericParam(
            'Number of Amplitudes', value=2, group='Sound Parameters')
        self.params['minBand'] = paramgui.NumericParam(
            'Minimum bandwidth (octaves)',
            value=0.25,
            group='Sound Parameters')
        self.params['maxBand'] = paramgui.NumericParam(
            'Maximum bandwidth (octaves)', value=2.0, group='Sound Parameters')
        self.params['numBands'] = paramgui.NumericParam(
            'Number of bandwidths', value=4, group='Sound Parameters')
        # -- Added extremes as separate option in case we want to add other stim types (unmodulated white noise) --
        self.params['whiteNoise'] = paramgui.MenuParam(
            'Add white noise to bandwidths?', ['yes', 'no'],
            value=0,
            group='Sound Parameters')
        self.params['pureTone'] = paramgui.MenuParam(
            'Add pure tone to bandwidths?', ['yes', 'no'],
            value=1,
            group='Sound Parameters')
        self.params['soundType'] = paramgui.MenuParam(
            'Sound type', ['full_spectrum', 'harmonics', 'both'],
            value=0,
            group='Sound Parameters')
        self.params['stimDur'] = paramgui.NumericParam(
            'Stimulus Duration (s)', value=1.0, group='Sound Parameters')
        self.params['isiMean'] = paramgui.NumericParam(
            'Interstimulus interval mean (s)',
            value=2,
            group='Sound Parameters')
        self.params['isiHalfRange'] = paramgui.NumericParam(
            '+/-', value=1, group='Sound Parameters')
        self.params['randomMode'] = paramgui.MenuParam(
            'Presentation Mode', ['Ordered', 'Random'],
            value=1,
            group='Sound Parameters')
        soundParams = self.params.layout_group('Sound Parameters')

        self.params['signalType'] = paramgui.MenuParam(
            'Include pure tone signal?', ['yes', 'no'],
            value=1,
            group='Signal Parameters')
        self.params['minSNR'] = paramgui.NumericParam(
            'Minimum signal to noise',
            value=10,
            decimals=0,
            units='dB',
            group='Signal Parameters')
        self.params['maxSNR'] = paramgui.NumericParam(
            'Maximum signal to noise',
            value=20,
            decimals=0,
            units='dB',
            group='Signal Parameters')
        self.params['numSNRs'] = paramgui.NumericParam(
            'Number of SNRs',
            value=3,
            decimals=0,
            units='dB',
            group='Signal Parameters')
        signalParams = self.params.layout_group('Signal Parameters')

        self.params['laserPercent'] = paramgui.MenuParam(
            'Percentage of trials with laser', ['0%', '50%', '100%'],
            value=1,
            group='Laser Parameters')
        self.params['laserType'] = paramgui.MenuParam('Laser colour',
                                                      ['blue', 'green'],
                                                      value=1,
                                                      group='Laser Parameters')
        self.params['laserFrontOverhang'] = paramgui.NumericParam(
            'Laser Front Overhang',
            value=0,
            group='Laser Parameters',
            decimals=1)
        self.params['laserBackOverhang'] = paramgui.NumericParam(
            'Laser Back Overhang',
            value=0,
            group='Laser Parameters',
            decimals=1)
        laserParams = self.params.layout_group('Laser Parameters')

        self.params['currentAmp'] = paramgui.NumericParam(
            'Current Amplitude',
            value=0,
            enabled=False,
            group='Current Trial',
            decimals=1)
        self.params['currentBand'] = paramgui.NumericParam(
            'Current Bandwidth',
            value=0,
            enabled=False,
            group='Current Trial',
            decimals=2)
        self.params['currentSNR'] = paramgui.NumericParam(
            'Current SNR',
            value=0.0,
            decimals=1,
            units='dB',
            enabled=False,
            group='Current Trial')
        self.params['laserTrial'] = paramgui.NumericParam(
            'Laser Trial?',
            value=0,
            enabled=False,
            group='Current Trial',
            decimals=0)
        self.params['harmTrialType'] = paramgui.NumericParam(
            'Harmonics Trial?',
            value=0,
            enabled=False,
            group='Current Trial',
            decimals=0)
        trialParams = self.params.layout_group('Current Trial')

        # -- Load parameters from a file --
        self.params.from_file(paramfile, paramdictname)

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

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

        # -- Add graphical widgets to main window --
        self.centralWidget = QtGui.QWidget()
        layoutMain = QtGui.QHBoxLayout()  #Create a main layout and two columns
        layoutCol1 = QtGui.QVBoxLayout()
        layoutCol2 = QtGui.QVBoxLayout()

        layoutMain.addLayout(layoutCol1)  #Add the columns to the main layout
        layoutMain.addLayout(layoutCol2)

        layoutCol1.addWidget(self.dispatcherView)  #Add the dispatcher to col1
        layoutCol1.addWidget(self.saveData)
        layoutCol1.addWidget(self.manualControl)
        layoutCol1.addWidget(trialParams)

        self.clearButton = QtGui.QPushButton('Clear Stim List', self)
        self.clearButton.clicked.connect(self.clear_tone_list)
        layoutCol1.addWidget(self.clearButton)

        layoutCol2.addWidget(sessionParams)  #Add the parameter GUI to column 2
        layoutCol2.addWidget(soundParams)
        layoutCol2.addWidget(signalParams)
        layoutCol2.addWidget(laserParams)

        self.centralWidget.setLayout(
            layoutMain)  #Assign the layouts to the main window
        self.setCentralWidget(self.centralWidget)

        # -- Connect signals from dispatcher --

        #prepare_next_trial is sent whenever the dispatcher reaches the end of
        #the current trial.
        self.dispatcherModel.prepareNextTrial.connect(self.prepare_next_trial)

        # -- Connect the save data button --
        self.saveData.buttonSaveData.clicked.connect(self.save_to_file)

        print "Connecting to sound server"
        print '***** FIXME: HARDCODED TIME DELAY TO WAIT FOR SERIAL PORT! *****'
        time.sleep(0.2)
        self.soundClient = soundclient.SoundClient()
        self.soundClient.start()
        #soundFreq = self.params['soundFreq'].get_value()

        # -- Initialize the list of trial parameters --
        self.trialParams = []
        self.soundParamList = []
Ejemplo n.º 5
0
    def __init__(self, parent=None, paramfile=None, paramdictname=None):
        super(Paradigm, self).__init__(parent)

        # -- Performance dynamics plot --
        performancedynamicsplot.set_pg_colors(self)
        self.myPerformancePlot = performancedynamicsplot.PerformanceDynamicsPlot(
            nTrials=400, winsize=10)

        # -- Add parameters --
        self.params['timeWaterValveL'] = paramgui.NumericParam(
            'Time valve left',
            value=0.03,
            enabled=False,
            units='s',
            group='Water delivery')
        self.params['baseWaterValveL'] = paramgui.NumericParam(
            'Base time left', value=0.03, units='s', group='Water delivery')
        self.params['factorWaterValveL'] = paramgui.NumericParam(
            'Factor left', value=1, units='s', group='Water delivery')
        self.params['timeWaterValveR'] = paramgui.NumericParam(
            'Time valve right',
            value=0.03,
            enabled=False,
            units='s',
            group='Water delivery')
        self.params['baseWaterValveR'] = paramgui.NumericParam(
            'Base time right', value=0.03, units='s', group='Water delivery')
        self.params['factorWaterValveR'] = paramgui.NumericParam(
            'Factor right', value=1, units='s', group='Water delivery')
        waterDelivery = self.params.layout_group('Water delivery')

        self.params['outcomeMode'] = paramgui.MenuParam(
            'Outcome mode', [
                'sides_direct', 'direct', 'on_next_correct', 'only_if_correct',
                'simulated'
            ],
            value=3,
            group='Choice parameters')
        self.params['antibiasMode'] = paramgui.MenuParam(
            'Anti-bias mode', ['off', 'repeat_mistake'],
            value=0,
            group='Choice parameters')
        choiceParams = self.params.layout_group('Choice parameters')

        self.params['delayToTargetMean'] = paramgui.NumericParam(
            'Mean delay to target',
            value=0.04,
            units='s',
            group='Timing parameters')
        self.params['delayToTargetHalfRange'] = paramgui.NumericParam(
            '+/-', value=0.0, units='s', group='Timing parameters')
        self.params['delayToTarget'] = paramgui.NumericParam(
            'Delay to target',
            value=0.3,
            units='s',
            group='Timing parameters',
            enabled=False,
            decimals=3)
        self.params['targetDuration'] = paramgui.NumericParam(
            'Target duration', value=0.5, units='s', group='Timing parameters')
        self.params['rewardAvailability'] = paramgui.NumericParam(
            'Reward availability',
            value=4,
            units='s',
            group='Timing parameters')
        self.params['punishTimeError'] = paramgui.NumericParam(
            'Punishment (error)',
            value=0,
            units='s',
            group='Timing parameters')
        self.params['punishTimeEarly'] = paramgui.NumericParam(
            'Punishment (early)',
            value=0,
            units='s',
            group='Timing parameters')
        timingParams = self.params.layout_group('Timing parameters')

        self.params['automationMode'] = paramgui.MenuParam('Automation Mode', [
            'off', 'increase_delay', 'same_left_right', 'same_right_left',
            'left_right_left'
        ],
                                                           value=0,
                                                           group='Automation')
        automationParams = self.params.layout_group('Automation')

        self.params['threshMode'] = paramgui.MenuParam(
            'Threshold Mode', ['max_only', 'linear', 'exponential'],
            value=0,
            group='Threshold detection parameters')
        # -- tone intensity refers to difference between tone and masking noise --
        self.params['minSNR'] = paramgui.NumericParam(
            'Minimum signal to noise',
            value=2,
            decimals=1,
            units='dB',
            group='Threshold detection parameters')
        self.params['maxSNR'] = paramgui.NumericParam(
            'Maximum signal to noise',
            value=20,
            decimals=0,
            units='dB',
            group='Threshold detection parameters')
        self.params['numSNRs'] = paramgui.NumericParam(
            'Number of SNRs',
            value=2,
            decimals=0,
            units='dB',
            group='Threshold detection parameters')
        threshParams = self.params.layout_group(
            'Threshold detection parameters')

        self.params['bandMode'] = paramgui.MenuParam(
            'Bandwidth Mode', ['white_only', 'max_only', 'uniform'],
            value=0,
            group='Bandwidth parameters')
        self.params['minBand'] = paramgui.NumericParam(
            'Minimum bandwidth',
            value=0.25,
            decimals=2,
            units='octaves',
            group='Bandwidth parameters')
        self.params['maxBand'] = paramgui.NumericParam(
            'Maximum bandwidth',
            value=4.0,
            decimals=2,
            units='octaves',
            group='Bandwidth parameters')
        self.params['numBands'] = paramgui.NumericParam(
            'Number of bandwidths',
            value=5,
            decimals=0,
            group='Bandwidth parameters')
        self.params['includeWhite'] = paramgui.MenuParam(
            'Include white noise?', ['yes', 'no'],
            value=0,
            group='Bandwidth parameters')
        bandParams = self.params.layout_group('Bandwidth parameters')

        self.params['noiseMode'] = paramgui.MenuParam(
            'Masker amplitude mode', ['max_only', 'uniform'],
            value=1,
            group='Masker amplitude parameters')
        # -- power refers to average power of noise stimulus
        self.params['minNoiseAmp'] = paramgui.NumericParam(
            'Minimum noise power',
            value=30,
            decimals=0,
            units='dB',
            group='Masker amplitude parameters')
        self.params['maxNoiseAmp'] = paramgui.NumericParam(
            'Maximum noise power',
            value=40,
            decimals=0,
            units='dB',
            group='Masker amplitude parameters')
        self.params['numAmps'] = paramgui.NumericParam(
            'Number of noise amplitudes',
            value=2,
            decimals=0,
            group='Masker amplitude parameters')
        noiseParams = self.params.layout_group('Masker amplitude parameters')

        self.params['toneFreq'] = paramgui.NumericParam(
            'Tone frequency', value=8000, units='Hz', group='Sound parameters')
        self.params['modRate'] = paramgui.NumericParam(
            'Modulation Rate', value=8, units='Hz', group='Sound parameters')
        self.params['punishSoundAmplitude'] = paramgui.NumericParam(
            'Punish amplitude',
            value=0.01,
            units='[0-1]',
            enabled=True,
            group='Sound parameters')
        soundParams = self.params.layout_group('Sound parameters')

        self.params['currentBand'] = paramgui.NumericParam(
            'Trial bandwidth',
            value=0.0,
            decimals=2,
            units='octaves',
            enabled=False,
            group='Current Trial')
        self.params['currentNoiseAmp'] = paramgui.NumericParam(
            'Trial noise power',
            value=0.0,
            decimals=0,
            units='dB',
            enabled=False,
            group='Current Trial')
        self.params['currentSNR'] = paramgui.NumericParam(
            'Trial SNR',
            value=0.0,
            decimals=1,
            units='dB',
            enabled=False,
            group='Current Trial')
        trialParams = self.params.layout_group('Current Trial')

        self.params['nValid'] = paramgui.NumericParam('N valid',
                                                      value=0,
                                                      units='',
                                                      enabled=False,
                                                      group='Report')
        self.params['nRewarded'] = paramgui.NumericParam('N rewarded',
                                                         value=0,
                                                         units='',
                                                         enabled=False,
                                                         group='Report')
        reportParams = self.params.layout_group('Report')

        #
        self.params['experimenter'].set_value('santiago')
        self.params['subject'].set_value('test')

        # -- 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()
        layoutCol3 = QtGui.QVBoxLayout()
        layoutCol4 = QtGui.QVBoxLayout()

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

        layoutTop.addWidget(self.mySidesPlot)
        layoutTop.addWidget(self.myPerformancePlot)

        layoutBottom.addLayout(layoutCol1)
        layoutBottom.addLayout(layoutCol2)
        layoutBottom.addLayout(layoutCol3)
        layoutBottom.addLayout(layoutCol4)

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

        layoutCol2.addWidget(self.manualControl)
        layoutCol2.addStretch()
        layoutCol2.addWidget(waterDelivery)
        layoutCol2.addStretch()
        layoutCol2.addWidget(choiceParams)
        layoutCol2.addStretch()

        layoutCol3.addWidget(timingParams)
        layoutCol3.addStretch()
        layoutCol3.addWidget(automationParams)
        layoutCol3.addStretch()
        layoutCol3.addWidget(trialParams)
        layoutCol3.addStretch()
        layoutCol3.addWidget(reportParams)
        layoutCol3.addStretch()

        layoutCol4.addWidget(soundParams)
        layoutCol4.addStretch()
        layoutCol4.addWidget(threshParams)
        layoutCol4.addStretch()
        layoutCol4.addWidget(bandParams)
        layoutCol4.addStretch()
        layoutCol4.addWidget(noiseParams)
        layoutCol4.addStretch()

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

        # -- Add variables for storing results --
        maxNtrials = 4000  # Preallocating space for each vector makes things easier
        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,
            'free': 3,
            'nochoice': 4,
            'aftererror': 5,
            'aborted': 6
        }
        self.results['outcome'] = np.empty(maxNtrials, dtype=int)
        # Saving as bool creates an 'enum' vector, so I'm saving as 'int'
        self.results['valid'] = np.zeros(maxNtrials,
                                         dtype='int8')  # redundant but useful
        self.results['timeTrialStart'] = np.empty(maxNtrials, dtype=float)
        self.results['timeTarget'] = 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)

        # -- Load parameters from a file --
        self.params.from_file(paramfile, paramdictname)

        # -- Connect to sound server and define sounds --
        print 'Conecting to soundserver...'
        print '***** FIXME: HARDCODED TIME DELAY TO WAIT FOR SERIAL PORT! *****'  ### DEBUG
        time.sleep(0.2)
        self.soundClient = soundclient.SoundClient()
        self.punishSoundID = 127
        self.soundClient.start()