Advertisement
LeeB_86

s1_phono_pairs

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