Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to: Python and OpenSesame THE BASICS.

Similar presentations


Presentation on theme: "Introduction to: Python and OpenSesame THE BASICS."— Presentation transcript:

1 Introduction to: Python and OpenSesame THE BASICS

2 OpenSesame OpenSesame is an open-source experiment building platform. It is totally free. It has Python in-line integration which enables complex experimental designs. Intro to: Python and OpenSesame2

3 Looks and Feels Intro to: Python and OpenSesame3 Objects Experiment Sequence Overview Working Window

4 Our Experiment Intro to: Python and OpenSesame4 We will create two versions of the Posner’s cuing paradigm. 1.Exogenous cue 2.Endogenous cue

5 Our Experiment – Exogenous Version Intro to: Python and OpenSesame5

6 Our Experiment – Endogenous Version Intro to: Python and OpenSesame6

7 Our Experiment Intro to: Python and OpenSesame7 We manipulate these factors: 1.Side of the cue (left / right) 2.Side of the target (left / right) 3.Stimulus onset asynchrony (200, 400, 600, 800 ms). We will start with the exogenous cue

8 Outline of an experiment Intro to: Python and OpenSesame8 Instruction message Practice Start of experiment message Experiment (x blocks) End of experiment message

9 Structure of the experiment Intro to: Python and OpenSesame9 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

10 Intro to: Python and OpenSesame10 Create a new experiment let’s create a new experiment We will use the default template

11 Intro to: Python and OpenSesame11 General Properties Here we define the general properties of our experiment, For example the back-end, resolution, fonts and colors Under the hood

12 Intro to: Python and OpenSesame12 General Properties We can check under the hood of every object in the experiment and change its properties with script changes. These are not Python scripts, but they are pretty straight-forward and easily manipulated

13 Sequence Intro to: Python and OpenSesame13 An object that holds other objects in order (you can add conditions for objects). As its name implies, it is launching the objects in a sequence. Our whole experiment is created inside a sequence called experiment

14 Sequence Intro to: Python and OpenSesame14 Let’s start filling the experiment sequence with the most important thing in the experiment, the instructions

15 Built-In Objects Intro to: Python and OpenSesame15 OpenSesame has plenty of objects for many specific needs. We will use the commonly used ones for this class.

16 Sketchpad – Where the magic happens Intro to: Python and OpenSesame16 Tools: like writing, drawing lines and dots, presenting images Canvas – An object which holds what you see on the screen Extra options

17 Sketchpad – Introduction message Intro to: Python and OpenSesame17 Change name Use a text tool to write instructions

18 Structure of the experiment Intro to: Python and OpenSesame18 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

19 Do it yourself - Intro to: Python and OpenSesame19 Use sketchpad objects to create: 1.Begin experiment message. 2.End of experiment message. Make sure that their duration is until keypress

20 Structure of the experiment Intro to: Python and OpenSesame20 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

21 Looping – Experiment loop Intro to: Python and OpenSesame21 We will use a loop object to loop over the block sequence for the amount of blocks needed in our experiment. *[ block = a collection of trials ]

22 Experiment loop Intro to: Python and OpenSesame22 Change name Create variables

23 Experiment loop Intro to: Python and OpenSesame23 We will have 3 experimental blocks (which are exactly the same) We will have two variables, block and practice. Note that the blocks should be sequential and not random

24 Block Sequence Intro to: Python and OpenSesame24 We need a block_sequence. We can drag a sequence object from the menu and place it on the exp_loop. We tell OpenSesame to set the sequence as an item to run for exp_loop

25 Structure of the experiment Intro to: Python and OpenSesame25 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

26 Inside Block Sequence Intro to: Python and OpenSesame26 block_Sequence should have a trial_loop inside as well as a break message.

27 Structure of the experiment Intro to: Python and OpenSesame27 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

28 Trial loop is looping over a trial sequence Intro to: Python and OpenSesame28 We will leave the trial_loop information for now Let’s build trial_sequence

29 Structure of the experiment Intro to: Python and OpenSesame29 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

30 Fixation Point Intro to: Python and OpenSesame30 We can use the rectangle tool and line tool to draw these stimuli Set the duration to 400 (ms) Not good enough.. Some fine tuning are needed.. Let’s check under the hood

31 Under the hood - Sketchpad Intro to: Python and OpenSesame31 Do it yourself – Change the fixation cross size to be a little bit smaller and broader

32 Fixation Intro to: Python and OpenSesame32 Much better!

33 Structure of the experiment Intro to: Python and OpenSesame33 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Feedback? Logging Trial Loop Break SOA

34 Cue Intro to: Python and OpenSesame34 We can easily copy the script from fixation sketchpad to the cue sketchpad to keep the same design We want either the left or right squares to highlight depending on the condition

35 Cue Intro to: Python and OpenSesame35 We can use the show if conditions (just like in Python ifs!) to tell OpenSesame when to highlight which square Putting a variable name in squared brackets is OpenSesame’s way of using variables. So [cue] is a variable (not yet defined) which represents the side of the cue (can be right / left) We can also see this information in the script (under the hood)

36 Structure of the experiment Intro to: Python and OpenSesame36 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

37 Intro to: Python and OpenSesame37 The SOA sketchpad is pretty similar to the fixation sketchpad with a small difference, we can create an unlinked copy of fixation (right-click) and change what we need.

38 SOA Intro to: Python and OpenSesame38 We need the duration of SOA to vary according to an experiment variable.. We’ll call the variable [SOA].

39 Structure of the experiment Intro to: Python and OpenSesame39 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

40 Target Intro to: Python and OpenSesame40 Use the fixdot tool in the target sketchpad to draw a target in each of the squares. Use the show if condition to select when to present it (name the variable [target])

41 Target Intro to: Python and OpenSesame41 Also, set the duration to be 0 This is the opensesame way of making the duration of presentation controlled by the keyboard response

42 Our Experiment so far; Intro to: Python and OpenSesame42 We’re getting there! This is what you all should see in your programs

43 Structure of the experiment Intro to: Python and OpenSesame43 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

44 Keyboard response Intro to: Python and OpenSesame44 Define the correct response Define the allowed responses (separated by ;) Timeout (how long to listen to the keyboard) Flush – discard any previous keyboard presses

45 Keyboard response Intro to: Python and OpenSesame45 The variable [correct_response] is in charge of the correct response in a trial and its already linked to the keyboard object. We set it elsewhere (where all the variables are set). We want the participant to press: ‘q’ if the target is in the left square ‘p’ if the target is in the right square We give the participant 2 seconds to respond.

46 Structure of the experiment Intro to: Python and OpenSesame46 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

47 Logger tool Intro to: Python and OpenSesame47 Decides which variables to save at every trial For now we will let it save all the variables for us.

48 Structure of the experiment Intro to: Python and OpenSesame48 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

49 Looping – Trial Loop Intro to: Python and OpenSesame49 Now that we have the trial_sequence out of the way.. Let’s define the trial_loop that represent all the variables we used in the sequence. 1.[cue] 2.[target] 3.[SOA] 4.[correct_response]

50 trial_loop Intro to: Python and OpenSesame50 We will use the variable wizard to define most of the variables

51 Loop Variable Wizard Intro to: Python and OpenSesame51 The first row represents the variable names. The rest of the rows represent the categories of the variables

52 Loop Variable Wizard Intro to: Python and OpenSesame52 The wizard will create all the combination of these three variables for us. 2*2*4 = 16 combinations

53 trial_loop Intro to: Python and OpenSesame53 We still have to set the [correct_response] variable to be ‘p’ when the target is to the right and ‘q’ when it is left. Sounds like an if statement.. I wish we had Python to do that automatically..

54 trial_loop Intro to: Python and OpenSesame54

55 trial_loop Intro to: Python and OpenSesame55 We can set a loop for 4 times in a block And randomly

56 Structure of the experiment Intro to: Python and OpenSesame56 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

57 Status Intro to: Python and OpenSesame57 The experiment is almost done! We need to make sure the participant understands the instructions and so a practice block is required. Append a new loop after the instructions and call it prac_loop

58 Practice vs. Experiment Intro to: Python and OpenSesame58 The practice and experiment sequences are pretty much similar. There are some differences: 1.The practice block should have only 1 block 2.A practice block should have only 8 trials and not 64. 3.We need breaks in the experiment blocks but not the practice blocks. We should re-use objects as much as we can to avoid bugs and having to change multiple places.

59 Prac_loop Intro to: Python and OpenSesame59 Like exp_loop, prac_loop should have two variables, block and practice. And we tell prac_loop to iterate on block_sequence (our pre-defined sequence). This creates a linked copy of block_sequence in prac_loop

60 Practice vs. Experiment Intro to: Python and OpenSesame60 1.The practice block should have only 1 block 2.A practice block should have only 8 trials and not 64. 3.We need breaks in the experiment blocks but not the practice blocks.

61 Practice vs. Experiment Intro to: Python and OpenSesame61 So how would we create the other two differences between the sequences?

62 Breaks! Intro to: Python and OpenSesame62 Inside block_sequence, We can tell OpenSesame to run the break sketchpad only if the [practice] variable is set to no (i.e, in the exp_loop)

63 Practice vs. Experiment Intro to: Python and OpenSesame63 1.The practice block should have only 1 block 2.A practice block should have only 8 trials and not 64. 3.We need breaks in the experiment blocks but not the practice blocks.

64 Practice vs. Experiment Intro to: Python and OpenSesame64 We notice that an experiment block has: 64 trials (4 repeats of 16 trials). The practice block should have: 8 trials, or 0.5 repeats of 16 trials. We can create a variable to define our repeats.

65 Repeating trials Intro to: Python and OpenSesame65 We create a new variable in both exp_loop and prac_loop called repeat_block We set it to 0.5 in the prac_loop and 4 in the exp_loop

66 Trial_loop Intro to: Python and OpenSesame66 Next, in the trial_loop, we tell the repeat command to take input from the [repeat_block] variable!

67 Practice vs. Experiment Intro to: Python and OpenSesame67 1.The practice block should have only 1 block 2.A practice block should have only 8 trials and not 64. 3.We need breaks in the experiment blocks but not the practice blocks.

68 Structure of the experiment Intro to: Python and OpenSesame68 General Properties (Posner’s Cuing Paradigm) Experiment Sequence Instructions (txt)Practice Loop Start Experiment (txt) Experiment Loop End (txt) Block Sequence Trial Sequence FixationCue Target Appearance Keyboard Response Logging Trial Loop Break SOA

69 Time for a test drive! Intro to: Python and OpenSesame69 Save the experiment and run it using this key: Seems to run pretty too fast and the target doesn’t disappear after you press the keyboard.. We better add another sketchpad at the beginning of trial_sequence. Call it blank and set the duration for 1000 ms.

70 Log file Intro to: Python and OpenSesame70 OpenSesame saves the experiment log in.csv files (comma separated values). These can be easily opened with Microsoft Excel But they are pretty big if we ask OpenSesame to save all the variables from the experiment.

71 OpenSesame Logging Intro to: Python and OpenSesame71 We can tell opensesame which variables are important to us in the logger tool. [Although, I recommend logging everything in the beginning until you know what are the relevant variables, better to work harder on pre- processing than re-running the experiment]

72 Log file Intro to: Python and OpenSesame72 We can scroll and choose manually… Or use the script to log the variables we are interested in

73 OpenSesame Experiment Files Intro to: Python and OpenSesame73 When saving an opensesame project, we can save it in a couple of ways: Re-save our experiment in an OpenSesame files type and call it PosnersCueingParadigm_endo Just the experiment The experiment with the files (e.g., pictures)

74 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame74 To create the endogenous cue version of the task, we’ll need arrow stimuli. One easy one of getting these pictures is from PowerPoint. Create a white arrow and save it as a.png file.

75 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame75 We should create two arrows left.png right.png We’ll add these two files to the experiment’s file pool Make sure these arrows are pretty small

76 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame76 To alter our experiment, we just need some minor modifications to the cue sketchpad.

77 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame77 First, we remove the highlighted squares and fixation cross (use the sketchpad script)

78 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame78 Next, place one of the arrows in the middle Use the draw image element

79 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame79 We want a left arrow to appear when [cue] is left and a right arrow when [cue] is right…

80 Posner’s Cueing paradigm – endogenous cue Intro to: Python and OpenSesame80

81 Testing our work Intro to: Python and OpenSesame81 We are done! Let’s test our work


Download ppt "Introduction to: Python and OpenSesame THE BASICS."

Similar presentations


Ads by Google