From Lupyan Lab
Jump to: navigation, search

Display a random name, take in responses, read from a file

names = ['first1 last1', 'first2 last2'] #etc. where first and last are first and last names you'd like to play around with.
"""Show each name for 750 ms"""
firstNames = [name.split(' ')[0] for name in names]
the line above is equivalent to: 
for name in names:
	firstNames.append(name.split(' ')[0])
win = visual.Window([800,600],color="black", units='pix')
firstNameStim = visual.TextStim(win,text=random.choice(firstNames), height=40, color='white',pos=[0,0])
while True:
	nameShown = random.choice(firstNames)
	if event.getKeys(keyList=['q']):

  1. Create a fixation cross using a TextStim object (text="+", color="white") such that it appears for 500 ms before each name and disappears right before the name comes up.
  2. Open names.py to see what the names list looks like. Make the script show last names instead of first names (don't change the names.py file)
  3. Make the program randomly alternate between first names and last names.
  4. On each presentation of a name, wait for a response ('f' for first name, 'l' for last-name) and only proceed to the next name if the response is correct. Hint: if you've done steps 2-3 properly, this should be really easy. Refer to the psychopy documentation of event.waitKeys() if you have trouble.
  5. Normally, if you're reading in trial information from a file, it won't come as a python list (a la names.py). Instead of names.py, read in the names from names.txt such that your script converts the names inside names.txt into a python list from which you can randomly select a name, etc. See here for a primer on how to read (and write) files. Hint: you'll have to do something to the end of each line in names.txt before the text is "usable" (you'll see what I mean).
  6. solution Now let's implement some feedback. Let's allow either a 'f' or 'l' response for each trial. If the response is correct, show a green 'O' before the start of the next trial. If the response is wrong, show a red 'X' (you can use textStim objects for feedback). Show the feedback for 500 ms. Note: we have someone in a class whose last name is a common first name. If this were an experiment, how might this affect responses?
  7. Now, instead of waiting for a response forever, let's implement a timeout. Show accuracy feedback as before, but now also show a red 'X' if no response is received for 1 sec (and go on to the next trial automatically following the feedback). (Use psychopy timers)
  8. Pop up a box that accepts a first name, and check to make sure that the name exists. If it doesn't, pop-up a 'Name does not exist' error box
  9. Extend the task by requiring the subject to respond by pressing a spacebar, as quickly as possible anytime the name on the screen matches the name you entered into the box (so if I enter 'Gary' I would have to press 'space' anytime the name 'Gary' shows up. If the participant presses 'space' to the wrong name (false alarm), or misses the name (a miss), show a red X.
  10. See if you can figure out how to compute the response times, measured from the onset of the name, to the response (Use psychopy timers)
  11. Output the response times (in ms, e.g., 453 for 453 ms) and accuracy (1 for correct, 0 for incorrect) to a file output.txt. Output one line per trial: each line should contain the accuracy (1 or 0) and the response time (in milliseconds). See the python documentation for examples of how to write to a file. Ask for help if you are stuck.
  12. Do something cool. Compare response times to first and last names, measure effect of font face, etc.

Solutions to Exercise 2

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