rtCommon.bidsRun


bidsRun.py

Implements the BIDS Run data type used for representing full fMRI scanning runs as sequences of BIDS incrementals.


Module Contents

Classes

BidsRun

Attributes

logger

rtCommon.bidsRun.logger
class rtCommon.bidsRun.BidsRun(**entities)
__eq__(other)

Return self==value.

getIncremental(index: int) rtCommon.bidsIncremental.BidsIncremental

Returns the incremental in the run at the provided index.

Parameters:

index – Which image of the run to get (0-indexed)

Returns:

Incremental at provided index.

Raises:

IndexError – If index is out of bounds for this run.

Examples

>>> print(run.numIncrementals())
5
>>> inc = run.getIncremental(1)
>>> inc2 = run.getIncremental(5)
IndexError
appendIncremental(incremental: rtCommon.bidsIncremental.BidsIncremental, validateAppend: bool = True) None

Appends an incremental to this run’s data, setting the run’s entities if the run is empty.

Parameters:
  • incremental – The incremental to add to the run.

  • validateAppend – Validate the incremental matches the current run’s data (default True). Turning off is useful for efficiently creating a whole run at once from an existing image volume, where all data is known to be match already.

Raises:

MetadataMismatchError – If either the incremental’s entities, its images’s NIfTI header, or its metadata doesn’t match the existing run’s data.

Examples

Suppose a NIfTI image and metadata dictionary are available in the environment.

>>> incremental = BidsIncremental(image, metadata)
>>> run = BidsRun()
>>> run.appendIncremental(incremental)
>>> metadata['subject'] = 'new_subject'
>>> incremental2 = BidsIncremental(image, metadata)
>>> run.appendIncremental(incremental2)
MetadataMismatchError
asSingleIncremental() rtCommon.bidsIncremental.BidsIncremental

Coalesces the entire run into a single BIDS-I that can be sent over a network, written to disk, or added to an archive.

Returns:

BidsIncremental with all image data and metadata represented by the

incrementals composing the run, or None if the run is empty.

Examples

>>> incremental = run.asSingleIncremental()
>>> incremental.writeToDisk('/tmp/new_dataset')
numIncrementals() int

Returns number of incrementals in this run.

getRunEntities() dict

Returns dictionary of the BIDS entities associated with this run.

Examples

>>> print(run.getRunEntities())
{'subject': '01', 'session': '01', 'task': 'test', run: 1,
'datatype': 'func', 'suffix': 'bold'}