def pst(controller, outfile): duration = pstSettings(controller) if duration == -1: print 'PST Cancelled' return display.text(controller.experWin, 'Running PST') testWin = controller.testWin display.countdown(controller) display.fill_screen(testWin, [-1, -1, -1]) if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams(['task','duration']) controller.tobii_cont.setParam('task', 'pst') controller.tobii_cont.setParam('duration', duration) core.wait(duration) if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def imagetest(controller, outfile): stim_dur, images = image_settings(controller) if stim_dur == -999: return display.text(controller.experWin, 'Running Image Test') # set up test window testWin = controller.testWin # parameters for task iti_mean = 3 iti_range = 2 # set up image stim object stim = visual.ImageStim(testWin, image=os.path.join(os.getcwd(), 'images', images[0]), units='norm', size=(1.0, 1.0)) # display instructions display.text_keypress( testWin, 'In this task, you will view some images. \n Press any key when ready to begin.') display.countdown(controller) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams( ['task', 'imagetime', 'iti_mean', 'iti_range', 'image_order', 'isfear']) controller.tobii_cont.setParam('task', 'image_test') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('image_order', images) core.wait(2.0) # give small wait time before starting trial for image in images: if not controller.testing: # RECORD TIMESTAMP FOR IMAGE DISPLAY controller.tobii_cont.recordEvent('imagetime') # record whether it is a fearful image or not if 'fear' in image: controller.tobii_cont.addParam('isfear', 1) else: controller.tobii_cont.addParam('isfear', 0) # display image stim.setImage(os.path.join(os.getcwd(), 'images', image)) stim.draw() testWin.flip() # wait for predetermined stim_dur time core.wait(stim_dur) # clear screen testWin.flip() iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def lightdarktest(controller, mode, outfile): # Create window to display test testWin = controller.testWin if mode == 0: # dark test task = 'darktest' numtrials = 3 # number of light/dark cycles habit_mat = [1, 1, 1] # set habituation to full brightness # set stimulus matrix to darkness stim_mat = np.negative(np.ones((numtrials, 3))) # back to full brightness for recovery rec_mat = np.ones((numtrials, 3)) stim_time = 1 # duration of stimulus in seconds display.text(controller.experWin, 'Running Dark Test') elif mode == 1: # light test task = 'lighttest' habit_mat = [-1, -1, -1] # habituation is black stim_mat = [[-0.5, -0.5, -0.5], # stimulus is increasing brightness each time [0.00, 0.00, 0.00], [0.50, 0.50, 0.50], [1.00, 1.00, 1.00]] # set numtrials based on number of stimulus conditions numtrials = len(stim_mat) # recovery goes back to black rec_mat = np.negative(np.ones((numtrials, 3))) stim_time = 0.2 # length of stimulus time in seconds display.text(controller.experWin, 'Running Light Test') habit_dur = 10 # time for habituation # time for recovery between stimuli recover_dur = 8 * np.ones((1, numtrials)) stim_dur = stim_time * np.ones((1, numtrials)) # duration of each stimulus display.countdown(controller) # display countdown before task # habituation display.fill_screen(testWin, habit_mat) core.wait(habit_dur) # Start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams(['ontime', 'offtime', 'task']) controller.tobii_cont.setParam('task', task) for i in range(numtrials): core.wait(2.0) # display stimulus display.fill_screen(testWin, stim_mat[i]) # record timestamp on tracker for start of stimulus if not controller.testing: controller.tobii_cont.recordEvent('ontime') # wait for stimulus core.wait(stim_dur[0][i]) # display recovery display.fill_screen(testWin, rec_mat[i]) # record timestamp on tracker for end of stimulus if not controller.testing: controller.tobii_cont.recordEvent('offtime') # wait for recovery core.wait(recover_dur[0][i]) # End eye tracking if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def lightdarktest(controller, mode, outfile): # Create window to display test testWin = controller.testWin if mode == 0: # dark test task = 'darktest' numtrials = 3 # number of light/dark cycles habit_mat = [1, 1, 1] # set habituation to full brightness # set stimulus matrix to darkness stim_mat = np.negative(np.ones((numtrials, 3))) # back to full brightness for recovery rec_mat = np.ones((numtrials, 3)) stim_time = 1 # duration of stimulus in seconds display.text(controller.experWin, 'Running Dark Test') elif mode == 1: # light test task = 'lighttest' habit_mat = [-1, -1, -1] # habituation is black stim_mat = [ [-0.5, -0.5, -0.5], # stimulus is increasing brightness each time [0.00, 0.00, 0.00], [0.50, 0.50, 0.50], [1.00, 1.00, 1.00] ] # set numtrials based on number of stimulus conditions numtrials = len(stim_mat) # recovery goes back to black rec_mat = np.negative(np.ones((numtrials, 3))) stim_time = 0.2 # length of stimulus time in seconds display.text(controller.experWin, 'Running Light Test') habit_dur = 10 # time for habituation # time for recovery between stimuli recover_dur = 8 * np.ones((1, numtrials)) stim_dur = stim_time * np.ones((1, numtrials)) # duration of each stimulus display.countdown(controller) # display countdown before task # habituation display.fill_screen(testWin, habit_mat) core.wait(habit_dur) # Start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams(['ontime', 'offtime', 'task']) controller.tobii_cont.setParam('task', task) for i in range(numtrials): core.wait(2.0) # display stimulus display.fill_screen(testWin, stim_mat[i]) # record timestamp on tracker for start of stimulus if not controller.testing: controller.tobii_cont.recordEvent('ontime') # wait for stimulus core.wait(stim_dur[0][i]) # display recovery display.fill_screen(testWin, rec_mat[i]) # record timestamp on tracker for end of stimulus if not controller.testing: controller.tobii_cont.recordEvent('offtime') # wait for recovery core.wait(recover_dur[0][i]) # End eye tracking if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def oddball(controller, outfile): trialvec = oddSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Oddball') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' lowsnd = sound.Sound(resource_path + '500.wav') highsnd = sound.Sound(resource_path + '1000.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress( testWin, 'In this task, you will listen to some sounds. \n Press any key to continue') # play sound samples lowsnd.play() display.text_keypress( testWin, 'Some sounds are low... \n Press any key to continue') highsnd.play() display.text_keypress( testWin, '...and some are high. \n Press any key to continue') display.text_keypress( testWin, 'When you hear a sound, press the space bar.\n\nPress any key when ready.') display.countdown(controller) display.cross(controller.testWin) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams( ['task', 'soundtime', 'presstime', 'iti_mean', 'iti_range', 'trialvec']) controller.tobii_cont.setParam('task', 'oddball') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2.0) # give small wait time before starting trial for isHigh in trialvec: # RECORD TIMESTAMP FOR SOUND PLAY if not controller.testing: controller.tobii_cont.recordEvent('soundtime') if isHigh: highsnd.play() # play high sound if oddball else: lowsnd.play() # otherwise play low sound # wait for space bar keypress = event.waitKeys(keyList=['space', 'q']) if keypress[0] == 'q': break elif keypress[0] == 'space': if not controller.testing: # RECORD TIMESTAMP FOR KEY PRESS controller.tobii_cont.recordEvent('presstime') iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def revlearn(controller, outfile): trialvec = revSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Reversal Learning') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' wrongsnd = sound.Sound(resource_path + 'buzz1.wav') rightsnd = sound.Sound(resource_path + 'dinga.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress(testWin, ('Press the left or right key \n' + 'when the cross appears onscreen.\n' + 'You must learn by trial and error\n' + 'which is correct. \n\n' + '(Press any key to continue)')) # sound samples rightsnd.play() display.text_keypress( testWin, 'You will hear this for correct responses. \n (Press any key to continue)') wrongsnd.play() display.text_keypress( testWin, 'And this for incorrect responses. \n (Press any key to continue)') display.text_keypress( testWin, 'Please make a choice as soon as the "+" appears\n(Press any key when ready)') # display countdown display.countdown(controller) # start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams( ['task', 'soundtime', 'presstime', 'cuetime', 'correct', 'choice', 'iti_mean', 'iti_range', 'trialvec']) controller.tobii_cont.setParam('task', 'revlearn') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2) for isTrue in trialvec: # display cross display.cross(testWin) if not controller.testing: controller.tobii_cont.recordEvent('cuetime') keypress = event.waitKeys(keyList=['left', 'right', 'q']) if not controller.testing: controller.tobii_cont.recordEvent('presstime') controller.tobii_cont.addParam('choice', keypress[0]) if keypress[0] == 'q': break elif (keypress[0] == 'left' and not isTrue) or (keypress[0] == 'right' and isTrue): if not controller.testing: controller.tobii_cont.recordEvent('soundtime') rightsnd.play() correct = 1 else: if not controller.testing: controller.tobii_cont.recordEvent('soundtime') wrongsnd.play() correct = 0 if not controller.testing: controller.tobii_cont.addParam('correct', correct) # outcome period core.wait(1.0) # clear screen testWin.flip(clearBuffer=True) iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # stop eye tracking and save data if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def oddball(controller, outfile): trialvec = oddSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Oddball') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' lowsnd = sound.Sound(resource_path + '500.wav') highsnd = sound.Sound(resource_path + '1000.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress( testWin, 'In this task, you will listen to some sounds. \n Press any key to continue' ) # play sound samples lowsnd.play() display.text_keypress( testWin, 'Some sounds are low... \n Press any key to continue') highsnd.play() display.text_keypress( testWin, '...and some are high. \n Press any key to continue') display.text_keypress( testWin, 'When you hear a sound, press the space bar.\n\nPress any key when ready.' ) display.countdown(controller) display.cross(controller.testWin) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams([ 'task', 'soundtime', 'presstime', 'iti_mean', 'iti_range', 'trialvec' ]) controller.tobii_cont.setParam('task', 'oddball') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2.0) # give small wait time before starting trial for isHigh in trialvec: # RECORD TIMESTAMP FOR SOUND PLAY if not controller.testing: controller.tobii_cont.recordEvent('soundtime') if isHigh: highsnd.play() # play high sound if oddball else: lowsnd.play() # otherwise play low sound # wait for space bar keypress = event.waitKeys(keyList=['space', 'q']) if keypress[0] == 'q': break elif keypress[0] == 'space': if not controller.testing: # RECORD TIMESTAMP FOR KEY PRESS controller.tobii_cont.recordEvent('presstime') iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def imagetest(controller, outfile): stim_dur, images = image_settings(controller) if stim_dur == -999: return display.text(controller.experWin, 'Running Image Test') # set up test window testWin = controller.testWin # parameters for task iti_mean = 3 iti_range = 2 # set up image stim object stim = visual.ImageStim(testWin, image=os.path.join(os.getcwd(), 'images', images[0]), units='norm', size=(1.0, 1.0)) # display instructions display.text_keypress( testWin, 'In this task, you will view some images. \n Press any key when ready to begin.' ) display.countdown(controller) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams([ 'task', 'imagetime', 'iti_mean', 'iti_range', 'image_order', 'isfear' ]) controller.tobii_cont.setParam('task', 'image_test') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('image_order', images) core.wait(2.0) # give small wait time before starting trial for image in images: if not controller.testing: # RECORD TIMESTAMP FOR IMAGE DISPLAY controller.tobii_cont.recordEvent('imagetime') # record whether it is a fearful image or not if 'fear' in image: controller.tobii_cont.addParam('isfear', 1) else: controller.tobii_cont.addParam('isfear', 0) # display image stim.setImage(os.path.join(os.getcwd(), 'images', image)) stim.draw() testWin.flip() # wait for predetermined stim_dur time core.wait(stim_dur) # clear screen testWin.flip() iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def revlearn(controller, outfile): trialvec = revSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Reversal Learning') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' wrongsnd = sound.Sound(resource_path + 'buzz1.wav') rightsnd = sound.Sound(resource_path + 'dinga.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress( testWin, ('Press the left or right key \n' + 'when the cross appears onscreen.\n' + 'You must learn by trial and error\n' + 'which is correct. \n\n' + '(Press any key to continue)')) # sound samples rightsnd.play() display.text_keypress( testWin, 'You will hear this for correct responses. \n (Press any key to continue)' ) wrongsnd.play() display.text_keypress( testWin, 'And this for incorrect responses. \n (Press any key to continue)') display.text_keypress( testWin, 'Please make a choice as soon as the "+" appears\n(Press any key when ready)' ) # display countdown display.countdown(controller) # start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams([ 'task', 'soundtime', 'presstime', 'cuetime', 'correct', 'choice', 'iti_mean', 'iti_range', 'trialvec' ]) controller.tobii_cont.setParam('task', 'revlearn') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2) for isTrue in trialvec: # display cross display.cross(testWin) if not controller.testing: controller.tobii_cont.recordEvent('cuetime') keypress = event.waitKeys(keyList=['left', 'right', 'q']) if not controller.testing: controller.tobii_cont.recordEvent('presstime') controller.tobii_cont.addParam('choice', keypress[0]) if keypress[0] == 'q': break elif (keypress[0] == 'left' and not isTrue) or (keypress[0] == 'right' and isTrue): if not controller.testing: controller.tobii_cont.recordEvent('soundtime') rightsnd.play() correct = 1 else: if not controller.testing: controller.tobii_cont.recordEvent('soundtime') wrongsnd.play() correct = 0 if not controller.testing: controller.tobii_cont.addParam('correct', correct) # outcome period core.wait(1.0) # clear screen testWin.flip(clearBuffer=True) iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # stop eye tracking and save data if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()