def startExperiment(): try: expInfo, trialInfo, outputfile, monitorInfo = setupExperiment() win = open_window(monitorInfo) show_instructions(win, "Press spacebar to start experiment") # We instanciate 4 staircases, we must decide the starting values for each of them # The speed value is the speedValue in the for loop of staircases and is measured in [cm/s] # The staircase will terminate when nTrials AND nReversals have been exceeded. # If stepSizes was an array and has been exceeded before nTrials is # exceeded then the staircase will continue to reverse if (monitorInfo['RunSpeedTest']): from common.draw_test_square import draw_test_square draw_test_square(win) nTrialCounter = {} responses = {} if expInfo['Block'] == 'Unilateral': nTrialCounter['Unilateral-Left'] = 0 nTrialCounter['Unilateral-Right'] = 0 responses['Unilateral-Left'] = [] responses['Unilateral-Right'] = [] if expInfo['Block'] == 'Bilateral': nTrialCounter['Bilateral-Left'] = 0 nTrialCounter['Bilateral-Right'] = 0 responses['Bilateral-Left'] = [] responses['Bilateral-Right'] = [] if expInfo['Block'] == 'Uni+Bi': nTrialCounter['Unilateral-Left'] = 0 nTrialCounter['Unilateral-Right'] = 0 nTrialCounter['Bilateral-Left'] = 0 nTrialCounter['Bilateral-Right'] = 0 responses['Unilateral-Left'] = [] responses['Unilateral-Right'] = [] responses['Bilateral-Left'] = [] responses['Bilateral-Right'] = [] maxTrials = trialInfo['TotalTrialsPerCondition'] * 2 if (expInfo['Block'] == 'Uni+Bi'): maxTrials *= 2 output = open(outputfile + "_fixed_tracking.txt", 'w') output.write('Trial\tNTrial\tTrial Condition\tResponse\tStartTime\n') # Generate a list of balanced random conditions allConditions = [] for n in range(0, maxTrials): condition = {} if n % 2: condition['Side'] = 'Left' else: condition['Side'] = 'Right' if expInfo['Block'] == 'Unilateral': condition['label'] = 'Unilateral' + '-' + condition['Side'] if expInfo['Block'] == 'Bilateral': condition['label'] = 'Bilateral' + '-' + condition['Side'] if expInfo['Block'] == 'Uni+Bi': if n % 4 == 0: condition['label'] = 'Unilateral' + '-Right' if n % 4 == 1: condition['label'] = 'Unilateral' + '-Left' if n % 4 == 2: condition['label'] = 'Bilateral' + '-Right' if n % 4 == 3: condition['label'] = 'Bilateral' + '-Left' allConditions.append(condition) # Prepare some trials with catch trials import copy for i in range(0, len(allConditions)): thisCondition = allConditions[i] if np.random.rand() < 0.5 and (thisCondition['label'].split('-')[0] == 'Bilateral'): thisCondition = copy.deepcopy(allConditions[i]) thisCondition['isCatchTrial'] = True allConditions.append(thisCondition) if (trialInfo['Selection'] == 'random'): from random import shuffle shuffle(allConditions) for thisCondition in allConditions: print thisCondition n = 0 expClock = core.Clock() trigger_received = False # Indicates whether it received the '=' symbol from the fMRI (or from the keyboard) while not trigger_received: win.flip() triggerKeys = event.getKeys(keyList=['equal']) if len(triggerKeys) > 0: #'=' in triggerKeys: ## trigger_received = True expClock.reset() if 'escape' in triggerKeys: win.close() core.quit() event.clearEvents(eventType='keyboard') for thisCondition in allConditions: t0 = expClock.getTime() if expInfo['Block'] == 'Unilateral': if nTrialCounter[ 'Unilateral-Left'] > maxTrials and nTrialCounter[ 'Unilateral-Right'] > maxTrials: break if expInfo['Block'] == 'Bilateral': if nTrialCounter[ 'Bilateral-Left'] > maxTrials and nTrialCounter[ 'Bilateral-Right'] > maxTrials: break if expInfo['Block'] == 'Uni+Bi': if nTrialCounter[ 'Bilateral-Left'] > maxTrials and nTrialCounter[ 'Bilateral-Right'] > maxTrials: break # Extract the speed value from the input dialog for staircase for the # current condition speedValue = trialInfo[thisCondition['label'] + ' speed'] if 'isCatchTrial' in thisCondition: # print "Catch trial, sarebbe ", thisCondition['Side'], "invece # fa dall'altra" if thisCondition['Side'] == 'Left': thisCondition['Side'] = 'Right' else: thisCondition['Side'] = 'Left' trackingTrial(win, expInfo, speedValue, thisCondition, expInfo['SimulationMode']) else: # print thisCondition, speedValue thisResp = trackingTrial(win, expInfo, speedValue, thisCondition, expInfo['SimulationMode']) responses[thisCondition['label']].append(thisResp) output.write( str(n) + "\t" + str(nTrialCounter[thisCondition['label']]) + "\t" + thisCondition['label'] + "\t" + str(int(thisResp)) + "\t" + str(t0) + "\n") nTrialCounter[thisCondition['label']] += 1 n += 1 experiment_finished(win) except: raise win.close() else: output.write('\n') # Compute accuracy, we keep just the trials from 0 to maxTrials accuracies = {} for k in responses.keys(): accuracies[k] = float(sum(responses[k][0:maxTrials])) / len( responses[k][0:maxTrials]) output.write('Accuracy ' + k + ' = ' + str(accuracies[k]) + "\n")
def startExperiment(): try: expInfo, stairInfo, outputfile, monitorInfo = setupExperiment() win = open_window(monitorInfo) show_instructions(win, "Press spacebar to start experiment, doing " + str(expInfo['TrainingTrials']) + " training trials") # We instanciate 4 staircases, we must decide the starting values for each of them # The speed value is the speedValue in the for loop of staircases and is measured in [cm/s] # The staircase will terminate when nTrials AND nReversals have been exceeded. # If stepSizes was an array and has been exceeded before nTrials is # exceeded then the staircase will continue to reverse # Convert the string of steps to a list of floats to feed to every # staircase stepSizes = [float(x) for x in stairInfo['StepSizes'].replace('[', '').replace(']', '').split(',')] # Convert the initial velocities of the staircases SpeedBiRight = [float(x) for x in stairInfo['SpeedBiRight'].replace('[', '').replace(']', '').split(',')] SpeedBiLeft = [float(x) for x in stairInfo['SpeedBiLeft'].replace('[', '').replace(']', '').split(',')] SpeedUniRight = [float(x) for x in stairInfo['SpeedUniRight'].replace('[', '').replace(']', '').split(',')] SpeedUniLeft = [float(x) for x in stairInfo['SpeedUniLeft'].replace('[', '').replace(']', '').split(',')] conditionsBilateral = [ {'label': 'Bilateral-Right_0', 'Side': 'Right', 'startVal': SpeedBiRight[0], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpBiRight'], 'nDown':stairInfo['nDownBiRight'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 }, {'label': 'Bilateral-Left_0', 'Side': 'Left', 'startVal': SpeedBiLeft[0], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpBiLeft'], 'nDown':stairInfo['nDownBiLeft'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 }, {'label': 'Bilateral-Right_1', 'Side': 'Right', 'startVal': SpeedBiRight[1], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpBiRight'], 'nDown':stairInfo['nDownBiRight'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 }, {'label': 'Bilateral-Left_1', 'Side': 'Left', 'startVal': SpeedBiLeft[1], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpBiLeft'], 'nDown':stairInfo['nDownBiLeft'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 } ] ########## CONDITIONS UNILATERAL ########## conditionsUnilateral = [ {'label': 'Unilateral-Right_0', 'Side': 'Right', 'startVal': SpeedUniRight[0], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpUniRight'], 'nDown':stairInfo['nDownUniRight'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 }, {'label': 'Unilateral-Left_0', 'Side': 'Left', 'startVal': SpeedUniLeft[0], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpUniLeft'], 'nDown':stairInfo['nDownUniLeft'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 }, {'label': 'Unilateral-Right_1', 'Side': 'Right', 'startVal': SpeedUniRight[1], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpUniRight'], 'nDown':stairInfo['nDownUniRight'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 }, {'label': 'Unilateral-Left_1', 'Side': 'Left', 'startVal': SpeedUniLeft[1], 'method':'2AFC', 'stepType':stairInfo['StepType'], 'stepSizes':stepSizes, 'nUp':stairInfo['nUpUniLeft'], 'nDown':stairInfo['nDownUniLeft'], 'nTrials':stairInfo['MinTrials'], 'nReversals':stairInfo['MinReversals'], 'minVal':0 } ] conditions = None if expInfo['Block'] == 'Unilateral': conditions = conditionsUnilateral if expInfo['Block'] == 'Bilateral': conditions = conditionsBilateral if expInfo['Block'] == 'Uni+Bi': conditions = conditionsUnilateral + conditionsBilateral from psychopy import data stairs = data.MultiStairHandler( conditions=conditions, nTrials=2, method=stairInfo['Selection']) if (monitorInfo['RunSpeedTest']): from common.draw_test_square import draw_test_square draw_test_square(win) # Do some training trials with no variation in speed for i in range(0, int(expInfo['TrainingTrials'])): speedValue = 1.25 * (i + 1) trackingTrial(win, expInfo, speedValue, conditions[randrange(0, 2)]) show_instructions( win, "Finished training trials, press spacebar to begin") velocityConditions = {} velocityConditions['Left'] = [] velocityConditions['Right'] = [] # Start of the trial loop # We save the last speed used for every side of stimulus presentation nTrial = 0 import copy # Has to initialize the first trial speedValue, thisCondition = stairs.next() nCatchTrials = 0 nValidTrials = 0 dfrows = [] # Collects all trials included catch trials print thisCondition while True: # Using while True is the correct way to insert catch trials velocityConditions[thisCondition['Side']].append(speedValue) # print thisCondition['Side'], speedValue # Catch trial presentato al 25% di probabilita if np.random.rand() < 0.25 and nTrial > 2: nCatchTrials += 1 catchCondition = copy.deepcopy(thisCondition) if thisCondition['Side'] == 'Left': catchCondition['Side'] = 'Left' catchSpeedValue = velocityConditions['Right'][-1] else: catchCondition['Side'] = 'Right' catchSpeedValue = velocityConditions['Left'][-1] catchResp = trackingTrial(win, expInfo, catchSpeedValue, catchCondition, simulation=expInfo['SimulationMode'], isCatchTrial=0) #doesn't print message dfrows.append({'label':catchCondition['label'], 'Side':catchCondition['Side'], 'CatchCondition':1, 'Speed':speedValue, 'Response':int(not catchResp)}) else: thisResp = trackingTrial(win, expInfo, speedValue, thisCondition, simulation=expInfo['SimulationMode'],isCatchTrial=0) dfrows.append({'label':thisCondition['label'], 'Side':thisCondition['Side'], 'CatchCondition':0, 'Speed':speedValue, 'Response':int(not thisResp)}) if thisResp is not None: stairs.addResponse(int(not thisResp)) nValidTrials += 1 try: speedValue, thisCondition = stairs.next() except StopIteration: break else: raise # Increase the trial counter and save the temporary results nTrial = nTrial + 1 stairs.saveAsText(outputfile) stairs.saveAsPickle(outputfile) df = pd.DataFrame(dfrows) # this holds all trials in raw mode stairs.saveAsExcel(outputfile) experiment_finished(win) df.to_excel(outputfile+'_trials_summary.xlsx') except: # If the experiments stops before a default response is inserted stairs.addResponse(0) stairs.saveAsExcel(outputfile) df.to_excel(outputfile+'_trials_summary.xlsx') win.close() raise
def startExperiment(): try: expInfo, stairInfo, outputfile, monitorInfo = setupExperiment() win = open_window(monitorInfo) show_instructions( win, "Press spacebar to start experiment, doing " + str(expInfo['TrainingTrials']) + " training trials") # We instanciate 4 staircases, we must decide the starting values for each of them # The speed value is the speedValue in the for loop of staircases and is measured in [cm/s] # The staircase will terminate when nTrials AND nReversals have been exceeded. # If stepSizes was an array and has been exceeded before nTrials is # exceeded then the staircase will continue to reverse # Convert the string of steps to a list of floats to feed to every # staircase stepSizes = [ float(x) for x in stairInfo['StepSizes'].replace('[', '').replace( ']', '').split(',') ] # Convert the initial velocities of the staircases SpeedBiRight = [ float(x) for x in stairInfo['SpeedBiRight'].replace('[', '').replace( ']', '').split(',') ] SpeedBiLeft = [ float(x) for x in stairInfo['SpeedBiLeft'].replace('[', '').replace( ']', '').split(',') ] SpeedUniRight = [ float(x) for x in stairInfo['SpeedUniRight'].replace('[', '').replace( ']', '').split(',') ] SpeedUniLeft = [ float(x) for x in stairInfo['SpeedUniLeft'].replace('[', '').replace( ']', '').split(',') ] conditionsBilateral = [{ 'label': 'Bilateral-Right_0', 'Side': 'Right', 'startVal': SpeedBiRight[0], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpBiRight'], 'nDown': stairInfo['nDownBiRight'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }, { 'label': 'Bilateral-Left_0', 'Side': 'Left', 'startVal': SpeedBiLeft[0], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpBiLeft'], 'nDown': stairInfo['nDownBiLeft'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }, { 'label': 'Bilateral-Right_1', 'Side': 'Right', 'startVal': SpeedBiRight[1], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpBiRight'], 'nDown': stairInfo['nDownBiRight'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }, { 'label': 'Bilateral-Left_1', 'Side': 'Left', 'startVal': SpeedBiLeft[1], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpBiLeft'], 'nDown': stairInfo['nDownBiLeft'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }] ########## CONDITIONS UNILATERAL ########## conditionsUnilateral = [{ 'label': 'Unilateral-Right_0', 'Side': 'Right', 'startVal': SpeedUniRight[0], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpUniRight'], 'nDown': stairInfo['nDownUniRight'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }, { 'label': 'Unilateral-Left_0', 'Side': 'Left', 'startVal': SpeedUniLeft[0], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpUniLeft'], 'nDown': stairInfo['nDownUniLeft'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }, { 'label': 'Unilateral-Right_1', 'Side': 'Right', 'startVal': SpeedUniRight[1], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpUniRight'], 'nDown': stairInfo['nDownUniRight'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }, { 'label': 'Unilateral-Left_1', 'Side': 'Left', 'startVal': SpeedUniLeft[1], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpUniLeft'], 'nDown': stairInfo['nDownUniLeft'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': 0 }] conditions = None if expInfo['Block'] == 'Unilateral': conditions = conditionsUnilateral if expInfo['Block'] == 'Bilateral': conditions = conditionsBilateral if expInfo['Block'] == 'Uni+Bi': conditions = conditionsUnilateral + conditionsBilateral from psychopy import data stairs = data.MultiStairHandler(conditions=conditions, nTrials=2, method=stairInfo['Selection']) if (monitorInfo['RunSpeedTest']): from common.draw_test_square import draw_test_square draw_test_square(win) # Do some training trials with no variation in speed for i in range(0, int(expInfo['TrainingTrials'])): speedValue = 1.25 * (i + 1) trackingTrial(win, expInfo, speedValue, conditions[randrange(0, 2)]) show_instructions(win, "Finished training trials, press spacebar to begin") velocityConditions = {} velocityConditions['Left'] = [] velocityConditions['Right'] = [] # Start of the trial loop # We save the last speed used for every side of stimulus presentation nTrial = 0 import copy for speedValue, thisCondition in stairs: velocityConditions[thisCondition['Side']].append(speedValue) # print thisCondition['Side'], speedValue # Catch trial presentato al 25% di probabilita if np.random.rand() < 0.25 and nTrial > 2: catchCondition = copy.deepcopy(thisCondition) if thisCondition['Side'] == 'Left': catchCondition['Side'] = 'Left' # print "Using speed value", velocityConditions['Right'][-1], " instead of ", speedValue # get the last speed used element speedValue = velocityConditions['Right'][-1] else: catchCondition['Side'] = 'Right' # print "Using speed value", velocityConditions['Left'][-1], " instead of ", speedValue # get the last speed used element speedValue = velocityConditions['Left'][-1] # print "0.25 catch trial, showing ", catchCondition['Side'], " # instead of ", thisCondition['Side'] trackingTrial(win, expInfo, speedValue, catchCondition, expInfo['SimulationMode']) # Catch trial lanciato quando una delle due staircase finita # e che randomizza il lato di presentazione elif np.random.rand() < 0.5: catchCondition = copy.deepcopy(thisCondition) if thisCondition['Side'] == 'Left': catchCondition['Side'] = 'Right' else: catchCondition['Side'] = 'Left' # print "0.5 catch trial, showing ", catchCondition['Side'], " # instead of ", thisCondition['Side'] trackingTrial(win, expInfo, speedValue, catchCondition, expInfo['SimulationMode']) else: thisResp = trackingTrial(win, expInfo, speedValue, thisCondition, expInfo['SimulationMode']) if thisResp is not None: # print speedValue, thisCondition, nTrial stairs.addData(not thisResp) else: raise nTrial = nTrial + 1 stairs.saveAsText(outputfile) # Finally save the results of the experiment stairs.saveAsText(outputfile) # stairs.saveAsExcel(outputfile) stairs.saveAsPickle(outputfile) experiment_finished(win) except: stairs.saveAsText(outputfile) # stairs.saveAsExcel(outputfile) stairs.saveAsPickle(outputfile) win.close() raise
def startExperiment(): try: expInfo, stairInfo, outputfile, monitorInfo = setupExperiment() win = open_window(monitorInfo, measureFPS=False) win.measuredFPS = 59.95 show_instructions( win, "Press spacebar to start experiment, doing " + str(expInfo['TrainingTrials']) + " training trials") # Convert the string of steps to a list of floats to feed to every # staircase stepSizes = [ float(x) for x in stairInfo['StepSizes'].replace('[', '').replace( ']', '').split(',') ] expConditions = [{ 'label': 'Right', 'startVal': stairInfo['ContrastRight'], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpRight'], 'nDown': stairInfo['nDownRight'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': min(stepSizes), 'maxVal': 1 }, { 'label': 'Left', 'startVal': stairInfo['ContrastLeft'], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpLeft'], 'nDown': stairInfo['nDownLeft'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': min(stepSizes), 'maxVal': 1 }] print "Minimum value for staircase = ", min(stepSizes) from psychopy import data stairs = data.MultiStairHandler(conditions=expConditions, nTrials=1, method=stairInfo['Selection']) if (monitorInfo['RunSpeedTest']): from common.draw_test_square import draw_test_square draw_test_square(win) # Do some training trials with no variation in speed for i in np.linspace(0.0, 2.0, expInfo['TrainingTrials']): contrastTrial(win, expInfo, contrastValue=i, side='Left', useSameStimuli=randrange(0, 2)) show_instructions(win, "Finished training trials, press spacebar to begin") for contrast, thisCondition in stairs: sameStimuli = randrange(0, 100) < 25 # To present 4 equal stimuli thisResp = contrastTrial(win, expInfo, contrastValue=contrast, side=thisCondition['label'], useSameStimuli=sameStimuli) if thisResp is not None: stairs.addData(not thisResp) else: print "skipped" # save data as multiple formats for every trial stairs.saveAsText(outputfile) stairs.saveAsText(outputfile) stairs.saveAsPickle(outputfile) stairs.saveAsExcel(outputfile) experiment_finished(win) except: win.close() raise
def startExperiment(): """ Begin the experiment 1. Set experimental parameters 2. Open the window and take measurements of the refresh rate 3. Start some training trials if needed 4. Start the interleaved staircase experiment 5. Save the result """ try: expInfo, stairInfo, outputfile, monitorInfo = setupExperiment() except: raise try: win = open_window(monitorInfo) show_instructions( win, "Press spacebar to start experiment, doing " + str(expInfo['TrainingTrials']) + " training trials") # Convert the string of steps to a list of floats to feed to every # staircase stepSizes = [ float(x) for x in stairInfo['StepSizes'].replace('[', '').replace( ']', '').split(',') ] expConditions = [{ 'label': 'Right', 'startVal': stairInfo['FlickerFreqRight'], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpRight'], 'nDown': stairInfo['nDownRight'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': min(stepSizes) }, { 'label': 'Left', 'startVal': stairInfo['FlickerFreqLeft'], 'method': '2AFC', 'stepType': stairInfo['StepType'], 'stepSizes': stepSizes, 'nUp': stairInfo['nUpLeft'], 'nDown': stairInfo['nDownLeft'], 'nTrials': stairInfo['MinTrials'], 'nReversals': stairInfo['MinReversals'], 'minVal': min(stepSizes) }] from psychopy import data stairs = data.MultiStairHandler(conditions=expConditions, nTrials=1, method=stairInfo['Selection']) if (monitorInfo['RunSpeedTest']): from common.draw_test_square import draw_test_square draw_test_square(win) # Do some training trials with no variation in speed for i in range(0, int(expInfo['TrainingTrials'])): flickerTrial(win, expInfo, flickerFreq=1, side='Left', useOddBall=True) show_instructions(win, "Finished training trials, press spacebar to begin") for flickerFreq, thisCondition in stairs: thisResp = flickerTrial(win, expInfo, flickerFreq, side=thisCondition['label'], useOddBall=True) if thisResp is not None: stairs.addData(not thisResp) stairs.saveAsText(outputfile) stairs.saveAsText(outputfile) stairs.saveAsPickle(outputfile) stairs.saveAsExcel(outputfile) experiment_finished(win) except: stairs.saveAsText(outputfile) stairs.saveAsPickle(outputfile) stairs.saveAsExcel(outputfile) win.close() raise