Skip to content

Code conventions

Oscar Esteban edited this page Mar 5, 2018 · 2 revisions

General conventions:

niworkflows:

Some responsibilities of fMRIPrep that are generic are outsourced to the poldracklab/niworkflows package. Additionally, niworkflows ships with an internal version of nipype to make it easier to pin experimental versions of nipype. For this reason, no imports from the top-level nipype will be done to use the one packed with niworkflows:

from niworkflows.nipype.interfaces import fsl
bet = fsl.BET()

Writing workflows:

Whenever possible, instances of Node and Workflow should use the same names as the variables they are assigned to. This makes it easier to relate the content of the working directory to the code that generated it when debugging.

Workflow variables should end in _wf to indicate that they refer to Workflows and not Nodes. For instance, a workflow whose basename is myworkflow might be defined as follows:

from niworkflows.nipype.pipeline import engine as pe
myworkflow_wf = pe.Workflow(name='myworkflow_wf')

If a workflow is generated by a function, the name of the function should take the form init_<basename>_wf:

def init_myworkflow_wf(name='myworkflow_wf):
    workflow = pe.Workflow(name=name)
    ...
    return workflow

myworkflow_wf = init_workflow_wf(name='myworkflow_wf')

If multiple instances of the same workflow might be instantiated in the same namespace, the workflow names and variables should include either a numeric identifier or a one-word description, such as:

myworkflow0_wf = init_workflow_wf(name='myworkflow0_wf')
myworkflow1_wf = init_workflow_wf(name='myworkflow1_wf')

# or

myworkflow_lh_wf = init_workflow_wf(name='myworkflow_lh_wf')
myworkflow_rh_wf = init_workflow_wf(name='myworkflow_rh_wf')

Reports engine

fMRIPrep includes a reporting system that collects reportlets throughout the working directory structure. A reportlet is a visual element, HTML-compatible to visually show how a particular step of the processing worked. The reporting engine works with three basic steps:

  1. A Nipype interface generates a reportlet (for instance, the BOLD ROIs Plot here).
  2. A DerivativesDatasink included in the workflow instructs fMRIPrep to place a reportlets in under the <workdir>/reportlets folder. These data-sinks MUST have a name that starts with ds_report_ and they should specify a suffix for that particular reportlet. Again, this would be the DerivativesDataSink for the ROIs Plot
  3. Finally, the report engine crawls the <workdir>/reportlets folder and composes the final report using the reportlets as prescribed in the configuration file (see the configuration corresponding to the ROIs Plot).

Deviations from PEP8:

  • Line width: 99 characters