Advertisement
Guest User

Form log issues - script

a guest
Jul 9th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.87 KB | None | 0 0
  1. # Generated by OpenSesame 2.8.2 (Gutsy Gibson)
  2. # Wed Jul 09 14:02:03 2014 (nt)
  3. # <http://www.cogsci.nl/opensesame>
  4.  
  5. set mouse_backend "legacy"
  6. set subject_parity "even"
  7. set height "1050"
  8. set font_family "mono"
  9. set font_italic "no"
  10. set synth_backend "legacy"
  11. set title "Face Conditioning"
  12. set coordinates "relative"
  13. set start "experiment"
  14. set sampler_backend "legacy"
  15. set transparent_variables "no"
  16. set foreground "#000000"
  17. set font_bold "no"
  18. set description "Default description"
  19. set background "#bfbfbf"
  20. set font_size "18"
  21. set keyboard_backend "legacy"
  22. set canvas_backend "legacy"
  23. set compensation "0"
  24. set bidi "no"
  25. set subject_nr "0"
  26. set width "1680"
  27.  
  28. define sketchpad Break_pad
  29.     set duration "keypress"
  30.     set description "Displays stimuli"
  31.     draw textline 0 -288 "You may now take a short break" center=1 color=#000000 font_family="mono" font_size=25 font_italic=no font_bold=no show_if="always" html="yes"
  32.     draw textline 0 0 "Press any key when you are ready to continue" center=1 color=#000000 font_family="mono" font_size=25 font_italic=no font_bold=no show_if="always" html="yes"
  33.  
  34. define text_display Capture_Intro
  35.     set foreground "#000000"
  36.     set font_size "18"
  37.     set description "Presents a display consisting of text"
  38.     set maxchar "90"
  39.     set align "center"
  40.     __content__
  41.    
  42.     Here begins the second part of the experiment
  43.    
  44.     Here, you will see a number of figures (ellipse and squares) containing lines with different orientations.
  45.    
  46.     At the begining of each trial you will see a cross in the middle of the screen. Please keep your eyes fixated on it.
  47.    
  48.     Your task will be to spot the green ellipse, and report the orientation of the line inside it.
  49.    
  50.     If the line is horizontal, press "z";
  51.    
  52.     If it is vertical, press "m".
  53.    
  54.     In this task both your speed and precision will be tested, so please try to respond as fast and accurately as possible.
  55.    
  56.     Note that there will be NO electric shocks during this phase of the experiment.
  57.    
  58.     You will begin with a few practice trials, during which you will receive feedback on your performance.
  59.     After the training phase, all incorrect answers will be signaled only by a tone.
  60.    
  61.     Press any key to begin
  62.     __end__
  63.     set background "#bfbfbf"
  64.     set duration "keypress"
  65.     set font_family "mono"
  66.  
  67. define inline_script Capture_Training
  68.     ___run__
  69.     # Show the stimuli display
  70.     self.fixd.show()
  71.     self.sleep(500)
  72.     self.c.show()
  73.     self.sleep(500)
  74.     #self.c.clear()
  75.     #self.c.show()
  76.     __end__
  77.     ___prepare__
  78.     import random
  79.     import math
  80.    
  81.     #Canvas format & initializing elements
  82.     exp.set("foreground", "#000000")
  83.     exp.set("background", "#7f7f7f")
  84.    
  85.     #Stimuli set definition
  86.     Stimuli = []
  87.     angle = 0
  88.     exp.Target_Switch = False
  89.    
  90.     #if self.get("condition") == 1:
  91.     #   Targets = ["G_Ellipse_H", "G_Ellipse_V"]
  92.     #   Nontargets = ["B_Ellipse_H", "B_Ellipse_V", "B_Ellipse_L", "B_Ellipse_R"]  
  93.     #else:
  94.     Targets = ["G_Ellipse_H", "G_Ellipse_V"]
  95.     Nontargets = ["G_Diamond_H", "G_Diamond_V", "G_Diamond_L", "G_Diamond_R"]
  96.    
  97.     #Add Target
  98.     Stimuli.append(random.choice(Targets))
  99.    
  100.     #Revise Target ensuring that same target is not repeated more than twice in a row
  101.    
  102.     if (len(exp.Train_Target_list) >= 2):
  103.             Last_Target = exp.Train_Target_list[-1]
  104.             SLast_Target = exp.Train_Target_list[-2]
  105.             Target = Stimuli[0]
  106.             if (Last_Target == SLast_Target):
  107.                 exp.Target_Switch = True
  108.             if (exp.Target_Switch == True):
  109.                 while (Last_Target == Target):
  110.                     Target = random.choice(Targets)
  111.                     del Stimuli[0]
  112.                     Stimuli.append(Target)
  113.    
  114.     exp.Train_Target_list.append(Stimuli[-1])
  115.    
  116.    
  117.     ##Add predefined distractor (Distractors not used in training sequence)
  118.     #if self.get("Distractor") == "Male_GS":
  119.     #   Stimuli.append("Dist_Male_GS")
  120.     #elif self.get("Distractor") == "Fem_GS":
  121.     #   Stimuli.append("Dist_Fem_GS")
  122.     #elif self.get("Distractor") == "Male_HSF":
  123.     #   Stimuli.append("Dist_Male_HSF")
  124.     #elif self.get("Distractor") == "Fem_HSF":
  125.     #   Stimuli.append("Dist_Fem_HSF")
  126.     #elif self.get("Distractor") == "Male_LSF":
  127.     #   Stimuli.append("Dist_Male_LSF")
  128.     #elif self.get("Distractor") == "Fem_LSF":
  129.     #   Stimuli.append("Dist_Fem_LSF")
  130.     #elif self.get("Distractor") == "No":
  131.     #   Stimuli.append((Nontarget))
  132.    
  133.     #Add non targets
  134.     while (len(Stimuli) < 8):
  135.         Stimuli.append(random.choice(Nontargets))
  136.    
  137.     #Randomize stimuli order in the list (Order defines position)
  138.     #Correct Target/distractor position so that they are never contiguous in display:
  139.     random.shuffle(Stimuli) #First stimuli randomization
  140.     ## Correction not needed in training
  141.     #if self.get("Distractor") != "No": #Corrects target/distractor position only if there is a distractor. Otherwise move on with first randomization
  142.     #   a = Stimuli.index(Target) #Get index of the Target in stimuli list
  143.     #   b = [s for s in Stimuli if "Dist" in s] #Find distractor (Returns a list)
  144.     #   b = ''.join(b) #Convert b from list to string
  145.     #   c = Stimuli.index(b) #Get index of distractor (b)
  146.     #   while (b == c+1) or (b == c-1) or (c == 0 and a == 7) or (a == 0 and c == 7):
  147.     #       random.shuffle(Stimuli)
  148.     #
  149.     ##Log distance between Target and distractor
  150.     #distance = (abs(a - c))
  151.     #exp.set("distance", distance)  
  152.    
  153.     #Set correct response (Horizontal - Z, Vertical - M)
  154.     if "G_Ellipse_H" in Stimuli:
  155.         self.experiment.set("Train_correct_ans","z")
  156.     else:
  157.         self.experiment.set("Train_correct_ans","m")
  158.    
  159.     #Prepare offline canvas
  160.    
  161.     #Create offline canvas
  162.     self.c = self.offline_canvas()
  163.     self.fixd = self.offline_canvas()
  164.     #Draw fixation dot
  165.     self.c.fixdot
  166.     self.fixd.fixdot()
  167.     #Fill stimuli in canvas
  168.     for i in Stimuli:
  169.         #Determine coordinates
  170.         x = self.get("width") / 2 + exp.Radius * math.cos(math.radians(angle))
  171.         y = self.get("height") / 2 + exp.Radius * math.sin(math.radians(angle))
  172.         #Draw image
  173.         self.c.image(exp.get_file(i + ".png"), True, x, y, exp.Stim_scale) # Draw the image on the canvas
  174.         #Move to next location
  175.         angle += exp.ang_sep #Confirm angle separation and radius for fitting screen resolution
  176.     __end__
  177.     set description "Executes Python code"
  178.  
  179. define inline_script Capture_Trial_Script
  180.     ___run__
  181.     # Show the stimuli display
  182.     self.fixd.show()
  183.     self.sleep(500)
  184.     self.c.show()
  185.     self.sleep(500)
  186.     #self.c.clear()
  187.     #self.c.show()
  188.     __end__
  189.     ___prepare__
  190.     import random
  191.     import math
  192.    
  193.     #Canvas format & initializing elements
  194.     exp.set("foreground", "#000000")
  195.     exp.set("background", "#7f7f7f")
  196.    
  197.     #Stimuli set definition
  198.     Stimuli = []
  199.     angle = 0
  200.    
  201.     #if self.get("condition") == 1:
  202.     #   Targets = ["G_Ellipse_H", "G_Ellipse_V"]
  203.     #   Nontargets = ["B_Ellipse_H", "B_Ellipse_V", "B_Ellipse_L", "B_Ellipse_R"]  
  204.     #else:
  205.     Targets = ["G_Ellipse_H", "G_Ellipse_V"]
  206.     Nontargets = ["G_Diamond_H", "G_Diamond_V", "G_Diamond_L", "G_Diamond_R"]
  207.    
  208.     #Add Target
  209.     Stimuli.append(random.choice(Targets))
  210.    
  211.    
  212.     #Review Target ensuring that same target is not repeated more than twice in a row
  213.    
  214.     if (len(exp.Capture_Target_list) >= 2):
  215.             Last_Target = exp.Capture_Target_list[-1]
  216.             SLast_Target = exp.Capture_Target_list[-2]
  217.             Target = Stimuli[0]
  218.             if (Last_Target == SLast_Target):
  219.                 exp.Target_Switch = True
  220.             if (exp.Target_Switch == True):
  221.                 while (Last_Target == Target):
  222.                     Target = random.choice(Targets)
  223.                     del Stimuli[0]
  224.                     Stimuli.append(Target)
  225.    
  226.     exp.Capture_Target_list.append(Stimuli[-1])
  227.    
  228.     #Add distractor at random location (Not contiguous to target)
  229.     #Function to add predefined distractors
  230.     if self.get("Distractor") == "Male_GS":
  231.         Stimuli.append("Dist_Male_GS")
  232.     elif self.get("Distractor") == "Fem_GS":
  233.         Stimuli.append("Dist_Fem_GS")
  234.     elif self.get("Distractor") == "Male_HSF":
  235.         Stimuli.append("Dist_Male_HSF")
  236.     elif self.get("Distractor") == "Fem_HSF":
  237.         Stimuli.append("Dist_Fem_HSF")
  238.     elif self.get("Distractor") == "Male_LSF":
  239.         Stimuli.append("Dist_Male_LSF")
  240.     elif self.get("Distractor") == "Fem_LSF":
  241.         Stimuli.append("Dist_Fem_LSF")
  242.     elif self.get("Distractor") == "No":
  243.         Stimuli.append(random.choice(Nontargets))
  244.    
  245.     #Add non targets
  246.     while (len(Stimuli) < 8):
  247.         Stimuli.append(random.choice(Nontargets))
  248.    
  249.     #Log distance between Target and distractor
  250.     a = Stimuli[0] #Get Target from Stimuli list
  251.     b = Stimuli[1] #Get Distractor from Stimuli list
  252.     #Correct Target/distractor position so that they are never contiguous in display:
  253.     random.shuffle(Stimuli) #First stimuli randomization
  254.     c = Stimuli.index(a) #Find Target in randomized list
  255.     d = Stimuli.index(b) #Find Distractor in randomized list
  256.     distance = (abs(c - d)) #Estimate absolute distance between Target and Distractor
  257.     exp.set("distance", distance) #Set distance as variable, and store calculated value
  258.    
  259.     #Ensure that Target and Distractor are not contiguous
  260.     while distance == 7 or distance == 1:
  261.         random.shuffle(Stimuli)
  262.         c = Stimuli.index(a) #Find Target in randomized list
  263.         d = Stimuli.index(b) #Find Distractor in randomized list
  264.         distance = (abs(c - d)) #Recalculate distance
  265.         exp.set("distance", distance) #Re-set distance
  266.    
  267.     #Set correct response (Horizontal - Z, Vertical - M)
  268.     if "G_Ellipse_H" in Stimuli:
  269.         self.experiment.set("Capture_correct_ans","z")
  270.     else:
  271.         self.experiment.set("Capture_correct_ans","m")
  272.    
  273.     #Prepare offline canvas
  274.    
  275.     #Create offline canvas
  276.     self.c = self.offline_canvas()
  277.     self.fixd = self.offline_canvas()
  278.     #Draw fixation dot
  279.     self.c.fixdot
  280.     self.fixd.fixdot()
  281.     #Fill stimuli in canvas
  282.     for i in Stimuli:
  283.         #Determine coordinates
  284.         x = self.get("width") / 2 + exp.Radius * math.cos(math.radians(angle))
  285.         y = self.get("height") / 2 + exp.Radius * math.sin(math.radians(angle))
  286.         #Draw image
  287.         self.c.image(exp.get_file(i + ".png"), True, x, y, exp.Stim_scale) # Draw the image on the canvas
  288.         #Move to next location
  289.         angle += exp.ang_sep #Confirm angle separation and radius for fitting screen resolution
  290.     __end__
  291.     set description "Executes Python code"
  292.  
  293. define loop Capture_loop
  294.     set repeat "1"
  295.     set description "Repeatedly runs another item"
  296.     set item "Capture_seq"
  297.     set break_if "never"
  298.     set column_order "Distractor"
  299.     set cycles "8"
  300.     set order "random"
  301.     setcycle 0 Distractor "Male_GS"
  302.     setcycle 1 Distractor "Male_HSF"
  303.     setcycle 2 Distractor "Male_LSF"
  304.     setcycle 3 Distractor "Fem_GS"
  305.     setcycle 4 Distractor "Fem_HSF"
  306.     setcycle 5 Distractor "Fem_LSF"
  307.     setcycle 6 Distractor "No"
  308.     setcycle 7 Distractor "No"
  309.     run Capture_seq
  310.  
  311. define loop Capture_loop_Training
  312.     set repeat "1"
  313.     set description "Repeatedly runs another item"
  314.     set item "Capture_seq_Training"
  315.     set break_if "never"
  316.     set column_order "Training"
  317.     set cycles "1"
  318.     set order "random"
  319.     setcycle 0 Training "y"
  320.     run Capture_seq_Training
  321.  
  322. define sequence Capture_seq
  323.     set flush_keyboard "yes"
  324.     set description "Runs a number of items in sequence"
  325.     run Fixation "always"
  326.     run FixDot "always"
  327.     run Capture_Trial_Script "always"
  328.     run keyboard_response_Capture "always"
  329.     run Incorrect_tone "[correct]=0"
  330.     run logger "always"
  331.     run Intertrial_pad "always"
  332.     run Break_pad "=self.get('count_Capture_Trial_Script') % 56 == 55"
  333.  
  334. define sequence Capture_seq_Training
  335.     run Fixation "always"
  336.     run FixDot "always"
  337.     run Capture_Training "always"
  338.     run keyboard_response_training "always"
  339.     run Incorrect_tone "[correct]=0"
  340.     run logger "always"
  341.     run Intertrial_pad "always"
  342.     run Correct_ans "[correct]=1"
  343.     run Incorrect_ans "[correct]=0"
  344.  
  345. define text_display Conditioning_Intro
  346.     set foreground "#000000"
  347.     set font_size "18"
  348.     set description "Presents a display consisting of text"
  349.     set maxchar "75"
  350.     set align "center"
  351.     __content__
  352.    
  353.     Here begins the first part of the experiment
  354.    
  355.     As indicated before, in this part you will presented with one of two photos, a man and a woman.
  356.    
  357.     Each trial begins with a fixation cross in the middle of the screen, followed by a picture. Trials follow each other automatically, so your only need to pay attention to the center of the screen throughout the experiment.
  358.    
  359.     Remember, one of these pictures (either the man or the woman) will be occassionally accompanied by an electric shock. The intensity of this shock will be the one defined in the shock callibration procedure that you just completed.
  360.    
  361.     Press any key to begin
  362.     __end__
  363.     set background "#bfbfbf"
  364.     set duration "keypress"
  365.     set font_family "mono"
  366.  
  367. define text_display Conditioning_end
  368.     set foreground "#000000"
  369.     set font_size "18"
  370.     set description "Presents a display consisting of text"
  371.     set maxchar "75"
  372.     set align "center"
  373.     __content__
  374.    
  375.     This is the end of the first phase of the experiment.
  376.    
  377.     From this moment on, no more shocks will be delivered.
  378.    
  379.     Press any key when you are ready to continue to continue.
  380.     __end__
  381.     set background "#bfbfbf"
  382.     set duration "keypress"
  383.     set font_family "mono"
  384.  
  385. define loop Conditioning_loop
  386.     set repeat "1"
  387.     set description "Repeatedly runs another item"
  388.     set skip "0"
  389.     set item "Conditioning_seq"
  390.     set break_if "never"
  391.     set column_order "CS;US"
  392.     set cycles "5"
  393.     set order "sequential"
  394.     setcycle 0 CS "CS_0"
  395.     setcycle 0 US "US_0"
  396.     setcycle 1 CS "CS_1"
  397.     setcycle 1 US "US_1"
  398.     setcycle 2 CS "CS_0"
  399.     setcycle 2 US "US_0"
  400.     setcycle 3 CS "CS_0"
  401.     setcycle 3 US "US_0"
  402.     setcycle 4 CS "CS_1"
  403.     setcycle 4 US "US_1"
  404.     run Conditioning_seq
  405.  
  406. define inline_script Conditioning_script
  407.     ___run__
  408.     #Show Conditioning canvas
  409.     self.cond.show()
  410.     self.sleep(exp.interval)
  411.    
  412.     #Send shock trigger via USB PORT (While image is still visible)
  413.     if exp.CS == "CS_1":  
  414.         if exp.US == "US_1":
  415.             try:
  416.                 exp.shock()
  417.                 exp.set("shock_del", 1)
  418.                 print "Shock delivered"
  419.             except:
  420.                 print "Failed to send trigger!"
  421.                 exp.set("shock_del", 0)
  422.                
  423.     self.sleep(4000-exp.interval)
  424.     #self.condmask.show() #Show image mask
  425.     #self.sleep(1500)
  426.     self.cond.clear()
  427.     self.cond.show()
  428.     __end__
  429.     ___prepare__
  430.     #Import serial port
  431.     import serial
  432.     try:
  433.         exp.serial_port = serial.Serial('COM4') #Confirm COM# port
  434.     except:
  435.         print 'The port couldnt be opened'
  436.    
  437.     #Prepare offline canvas
  438.     x = self.get("width") / 2
  439.     y = self.get("height") / 2
  440.     exp.set("foreground", "#000000")
  441.     exp.set("background", "#7f7f7f")
  442.     #Create offline canvases
  443.     self.condfixd = self.offline_canvas() #Fixation cross
  444.     self.cond = self.offline_canvas() #Stimuli display
  445.     #self.condmask = self.offline_canvas() #Stimuli mask
  446.     #Draw fixation dot and image mask
  447.     self.cond.fixdot()
  448.     self.condfixd.fixdot()
  449.     #self.condmask.image(exp.get_file("Face_Mask.png"), True, x, y, exp.Stim_scale)
  450.     #Draw image (Even - CS1 Male (Condition 1) and odd - CS1 Female (Condition 2)
  451.     if exp.condition == 1:
  452.         if exp.CS == "CS_1":
  453.             self.cond.image(exp.get_file("Dist_Male_GS.png"), True, x, y, exp.Stim_scale)
  454.         else:
  455.             self.cond.image(exp.get_file("Dist_Fem_GS.png"), True, x, y, exp.Stim_scale)
  456.     elif exp.condition == 2:
  457.         if exp.CS == "CS_1":
  458.             self.cond.image(exp.get_file("Dist_Fem_GS.png"), True, x, y, exp.Stim_scale)
  459.         else:
  460.             self.cond.image(exp.get_file("Dist_Male_GS.png"), True, x, y, exp.Stim_scale)
  461.     __end__
  462.     set description "Executes Python code"
  463.  
  464. define sequence Conditioning_seq
  465.     set flush_keyboard "yes"
  466.     set description "Runs a number of items in sequence"
  467.     run Fixation "always"
  468.     run FixDot "always"
  469.     run Conditioning_script "always"
  470.  
  471. define inline_script Contingency_Check
  472.     ___run__
  473.     #Import form widgets
  474.     from libopensesame import widgets
  475.    
  476.     #Create base form & needed variables
  477.     ContCheck_Form = widgets.form(self.experiment, cols=[1,1,1,1,1,1], rows=[1,1,1], margins=(100,100,100,100), spacing=25)
  478.     ContCheck_Title = widgets.label(ContCheck_Form, text="Which of the faces is more likely to predict a shock?")
  479.    
  480.     #Define buttons & Images
  481.     Male_pic = widgets.image(ContCheck_Form, path=exp.get_file("Dist_Male_GS.png"), adjust=True)
  482.     Fem_pic = widgets.image(ContCheck_Form, path=exp.get_file("Dist_Fem_GS.png"), adjust=True)
  483.     ContCheck_RatingScale = widgets.rating_scale(ContCheck_Form, nodes=['Male', 'No idea', 'Female'], var='Cont_Check', click_accepts=True)
  484.    
  485.     #Run questionnaire
  486.     ContCheck_Form.set_widget(ContCheck_Title, (1,0), colspan=4)
  487.     ContCheck_Form.set_widget(ContCheck_RatingScale, (1,1), colspan=4)
  488.     ContCheck_Form.set_widget(Male_pic, (1,2))
  489.     ContCheck_Form.set_widget(Fem_pic, (4,2))
  490.     ContCheck_Form._exec()
  491.     __end__
  492.     set _prepare ""
  493.     set description "Executes Python code"
  494.  
  495. define inline_script Contingency_Recheck
  496.     ___run__
  497.     #Import form widgets
  498.     from libopensesame import widgets
  499.    
  500.     #Create base form & needed variables
  501.     ContRecheck_Form = widgets.form(self.experiment, cols=[1,1,1,1,1,1], rows=[1,1,1,1], margins=(100,100,100,100), spacing=25)
  502.     ContRecheck_Title = widgets.label(ContRecheck_Form, text="Do you still remember which of the faces is more likely to predict a shock?")
  503.    
  504.     #Define buttons & Images
  505.     Male_pic = widgets.image(ContRecheck_Form, path=exp.get_file("Dist_Male_GS.png"), adjust=True)
  506.     Fem_pic = widgets.image(ContRecheck_Form, path=exp.get_file("Dist_Fem_GS.png"), adjust=True)
  507.     ContRecheck_RatingScale = widgets.rating_scale(ContRecheck_Form, nodes=['Male', 'No idea', 'Female'], var='Cont_Recheck', click_accepts=False)
  508.     nextbutton = widgets.button(ContRecheck_Form, text="Next")
  509.     #Run questionnaire
  510.    
  511.     ContRecheck_Form.set_widget(ContRecheck_Title, (1,0), colspan=4)
  512.     ContRecheck_Form.set_widget(ContRecheck_RatingScale, (1,1), colspan=4)
  513.     ContRecheck_Form.set_widget(Male_pic, (1,2))
  514.     ContRecheck_Form.set_widget(Fem_pic, (4,2))
  515.     ContRecheck_Form.set_widget(nextbutton, (4,3))
  516.     ContRecheck_Form._exec()
  517.     __end__
  518.     set _prepare ""
  519.     set description "Executes Python code"
  520.  
  521. define sketchpad Correct_ans
  522.     set duration "1000"
  523.     set description "Displays stimuli"
  524.     draw textline 0 0 "Correct!" center=1 color=#000000 font_family="mono" font_size=25 font_italic=no font_bold=no show_if="always" html="yes"
  525.  
  526. define text_display Experiment_end
  527.     set foreground "#000000"
  528.     set font_size "20"
  529.     set description "Presents a display consisting of text"
  530.     set maxchar "75"
  531.     set align "center"
  532.     __content__
  533.     This is the end of the experiment
  534.    
  535.     Thank you very much for your participation!
  536.    
  537.     Press any key to exit
  538.     __end__
  539.     set background "#bfbfbf"
  540.     set duration "keypress"
  541.     set font_family "mono"
  542.  
  543. define fixation_dot FixDot
  544.     set foreground "#000000"
  545.     set style "default"
  546.     set description "Presents a central fixation dot with a choice of various styles"
  547.     set y "0"
  548.     set background "#7f7f7f"
  549.     set duration "1500"
  550.     set x "0"
  551.     set penwidth "3"
  552.  
  553. define fixation_dot Fixation
  554.     set foreground "#000000"
  555.     set style "cross"
  556.     set description "Presents a central fixation dot with a choice of various styles"
  557.     set y "0"
  558.     set background "#7f7f7f"
  559.     set duration "1500"
  560.     set x "0"
  561.     set penwidth "5"
  562.  
  563. define inline_script Functions
  564.     set _run ""
  565.     ___prepare__
  566.     import random
  567.    
  568.     #Canvas format
  569.     exp.set("foreground", "#000000")
  570.     exp.set("background", "#7f7f7f")
  571.    
  572.     #Shocker preparation - USB port
  573.     #Define shock
  574.     def shock():
  575.         """
  576.         Send shock to shock unit over COM port
  577.         """
  578.         shock_trigger = chr(int("01000010", 2))
  579.         shock_stopper = chr(int("01000000", 2))
  580.         exp.serial_port.write(shock_trigger)
  581.         exp.serial_port.write(shock_stopper)
  582.        
  583.     exp.shock = shock
  584.    
  585.     #Definitions
  586.     exp.interval = random.randint(500,1500)
  587.     exp.shock_del = 0 #Log delivered shocks (1 for shock delivered, 0 for shock not delivered).
  588.     exp.Radius = 288 #Distance from the center in pixels (check screen resution)
  589.     exp.Stim_scale = 0.45 #Scale to draw image
  590.     exp.ang_sep = 45 #45 degrees separation between stimuli in display (6 item search display)
  591.     exp.Train_Target_list = [] # Lists all used Targets during training
  592.     exp.Capture_Target_list = [] # Lists all used Targets during capture
  593.    
  594.     #Experimental condition definition
  595.     if exp.subject_parity == "even":
  596.         exp.set("condition", 1)
  597.     else:
  598.         exp.set("condition",2)
  599.     __end__
  600.     set description "Executes Python code"
  601.  
  602. define sketchpad Incorrect_ans
  603.     set duration "1000"
  604.     set description "Displays stimuli"
  605.     draw textline 0 0 "Incorrect." center=1 color=#000000 font_family="mono" font_size=25 font_italic=no font_bold=no show_if="always" html="yes"
  606.  
  607. define synth Incorrect_tone
  608.     set description "A basic sound synthesizer"
  609.     set decay "5"
  610.     set attack "0"
  611.     set volume "1"
  612.     set length "100"
  613.     set duration "sound"
  614.     set freq "440"
  615.     set osc "sine"
  616.     set pan "0"
  617.  
  618. define sketchpad Intertrial_pad
  619.     set duration "1000"
  620.     set description "Displays stimuli"
  621.  
  622. define text_display Introduction
  623.     set foreground "#000000"
  624.     set font_size "18"
  625.     set description "Presents a display consisting of text"
  626.     set maxchar "75"
  627.     set align "center"
  628.     __content__
  629.     Welcome!
  630.    
  631.     With this experiment we want to investigate how emotions influence your performance on an attention task.
  632.    
  633.     The experiment has 2 parts:
  634.    
  635.     - In the first one, you will simply be presented with pictures of a man and a woman. One of this pictures will be occasionally accompanied by an electric shock.
  636.    
  637.     - The second phase consists of an attentional task. You will receive detailed instructions for this task shortly before it begins.
  638.    
  639.     When you are ready, press any key to continue
  640.     __end__
  641.     set background "#bfbfbf"
  642.     set duration "keypress"
  643.     set font_family "mono"
  644.  
  645. define text_display Training_end
  646.     set foreground "#000000"
  647.     set font_size "18"
  648.     set description "Presents a display consisting of text"
  649.     set maxchar "75"
  650.     set align "center"
  651.     __content__
  652.     This is the end of the training phase
  653.    
  654.     From now on, no visual feedback will be given about your responses. You will only hear a tone when your response is incorrect.
  655.    
  656.     There will be NO shocks during this phase either.
  657.    
  658.     Remember: Your task is to spot the green ellipse, and report the orientation of the line inside it.
  659.    
  660.     If the line is horizontal, press "z";
  661.    
  662.     If it is vertical, press "m".
  663.    
  664.     Press any key to begin
  665.     __end__
  666.     set background "#bfbfbf"
  667.     set duration "keypress"
  668.     set font_family "mono"
  669.  
  670. define sequence experiment
  671.     run Introduction "always"
  672.     run Functions "always"
  673.     run Conditioning_Intro "always"
  674.     run Conditioning_loop "always"
  675.     run Contingency_Check "always"
  676.     run Conditioning_end "always"
  677.     run logger "always"
  678.     run Capture_Intro "always"
  679.     run Capture_loop_Training "always"
  680.     run Training_end "always"
  681.     run Capture_loop "always"
  682.     run Contingency_Recheck "always"
  683.     run logger "always"
  684.     run Experiment_end "always"
  685.  
  686. define keyboard_response keyboard_response_Capture
  687.     set correct_response "[Capture_correct_ans]"
  688.     set allowed_responses "z;m"
  689.     set description "Collects keyboard responses"
  690.     set timeout "2000"
  691.     set flush "yes"
  692.  
  693. define keyboard_response keyboard_response_training
  694.     set correct_response "[Train_correct_ans]"
  695.     set allowed_responses "z;m"
  696.     set description "Collects keyboard responses"
  697.     set timeout "2000"
  698.     set flush "yes"
  699.  
  700. define logger logger
  701.     set ignore_missing "yes"
  702.     set description "Logs experimental data"
  703.     set auto_log "yes"
  704.     set use_quotes "yes"
  705.     log "time_Incorrect_ans"
  706.     log "count_Incorrect_ans"
  707.     log "duration"
  708.     log "subject_parity"
  709.     log "start"
  710.     log "subject_nr"
  711.     log "time_Intertrial_pad"
  712.     log "count_Intertrial_pad"
  713.     log "time_Capture_seq_Training"
  714.     log "count_Capture_seq_Training"
  715.     log "time_Capture_Trial_Script"
  716.     log "count_Capture_Trial_Script"
  717.     log "Capture_correct_ans"
  718.     log "distance"
  719.     log "time_Capture_loop_Training"
  720.     log "count_Capture_loop_Training"
  721.     log "Training"
  722.     log "time_keyboard_response_training"
  723.     log "count_keyboard_response_training"
  724.     log "response_keyboard_response_training"
  725.     log "response_time_keyboard_response_training"
  726.     log "correct"
  727.     log "correct_keyboard_response_training"
  728.     log "average_response_time"
  729.     log "avg_rt"
  730.     log "accuracy"
  731.     log "acc"
  732.     log "correct_response"
  733.     log "time_Contingency_Check"
  734.     log "count_Contingency_Check"
  735.     log "time_Capture_Training"
  736.     log "count_Capture_Training"
  737.     log "Train_correct_ans"
  738.     log "CS"
  739.     log "US"
  740.     log "time_Capture_loop"
  741.     log "count_Capture_loop"
  742.     log "Distractor"
  743.     log "time_Contingency_Recheck"
  744.     log "count_Contingency_Recheck"
  745.     log "time_Correct_ans"
  746.     log "count_Correct_ans"
  747.     log "time_keyboard_response_Capture"
  748.     log "count_keyboard_response_Capture"
  749.     log "response_keyboard_response_Capture"
  750.     log "response_time_keyboard_response_Capture"
  751.     log "correct_keyboard_response_Capture"
  752.     log "shock_del"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement