view#

pypillometry.view(data, variables=None, eyes=None, time=None, overlay=None, overlay_pupil=None, overlay_x=None, overlay_y=None, extra_plots=None, colors=None, highlight=None, highlight_color='lightblue', show_layers=False, layers_kw=None, show_bands=True, overlay_behind=None, show_overview=True, marks=None)[source]#

View eye-tracking data or numpy arrays with GPU-accelerated rendering.

Opens an interactive viewer window using VisPy for fast GPU-based rendering. Suitable for long recordings (60+ minutes at 1000 Hz).

Viewer showing pupil size and gaze of both eyes

See GPU-Accelerated Viewer (pp.view) for more examples.

Parameters:
  • data (EyeData, ndarray, list of ndarrays, or dict) –

    Data to view. Supports multiple input types:

    • EyeData object: Eye-tracking data with tx attribute and dictionary-like access to modalities (left_pupil, right_x, etc.)

    • ndarray or MaskedArray: Single array displayed as one plot

    • list of arrays: Multiple arrays overlaid in one plot with different colors

    • dict of arrays: Keys become plot labels (y-axis), values are arrays or lists of arrays. Example: {"upper": [x, y], "lower": z} creates two subplots with x,y overlaid in “upper” and z in “lower”

  • variables (list of str, optional) – For EyeData objects only. Filter which modalities to display: ‘pupil’, ‘x’, ‘y’, other variables of the eyes (e.g., "pupilsmooth" for data["left_pupilsmooth"], one subplot with all eyes) and channels in data.aux (see EyeData.aux). Default: show pupil, x and y (no other variables of the eyes and no channels of data.aux). A name that is not a variable of the eyes is looked up in data.aux: the channel with this name, or all channels whose name starts with <name>_ or ends with _<name> (e.g., “distance”: left_distance, right_distance), shown together in a subplot below the eyes (highlight key 'extra_<name>'); channels of eyes not in eyes are left out. Names found in neither are skipped with a warning. Example: variables=['pupil', 'distance'], variables=['pupil', 'pupilsmooth'].

  • eyes (list of str, optional) – For EyeData objects only. Filter which eyes to display. Example: eyes=['left'] shows only left eye data. If not provided, all available eyes are detected and displayed.

  • time (ndarray, optional) – Time vector for raw array viewing. If not provided, uses sample index (0, 1, 2, …). Should have same length as data arrays. Ignored for EyeData objects, where data.tx (converted to seconds) is used.

  • overlay (EyeData, dict of arrays or a list of them, optional) –

    (EyeData only) other versions of the data to overlay:

    • EyeData: e.g., with the blinks interpolated in another way; its variables are drawn on the plots of the same variable (pupil, x, y and the other shown variables), one line per eye, labelled with its name (data.name) and the eye. If its time axis differs from that of data (e.g., the raw data with a higher sampling rate or before cropping), it is interpolated linearly onto data.tx; times outside of its range and samples next to a NaN become NaN (gaps are not bridged)

    • dict {key: array}: the key (also the label) says where the array is drawn: "<eye>_<variable>" (e.g., "left_pupilsmooth") and "<variable>" (e.g., "x") on the plot of the variable; "<eye>" (e.g., "left") on the pupil plot (or on the only plot, if only one variable is shown); other keys, and variables without a plot of their own (e.g., "pupilsmooth" with variables="pupil"), on the pupil plot

  • overlay_pupil (dict, optional) –

    (EyeData only) Additional timeseries to overlay on the pupil plot. Keys are labels for legend, values are either:

    • str: name of data in eyedata.data (e.g., ‘left_pupil_filtered’)

    • array-like: timeseries of same length as eyedata

    Overlays with an unknown key or a wrong length are skipped with a warning.

  • overlay_x (dict, optional) – (EyeData only) Additional timeseries to overlay on the gaze X plot.

  • overlay_y (dict, optional) – (EyeData only) Additional timeseries to overlay on the gaze Y plot.

  • extra_plots (dict, optional) – (EyeData only) Additional numpy arrays to display as separate subplots below the EyeData variables. Keys become subplot labels (y-axis), values are arrays or lists of arrays. Arrays must have the same length as the EyeData. Example: extra_plots={"velocity": vel, "custom": [a, b]}

  • colors (dict, optional) –

    Colors of the traces, {name: color}, with any color vispy understands (a name like "lightgray", "#808080" or an RGB(A) tuple); the other traces keep their default colors. Names are

    • channels of the eyes: the channel ("left_pupil") or the eye ("left", all channels of the eye)

    • overlays: their label, i.e., the key in overlay or overlay_pupil etc.; for an EyeData object in overlay its label ("<name> <eye>") or its name (data.name, all eyes)

    • arrays (extra_plots, channels in data.aux and raw arrays): the legend name ("<label> #<i>", the channel name) or the plot label (all arrays of the plot)

    A key that names several traces (e.g., "left" for the left eye and an overlay with the key "left") colors all of them; keys that name no trace are ignored with a warning. Samples in masked periods are drawn in a lighter version of the color. Example: colors={"left_pupil": "lightgray", "smooth": "black"}.

  • overlay_behind (str or list of str, optional) – (EyeData only) overlays drawn behind the data instead of on top of it (e.g., the raw data under a reconstruction): their labels or, for an EyeData object in overlay, its name (all eyes), as in colors. Names that match no overlay are ignored with a warning.

  • highlight (Intervals or dict, optional) –

    Intervals to highlight in the plots. Can be:

    • An Intervals object (applied to all plots)

    • A dict mapping plot key to Intervals objects; keys are ‘pupil’, ‘x’, ‘y’ and 'extra_<label>' for extra_plots (EyeData), or the plot labels (arrays). Keys like 'left_pupil' (e.g. from get_blinks()) go to the plot of the variable; the intervals of both eyes are shown together.

    Intervals in time units are converted to seconds; Intervals in sample indices (units="samples") are placed using the time vector. For raw arrays without time, the x-axis is in sample indices and only Intervals in sample indices can be shown.

  • highlight_color (str, optional) – Color for highlighted regions (default: ‘lightblue’)

  • show_layers (bool, optional) – (EyeData only) start with a panel at the bottom that shows the mask layers of the shown channels (blinks, interpolated samples, user masks, excluded periods, …) and the samples that are unusable under the default mask policy, one row each (as plot_masked()); each channel has a lane in each row. The L key shows or hides the panel (also when the viewer was started without it); the other plots take its space while it is hidden. Default False.

  • layers_kw (dict, optional) – (EyeData only) options of the layer panel: layers, policies, show_nan and colors (see plot_masked())

  • show_bands (bool, optional) – (EyeData only) start with the uncertainty bands shown: a shown channel <eye>_V has a band if <eye>_V_lower and <eye>_V_upper exist (e.g., from TimescaleModel.store(interval=...)), drawn as a light area in the color of its line (it does not change the y-range); the limits are then not shown as variables of their own. Overlays have bands too: the variables V_lower and V_upper of an EyeData object, the arrays <key>_lower and <key>_upper of a dict, or <key>_lower and <key>_upper in the data for a key in overlay_pupil etc. The B key shows or hides the bands. Default True.

  • show_overview (bool, optional) – start with the overview band at the bottom of the window: the whole recording with the signal of the first plot (all its arrays, each scaled into the band), a bar with the unusable samples (EyeData: under the default mask policy in any of the shown channels; arrays: the masked samples), ticks at the events, the highlighted regions of the first plot and the current view as a framed rectangle. A click into the band centers the view there (same width). The V key shows or hides the band. Default True.

  • marks (str, Intervals, array or dict, optional) –

    things to find in the recording, e.g. the output of an artifact detection: each set of marks is a thin lane in a strip above the plots and in the overview band, and an entry in the legend. A set is

    • the name of a mask layer (EyeData only, e.g. "blink"): where it is set in any of the shown channels (pupil, x, y and the variables in variables; recording-wide layers such as "excluded" everywhere)

    • an Intervals object (placed as in highlight)

    • a boolean array with one value per sample

    A dict {name: set} gives several sets (e.g. the dict of get_blinks()); a single set is named after the layer, the label of the Intervals or "marks". The colors are those of the layers or in turn from a palette; colors can give them by name. The K key makes the next set the active one (its name is framed), N and P center the next and previous mark of the active set (same width of the view).

Return type:

Optional[Dict[str, Intervals]]

Returns:

If regions were selected (S key, then drag with the left mouse button), returns a dict mapping plot key (same keys as for highlight) to Intervals objects containing the selected regions with units='sec'; for raw arrays without time the values are sample indices (units="samples"). Returns None if no selections were made.

Raises:
  • ValueError – If arrays have different lengths.

  • TypeError – If data type is not supported.

Notes

Keyboard controls:

  • Left/Right arrows: Pan 10% of view

  • Up/Down arrows: Zoom in/out (20%/25%)

  • PgUp/PgDn: Pan 50% of view

  • Home/End: Jump to start/end

  • Space: Reset to full view

  • +/-: Zoom in/out

  • Mouse wheel: Zoom X-axis around the mouse position

  • Shift + Up/Down, Shift + mouse wheel: Zoom Y-axis of the plot under the mouse (with robust y-limits, Shift + Up/Down divides/multiplies the number of SDs of that plot by 1.25, within 1-20)

  • Shift + Space: Reset Y-axis of the plot under the mouse

  • Y: Y-limits from the minimum and maximum of the data in the view (start) or robust ones: per array (data and overlays), the local level of the view (local_level() with windows of 1/64 to 1/8 of the view, from the usable samples, at most 5000 of them) minus 4 robust SDs of the residuals below their median, plus 4 of those above (both in the view), but not beyond the minimum and maximum of the data in the view; 5% padding

  • M: Toggle mask regions (EyeData only)

  • L: Show/hide the panel with the mask layers (EyeData only)

  • B: Show/hide the uncertainty bands (EyeData only)

  • O: Toggle event markers (EyeData only)

  • V: Show/hide the overview band (click into it to go there)

  • K: Next set of marks; N/P: center the next/previous mark of the set

  • S: Enter/exit selection mode (drag to mark a region)

  • D/Backspace: Remove last selection

  • H/?: Show help

  • Q/Esc: Close viewer (Esc first leaves selection mode)

Examples

View EyeData:

>>> import pypillometry as pp
>>> data = pp.EyeData.from_eyelink('recording.edf')
>>> pp.view(data)
>>> pp.view(data, variables=['pupil'])  # Only show pupil plots
>>> pp.view(data, eyes=['left'])  # Only show left eye data
>>> pp.view(data, variables=['pupil', 'distance'])  # with channels in aux
>>> pp.view(data, show_layers=True)  # with the mask layers

View numpy arrays:

>>> import numpy as np
>>> x = np.random.randn(1000)
>>> y = np.random.randn(1000)
>>> pp.view(x)  # Single array
>>> pp.view([x, y])  # Multiple arrays in one plot
>>> pp.view({"Signal 1": x, "Signal 2": y})  # Two separate plots
>>> pp.view({"upper": [x, y], "lower": x + y})  # Complex layout

With time vector:

>>> t = np.linspace(0, 10, 1000)  # 10 seconds
>>> pp.view(x, time=t)

EyeData with overlays, e.g. two interpolations of the blinks:

>>> mahot = data.pupil.blinks_interpolate(inplace=False)
>>> kalman = data.pupil.blinks_interpolate(method="kalman", inplace=False)
>>> pp.view(mahot, overlay=kalman, variables="pupil")
>>> smoothed = np.convolve(data['left_pupil'], np.ones(100)/100, 'same')
>>> pp.view(data, overlay_pupil={'smoothed': smoothed})

A smoothed signal on top of the raw signal in light gray:

>>> pp.view(data, variables="pupil", overlay={"smoothed": smoothed},
...         colors={"left_pupil": "lightgray", "smoothed": "black"})