concat_segments#

pypillometry.concat_segments(segments, name=None, channels=None, key='subject')[source]#

Stack the segments of several participants (or sessions) into one object.

The columns (trials or averages) of all segments are put one after the other, with their epochs; the metadata column key (default "subject") says which segments each column comes from. The result can be selected and averaged like the segments of one participant, e.g., concat_segments(segs).average(by=["subject", "cond"]).

Parameters:
  • segments (list or dict of SegmentedEyeData) – the segments, e.g., one object per participant; for a dict, the keys are the values of key (otherwise the names of the segments, or numbers if these are not unique). All must have the same time axis.

  • name (str) – name of the result (default: the name of the first segments)

  • channels (str or list of str, optional) – channels to combine (default: those of the first segments); all segments must have them

  • key (str) – metadata column for the names of the segments (default "subject"); None adds no column

Return type:

SegmentedEyeData

Returns:

the stacked segments

Raises:
  • ValueError – if segments is empty, the time axes differ, or the epochs already have a metadata column key

  • KeyError – if segments lack a channel

Examples

One SegmentedEyeData per participant (here: the example recording twice):

>>> import pypillometry as pp
>>> from pypillometry import u
>>> d = pp.get_example_data("rlmw_002_short")
>>> epochs = d.get_epochs("S_", (-500, 2500) * u.ms)
>>> seg = d.get_segments(epochs, variables="pupil")
>>> both = pp.concat_segments({"S01": seg, "S02": seg})
>>> both.n_segments
20
>>> both.filter(subject="S01").n_segments
10