Advertisement
peapodpeapod

click paradigm + word loop (coroutine)

Feb 27th, 2019
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. ---
  2. API: 2.1
  3. OpenSesame: 3.2.6
  4. Platform: nt
  5. ---
  6. set width 1024
  7. set uniform_coordinates yes
  8. set title "New experiment"
  9. set subject_parity even
  10. set subject_nr 0
  11. set start experiment
  12. set sound_sample_size -16
  13. set sound_freq 48000
  14. set sound_channels 2
  15. set sound_buf_size 1024
  16. set round_decimals 2
  17. set height 768
  18. set fullscreen no
  19. set form_clicks no
  20. set foreground white
  21. set font_underline no
  22. set font_size 18
  23. set font_italic no
  24. set font_family mono
  25. set font_bold no
  26. set experiment_path "F:\\Tamil Eng Exp"
  27. set disable_garbage_collection yes
  28. set description "Default description"
  29. set coordinates uniform
  30. set compensation 0
  31. set canvas_backend xpyriment
  32. set background black
  33.  
  34. define keyboard_response click_keyb_resp
  35. set timeout 1000
  36. set flush yes
  37. set event_type keypress
  38. set duration keypress
  39. set description "Collects subjects' keyboard responses to clicks"
  40. set correct_response space
  41. set allowed_responses space
  42.  
  43. define inline_script click_paradigm
  44. set description "Executes Python code"
  45. set _run ""
  46. ___prepare__
  47. current_idx = var.get('count_nonword_sequence')
  48.  
  49. if current_idx in click_indices:
  50. print("Indices: {} - current_idx: {}".format(click_indices, current_idx))
  51. click_sound.play()
  52. __end__
  53.  
  54. define inline_script define_nonwords
  55. set description "Executes Python code"
  56. set _run ""
  57. ___prepare__
  58. import random
  59.  
  60. # This to expose variables to other Python inline block
  61. global placeholders, nonwords, wordmap
  62.  
  63.  
  64. placeholders = ['a0', 'a1', 'a2', 'a3', 'b0', 'b1', 'b2', 'b3']
  65. nonwords = ['machant', 'knovy', 'gonper', 'rafic', 'bockel', 'howest', 'pelly', 'sovate']
  66.  
  67. random.shuffle(nonwords)
  68.  
  69. # To create a map between placeholders and nonwords
  70. wordmap = {x: y for x, y in zip(placeholders, nonwords)}
  71. __end__
  72.  
  73. define sequence experiment
  74. set flush_keyboard yes
  75. set description "Runs a number of items in sequence"
  76. run new_sketchpad_1 always
  77. run define_nonwords always
  78. run setup_random_clicks always
  79. run nonword_loop always
  80.  
  81. define inline_script keyb_resp_script
  82. set description "recording reaction times to click sounds"
  83. ___run__
  84. from openexp.keyboard import keyboard
  85. my_keyboard = keyboard(self.experiment)
  86.  
  87. start_time = clock.time()
  88.  
  89. current_idx = var.get('count_nonword_sequence')
  90.  
  91.  
  92. var.set('my_subj_should_click', current_idx in click_indices)
  93.  
  94. key, end_time = my_keyboard.get_key()
  95.  
  96. if key is not None:
  97. var.set('my_subj_click_rt', end_time - start_time)
  98. else:
  99. var.set('my_subj_click_rt', 0)
  100. __end__
  101. set _prepare ""
  102.  
  103. define logger logger
  104. set description "Logs experimental data"
  105. set auto_log yes
  106.  
  107. define sketchpad new_sketchpad_1
  108. set duration keypress
  109. set description "Displays stimuli"
  110. draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="spacebar to start" x=0 y=0 z_index=0
  111.  
  112. define sketchpad nonword
  113. set duration 240
  114. set description "Displays stimuli"
  115. draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=31 html=yes show_if=always text="[nonword]" x=0 y=0 z_index=0
  116.  
  117. define loop nonword_loop
  118. set source_file ""
  119. set source table
  120. set skip 0
  121. set repeat 1
  122. set order sequential
  123. set offset no
  124. set item nonword_sequence
  125. set description "Repeatedly runs another item"
  126. set cycles 40
  127. set continuous no
  128. set column_order wordorder
  129. set break_if_on_first yes
  130. set break_if never
  131. setcycle 0 wordorder a0
  132. setcycle 1 wordorder a1
  133. setcycle 2 wordorder b0
  134. setcycle 3 wordorder b1
  135. setcycle 4 wordorder a0
  136. setcycle 5 wordorder a2
  137. setcycle 6 wordorder b0
  138. setcycle 7 wordorder b3
  139. setcycle 8 wordorder a0
  140. setcycle 9 wordorder a3
  141. setcycle 10 wordorder b0
  142. setcycle 11 wordorder b1
  143. setcycle 12 wordorder a0
  144. setcycle 13 wordorder a2
  145. setcycle 14 wordorder b0
  146. setcycle 15 wordorder b2
  147. setcycle 16 wordorder a0
  148. setcycle 17 wordorder a1
  149. setcycle 18 wordorder b0
  150. setcycle 19 wordorder b3
  151. setcycle 20 wordorder a0
  152. setcycle 21 wordorder a3
  153. setcycle 22 wordorder b0
  154. setcycle 23 wordorder b2
  155. setcycle 24 wordorder a0
  156. setcycle 25 wordorder a1
  157. setcycle 26 wordorder b0
  158. setcycle 27 wordorder b1
  159. setcycle 28 wordorder a0
  160. setcycle 29 wordorder a3
  161. setcycle 30 wordorder b0
  162. setcycle 31 wordorder b2
  163. setcycle 32 wordorder a0
  164. setcycle 33 wordorder a2
  165. setcycle 34 wordorder b0
  166. setcycle 35 wordorder b1
  167. setcycle 36 wordorder a0
  168. setcycle 37 wordorder a3
  169. setcycle 38 wordorder b0
  170. setcycle 39 wordorder b3
  171. run nonword_sequence
  172.  
  173. define inline_script nonword_mapping
  174. set description "Executes Python code"
  175. set _run ""
  176. ___prepare__
  177. var.set('nonword', wordmap[var.get('wordorder')])
  178. __end__
  179.  
  180. define sequence nonword_sequence
  181. set flush_keyboard yes
  182. set description "Runs a number of items in sequence"
  183. run nonword_mapping always
  184. run wordloop_coroutine always
  185. run keyb_resp_script always
  186. run logger always
  187.  
  188. define inline_script setup_random_clicks
  189. set description "Executes Python code"
  190. set _run ""
  191. ___prepare__
  192. import random
  193.  
  194. #setup sampler
  195. sound = pool['click.wav']
  196. click_sound = sampler(sound, duration=0, volume=1)
  197.  
  198. #40 words in word loop
  199. population = list(range(40))
  200.  
  201. #select 5 random positions
  202. click_indices = random.sample(population, k=5)
  203. __end__
  204.  
  205. define coroutines wordloop_coroutine
  206. set flush_keyboard yes
  207. set end_after_item ""
  208. set duration 1000
  209. set description "Run items simultaneously"
  210. run click_paradigm end=0 runif=always start=0
  211. run nonword end=0 runif=always start=0
  212. run click_keyb_resp end=1000 runif=always start=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement