Simulation#

class pypillometry.sim.Simulation(duration=None, fs=1000.0, eyes='left', seed=None, setup=None, name=None, missing_value=None)[source]#

Bases: Stateful

Recipe of a simulated recording.

A simulation is built by chaining steps; each method returns a new Simulation with one more step, so that a base simulation can be varied:

base = pp.sim.Simulation("2 min", fs=1000, seed=1).pupil().units(800)
low, high = base.noise(0.1), base.noise(1.0)

run() makes the data: a SimEyeData with the ground truth in d.truth and the recipe in d.simulation. The steps run in a fixed order of stages, whatever the order in which they were added: latent pupil size (log-%), gaze, foreshortening, units of the tracker, noise (see pypillometry.sim.steps). Without a units step, the pupil has a median of 1000.

Parameters:
  • duration (float, str or Quantity, optional) – duration of the recording (plain numbers are ms), e.g. "2 min"; default: until the end of the task (see task())

  • fs (float) – sampling rate in Hz (default 1000)

  • eyes (str or list) – "left" (default), "right" or both

  • seed (int, optional) – seed of the random numbers; if None, run() draws one and stores it in the simulation of the data, so that every result can be made again

  • setup (ExperimentalSetup, optional) – geometry of the setup (needed for foreshortening(); the screen size is used by gaze())

  • name (str, optional) – name of the data (default: a random name)

  • missing_value (float, optional) – value of the samples without pupil (blinks, losses): NaN (default) or, e.g., 0 like some trackers

Attributes:
stepslist

the steps (see pypillometry.sim.steps)

Examples

>>> import pypillometry as pp
>>> sim = (pp.sim.Simulation("10 s", fs=100, eyes=["left", "right"], seed=1)
...        .pupil(binocular=True).units(800).noise(0.2))
>>> d = sim.run()
>>> d.truth.variables[:3]
['log_size', 'log_fast', 'log_diff']
>>> bool((d.simulation.run()["left_pupil"] == d["left_pupil"]).all())
True

Methods

add

A copy with one more step.

blinks

Add blinks: step, or Blinks with the keyword arguments (e.g., rate="20/min").

comb

Add comb artifacts (bursts of short dropouts with lowered samples at their edges, or of short drops): step, or Comb with the keyword arguments (e.g., rate="5/min", missing=0.5).

foreshortening

Add the foreshortening of the pupil (Foreshortening); needs the gaze and the setup of the simulation.

gaze

Add the gaze: step, or Fixations with the keyword arguments.

loss

Add losses of the pupil by the tracker: step, or TrackerLoss with the keyword arguments (e.g., rate="1/min").

noise

Add white measurement noise (WhiteNoise).

pupil

Add the latent pupil size: the given steps, or a TimescalePupil with the keyword arguments (e.g., params={"fast_sd": 5.0}; default: the centre of the general prior of the timescale model).

run

Simulate the recording.

task

Add the events of a task (see Task and pypillometry.sim.tasks).

units

Add the units of the tracker (Units).

Details

add(step)[source]#

A copy with one more step.

Parameters:

step (SimStep) – the step (see pypillometry.sim.steps)

Return type:

Self

Add blinks: step, or Blinks with the keyword arguments (e.g., rate="20/min").

Return type:

Self

comb(step=None, **kwargs)[source]#

Add comb artifacts (bursts of short dropouts with lowered samples at their edges, or of short drops): step, or Comb with the keyword arguments (e.g., rate="5/min", missing=0.5).

Return type:

Self

foreshortening(**kwargs)[source]#

Add the foreshortening of the pupil (Foreshortening); needs the gaze and the setup of the simulation.

Return type:

Self

gaze(step=None, **kwargs)[source]#

Add the gaze: step, or Fixations with the keyword arguments.

Return type:

Self

loss(step=None, **kwargs)[source]#

Add losses of the pupil by the tracker: step, or TrackerLoss with the keyword arguments (e.g., rate="1/min").

Return type:

Self

noise(sd=0.2, scale='log%', eyes=None)[source]#

Add white measurement noise (WhiteNoise).

Parameters:
  • sd (float) – standard deviation (log-% by default)

  • scale ({"log%", "data"}) – units of sd

  • eyes (str or list, optional) – eyes (default: all)

Return type:

Self

pupil(*steps, **kwargs)[source]#

Add the latent pupil size: the given steps, or a TimescalePupil with the keyword arguments (e.g., params={"fast_sd": 5.0}; default: the centre of the general prior of the timescale model).

Return type:

Self

run(seed=None)[source]#

Simulate the recording.

Parameters:

seed (int, optional) – seed of the random numbers; default: the seed of the simulation (or a new one if it has none)

Return type:

SimEyeData

Returns:

the data, with the ground truth (d.truth) and the simulation with the seed that was used (d.simulation)

task(task, start=None)[source]#

Add the events of a task (see Task and pypillometry.sim.tasks).

The events of the task become the events of the data (d.events, with their metadata); events outside of the recording are left out.

Parameters:
  • task (Task)

  • start (float, str or distribution, optional) – time of the start of the task in the recording (default: that of the task, 0)

Return type:

Self

units(median=1000.0)[source]#

Add the units of the tracker (Units).

Parameters:

median (float or dict) – median pupil size (per eye with a dict)

Return type:

Self