Skip to content

Instantly share code, notes, and snippets.

@dilawar
Last active April 29, 2019 20:34
Show Gist options
  • Save dilawar/f100626c6eba06a616e3 to your computer and use it in GitHub Desktop.
Save dilawar/f100626c6eba06a616e3 to your computer and use it in GitHub Desktop.
Create white noise stimulus in python using psychopy
# Generate noise frames
# dependencies: psychopy, python-numpy, python-pyglet
from numpy import random
from psychopy import visual
# create a window
win = visual.Window([800, 600], monitor="testMonitor", units="deg")
maskDuration = 180 # Duration of mask in frames
visualNoiseSize = 512 # Dimension in pixels of visual noise. Must be a power of 2
noiseSize = 512
visualNoise = [] # list of rendered frames
for n in range(maskDuration):
noiseTexture = random.rand(visualNoiseSize,visualNoiseSize)*2-1
visualNoise += [visual.PatchStim(win=win, tex=noiseTexture, size=(visualNoiseSize,visualNoiseSize), units='pix',interpolate=False, mask='gauss')]
visualNoise[-1].draw() # first draw is slower. So do it now.
win.clearBuffer()
# ACTION: shows mask and the trial's stimulus
for frame in range(maskDuration):
visualNoise[frame].draw()
stim.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment