Stimuli

Repetitive stimulation

To generate repetitive stimulation, which is sometimes used in psychophysics, I created the function \(repite\).

The demo bellow displays a stimulus that alternates between three colors. Every color is displayed for 10 frames. In the argument ‘start’, I indicate where I want the sequence to start. In this case, I want the onset of the red color to be displayed in the frame 13.

Point-light walker

In the demo bellow the coordinates of each point are in the file walker.txt that should be included in the same folder that the psychopy file.

from psychopy import *
from numpy import *
from random import *
### function to escape the program
def esc():
for keys in event.getKeys():
if keys in ['escape','q']:
core.quit()
framesFile = open('walker.txt','r') #open the file that contains the coordinates of each point
### reading the first line of the file; contains the general information of the animation
firstLine=framesFile.readline()
firstLineSplit=firstLine.split()
numberFrames=int(firstLineSplit[0])
numberMarkers=int(firstLineSplit[1])
numberHz=int(firstLineSplit[2])
### defining the dimensions of the main structure data
m=zeros((numberFrames,numberMarkers,3))
### creating the matrix that contain the coordinates of each point
for frame in range(numberFrames):
for marker in range(numberMarkers):
line=framesFile.readline()
lineSplit=line.split()
for i in range(3):
m[frame][marker][i]=float(lineSplit[i])
myWin = visual.Window(monitor='testMonitor',units='deg')
sti = visual.PatchStim(myWin,tex='None',mask='circle',size=.2)
size=0.02
frame=1
while True:
for marker in range(numberMarkers):
x=size*m[frame%numberFrames][marker][0]
y=size*m[frame%numberFrames][marker][2]
sti.setPos([x,y])
sti.draw()
sti.draw()
myWin.flip()
frame+=1
esc()
core.quit()

Template to create experiment

Below a template that I used to run experiments using the method of constant stimuli. The relevant information needs to be included only once in the list \(vars\). It uses some helper functions that I created grouped in the module psychopyHelp.py that it could be placed in the same folder as the template.