Introduction to: Python and OpenSesame FOR PROS. OpenSesame In OpenSesame you can add Python in-line codes which enables complex experiment. We will go.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

SCRATCH Lesson Two – Interactive Concepts Using Sensing, Operators, and Variables.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Right-click on the colored box and remove it.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Information Technology Center Hany Abdelwahab Computer Specialist.
2. Run. Hours button 1. Run. Hours screen Running hours.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Conversational Computers
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Lab 1: The Stroop Effect (1935) Measuring interference effects
Chapter Introduction to Computers and Programming 1.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
VBA session 3 Paul Rubinov  My job: diverse audience so Bore you for 15 minutes. Confuse you for the other 15 min.  Feel free to contact me
Introduction to Python
Chapter 1: Introduction to Computers and Programming.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
General Programming Introduction to Computing Science and Programming I.
Peter Andreae Python for Level 3 CS4HS see website: ecs.vuw.ac.nz/Main/PythonForSchools.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to: Python and OpenSesame Part I. Python A high-level programming language It can do a lot of things We will use python in this course in.
Move the mouse to the IE icon on the Quick Launch Bar and click to cut a small picture. This small picture is for locating the position of IE Quick Launch.
Building the experiment in PsychoPy
Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved.
Using Visual Basic for Applications in Microsoft Project Sean Vogel.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
The desktop (overview) Working with desktop icons The desktop is the main screen area that you see after you turn on your computer and log on to Windows.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Speedway Schools. A computer has many parts that make it work. Some of those parts we can see. Others are hidden inside where we can't see them. In this.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Introduction to: Python and OpenSesame THE BASICS.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Lab 2: Sternberg (1966) How we search our memory
BASIC PROGRAMMING C SCP1103 (02)
Development Environment
MOM! Phineas and Ferb are … Aims:
Introduction to Programming
PYGAME.
BASIC PROGRAMMING C SCP1103 (02)
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
Microsoft Office Illustrated
File IO and Strings CIS 40 – Introduction to Programming in Python
Loops CIS 40 – Introduction to Programming in Python
I210 review.
Python programming exercise
Introduction to Python
Starter Which of these inventions is: Used most by people in Britain
Presentation transcript:

Introduction to: Python and OpenSesame FOR PROS

OpenSesame In OpenSesame you can add Python in-line codes which enables complex experiment. We will go over a few examples of tasks that require coding. In this session, you should work with me on the examples (work on the _blank files) Intro to: Python and OpenSesame2

OpenSesame Opensesame has a debugger window, which is actually a Python Shell! Open the debugger and Python around! Hint: We can use print statements to the debugger to see if the code we wrote is good Intro to: Python and OpenSesame3

OpenSesame + Python Interacting with OpenSesame with the Python in-lines is through objects. [Recall: Turtle!] For that we need to: 1.Import the modules relevant for the objects we need 2.Create instances 3.Use their methods Intro to: Python and OpenSesame4 Import turtle yoni = turtle.Turtle() yoni.forward(100)

In-Line Object To be able to write Python code, you need to add a Python in-line object to the sequence. You can add multiple Python in-lines to a task, but they act as one large script (so a variable defined in one is available in the other). Intro to: Python and OpenSesame5

In-Line Object You can append the in-line object in different places in the experiment. For example, in the start of the experiment to initialize some variables. Or during a trial loop to alter variables after a trial. Intro to: Python and OpenSesame6

OpenSesame + Python This link has all the objects that OpenSesame has and how to interact with them. Intro to: Python and OpenSesame7

In-line Variables First thing we need to learn is how to interact with OpenSesame Variables. That is to get the value of a variable And set the value of a variable Intro to: Python and OpenSesame8

Example #0 – working with inlines Open a new experiment in OpenSesame and drag an inline object to the experiment sequence. We can get access OpenSesame experiment variables with the self.get(“var”) method. the input is a string with the name of the opensesame variable Intro to: Python and OpenSesame9 The self object is actually the in-line script object. The get method makes experiment variables available to it.

Example #0 – working with inlines To know which variables are available in OpenSesame, we can check the Variable inspector. Do it yourself: Set a python variable num to be the subject number (an experiment variable). Print it to the debugger Intro to: Python and OpenSesame10 self.get(‘variable’)

Example #0 – working with inlines To use variables we defined in the in-line script outside the in-line script, we need to set them as OpenSesame experiment variables. We can use the exp.set(“var”,value) method. The input is a string with the name of the variable and a value Intro to: Python and OpenSesame11 Exp is the experiment object and the set method sets the variable to some value. You can create a new variable / update an existing variable

Example #0 – working with inlines Do it yourself: Set an experiment variable msg to be the message: Welcome subject number : (use the subject number) Intro to: Python and OpenSesame12 exp.set(‘var’,value)

Example #0 – working with inlines Using variables that were set in inline code: 1.Create a sketchpad object after the python inline object. 2.Print the message in the experiment variable msg with the sketchpad Intro to: Python and OpenSesame13

Prepare / Run Opensesame has two phases: Prepare – runs first, before running a sequence Run – runs only when called Intro to: Python and OpenSesame14 This is true for every object, as well as the sketchpad object. The prepare phase of the sketchpad object couldn’t recognize the msg variable because it wasn’t there yet.. We should create our variable in the prepare phase of the inline script

Example #1: Updating during Exp For our first [real] example we will create the stop-signal task. In this task participants are presented with two types of stimuli and they need to make a speeded discrimination. On 25% of the trials, a beep appears after the presentation of a stimuli and the participant needs to withhold their response. Intro to: Python and OpenSesame15

Example #1: Updating during Exp If the participant succeeded in avoiding a response, the SSD [Stop-Signal Delay] is increased, so that the time between the appearance of the stimuli and the stop-signal is longer (harder to stop) If the participant responded, the SSD is decreased, so that the time between the appearance of the stimuli and the stop-signal is shorter (easier to stop) Intro to: Python and OpenSesame16

Example #1: Updating during Exp We need a way to control the change in the SSD during the task. For that we need some in-line scripting. Open the stop-signal task Intro to: Python and OpenSesame17

Example #1: Updating during Exp 1.First, we need to define our SSD variable as an experiment variable [set it to 200ms]. 2.Make sure that the experiment uses our SSD variable. 3.We need to update SSD to: – +20 if the subject didn’t respond – -20 if the subject did respond Intro to: Python and OpenSesame18

1. Define SSD Create a new inline object in the head of the experiment. Set a new experiment variable called SSD and set it to 200. Intro to: Python and OpenSesame19

2. Setup the experiment (key idea) Intro to: Python and OpenSesame20 Target appears Stop Signal SSD Keyboard Response Keyboard Response Duration

2. Setup the experiment We will use SSD as the duration for the key1 keyboard response object (the response after presentation of the stimuli and before the beep. We want to make sure that we get 2000ms of response time available, so we should set the timing of key2 to be 2000-SSD Intro to: Python and OpenSesame21

3. Update SSD – Key Ideas We want to update SSD according to the response after the beep (yes / no). But what happens if the subject pressed before the beep? Do we update? What if the participant doesn’t press anything? Can SSD get to below zero? Intro to: Python and OpenSesame22

Update SSD Add a new in-line script object after the key2 response. Create the conditions needed to update SSD according to the task rules. Intro to: Python and OpenSesame23 Note: Keyboard response objects create an experiment variable that stores the response. It stores “None” if no key was pressed…

Test Drive Run the experiment Intro to: Python and OpenSesame24

Example #2: Drawing Objects We will learn how to draw objects on the screen with this next example. In the visual search task a few objects appear on the screen and the participant needs to say if a target object is present. Intro to: Python and OpenSesame25

Intro to: Python and OpenSesame26

Example #2: Key Idea Intro to: Python and OpenSesame27 (x_cent,y_cent)

Example #2: Drawing Objects We need a way to draw shapes randomly on the screen. For that we need some in-line scripting. Open the visual_search task Intro to: Python and OpenSesame28

Canvas object In order to present things on the screen, we need access to the canvas object. We can import it: from openexp.canvas import canvas Intro to: Python and OpenSesame29 Note: Opensesame doesn’t follow the Python convention of writing objects with a first capital letter.

Using Canvas 1.Create an instance of canvas (my_canvas) 2.Draw things on it (with methods) 3.Show it on the screen (the show() method) Intro to: Python and OpenSesame30

Inline script - Overview 1.Import the libraries we need 2.Get and set the relevant variables and instances 3.Plot stimuli on the screen 4.Show screen Intro to: Python and OpenSesame31

1. importing We need two modules – 1.Canvas (from openexp.canvas import canvas) 2.random Intro to: Python and OpenSesame32

2. Get/Set relevant variables We need: 1.Access to the num_items and target experiment variables. – Get from the experiment loop 2.A canvas instance (my_canvas) – my_canvas = canvas(exp) 3.Set variables with the center coordinates – Canvas methods xcenter() and ycenter() Intro to: Python and OpenSesame33

3. Plot Stimuli We need to: 1.Randomly place (num_items – 1) distractors 2.Randomly place a target stimulus or another distractor (depending on the target [yes/no] value) Intro to: Python and OpenSesame34 We will use circles as the stimuli: Distractors are red Target is green Syntax: my_canvas.circle(x, y, radius, fill=[True/False], color=‘’”)

Test Drive Run the experiment Intro to: Python and OpenSesame35

Visual Search Versions The task has two versions: Easy(pop-out) – the distractors are in the same shape and color, the target has a different color Hard(Feature conjunction) – the distractors have varying shapes and colors, the target stimulus is a unique combination of shape and color. Intro to: Python and OpenSesame36 Home exercise – try to create the hard version

Example #3: Control We will learn how to use input devices to control changes in the experiment. We will create a basic sensitivity learning task. a participant sees a reference stimulus and needs to set the size of another target stimulus to be as close as possible to the reference. Intro to: Python and OpenSesame37

Example #3: Key Idea Intro to: Python and OpenSesame38 Reference Stimulus Target Stimulus “pressed” You are off by: 10%

Inline script - Overview 1.Import the libraries we need 2.Get and set the relevant variables and instances 3.Present the starting position 4.Wait for mouse response 5.Increase target size while button is pressed 6.Calculate size difference 7.present feedback Intro to: Python and OpenSesame39

1. Importing We will use modules for: 1.A canvas object to draw stuff on the screen – from openexp.canvas import canvas 2.A mouse object to control the size – from openexp.mouse import mouse Intro to: Python and OpenSesame40

2. Get/Set relevant variables We need: 1.A canvas instance – my_canvas = canvas(exp) 2.A mouse instance (with timeout of 2 seconds) – my_mouse = mouse(exp,timeout = 2000) 3.x,y coordinates of the center of the screen – Canvas methods xcenter() and ycenter() 4.The size of the reference stimulus – Get from the experiment loop 5.A baseline size 6.A scalar value Intro to: Python and OpenSesame41

3. Presenting the starting position We need to: 1.Draw the reference stimulus (with given size) – Canvas method circle() 2.Draw the target stimulus (at baseline size) – Canvas methods circle() 3. Show the canvas – Canvas method show() Intro to: Python and OpenSesame42

3. Wait for mouse response We need to: 1.Wait for a mouse click response for a maximum duration of 2 seconds. Intro to: Python and OpenSesame43 button, position, timestamp = my_mouse.get_click() Returns three variables, the buttons pressed, the position on the screen and the time the click happened

5. Increase target size While the mouse button is pressed: 1.clear the canvas (helps reduce memory consumption) – Canvas method clear() 2.Increase target size by scaler 3.Re-draw the reference and target (new size) stimuli 4.Show canvas 5.Re-check if button is still pressed Intro to: Python and OpenSesame44 buttons = my_mouse.get_pressed() Returns a tuple with the state [True/False] of all three mouse buttons in the form of (0, 0, 0)

6. Calculate size difference After the button is no longer pressed: 1.Calculate the ratio between the target size and the reference size. – If the target is size 150 and the reference is 100, you should get a size_diff of +50% 2.Create a string to present as feedback: – you are off by : x % 3.Save the size difference as an experiment variable Intro to: Python and OpenSesame45

7. Present Feedback 1.Draw the final size of the two stimuli 2.Present the text string – Canvas method text() 3.Show canvas 4.Pause for 1 second – Inline method sleep(ms) Intro to: Python and OpenSesame46

Test Drive Run the experiment Intro to: Python and OpenSesame47

Course Summary For the last month we studied a bit of the Python programming language and the OpenSesame experiment building platform. Hopefully you have seen how with few lines of code you can create complex and interesting experiments. Intro to: Python and OpenSesame48

Course Summary What to do next? Analyzing Results with Excel Intro to: Python and OpenSesame49

Course Summary As always, I encourage you to take what you’ve learned here to the next level: Study more of Python Build crazy and complex experiments with code Intro to: Python and OpenSesame50