bids.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', 'regressors', '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
(self, func[, groupby])Applies the passed function to the groups defined by the groupby argument.
clone
(self[, data])Clone (deep copy) the current column, optionally replacing its data and/or any other attributes.
filter
(self[, filters, query, strict, inplace])Returns a copy of the current Variable with only rows that match the filters retained.
get_grouper
(self[, groupby])Return a list suitable for use in groupby calls.
matches_entities
(self, 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
(self, sampling_rate[, inplace, kind])Resample the Variable to the specified sampling rate.
split
(self, grouper)Split the current DenseRunVariable into multiple columns.
to_df
(self[, condition, entities, timing, …])Convert to a DataFrame, with columns for name and entities.
-
__init__
(self, name, values, run_info, source, sampling_rate)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(self, name, values, run_info, …)Initialize self.
apply
(self, func[, groupby])Applies the passed function to the groups defined by the groupby argument.
clone
(self[, data])Clone (deep copy) the current column, optionally replacing its data and/or any other attributes.
filter
(self[, filters, query, strict, inplace])Returns a copy of the current Variable with only rows that match the filters retained.
get_grouper
(self[, groupby])Return a list suitable for use in groupby calls.
matches_entities
(self, 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
(self, sampling_rate[, inplace, kind])Resample the Variable to the specified sampling rate.
split
(self, grouper)Split the current DenseRunVariable into multiple columns.
to_df
(self[, condition, entities, timing, …])Convert to a DataFrame, with columns for name and entities.
-
apply
(self, 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.
- Parameters
func (callable) – The function to apply to each group.
groupby (str or list) – Name(s) of column(s) defining the grouping.
kwargs (args,) – Optional positional and keyword arguments to pass onto the function call.
-
clone
(self, data=None, **kwargs)¶ Clone (deep copy) the current column, optionally replacing its data and/or any other attributes.
- Parameters
data (
pandas.DataFrame
or array_like) – 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
(self, 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
- Return type
BIDSVariable or None if no rows are left after filtering.
-
get_grouper
(self, groupby='run')¶ Return a list suitable for use in groupby calls.
- Parameters
groupby (str or list) – 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.
- Return type
list
-
matches_entities
(self, 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 (dict) – Optional keyword arguments to pass onto the class-specific merge() call. See merge_variables docstring for details.
- Returns
- Return type
A single BIDSVariable of the same class as the input variables.
See also
-
resample
(self, 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
(self, 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 currentDenseRunVariable
; a newDenseRunVariable
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
(self, condition=True, entities=True, timing=True, sampling_rate=None)[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.