Segment a dataset by extracting boxcar events
(Multiple) consecutive samples are extracted for each event, and are either returned in a flattened shape, or subject to further processing.
Events are specified as a list of dictionaries (see:class:Event) for a helper class. Each dictionary contains all relevant attributes to describe an event. This is at least the onset time of an event, but can also comprise of duration, amplitude, and arbitrary other attributes.
Parameters: | ds : Dataset
events : list
time_attr : str or None
match : {‘prev’, ‘next’, ‘closest’}
event_offset : None or float
event_duration : None or float
eprefix : str or None
event_mapper : Mapper
|
---|---|
Returns: | Dataset :
|
Examples
The documentation also contains an example script showing a spatio-temporal analysis of fMRI data that involves this function.
>>> from mvpa2.datasets import Dataset
>>> ds = Dataset(np.random.randn(10, 25))
>>> events = [{'onset': 2, 'duration': 4},
... {'onset': 4, 'duration': 4}]
>>> eds = eventrelated_dataset(ds, events)
>>> len(eds)
2
>>> eds.nfeatures == ds.nfeatures * 4
True
>>> 'mapper' in ds.a
False
>>> print eds.a.mapper
<Chain: <Boxcar: bl=4>-<Flatten>>
And now the same conversion, but with events specified as real time. This is on possible if the input dataset contains a sample attribute with the necessary information about the input samples.
>>> ds.sa['record_time'] = np.linspace(0, 5, len(ds))
>>> rt_events = [{'onset': 1.05, 'duration': 2.2},
... {'onset': 2.3, 'duration': 2.12}]
>>> rt_eds = eventrelated_dataset(ds, rt_events, time_attr='record_time',
... match='closest')
>>> np.all(eds.samples == rt_eds.samples)
True
>>> # returned dataset e.g. has info from original samples
>>> rt_eds.sa.record_time
array([[ 1.11111111, 1.66666667, 2.22222222, 2.77777778],
[ 2.22222222, 2.77777778, 3.33333333, 3.88888889]])
mvpa2.datasets.eventrelated.events2sample_attr
mvpa2.datasets.eventrelated.find_events
Enter search terms or a module, class or function name.