Skip to content

Instantly share code, notes, and snippets.

@nmningmei
Forked from dilawar/white_noise.py
Created April 29, 2019 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmningmei/95e41408d42450200646c8935e64e0aa to your computer and use it in GitHub Desktop.
Save nmningmei/95e41408d42450200646c8935e64e0aa 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