Epochs#
- class pypillometry.Epochs(onsets, window, labels=None, meta=None, label=None)[source]#
Bases:
StatefulEvent-locked windows: the onsets of events and one time window around them.
An Epochs object describes the same window around each of several events, e.g., -200 to 800 ms around every stimulus. It is returned by
get_epochs()and is the input ofget_segments(), which takes the length and the time axis of the segments from the window. Spans of time that are not locked to one event (e.g., between two events) areIntervals.The columns of averaged segments (see
average()) have Epochs without a time: their onsets are NaN. Such epochs can be selected and their metadata used, but they have no spans in the data.Epochs iterate like spans (
(onset + window[0], onset + window[1])in ms), so they can be used wherever the eyedata methods take Intervals (e.g.,mask_intervals()orstat_per_event());to_intervals()converts them explicitly. Windows that extend beyond the data are not clipped; the methods that read the data handle the parts outside of it.The events are kept as an
Eventsobject (events, in ms). Epochs are selected like events, by label, time or metadata (filter(),keep()), and their metadata are changed withset_meta(),drop_meta()andparse_labels(); these methods return new Epochs with the same window.- Parameters:
onsets (array-like or Quantity) – onsets of the events in ms (or with units, e.g.,
[1, 2] * u.sec); NaN for epochs without a time (averages)window (tuple (start, end) or Quantity) – the window relative to each onset in ms (or with units, e.g.,
(-200, 800) * u.ms); start < endlabels (array-like of str, optional) – label of each event (default: empty strings)
meta (dict, optional) – metadata of the events (column name -> array with one value per event, see
Events)label (str, optional) – name of the epochs (e.g., the event selector)
- Attributes:
- eventsEvents
the events the epochs are locked to (onsets in ms)
onsetsnp.ndarrayOnsets of the events in ms (read-only).
- windowtuple of float
window in ms
labelsnp.ndarrayLabels of the events (read-only).
metamappingMetadata of the events (read-only mapping: column name -> array).
- labelstr or None
name of the epochs
Examples
>>> ep = Epochs([1000, 3000], (-200, 800), labels=["stim", "stim"]) >>> list(ep) [(800.0, 1800.0), (2800.0, 3800.0)] >>> ep.to_intervals("sec").intervals[0] (0.8, 1.8) >>> ep = Epochs([1000, 3000], (-200, 800), meta={"cond": ["easy", "hard"]}) >>> ep.filter(cond="easy").onsets array([1000.])
Methods
The epochs as a
pandas.DataFrame.Epochs without the metadata columns names (all, if none given; see
Events.drop_meta).Epochs whose events match the criteria.
Epochs around all events of an
Eventsobject.Epochs where mask is True.
Epochs with metadata from a table with one row per trial (see
Events.merge_table).Epochs with metadata from the labels of the events (see
Events.parse_labels).Epochs with a metadata column set (see
Events.set_meta).The spans of the epochs as
Intervals.Details
- classmethod from_events(events, window, label=None)[source]#
Epochs around all events of an
Eventsobject.
- as_pandas()[source]#
The epochs as a
pandas.DataFrame.- Return type:
- Returns:
columns
onset,start,end(in ms; NaN for epochs without a time),labeland the metadata columns
- drop_meta(*names)[source]#
Epochs without the metadata columns names (all, if none given; see
Events.drop_meta).- Return type:
- filter(selector=None, exact=False, **conditions)[source]#
Epochs whose events match the criteria.
The events are selected as in
Events.filter: by label, onset time (in ms), a boolean array or metadata.- Parameters:
selector (str, callable, tuple or boolean array, optional) – criterion for the events (see
Events.filter)exact (
bool) – if True, a string selector matches only labels equal to it**conditions – criteria for metadata columns, e.g.
cond="easy",trial=[1, 2]orrt=lambda rt: rt < 800
- Return type:
- Returns:
the selected epochs (same window and label)
Examples
>>> ep = Epochs([100, 500, 900], (0, 100), labels=["A", "B", "A"], ... meta={"rt": [300, 900, 500]}) >>> ep.filter("A", rt=lambda rt: rt < 400).onsets array([100.])
- keep(mask)[source]#
Epochs where mask is True.
- Parameters:
mask (array-like of bool) – one value per epoch
- Return type:
- Returns:
the selected epochs (with their labels and metadata)
Examples
>>> ep = Epochs([100, 500, 900], (0, 100), labels=["A", "B", "C"]) >>> ep.keep(ep.onsets < 600).labels array(['A', 'B'], dtype='<U1')
- merge_table(table, on, columns=None)[source]#
Epochs with metadata from a table with one row per trial (see
Events.merge_table).- Return type:
- parse_labels(parser)[source]#
Epochs with metadata from the labels of the events (see
Events.parse_labels).- Return type:
- set_meta(name, values, select=None, exact=False)[source]#
Epochs with a metadata column set (see
Events.set_meta).- Return type:
- Returns:
new Epochs with the changed metadata
- to_intervals(units='ms', data=None)[source]#
The spans of the epochs as
Intervals.The Intervals keep the event labels, onsets and metadata per row.
- property meta#
Metadata of the events (read-only mapping: column name -> array).