Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

BIDSLayout.get_collections / bids.variables #21

Merged
merged 14 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion bids/layout/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,57 @@ def get_tr(self, derivatives=False, **entities):
.format(entities))
return all_trs.pop()

class BIDSLayoutVariablesMixin:
def get_collections(self, level, types=None, variables=None, merge=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does get_collections() already work using the current state of BIDSLayout? would be great :-)

Copy link
Collaborator Author

@adelavega adelavega Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite yet. It's not terribly far though.

sampling_rate=None, skip_empty=False, **kwargs):
"""Return one or more variable Collections in the BIDS project.
Parameters
----------
level : {'run', 'session', 'subject', 'dataset'}
The level of analysis to return variables for.
Must be one of 'run', 'session','subject', or 'dataset'.
types : str or list
Types of variables to retrieve. All valid values reflect the
filename stipulated in the BIDS spec for each kind of variable.
Valid values include: 'events', 'physio', 'stim', 'scans',
'participants', 'sessions', and 'regressors'. Default is None.
variables : list
Optional list of variables names to return. If None, all available
variables are returned.
merge : bool
If True, variables are merged across all observations of the
current level. E.g., if level='subject', variables from all
subjects will be merged into a single collection. If False, each
observation is handled separately, and the result is returned
as a list.
sampling_rate : int or str
If level='run', the sampling rate to pass onto the returned
:obj:`bids.variables.collections.BIDSRunVariableCollection`.
skip_empty : bool
Whether or not to skip empty Variables (i.e., where there are no
rows/records in a file after applying any filtering operations
like dropping NaNs).
kwargs
Optional additional arguments to pass onto
:obj:`bids.variables.io.load_variables`.
Returns
-------
list of :obj:`bids.variables.collections.BIDSVariableCollection`
or :obj:`bids.variables.collections.BIDSVariableCollection`
A list if merge=False;
a single :obj:`bids.variables.collections.BIDSVariableCollection`
if merge=True.
"""

from bids.variables import load_variables
index = load_variables(self, types=types, levels=level,
skip_empty=skip_empty, **kwargs)
return index.get_collections(level, variables, merge,
sampling_rate=sampling_rate)



class BIDSLayout(BIDSLayoutMRIMixin, BIDSLayoutWritingMixin):
class BIDSLayout(BIDSLayoutMRIMixin, BIDSLayoutWritingMixin, BIDSLayoutVariablesMixin):
"""A convenience class to provide access to an in-memory representation of a BIDS dataset.

.. code-block::
Expand Down