Ejemplo n.º 1
0
    def proceedure(self):
        '''The proceedure of the experiment'''
        self.count = 0
        for frames, condition in self.handler:
            data = {}
            data['trial'] = self.count + 1
            data['intensity'] = frames
            data['requestedLatency'] = frames * SPF
            # set up windows according to this handler
            primeWindow = condition['prime']
            mainWindow = condition['stim']
            if mainWindow is not None:
                extraWindow = condition['extra']
            else:
                i = list(range(len(self.windows)))
                i.pop(condition['extra'])
                mainWindow = random.choice(i)
                extraWindow = condition['extra']
            data['nearToFar'] = primeWindow < mainWindow
            data['diopters'] = abs(primeWindow - mainWindow)
            # set up stimuli with some randomness
            prime = self.primeStim[
                primeWindow]  # choose the right prime text stimulus
            primeIter = random.choice(self.config.primePresentations)
            data['primeDepth'] = self.config.monitors[
                primeWindow].currentCalib['distance']
            direction = random.randint(0, 3)
            main = self.mainStim[mainWindow][direction]
            post = self.postStim[mainWindow]
            data['direction'] = direction
            data['size'] = main.height
            data['stimDepth'] = self.config.monitors[mainWindow].currentCalib[
                'distance']
            extra = self.odStim[extraWindow][direction]
            data['extraDepth'] = self.config.monitors[
                extraWindow].currentCalib['distance']
            driveFrames = condition['driveFrames']
            # run the proceedure
            #print(direction, self.responses[direction])
            itr = 0
            resp1 = False
            primeValue = True
            while itr < primeIter or resp1 != primeValue:
                text, primeValue = self.genLogicPrimer(
                )  # set the text and store the value for the primer
                prime.text = text
                self.present(prime)
                self.stimuliTime[0] = self.clock.getTime()
                self.waitTime(.5)
                resp1 = self.waitForResponse(self.joy.getAllButtons, [0, 1],
                                             true=[[True, False]],
                                             false=[[False, True]])
                itr += 1
            self.clear(prime)
            data['primeIter'] = itr
            data['primeTime'] = self.clock.getTime() - self.stimuliTime[0]
            if driveFrames > 0:
                if self.concurrent:
                    self.present(main, False)
                self.present(extra)
                self.stimuliTime[2] = self.clock.getTime()
                self.waitTime(driveFrames * SPF)
                self.clear(extra)
                data['extraLatency'] = self.clock.getTime(
                ) - self.stimuliTime[2]
            else:
                data['extraLatency'] = 0
            self.present(main)
            self.stimuliTime[1] = self.clock.getTime()
            self.waitTime(frames * SPF)
            self.present(post)
            self.clear(main)
            data['mainLatency'] = self.clock.getTime() - self.stimuliTime[1]
            data['driveFrames'] = driveFrames
            data['totalLatency'] = data['extraLatency'] + data['mainLatency']
            self.stimuliTime[0] = self.clock.getTime()
            resp2 = None
            while resp2 is None:
                resp2 = self.waitForResponse(
                    self.joy.getAllHats, [0],
                    true=[self.responses[direction]],
                    false=[
                        i for i in self.responses
                        if i != self.responses[direction]
                    ])
            self.clear(post)
            data['responseTime'] = self.clock.getTime() - self.stimuliTime[0]
            self.clearStimuli()
            # record the results
            data['primeCorrect'] = resp1 == primeValue
            data['correct'] = resp2
            # extra results
            data.update({
                'caseLabel':
                condition['label'],
                'stepCorrect':
                sum(self.handler.currentStaircase.
                    data[self.handler.currentStaircase.stepChangeidx:]) +
                data['correct'],
                'w':
                self.handler.currentStaircase.pest_w,
                'direction':
                self.handler.currentStaircase.currentDirection,
                'stepsize':
                self.handler.currentStaircase.stepSizes[
                    self.handler.currentStaircase.currentStepSizeIdx],
            })
            data['caseTrial'] = len(self.handler.currentStaircase.data) + 1
            data['trialsAtStep'] = data[
                'caseTrial'] - self.handler.currentStaircase.stepChangeidx
            data['expected'] = data[
                'trialsAtStep'] * self.handler.currentStaircase.targetProb
            data['stepChange'] = int(
                self.handler.currentStaircase.currentLevelTrialCount /
                self.handler.currentStaircase.findlay_m)
            if data['primeCorrect']:  # prime was correct - this one counted
                self.handler.addResponse(data['correct'])
                for k, v in data.items():
                    self.handler.addOtherData(k, v)
                # add an inital rule for vPest
                if data['correct'] and len(
                        self.handler.currentStaircase.reversalIntensities
                ) == 0 and self.handler.currentStaircase.currentDirection in [
                        'down', 'start'
                ]:
                    self.handler.currentStaircase.stimuliLevelTrialCounts.append(
                        self.handler.currentStaircase.currentLevelTrialCount)
                    self.handler.currentStaircase._intensityDec()
                    self.handler.currentStaircase.stepChangeidx = len(
                        self.handler.currentStaircase.data)
            else:
                self.handler.currentStaircase.intensities.pop()
            if self.storeData:
                self.dataFile.write(
                    '%s\n' % ','.join(['%s' % data[i] for i in self.dataKeys]))
            # TODO print update on number of trials completed - out of how many? Does the handler know that? probably not
            self.count += 1
            print('Trial # %s:\tFrames = %s\tExpr = %s' %
                  (self.count, frames, condition['label']))
            logging.flush()

            # Do some checking to make sure we aren't only running random Experiments or not running any?
            #if set(self.handler.runningStaircases).issubset(self.dummies):
            if all(i in self.dummies for i in self.handler.runningStaircases):
                print('All running staircases are dummies. Ending run.')
                for stair in self.dummies:
                    stair.finished = True
            #if not set(self.handler.runningStaircases).intersection(self.dummies):
            if not [
                    i for i in self.handler.runningStaircases
                    if i in self.dummies
            ]:
                print(
                    'No running staircases are dummies. Restarting all dummies.'
                )
                for stair in self.dummies:
                    stair.finished = False
                    stair.reversalIntensities = []
                    stair.intensities = []
                    stair.currentStepSizeIdx = 0
                    stair.currentDirectionStepCount = 0
                    stair.correctCounter = 0
                    #stair._nextIntensity = stair.startVal
                    self.handler.runningStaircases.append(stair)
Ejemplo n.º 2
0
 def proceedure(self):
     '''The proceedure of the experiment'''
     '''
     ref = visual.GratingStim(win=self.windows[3], size=1, pos=[0,2], sf=20, contrast=0, autoLog=True)
     ref.setAutoDraw(True)
     refText = visual.TextStim(win=self.windows[3],height=.15,pos=[0,-2],autoLog=True)
     refText.fontFiles = [os.path.join(self.config.assetsPath,self.config.stimulusFont)]
     refText.font = os.path.splitext(self.config.stimulusFont)[0]
     refText.text = 'Default'
     refText.setAutoDraw(True)
     for a in range(4):
         for idx, win in enumerate(self.windows):
             for stim in self.stimuli:
                 stim.win = self.windows[idx]
                 #stim.wrapWidth = None
                 #print(stim.wrapWidth)
                 stim._needVertexUpdate = True
                 stim._needUpdate = True
             for idx, stim in enumerate(self.stimuli):
                 self.presentStimulus(idx)
                 self.waitTime(60*SPF)
                 self.clearStimuli()
     '''
     self.count = 0
     for frames, condition in self.handler:
         data = {}
         data['trial'] = self.count + 1
         data['intensity'] = frames
         data['requestedLatency'] = frames * SPF
         # set up windows according to this handler
         i = list(range(len(self.windows)))
         mainWindow = random.choice(i[condition['diopters']:])
         primeWindow = mainWindow - condition['diopters']
         if not condition['nearToFar']:
             primeWindow = mainWindow
             mainWindow = primeWindow - condition['diopters']
         data['nearToFar'] = condition['nearToFar']
         data['diopters'] = condition['diopters']
         # set up stimuli with some randomness
         prime = self.primeStim[
             primeWindow]  # choose the right prime text stimulus
         primeIter = random.choice(self.config.primePresentations)
         data['primeDepth'] = self.config.monitors[
             primeWindow].currentCalib['distance']
         direction = random.randint(0, 3)
         main = self.mainStim[mainWindow][direction]
         post = self.postStim[mainWindow]
         data['direction'] = direction
         data['size'] = main.height
         data['stimDepth'] = self.config.monitors[mainWindow].currentCalib[
             'distance']
         # run the proceedure
         itr = 0
         resp1 = False
         primeValue = True
         while itr < primeIter or resp1 != primeValue:
             text, primeValue = self.genLogicPrimer(
             )  # set the text and store the value for the primer
             prime.text = text
             self.present(prime)
             self.stimuliTime[0] = self.clock.getTime()
             self.waitTime(.5)
             resp1 = self.waitForResponse(self.joy.getAllButtons, [0, 1],
                                          true=[[True, False]],
                                          false=[[False, True]])
             itr += 1
         self.clear(prime)
         data['primeIter'] = itr
         data['primeTime'] = self.clock.getTime() - self.stimuliTime[0]
         self.present(main)
         self.stimuliTime[1] = self.clock.getTime()
         self.waitTime(frames * SPF)
         self.present(post)
         self.clear(main)
         data['actualLatency'] = self.clock.getTime() - self.stimuliTime[1]
         data['totalLatency'] = data['actualLatency']
         self.stimuliTime[2] = self.clock.getTime()
         resp2 = None
         while resp2 is None:
             resp2 = self.waitForResponse(
                 self.joy.getAllHats, [0],
                 true=[self.responses[direction]],
                 false=[
                     i for i in self.responses
                     if i != self.responses[direction]
                 ])
         self.clear(post)
         data['responseTime'] = self.clock.getTime() - self.stimuliTime[2]
         self.clearStimuli()
         # record the results
         data['primeCorrect'] = resp1 == primeValue
         data['correct'] = resp2
         # extra results
         data.update({
             'caseLabel':
             condition['label'],
             'stepCorrect':
             sum(self.handler.currentStaircase.
                 data[self.handler.currentStaircase.stepChangeidx:]) +
             data['correct'],
             'w':
             self.handler.currentStaircase.pest_w,
             'direction':
             self.handler.currentStaircase.currentDirection,
             'stepsize':
             self.handler.currentStaircase.stepSizes[
                 self.handler.currentStaircase.currentStepSizeIdx],
         })
         data['caseTrial'] = len(self.handler.currentStaircase.data) + 1
         data['trialsAtStep'] = data[
             'caseTrial'] - self.handler.currentStaircase.stepChangeidx
         data['expected'] = data[
             'trialsAtStep'] * self.handler.currentStaircase.targetProb
         data['stepChange'] = int(
             self.handler.currentStaircase.currentLevelTrialCount /
             self.handler.currentStaircase.findlay_m)
         initialRule = False
         if data['primeCorrect']:  # prime was correct - this one counted
             self.handler.addResponse(data['correct'])
             for k, v in data.items():
                 self.handler.addOtherData(k, v)
             # add an inital rule for vPest
             if data['correct'] and len(
                     self.handler.currentStaircase.reversalIntensities
             ) == 0 and self.handler.currentStaircase.currentDirection in [
                     'down', 'start'
             ]:
                 self.handler.currentStaircase.stimuliLevelTrialCounts.append(
                     self.handler.currentStaircase.currentLevelTrialCount)
                 self.handler.currentStaircase._intensityDec()
                 self.handler.currentStaircase.stepChangeidx = len(
                     self.handler.currentStaircase.data)
                 initialRule = True
         else:
             self.handler.currentStaircase.intensities.pop()
         if self.storeData:
             self.dataFile.write(
                 '%s\n' % ','.join(['%s' % data[i] for i in self.dataKeys]))
         # TODO print update on number of trials completed - out of how many? Does the handler know that? probably not
         self.count += 1
         print(
             'Trial # %s:\tFrames = %s\tExpr = %s\tInitial Rule = %s\tReversals: %s'
             % (self.count, frames, condition['label'], initialRule,
                len(self.handler.currentStaircase.reversalIntensities)))
         logging.flush()
Ejemplo n.º 3
0
    def proceedure(self):
        '''The proceedure of the experiment'''
        self.count = 0
        for frames, condition in self.handler:
            data = {}
            data['trial'] = self.count + 1
            data['intensity'] = frames
            data['requestedLatency'] = frames * SPF
            # set up windows according to this handler
            primeWindow = condition['prime']
            mainWindow = condition['stim']
            if mainWindow is not None:
                extraWindow = condition['extra']
            else:
                i = list(range(len(self.windows)))
                i.pop(condition['extra'])
                mainWindow = random.choice(i)
                extraWindow = condition['extra']
            data['nearToFar'] = primeWindow < mainWindow
            data['diopters'] = abs(primeWindow - mainWindow)
            # set up stimuli with some randomness
            self.stimuli[0] = self.primeStim[
                primeWindow]  # choose the right prime text stimulus
            text, primeValue = self.genLogicPrimer(
            )  # set the text and store the value for the primer
            self.stimuli[0].text = text
            data['primeDepth'] = self.config.monitors[
                primeWindow].currentCalib['distance']
            orientation = random.getrandbits(
                1)  # set and store the orientation of the grating
            self.stimuli[1].ori = orientation * 90
            self.stimuli[3].ori = orientation * 90
            data['orientation'] = self.stimuli[1].ori
            data['contrast'] = self.stimuli[1].contrast
            data['frequency'] = self.stimuli[1].sf
            for stim in self.stimuli[1:3]:
                stim.win = self.windows[
                    mainWindow]  # set the grating and post grating stimulus window
                stim._needVertexUpdate = True  # make sure it recalculates the size
                stim._needUpdate = True  # make sure it redraws the size
            data['stimDepth'] = self.config.monitors[mainWindow].currentCalib[
                'distance']
            self.stimuli[3].win = self.windows[extraWindow]
            self.stimuli[3]._needVertexUpdate = True
            self.stimuli[3]._needUpdate = True
            data['extraDepth'] = self.config.monitors[
                extraWindow].currentCalib['distance']
            driveFrames = condition['driveFrames']
            # run the proceedure
            self.presentStimulus(0)
            resp1 = self.waitForResponse(self.joy.getAllButtons, [0, 1],
                                         true=[[True, False]],
                                         false=[[False, True]])
            self.clearStimuli()
            data['primeTime'] = self.stimuliTime[0]
            if driveFrames > 0:
                self.presentStimulus(3)
                self.waitTime(driveFrames * SPF)
                self.clearStimuli()
            self.presentStimulus(1)
            self.waitTime(frames * SPF)
            self.clearStimuli()
            data['driveFrames'] = driveFrames
            data['actualDriveTime'] = self.stimuliTime[3]
            data['actualLatency'] = self.stimuliTime[1]
            self.presentStimulus(2)
            resp2 = self.waitForResponse(self.joy.getAllHats, [0],
                                         true=[[1, 0], [-1, 0]],
                                         false=[[0, 1], [0, -1]])
            self.clearStimuli()
            data['responseTime'] = self.stimuliTime[2]
            # record the results
            data['primeCorrect'] = resp1 == primeValue
            data['correct'] = resp2 == orientation
            # extra results
            data.update({
                'caseLabel':
                condition['label'],
                'stepCorrect':
                sum(self.handler.currentStaircase.
                    data[self.handler.currentStaircase.stepChangeidx:]) +
                data['correct'],
                'w':
                self.handler.currentStaircase.pest_w,
                'direction':
                self.handler.currentStaircase.currentDirection,
                'stepsize':
                self.handler.currentStaircase.stepSizes[
                    self.handler.currentStaircase.currentStepSizeIdx],
            })
            data['caseTrial'] = len(self.handler.currentStaircase.data) + 1
            data['trialsAtStep'] = data[
                'caseTrial'] - self.handler.currentStaircase.stepChangeidx
            data['expected'] = data[
                'trialsAtStep'] * self.handler.currentStaircase.targetProb
            data['stepChange'] = int(
                self.handler.currentStaircase.currentLevelTrialCount /
                self.handler.currentStaircase.findlay_m)
            if data['primeCorrect']:  # prime was correct - this one counted
                self.handler.addResponse(data['correct'])
                for k, v in data.items():
                    self.handler.addOtherData(k, v)
                # add an inital rule for vPest
                #if data['correct'] and len(self.handler.currentStaircase.reversalIntensities) == 0 and self.handler.currentStaircase.currentDirection in ['down', 'start']:
                #    self.handler.currentStaircase.stimuliLevelTrialCounts.append(self.handler.currentStaircase.currentLevelTrialCount)
                #    self.handler.currentStaircase._intensityDec()
                #    self.handler.currentStaircase.stepChangeidx = len(self.handler.currentStaircase.data)
                #    #self.handler.currentStaircase.calculateNextIntensity()
            else:
                self.handler.currentStaircase.intensities.pop()
            if self.storeData:
                self.dataFile.write(
                    '%s\n' % ','.join(['%s' % data[i] for i in self.dataKeys]))
            # TODO print update on number of trials completed - out of how many? Does the handler know that? probably not
            self.count += 1
            print('Trial # %s:\tFrames = %s\tExpr = %s' %
                  (self.count, frames, condition['label']))
            logging.flush()

            # Do some checking to make sure we aren't only running random Experiments or not running any?
            #if set(self.handler.runningStaircases).issubset(self.dummies):
            if all(i in self.dummies for i in self.handler.runningStaircases):
                print('All running staircases are dummies. Ending run.')
                for stair in self.dummies:
                    stair.finished = True
            #if not set(self.handler.runningStaircases).intersection(self.dummies):
            if not [
                    i for i in self.handler.runningStaircases
                    if i in self.dummies
            ]:
                print(
                    'No running staircases are dummies. Restarting all dummies.'
                )
                for stair in self.dummies:
                    stair.finished = False
                    stair.reversalIntensities = []
                    stair.intensities = []
                    stair.currentStepSizeIdx = 0
                    stair.currentDirectionStepCount = 0
                    stair.correctCounter = 0
                    #stair._nextIntensity = stair.startVal
                    self.handler.runningStaircases.append(stair)