HeadMountedEyeData#

class pypillometry.HeadMountedEyeData(time=None, left_x=None, left_y=None, left_pupil=None, right_x=None, right_y=None, right_pupil=None, both_x=None, both_y=None, aux=None, scene_video=None, scene_video_offset=0.0, scene_size=None, fill_time_discontinuities=True, keep_orig=False, **kwargs)[source]#

Bases: EyeData

Data from a head-mounted eye tracker (eye-tracking glasses).

An EyeData object (all its methods work) with the additional data of such trackers:

  • the gaze position is the point at which the person looks in the video of the scene camera: both_x and both_y in pixels of the video (one position for both eyes, y pointing down)

  • aux: channels that do not belong to an eye, with one value per sample (e.g., the motion sensors gyro_x, acc_x, mag_x). They are cut, downsampled and saved together with the data.

  • the scene video: the object stores the name of the video file (scene_video), not the video itself

  • the namespace d.scene (SceneNamespace) with methods for the scene video and the motion sensors, and the plot d.plot.plot_scene_scanpath()

The camera moves with the head, so there is no screen: an experimental setup and the methods that need one (e.g., the correction of the foreshortening) do not apply.

Parameters:
  • time (np.ndarray or None) – timing array (in ms), see EyeData

  • left_x (np.ndarray or None) – data of the left and right eye (see EyeData); at least one of these channels must be provided

  • left_y (np.ndarray or None) – data of the left and right eye (see EyeData); at least one of these channels must be provided

  • left_pupil (np.ndarray or None) – data of the left and right eye (see EyeData); at least one of these channels must be provided

  • right_x (np.ndarray or None) – data of the left and right eye (see EyeData); at least one of these channels must be provided

  • right_y (np.ndarray or None) – data of the left and right eye (see EyeData); at least one of these channels must be provided

  • right_pupil (np.ndarray or None) – data of the left and right eye (see EyeData); at least one of these channels must be provided

  • both_x (np.ndarray or None) – gaze position in the scene video (pixels); both or neither

  • both_y (np.ndarray or None) – gaze position in the scene video (pixels); both or neither

  • aux (Optional[dict]) – additional channels with one value per sample: name -> array. The names have two parts joined by _ (e.g., "gyro_x").

  • scene_video (Optional[str]) – filename of the scene video

  • scene_video_offset (float) – time of the first frame of the scene video on the clock of the data (ms); default 0

  • scene_size (Optional[tuple]) – width and height of the scene video in pixels

  • **kwargs – other parameters of EyeData (e.g., sampling_rate, events, name, info)

Examples

>>> import numpy as np
>>> import pypillometry as pp
>>> rng = np.random.default_rng(1)
>>> d = pp.HeadMountedEyeData(time=np.arange(0, 1000, 10),
...                           left_pupil=rng.normal(5, 0.1, size=100),
...                           both_x=rng.uniform(0, 1920, size=100),
...                           both_y=rng.uniform(0, 1080, size=100),
...                           aux={"gyro_x": rng.normal(size=100)},
...                           scene_size=(1920, 1080))
>>> d.eyes, list(d.aux)
(['left', 'both'], ['gyro_x'])

Methods

add_events

Add events to the events of the dataset.

add_to_history

Add event to history.

blink_stats

Return statistics on blink durations.

clear_layer

Clear a mask layer (e.g., "blink") for the selected channels.

copy

Make and return a deep-copy of the eyedata object.

copy_eye

Copy an eye (all its variables or only variables) to a new eye.

copy_variable

Copy a variable (of all eyes or of eyes) to a new name.

crop

Crop the data to the time range from start to end.

downsample

Simple downsampling scheme using mean within the downsampling window.

drop_data

Drop specified eyes and/or variables from the data.

drop_original

Drop original dataset from record (e.g., to save space).

exclude_intervals

Exclude periods that are not part of the analysis (e.g., breaks or the calibration at the start).

excluded_duration

Total duration of the excluded periods within the data.

fill_time_discontinuities

Find gaps in the time-vector and fill them in.

from_eyelink

Reads an eyedata object from an Eyelink file.

from_file

Reads a EyeData object from a pickle or HDF5 file (see write_file()).

from_gazepoint

Read a recording of a GazePoint eye tracker (e.g., GP3).

from_tobii_prolab

Reads a recording of Tobii Pro Glasses from a data export of Tobii Pro Lab.

get_blinks

Get blinks as a dict of Intervals (one per eye/variable).

get_duration

Return duration of the dataset in units specified.

get_epochs

Return the time windows around events (Epochs).

get_excluded

Return the excluded periods (see exclude_intervals()).

get_included

Return the periods that are not excluded (see exclude_intervals()).

get_interpolated

Get the interpolated stretches as a dict of Intervals (one per eye/variable).

get_intervals

Return the spans between two kinds of events (Intervals).

get_layer_intervals

Get the runs of a mask layer (e.g., "offscreen") as a dict of Intervals.

get_segments

Cut the data around events into segments of equal length.

get_size

Return the size of the object in bytes.

get_values

Values of a channel with NaN where the sample is unusable under policy.

interpolate_intervals

Interpolate data within specified intervals.

keep_intervals

Exclude everything outside the given periods (e.g., keep only the task blocks or the fMRI run).

layer_stats

Statistics of the mask layers: how often and how long each channel is marked by each layer.

local_level

The local level of a channel: a robust, multi-scale moving median.

mask

Mask of a channel under a mask policy (True: unusable sample).

mask_as_intervals

Convert masks to Intervals objects.

mask_intervals

Apply Intervals as masks to selected data.

mask_islands

Mask islands: short stretches of usable data between unusable ones.

mask_signal

Mask the data where a quality signal is out of range.

merge_eyes

Merge data from both eyes into a single variable.

merge_masks

Merge masks of all variables into a single joint mask.

nevents

Return number of events in data.

print_history

Pretty-print the history of the current dataset (which manipulations where done on it).

quality_report

Report the quality of the data.

remove_intervals

Remove the data in the given periods (e.g., breaks) and join the rest.

rename_eye

Rename an eye (all its variables or only variables).

rename_variable

Rename a variable (of all eyes or of eyes).

reset_time

Resets time so that time t0 becomes time zero.

scale

Scale the signal: subtract center and divide by scale.

set_blinks

Set blinks for specified eyes and variables (in-place).

set_events

Replace the events of the dataset (in-place).

set_experimental_setup

Set or update the experimental setup geometry (in-place).

split_excluded

Split the data at the excluded periods (see exclude_intervals()).

stat_per_event

Return result of applying a statistical function to data in a given interval relative to event-onsets.

summary

Return a summary of the dataset as a dictionary.

unscale

Scale back to original values using either values provided as arguments or the values stored in params["scale"] by scale().

write_file

Save to file (using write_file()).

Details

gaze#

alias of GazeNamespace

plot#

alias of HeadMountedPlotNamespace

pupil#

alias of PupilNamespace

scene#

alias of SceneNamespace

Reads an eyedata object from an Eyelink file.

Overloads:

All “messages” are stored as events (can be filtered later) and it tries to be smart to detect different information from the EDF file. Spatial calibration/validation data is automatically parsed and stored in the calibration attribute as SpatialCalibration objects. Eyelink codes missing pupil samples (e.g., during blinks) as 0; these are converted to NaN (and therefore masked).

However, the EDF file may contain other information of interest, e.g., eyelink-detected saccades, etc. If you need more control, use the “eyelinkio” package directly and create the object manually.

Reading EDF files is slow (about a minute for a 90 MB file). Save the object with write_file() and read it with from_file() later, or convert the files once with the command-line program edf2pypil.

Parameters:
  • fname (str) – filename of the EDF file, HTTP(S) URL or SSH URL (ssh://server/folder/file.edf, see pypillometry.io.fetch_url())

  • return_edf_obj (bool) – if True, return a tuple with the eyedata object and the object returned by the “eyelinkio” package; if False (default), return only the eyedata object

  • remove_eyelink_triggers (bool) – if True (default), remove all Eyelink triggers from the events (related to eye-tracker settings, calibration, validation etc)

  • **kwargs – additional arguments passed to pypillometry.io.read_eyelink() (e.g., cache_file, cache_dir, cache_layout, autodelete, session)

Return type:

EyeData or tuple

Returns:

object of the class this method is called on (e.g., EyeData), or tuple with that object and the object returned by the “eyelinkio” package

Examples

>>> import pypillometry as pp
>>> d = pp.EyeData.from_eyelink('data.edf')
>>> # Access calibration data
>>> print(d.calibration['left'])
<SpatialCalibration: left eye, HV9, n=9, error=0.45±0.23° (max=0.79°)>
classmethod from_file(fname, **kwargs)#

Reads a EyeData object from a pickle or HDF5 file (see write_file()). Use as pypillometry.EyeData.from_file("yourfile.pypil").

The file is read with pypillometry.io.read_file(), so fname can also be an HTTP(S) or SSH URL. Files written by older versions of pypillometry are upgraded to the current version. Pickle files can run arbitrary code when they are read: only read them from sources you trust (HDF5 files do not run code).

Parameters:
  • fname (str) – filename (or URL)

  • **kwargs – passed to pypillometry.io.read_file() (e.g., cache_file, cache_dir, cache_layout, autodelete, session)

Return type:

Self

Returns:

the object stored in the file (its class is the one that was stored, independent of the class this method is called on)

classmethod from_gazepoint(fname, pupil='mm', gaze=True, camera=True, screen_resolution=None, label_prefix=None, keep_initial_label=False, **kwargs)#

Read a recording of a GazePoint eye tracker (e.g., GP3).

The file is read with pypillometry.io.read_gazepoint() (a table with the columns of the GazePoint Open Gaze API). Each change of the label in the column USER is an event.

The time of the samples comes from the sample counter CNT (see read_gazepoint()); samples that the eye tracker lost (gaps in CNT) are NaN (masked).

GazePoint marks samples without a pupil in two ways: LPV/RPV is 0 if the pupil was not found in the camera image (e.g., during a blink), LPUPILV/RPUPILV is 0 if the pupil size in mm could not be computed. During blinks, LPUPILV often stays 1 and the last pupil size is repeated, so that blinks look like flat stretches instead of gaps. Pupil samples are therefore only kept where both flags are 1 (pupil="px": where LPV is 1); all other samples are NaN (masked). Gaze samples are kept where LPOGV/RPOGV is 1.

With camera (default), the measurements of the camera are stored in aux for each eye (e.g., for left), where the pupil was found in the camera image (LPV is 1):

  • left_camx, left_camy: position of the pupil centre in the camera image (LPCX, LPCY; fraction of the image, 0-1). The eye tracker sometimes follows another dark spot (e.g., the frame of glasses) or the other eye; the pupil is then far from its usual position.

  • left_pupilpx (with pupil="mm") or left_pupilmm (with pupil="px"): the pupil size in the other unit (in mm only where LPUPILV is 1). The size in mm is the size in pixels times a factor that follows the distance of the head from the camera; jumps of the factor that the distance does not explain indicate artifacts.

  • left_distance: distance of the eye from the camera (mm, LEYEZ), only where LPUPILV is also 1: without a valid model of the eye (LPUPILV is 0), LEYEZ holds meaningless values (e.g., 2-3 m).

Parameters:
  • fname (str) – filename of the recording

  • pupil (str) – "mm" (default): pupil diameter in mm (LPUPILD, RPUPILD; in steps of 0.01 mm, the resolution of the file); "px": pupil diameter in pixels of the camera image (LPD, RPD; finer, but the scale differs between participants)

  • gaze (bool) – if True (default), read the gaze position of each eye (LPOGX, LPOGY, …)

  • camera (bool) – if True (default), store the measurements of the camera in aux (see above)

  • screen_resolution (Optional[Tuple[int, int]]) – screen resolution (width, height) in pixels; if given, the gaze position is converted to pixels and the resolution is stored in the experimental setup. Otherwise, the gaze position is a fraction of the screen (0-1, as in the file)

  • label_prefix (Optional[str]) – prefix that is removed from the event labels (e.g., "VAR ")

  • keep_initial_label (bool) – if False (default), the label of the first sample is not an event (it was sent before the recording started)

  • **kwargs – additional arguments passed to the constructor (e.g., name, keep_orig)

Return type:

Self

Returns:

object of the class this method is called on

Examples

>>> import pypillometry as pp
>>> d = pp.EyeData.from_gazepoint("rec.tsv", gaze=False)
>>> d.aux["left_camx"]
classmethod from_tobii_prolab(fname, video=None, video_offset=None, remove_sync_events=True, **kwargs)[source]#

Reads a recording of Tobii Pro Glasses from a data export of Tobii Pro Lab.

The export is read with pypillometry.io.read_tobii_prolab() (Excel files require the optional package openpyxl). The object holds

  • left_pupil, right_pupil: pupil diameter in mm

  • both_x, both_y: gaze position in the scene video (pixels)

  • in aux: the 3D gaze point in mm from the scene camera (gaze3d_x, gaze3d_y, gaze3d_z) and, interpolated to the times of the eye-tracker samples, the gyroscope (gyro_x, …, deg/s), the accelerometer (acc_x, …, m/s²) and the magnetometer (mag_x, …, µT)

  • the events of the export

  • the description of the recording (participant, date, …) in info

Samples without valid data are empty in the export; they are NaN (and therefore masked). Gaps in the samples are filled in.

Parameters:
  • fname (str) – filename of the export (.xlsx or tab-separated text)

  • video (Optional[str]) – filename of the scene video; default: the file with the name of the export and the extension .mp4, if it exists

  • video_offset (Optional[float]) – time of the first frame of the video on the clock of the data (ms); default: the first timestamp of the export (the video that Tobii Pro Lab exports covers the same period as the data)

  • remove_sync_events (bool) – if True (default), remove the events of the sync port (SyncPortOutHigh, SyncPortInLow, …) from the events

  • **kwargs – additional arguments passed to the constructor (e.g., name, keep_orig)

Return type:

Self

Returns:

object of the class this method is called on

Examples

>>> import pypillometry as pp
>>> d = pp.HeadMountedEyeData.from_tobii_prolab("rec.xlsx")
>>> d.plot.plot_scene_scanpath((10, 12))
add_events(events, inplace=None)#

Add events to the events of the dataset.

The new events are merged with the existing ones and all events are sorted by onset (events at the same time keep their order, existing ones first). Metadata columns that only the existing or only the new events have get missing values (NaN or “”) for the other events. Events from a behaviour log on another clock must be mapped to the eye-tracker clock with sync_clocks() first; a warning is given for events that are marked as being on another clock (needs_sync, e.g., from from_table()).

Parameters:
  • events (Events) – the events to add (converted to ms if needed)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the added events (self or a copy, depending on inplace)

Raises:
  • TypeError – if events is not an Events object

  • ValueError – if an onset is outside the time range of the data

See also

set_events

replace all events

Examples

Events from a behaviour log behav (a table with times in sec, already on the eye-tracker clock; otherwise, see sync_clocks()):

>>> ev = pp.Events.from_table(behav, ["stim_on", "response"], units="sec",
...                           needs_sync=False)
>>> d = d.add_events(ev)
add_to_history(event)#

Add event to history.

Usually called by the keephistory decorator.

Parameters:

event (dict) – description of the operation with keys “funcstring” (printable call) and “funcname” (method name), optionally “note” (e.g., the thresholds that the method used)

Return type:

None

Return statistics on blink durations.

Uses the blinks stored for the “pupil” variable of each eye; a shortcut for the rows "blink" of layer_stats(), as a dict. If partial blinks were detected (see blinks_detect_partial()), their statistics are under the key "partial" of each eye.

Parameters:
  • eyes (list) – eye(s) to consider; if empty, all available eyes

  • units (str) – Units for statistics: “ms”, “sec”, “min”, or “h”. Default “ms”.

Return type:

dict[str, dict[str, Any]]

Returns:

stats dict (number, mean, sd, min, max and total duration of blinks; number 0 and NaN without blinks) for each eye with pupil data, with keys like “left_pupil”; with partial blinks, the same for them under "partial"

clear_layer(name, eyes=[], variables=[], inplace=None)#

Clear a mask layer (e.g., "blink") for the selected channels.

Clearing "blink" removes the blinks and their mask (e.g., to undo d.pupil.blinks_detect()). "excluded" is a recording-wide layer: clearing it removes the excluded periods (eyes and variables are ignored).

Parameters:
  • name (str) – name of the layer

  • eyes (str | list) – eye(s); if empty, all available eyes

  • variables (str | list) – variable(s); if empty, all available variables

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object without the layer (self or a copy, depending on inplace)

copy(new_name=None)#

Make and return a deep-copy of the eyedata object.

Parameters:

new_name (Optional[str]) – New name for the copy. If None, “_copy” is appended to the original name.

Return type:

Self

Returns:

deep copy of the object (same class as the original)

copy_eye(old, new, variables=[], overwrite=False, inplace=None)#

Copy an eye (all its variables or only variables) to a new eye.

Values, mask layers and the parameters of scale() are copied; so are the limits of an uncertainty band (<old>_<var>_lower and _upper). Typical use: a merged eye "mean" in a recording with only one usable eye, so that all recordings of a study have the same variables (for two eyes, see merge_eyes()).

Parameters:
  • old (str) – the eye (e.g., "left")

  • new (str) – the name of the copy (e.g., "mean"; without _)

  • variables (str | list) – only these variables; default all variables of the eye (including gaze)

  • overwrite (bool) – replace the variables of eye new if they exist (else an error)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the copy (self or a copy, depending on inplace)

Raises:
  • KeyError – if the eye (or one of variables of it) does not exist

  • ValueError – if a variable of eye new exists (and not overwrite), or new is not a valid eye name

See also

rename_eye

rename the eye instead

merge_eyes

merge two eyes

copy_variable

copy a variable within the eyes

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d.copy_eye("left", "mean", variables="pupil", inplace=False)
>>> d.eyes
['left', 'right', 'mean']
copy_variable(old, new, eyes=[], overwrite=False, inplace=None)#

Copy a variable (of all eyes or of eyes) to a new name.

Values, mask layers and the parameters of scale() are copied; so are the limits of an uncertainty band (<eye>_<old>_lower and _upper). Typical use: keep the original before a step replaces the variable, e.g., d.copy_variable("pupil", "pupilraw") before storing a reconstruction as "pupil". For the channels in aux, see EyeDataDict.copy_key.

Parameters:
  • old (str) – the variable (e.g., "pupil")

  • new (str) – the name of the copy (e.g., "pupilraw")

  • eyes (str | list) – only these eyes; default all eyes with the variable

  • overwrite (bool) – replace the variable new if it exists (else an error)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the copy (self or a copy, depending on inplace)

Raises:
  • KeyError – if the variable does not exist (for an eye in eyes)

  • ValueError – if new exists (and not overwrite)

See also

rename_variable

rename the variable instead

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d.copy_variable("pupil", "pupilraw", inplace=False)
>>> d.data.variables
['x', 'y', 'pupil', 'pupilraw']
crop(start=-inf, end=inf, units='ms', inplace=None)#

Crop the data to the time range from start to end.

The result contains all data (and events) between start and end (inclusive), e.g. d.crop(3*u.min, 5*u.min) or d.crop("3 min", "5 min"). start and end refer to the values of the time-vector (not to the time since the start of the recording). Masks are kept; stored blinks (in sample indices) are shifted and cut to the new range.

Parameters:
  • start (float) – start for new dataset; default: beginning of the data

  • end (float) – end of new dataset; default: end of the data

  • units (str) – time units of start and end if they are plain numbers (one of “ms”, “sec”, “min”, “h”); default “ms” (the units of the time vector).

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the shortened object (self or a copy, depending on inplace)

Raises:

ValueError – if start is after end or there are no samples between them

See also

remove_intervals

remove periods (e.g., breaks) and join the rest

downsample(fsd, dsfac=False, policy='default', inplace=None)#

Simple downsampling scheme using mean within the downsampling window.

All data fields and the time-vector are downsampled simultaneously. See pypillometry.signal.baseline.downsample(). The samples that are unusable under the mask policy are left out of the window means (by default, interpolated samples are used, see mask()). A layer is kept for a new sample if it covers more than half of its window. A new sample whose window has no usable sample holds the mean of the stored values (NaN only if they are NaN) and stays unusable.

The new sampling rate is fs/factor, the rate of the decimated data. It differs from fsd if fs/fsd is not an integer (e.g., 1000 Hz with fsd=300 gives factor 3 and 333.3 Hz).

Parameters:
  • fsd (float) – new sampling-rate (in Hz) or decimate-factor

  • dsfac (bool) – if False (default), fsd is the requested sampling rate (the decimate factor is int(fs/fsd); a warning is logged if fs/fsd is not an integer); if True, fsd is the decimate factor (a positive integer)

  • policy (str, MaskPolicy or list of str) – mask policy that decides which samples are used for the window means (see mask()); default "default"

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the downsampled object (self or a copy, depending on inplace)

Raises:
  • TypeError – if fsd is not a number

  • ValueError – if the sampling rate fsd is not above 0 and at most fs, or the decimate factor is not a positive integer

drop_data(eyes=[], variables=[], inplace=None)#

Drop specified eyes and/or variables from the data.

All data of the given eyes and all data of the given variables are dropped (together with their mask layers). Everything else is kept (events, excluded periods, parameters, history, experimental setup, calibration); the class of the object does not change.

Parameters:
  • eyes (list) – Eyes to drop (e.g., [‘left’] or [‘right’] or [‘left’, ‘right’]); if empty, no eye is dropped

  • variables (list) – Variables to drop (e.g., [‘pupil’] or [‘x’, ‘y’]); if empty, no variable is dropped

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object without the specified data (self or a copy, depending on inplace)

Raises:
  • KeyError – If an eye or variable does not exist.

  • ValueError – If dropping would result in no data remaining.

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> # Drop left eye data
>>> right_only = d.drop_data(eyes=["left"], inplace=False)
>>> right_only.eyes
['right']
>>> # Drop pupil data, keep only gaze
>>> gaze_only = d.drop_data(variables=["pupil"], inplace=False)
>>> # Drop right eye and pupil data
>>> left_gaze = d.drop_data(eyes=["right"], variables=["pupil"], inplace=False)
>>> sorted(left_gaze.data.keys())
['left_x', 'left_y']
drop_original(inplace=None)#

Drop original dataset from record (e.g., to save space).

Sets the original attribute (stored when the object was created with keep_orig=True) to None.

Parameters:

inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object without the original data (self or a copy, depending on inplace)

exclude_intervals(intervals, inplace=None)#

Exclude periods that are not part of the analysis (e.g., breaks or the calibration at the start).

The periods are stored with the object as the recording-wide "excluded" layer (see get_excluded()), which masks all variables (also those added later), so that functions that ignore masked data (e.g., scale(), get_segments()) also ignore the excluded periods. Unlike other masked data (blinks, artifacts), excluded periods are not treated as missing data: blink detection cuts blinks at them, and blinks that end in an excluded period are not interpolated. Blinks detected before keep their layer.

The layer moves with the samples (crop(), downsample(), remove_intervals(), …). Calling the method again adds to the excluded periods; clear_layer("excluded") removes them.

Parameters:
  • intervals (Intervals, Epochs or list of tuple) – the periods to exclude: an Intervals object (e.g., from get_intervals(); in time units or sample indices), Epochs or a list of (start, end) tuples (in ms, or with units, e.g., [(0, 2 * u.min)]; "<start>" and "<end>" stand for the start and end of the recording, e.g., [(10 * u.min, "<end>")]); ends are exclusive

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the excluded periods (self or a copy, depending on inplace)

See also

keep_intervals

exclude everything outside the given periods

Examples

>>> breaks = d.get_intervals(start="break_start", end="break_end", units="ms")
>>> d = d.exclude_intervals(breaks)
>>> d = d.exclude_intervals([(0, 2 * u.min)])
excluded_duration(units='ms')#

Total duration of the excluded periods within the data.

Parameters:

units (str) – units of the result (“ms” (default), “sec”, “min”, “h” or “samples”)

Return type:

float

Returns:

the excluded time (number of excluded samples / sampling rate)

fill_time_discontinuities(yval=nan, print_info=True, inplace=None)#

Find gaps in the time-vector and fill them in.

A gap is a step between consecutive time points that is larger than twice the median step. New time points are inserted into each gap at the median step size and all data variables are set to yval at these new time points; they are masked as missing. Existing masks are kept and stored blinks (in sample indices) are moved to the new sample positions. This is called by the constructor when fill_time_discontinuities=True.

Parameters:
  • yval (float, optional) – value used for the data in the filled-in gaps; default NaN, so the filled-in samples are masked as missing data (other values: masked by the "user" layer)

  • print_info (bool, optional) – if True (default), log the number of gaps that are filled in

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object without gaps (self or a copy, depending on inplace)

Get blinks as a dict of Intervals (one per eye/variable).

The blinks are the runs of the "blink" layer (blinks that overlap or touch are one blink), also those in or next to an excluded period (see exclude_intervals()). If no blinks are stored for an eye/variable, an empty Intervals object is returned for it.

Parameters:
  • eyes (str | list) – Eye(s) to get blinks for; if empty, all available eyes.

  • variables (str | list) – Variable(s) to get blinks for; if empty, all available variables.

  • units (str) – Units for intervals: “ms” (default), “sec”, “min”, “h”, or “samples” for sample indices

Return type:

dict[str, Intervals]

Returns:

one Intervals object per existing eye/variable combination, keys like “left_pupil” (also for a single eye and variable)

Raises:

KeyError – if a requested eye/variable combination does not exist (see select())

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short").pupil.blinks_detect()
>>> blinks = d.get_blinks("left", "pupil")["left_pupil"]
>>> blinks_sec = d.get_blinks("left", "pupil", units="sec")["left_pupil"]
>>> blinks_dict = d.get_blinks(["left", "right"], "pupil")
>>> list(blinks_dict)
['left_pupil', 'right_pupil']
>>> blinks_idx = blinks.to_units("indices", d)
get_duration(units='ms')#

Return duration of the dataset in units specified.

Parameters:

units (str, optional) – unit one of “ms” (default), “sec”, “min”, “h” or “samples”

Return type:

float

Returns:

duration of dataset in specified units

get_epochs(event_select, window, units=UNSET, label=None, exact=False, **kwargs)#

Return the time windows around events (Epochs).

Selects events, e.g., all stimuli, and one time window around each of them, e.g., from 200 ms before to 1000 ms after the stimulus. The result is the input of get_segments() (event-related pupil dilations) and can be used wherever intervals are taken (e.g., stat_per_event(), mask_intervals()). For spans between two different events (e.g., from trial start to response), use get_intervals().

Parameters:
  • event_select (str, function or Events) –

    which events to select:

    • str: all events whose label contains the string (or is equal to it, if exact is True); "<start>" and "<end>" stand for the start and the end of the recording

    • function: applied to all labels, the events where it returns True are used

    • Events: the events of this Events object (e.g., d.events.filter(cond="easy"))

  • window (tuple (min, max) or Quantity) – time window relative to the event onset (0 is the onset; negative numbers are before it), e.g. (-200, 800) * u.ms or ("-0.2 sec", "0.8 sec"). Plain numbers are in units.

  • units (str) – units of plain numbers in window (“ms”, “sec”, “min”, “h”, or “samples” for sample indices, converted to ms with the sampling rate); default: the units of window, or “ms” for plain numbers

  • label (str | None) – label of the Epochs; if None, it is taken from event_select

  • exact (bool) – if True, a string selector matches only labels that are equal to it; if False (default), labels that contain it

  • **kwargs – passed on to the event_select function; an error is raised if it is not a function

Return type:

Epochs

Returns:

the selected events (onsets in ms, labels and metadata, see Events) and the window (in ms). Windows that extend beyond the data are not clipped.

Examples

>>> import pypillometry as pp
>>> from pypillometry import u
>>> d = pp.EyeData(time=range(10000), left_pupil=range(10000),
...                event_onsets=[2000, 6000], event_labels=["stim", "stim"])
>>> d.get_epochs("stim", (-200, 800) * u.ms)
Epochs 'stim' | 2 epochs, window (-200, 800) ms
get_excluded(units='ms')#

Return the excluded periods (see exclude_intervals()).

The periods are the runs of samples of the "excluded" layer (from the time of their first sample to the time of the sample after the last one).

Parameters:

units (str) – units of the returned intervals (“ms” (default), “sec”, “min”, “h”, or “samples” for sample indices)

Return type:

Intervals

Returns:

the excluded periods (empty if there are none)

get_included(units='ms')#

Return the periods that are not excluded (see exclude_intervals()).

These are the contiguous runs of samples outside the excluded periods (the whole recording if nothing is excluded).

Parameters:

units (str) – units of the returned intervals (“ms” (default), “sec”, “min”, “h”, or “samples” for sample indices)

Return type:

Intervals

Returns:

the included periods (end-exclusive)

get_interpolated(eyes=[], variables=[], units='ms')#

Get the interpolated stretches as a dict of Intervals (one per eye/variable).

These are the runs of the "interpolated" layer, set by d.pupil.blinks_interpolate() (interpolated blinks) and by interpolate_intervals() (any intervals). Interpolated blinks may differ from the detected blinks (get_blinks()) because:

  • Blink boundaries are refined using rates of change

  • Some blinks may be skipped if they’re too short to interpolate

If nothing was interpolated for an eye/variable, an empty Intervals object is returned for it.

Parameters:
  • eyes (str | list) – Eye(s) to get interpolated stretches for; if empty, all available eyes.

  • variables (str | list) – Variable(s) to get interpolated stretches for; if empty, all available variables.

  • units (str) – Units for intervals: “ms” (default), “sec”, “min”, “h”, or “samples” for sample indices

Return type:

dict[str, Intervals]

Returns:

one Intervals object per existing eye/variable combination, keys like “left_pupil” (also for a single eye and variable)

Raises:

KeyError – if a requested eye/variable combination does not exist (see select())

See also

get_blinks

Get detected blinks

get_layer_intervals

Get the runs of any mask layer

pypillometry.eyedata.pupil.PupilNamespace.blinks_interpolate

Interpolate blinks

get_intervals(*, start, end, window=(0, 0), units=UNSET, label=None, exact=False, **kwargs)#

Return the spans between two kinds of events (Intervals).

For example, the time from each trial start to the response, or the breaks between blocks. For one time window around single events (e.g., stimuli), use get_epochs().

Each start event is paired with the next end event after it (an end event at the same time does not count). If several start events come before the same end event, the last of them is used. Events without a partner are skipped with a warning that lists them (not for "<start>" and "<end>", which are paired with the first or last event only).

Parameters:
  • start (str or function) –

    the events at the start and at the end of the spans:

    • str: all events whose label contains the string (or is equal to it, if exact is True); "<start>" and "<end>" stand for the start and the end of the recording (the first sample and one sample past the last one, as intervals are end-exclusive)

    • function: applied to all labels, the events where it returns True are used

    For example, start="End Block", end="Start Block" gives the breaks between blocks and start="<start>", end="Start Block" the time before the first block.

  • end (str or function) –

    the events at the start and at the end of the spans:

    • str: all events whose label contains the string (or is equal to it, if exact is True); "<start>" and "<end>" stand for the start and the end of the recording (the first sample and one sample past the last one, as intervals are end-exclusive)

    • function: applied to all labels, the events where it returns True are used

    For example, start="End Block", end="Start Block" gives the breaks between blocks and start="<start>", end="Start Block" the time before the first block.

  • window (tuple or Quantity, optional) – window[0] is added to the start events and window[1] to the end events; default (0, 0): exactly the spans between them. Plain numbers are in units.

  • units (str) – units of plain numbers in window and of the returned Intervals (“ms”, “sec”, “min”, “h”, or “samples” for sample indices: each event is placed at the first sample at or after its onset); default: the units of window, or “ms”

  • label (str | None) – label of the Intervals; if None, "<start> to <end>" (for two strings)

  • exact (bool) – if True, string selectors match only labels that are equal to them; if False (default), labels that contain them

  • **kwargs – passed on to the selector functions; an error is raised if no selector is a function

Return type:

Intervals

Returns:

the spans (in units) with, per interval, the label "<start label> to <end label>", the onset of the start event and its metadata (those of the end event if start is "<start>"). Intervals that extend beyond the data are not clipped.

Examples

>>> import pypillometry as pp
>>> d = pp.EyeData(time=range(10000), left_pupil=range(10000),
...                event_onsets=[1000, 3000, 5000, 8000],
...                event_labels=["trial", "resp", "trial", "resp"])
>>> d.get_intervals(start="trial", end="resp").intervals
[(1000.0, 3000.0), (5000.0, 8000.0)]
get_layer_intervals(name, eyes=[], variables=[], units='ms')#

Get the runs of a mask layer (e.g., "offscreen") as a dict of Intervals.

Each contiguous run of samples in which the layer is set becomes one interval. See get_blinks() for the blinks and get_excluded() for the excluded periods.

Parameters:
  • name (str) – name of the layer (e.g., "blink", "interpolated", "offscreen", "divergence", "user")

  • eyes (str | list) – eye(s); if empty, all available eyes

  • variables (str | list) – variable(s); if empty, all available variables

  • units (str) – units of the intervals: “ms” (default), “sec”, “min”, “h”, or “samples” for sample indices

Return type:

dict[str, Intervals]

Returns:

one Intervals object per existing eye/variable combination, keys like “left_x” (empty Intervals where the layer is not set)

Examples

>>> d = d.gaze.mask_offscreen()
>>> d.get_layer_intervals("offscreen", variables="x")
get_segments(epochs, channels=None, name=None, policy='default', eyes=[], variables=[])#

Cut the data around events into segments of equal length.

Creates a SegmentedEyeData object with the segments of one or several channels (by default, all), cut at the same epochs; trials are selected for all channels at once (e.g., seg.filter(cond="easy")).

Parameters:
  • epochs (Epochs or Intervals) – the segments to extract: Epochs (from get_epochs(); length and time axis window[0] + arange(n) * 1000/fs from the window, parts outside the data masked) or Intervals that all have the same length (time axis from 0 at their starts)

  • channels (str or list of str, optional) – channels to extract (e.g., "left_pupil" or ["left_x", "left_y"]); if None, those of eyes and variables

  • name (str) – Name for the segmented dataset. If None, uses the label of epochs or “segments”

  • policy (str, MaskPolicy or list of str) – mask policy of the segments: the samples that are unusable under it are masked (see mask()); default "default" (interpolated samples are used)

  • eyes (str or list of str, optional) – eyes to extract if channels is None (default: all)

  • variables (str or list of str, optional) – variables to extract if channels is None (e.g., "pupil"; default: all)

Return type:

SegmentedEyeData

Returns:

Object containing the extracted segments with mask information

Raises:
  • ValueError – if epochs are Intervals of different lengths (e.g., between two events), or both channels and eyes/variables are given

  • KeyError – if a channel, eye or variable does not exist

See also

get_epochs

Windows around events (Epochs)

SegmentedEyeData

Class holding segmented data

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> epochs = d.get_epochs("F_", window=(-200, 800), units="ms")
>>> # all channels (pupil and gaze of both eyes)
>>> seg = d.get_segments(epochs)
>>> # pupil segments around the feedback events
>>> erpd = d.get_segments(epochs, variables="pupil")
>>> erpd.channels
['left_pupil', 'right_pupil']
>>> erpd.pupil.plot()
>>> # Apply baseline correction
>>> erpd_bc = erpd.pupil.baseline_correct(window=(-200, 0))
get_size()#

Return the size of the object in bytes.

Return type:

ByteSize

Returns:

Total size of the object, including data and all attributes.

get_values(eye, var=None, policy='default')#

Values of a channel with NaN where the sample is unusable under policy.

Parameters:
Return type:

ndarray

Returns:

copy of the values (float), NaN where mask() is True

interpolate_intervals(intervals, eyes=[], variables=[], method='linear', margin=(-20, 20), store_as_suffix=None, policy='default', inplace=None)#

Interpolate data within specified intervals.

This function replaces data within the specified intervals with interpolated values based on boundary points outside each interval. The interpolated samples get the "interpolated" layer (see get_interpolated()), so they are used under the default mask policy and masked under the "strict" one (see mask()). Intervals without usable boundary points on both sides are skipped with a warning.

Parameters:
  • intervals (Intervals, Epochs, list of tuple or dict) –

    Either:

    • A single Intervals (or Epochs) object or a list of (start, end) tuples (in ms, or with units): applied to all specified eyes/variables

    • A dict of Intervals (or Epochs): keys like “left_pupil”, “right_x”, etc. When dict is provided, eyes and variables are ignored.

  • eyes (str or list of str, optional) – eye(s) to interpolate; if empty, all available eyes. Ignored if intervals is a dict.

  • variables (str or list of str, optional) – variable(s) to interpolate; if empty, all available variables. Ignored if intervals is a dict.

  • method (str, default "linear") – Interpolation method. Options: “linear”, “nearest”, “zero”, “slinear”, “quadratic”, “cubic”, “previous”, “next”. Passed to scipy.interpolate.interp1d.

  • margin (tuple, default (-20, 20)) – Time window (in ms) before and after the interval to collect boundary points for interpolation, relative to the start and end of each interval: points are taken from start + margin[0] to the start and from the end to end + margin[1], so margin[0] must be <= 0 and margin[1] >= 0. Samples that are unusable under policy (masked or NaN) are not used. For higher-order methods like “cubic” or “quadratic”, more boundary points from this margin are used to fit the interpolation curve.

  • store_as_suffix (str or None, default None) – If None, replace the original data. If a string, store interpolated data in a new variable with this suffix (e.g., “_interp” creates “left_pupil_interp”).

  • policy (str, MaskPolicy or list of str) – mask policy that decides which boundary points are usable (see mask()); default "default"

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

The object with interpolated data (self or a copy, depending on inplace).

See also

mask_intervals

Apply intervals as masks without interpolation

get_blinks

Retrieve stored blink intervals

Examples

Interpolate blinks for left eye pupil data:

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short").pupil.blinks_detect()
>>> blinks = d.get_blinks(eyes="left", variables="pupil")["left_pupil"]
>>> d1 = d.interpolate_intervals(blinks, eyes=["left"], variables=["pupil"],
...                              inplace=False)

Interpolate using a dict of intervals:

>>> blinks = d.get_blinks()  # returns dict
>>> d2 = d.interpolate_intervals(blinks, inplace=False)

Store interpolated data in a new variable:

>>> d3 = d.interpolate_intervals(blinks, store_as_suffix="_interp",
...                              inplace=False)
>>> "left_pupil_interp" in d3.data
True

Use cubic interpolation with wider margin:

>>> d4 = d.interpolate_intervals(blinks, method="cubic", margin=(-50, 50),
...                              inplace=False)
keep_intervals(intervals, inplace=None)#

Exclude everything outside the given periods (e.g., keep only the task blocks or the fMRI run).

Same as exclude_intervals(intervals.complement(d)): the time before, between and after the periods is excluded (see exclude_intervals()). Periods that are already excluded stay excluded, also if they are within intervals.

Parameters:
  • intervals (Intervals, Epochs or list of tuple) – the periods to keep: an Intervals object (e.g., from get_intervals(); in time units or sample indices), Epochs or a list of (start, end) tuples (in ms, or with units; "<start>" and "<end>" stand for the start and end of the recording); ends are exclusive

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the excluded periods (self or a copy, depending on inplace)

Examples

>>> run = d.get_intervals(start="rsfMRI_ONSET", end="rsfMRI_END", units="ms")
>>> d = d.keep_intervals(run)
layer_stats(layers=None, eyes=[], variables=[], units='ms', policy='default')#

Statistics of the mask layers: how often and how long each channel is marked by each layer.

For each channel and layer: the number of stretches (runs of marked samples), their mean, SD, minimum, maximum and total duration, and the percentage of the samples that are marked. The entry "masked" of a channel counts all samples that are unusable under policy (all layers together, and NaN; a sample can be in several layers, so the percentages of the layers do not add up to it).

Stretches and percentages refer to the included time (excluded periods left out), as in the quality report (quality_report()). The excluded periods themselves are described by d.get_excluded().stats() and excluded_duration().

Parameters:
  • layers (str or list of str, optional) – layers to describe (e.g., "blink", ["offscreen", "masked"]); default: all layers that are set on a channel (a pupil channel has no "offscreen" entry, for example) and "masked"

  • eyes (str | list) – eyes to consider; if empty, all available eyes

  • variables (str | list) – variables to consider; if empty, all available variables

  • units (str) – units of the durations: “ms” (default), “sec”, “min”, “h” or “samples”

  • policy (str, MaskPolicy or list of str, optional) – mask policy of the entry "masked" (see mask()); default "default"

Return type:

RecordDict

Returns:

channel -> layer -> statistics (n, mean, sd, min, max, total_duration and units of the stretches, percent of the samples), e.g. stats["left_pupil"]["blink"]["n"]; displayed as a table with one row per channel and layer (see RecordDict)

Raises:

ValueError – if layers contains "excluded" (see above)

See also

blink_stats

the statistics of the blinks only

get_layer_intervals

the stretches of a layer as Intervals

plot.PlotNamespace.plot_masked

plot of the unusable stretches

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d | pp.pupil.blinks_detect() | pp.gaze.mask_offscreen()
>>> stats = d.layer_stats(eyes="left")
>>> {ch: list(layers) for ch, layers in stats.items()}
{'left_x': ['offscreen', 'masked'], 'left_y': ['offscreen', 'masked'], 'left_pupil': ['blink', 'masked']}
>>> stats["left_pupil"]["blink"]["n"]
11
local_level(eye, variable='pupil', scales=('30 s', '60 s', '120 s', '240 s'), min_coverage=0.5, max_dev=0.2, policy='strict', details=False)#

The local level of a channel: a robust, multi-scale moving median.

Overloads:

For each sample, the median of the usable samples in a window around it, from the finest of scales that has enough usable samples and agrees with the coarser ones (see local_level()). Used as the reference of rates in percent of the pupil size ("%/ms"); see plot.plot_local_level for a plot.

Parameters:
  • eye (str) – the eye

  • variable (str) – the variable (default "pupil")

  • scales (sequence of float, str or Quantity) – window lengths (plain numbers in ms; default 30, 60, 120 and 240 s: a rough reference, so that rates in %/ms are not misaligned)

  • min_coverage (float) – minimum share (0-1) of usable samples in a window (default 0.5)

  • max_dev (float) – maximum deviation of a scale from the next coarser one, as a fraction of its level (default 0.2)

  • policy (str or MaskPolicy) – samples masked under this policy (and 0) are not used (default "strict")

  • details (bool) – also return the medians and coverage of each scale (for plots)

Returns:

  • level (np.ndarray) – the local level of each sample, in the units of the data (on data scaled with scale(), computed on the unscaled data, since max_dev is relative)

  • scale (np.ndarray) – the window length (s) chosen for each sample; inf: the median of the whole recording

  • details (dict, only with details) – "scales" (s) and, per scale, "centers" (sample indices), "median" and "coverage"

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> level, scale = d.local_level("left")
mask(eye, var=None, policy='default')#

Mask of a channel under a mask policy (True: unusable sample).

A sample is unusable if its value is NaN or if one of the layers of the policy is set (see MaskPolicy). By default, blinks, off-screen gaze, eye divergences, user masks and excluded periods are masked, interpolated samples are not.

Parameters:
  • eye (str) – eye (e.g., “left”) or the key of the channel (e.g., “left_pupil”)

  • var (str | None) – variable (e.g., “pupil”); None if eye is the key

  • policy (str, MaskPolicy or list of str) – "default", "strict" (interpolated samples are masked too), "raw" (nothing is masked), a MaskPolicy or a list of layers

Return type:

ndarray

Returns:

boolean array, one value per sample

Examples

>>> d.mask("left", "pupil")
>>> d.mask("left_pupil", policy="strict")
>>> d.mask("left", "pupil", policy=["blink"])
mask_as_intervals(eyes=[], variables=[], units='ms', label=None, policy='default')#

Convert masks to Intervals objects.

Each contiguous run of masked samples (unusable under the mask policy, see mask()) becomes one interval.

Parameters:
  • eyes (str | list) – Eye(s) to get masks for; if empty, all available eyes.

  • variables (str | list) – Variable(s) to get masks for; if empty, all available variables (combinations not present in the data are left out).

  • units (str) – Units for intervals: “ms” (default), “sec”, “min”, “h”, or “samples” for sample indices.

  • label (str | None) – Descriptive label for the intervals. Default is None.

  • policy (str, MaskPolicy or list of str) – mask policy (see mask()); default "default"

Return type:

dict[str, Intervals]

Returns:

one Intervals object per existing eye/variable combination, keys like “left_pupil” (also for a single eye and variable)

Raises:

KeyError – if a requested eye/variable combination does not exist (see select())

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short").pupil.blinks_detect()
>>> masked = d.mask_as_intervals("left", "pupil")["left_pupil"]
>>> masked_sec = d.mask_as_intervals("left", "pupil", units="sec")["left_pupil"]
>>> mask_dict = d.mask_as_intervals(["left", "right"], "pupil")
>>> list(mask_dict)
['left_pupil', 'right_pupil']
mask_intervals(intervals, eyes=[], variables=[], inplace=None)#

Apply Intervals as masks to selected data.

Takes detected intervals (e.g., blinks, artifacts) and applies them as masks to specified eyes and variables: they are added to the "user" layer (existing masks are kept).

Parameters:
  • intervals (Intervals, Epochs, list of tuple or dict) –

    Either:

    • A single Intervals (or Epochs) object or a list of (start, end) tuples (in ms, or with units): applied to all specified eyes/variables

    • A dict of Intervals (or Epochs): keys like “left_pupil”, “right_x”, etc. When dict is provided, eyes and variables are ignored.

  • eyes (str or list of str, optional) – eye(s) to apply mask to (e.g., ["left", "right"]); if empty, all available eyes. Ignored if intervals is a dict.

  • variables (str or list of str, optional) – variable(s) to apply mask to (e.g., ["pupil", "x", "y"]); if empty, all available variables. Ignored if intervals is a dict.

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

The object with masks applied (self or a copy, depending on inplace).

See also

pypillometry.eyedata.pupil.PupilNamespace.blinks_detect

Detect blinks

get_blinks

Retrieve stored blink intervals

Examples

Apply blinks from a single Intervals object to left eye pupil data:

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short").pupil.blinks_detect()
>>> blinks = d.get_blinks()
>>> d = d.mask_intervals(blinks["left_pupil"], eyes=["left"], variables=["pupil"])

Apply a dict of intervals (one per eye/variable):

>>> d = d.mask_intervals(blinks)  # eyes and variables ignored

Chain with other operations:

>>> d = d.mask_intervals(blinks).pupil.lowpass_filter(cutoff=5)
mask_islands(min_duration=50, max_gap=5, min_density=None, eyes=[], variables=['pupil'], policy='default', inplace=None)#

Mask islands: short stretches of usable data between unusable ones.

After masking (dropouts, transients, off-screen gaze, quality signals, …), single fragments of data often remain between the masked stretches. They are usually artifacts as well and are too short to be of use. Unusable stretches of up to max_gap do not separate the data (e.g., single missing samples every few samples in otherwise good data), so that thinned-out data are not taken apart. The usable data then fall into segments, separated by longer unusable stretches (or the start and end of the recording); a segment is an island if its span (from its first to its last usable sample) is shorter than min_duration, or, with min_density, if less than this fraction of it is usable (e.g., flickering data).

Islands are found from all other masks, so this is best done after the other masking steps (and before interpolating). Each channel is treated separately. The islands are stored as the "island" layer; they replace the ones masked before (masking islands does not make new ones, so running it again gives the same result).

Parameters:
  • min_duration (float, str or Quantity) – minimum span of a segment (in ms, or with units; default 50 ms)

  • max_gap (float, str or Quantity) – longest unusable stretch that does not separate segments (in ms, or with units; default 5 ms)

  • min_density (Optional[float]) – minimum fraction (0-1) of usable samples in a segment; default None (no minimum)

  • eyes (str or list) – eyes to process (default: all)

  • variables (str or list) – variables to process (default: the pupil)

  • policy (str or MaskPolicy) – samples that are unusable under this policy (default "default"; the "island" layer itself does not count) separate the segments

  • inplace (bool or None) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting

Return type:

Self

Returns:

the object with the islands masked (self or a copy, depending on inplace)

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d.pupil.mask_transients().mask_islands()
>>> stats = d.layer_stats("island", variables="pupil")
mask_signal(signal, lower=None, upper=None, method='value', percentile=False, eyes=[], variables=[], layer=None, margin=0, ignore_existing_mask=True, store_as=None, inplace=None)#

Mask the data where a quality signal is out of range.

The quality signal is a channel in d.aux (e.g., the distance of the eye from the camera), a variable of the eyes or a signal you compute. Samples where it (or a statistic of it, see method) is below lower or above upper are masked in layer layer of the selected eyes and variables. The layer replaces the one from an earlier call with the same layer (so running the method again with other thresholds gives the same result as running it once; clear_layer(layer) removes it). Like all layers except "interpolated", it makes the samples unusable under the "default" policy. Samples where the signal is NaN are not masked (there is no information about them).

The thresholds are found for each eye separately; those that were used (e.g., the value of the 99th percentile) are noted in the history (see print_history()).

Parameters:
  • signal (str, callable, array or dict) –

    the quality signal:

    • a name, looked up like the variables of the plots (see plot_timeseries()): a variable of the eyes (e.g., "pupil") or a channel in d.aux (e.g., "gaze_luminance"), or the last or first part of the names of channels, e.g. "distance" for left_distance and right_distance. A channel of an eye (<eye>_...) is used for this eye, other channels for all eyes.

    • a function f(d, eye) that returns the signal of eye (one value per sample) or None (the eye is not checked), e.g. lambda d, eye: d.data[f"{eye}_pupil"] / d.aux[f"{eye}_pupilpx"]

    • an array (one value per sample) used for all eyes, or a dict {eye: array}

  • lower (float, optional) – thresholds: samples where the statistic of the signal is below lower or above upper are masked; at least one is needed. With percentile, they are fractions (0-1) of the distribution of the statistic (e.g., upper=0.99).

  • upper (float, optional) – thresholds: samples where the statistic of the signal is below lower or above upper are masked; at least one is needed. With percentile, they are fractions (0-1) of the distribution of the statistic (e.g., upper=0.99).

  • method (str) –

    the statistic that the thresholds apply to:

    • "value" (default): the signal itself

    • "mad": the robust z-score, i.e. the distance from the median in units of the median absolute deviation (scaled to the SD for normal data), e.g. lower=-5, upper=5

    • "jump": the absolute change per second to the previous or next sample (the larger one), so that both samples of a jump are masked, e.g. upper=2000 for a distance that changes by more than 2000 mm/s

  • percentile (bool) – lower and upper are percentiles (0-1) of the statistic

  • eyes (str or list) – eyes to check (default: all)

  • variables (str or list) – variables of the eyes to mask (default: all)

  • layer (Optional[str]) – name of the layer; default: signal (needed if signal is not a name). Not "interpolated" or "excluded".

  • margin (float, str, Quantity or tuple) – time added before and after each masked stretch (plain numbers in ms; a tuple (before, after) for different margins); default 0

  • ignore_existing_mask (bool) – if True (default), check all samples, also those that are masked already (e.g., blinks); if False, only those that are usable under the default policy for all masked variables of the eye (the layer itself does not count). The thresholds of percentile and "mad" come from the checked samples.

  • store_as (Optional[str]) – store the signal in d.aux: as <eye>_<store_as> if it belongs to an eye, otherwise as store_as (which then needs the form <group>_<name>)

  • inplace (bool or None) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting

Return type:

Self

Returns:

the object with the samples masked (self or a copy, depending on inplace)

Raises:

ValueError – if signal is not found, a name stands for several channels of the same eye, no threshold is given, method is unknown, a percentile is not between 0 and 1, layer is missing or not allowed, or a signal does not have one value per sample

Examples

>>> import numpy as np
>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> dist = np.full(len(d), 600.)         # e.g., the eye-camera distance in mm
>>> dist[1000:1100] = 900.
>>> d = d.mask_signal(dist, upper=750, layer="distance", margin=50)
>>> blocks = d.get_layer_intervals("distance", "left", "pupil", units="samples")
>>> blocks["left_pupil"].intervals    # 50 ms (25 samples) margin
[(975, 1125)]

With a channel in d.aux, e.g. of a GazePoint recording (left_distance, right_distance, in mm), the percentiles of the change of the distance, or a computed signal:

>>> d = pp.get_example_data("robison_pvt")
>>> d = d.mask_signal("distance", lower=450, upper=750)
>>> d = d.mask_signal("distance", method="jump", upper=0.999, percentile=True,
...                   layer="distance_jump")
>>> d = d.mask_signal(lambda d, eye: d.data[f"{eye}_pupil"] / d.aux[f"{eye}_pupilpx"],
...                   method="mad", lower=-5, upper=5, layer="mmpx")
>>> d.print_history()  # the thresholds that were used
merge_eyes(eyes=[], variables=[], method='mean', keep_eyes=True, policy='default', name='mean', inplace=None)#

Merge data from both eyes into a single variable.

The merged data is stored under the eye name name (default “mean”, e.g., obj["mean", "pupil"]). Each sample is the mean over the eyes in which it is usable under the mask policy (see mask()), where recorded samples come first: an interpolated sample is used only if no eye has a recorded one there. A sample is masked in the merged data only if it is unusable in all merged eyes (it then holds the mean of the stored values; NaN only if they are NaN). The merged data get the layers that are set in all eyes that went into a sample (e.g., "interpolated" where all of them were interpolated, or "blink" where all eyes are masked by a blink); masked samples without such a common layer get the "user" layer. Each variable is merged over the selected eyes that have data for it.

Parameters:
  • eyes (str or list of str, optional) – eye(s) to merge; if empty, all available eyes

  • variables (str or list of str, optional) – variable(s) to merge; if empty, all available variables

  • method (str, optional) – which method to use for merging; currently only “mean” is implemented, by default “mean”

  • keep_eyes (bool, optional) – keep original eye data (True, default) or drop it together with its stored blinks (False)

  • policy (str, MaskPolicy or list of str) – mask policy that decides which samples are usable (see mask()); default "default"

  • name (str, optional) – name of the new eye; default "mean" (as in d.pupil.merge_eyes())

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with merged data (self or a copy, depending on inplace)

merge_masks(inplace=None)#

Merge masks of all variables into a single joint mask.

This function creates a joint mask by taking the logical OR of all individual masks (under the default mask policy, see get_mask()), then applies this joint mask to all variables (the newly masked samples get the "user" layer).

Parameters:

inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with merged masks (self or a copy, depending on inplace)

nevents()#

Return number of events in data.

Return type:

int

print_history()#

Pretty-print the history of the current dataset (which manipulations where done on it).

Return type:

None

quality_report(thresholds=None, eyes=[], policy='default')#

Report the quality of the data.

Measures that need no preprocessing are always computed (on the stored values, where missing samples are NaN):

  • pupil (if available): missing data, dropouts (periods of missing data) and high-frequency noise

  • gaze (if available): missing data, off-screen samples (needs the screen resolution) and precision (in degrees if screen size and eye distance are set in the experimental setup, else in pixels)

  • both eyes: correlation of the pupils and disparity of the gaze

Further measures are added if available: blinks (after d.pupil.blinks_detect()), masked and interpolated data (after preprocessing; masked: unusable under the mask policy, see mask()) and calibration/validation errors (e.g., when read from an Eyelink file).

Where it makes sense, each measure is labeled as “good”, “ok”, “poor” or “bad”. The overall label is the worst of all labels.

Excluded periods (see exclude_intervals()) are left out: all measures refer to the included time, and dropouts and sample-to-sample differences end at their boundaries.

Parameters:
  • thresholds (Optional[dict]) – thresholds for the labels, overriding the defaults in pypillometry.quality.DEFAULT_QUALITY_THRESHOLDS. Keys are "<section>.<metric>" (e.g., "pupil.missing_pct"), values are three bounds (good, ok, poor). Increasing bounds mean that lower values are better, decreasing bounds that higher values are better. None turns the label off.

  • eyes (str | list) – eye(s) to report; if empty, all available eyes

  • policy (str, MaskPolicy or list of str) – mask policy for the masked data (see mask()); default "default" (interpolated samples are not masked)

Return type:

QualityReport

Returns:

the report; print it for a text version, display it in a notebook for an HTML version or use to_dict() to get a dict

Examples

>>> import pypillometry as pp
>>> d = pp.get_rlmw_002_short()
>>> print(d.quality_report())
>>> d.quality_report(thresholds={"pupil.missing_pct": (2, 10, 20)})
remove_intervals(intervals, inplace=None)#

Remove the data in the given periods (e.g., breaks) and join the rest.

The samples in the periods are deleted. Gaps between the remaining data are closed: the data after a removed period are shifted back in time, so that they continue where the removed period started (the time vector has no gap). Removing data at the beginning or end does not change the times, so removing everything before start and after end is the same as crop(). Event onsets are shifted with the data; events within removed periods are deleted. Stored blinks and excluded periods are moved to the new positions. The removed periods are added to params["removed_intervals"], in the original time (the time before any periods were removed; a period across a gap closed by an earlier call is split at the gap). params["removed_shifts"] holds the shifts between the current and the original time.

To remove the periods marked with exclude_intervals(), use d.remove_intervals(d.get_excluded()).

Filters or interpolation applied after joining treat the data on both sides of a removed period as neighbors; apply them before, or use split_excluded() to process the parts separately.

Parameters:
  • intervals (Intervals, Epochs or list of tuple) – the periods to remove: an Intervals object (in time units or sample indices), Epochs or a list of (start, end) tuples (in ms, or with units, e.g., [(10 * u.min, 12 * u.min)]; "<start>" and "<end>" stand for the start and end of the recording); ends are exclusive

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object without the removed periods (self or a copy, depending on inplace)

Raises:

ValueError – if all samples would be removed

See also

crop

keep only the data between two times

split_excluded

split the data at the excluded periods

Examples

>>> breaks = d.get_intervals(start="break_start", end="break_end", units="ms")
>>> d = d.remove_intervals(breaks)
>>> d = d.remove_intervals(d.get_excluded())
rename_eye(old, new, variables=[], overwrite=False, inplace=None)#

Rename an eye (all its variables or only variables).

Values, mask layers and the parameters of scale() move to the new eye; so do the limits of an uncertainty band (<old>_<var>_lower and _upper). Typical use: a recording in which the eye tracker labelled the eye wrongly.

Parameters:
  • old (str) – the eye (e.g., "left")

  • new (str) – its new name (e.g., "right"; without _)

  • variables (str | list) – only these variables; default all variables of the eye (including gaze)

  • overwrite (bool) – replace the variables of eye new if they exist (else an error)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the renamed eye (self or a copy, depending on inplace)

Raises:
  • KeyError – if the eye (or one of variables of it) does not exist

  • ValueError – if a variable of eye new exists (and not overwrite), or new is not a valid eye name

See also

copy_eye

keep the eye and add a copy

rename_variable

rename a variable within the eyes

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d.drop_data(eyes="right", inplace=False).rename_eye("left", "right")
>>> d.eyes
['right']
rename_variable(old, new, eyes=[], overwrite=False, inplace=None)#

Rename a variable (of all eyes or of eyes).

Values, mask layers and the parameters of scale() move to the new name; so do the limits of an uncertainty band (<eye>_<old>_lower and _upper). Typical use: move a variable out of the way before another one takes its name. For the channels in aux, see EyeDataDict.rename.

Parameters:
  • old (str) – the variable (e.g., "pupil")

  • new (str) – its new name (e.g., "pupilraw")

  • eyes (str | list) – only these eyes; default all eyes with the variable

  • overwrite (bool) – replace the variable new if it exists (else an error)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with the renamed variable (self or a copy, depending on inplace)

Raises:
  • KeyError – if the variable does not exist (for an eye in eyes)

  • ValueError – if new exists (and not overwrite)

See also

copy_variable

keep the variable and add a copy

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d.rename_variable("pupil", "pupilraw", inplace=False)
>>> d.data.variables
['x', 'y', 'pupilraw']
reset_time(t0=None, inplace=None)#

Resets time so that time t0 becomes time zero.

t0 is subtracted from the time-vector, the event onsets and the periods in params["removed_intervals"] (see remove_intervals()). params["time_zero"] holds the time of the recording (before all resets) that is now time zero.

Parameters:
  • t0 (float | None) – time (in ms) that becomes the new time zero; if None, use the first time point (so that the time-vector starts at zero)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the object with shifted time (self or a copy, depending on inplace)

scale(variables=[], method='z', center=None, scale=None, eyes=[], policy='default', inplace=None)#

Scale the signal: subtract center and divide by scale.

method says how center and scale are computed from the usable samples of each channel (under policy) if they are not given:

  • "z" (default): mean and standard deviation (z-scores)

  • "robust": median and median absolute deviation (MAD; the raw MAD, not multiplied by 1.4826), so the result is in units of the MAD and outliers (e.g., artefacts) have little influence

  • "minmax": minimum and range (max - min), so the result lies between 0 and 1

  • "percent": mean and mean / 100, so the result is the change in % of the mean (for a percent change relative to a baseline before each event, see SegmentedEyeData.pupil.baseline_correct)

Parameters:
  • variables (str or list of str, optional) – variables to scale; can be “pupil”, “x”,”y”, “baseline”, “response” or any other variable that is available in the dataset; either a string or a list of strings; available variables can be checked with obj.variables; empty list means all variables

  • method (str) – how center and scale are computed if they are None: "z" (default), "robust", "minmax" or "percent" (see above)

  • center (Union[float, dict, None]) – value to subtract; if None, computed with method; a number (same for all eyes and variables) or one per channel as {"left_pupil": value, ...}

  • scale (Union[float, dict, None]) – value to divide by; if None, computed with method; a number or one per channel as {"left_pupil": value, ...}

  • eyes (str or list of str, optional) – eye(s) to consider; if empty, all available eyes

  • policy (str, MaskPolicy or list of str) – mask policy that decides which samples are used for center and scale (see mask()); default "default" (interpolated samples are used)

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the scaled object (self or a copy, depending on inplace)

Raises:

ValueError – if method is unknown, or scale is 0 or not finite for a channel (e.g., a constant signal, or a MAD of 0)

Notes

The scaling parameters are stored in params["scale"] ({"center": {"left_pupil": ...}, "scale": {...}, "method": {...}}) and used by unscale(). Scaling a variable again combines the parameters, so that unscale() restores the values before the first scale.

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> z = d.scale("pupil", inplace=False)                     # z-scores
>>> r = d.scale("pupil", method="robust", inplace=False)    # units of the MAD
>>> p = d.scale("pupil", method="minmax", inplace=False)
>>> bool(p["left_pupil"].min() == 0 and p["left_pupil"].max() == 1)
True

Set blinks for specified eyes and variables (in-place).

The blinks replace the "blink" layer of the selected variables (and the mask of the blinks set before). Blinks are masked under the mask policies (see mask()).

Parameters:
  • intervals (Intervals, dict or None) –

    Either:

    • a single Intervals object: stored for all specified eyes/variables;

    • a dict of Intervals (or None) with keys like “left_pupil”, “right_x”, etc.; when a dict is provided, eyes and variables are ignored;

    • None: remove the blinks for the specified eyes/variables (and their mask).

  • eyes (str or list of str, optional) – eye(s) to set blinks for (e.g., ["left", "right"]); if empty, all available eyes. Ignored if intervals is a dict.

  • variables (str or list of str, optional) – variable(s) to set blinks for (e.g., ["pupil", "x", "y"]); if empty, all available variables. Ignored if intervals is a dict.

Return type:

Self

Returns:

the object itself (always modified in-place)

set_events(events)#

Replace the events of the dataset (in-place).

The onsets are converted to ms (the internal storage format) if needed. The time range of the data is not stored with the events. A warning is given for events that are marked as being on another clock (needs_sync, see sync_clocks()).

Parameters:

events (Events) – the new events (onsets, labels and metadata)

Return type:

Self

Returns:

the object itself, with the new events (use d.copy() first to keep the old events)

Raises:
  • TypeError – if events is not an Events object

  • ValueError – if an onset is outside the time range of the data

See also

events

the events of the dataset

add_events

add events to the existing ones

Examples

>>> d = d.set_events(d.events.filter("stim"))
>>> d = d.set_events(d.events.parse_labels(r"_(?P<trial>\d+)"))
set_experimental_setup(**kwargs)#

Set or update the experimental setup geometry (in-place).

Creates a new ExperimentalSetup or updates the existing one with the provided parameters (parameters that are not given are taken from the existing setup). All parameters are passed through to the ExperimentalSetup constructor.

Parameters:

**kwargs (dict) –

Any parameters accepted by ExperimentalSetup:

  • screen_resolution: tuple (width, height) in pixels

  • physical_screen_size: tuple (width, height) with units

  • eye_to_screen_center: distance from the eye to the screen center

  • screen_offset: tuple (delta_x, delta_y) - offset of screen center from eye

  • screen_pitch: tilt angle (alpha_tilt)

  • screen_yaw: tilt angle (beta_tilt)

  • camera_offset: tuple (x, y, z) in eye-centric frame

  • camera_spherical: tuple (theta, phi, r)

  • ipd: inter-pupillary distance

Return type:

Self

Returns:

the object itself (always modified in-place)

Examples

>>> import pypillometry as pp
>>> d = pp.get_example_data("rlmw_002_short")
>>> d = d.set_experimental_setup(
...     screen_resolution=(1920, 1080),
...     physical_screen_size=("52 cm", "29 cm"),
...     eye_to_screen_center="65 cm",
... )
split_excluded()#

Split the data at the excluded periods (see exclude_intervals()).

Returns one object per included period (see get_included()), each with the samples, masks, blinks and events of that period and the original time vector. The objects are copies; self is not changed.

Return type:

list[Self]

Returns:

the parts of the recording between the excluded periods

See also

remove_intervals

remove periods and join the rest, e.g., d.remove_intervals(d.get_excluded())

stat_per_event(intervals=None, window=None, event_select=None, eyes=[], variables=[], statfct=<function mean>, units='ms', policy='default', **kwargs)#

Return result of applying a statistical function to data in a given interval relative to event-onsets. For example, extract mean pupil-size in interval before trial onset.

Parameters:
  • intervals (Intervals or Epochs, optional) – Intervals object (in any time units or in sample indices, e.g., from get_intervals()) or Epochs (e.g., from get_epochs()). If provided, window and event_select are ignored.

  • window (Tuple[float, float]) – time-window relative to event-onset (0 is event-onset), e.g. (-200, 0) * u.ms; plain numbers are in units given by units. Required if intervals is not provided.

  • event_select (str, function or Events, optional) – the events to select (see get_epochs()); required if intervals is not provided

  • eyes (str | list) – eye(s) to consider; if empty, all available eyes

  • variables (str | list) – variable(s) to consider; if empty, all available variables

  • statfct (Callable) – function mapping a masked array to a single number; it must ignore masked samples (e.g., np.mean (default) or np.ma.median, but not np.median; a warning is logged otherwise). Intervals where all samples are masked give NaN.

  • units (str) – units for plain numbers in window (if used); default “ms”

  • policy (str, MaskPolicy or list of str) – mask policy: the samples that are unusable under it are masked (see mask()); default "default" (interpolated samples are used)

  • **kwargs – passed onto the event_select function

Return type:

dict[str, ndarray]

Returns:

one array per eye/variable (keys like “left_pupil”), with one value per interval/event

summary()#

Return a summary of the dataset as a dictionary.

Return type:

dict[str, Any]

Returns:

A dictionary summarizing the dataset.

unscale(variables=[], center=None, scale=None, eyes=[], inplace=None)#

Scale back to original values using either values provided as arguments or the values stored in params[“scale”] by scale().

The signal is multiplied by scale and center is added. The stored parameters of the unscaled channels are removed.

Parameters:
  • variables (str or list of str, optional) – variables to unscale; can be “pupil”, “x”,”y”, “baseline”, “response” or any other variable that is available in the dataset; either a string or a list of strings; available variables can be checked with obj.variables; empty list means all variables

  • center (None, float or dict, optional) – value to add to the signal; a number (same for all eyes and variables) or {"left_pupil": value, ...}; if None, use the value stored by scale()

  • scale (None, float or dict, optional) – value to multiply the signal with; a number (same for all eyes and variables) or {"left_pupil": value, ...}; if None, use the value stored by scale()

  • eyes (str or list of str, optional) – eye(s) to consider; if empty, all available eyes

  • inplace (bool or None, optional) – if True, make change in-place and return the object; if False, make and return copy before making changes; if None, use the object-level setting (specified in the constructor)

Return type:

Self

Returns:

the unscaled object (self or a copy, depending on inplace)

write_file(fname, compress=True)#

Save to file (using write_file()).

The format follows from the extension: HDF5 for .h5 and .hdf5, pickle otherwise (e.g., .pypil).

Parameters:
  • fname (str) – str: filename

  • compress (bool) – bool: compress the file (default True; pickle: zstd, HDF5: gzip)

Return type:

None

LOCAL_LEVEL_SCALES = ('30 s', '60 s', '120 s', '240 s')#

default scales of local_level()

Return blinks (intervals) for all eyes.

Return type:

dict

Returns:

dictionary with blinks (Intervals in ms) for each eye/variable, keys like “left_pupil” (same as get_blinks())

property events: Events#

The events of the data (onsets in ms).

An Events object. Events are immutable: their methods (e.g., filter(), parse_labels()) return new Events, which are stored with set_events(). Operations on the data that change the time (e.g., crop(), remove_intervals(), reset_time()) move the events with it.

Examples

>>> d.events.filter("stim")
>>> d = d.set_events(d.events.parse_labels(r"_(?P<trial>\d+)"))
property eyes: List[str]#

Return a list of available eyes in the dataset.

property variables: List[str]#

Return a list of available variables in the dataset.