smathot

Flicker fusion task

Oct 30th, 2012
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. # This script shows two patches in rapid succession, to get a flicker fusion
  2. # effect. It requires the PsychoPy backend.
  3.  
  4. from psychopy import visual
  5. from openexp.keyboard import keyboard
  6. import numpy as np
  7.  
  8. size = 512 # Stimulus size
  9. n = 50 # Number of presentation cycles
  10. delay = 20 # Delay between presentations (the actual delay depends on the
  11.            # display refresh as well!)
  12.  
  13. # Initial colors in HSV color space. See http://www.psychopy.org/general/colours.html
  14. col1 = [0,1,.5]
  15. col2 = [180,1,.5]
  16. colD = .005 # Luminance change per step
  17.  
  18.  
  19. my_keyboard = keyboard(self.experiment, keylist=["up", "down", 'space'],
  20.     timeout=1)
  21.  
  22. # Create two stimuli, see
  23. # http://www.psychopy.org/api/visual/patchstim.html
  24. patch1 = visual.PatchStim(win, tex=None, mask='gauss', color=col1,
  25.     size=size, colorSpace='hsv')
  26. patch2 = visual.PatchStim(win, tex=None, mask='gauss', color=col2,
  27.     size=size, colorSpace='hsv')
  28.  
  29. # Alternately show the stimuli. Also record the timestamps, so we can verify
  30. # the timing
  31. l = []
  32. while True:
  33.  
  34.     # Accept when space is pressed, and use up and down to calibrate colors
  35.     resp, time = my_keyboard.get_key()
  36.     if resp == 'space':
  37.         break
  38.     if resp == 'up':
  39.         col1[2] = max(0, min(1, col1[2]+colD))
  40.         col2[2] = max(0, min(1, col2[2]-colD))
  41.         patch1.setColor(col1)
  42.         patch2.setColor(col2)
  43.     if resp == 'down':
  44.         col1[2] = max(0, min(1, col1[2]-colD))
  45.         col2[2] = max(0, min(1, col2[2]+colD))
  46.         patch1.setColor(col1)
  47.         patch2.setColor(col2)
  48.        
  49.     # Show the two patches
  50.     patch1.draw()
  51.     win.flip()
  52.     self.sleep(delay)
  53.     l.append(self.time())
  54.     patch2.draw()  
  55.     win.flip()
  56.     l.append(self.time())
  57.     self.sleep(delay)
  58.    
  59.     l = l[-100:] # Make sure the list doesn't grow too long
  60.    
  61. # Store the actual delay between the two stimuli, and the standard deviation
  62. # of the delay for offline verification
  63. a = np.array(l)
  64. exp.set('mean_soa', np.mean(a[1:]-a[:-1]))
  65. exp.set('sd_soa',  np.std(a[1:]-a[:-1]))
  66.  
  67. exp.set('col1', '%s' % col1)
  68. exp.set('col2', '%s' % col2)
Advertisement
Add Comment
Please, Sign In to add comment