From Lupyan Lab
Display a random name, take in responses, read from a file
- Open the file namesRSVP.py in your Exercise_2 folder (or use the code below).
- If you don't have access to the personalized names.py file, you can create your own using the following format:
names = ['first1 last1', 'first2 last2'] #etc. where first and last are first and last names you'd like to play around with.
- Run the file below (press 'q' to quit at anytime). Go through each line below and understand what it's doing.
"""Show each name for 750 ms""" firstNames = [name.split(' ') for name in names] """ the line above is equivalent to: firstNames= for name in names: firstNames.append(name.split(' ')) """ 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) firstNameStim.setText(nameShown) firstNameStim.draw() win.flip() core.wait(.75) win.flip() core.wait(.15) if event.getKeys(keyList=['q']): break
- 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.
- 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)
- Make the program randomly alternate between first names and last names.
- 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.
- 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).
- 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?
- 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)
- 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
- 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.
- 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)
- 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.
- Do something cool. Compare response times to first and last names, measure effect of font face, etc.
- Bonus: You've probably noticed that the name you typed in only appears rarely (in fact, it will appear 1/# of people in the class, on average). Change the code so that the name you entered appears on 1/4 of the trials.