Example #1
0
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()
Example #2
0
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()
Example #3
0
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()
Example #4
0
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()
Example #5
0
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()
Example #6
0
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()