Developers - API
The NiPreps community and contributing guidelines
sMRIPost-LINC is a NiPreps application, and abides by the NiPreps Community guidelines. Please, make sure you have read and understood all the documentation provided in the NiPreps portal before you get started.
Setting up your development environment
We believe that sMRIPost-LINC must be free to use, inspect, and critique. Correspondingly, you should be free to modify our software to improve it or adapt it to new use cases and we especially welcome contributions to improve it or its documentation.
We actively direct efforts into making the scrutiny and improvement processes as easy as possible. As part of such efforts, we maintain some tips and guidelines for developers to help minimize your burden if you want to modify the software.
Internal configuration system
A Python module to maintain unique, run-wide sMRIPost-LINC settings.
This module implements the memory structures to keep a consistent, singleton config.
Settings are passed across processes via filesystem, and a copy of the settings for
each run and subject is left under
<fmriprep_dir>/sub-<participant_id>/log/<run_unique_id>/smripost_linc.toml.
Settings are stored using ToML.
The module has a to_filename() function to allow writing out
the settings to hard disk in ToML format, which looks like:
This config file is used to pass the settings across processes,
using the load() function.
Configuration sections
- class smripost_linc.config.environment[source]
Read-only options regarding the platform and environment.
Crawls runtime descriptive settings (e.g., default FreeSurfer license, execution environment, nipype and sMRIPost-LINC versions, etc.). The
environmentsection is not loaded in from file, only written out when settings are exported. This config section is useful when reporting issues, and these variables are tracked whenever the user does not opt-out using the--notrackargument.- cpu_count = 2
Number of available CPUs.
- exec_docker_version = None
Version of Docker Engine.
- exec_env = 'posix'
A string representing the execution platform.
- free_mem = None
Free memory at start.
- nipype_version = '1.9.1'
Nipype’s current version.
- overcommit_limit = '50%'
Linux’s kernel virtual memory overcommit limits.
- overcommit_policy = 'heuristic'
Linux’s kernel virtual memory overcommit policy.
- templateflow_version = '24.2.2'
The TemplateFlow client version installed.
- version = '0.1.dev5+g899b498'
sMRIPost-LINC’s version.
- class smripost_linc.config.execution[source]
Configure run-level settings.
- aggr_ses_reports = None
Maximum number of sessions aggregated in one subject’s visual report.
- atlases = None
Atlases to use.
- bids_database_dir = None
Path to the directory containing SQLite database indices for the input BIDS dataset.
- bids_description_hash = None
Checksum (SHA256) of the
dataset_description.jsonof the BIDS dataset.
- bids_dir = None
An existing path to the dataset, which must be BIDS-compliant.
- bids_filters = None
A dictionary of BIDS selection filters.
- boilerplate_only = False
Only generate a boilerplate.
- country_code = 'CAN'
Country ISO code used by carbon trackers.
- datasets = {}
Path(s) to search for pre-computed derivatives or BIDS-Atlas datasets
- debug = []
Debug mode(s).
- fs_license_file = None
An existing file containing a FreeSurfer license.
- fs_subjects_dir = None
An existing directory containing FreeSurfer subjects.
- layout = None
A
BIDSLayoutobject, seeinit().
- log_dir = None
The path to a directory that contains execution logs.
- log_level = 25
Output verbosity.
- low_mem = None
Utilize uncompressed NIfTIs and other tricks to minimize memory allocation.
- md_only_boilerplate = False
Do not convert boilerplate from MarkDown to LaTex and HTML.
- notrack = False
Do not collect telemetry information for sMRIPost-LINC.
- output_dir = None
Folder where derivatives will be stored.
- output_spaces = None
List of (non)standard spaces designated (with the
--output-spacesflag of the command line) as spatial references for outputs.
- participant_label = None
List of participant identifiers that are to be preprocessed.
- reports_only = False
Only build the reports, based on the reportlets found in a cached working directory.
- run_uuid = '20241205-205620_79a44d32-95fa-445b-b8be-3c1011a1992e'
Unique identifier of this particular run.
- sloppy = False
Run in sloppy mode (meaning, suboptimal parameters that minimize run-time).
- templateflow_home = PosixPath('/home/docs/.cache/templateflow')[source]
The root folder of the TemplateFlow client.
- track_carbon = False
Tracks power draws using CodeCarbon package.
- work_dir = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/smripost-linc/checkouts/latest/docs/work')[source]
Path to a working directory where intermediate results will be available.
- write_graph = False
Write out the computational graph corresponding to the planned preprocessing.
- class smripost_linc.config.workflow[source]
Configure the particular execution graph of this workflow.
- cifti_output = None
Generate HCP Grayordinates, accepts either
'91k'(default) or'170k'.
- dummy_scans = None
Set a number of initial scans to be considered nonsteady states.
- err_on_warn = False
Cast sMRIPost-LINC warnings to errors.
- ignore = None
Ignore particular steps for sMRIPost-LINC.
- class smripost_linc.config.nipype[source]
Nipype settings.
- crashfile_format = 'txt'
The file format for crashfiles, either text (txt) or pickle (pklz).
- get_linked_libs = False
Run NiPype’s tool to enlist linked libraries for every interface.
- memory_gb = None
Estimation in GB of the RAM this workflow can allocate at any given time.
- nprocs = 2
Number of processes (compute tasks) that can be run in parallel (multiprocessing only).
- omp_nthreads = None
Number of CPUs a single process can access for multithreaded execution.
- plugin = 'MultiProc'
NiPype’s execution plugin.
- plugin_args = {'maxtasksperchild': 1, 'raise_insufficient': False}
Settings for NiPype’s execution plugin.
- remove_unnecessary_outputs = True
Clean up unused outputs after running
- resource_monitor = False
Enable resource monitor.
- stop_on_first_crash = True
Whether the workflow should stop or continue after the first error.
Usage
A config file is used to pass settings and collect information as the execution graph is built across processes.
from smripost_linc import config
config_file = config.execution.work_dir / '.smripost_linc.toml'
config.to_filename(config_file)
# Call build_workflow(config_file, retval) in a subprocess
with Manager() as mgr:
from .workflow import build_workflow
retval = mgr.dict()
p = Process(target=build_workflow, args=(str(config_file), retval))
p.start()
p.join()
config.load(config_file)
# Access configs from any code section as:
value = config.section.setting
Logging
Other responsibilities
The config is responsible for other conveniency actions.
Switching Python’s
multiprocessingto forkserver mode.Set up a filter for warnings as early as possible.
Automated I/O magic operations. Some conversions need to happen in the store/load processes (e.g., from/to
Path<->str,BIDSLayout, etc.)
- smripost_linc.config.from_dict(settings, init=True, ignore=None)[source]
Read settings from a flat dictionary.
- smripost_linc.config.load(filename, skip=None, init=True)[source]
Load settings from file.
- Parameters:
filename (
os.PathLike) – TOML file containing sMRIPost-LINC configuration.skip (dict or None) – Sets of values to ignore during load, keyed by section name
init (bool or
Container) – Initialize all, none, or a subset of configurations.
Workflows
sMRIPost-LINC workflows
- smripost_linc.workflows.base.init_smripost_linc_wf()[source]
Build sMRIPost-LINC’s pipeline.
This workflow organizes the execution of sMRIPost-LINC, with a sub-workflow for each subject.
- Workflow Graph
- smripost_linc.workflows.base.init_single_subject_wf(subject_id: str, atlases: list)[source]
Organize the postprocessing pipeline for a single subject.
It collects and reports information about the subject, and prepares sub-workflows to postprocess each BOLD series.
- Workflow Graph
- Parameters:
subject_id (
str) – Subject label for this single-subject workflow.
Notes
Load sMRIPost-LINC config file.
Collect sMRIPrep and Freesurfer derivatives.
Warp/convert atlases to fsnative-space annot files.
Use mri_anatomical_stats to extract brain tissue volumes for each of the atlases.
Extract Euler number from recon-all.log.
Workflows for working with FreeSurfer derivatives.
Workflows for parcellating imaging data.