Simulation#
- class pypillometry.sim.Simulation(duration=None, fs=1000.0, eyes='left', seed=None, setup=None, name=None, missing_value=None)[source]#
Bases:
StatefulRecipe of a simulated recording.
A simulation is built by chaining steps; each method returns a new
Simulationwith 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: aSimEyeDatawith the ground truth ind.truthand the recipe ind.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 (seepypillometry.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 (seetask())fs (float) – sampling rate in Hz (default 1000)
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 againsetup (ExperimentalSetup, optional) – geometry of the setup (needed for
foreshortening(); the screen size is used bygaze())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
A copy with one more step.
Add blinks: step, or
Blinkswith the keyword arguments (e.g.,rate="20/min").Add comb artifacts (bursts of short dropouts with lowered samples at their edges, or of short drops): step, or
Combwith the keyword arguments (e.g.,rate="5/min",missing=0.5).Add the foreshortening of the pupil (
Foreshortening); needs the gaze and the setup of the simulation.Add the gaze: step, or
Fixationswith the keyword arguments.Add losses of the pupil by the tracker: step, or
TrackerLosswith the keyword arguments (e.g.,rate="1/min").Add white measurement noise (
WhiteNoise).Add the latent pupil size: the given steps, or a
TimescalePupilwith the keyword arguments (e.g.,params={"fast_sd": 5.0}; default: the centre of the general prior of the timescale model).Simulate the recording.
Add the events of a task (see
Taskandpypillometry.sim.tasks).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:
- blinks(step=None, **kwargs)[source]#
Add blinks: step, or
Blinkswith the keyword arguments (e.g.,rate="20/min").- Return type:
- comb(step=None, **kwargs)[source]#
Add comb artifacts (bursts of short dropouts with lowered samples at their edges, or of short drops): step, or
Combwith the keyword arguments (e.g.,rate="5/min",missing=0.5).- Return type:
- foreshortening(**kwargs)[source]#
Add the foreshortening of the pupil (
Foreshortening); needs the gaze and the setup of the simulation.- Return type:
- gaze(step=None, **kwargs)[source]#
Add the gaze: step, or
Fixationswith the keyword arguments.- Return type:
- loss(step=None, **kwargs)[source]#
Add losses of the pupil by the tracker: step, or
TrackerLosswith the keyword arguments (e.g.,rate="1/min").- Return type:
- noise(sd=0.2, scale='log%', eyes=None)[source]#
Add white measurement noise (
WhiteNoise).
- pupil(*steps, **kwargs)[source]#
Add the latent pupil size: the given steps, or a
TimescalePupilwith the keyword arguments (e.g.,params={"fast_sd": 5.0}; default: the centre of the general prior of the timescale model).- Return type:
- 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:
- Returns:
the data, with the ground truth (
d.truth) and the simulation with the seed that was used (d.simulation)