Task#
- class pypillometry.sim.Task(name='task', blocks=(), repeat_n=None, repeat_duration=None, start=0)[source]#
Bases:
SimStepDesign of an experiment: blocks of trials with stimuli and responses.
A task is built by chaining:
block()starts a block of trials,stimulus()andresponse()add events to each trial of the current block,rest()adds a pause andrepeat()repeats the blocks. Each method returns a new task. Times are fixed ("250 ms", plain numbers are ms) or distributions ("uniform(2 s, 10 s)","lognormal(350 ms, 70 ms)", seeparse_dist()).In a simulation (
Simulation.task), the task makes the events of the data, with the metadatakind("stimulus"or"response"),modality,trial(numbered over the task),block,condition,duration(of stimuli, ms),luminance,rt(of responses: the time from the event they follow, ms) and the values given in meta of the events. Ready-made tasks are inpypillometry.sim.tasks.- Parameters:
name (
str) – name of the task
Examples
>>> import pypillometry as pp >>> sart = (pp.sim.Task("SART") ... .block(n=225, soa="1150 ms", conditions={"go": 8/9, "nogo": 1/9}) ... .stimulus("digit", "visual", duration="250 ms") ... .stimulus("mask", "visual", at="250 ms", duration="900 ms") ... .response("press", after="digit", rt="lognormal(350 ms, 70 ms)", ... p={"go": 0.97, "nogo": 0.3})) >>> import numpy as np >>> ev, end = sart.generate(np.random.default_rng(1)) >>> sorted(str(x) for x in set(ev["label"])) ['digit', 'mask', 'press']
Methods
change the arrays of the running simulation run
Start a block of trials.
the eyes of the simulation the step applies to
the step from
to_dict()Simulate the events of the task.
Schematic of the trials of each block of the task.
Repeat the blocks of the task.
Add a response to each trial of the current block.
Add a pause without events.
Add a stimulus to each trial of the current block.
name and parameters of the step (numbers, strings, lists, dicts)
Details
- block(n=None, duration=None, soa=None, isi=None, conditions=None)[source]#
Start a block of trials.
- Parameters:
n (int, optional) – number of trials
duration (float, str or distribution, optional) – duration of the block (trials start until it is over); n and/or duration must be given
soa (float, str or distribution, optional) – time from the start of one trial to the start of the next
isi (float, str or distribution, optional) – time from the end of one trial (its last event, or the end of the last stimulus) to the start of the next; default 0 if neither soa nor isi is given (then a block with a duration but no n needs trials that take time)
conditions (dict or list, optional) – conditions of the trials with their probabilities (e.g.
{"go": 8/9, "nogo": 1/9}; a list for equal probabilities)
- Return type:
- plot(axes=None, figsize=None)[source]#
Schematic of the trials of each block of the task.
One panel per block with events: one lane per event, stimuli as bars (coloured by modality), the onsets that vary as a band from the 10% to the 90% quantile around the mean, the spacing of the trials and the probabilities of the events.
- response(label, after=None, rt=0, p=1.0, modality='motor', meta=None)[source]#
Add a response to each trial of the current block.
- Parameters:
label (str) – label of the event
after (str, optional) – label of the earlier event of the trial that it responds to; if None, rt is relative to the start of the trial
rt (float, str or distribution) – time from the event after (the reaction time; may be negative, e.g. for taps that anticipate a tone)
p (float or dict) – probability of the response (per condition with a dict; 0 for conditions that are not given)
modality (str) – default
"motor"meta (dict, optional) – further metadata (see
stimulus())
- Return type:
- stimulus(label, modality='visual', at=0, after=None, duration=None, timeout='30 s', p=1.0, luminance=None, meta=None)[source]#
Add a stimulus to each trial of the current block.
- Parameters:
label (str) – label of the event
modality (str) –
"visual"(default),"auditory"or another modalityat (float, str or distribution) – onset relative to the start of the trial, or to the event after (default 0)
after (str, optional) – label of an earlier event of the trial that at refers to
duration (float, str or distribution, optional) – duration of the stimulus;
"until response": until the first response that follows it (or timeout)timeout (float, str or distribution) – duration of a stimulus
"until response"without a response (default 30 s)p (float or dict) – probability of the stimulus (per condition with a dict; 0 for conditions that are not given)
luminance (float, optional) – change of the luminance at the onset (for visual stimuli; used by future pupil responses)
meta (dict, optional) – further metadata, name -> values: a value, a list (drawn with equal probabilities), a dict value -> probability, a dict condition -> one of these, or
{"nback": k, "values": [...]}for the stimuli of an n-back task (in condition"target"the value of k trials before, otherwise another value)
- Return type: