We are developing several tasks with the PsychoPy builder, that will form a task battery in an experiment.
Our question is: Is there a way to “share” information/variable (e.g. LSL stream, participant ID, session number, etc) between these different tasks, without having to enter these infos again for each task?
There is the solution of doing everything in a single PsychoPy experiment (.psyexp file), but this doesn’t really suit us because of the lack of flexibility. We would prefer to have a metascript with the shared variables, in which we can launch individual tasks through a GUI.
This setup works well; both tasks run sequentially (the complete battery will have more tasks), and we successfully collect the data from both tasks in the data folder.
However, we would like to initialize variables at the beginning of the session that can be passed to the task scripts. For example, our participants can be either French or English speakers, and we want the instructions to adapt accordingly based on the language selected at the start of the experiment.
Is there a way to pass such variables to the task scripts within this “metascript”?
It can be launched both from
thisSession.runExperiment(“DoubleRTT”, expInfo={‘language’: language_participant})
where language_participant is decided with a language questionnaire prior to this task;
And from stand alone with psychopy builder (default instructions will be english language).
Thanks to this function, we were also able to add more variables such as these:
thisSession.runExperiment(“DoubleRTT”, expInfo={‘participant’: participant_id, ‘session’: session_n, ‘language’: language_participant, ‘date’: date_str})
OS : macOS Ventura 13.4 PsychoPy version : 2024.1.5 Standard Standalone? (y/n) If not then what?: Y
Hello,
I am trying to use this session object in Builder (I need Builder for several reasons). I had a look at the posts linked and above but I am getting an error.
thisSession = session.Session(
NameError: name ‘session’ is not defined
My guess is that I am declaring the object in the wrong place.
I have a simple experiment, showing a dialog box, then calling another experiment.
I have a code component with the following:
thisSession = session.Session(
win=win,
root="root_path",
experiments={
# paths should be relative to the root folder
'task_checklist': "./task_checklist/task_checklist.psyexp",
'task_saturn': "./task_saturn/task_saturn.psyexp",
}
)
I placed the code in the ‘Before experiment’ tab (tried also the ‘Begin experiment’ but i always get the error. Any idea what I am missing?
I also encountered this error. I needed to create variables for the expInfo. Here is the work-in-progress code that I use as an example (note that I am not using the builder and this is a standalone python script).
import os
from psychopy import visual, core, session
from datetime import datetime
# Get the directory where the script is located
script_dir = os.path.dirname(os.path.abspath(__file__))
# Variables for expInfo
participant_id = 'sub-001'
language_participant = 'English'
session_n = '001'
date_str = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
# Create a window
win = visual.Window(size=[1920, 1080], fullscr=True, screen=0,
winType='pyglet', allowGUI=True, allowStencil=False,
monitor='testMonitor', color='black', colorSpace='rgb',
blendMode='avg', useFBO=True)
# Define the path of the project root
root_path = script_dir
# Save the participant ID to a data file
data_file = os.path.join(root_path, f"data_{participant_id}.csv")
# Create a Session object
thisSession = session.Session(
win=win,
root=root_path,
experiments={
'DoubleRTT': "DoubleRTT/DoubleRTT_lastrun.py",
'SimpleRTT': "SimpleRTT/simpleRTT_lastrun.py",
}
)
# Run the DoubleRTT experiment
thisSession.runExperiment("DoubleRTT", expInfo={'participant': participant_id, 'session': session_n, 'language': language_participant, 'date': date_str})
# Run the SimpleRTT experiment
thisSession.runExperiment("SimpleRTT", expInfo={'participant': participant_id, 'session': session_n, 'language': language_participant, 'date': date_str})
# Close the window
win.close()
core.quit()