rewardgym.psychopy_render

rewardgym.psychopy_render.logger

Logger classes used by the experiment.

class rewardgym.psychopy_render.logger.ExperimentLogger(file_name: str, global_clock: psychopy.core.Clock | None = None, participant_id: str = 'n/a', task: str = 'hcp', run: int = 1, seq_tr: float = 0.752, sep: str = '\t', na: str = 'n/a', kill_switch: str = 'q', mr_trigger: str = '5', mr_clock: psychopy.core.Clock | None = None)[source]

Bases: object

Logger class to log what is going on during the experiment.

__init__(file_name: str, global_clock: psychopy.core.Clock | None = None, participant_id: str = 'n/a', task: str = 'hcp', run: int = 1, seq_tr: float = 0.752, sep: str = '\t', na: str = 'n/a', kill_switch: str = 'q', mr_trigger: str = '5', mr_clock: psychopy.core.Clock | None = None)[source]

Logger class to help with logging during a potential fMRI experiment, which is implemented in PsychoPy.

Parameters:
  • file_name (str) – Name of the output file.

  • global_clock (core.Clock) – Clock that is used by the experiment.

  • participant_id (str) – The participant id (logged as its own persistent column)

  • task (str, optional) – The task, also logged as persistent column, by default “hcp”

  • run (int, optional) – The run, also logged as persistent column, by default 1

  • seq_tr (float, optional) – If it is an fMRI experiment, this is echo time. Used to calculate the expected collection between acquisitions, by default 0.752

  • sep (str, optional) – What kind of separator to use in output file, by default “ “

  • na (str, optional) – How NaN values are written to file, by default “n/a”

  • kill_switch (str, optional) – Button to press to exit the experiment, by default “q”

  • mr_trigger (str, optional) – Trigger of the MRI (assuming that it is transformed to a key press), by default “5”

close()[source]

Closes the file.

create(mode: str = 'w')[source]

Creates new file with the given columns. Or opens to append.

Parameters:

mode (str, optional) – mode (str, optional): Writing mode, by default “w”

get_time() float[source]

Get the current time from the global clock.

Returns:

time passed sine last reset

Return type:

float

key_strokes(win: psychopy.visual.Window, keyList: List[str] = []) Tuple[str, float] | None[source]

Check for key strokes in the keyboard buffer. Checking for MR-triggers, close commands (kill_switch), or other allowed responses.

Parameters:
  • win (Window) – Psychopy window object, used to display the task.

  • keyList (List[str], optional) – List of allowed keys., by default []

Returns:

_description_

Return type:

Union[Tuple[str, float], None]

log_event(info_dict: Dict, reward: float | None = None, onset: float | None = None)[source]

Logs the current event.

Parameters:
  • info_dict (Dict) – the dictionary that contains the current information of the trial.

  • reward (float, optional) – reward received in the trial, by default None

  • onset (float, optional) –

    The real onset of the event, duration is

    calculated between onset and current time, by default None

Raises:

ValueError – Returns an error if onset is after the current time.

set_trial_time()[source]

Set the trial’s start using the global clock.

wait(win, time: float, start: float | None = None, wait_no_keys: bool = False)[source]

Wait for a given time.

Parameters:
  • time (float) – Time to wait, in seconds.

  • start (float, optional) – Specify a different time, than the current one of the Logger, by default None

class rewardgym.psychopy_render.logger.MinimalLogger(global_clock: psychopy.core.Clock | None = None, seq_tr: float = 0.752, na: str = 'n/a', kill_switch: str = 'q', mr_trigger: str = '5', mr_clock: psychopy.core.Clock | None = None)[source]

Bases: ExperimentLogger

Emulates the experiment logger, to keep stimuli classes working, does not write to file (uses stubs)

__init__(global_clock: psychopy.core.Clock | None = None, seq_tr: float = 0.752, na: str = 'n/a', kill_switch: str = 'q', mr_trigger: str = '5', mr_clock: psychopy.core.Clock | None = None)[source]

Logger class to help with logging during a potential fMRI experiment, which is implemented in PsychoPy.

Parameters:
  • global_clock (Clock) – Clock that is used by the experiment.

  • seq_tr (float, optional) – If it is an fMRI experiment, this is echo time. Used to calculate the expected collection between acquisitions, by default 0.752

  • na (str, optional) – How NaN values are written to file, by default “n/a”

  • kill_switch (str, optional) – Button to press to exit the experiment, by default “q”

  • mr_trigger (str, optional) – Trigger of the MRI (assuming that it is transformed to a key press), by default “5”

close()[source]

Close stub.

create(*args, **kwargs)[source]

Create stub.

log_event(*args, **kwargs)[source]

Log event stub.

class rewardgym.psychopy_render.logger.SimulationLogger(file_name: str, global_clock: psychopy.core.Clock | None = None, participant_id: str = 'n/a', task: str = 'hcp', run: int = 1, seq_tr: float = 0.752, sep: str = '\t', na: str = 'n/a', kill_switch: str = 'q', mr_trigger: str = '5', mr_clock: psychopy.core.Clock | None = None)[source]

Bases: ExperimentLogger

close()[source]

Closes the file.

create()[source]

Creates new file with the given columns. Or opens to append.

Parameters:

mode (str, optional) – mode (str, optional): Writing mode, by default “w”

key_strokes(key, rt) Tuple[str, float] | None[source]

Check for key strokes in the keyboard buffer. Checking for MR-triggers, close commands (kill_switch), or other allowed responses.

Parameters:
  • win (Window) – Psychopy window object, used to display the task.

  • keyList (List[str], optional) – List of allowed keys., by default []

Returns:

_description_

Return type:

Union[Tuple[str, float], None]

wait(win, time: float, start: float | None = None)[source]

Wait for a given time.

Parameters:
  • time (float) – Time to wait, in seconds.

  • start (float, optional) – Specify a different time, than the current one of the Logger, by default None

rewardgym.psychopy_render.special_stimuli

class rewardgym.psychopy_render.special_stimuli.ActionStimulusTooEarly(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', timeout_action: int | None = None, name_timeout='response-time-out', name_tooearly='response-too-early', text_tooearly={'color': 'white', 'height': 28, 'pos': (0, -150), 'text': "Don't press too early!"})[source]

Bases: ActionStimulus

Stimulus class, for when actions are required by the participants.

__init__(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', timeout_action: int | None = None, name_timeout='response-time-out', name_tooearly='response-too-early', text_tooearly={'color': 'white', 'height': 28, 'pos': (0, -150), 'text': "Don't press too early!"})[source]

Setting up the action object.

Parameters:
  • duration (float) – Duration of the response window.

  • key_dict (dict, optional) – Dictionary to map keyboard responses to actions recognized by the environment, by default {“left”: 0, “right”: 1}

  • name (str, optional) – name of the object, will be used for logging, by default None

  • timeout_action (int, optional) – Behavior of the object if the response window times out, making it possible that no response is also a distinc action, by default None

display(win: psychopy.visual.Window, logger: ExperimentLogger, info: Dict, **kwargs) int | str[source]

Calls the stimulus object. In this case waiting for a specific response, returning it and logging the process. Flipping the window in the end.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

Returns:

The response issued by the participant, interpretable by the environment.

Return type:

Union[int, str]

class rewardgym.psychopy_render.special_stimuli.ConditionBasedDisplay(duration, name=None, image_position=(0, 0), image_shift=350, with_action=False, image_map={1: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 2: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 3: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 4: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 5: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4))})[source]

Bases: BaseStimulus

__init__(duration, name=None, image_position=(0, 0), image_shift=350, with_action=False, image_map={1: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 2: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 3: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 4: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), 5: array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4))})[source]

Stimulus presentation base class. The parameters do not really do anything.

Parameters:
  • duration (float, optional) – duration of the stimulus presentation, by default None

  • name (str, optional) – name of the object, will be used for logging, by default None

display(win, logger, condition, action=None, **kwargs)[source]

Calls the stimulus object. In this case initiate a window flip. Should only return something, if there has been an action required.

Returns:

Should return None

Return type:

None

class rewardgym.psychopy_render.special_stimuli.StimuliWithResponse(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', target_name: str | None = None, target_duration: float = 0.0, timeout_action: int | None = None, name_timeout='response-time-out', positions=((0, 0), (0, 0)), images=[array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4))], flip_probability=0.5, flip_dir: str = 'horiz', seed=111)[source]

Bases: ActionStimulus

__init__(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', target_name: str | None = None, target_duration: float = 0.0, timeout_action: int | None = None, name_timeout='response-time-out', positions=((0, 0), (0, 0)), images=[array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4))], flip_probability=0.5, flip_dir: str = 'horiz', seed=111)[source]

Setting up the action object.

Parameters:
  • duration (float) – Duration of the response window.

  • key_dict (dict, optional) – Dictionary to map keyboard responses to actions recognized by the environment, by default {“left”: 0, “right”: 1}

  • name (str, optional) – name of the object, will be used for logging, by default None

  • timeout_action (int, optional) – Behavior of the object if the response window times out, making it possible that no response is also a distinc action, by default None

display(win, logger, info, **kwargs)[source]

Calls the stimulus object. In this case waiting for a specific response, returning it and logging the process. Flipping the window in the end.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

Returns:

The response issued by the participant, interpretable by the environment.

Return type:

Union[int, str]

simulate(win: psychopy.visual.Window, logger=<class 'rewardgym.psychopy_render.logger.SimulationLogger'>, key: str | None = None, rt: float | None = None, info: ~typing.Dict | None = None, **kwargs)[source]

Function to pretend that a stimulus has been shown. Logging and creating timing.

Returns:

Does not return anything, but logs the stimulus.

Return type:

None

class rewardgym.psychopy_render.special_stimuli.TextWithBorder(text, condition_text, duration=1.0, width=250, height=350, lineWidth=3, lineColor='white', fillColor='grey', textColor='white', target='reward', font_height=150, position=(0, 0), name=None)[source]

Bases: BaseStimulus

__init__(text, condition_text, duration=1.0, width=250, height=350, lineWidth=3, lineColor='white', fillColor='grey', textColor='white', target='reward', font_height=150, position=(0, 0), name=None)[source]

Stimulus presentation base class. The parameters do not really do anything.

Parameters:
  • duration (float, optional) – duration of the stimulus presentation, by default None

  • name (str, optional) – name of the object, will be used for logging, by default None

display(win, logger, reward, action, **kwargs)[source]

Calls the stimulus object. In this case initiate a window flip. Should only return something, if there has been an action required.

Returns:

Should return None

Return type:

None

setup(win, **kwargs)[source]

Call this to setup the stimulus. This means associating the stimulus with a window (so there is something to flip).

Parameters:

win (Window) – The psychopy window object that is used for displaying stimuli.

class rewardgym.psychopy_render.special_stimuli.TwoStimuliWithResponseAndSelection(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', name_phase1: str | None = None, name_phase2: str | None = None, duration_phase1: float = 0.0, duration_phase2: float = 0.0, timeout_action: int | None = None, name_timeout='response-time-out', positions=((0, 0), (0, 0)), images=[array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4))], flip_probability=0.5, seed=111)[source]

Bases: ActionStimulus

__init__(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', name_phase1: str | None = None, name_phase2: str | None = None, duration_phase1: float = 0.0, duration_phase2: float = 0.0, timeout_action: int | None = None, name_timeout='response-time-out', positions=((0, 0), (0, 0)), images=[array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4)), array([[[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], ..., [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]], [[0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.], ..., [0., 0., 0., 1.], [0., 0., 0., 1.], [0., 0., 0., 1.]]], shape=(484, 304, 4))], flip_probability=0.5, seed=111)[source]

Setting up the action object.

Parameters:
  • duration (float) – Duration of the response window.

  • key_dict (dict, optional) – Dictionary to map keyboard responses to actions recognized by the environment, by default {“left”: 0, “right”: 1}

  • name (str, optional) – name of the object, will be used for logging, by default None

  • timeout_action (int, optional) – Behavior of the object if the response window times out, making it possible that no response is also a distinc action, by default None

display(win, logger, info, **kwargs)[source]

Calls the stimulus object. In this case waiting for a specific response, returning it and logging the process. Flipping the window in the end.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

Returns:

The response issued by the participant, interpretable by the environment.

Return type:

Union[int, str]

simulate(win: psychopy.visual.Window, logger=<class 'rewardgym.psychopy_render.logger.SimulationLogger'>, key: str | None = None, rt: float | None = None, info: ~typing.Dict | None = None, **kwargs)[source]

Function to pretend that a stimulus has been shown. Logging and creating timing.

Returns:

Does not return anything, but logs the stimulus.

Return type:

None

rewardgym.psychopy_render.stimuli

class rewardgym.psychopy_render.stimuli.ActionStimulus(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', timeout_action: int | None = None, name_timeout='response-time-out')[source]

Bases: BaseStimulus

Stimulus class, for when actions are required by the participants.

__init__(duration: float, key_dict: Dict = {'left': 0, 'right': 1}, name: str = 'response', timeout_action: int | None = None, name_timeout='response-time-out')[source]

Setting up the action object.

Parameters:
  • duration (float) – Duration of the response window.

  • key_dict (dict, optional) – Dictionary to map keyboard responses to actions recognized by the environment, by default {“left”: 0, “right”: 1}

  • name (str, optional) – name of the object, will be used for logging, by default None

  • timeout_action (int, optional) – Behavior of the object if the response window times out, making it possible that no response is also a distinc action, by default None

display(win: psychopy.visual.Window, logger: ExperimentLogger, info: Dict, **kwargs) int | str[source]

Calls the stimulus object. In this case waiting for a specific response, returning it and logging the process. Flipping the window in the end.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

Returns:

The response issued by the participant, interpretable by the environment.

Return type:

Union[int, str]

simulate(win: psychopy.visual.Window, logger=<class 'rewardgym.psychopy_render.logger.SimulationLogger'>, key: str | None = None, rt: float | None = None, info: ~typing.Dict | None = None, **kwargs)[source]

Function to pretend that a stimulus has been shown. Logging and creating timing.

Returns:

Does not return anything, but logs the stimulus.

Return type:

None

class rewardgym.psychopy_render.stimuli.BaseStimulus(duration: float | None = None, name: str | None = None, wait_no_keys=False)[source]

Bases: object

Base class for stimulus presentation. If called on its own it will flip the window.

__init__(duration: float | None = None, name: str | None = None, wait_no_keys=False)[source]

Stimulus presentation base class. The parameters do not really do anything.

Parameters:
  • duration (float, optional) – duration of the stimulus presentation, by default None

  • name (str, optional) – name of the object, will be used for logging, by default None

display(win: psychopy.visual.Window, logger: ExperimentLogger, **kwargs) None[source]

Calls the stimulus object. In this case initiate a window flip. Should only return something, if there has been an action required.

Returns:

Should return None

Return type:

None

setup(win: psychopy.visual.Window, **kwargs)[source]

Call this to setup the stimulus. This means associating the stimulus with a window (so there is something to flip).

Parameters:

win (Window) – The psychopy window object that is used for displaying stimuli.

simulate(logger: ExperimentLogger, **kwargs) None[source]

Function to pretend that a stimulus has been shown. Logging and creating timing.

Returns:

Does not return anything, but logs the stimulus.

Return type:

None

class rewardgym.psychopy_render.stimuli.FeedBackStimulus(duration: float, text: str, position: Tuple[int, int] = (0, 125), name: str | None = None, target: Literal['reward', 'total_reward'] = 'reward', text_color: str = 'white', font_height: float = 50, feedback_stim: Dict = True, simple: bool = False, bar_total: float | None = None, bar_labels: Dict = {'left': '0 kr', 'right': '75 kr'})[source]

Bases: BaseStimulus

Class that possibly will be superseded or become obsolete at some point.

Purpose of the class is to provide feedback to the participant, about the number of points they have received in a given trial or across the experiment.

__init__(duration: float, text: str, position: Tuple[int, int] = (0, 125), name: str | None = None, target: Literal['reward', 'total_reward'] = 'reward', text_color: str = 'white', font_height: float = 50, feedback_stim: Dict = True, simple: bool = False, bar_total: float | None = None, bar_labels: Dict = {'left': '0 kr', 'right': '75 kr'})[source]

FeedBack class, provides feedback to the participant, by creating updatable TextStims.

Parameters:
  • duration (float) – Duration of the feedback.

  • text (str) – The text that should be displayed on the screen. Should be a format string!

  • position (Tuple[int, int], optional) – Where to display the text (by default in px), by default None

  • name (str, optional) – name of the object, will be used for logging, by default None

  • target (Literal[&quot;reward&quot;, &quot;total_reward&quot;], optional) – If the trial’s reward or the total reward should be shown, by default “reward”

  • text_color (str, optional) – Color of the text, by default “white”

  • feedback_stim (Dict, optional) – If the feedback_stim should be displayed, if True changes fixation cross, if None does not show an image as feedback. For other images populate the keys: win, lose, zero with a string to an image or a numpy array.

display(win: psychopy.visual.Window, logger: ExperimentLogger, reward: float, total_reward: float, **kwargs) None[source]

Calls the stimulus object, to display the reward. Uses reward or total_reward depending on the target that has been defined.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

  • reward (float) – Reward of the given trial, provided by the environment.

  • total_reward (float) – Total reward, provided by the environment.

Returns:

Should return None

Return type:

None

simulate(logger=<class 'rewardgym.psychopy_render.logger.ExperimentLogger'>, reward: float | None = None, total_reward: float | None = None, **kwargs) None[source]

Function to pretend that a stimulus has been shown. Logging and creating timing.

Returns:

Does not return anything, but logs the stimulus.

Return type:

None

class rewardgym.psychopy_render.stimuli.ImageStimulus(duration: float, image_paths: List, positions: List | None = None, name: str | None = None, width: float | None = None, height: float | None = None, autodraw: bool = False, wait_no_keys: bool = False)[source]

Bases: BaseStimulus

A stimulus class to display (multiple) images in psychopy.

__init__(duration: float, image_paths: List, positions: List | None = None, name: str | None = None, width: float | None = None, height: float | None = None, autodraw: bool = False, wait_no_keys: bool = False)[source]

Stimulus class for image displays.

Parameters:
  • duration (float) – Duration of the stimulus presentation.

  • image_paths (List) – A list of paths to images that should be displayed on screen.

  • positions (List, optional) – A list of positions (where the images should be displayed), by default None

  • name (str, optional) – name of the object, will be used for logging, by default None

  • wait_no_keys (str, optional) – If the logger’s wait function should get key presses - only set to True if presses that are too early should be used, by default False

display(win: psychopy.visual.Window, logger: ExperimentLogger, **kwargs)[source]

Calls the stimulus object. In this case drawing the images stims, flipping the window, waiting and logging.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

Returns:

  • None

  • Should return None

class rewardgym.psychopy_render.stimuli.TextStimulus(duration: float, text: str, position: Tuple[int, int] | None = None, name: str | None = None, text_color: str = 'white')[source]

Bases: BaseStimulus

A stimulus class for text display in psychopy.

__init__(duration: float, text: str, position: Tuple[int, int] | None = None, name: str | None = None, text_color: str = 'white')[source]

Stimulus class for text displays.

Parameters:
  • duration (float) – Duration of the stimulus presentation.

  • text (str) – The text that should be displayed on the screen.

  • position (Tuple[int, int], optional) – Where to display the text (by default in px), by default None

  • name (str, optional) – name of the object, will be used for logging, by default None

  • text_color (str, optional) – Color of the text string, by default “white”

display(win: psychopy.visual.Window, logger: ExperimentLogger, **kwargs) None[source]

Calls the stimulus object. In this case drawing the text stim, flipping the window, waiting and logging.

Parameters:
  • win (Window) – The psychopy window object that is used for displaying stimuli.

  • logger (ExperimentLogger) – The logger associated with the experiment.

Returns:

  • None

  • Should return None