psychopy | For running psychology and neuroscience experiments | Machine Learning library
kandi X-RAY | psychopy Summary
kandi X-RAY | psychopy Summary
PsychoPy is an open-source package for creating experiments in behavioral science. It aims to provide a single package that is:. To meet these goals PsychoPy provides a choice of interface - you can use a simple graphical user interface called Builder, or write your experiments in Python code. The entire application and library are written in Python and is platform independent.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Layout the text .
- Make the menu
- Runs the program diagnostics .
- Imports conditions from file .
- Write iohub code to file .
- Save an event report .
- Load plugin .
- Launch Hub server .
- Create a texture .
- Load a file into memory .
psychopy Key Features
psychopy Examples and Code Snippets
from py_client import PythonMHC
makehuman = PythonMHC()
import atexit
# when the session ends, close the link, but keep the server alive, waiting for the next PsychoPy run.
# at the end of a run, makehuman.close() will send the string, 'exit',
# t
# ...
from pylsl import StreamInfo, StreamOutlet
info = StreamInfo(name='my_stream_name', type='Markers', channel_count=1,
channel_format='int32', source_id='uniqueid12345')
# Initialize the stream.
outlet = StreamOutlet(info)
# ...
>>> from psychopy import logging
>>> help(logging.log)
Help on function log in module psychopy.logging:
log(msg, level, t=None, obj=None)
Log a message
usage::
log(level, msg, t=t, obj=obj)
Log the
def onExit():
"""Restore keystroke echo when we exit"""
os.system('stty echo')
def captureControl_C(signum, frame):
"""If user types control-c, restore keystroke echo before quitting"""
# Restore th
if kb.status == STARTED:
# At the start of the loop, we check whether the scale is at either of its poles,
# and if so, we reset the keys variable and clear the event log.
if abs(y1)
if keyDecisionResponse.keys is None:
keyDecisionResponse.keys = "left" # Or however you assign it
datafile = open("stimuli.csv", "rt")
datafile = open("stimuli.csv", "r", encoding="utf-8-sig")
Mouse = [['x1', 'y1'], ['x2', 'y2']]
Target = [['xA', 'yA'], ['xB', 'yB']]
[item for sublist in zip(Mouse, Target) for item in sublist]
[['x1', 'y1'], ['xA', 'yA'], ['x2', 'y2'], ['xB', 'yB']]
<
import csv
import glob
import os
path = r'.\_reading data-2' # Path of directory containing data files.
extension = 'csv'
fieldnames = 'key_resp.rt', 'key_resp_4.rt', 'participant'
output_filename = 'sort.csv' # Output filename.
output_
Community Discussions
Trending Discussions on psychopy
QUESTION
I get a syntax error in PsychoPy’s PTB logging code. My code:
...ANSWER
Answered 2022-Feb-19 at 03:12If you look at the documentation for logging.log
...
QUESTION
I'm using the Psychopy module in Python. My code calls waitKeys(...) to get keypresses and reaction times. 90% of the time it works perfectly, but occasionally when I launch it I get this (exactly this, not an infinite repetition):
...ANSWER
Answered 2022-Feb-12 at 20:36Solved (kind of!).
For UI reasons, I stop keys typed during the experiment from being echoed to the screen (otherwise the screen gets full of random junk). I do this by sending stty -echo
to the parent shell.
But when exiting from the program (for any reason) I need to undo this by sending stty echo
. So I set up an exit handler:
QUESTION
ANSWER
Answered 2021-Dec-17 at 12:11From the error message I believe the sound file you've used here has a sampling rate of 32000 Hz, but you have another sound in your project sampled at 48000 Hz. Switching between sample rates is called resampling but resampling takes time. PsychoPy is designed to provide low-latency playback of sounds but to do this it will not perform any resampling for you. As a result, you should convert all your sounds to use the same sampling rate before the study runs using some audio software
QUESTION
enter image description hereI am trying to adapt an existing script to create a very simple experiment in psychopy in which the aim is that a rectangle with different colours and dimensions loops through the screen.
...ANSWER
Answered 2021-Jun-06 at 22:00I see no problem in your code.
Most likely the problem is in your CSV file. I think it was saved with encoding UTF-8 with BOM-signature. Try to change one line in your code:
QUESTION
My task is to design a square block. It will run randomly from one side of the screen to the other. And a beep will be played sometime. One has to push the botton(Here is keyboard) as soon as he hears the beep. The question is, when I use the "getkeys" method, it always returns an empty list. The RT shows that it main get the very first input in the buffer. I also tried eventclear, but seemed useless.
Here is the code.
...ANSWER
Answered 2021-Mar-25 at 04:42The question is, when I use the "getkeys" method, it always returns an empty list.
event.getKeys()
is an instantaneous check of the keyboard buffer. It will always return an empty list unless a key has been pressed since the last call to the function. So it is usually called in a loop, often once per screen refresh, to detect when a keypress has occurred. The result is that it will return an empty list many times, until a key is actually pressed.
But PsychoPy's event
module has actually been deprecated in favour of the newer Keyboard
class. This has the advantage that it returns the actual time that the key was pressed: when using event.getKeys()
, one just infers the reaction time from the time that the function was called. This is some time after the key is pressed - even if you are calling the function on every screen refresh (typically at 60 Hz), this limits the time resolution to 16.7 ms. The Keyboard
class, meanwhile, runs in a separate process and continually checks the keyboard hardware, allowing a precision more at the millisecond level.
Documentation on the Keyboard
class is here: https://www.psychopy.org/api/hardware/keyboard.html
QUESTION
I'm really sorry if the question was already answered, I haven't found the correct topic ... I'm on a project with Pavlovia and Pyschopy.
I want my participants to keep the cursor of the mouse inside a moving box (target). I'm recording the data, and I want to:
- record the position of the mouse and the target
- calculate the distance between the mouse and the centre of the target during each frame
- count how often the mouse was out of the box
The problem is between step 1 & step 2 :
- I can record in file "Mouse.csv" the position of the mouse (column for x and column for y)
- I can record in the file "Target.csv" the position of the target (column for x and column for y)
BUT I can't have the positions in 1 file with 4 columns (Mouse x ; Mouse y ; Target x ; Target y)
My problem is very similar as :
But it's not working correctly
The lists are looking like :
- Mouse : [['x1', 'y1'], ['x2', 'y2'], [...]]
- Target : [['xA', 'yA'], ['xB', 'yB'],[...]]
And I would like to get [['x1', 'y1'], ['xA', 'yA'], ['x2', 'y2'],['xB', 'yB'],[...]]
But when I can join the lists I just have something like [['x1', 'y1'], ['x2', 'y2'], ['xA', 'yA'], ['xB', 'yB'],[...]] :-(
...ANSWER
Answered 2021-Mar-05 at 21:50You can do this with zip
and then flatten it to get items back. You can zip the 2 lists element-wise (corresponding elements of both lists added to a tuple together.
Post that you can use [item for sublist in list for item in sublist]
which lets you flatten and break the tuples into corresponding items.
List this -
QUESTION
I am trying to read through multiple csv files in a folder, extract three columns (key_resp.rt
, key_resp_4.rt
, and participant
) from each csv file and write these information in a new csv file. I am able to get the for
loop running without write the result into the csv files. But with the code below, the new csv file (sort.csv
) only contains the header of the data strings without the real data.
My code:
...ANSWER
Answered 2021-Feb-12 at 17:36While it would be possible to open the output file multiple times and add data to it (by using a mode
argument of 'a'
for "append" instead of "w"
for normal (over) writing—see the open()
function documentation—in this case it would be less awkward to just open the output file once and leave it that way while appending data to it from the input files, one-by-one.
This is what I mean: (Note: no attempt was made to sort the data because you haven't specified how you wanted that done.)
QUESTION
I'm trying to build a brain-computer interface (BCI) experiment in Python that involves "high frequency" flashing (SSVEP), decision-making stimuli (P300), signal acquisition (EEG, with OpenBCI), and classifiers. I've been trying to use Psychopy toolbox for the interface part, but, unfortunately, it has been such a headache to make it work properly in parallel with the other processes on my current Lab PC that I'm starting to look for substitutes.
I was wondering if anyone knows alternative toolkits, plugins, or libraries that would be suitable for implementing such interfaces (i.e., flashing, sending timestamps, and modifying interface based on classification feedback).
Side-notes:Some toolkits that show up as alternatives to Psychopy are PsyToolkit, Paradigm and SuperLab 6, but I'm not sure they have the same functionality.
I tried looking into OpenSesame in the past too, but it seems like it is not possible to acquire signals that easily with it. If you have any resources that could prove me wrong, please feel free to link them too.
Thoughts on those would be also very welcomed.
...ANSWER
Answered 2020-Nov-30 at 21:11If you are facing difficulties with PsychoPy, which is really just a set of modules with the full power of Python behind it, then you are certainly going to be frustrated with options like PsyToolKit, which, being browser-based, is never going to be able to give you the level of control you need over your system.
OpenSesame is Python (and often PsychoPy) based under the hood. Paradigm seems to have a nice interface but to add more sophisticated functionality, also uses Python scripting (although seems to still be at version 2.6). I'm not that familiar with SuperLab, but it has been around a long time, and does seem to be focussed on lab equipment use.
But it seems that your issues are more to do with working in parallel with other computer processes rather than PsychoPy per se (which doesn't impose any limitations other than those inherent in Python itself). As noted above, the alternatives you list either won't give the level of control you need, or will also require Python for hardware interfacing.
You might be best to describe specific issues and seek help with those. Many other people have used PsychoPy and Python to display stimuli and record EEG - this task is in no way insurmountable.
QUESTION
I've just started using PsychoPy
and I've tried to flip text and a grating, both of which appear broken up with green lines.
Anyone know how to fix this?
I'm using PyCharm with Python 3.8 and I get these error messages, not sure if related:
...ANSWER
Answered 2020-Oct-29 at 15:50I'm experiencing the same issue but found that this is only the case on my computer. When I use the exact same code on a different computer, everything appears normal.
QUESTION
I am programming a task in PsychoPy (version 1.84.2), where participants have to rate the contrast difference between some gratings (e.g. a value between -1 and 1). I designed a rating scale using visual.RatingScale. Now I wanna ask the participants to add two more markers to the scale indicating their confidence interval. OR even better: participants could use the scroll wheel of the mouse to adapt the width of the interval.
Is there any possibility to do this??
Code:
...ANSWER
Answered 2020-Sep-24 at 00:42I'm not sure if it's available back in version 1.84 (or why you need to use such an old version of PsychoPy), but the general advice now would be to avoid using the RatingScale
class and instead use the simpler but more extensible Slider
class.
Regardless, what I'd suggest is that you avoid modifying that object by adding extra markers and so on. Instead create and draw a separate rectangular ShapeStim
object:
https://www.psychopy.org/api/visual/shapestim.html
Set the vertical position of that rectangle to be a constant, either above, below, or behind the slider as required. On each frame, set its centre to correspond to the marker value of the slider or rating scale. Monitor the mouse scroll wheel, and use that to control the length of the rectangle, to indicate the uncertainty width.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install psychopy
You can use psychopy like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page