Example #1
0
    def __init__(self):
        self.disp = libscreen.Display(monitor=MONITOR)
        self.mouse = libinput.Mouse(visible=True)
        self.keyboard = libinput.Keyboard(
            keylist=['space', 'left', 'right', 'lctrl', 'rctrl'], timeout=None)

        self.blank_screen = libscreen.Screen()

        self.intro_screen = libscreen.Screen()

        self.intro_screen.draw_text(
            text='During each trial, a cloud of moving dots is going to \
                                            appear on the screen. Watch it carefully to detect \
                                            whether the dots in general are moving to the left or \
                                            to the right (click left mouse button to start)',
            fontsize=18)

        self.fixation_screen = libscreen.Screen()
        self.fixation_screen.draw_fixation(fixtype='cross', pw=3)

        self.initialize_ready_screen()
        self.initialize_stimulus_screen()
        self.initialize_feedback_screen()

        self.warning_sound = sound.Sound(1000, secs=0.1)
Example #2
0
    def __init__(self):
        try:
            self.eyetracker = tr.find_all_eyetrackers()[0]
        except IndexError:
            messagebox.showinfo(
                "Error",
                "Tobii Eye Tracker not found. Please restart the Tobii Service\nfound in the \"Services\" application"
            )
            import sys
            sys.exit(1)

        self.gaze_data = []

        self.disp = libscreen.Display()
        self.screen = libscreen.Screen()
        self.kb = libinput.Keyboard(keylist=['space', 'escape', 'q'],
                                    timeout=1)
        self.screendist = constants.SCREENDIST

        # calibration and validation points
        lb = 0.1  # left bound
        xc = 0.5  # horizontal center
        rb = 0.9  # right bound
        ub = 0.1  # upper bound
        yc = 0.5  # vertical center
        bb = 0.9  # bottom bound
        self.points_to_calibrate = [
            self._norm_2_px(p)
            for p in [(lb, ub), (rb, ub), (xc, yc), (lb, bb), (rb, bb)]
        ]

        # maximal distance from fixation start (if gaze wanders beyond this, fixation has stopped)
        self.fixtresh = 1.5  # degrees
        # amount of time gaze has to linger within self.fixtresh to be marked as a fixation
        self.fixtimetresh = 100  # milliseconds
        # saccade velocity threshold
        self.spdtresh = 35  # degrees per second
        # saccade acceleration threshold
        self.accthresh = 9500  # degrees per second**2
        # blink detection threshold used in PyGaze method
        self.blinkthresh = 50  # milliseconds

        self.screensize = constants.SCREENSIZE  # display size in cm
        self.pixpercm = (
            self.disp.dispsize[0] / float(self.screensize[0]) +
            self.disp.dispsize[1] / float(self.screensize[1])) / 2.0
from pygaze import libtime
from pygaze import liblog
from pygaze import libinput
from pygaze import eyetracker

# # # # #
# experiment setup

# create display object
disp = libscreen.Display()

# create eyetracker object
tracker = eyetracker.EyeTracker(disp)

# create keyboard object
keyboard = libinput.Keyboard(keylist=['space'], timeout=None)

# create logfile object
log = liblog.Logfile()
log.write(["trialnr", "trialtype", "endpos", "latency", "correct"])

# create screens
inscreen = libscreen.Screen()
inscreen.draw_text(
    text=
    "When you see a cross, look at it and press space. Then make an eye movement to the black circle when it appears.\n\n(press space to start)",
    fontsize=24)
fixscreen = libscreen.Screen()
fixscreen.draw_fixation(fixtype='cross', pw=3)
targetscreens = {}
targetscreens['left'] = libscreen.Screen()
Example #4
0
from pygaze import libinput
from pygaze import libtime

from psychopy import visual
from psychopy import core
import matplotlib.pyplot as plt

import os
import constants
import Waveforms_v2 as wf

import numpy as np

disp = libscreen.Display()

kb_space = libinput.Keyboard(keylist=['space'], timeout=None)
kb_response = libinput.Keyboard(keylist=['s', 'v', 'q'], timeout=None)

scr = libscreen.Screen()
scr.draw_text(
    'Starting the ITD demo!\n\nPress S for sound first\n\nPress V for visual first\n\n--Space bar to start--',
    fontsize=24)
disp.fill(scr)
disp.show()
kb_space.get_key()

ITD_array = np.linspace(-1, 1, num=80)
ITD_size = 400
np.random.shuffle(ITD_array)
response_array = []
Example #5
0
import random
import constants

import pygaze
from pygaze import libscreen
from pygaze import libinput
from pygaze import libtime
from pygaze import eyetracker

from psychopy import visual

disp = libscreen.Display()
kb = libinput.Keyboard(timeout = None)
tracker = eyetracker.EyeTracker(disp)

fix = visual.Circle(pygaze.expdisplay,
                    size = 5,
                    lineWidth=10,
                    pos = [0, 0])

target = visual.Circle(pygaze.expdisplay,
                    size = 20,
                    fillColor=[-1,-1,-1],
                    lineColor=[0,0,0],
                    pos = [100, 200])
distractor = visual.Circle(pygaze.expdisplay,
                    size = 20,
                    fillColor=[1, 1, 1],
                    lineColor=[1, 1, 1],
                    pos = [200, 100])
Example #6
0
from pygaze import libinput
from pygaze import liblog
from pygaze import defaults
defaults.osexperiment = exp

w = 1024
h = 768

# # # # #
# setup the experiment

# create display object
disp = libscreen.Display(disptype='opensesame')

# create keyboard object
kb = libinput.Keyboard(disptype='opensesame', keylist=['left','right','escape'], timeout=2000)

# create logfile object
log = liblog.Logfile()
log.write(["trialnr", "trialtype", "response", "RT", "correct"])

# create screens
fixscreen = libscreen.Screen(disptype='opensesame')
fixscreen.draw_fixation(fixtype='cross',pw=2)
targetscreens = {}
targetscreens['left'] = libscreen.Screen(disptype='opensesame')
targetscreens['left'].draw_circle(pos=(w*0.25,h/2), fill=True)
targetscreens['right'] = libscreen.Screen(disptype='opensesame')
targetscreens['right'].draw_circle(pos=(w*0.75,h/2), fill=True)
feedbackscreens = {}
feedbackscreens[1] = libscreen.Screen(disptype='opensesame')
Example #7
0
# importing the relevant libraries
import random
import constants
from pygaze import libscreen
from pygaze import libtime
from pygaze import libinput
from pygaze import liblog

# # # # #
# setup the experiment

# create display object
disp = libscreen.Display()

# create keyboard object
kb = libinput.Keyboard(keylist=['left', 'right', 'escape'], timeout=2000)

# create logfile object
log = liblog.Logfile()
log.write(["trialnr", "trialtype", "response", "RT", "correct"])

# create screens
fixscreen = libscreen.Screen()
fixscreen.draw_fixation(fixtype='cross', pw=2)
targetscreens = {}
targetscreens['left'] = libscreen.Screen()
targetscreens['left'].draw_circle(pos=(constants.DISPSIZE[0] * 0.25,
                                       constants.DISPSIZE[1] / 2),
                                  fill=True)
targetscreens['right'] = libscreen.Screen()
targetscreens['right'].draw_circle(pos=(constants.DISPSIZE[0] * 0.75,
Example #8
0
    def __init__(self):
        self.expName = 'Bird'
        self.path = os.getcwd()
        self.subjInfo = {
                '1':  { 'name' : 'subjCode',
                        'prompt' : 'EXP_XXX',
                        'options': 'any',
                        'default':self.expName+'_101'},
                '2' : {	'name' : 'gender', 
			'prompt' : 'Subject Gender m/f: ', 
			'options' : ("m","f"),
			'default':'',
			'type' : str},
		'3' : {	'name' : 'age', 
			'prompt' : 'Subject Age: ', 
			'options' : 'any',
			'default':'',
			'type' : str},
		'4' : {'name' : 'seed', 
			'prompt' : 'Seed: ', 
			'options' : 'any', 
			'default' : 101, 
			'type' : 101},	
		'5' : {'name' : 'expInitials', 
			'prompt' : 'Experiment Initials: ', 
			'options' : 'any', 
			'default' : '', 
			'type' : str},
		'6' : {	'name' : 'activeMode', 
			'prompt' : 'input / gaze', 
			'options' : ("input","gaze"),
			'default':"gaze",
			'type' : str},
		'7' : { 'name' : 'inputDevice',
                        'prompt' : 'keyboard / mouse',
                        'options' : ("keyboard","mouse"),
                        'default':'keyboard'},
		'8' : { 'name' : 'eyetracker', 
			'prompt' : '(yes / no)', 
			'options' : ("yes","no"), 
			'default' : "yes", 
			'type' : str},
		'9' : { 'name' : 'pygazeVersion', 
			'prompt' : '(04 / 06)', 
			'options' : ("04","06"), 
			'default' : "06", 
			'type' : str},
		}

        optionsReceived = False
        fileOpened = False
        while not fileOpened:
            [optionsReceived, self.subjVariables] = enterSubjInfo(self.expName, self.subjInfo)
            constants.LOGFILENAME=constants.LOGFILEPATH+self.subjVariables['subjCode']
            constants.LOGFILE=constants.LOGFILENAME[:]
            if self.subjVariables['pygazeVersion'] == "06":
                from pygaze import display
                from pygaze import settings
                settings.LOGFILE = constants.LOGFILENAME[:]
                print settings.LOGFILE
            if not optionsReceived:
                popupError(self.subjVariables)
            elif not os.path.isfile('data/'+'data_'+self.subjVariables['subjCode']+'.txt'):
                
                #if using an eyetracker
                if self.subjVariables['eyetracker']=="yes":
                    #import eyetracking package from pygaze
                    from pygaze import eyetracker
                    
                    if not os.path.isfile(constants.LOGFILENAME+'_TOBII_output.tsv'):
                        fileOpened = True
                        self.outputFile = open('data/'+'data_'+self.subjVariables['subjCode']+'.txt','w')
                        
                    else:
                        fileOpened = False
                        popupError('That subject code for the eyetracking data already exists! The prompt will now close!')  
                        core.quit()  
                else:
                    fileOpened = True
                    self.outputFile = open('data/'+'data_'+self.subjVariables['subjCode']+'.txt','w')
            else:
                fileOpened = False
                popupError('That subject code already exists!')        
                    
        # create display object
        self.disp = libscreen.Display(disptype='psychopy')
        
        #create psychopy window based on Display() object 
        if self.subjVariables['pygazeVersion'] == "06":
            self.win = pygaze.expdisplay 
        else: 
            self.win = self.disp.expdisplay  
        
        if self.subjVariables['eyetracker']=="yes":
            # create eyetracker object
            self.tracker = eyetracker.EyeTracker(self.disp)
        
        if self.subjVariables['inputDevice'] == 'keyboard': 
            print "Using keyboard..."
            self.inputDevice = "keyboard"
            self.validResponses = {'1':'space','2': 'enter'}
            ## create keyboard object
            self.input = libinput.Keyboard(keylist=['space', 'enter', 'left', 'right'], timeout=None)
        elif self.subjVariables['inputDevice'] == 'mouse':
            print "Using mouse..."
            self.inputDevice = "mouse"
            self.input = libinput.Mouse(mousebuttonlist=[1], timeout=None)
            if self.subjVariables['activeMode']=="input":
                self.input.set_visible(visible=True)

        self.imagePath=self.path+'/stimuli/images/'
        self.soundPath=self.path+'/stimuli/sounds/'
        self.moviePath=self.path+'/stimuli/movies/'
        self.imageExt='.png'
Example #9
0
stimuli = [
    Stimulus("Geben Sie mir Ihren Zylinder!"),
    Stimulus("Hier ist ein Rezept für Tabletten."),
    Stimulus("Ich bin gut in Chemie."),
    Stimulus("Möchten Sie gerne etwas essen?")
]

### experiment setup ###

# start timing
libtime.expstart()

disp = libscreen.Display()
tracker = eyetracker.EyeTracker(disp)
keyboard = libinput.Keyboard(keylist=["space"], timeout=None)

# local log (mainly for debugging)
log = liblog.Logfile()
log.write([
    "time",
    "trialnr",
    "stimulus",
    "fixation_start",
    "fixation_pos",
])

inscreen = libscreen.Screen()
inscreen.draw_text(
    text=("On the next screen look at the center of the cross on the left."
          " Then read the sentence and after reading it, look at the dot"