Пример #1
0
def set_screen():  # screen properties
    global win, start_text, left_label, right_label, center_disp, instruction_page, left_bg, right_bg, ok_button, ok_text
    win = Window([1280, 1000],
                 color='Black',
                 fullscr=fullscreen,
                 screen=0,
                 units='pix',
                 allowGUI=True)  # 1280 1024
    text_left = 'nein'
    text_right = 'ja'
    h_dist = 80
    v_dist = -190
    left_bg = Rect(win,
                   fillColor='red',
                   pos=[-h_dist, v_dist - 7],
                   width=130,
                   height=85)
    right_bg = Rect(win,
                    fillColor='green',
                    pos=[h_dist, v_dist - 7],
                    width=130,
                    height=85)
    left_label = TextStim(win,
                          color='white',
                          font='Verdana',
                          text=text_left,
                          pos=[-h_dist, v_dist],
                          height=50,
                          alignHoriz='center')
    right_label = TextStim(win,
                           color='white',
                           font='Verdana',
                           text=text_right,
                           pos=[h_dist, v_dist],
                           height=50,
                           alignHoriz='center')
    center_disp = TextStim(win,
                           color='white',
                           font='Arial',
                           text='',
                           height=55)
    instruction_page = TextStim(win,
                                wrapWidth=1200,
                                pos=[0, 35],
                                height=28,
                                font='Verdana',
                                color=instruction_color)
    ok_button = Rect(win,
                     fillColor='black',
                     lineColor=instruction_color,
                     pos=[0, -345],
                     width=80,
                     height=50)
    ok_text = TextStim(win,
                       text='OK',
                       bold=True,
                       color=instruction_color,
                       pos=(0, -345),
                       height=30)
Пример #2
0
    def draw_rect(self, colour=None, color=None, x=None, y=None, w=50, h=50, \
        pw=1, fill=False):
        """Draws a rectangle on the screen
        
        arguments
        None
        
        keyword arguments
        colour    -- colour for the circle (a colour name (e.g. 'red') or
                   a RGB(A) tuple (e.g. (255,0,0) or (255,0,0,255))) or
                   None for the default foreground colour, self.fgc
                   (default = None)
        x        -- x coordinate of the rectangle or None for a
                   horizontal centrally drawn rectangle (default = None)
        y        -- y coordinate of the rectangle or None for a
                   vertical centrally drawn rectangle (default = None)
        w        -- width of the rectangle (default = 50)
        h        -- height of the rectangle (default = 50)
        pw        -- penwidth: ellipse line thickness (default = 1)
        fill        -- Boolean indicating whether rectangle should be filled
                   or not (default = False)
        
        returns
        Nothing    -- draws a rectangle on (PyGame) or adds a GratinsStim
                   stimulus to (PsychoPy) the self.screen property
        """

        if color is None and colour is None:
            pass
        elif color is None and colour is not None:
            pass
        elif color is not None and colour is None:
            colour = color
        elif colour != color:
            raise Exception(
                "The arguments 'color' and 'colour' are the same, but set to different values: color={}, colour={}"
                .format(color, colour))

        if colour is None:
            colour = self.fgc
        if x is None:
            x = self.dispsize[0] / 2
        if y is None:
            y = self.dispsize[1] / 2

        pos = x, y
        colour = rgb2psychorgb(colour)
        pos = pos2psychopos(pos, dispsize=self.dispsize)
        pos = pos[0] + w / 2, pos[1] - h / 2

        if fill:
            self.screen.append(Rect(pygaze.expdisplay, width=w, height=h, \
                lineWidth=pw, lineColor=colour, lineColorSpace='rgb', \
                fillColor=colour, fillColorSpace='rgb', pos=pos))
        else:
            self.screen.append(Rect(pygaze.expdisplay, width=w, height=h, \
                lineWidth=pw, lineColor=colour, lineColorSpace='rgb', \
                fillColor=None, pos=pos))
Пример #3
0
class SimpleCover():
    '''
        This class is a simplified version of class Cover for the practice mode.
    '''
    COVER, SHOW = range(2)
    def __init__(self, win, pos, name, width=0.15, height=0.1, color=(178, 178, 178)):
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.rect.setFillColor(color=color, colorSpace='rgb255')
        self.rect.setLineColor(color=color, colorSpace='rgb255')
        self.mouse = event.Mouse(win=win)
        self.state = self.COVER
        
    def draw(self):
        if self.state == self.COVER:
            self.rect.draw()
        elif self.state == self.SHOW:
            pass
    
    def process(self):
        x, y = self.mouse.getPos()
        # if need to click to see the information, uncomment the following line and comment the line after the following line
        if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1:
        # if self.rect.contains(x, y, units='norm'):
            self.state = self.SHOW
        elif not self.rect.contains(x, y, units='norm'):
            self.state = self.COVER
Пример #4
0
    def __init__(self, win, pos, name, detail_file, sub_id, test_id, width=0.15, height=0.1, color=(178, 178, 178)):
        self.name = name
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.rect.setFillColor(color=color, colorSpace='rgb255')
        self.rect.setLineColor(color=color, colorSpace='rgb255')
        self.mouse = event.Mouse(win=win)
        self.state = self.COVER
        self.time = 0
        self.single_time = 0
        self.last_state = self.COVER
        self.last_time = 0
        self.clk = clock.Clock()

        self.detail_file = detail_file
        self.sub_id = sub_id
        self.test_id = test_id
 def default_draw(self):
     y = 0
     left_box = Rect(disp,
                     pos=(self.left_x, y),
                     width=self.width,
                     height=self.height,
                     lineColor=self.normal_color,
                     lineWidth=self.normal_line)
     right_box = Rect(disp,
                      pos=(self.right_x, y),
                      width=self.width,
                      height=self.height,
                      lineColor=self.normal_color,
                      lineWidth=self.normal_line)
     left_box.draw()
     right_box.draw()
Пример #6
0
class Cover():
    COVER, SHOW = range(2)
    def __init__(self, win, pos, name, detail_file, sub_id, test_id, width=0.15, height=0.1, color=(178, 178, 178)):
        self.name = name
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.rect.setFillColor(color=color, colorSpace='rgb255')
        self.rect.setLineColor(color=color, colorSpace='rgb255')
        self.mouse = event.Mouse(win=win)
        self.state = self.COVER
        self.time = 0
        self.single_time = 0
        self.last_state = self.COVER
        self.last_time = 0
        self.clk = clock.Clock()

        self.detail_file = detail_file
        self.sub_id = sub_id
        self.test_id = test_id
        
    def draw(self):
        if self.state == self.COVER:
            self.rect.draw()
        elif self.state == self.SHOW:
            pass
    
    def process(self):
        x, y = self.mouse.getPos()
        # if need to click to see the information, uncomment the following line and comment the line after the following line
        if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1:
        # if self.rect.contains(x, y, units='norm'):
            self.state = self.SHOW
        elif not self.rect.contains(x, y, units='norm'):
            self.state = self.COVER
        if self.last_state == self.SHOW:
            this_time = self.clk.getTime() - self.last_time
            self.time += this_time
            self.single_time += this_time
            # time记录累加时间,single_time记录单次时间
            if self.state == self.COVER:
                self.detail_file.write(','.join((str(self.sub_id), str(self.test_id), str(self.name), str(self.single_time))))
                self.detail_file.write('\n')
                self.single_time = 0
        self.last_time = self.clk.getTime()
        self.last_state = self.state
Пример #7
0
    def __init__(self,
                 window,
                 response_size=(1, .5),
                 fillColor=(1, 1, -1),
                 *args,
                 **kwargs):

        n_responses = 4
        total_width = n_responses * \
            response_size[0] + (n_responses - 1) * .1 * response_size[0]
        positions = -total_width / 2. + \
            response_size[0]/2. + \
            np.arange(n_responses) * 1.1 * response_size[0]
        positions = [(pos, 0) for pos in positions]

        self.rectangles = [
            Rect(window,
                 size=response_size,
                 pos=positions[n],
                 opacity=.5,
                 fillColor=fillColor) for n in range(n_responses)
        ]

        self.stim_texts = [
            TextStim(window,
                     height=.45 * response_size[1],
                     wrapWidth=.9 * response_size[0],
                     pos=positions[n],
                     color=(-1, -1, -1),
                     text=n + 1) for n in range(n_responses)
        ]

        self.description_text = TextStim(
            window,
            pos=(0, 1.5 * response_size[1]),
            wrapWidth=response_size[0] * 8.8,
            text=
            'How certain are you about your choice (1=very certain,  4= very uncertain)'
        )
Пример #8
0
class Button():
    START, END = range(2)
    def __init__(self, win, pos, width, height, name, text='选择'):
        self.name = name
        self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
        self.mouse = event.Mouse(win=win)
        self.caption = TextStim(win, text=text, height=height - 0.01 , pos=pos, units='norm', color=(0, 0, 0), colorSpace='rgb255')
        self.state = self.START
        
    def draw(self):
        x, y = self.mouse.getPos()
        if self.rect.contains(x, y, units='norm'):
            self.rect.setLineColor(color=(0, 0, 204), colorSpace='rgb255')
            self.caption.setColor(color=(0, 0, 204), colorSpace='rgb255')
        else:
            self.rect.setLineColor(color=(0, 0, 0), colorSpace='rgb255')
            self.caption.setColor(color=(0, 0, 0), colorSpace='rgb255')
        self.rect.draw()
        self.caption.draw()
    
    def process(self):
        x, y = self.mouse.getPos()
        if self.rect.contains(x, y, units='norm') and self.mouse.getPressed()[0] == 1:
            self.state = self.END
Пример #9
0
def displayRecordResponse(on, trialStart, autoResp, StimLength):
    # take autoResp and trialStart and returns humanResp and humanRT
    while True:
        (button, time) = myMouse.getPressed(getTime=True)
        autoRT = 0.25
        if on > 0:
            if clock.getTime() > (trialStart + autoRT):
                if autoResp == 1:
                    target2 = Rect(win,
                                   units="deg",
                                   width=0.5,
                                   height=StimLength,
                                   fillColor="FireBrick",
                                   lineColor="FireBrick",
                                   pos=targpos)
                else:
                    target2 = Rect(win,
                                   units="deg",
                                   width=0.5,
                                   height=StimLength,
                                   fillColor="Lime",
                                   lineColor="Lime",
                                   pos=targpos)
                background.draw()
                target2.draw()
                win.flip()
        #Record response (either left or right click)
        if button[0]:  #Left click
            humanResp = 0
            humanRT = time[0]
            break
        elif button[2]:  #Right click
            humanResp = 1
            humanRT = time[2]
            break
    return (humanResp, humanRT)
Пример #10
0
test_phase_screen_en = visual.TextStim(win, text="?", color=black)
end_screen_en = visual.TextStim(win, text="?", color=black)

# item positions
item1_pos = [-300, 0]
item2_pos = [-100, 0]
item3_pos = [100, 0]
item4_pos = [300, 0]

# buttons
no_pos = [-300, -200]
yes_pos = [300, -200]

yes = Rect(win=win,
           pos=yes_pos,
           width=100,
           height=100,
           units="pix",
           fillColor="green")
no = Rect(win=win,
          pos=no_pos,
          width=100,
          height=100,
          units="pix",
          fillColor="red")

size = (150, 150)
units = "pix"

########### RUN EXPERIMENT ###########

if info['language'] == 'Xhosa':
Пример #11
0
from constants import *
from psychopy.visual import Window, TextStim, shape, Circle, Rect
from psychopy.event import waitKeys
from psychopy.core import wait

disp = Window(size=DISPSIZE, units='pix', color=BGC, fullscr=True)

instructions = 'Willkommen! \n\nIn diesem Experiment werden die Buchstaben E und F auf dem ' \
               'Bildschirm erscheinen. Wenn du eine E siehst, drücke das E. Wenn du ein F siehst' \
               ', drücke das F \n\n Versuche so genau und schnell wie möglich zu antworten. \n\n' \
               'Viel Glück!'

inststim = TextStim(disp, units='pix', text=instructions, color=FGC, height=35)
fixstim = Circle(disp, radius=6, edges = 32, lineColor = FGC, fillColor = FGC)

lboxstim = Rect(disp, pos=BOXCORS['left'], width=BOXSIZE, height=BOXSIZE, lineColor = FGC,
                lineWidth=3)
rboxstim = Rect(disp, pos=BOXCORS['right'], width=BOXSIZE, height=BOXSIZE, lineColor = FGC,
                lineWidth=3)
cuestim = {}

cuestim['left'] = Rect(disp, pos=BOXCORS['left'], width=BOXSIZE, height=BOXSIZE, lineColor = FGC,
                lineWidth=8)

cuestim['right'] = Rect(disp, pos=BOXCORS['right'], width=BOXSIZE, height=BOXSIZE, lineColor = FGC,
                lineWidth=8)

tarscr = {}

tarscr['left']  = {}
tarscr['right'] = {}
Пример #12
0
# Object Setup
positions = [0, 0]
startButton = Circle(win,
                     units="deg",
                     radius=1,
                     lineWidth=.5,
                     lineColor=(1, 1, 1),
                     fillColor=(0, 0, 0))
fixCross = Circle(win,
                  units="deg",
                  radius=1,
                  lineColor=(1, 1, 1),
                  fillColor=(0, 0, 0))
background = Rect(win,
                  units="deg",
                  width=13,
                  height=13,
                  fillColor=(0, 0, 0),
                  lineColor=(0, 0, 0))
placeholder = Circle(win,
                     radius=0.5,
                     fillColor=(-.5, -.5, -.5),
                     lineColor=(-.5, -.5, -.5),
                     pos=[0, 6])

#Introduction Slides

intromes = TextStim(win,
                    text="""Welcome to the Production Decision Experiment""",
                    wrapWidth=20,
                    units='deg',
                    pos=[0, 10],
    def cue(self, location):
        y = 0
        if location == "left":
            left_cue = Rect(disp,
                            pos=(self.left_x, y),
                            width=self.width,
                            height=self.height,
                            lineColor=self.cue_color,
                            lineWidth=self.cue_line)
            right_box = Rect(disp,
                             pos=(self.right_x, y),
                             width=self.width,
                             height=self.height,
                             lineColor=convertRGB(BLACK),
                             lineWidth=self.normal_line)
            right_box.draw()
            left_cue.draw()

        if location == "right":
            left_box = Rect(disp,
                            pos=(self.left_x, y),
                            width=self.width,
                            height=self.height,
                            lineColor=convertRGB(BLACK),
                            lineWidth=self.normal_line)
            right_cue = Rect(disp,
                             pos=(self.right_x, y),
                             width=self.width,
                             height=self.height,
                             lineColor=self.cue_color,
                             lineWidth=self.cue_line)
            right_cue.draw()
            left_box.draw()
def main(window, dominant_eye):

    """
    This is pretty much just a less complicated version of the step method
    in the testing script, so it's not commented that much.
    """

    # Fusion box stuff

    maskPos = -200
    if dominant_eye:
        maskPos = 200


    box_1 = Rect(win = window,
                 width = 180,
                 height = 180,
                 lineWidth = 4,
                 lineColor = 'grey',
                 pos = (-200, 150),
                 autoDraw = True)

    box_2 = Rect(win = window,
                 width = 180,
                 height = 180,
                 lineWidth = 4,
                 lineColor = 'grey',
                 pos = (-1 * -200, 150),
                 autoDraw = True)

    box_1.setAutoDraw(True)
    box_2.setAutoDraw(True)

    # Mask stuff

    frame_paths = ["Masks/" + file for file in os.listdir("Masks")]
    frames = map(lambda file_name: ImageStim(window,
                                            image = file_name,
                                            color = (1,1,1),
                                            size = [150, 150],
                                            pos = (maskPos,150),
                                            opacity = 1), frame_paths)

    #Fixation dot stuff

    fixation_dot_1 = Circle(win = window,
                          radius = 2,
                          fillColor = 'red',
                          pos = (-200, 150),
                          lineWidth = 0,
                          autoDraw = True)

    fixation_dot_2 = Circle(win = window,
                          radius = 2,
                          fillColor = 'red',
                          pos = (-1 * -200, 150),
                          lineWidth = 0,
                          autoDraw = True)



    img = Image("Pairs/practice_img.jpg", "")

    img = img.stimulus(window,
                       position = (-1*maskPos, 150),
                       transparency = 1)

    transparencies = [0.016 * (n + 1) * 0.1 for n in range(60)]

    # ten trials at 10% contrast and ten at 50%
    N_TRIALS = 20
    all_trials = [i for i in range(N_TRIALS)]
    shuffle(all_trials)

    low_contrast = all_trials[:10]
    high_contrast = all_trials[10:]

    low_transparencies = [0.016 * (n + 1) * 0.1 for n in range(60)]
    high_transparencies = [0.016 * (n + 1) * 0.5 for n in range(60)]

    for i in range(N_TRIALS):
        if i in low_contrast:
            step(window, low_transparencies, img, frames, 0.05 * i)
        if i in high_contrast:
            step(window, high_transparencies, img, frames, 0.05 * i)

    box_1.setAutoDraw(False)
    box_2.setAutoDraw(False)

    fixation_dot_1.setAutoDraw(False)
    fixation_dot_2.setAutoDraw(False)
Пример #15
0
 def __init__(self, win, pos, name, width=0.15, height=0.1, color=(178, 178, 178)):
     self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
     self.rect.setFillColor(color=color, colorSpace='rgb255')
     self.rect.setLineColor(color=color, colorSpace='rgb255')
     self.mouse = event.Mouse(win=win)
     self.state = self.COVER
# item positions in pixels
# the first number is lateral position, the second is vertical position
# 0,0 is the default setting (center screen)
item1_pos = [-300, 0]  # left
item2_pos = [-100, 0]  # left, but closer to center
item3_pos = [100, 0]  # right, but closer to center
item4_pos = [300, 0]  # right

# button positions
no_pos = [-300, -200]  # low, right
yes_pos = [300, -200]  # low, left

# create buttons as rectanfular objects
yes = Rect(win=win,
           pos=yes_pos,
           width=100,
           height=100,
           units="pix",
           fillColor="green")
no = Rect(win=win,
          pos=no_pos,
          width=100,
          height=100,
          units="pix",
          fillColor="red")

# settings for the stimuli
size = (150, 150)
units = "pix"

########### RUN EXPERIMENT ###########
Пример #17
0
 def __init__(self, win, pos, width, height, name, text='选择'):
     self.name = name
     self.rect = Rect(win, height=height, width=width, units='norm', pos=pos)
     self.mouse = event.Mouse(win=win)
     self.caption = TextStim(win, text=text, height=height - 0.01 , pos=pos, units='norm', color=(0, 0, 0), colorSpace='rgb255')
     self.state = self.START
Пример #18
0
def trigger_signal():
    Beep(750, 800)  #frequency, HZ, duration, ms
    print 'SIGNAL WAS TRIGGERED'


disp = Window(size=DISPSIZE,
              units='pix',
              color=(-1, -1, -1),
              fullscr=True,
              screen=0)
mouse = Mouse()
stim = Rect(disp,
            pos=RECPOS,
            width=RECSIZE[0],
            height=RECSIZE[1],
            lineColor=(0, 0, 0),
            fillColor=(0, 0, 0),
            lineWidth=3)


def main():

    tracker = Eyetracker(debug=True)
    tracker.connect_to_iView()
    tracker.calibrate()
    tracker.validate()

    stim.draw()
    disp.flip()
    print 'Stim appeared'
Пример #19
0
    export_json = json.dumps(dict(
        time = int(time()),
        subject = subject,
        email = email,
        first_d8 = d8(commitments.dateplus(date.today(), 1)),
        last_d8 = d8(commitments.dateplus(date.today(), commitments.checkin_range)),
        activities = activity_names))

    f = urllib2.urlopen(par['receiver_url'], data = urllib.urlencode(dict(
        hmac = hmac.new(par['hmac_key'], export_json).hexdigest(),
        json = export_json)))
    if par['debug']: print f.read()
    f.close()

divider_bar = Rect(o.win,
    fillColor = 'black', lineColor = 'black',
    width = 1.5, height = .01)
prompt = o.text(0, .8, 'Which option would you prefer?')

dec_rate = 1 / 0.25
inc_rate = 1 / 0.523852201187
trials = 26
  # Note that the catch-trials specifications implicitly rely on
  # this.

def econ_test(dkey_prefix, instructions, text_top, text_bottom,
        initial_discount_guess, catch_big, catch_small):
    with o.dkey_prefix(('econ', dkey_prefix)):
        o.instructions('instructions', instructions, wrap = 1.5)
        with o.showing(divider_bar, prompt):
            discount_guess = initial_discount_guess
Пример #20
0
                            pos=(0.0, 0.0),
                            color=FOREGROUND,
                            height=24)

# creating a fixation cross
fixStim = ShapeStim(win,
                    vertices=((0, -10), (0, 10), (0, 0), (-10, 0), (10, 0)),
                    lineWidth=3,
                    closeShape=False,
                    lineColor=FOREGROUND)

# create the left box
leftboxStim = Rect(win,
                   pos=BOX_LEFT,
                   width=BOXSIZE,
                   height=BOXSIZE,
                   lineColor=FOREGROUND,
                   lineWidth=3,
                   fillColor=None)
# create the right box
rightboxStim = Rect(win,
                    pos=BOX_RIGHT,
                    width=BOXSIZE,
                    height=BOXSIZE,
                    lineColor=FOREGROUND,
                    lineWidth=3,
                    fillColor=None)
# create left cue
cueleftStim = Rect(win,
                   pos=BOX_LEFT,
                   width=BOXSIZE,
Пример #21
0
# stimulus color always opposite of background color
if bg_color == 'white':
    stim_color = 'black'
elif bg_color == 'black':
    stim_color = 'white'
else:
    exit('wrong bg_color')

kb = keyboard.Keyboard()
my_win = Window(fullscr=True, size=(1000, 600), units='pix', color='white')

# define the "stimulus" rectangle whose color is going to be changing
therect = Rect(my_win,
               width=500,
               height=500,
               lineColor='lightblue',
               fillColor='red')
# define a small information box for continually updated info about the ongoing trials
info = TextStim(my_win,
                text='Info...',
                height=30,
                pos=(-400, 300),
                color='green')
info.autoDraw = True

durations = [16, 50, 150, 300, 500]  # variations of stimulus display duration
date_time = str(strftime("%Y_%m%d_%H%M", gmtime()))  # current date
data_out = open('disptime_psychopy_' + bg_color + '_' + date_time + '.txt',
                'a',
                encoding='utf-8')
Пример #22
0
stimuli_timer = CountdownTimer(0)
phase_timer = CountdownTimer(0)
global_time = Clock()
p_list = [0.25, 0.75]

data = []  #array for data
data.append(['time', 'R1', 'R2', 'score', 'number', 'zeros', 'ones',
             'p'])  #column names in csv file

#displayed text
text = TextStim(win=win, pos=(0, 0), text=' ')

#defines click boxes
lbox = Rect(win=win,
            width=0.3,
            height=0.3,
            lineColor='red',
            lineWidth=5,
            pos=(-0.3, -0.6))

rbox = Rect(win=win,
            width=0.3,
            height=0.3,
            lineColor='red',
            lineWidth=5,
            pos=(+0.3, -0.6))

while global_time.getTime() < session * 60:

    #checks of keyboard input
    resp_key = getKeys(['q', 'escape'])
Пример #23
0
    def create_trials(self):
        """creates trials"""

        this_instruction_string = """Determine whether the second flash is more left or right of the first.\nPress 'f' for left and 'j' for right. \nPress either key to start."""
        self.instruction = TextStim(self.screen, 
            text = this_instruction_string, 
            font = 'Helvetica Neue',
            pos = (0, 0),
            italic = True, 
            height = 20, 
            alignHoriz = 'center',
            color=self.config['stim_color'])
        self.instruction.setSize((1200,50))

        # combining all 5 positions gives 5x5=25 possible location combinations
        x_test_positions = np.array(np.meshgrid(self.config['test_stim_positions'], self.config['test_stim_positions'])).T.reshape((-1,2))
        # x1, x2 = x_test_positions[:,0], x_test_positions[:,1]
        x1, x2 = np.zeros_like(x_test_positions[:,0]), x_test_positions[:,1]

        # y position is above or below fp
        # y_test_positions = np.concatenate((-1 * np.ones(x_test_positions.shape[0]), np.ones(x_test_positions.shape[0])))
        y_test_positions = np.concatenate((-1*np.ones(x_test_positions.shape[0]), -1*np.ones(x_test_positions.shape[0])))

        # tile them 4 times, so that we have 25*4=100 trials
        x_test_positions_tiled = np.array([np.tile(x1, 4), np.tile(x2, 4)]).T
        y_test_positions_tiled = np.tile(y_test_positions, 2)

        # all combinations of parameters are now repeated twice, so we add the eye dir to first 50 and last 50
        eye_dir = np.concatenate([np.ones(x_test_positions_tiled.shape[0]/2),np.zeros(x_test_positions_tiled.shape[0]/2)])

        # now let's create a random trial order 
        self.trial_order = np.arange(eye_dir.shape[0])
        np.random.shuffle(self.trial_order)

        # and apply
        x_test_positions_tiled_shuffled = x_test_positions_tiled[self.trial_order]
        y_test_positions_tiled_shuffled = y_test_positions_tiled[self.trial_order]
        eye_dir_shuffled = eye_dir[self.trial_order]

        ITIs = np.zeros(len(self.trial_order))
        # and here's the distribution of ITIs:
        # unique_ITIs = {
        # 1: 37,
        # 2: 22,
        # 3: 15,
        # 4: 10,
        # 5: 7,
        # 6: 4,
        # 7: 3,
        # 8: 2
        # }

        unique_ITIs = {
        1: 50,
        2: 50
        }

        # randomly distribute ITI's over the trial combinations:
        ITI_order = np.arange(len(ITIs))
        np.random.shuffle(ITI_order)        
        k = 0
        for this_ITI in unique_ITIs.keys():
            ITIs[ITI_order[k:k+unique_ITIs[this_ITI]]] = this_ITI
            k += unique_ITIs[this_ITI]

        # and add or subtract 1 when a switch in eye dir is required:
        n_switches = 0
        for ti, this_eye_dir in enumerate(eye_dir_shuffled):
            ITI_cumsum = np.cumsum(ITIs)[ti]
            current_direction = ITI_cumsum%2
            if current_direction != this_eye_dir:
                ITIs[ti] += [-1,1][n_switches%2]
                n_switches += 1

        ITIs += self.config['minimal_iti']
       
        # the total number of TRs can now be either 661 or 662, depending on whether there even or even n_switches
        # thus add 1 TR when n_switches are uneven:
        padd_TR = n_switches%2

        # now add the first and last empty trials:
        x_test_positions_tiled_shuffled = np.vstack([[-1e3,-1e3],x_test_positions_tiled_shuffled,[-1e3,-1e3]]) #-1e3 means off the screen)
        y_test_positions_tiled_shuffled = np.hstack([-1e3,y_test_positions_tiled_shuffled,-1e3]) #-1e3 means off the screen)
        ITIs = np.hstack([self.config['warming_up_n_TRs'],ITIs,self.config['warming_up_n_TRs']+padd_TR])
        eye_dir_shuffled = np.hstack([0,eye_dir_shuffled,0])

        # define all durations per trial
        self.phase_durations = np.array([[
            10, # instruct time, skipped in all trials but the first (wait for t)
            ITI * self.config['TR'], # smooth pursuit before stim
            self.config['TR'], # smooth pursuit after stim 1
            self.config['TR'] # smooth pursuit after stim 2
            ] for ITI in ITIs] )    
        
        self.fixation = PatchStim(self.screen,
            mask='raisedCos',
            tex=None, 
            size=self.config['sp_target_size']*self.pixels_per_degree, 
            pos = np.array((0.0,self.config['sp_target_size']*self.pixels_per_degree)), 
            color = self.config['stim_color'], 
            opacity = 1.0, 
            maskParams = {'fringeWidth':0.4})

        # now define the test stim sizes dependent on screen size available:
        if self.config['test_stim_height'] == 0:
            self.config['test_stim_height'] = self.ywidth/4/self.pixels_per_degree
        if self.config['test_stim_y_offset'] == 0:
            self.config['test_stim_y_offset'] = self.ywidth/4/self.pixels_per_degree
        self.test_stim_1 = Rect(self.screen, 
                            width = self.config['test_stim_width']*self.pixels_per_degree,  
                            height = self.config['test_stim_height']*self.pixels_per_degree, 
                            lineColor = self.config['stim_color'],
                            fillColor = self.config['stim_color'])

        self.test_stim_2 = Rect(self.screen, 
                            width = self.config['test_stim_width']*self.pixels_per_degree, 
                            height = self.config['test_stim_height']*self.pixels_per_degree, 
                            lineColor = self.config['stim_color'],
                            fillColor = self.config['stim_color'])

        self.start_time = 0.0
        self.cumulative_phase_durations = np.cumsum(np.r_[0,self.phase_durations[:,1:].ravel()][:-1]).reshape((self.phase_durations.shape[0], -1))

        self.all_trials = []
        for i in range(len(eye_dir_shuffled)):#self.trial_order:

            this_trial_parameters={
                                    # trial varying params:
                                    'x_pos_1': x_test_positions_tiled_shuffled[i,0],
                                    'x_pos_2': x_test_positions_tiled_shuffled[i,1], 
                                    'y_order': y_test_positions_tiled_shuffled[i],
                                    'eye_dir': eye_dir_shuffled[i],
                                    'ITI': ITIs[i], # this should not be _shuffled

                                    # these params don't vary over trials:
                                    'TR': self.config['TR'],
                                    'sp_path_amplitude':self.config['sp_path_amplitude'],
                                    'test_stim_y_offset':self.config['test_stim_y_offset'],
                                    'sp_path_elevation':self.config['sp_path_elevation'],
                                    'sp_path_temporal_frequency':self.config['sp_path_temporal_frequency'],
                                    'warming_up_n_TRs':self.config['warming_up_n_TRs']
                                    }

            self.all_trials.append(SPTrial(i,this_trial_parameters, self.phase_durations[i], session = self, screen = self.screen, tracker = self.tracker))
#  notice that the "size" of the slider controls whether the slider is verticle or horizontal
#  change to desired style, using the in-built visual stimulus from psychopy

slider.marker = Circle(
    win,
    radius=slider.size[0] * 0.5,  # The radius should be half the width 
    edges=32,
    fillColor='black',
    lineColor='gray')

slider.line = Rect(
    win,
    units=slider.units,
    pos=slider.pos,
    width=slider.size[0],
    height=slider.size[1] +
    0.005,  # +0.005 just to make the rectangule looks better
    lineColor='black',
    fillColor='gray',
    autoLog=False)

text1 = visual.TextStim(win=win,
                        name='text1',
                        text='default text',
                        font='Arial',
                        pos=(text123X, text123Y),
                        height=text1H,
                        wrapWidth=None,
                        ori=0,
                        color='black',
                        colorSpace='rgb',
Пример #25
0
    height = 24)

#define the boxes for drawing cues and targets

Box_Dimen = [200, 200]

Box_Coord = {}
Box_Coord['left'] = (
    int(display_size[0] * -0.25), 0
)  # a quarter of the way to the left and right from the center of the screen
Box_Coord['right'] = (int(display_size[0] * 0.25), 0)

#create the left and right boxes for presentation

Box_Left = Rect(disp, pos = Box_Coord['left'],\
    width = Box_Dimen[0], height = Box_Dimen[1], \
    lineColor = FGC, lineWidth = 3)

Box_Right = Rect(disp, pos = Box_Coord['right'],\
    width = Box_Dimen[0], height = Box_Dimen[1], \
    lineColor = FGC, lineWidth = 3)

#define the cue and create the cue windows (thicker border)
cue_Stim = {}

cue_Stim['left'] = Rect(disp, pos = Box_Coord['left'], \
    width = Box_Dimen[0], height = Box_Dimen[1], \
    lineColor = cue_Flash, lineWidth = 8)

cue_Stim['right'] = Rect(disp, pos = Box_Coord['right'],\
    width = Box_Dimen[0], height = Box_Dimen[1],\