def setup(self, inputs=None, drop_na=False, **kwargs): """Set up the Step and construct the design matrix. Parameters ---------- inputs : list Optional list of BIDSVariableCollections produced as output by the preceding Step in the analysis. If None, uses inputs passed at initialization (if any). drop_na : bool Boolean indicating whether or not to automatically drop events that have a n/a amplitude when reading in data from event files. kwargs : dict Optional keyword arguments to pass onto load_variables. """ self._collections = [] # Convert input contrasts to a list of BIDSVariableCollections inputs = inputs or self.inputs or [] input_grps = self._merge_contrast_inputs(inputs) if inputs else {} # TODO: remove the scan_length argument entirely once we switch tests # to use the synthetic dataset with image headers. if self.level != 'run': kwargs = kwargs.copy() kwargs.pop('scan_length', None) # Now handle variables read from the BIDS dataset: read them in, filter # on passed selectors, and group by unit of current level collections = self.layout.get_collections(self.level, drop_na=drop_na, **kwargs) collections, _ = self._filter_collections(collections, kwargs) groups = self._group_objects_by_entities(collections) # Merge in the inputs for key, input_ in input_grps.items(): if key not in groups: groups[key] = [] groups[key].append(input_) # Set up and validate variable lists model = self.model or {} X = model.get('x', []) for grp, colls in groups.items(): coll = merge_collections(colls) colls = tm.TransformerManager().transform(coll, self.transformations) if X: tm.Select(coll, X) self._collections.append(coll)
def setup(self, inputs=None, **kwargs): """Set up the Step. Processes inputs from previous step, combines it with currently loaded data, and applies transformations to produce a design matrix-ready set of variable collections. Parameters ---------- inputs : list Optional list of BIDSVariableCollections produced as output by the preceding Step in the analysis. If None, uses inputs passed at initialization (if any). kwargs : dict Optional keyword arguments constraining the collections to include. """ inputs = inputs or self.inputs or [] input_grps = self._merge_contrast_inputs(inputs) if inputs else {} # filter on passed selectors and group by unit of current level collections, _ = self._filter_collections(self._raw_collections, kwargs) groups = self._group_objects_by_entities(collections) # Merge in the inputs for key, input_ in input_grps.items(): if key not in groups: groups[key] = [] groups[key].append(input_) # Set up and validate variable lists model = self.model or {} X = model.get('x', []) for grp, colls in groups.items(): coll = merge_collections(colls) colls = tm.TransformerManager().transform(coll, self.transformations) if X: tm.Select(coll, X) self._collections.append(coll)
def test_select(collection): coll = collection.clone() keep = ['RT', 'parametric gain', 'respcat'] transform.Select(coll, keep) assert set(coll.variables.keys()) == set(keep)