linspace(): Create an array of linearly spaced values. By default angles are in radians, if you want the cosine of an angle specified in degrees use cos(angle*180/pi), or use numpy’s conversion functions, rad2deg(angle) and deg2rad(angle). sin(), cos(), tan(), and pi: For geometry and trig.random(), randint(), normal(), shuffle() options for creating arrays of random numbers.The syntax to use within a Code Component is always regular python syntax. The syntax there is slightly different (requiring a $ to trigger the special handling, or \$ to avoid triggering special handling). It is also possible to put code into a non-code input field (such as the duration or text of a Text Component). Note that this page is concerned with Code Components specifically, and not all cases in which you might use python syntax within the Builder. To see what other variables you might want to use, and also what terms you need to avoid in your chunks of code, compile your script before inserting the code object and take a look at the contents of that script. So if you have a Routine called trial, there will be a Clock called trialClock and so you can get the time (in sec) from the beginning of the trial by using:: currentT = trialClock.getTime() For example, all routines have a stopwatch-style Clock associated with them, which gets reset at the beginning of that repeat of the routine. Within your code you can use other variables and modules from the script. You can move Components up and down the Routine by right-clicking on their icons. You may want the code not to take effect until next frame however, in which case put it at the bottom of the Routine. If you want your Code Component to alter a variable to be used by another component immediately, then it needs to be above that component in the view. See code uses below.īe aware that the code for each of the components in your Routine are executed in the order they appear on the Routine display (from top to bottom). writing code to interact with the serial/parallel ports). This might be create a variable that you want for another Component, to manipulate images before displaying them, to interact with hardware for which there isn’t yet a pre-packaged component in PsychoPy (e.g. Run the example in the terminal with the following command: python psychopy_stimulus_example.The Code Component can be used to insert short pieces of python code into your experiments. # Show the window (it should be empty, but we need it to record keyboard events) Copy-paste the following text and save it as “psychopy_keyboard_example.py”: # Import modules Now we will run a simple keyboard example script. Then use the terminal to run the file with a command: python psychopy_stimulus_example.py # Show the window after drawing the stimulus Message = visual.TextStim(window, text='Stimulus!') # Refresh/update the window (with the fixation point drawn on) # Prepare a fixation point (we will draw it in the next step)įixation = visual.TextStim(window, text='+') Open some text editor, e.g., Gedit (on Ubuntu), paste and save the following text to a filename named, e.g.: “psychopy_stimulus_example.py”: # Import modules Windows is generally not Python friendly, and installing all dependencies and virtual environments can be harder for a beginner even than installing a dual-boot Linux or just getting some old PC and installing Lubuntu there. I don’t recommend beginners using PsychoPy on Windows. Install PsychoPy: sudo pip install psychopy Open a terminal ( 5 Ways to Open a Terminal Console Window Using Ubuntu). Hence, I prepared this basic example featuring: However, it seems that entry-level examples one can find in the web are rather sophisticated. PsychoPy is an excellent tool for preparing psychological experiments in Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |