Advertisement
LeeB_86

Phono_test

Sep 2nd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.48 KB | None | 0 0
  1. # Generated by OpenSesame 0.27.3 (Frisky Freud)
  2. # Mon Sep 02 18:34:03 2013 (nt)
  3. # <http://www.cogsci.nl/opensesame>
  4.  
  5. set mouse_backend "xpyriment"
  6. set subject_parity "even"
  7. set height "768"
  8. set font_family "sans"
  9. set font_italic "no"
  10. set custom_cursor "yes"
  11. set synth_backend "legacy"
  12. set title "phonological_1234"
  13. set coordinates "relative"
  14. set start "experiment"
  15. set sampler_backend "legacy"
  16. set transparent_variables "no"
  17. set foreground "Black"
  18. set font_bold "no"
  19. set description "Default description"
  20. set background "White"
  21. set font_size "20"
  22. set keyboard_backend "legacy"
  23. set canvas_backend "xpyriment"
  24. set compensation "0"
  25. set subject_nr "0"
  26. set width "1366"
  27.  
  28. define loop s1_block_loop
  29.     set repeat "1"
  30.     set description "Repeatedly runs another item"
  31.     set skip "0"
  32.     set item "s1_trial_sequence"
  33.     set column_order "frame_colour;correct_cue_response"
  34.     set cycles "50"
  35.     set order "sequential"
  36.     setcycle 0 frame_colour "Black"
  37.     setcycle 0 correct_cue_response ""
  38.     setcycle 1 frame_colour "Black"
  39.     setcycle 1 correct_cue_response ""
  40.     setcycle 2 frame_colour "Black"
  41.     setcycle 2 correct_cue_response ""
  42.     setcycle 3 frame_colour "Black"
  43.     setcycle 3 correct_cue_response ""
  44.     setcycle 4 frame_colour "Black"
  45.     setcycle 4 correct_cue_response ""
  46.     setcycle 5 frame_colour "Black"
  47.     setcycle 5 correct_cue_response ""
  48.     setcycle 6 frame_colour "Black"
  49.     setcycle 6 correct_cue_response ""
  50.     setcycle 7 frame_colour "Black"
  51.     setcycle 7 correct_cue_response ""
  52.     setcycle 8 frame_colour "Black"
  53.     setcycle 8 correct_cue_response ""
  54.     setcycle 9 frame_colour "Black"
  55.     setcycle 9 correct_cue_response ""
  56.     setcycle 10 frame_colour "Black"
  57.     setcycle 10 correct_cue_response ""
  58.     setcycle 11 frame_colour "Black"
  59.     setcycle 11 correct_cue_response ""
  60.     setcycle 12 frame_colour "Black"
  61.     setcycle 12 correct_cue_response ""
  62.     setcycle 13 frame_colour "Black"
  63.     setcycle 13 correct_cue_response ""
  64.     setcycle 14 frame_colour "Black"
  65.     setcycle 14 correct_cue_response ""
  66.     setcycle 15 frame_colour "Black"
  67.     setcycle 15 correct_cue_response ""
  68.     setcycle 16 frame_colour "Black"
  69.     setcycle 16 correct_cue_response ""
  70.     setcycle 17 frame_colour "Black"
  71.     setcycle 17 correct_cue_response ""
  72.     setcycle 18 frame_colour "Black"
  73.     setcycle 18 correct_cue_response ""
  74.     setcycle 19 frame_colour "Green"
  75.     setcycle 19 correct_cue_response "g"
  76.     setcycle 20 frame_colour "Black"
  77.     setcycle 20 correct_cue_response ""
  78.     setcycle 21 frame_colour "Black"
  79.     setcycle 21 correct_cue_response ""
  80.     setcycle 22 frame_colour "Black"
  81.     setcycle 22 correct_cue_response ""
  82.     setcycle 23 frame_colour "Black"
  83.     setcycle 23 correct_cue_response ""
  84.     setcycle 24 frame_colour "Black"
  85.     setcycle 24 correct_cue_response ""
  86.     setcycle 25 frame_colour "Black"
  87.     setcycle 25 correct_cue_response ""
  88.     setcycle 26 frame_colour "Black"
  89.     setcycle 26 correct_cue_response ""
  90.     setcycle 27 frame_colour "Black"
  91.     setcycle 27 correct_cue_response ""
  92.     setcycle 28 frame_colour "Black"
  93.     setcycle 28 correct_cue_response ""
  94.     setcycle 29 frame_colour "Black"
  95.     setcycle 29 correct_cue_response ""
  96.     setcycle 30 frame_colour "Black"
  97.     setcycle 30 correct_cue_response ""
  98.     setcycle 31 frame_colour "Black"
  99.     setcycle 31 correct_cue_response ""
  100.     setcycle 32 frame_colour "Black"
  101.     setcycle 32 correct_cue_response ""
  102.     setcycle 33 frame_colour "Black"
  103.     setcycle 33 correct_cue_response ""
  104.     setcycle 34 frame_colour "Black"
  105.     setcycle 34 correct_cue_response ""
  106.     setcycle 35 frame_colour "Black"
  107.     setcycle 35 correct_cue_response ""
  108.     setcycle 36 frame_colour "Black"
  109.     setcycle 36 correct_cue_response ""
  110.     setcycle 37 frame_colour "Black"
  111.     setcycle 37 correct_cue_response ""
  112.     setcycle 38 frame_colour "Black"
  113.     setcycle 38 correct_cue_response ""
  114.     setcycle 39 frame_colour "Green"
  115.     setcycle 39 correct_cue_response "g"
  116.     setcycle 40 frame_colour "Black"
  117.     setcycle 40 correct_cue_response ""
  118.     setcycle 41 frame_colour "Black"
  119.     setcycle 41 correct_cue_response ""
  120.     setcycle 42 frame_colour "Black"
  121.     setcycle 42 correct_cue_response ""
  122.     setcycle 43 frame_colour "Black"
  123.     setcycle 43 correct_cue_response ""
  124.     setcycle 44 frame_colour "Black"
  125.     setcycle 44 correct_cue_response ""
  126.     setcycle 45 frame_colour "Black"
  127.     setcycle 45 correct_cue_response ""
  128.     setcycle 46 frame_colour "Black"
  129.     setcycle 46 correct_cue_response ""
  130.     setcycle 47 frame_colour "Black"
  131.     setcycle 47 correct_cue_response ""
  132.     setcycle 48 frame_colour "Black"
  133.     setcycle 48 correct_cue_response ""
  134.     setcycle 49 frame_colour "Black"
  135.     setcycle 49 correct_cue_response ""
  136.     run s1_trial_sequence
  137.  
  138. define inline_script s1_keyboard_response
  139.     set _run ""
  140.     ___prepare__
  141.     from openexp.keyboard import keyboard
  142.    
  143.     # The keypress timeout
  144.     timeout = 2000
  145.    
  146.     # We poll for two responses. The first 'keyboard_response_1'
  147.     # waits for a 'g'. The second waits for a 'z' or an 'm'. These
  148.     # responses can be given in arbitrary order, are stored in
  149.     # different variables, and can time out indendently of each
  150.     # other.
  151.     exp.set('keyboard_response_1', None)
  152.     exp.set('keyboard_response_time_1', None)
  153.     keylist_1 = ['g']
  154.     exp.set('keyboard_response_2', None)
  155.     exp.set('keyboard_response_time_2', None)
  156.     keylist_2 = ['z', 'm']
  157.    
  158.     # Create a keyboard object that doesn't block the
  159.     # experiment, so we can use it to poll for keypresses
  160.     # continuously.
  161.     my_keyboard = keyboard(exp, timeout=0)
  162.    
  163.     # Loop until we timeout
  164.     start_time = self.time()
  165.     while self.time() - timeout < start_time:
  166.         key, key_time = my_keyboard.get_key()
  167.    
  168.         # If a key from keylist 1 is pressed, set keyboard_response_1
  169.         # and keyboard_response_time_1. Also, set key_list_1 to [], so
  170.         # that we do not capture multiple keypresses from this list.
  171.         if key in keylist_1:
  172.             exp.set('keyboard_response_1', key)
  173.             exp.set('keyboard_response_time_1', key_time - start_time)
  174.             keylist_1 = []
  175.    
  176.         # The same principle is applied for keylist 2.
  177.         if key in keylist_2:
  178.             exp.set('keyboard_response_2', key)
  179.             exp.set('keyboard_response_time_2', key_time - start_time)
  180.             keylist_2 = []
  181.    
  182.     # Create a variable to check the response against the expected response:
  183.     if self.get('keyboard_response_2') == self.get('correct_ongoing_response'):
  184.         correct_2 = '1'
  185.     else:
  186.         correct_2 = '0'
  187.     exp.set("correct_2", correct_2)
  188.    
  189.     # Create a variable to check the response against the expected response:
  190.     if self.get('keyboard_response_1') == self.get('correct_cue_response'):
  191.         correct_1 = '1'
  192.     else:
  193.         correct_1 = '0'
  194.     exp.set("correct_1", correct_1)
  195.     __end__
  196.     set description "Executes Python code"
  197.  
  198. define loop s1
  199.     set repeat "1"
  200.     set description "Repeatedly runs another item"
  201.     set item "s1_sequence"
  202.     set column_order ""
  203.     set cycles "1"
  204.     set order "sequential"
  205.     run s1_sequence
  206.  
  207. define sequence s1_trial_sequence
  208.     set flush_keyboard "yes"
  209.     set description "Runs a number of items in sequence"
  210.     run ongoing_script "always"
  211.     run s1_trial_display "always"
  212.     run s1_response_script "always"
  213.     run s1_keyboard_response "always"
  214.     run logger "always"
  215.  
  216. define sketchpad s1_trial_display
  217.     set duration "2000"
  218.     set description "Displays stimuli"
  219.     draw textline -180 0 "[word1]" center=1 color=black font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always"
  220.     draw textline 180 0 "[word2]" center=1 color=black font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always"
  221.     draw rect -480 -160 960 320 fill=0 penwidth=3 color=[frame_colour] show_if="always"
  222.  
  223. define text_display end_s1
  224.     set foreground "#000000"
  225.     set font_size "20"
  226.     set description "Presents a display consisting of text"
  227.     set maxchar "200"
  228.     set align "center"
  229.     __content__
  230.     End of Session A.
  231.    
  232.     Press any key to continue.
  233.     __end__
  234.     set background "#ffffff"
  235.     set duration "keypress"
  236.     set font_family "sans"
  237.  
  238. define sequence experiment
  239.     set flush_keyboard "yes"
  240.     set description "Runs a number of items in sequence"
  241.     run read_tables "always"
  242.     run s1 "always"
  243.     run end_s1 "always"
  244.  
  245. define inline_script s1_response_script
  246.     set _run ""
  247.     ___prepare__
  248.     # For the ongoing task:
  249.    
  250.     # Determine correct ongoing response, depending on whether the words
  251.     # come from the rhyming or the non-rhyming list
  252.     if stim_pair in list_rhymes:
  253.         correct_keyboard_response_2 = 'm'
  254.     if stim_pair in list_non_rhymes:
  255.         correct_keyboard_response_2 = 'z'
  256.    
  257.     # Set the correct response for the ongoing task by giving the variable
  258.     # 'correct_ongoing_response' a value:
  259.     exp.set("correct_ongoing_response", correct_keyboard_response_2)
  260.    
  261.     # For the cues:
  262.    
  263.     # Determine correct response, depending on cues in session
  264.     if self.get('frame_colour') == 'Green':
  265.         correct_keyboard_response_1 = 'g'
  266.     if self.get('frame_colour') == 'Black':
  267.         correct_keyboard_response_1 = ''
  268.    
  269.     # Set the correct response by giving the variable 'correct_cue_response'
  270.     # a value: 
  271.     exp.set("correct_cue_response", correct_keyboard_response_1)
  272.     __end__
  273.     set description "Executes Python code"
  274.  
  275. define sequence s1_sequence
  276.     set flush_keyboard "yes"
  277.     set description "Runs a number of items in sequence"
  278.     run ongoing_task "always"
  279.     run s1_block_loop "always"
  280.  
  281. define inline_script ongoing_task
  282.     set _run ""
  283.     ___prepare__
  284.     # Randomise the from-the-csv-files-read lists
  285.     # and draw two samples containing the necessary numbers of rhymes and non-rhymes, respectively.
  286.    
  287.     # First, randomise the lists using the function random.shuffle() from
  288.     # the built-in Python module random:
  289.     # For more info, see:
  290.     # http://docs.python.org/2/library/random.html#random.shuffle
  291.     import random
  292.     random.shuffle(list_rhymes)
  293.     random.shuffle(list_non_rhymes)
  294.    
  295.     # Use the function random.sample() to obtain two lists containing the
  296.     # desired number of rhyme pairs and non-rhyme pairs.
  297.    
  298.     # The number of pairs per list is equal to half of the number of pairs in the
  299.     # original list (i.e. 20 rhyme pairs and 30 non-rhyme pairs).
  300.    
  301.     # For more info, see:
  302.     # http://docs.python.org/2/library/random.html#random.sample
  303.     samples_rhymes = random.sample(list_rhymes,len(list_rhymes)/2)
  304.     samples_non_rhymes = random.sample(list_non_rhymes, len(list_non_rhymes)/2)
  305.    
  306.     # The two lists are merged to create one block list:
  307.     block_list = samples_rhymes + samples_non_rhymes
  308.    
  309.     # The block list is then shuffled:
  310.     random.shuffle(block_list)
  311.    
  312.     # Block list made global for future use:
  313.     global block_list
  314.     __end__
  315.     set description "Executes Python code"
  316.  
  317. define logger logger
  318.     set ignore_missing "yes"
  319.     set description "Logs experimental data"
  320.     set auto_log "yes"
  321.     set use_quotes "yes"
  322.     log "count_s1_trial_sequence"
  323.     log "title"
  324.     log "count_s1_sequence"
  325.     log "frame_colour"
  326.     log "correct_cue_response"
  327.     log "count_experiment"
  328.     log "correct_ongoing_response"
  329.  
  330. define inline_script ongoing_script
  331.     set _run ""
  332.     ___prepare__
  333.     # Determine the word pair of the current trial by drawing one word pair
  334.     # from the previously defined block list.
  335.    
  336.     # To avoid repeat display of word pairs and non-display of others, draw
  337.     # pairs without replacement by using the built-in Python function pop() .
  338.     stim_pair = block_list.pop()
  339.     print stim_pair
  340.    
  341.     # The pair is separated by a comma (they come from a .csv file).
  342.     # Split them by using the built-in Python function split() :
  343.     word1, word2 = stim_pair.split(",")
  344.    
  345.     # To make the variables word1 and word2 available in the GUI (e.g. a
  346.     # sketchpad item), use the built-in OpenSesame function exp.set() :
  347.     exp.set("word1", word1)
  348.     exp.set("word2", word2)
  349.     # Now square bracket method can be used to display values
  350.     # of those two variables in the sketchpad item.
  351.     __end__
  352.     set description "Executes Python code"
  353.  
  354. define inline_script read_tables
  355.     set _run ""
  356.     ___prepare__
  357.     # Read the lists of the 40 rhyming pairs and the 60
  358.     # non-rhyming pairs from the two seperate .csv files.
  359.    
  360.     # Specify the paths to the files containing the pairs
  361.     # by using the built-in OpenSesame function exp.get_file.
  362.     # For more info, see:
  363.     #http://osdoc.cogsci.nl/python-inline-code/experiment-functions/#experiment.get_file
  364.     path_rhymes = exp.get_file("rhyming_pairs.csv")
  365.     path_non_rhymes = exp.get_file("non_rhyme_pairs.csv")
  366.    
  367.     # Use the built-in Python module numpy to read the .csv file:
  368.     # Import the module
  369.     import numpy as np
  370.    
  371.     # And load the text file.
  372.     #For more info, see:
  373.     #http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html
  374.     list_rhymes = np.loadtxt(path_rhymes, dtype = str)
  375.     list_non_rhymes = np.loadtxt(path_non_rhymes, dtype = str)
  376.    
  377.     # Make the two lists global for future use:
  378.     global list_rhymes, list_non_rhymes
  379.     __end__
  380.     set description "Executes Python code"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement