bids.variables.variables.DenseRunVariable

class DenseRunVariable(name, values, run_info, source, sampling_rate)[source]

A dense representation of a single column.

Parameters:
  • name (str) – The name of the column.
  • values (numpy.ndarray) – The values/amplitudes to store.
  • run_info (list) – A list of RunInfo objects carrying information about all runs represented in the Variable.
  • source ({'events', 'physio', 'stim', 'confounds', 'scans', 'sessions', 'participants', 'beh'}) – The type of BIDS variable file the data were extracted from.
  • sampling_rate (float) – Optional sampling rate (in Hz) to use. Must match the sampling rate used to generate the values. If None, the collection’s sampling rate will be used.

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.
resample(sampling_rate[, inplace, kind]) Resample the Variable to the specified sampling rate.
split(grouper) Split the current DenseRunVariable into multiple columns.
to_df([condition, entities, timing]) Convert to a DataFrame, with columns for name and entities.
__init__(name, values, run_info, source, sampling_rate)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(name, values, run_info, source, …) 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.
resample(sampling_rate[, inplace, kind]) Resample the Variable to the specified sampling rate.
split(grouper) Split the current DenseRunVariable into multiple columns.
to_df([condition, entities, timing]) 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.

resample(sampling_rate, inplace=False, kind='linear')[source]

Resample the Variable to the specified sampling rate.

Parameters:
  • sampling_rate (int, float) – Target sampling rate (in Hz).
  • inplace (bool, optional) – If True, performs resampling in-place. If False, returns a resampled copy of the current Variable. Default is False.
  • kind ({'linear', 'nearest', 'zero', 'slinear', 'quadratic', 'cubic'}) – Argument to pass to scipy.interpolate.interp1d; indicates the kind of interpolation approach to use. See interp1d docs for valid values. Default is ‘linear’.
split(grouper)[source]

Split the current DenseRunVariable into multiple columns.

Parameters:grouper (pandas.DataFrame) – Binary DF specifying the design matrix to use for splitting. Number of rows must match current DenseRunVariable; a new DenseRunVariable will be generated for each column in the grouper.
Returns:
Return type:A list of DenseRunVariables, one per unique value in the grouper.
to_df(condition=True, entities=True, timing=True)[source]

Convert to a DataFrame, with columns for name and entities.

Parameters:
  • condition (bool) – 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.
  • entities (bool) – If True, adds extra columns for all entities.
  • timing (bool) – If True, includes onset and duration columns (even though events are sampled uniformly). If False, omits them.