bidshandler.Session

class bidshandler.Session(id_, subject, initialize=True, no_folder=False)[source]

Bases: bidshandler.querymixin.QueryMixin

Session-level object.

Parameters:
  • id (str) – Id of the session. This is the sequence of characters after ‘ses-‘.
  • subject (bidshandler.Subject) – Parent Subject object containing this Session.
  • initialize (bool, optional) – Whether to parse the folder and load any child structures.
  • no_folder (bool, optional) – Whether or not the session is contained within a ses-XX folder. For experiments with multiple sessions each folder will correspond to a Session object, however if there is only a single session this can be omitted and the Subject folder is in fact the Session folder.
__init__(id_, subject, initialize=True, no_folder=False)[source]

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

Methods

__init__(id_, subject[, initialize, no_folder]) Initialize self.
add(other[, copier]) Add another Scan or Session to this object.
contained_files() Get the list of contained files.
delete() Delete the session information.
query(obj, token, condition, value) Query the BIDS object and return the appropriate data.
rename(id_) Change the sessions’ id.
scan([task, acq, run, return_all]) Return a list of all contained Scan’s corresponding to the provided values.

Attributes

ID ID with ‘ses’ prefix.
bids_tree Parent bidshandler.BIDSTree object.
date The recording date of the session.
inheritable_files List of files that are able to be inherited by child objects.
path Path to Session folder.
project Parent bidshandler.Project object.
projects
scans List of all contained bidshandler.Scan’s.
scans_tsv Path of associated scans.tsv file if there is one.
sessions
subjects
ID

ID with ‘ses’ prefix.

__contains__(other)[source]

Determine whether the Session object contains a scan.

Parameters:other (bidshandler.Scan) – Object to test whether it is contained in this Session.
Returns:Returns True if the object is contained within this Session.
Return type:bool
__iter__()[source]

Iterable of the contained Scan objects.

add(other, copier=<function _copyfiles>)[source]

Add another Scan or Session to this object.

Parameters:
  • other (Instance of bidshandler.Scan or bidshandler.Session) – Object to be added to this Session. The added object must already exist in the same context as this object.
  • copier (function, optional) – A function to facilitate the copying of any applicable data. This function must have the call signature function(src_files: list, dst_files: list) Where src_files is the list of files to be moved and dst_files is the list of corresponding destinations. This will default to using utils._copyfiles which simply implements shutil.copy() and creates any directories that do not already exist.
bids_tree

Parent bidshandler.BIDSTree object.

contained_files()[source]

Get the list of contained files.

Returns:file_list – List with paths to all contained files relating to the BIDS structure.
Return type:list
date

The recording date of the session.

Returns:known_date – Specific date of the year the session ocurred on.
Return type:datetime.date()
delete()[source]

Delete the session information.

inheritable_files

List of files that are able to be inherited by child objects.

path

Path to Session folder.

project

Parent bidshandler.Project object.

projects
query(obj, token, condition, value)

Query the BIDS object and return the appropriate data.

Parameters:
  • obj (str) – The object type that should be returned. This can be one of (‘project’, ‘subject’, ‘session’, ‘scan’)
  • token (str) –

    The key to query for. This can be a value from the following list:

    • task: Corresponds to the task key in the BIDS filename.
    • acquisition or acq: Corresponds to the acq key in the BIDS filename.
    • run: Corresponds to the run key in the BIDS filename.
    • proc: Corresponds to the proc key in the BIDS filename.
    • age: Corresponds to the age of the participant. [Only available for obj=’subject’]
    • sex: Corresponds to the gender of the participant. [Only available for obj=’subject’]
    • group: Corresponds to the group of the participant. [Only available for obj=’subject’]
    • rec_date: Corresponds to the time and date of the recording. The value can either be formatted like “%Y-%m-%d” (ie. YYYY-MM-DD) to specify a single day, or it can be specified to the second by formatting it using the format string “%Y-%m-%dT%H:%M:%S” (ie. YYYY-MM-DDTHH:mm:ss).
    • subjects: Corresponds to the number of subjects contained. [Only available for obj=’project’]
    • sessions: Corresponds to the number of sessions contained. [Only available for obj=’project’ or ‘subject’]
    • scans: Corresponds to the number of scans contained. [Only available for obj=’project’, ‘subject’ or ‘session’]
    • Any other token will be considered to be a key in the sidecar.json file.
  • condition (str) – One of (‘<’, ‘<=’, ‘=’, ‘!=’, ‘!!=’ (none equal), ‘=>’, ‘>’). Used to perform comaprisons between the value provided and the values the data have. The ‘!!=’ operator here is used to distinguish between the case of when you want to determine if something contains something that isn’t the value you specify, and whether something doesn’t contain the value specified. This operator is currently only supported for the tokens ‘task’, ‘acquisition’/’acq’, `’run’ and ‘proc’.
  • value (str | int | float) – The value the token has (or the value to compare using the condition argument). The value provided must match exactly if the equality operator is used, and must have a type appropriate for comparison if an inequality operator is used. Currently regex is not supported, but this may come in the future.
Returns:

return_data – List of objects that satisfy the provided query conditions.

Return type:

bidshandler.querylist.QueryList

rename(id_)[source]

Change the sessions’ id.

Parameters:id (str) – New id for the session object.
scan(task='.', acq='.', run='.', return_all=False)[source]

Return a list of all contained Scan’s corresponding to the provided values.

Parameters:
  • task (str) – Value of task in the BIDS filename.
  • acq (str) – Value of acq in the BIDS filename.
  • run (str) – Value of run in the BIDS filename.
  • return_all (bool) – Whether to return every scan in the session that matches the provided values or not.
Returns:

scan – List of Scan’s.

Return type:

list(bidshandler.Scan)

Notes

The task, acq and run arguments may all have regular expressions passed to them.

scans

List of all contained bidshandler.Scan’s.

Returns:All Scans within this Session.
Return type:list of bidshandler.Scan
scans_tsv

Path of associated scans.tsv file if there is one.

sessions
subjects