bids.variables.variables.SimpleVariable¶
-
class
SimpleVariable
(name, data, source, **kwargs)[source]¶ Represents a simple design matrix column that has no timing information.
Parameters: - name (str) – Name of the column.
- data (DataFrame) – A pandas DataFrame minimally containing a column named ‘amplitude’ as well as any identifying entities.
- source (str) – The type of BIDS variable file the data were extracted from. Must be one of: ‘events’, ‘physio’, ‘stim’, ‘regressors’, ‘scans’, ‘sessions’, ‘participants’, or ‘beh’.
- kwargs – Optional keyword arguments passed onto superclass.
Methods
apply
(func[, groupby])Applies the passed function to the groups defined by the groupby argument. clone
([data])Clone (deep copy) the current column, optionally replacing its data and/or any other attributes. filter
([filters, query, strict, inplace])Returns a copy of the current Variable with only rows that match the filters retained. get_grouper
([groupby])Return a list suitable for use in groupby calls. matches_entities
(entities[, strict])Checks whether current Variable’s entities match the input. merge
(variables[, name])Merge/concatenate a list of variables along the row axis. select_rows
(rows)Truncate internal arrays to keep only the specified rows. split
(grouper)Split the current SparseRunVariable into multiple columns. to_df
([condition, entities])Convert to a DataFrame, with columns for name and entities. -
__init__
(name, data, source, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(name, data, source, **kwargs)Initialize self. apply
(func[, groupby])Applies the passed function to the groups defined by the groupby argument. clone
([data])Clone (deep copy) the current column, optionally replacing its data and/or any other attributes. filter
([filters, query, strict, inplace])Returns a copy of the current Variable with only rows that match the filters retained. get_grouper
([groupby])Return a list suitable for use in groupby calls. matches_entities
(entities[, strict])Checks whether current Variable’s entities match the input. merge
(variables[, name])Merge/concatenate a list of variables along the row axis. select_rows
(rows)Truncate internal arrays to keep only the specified rows. split
(grouper)Split the current SparseRunVariable into multiple columns. to_df
([condition, entities])Convert to a DataFrame, with columns for name and entities. -
apply
(func, groupby='run', *args, **kwargs)¶ Applies the passed function to the groups defined by the groupby argument. Works identically to the standard pandas df.groupby() call. :param func: The function to apply to each group. :type func: callable :param groupby: Name(s) of column(s) defining the grouping. :type groupby: str, list :param args, kwargs: Optional positional and keyword arguments to pass
onto the function call.
-
clone
(data=None, **kwargs)¶ Clone (deep copy) the current column, optionally replacing its data and/or any other attributes.
Parameters: - data (DataFrame, ndarray) – Optional new data to substitute into the cloned column. Must have same dimensionality as the original.
- kwargs (dict) – Optional keyword arguments containing new attribute values to set in the copy. E.g., passing name=’my_name’ would set the .name attribute on the cloned instance to the passed value.
-
filter
(filters=None, query=None, strict=False, inplace=False)¶ Returns a copy of the current Variable with only rows that match the filters retained.
Parameters: - filters (dict) – Dictionary of filters to apply. Keys can be either ‘amplitude’ or any named entity. Values must be single values or lists.
- query (str) – Optional query string to pass to df.query(). Will not be validated in any way, so must have valid column names. Takes precedence over filters in the event that both are passed.
- strict (bool) – By default, keys in ‘filters’ that cannot be found in the Variable will be silently ignored. If strict=True, None will be returned in such cases.
- inplace (bool) – If True, filtering is performed in place. If False, a filtered copy of the Variable is returned.
Returns: A BIDSVariable, or None if no rows are left after filtering.
-
get_grouper
(groupby='run')¶ Return a list suitable for use in groupby calls. :param groupby: Name(s) of column(s) defining the grouper
object. Anything that would be valid inside a .groupby() call on a pandas structure.Returns: A list defining the groups.
-
matches_entities
(entities, strict=False)¶ Checks whether current Variable’s entities match the input.
-
classmethod
merge
(variables, name=None, **kwargs)¶ Merge/concatenate a list of variables along the row axis.
Parameters: - variables (list) – A list of Variables to merge.
- name (str) – Optional name to assign to the output Variable. By default, uses the same name as the input variables.
- kwargs – Optional keyword arguments to pass onto the class-specific merge() call. See merge_variables docstring for details.
Returns: A single BIDSVariable of the same class as the input variables.
Notes: see merge_variables docstring for additional details.
-
select_rows
(rows)[source]¶ Truncate internal arrays to keep only the specified rows.
Parameters: rows (array) – An integer or boolean array identifying the indices of rows to keep.
-
split
(grouper)[source]¶ Split the current SparseRunVariable into multiple columns.
Parameters: grouper (iterable) – list to groupby, where each unique value will be taken as the name of the resulting column. Returns: A list of SparseRunVariables, one per unique value in the grouper.
-
to_df
(condition=True, entities=True, **kwargs)¶ Convert to a DataFrame, with columns for name and entities. :param condition: If True, adds a column for condition name, and
names the amplitude column ‘amplitude’. If False, returns just onset, duration, and amplitude, and gives the amplitude column the current column name.Parameters: entities (bool) – If True, adds extra columns for all entities.