From Lupyan Lab
Jump to: navigation, search

Here is some 'bad' code that shows a blue circle and a blue square. In this assignment you'll work on this code to expand it to a full blown perceptual grouping task.

import time
import random
from psychopy import visual, core, event
win = visual.Window([800,600],color="black", units='pix')
circle = visual.Circle(win,size = 20)
square = visual.Rect(win,size = 40)
locations = [[-15,0], [15,0]]
colors = ['blue', 'blue']
Alternating shapes
  1. Now, for each trial, pick a random shape and "flip" it such that you have two squares or two circles in a row. The colors should always alternate. So, you might have red-square, blue-circle, red-circle, blue-square , etc.(a repetition of two circles in a row). Note, you will need to do more than just flip the one shape to make this work (flipping a single shape in an alternating sequence will create a sequence of three repeated items, which is not what you want).
    • hint: random.choice([0,1]) will output 0 or 1. The items in the list supplied as the argument to the random.choice function can be anything, e.g., random.choice(['within','between']) will output the words 'within' or 'between' randomly.
  2. Make it so that 50% of the trials have a repeat, and 50% don't (i.e., the latter just have the normal alternation, as in the picture above)
  3. The subject's task is to detect the repetition. If there's a repetition, they should press the 'up' arrow. If not, the 'down' arrow.
  4. Let's now add feedback. If there's an error, and only if there's an error, display the word 'ERROR' in red after the response.
  5. Let's make the subject report what shape was repeating. Make it so that if they press the 'up' arrow, they then see a prompt "Repeated square or circle?" which should stay up until they respond with the 's' key for square and the 'c' key for circle. If they press the 'down' arrow, just go on to the next trial.
  6. Now, let's actually keep track of what people are responding! For each trial, output the variables listed below to a file called results.txt. You can use
 '\t'.join([string1, string2, string3, stringN]) 

to create a line in which each variable is separated by a tab, and then write that line to the file. Each item in the list passed to join must be a string, so any items that are not (hint: the Reaction Time) must be first converted to a string using str(RT). See here for instructions on writing to a file one line at a time, making sure that there is no data loss if your program crashes. Here's what each line should contain:

7. This file will contain their responses and trial parameters, but we don't know who the subject is! Remember when I had you pop=up a box to enter in a person's name? Do the same thing here, but pop-up a box to ask for the subject code. You'll then want to do things with this subject code:

Name the output file with that code, e.g., repetition_101.txt, repetition_102.txt, etc. (there's a very good reason to start with 100 instead of 1. Any ideas?)
Write the subj code as the first entry in each column of your output file


Bonus: instead of having them respond with circle/square, let's make them tell us exactly where the repetition was. After they make a repeat/no-Repeat response, have the shapes change to X's and have the subject indicate with the mouse (ooo!) where the repeat was. Mark it as correct or not. If you want to try a 'bonus-lite' version, change the shapes to letters: a,b,c,d,e,f,g,h,i,j,k,l,m,n,o and have the subject press the letter corresponding to where the repeat was.

Personal tools
Download and Install
Notes for each class - will be updated ~week before each class.
Programming Exercises
Quick reference