FeatureSet#
- class braintools.cogtask.FeatureSet(*fts)[source]#
Collection of features with automatic index management.
Features in a set have their indices adjusted automatically to avoid overlap. Supports composition via +, -, | operators.
- Parameters:
*fts – Features to include in the set.
Examples
>>> from braintools.cogtask import Feature >>> features = Feature(1, 'fixation') + Feature(8, 'stimulus') >>> features FeatureSet(names=['fixation', 'stimulus'], nums=[1, 8]) >>> features['fixation'].i, features['stimulus'].i (slice(0, 1, None), slice(1, 9, None)) >>> 'stimulus' in features, len(features), features.num (True, 2, 9) >>> >>> # Removing a feature re-packs the remaining slices >>> rest = (features + Feature(2, 'choice')) - 'stimulus' >>> rest['choice'].i slice(1, 3, None)
- copy()[source]#
Create a deep copy of this feature set.
The copy keeps the layout of the original: its features and its own slice
isit at the same (possibly shifted) indices.- Return type:
- shift(num)[source]#
Shift all indices by the given amount.
Warning
This method mutates the FeatureSet in-place, unlike __add__ which creates a copy. If you need to preserve the original FeatureSet, create a copy before calling shift().
- Parameters:
num (
int) – The amount to shift indices by (can be positive or negative).