Skip to content

Commit 96bb6dc

Browse files
authored
ENH: Restore carpetplot and other final adjustments (#3131)
## Changes proposed in this pull request Closing in on the alpha. Getting tests running, but hopefully we'll finish up the reports and cleanup tomorrow.
2 parents a9ae847 + e55f185 commit 96bb6dc

File tree

14 files changed

+269
-1168
lines changed

14 files changed

+269
-1168
lines changed

docs/installation.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Installation
66
There are two ways to install *fMRIPrep*:
77

88
* using container technologies (RECOMMENDED); or
9-
* within a `Manually Prepared Environment (Python 3.8+)`_, also known as
9+
* within a `Manually Prepared Environment (Python 3.10+)`_, also known as
1010
*bare-metal installation*.
1111

1212
The ``fmriprep`` command-line adheres to the `BIDS-Apps recommendations
@@ -42,8 +42,18 @@ or `Singularity <https://www.nipreps.org/apps/singularity/>`__ subsections.
4242
The *NiPreps* portal also contains
4343
`extended details of execution with the Docker wrapper <https://www.nipreps.org/apps/docker/#running-a-niprep-with-a-lightweight-wrapper>`__.
4444

45-
Manually Prepared Environment (Python 3.8+)
46-
===========================================
45+
In short, install the ``fmriprep-docker`` wrapper with pip::
46+
47+
$ python -m pip install fmriprep-docker
48+
49+
Then run the ``fmriprep-docker`` command-line as if you were running
50+
``fmriprep`` on a *bare-metal* installation::
51+
52+
$ fmriprep-docker <input_bids_path> <derivatives_path> <analysis_level> <named_options>
53+
54+
55+
Manually Prepared Environment (Python 3.10+)
56+
============================================
4757

4858
.. warning::
4959

@@ -56,7 +66,7 @@ A relatively interpretable description of how your environment can be set-up
5666
is found in the `Dockerfile <https://github.com/nipreps/fmriprep/blob/master/Dockerfile>`_.
5767
As an additional installation setting, FreeSurfer requires a license file (see :ref:`fs_license`).
5868

59-
On a functional Python 3.8 (or above) environment with ``pip`` installed,
69+
On a functional Python 3.10 (or above) environment with ``pip`` installed,
6070
*fMRIPrep* can be installed using the habitual command ::
6171

6272
$ python -m pip install fmriprep

docs/outputs.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ This layout, now the default, may be explicitly specified with the
6262
For compatibility with versions of fMRIPrep prior to 21.0, the
6363
`legacy layout`_ is available via ``--output-layout legacy``.
6464

65+
Processing level
66+
----------------
67+
As of version 23.2.0, fMRIPrep supports three levels of derivatives:
68+
69+
* ``--level minimal``: This processing mode aims to produce the smallest
70+
working directory and output dataset possible, while enabling all further
71+
processing results to be deterministically generated. Most components of
72+
the `visual reports`_ can be generated at this level, so the quality of
73+
preprocessing can be assessed. Because no resampling is done, confounds
74+
and carpetplots will be missing from the reports.
75+
* ``--level resampling``: This processing mode aims to produce additional
76+
derivatives that enable third-party resampling, resampling BOLD series
77+
in the working directory as needed, but these are not saved to the output
78+
directory.
79+
The ``--me-output-echos`` flag will be enabled at this level, in which
80+
case the individual echos will be saved to the working directory after
81+
slice-timing correction, head-motion correction, and susceptibility
82+
distortion correction.
83+
* ``--level full``: This processing mode aims to produce all derivatives
84+
that have previously been a part of the fMRIPrep output dataset.
85+
This is the default processing level.
86+
6587
Visual Reports
6688
--------------
6789
*fMRIPrep* outputs summary reports, written to ``<output dir>/fmriprep/sub-<subject_label>.html``.

docs/usage.rst

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ would be equivalent to the latest example: ::
128128

129129
Reusing precomputed derivatives
130130
-------------------------------
131+
131132
Reusing a previous, partial execution of *fMRIPrep*
132133
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133134
*fMRIPrep* will pick up where it left off a previous execution, so long as the work directory
134135
points to the same location, and this directory has not been changed/manipulated.
136+
Some workflow nodes will rerun unconditionally, so there will always be some amount of
137+
reprocessing.
135138

136139
Using a previous run of *FreeSurfer*
137140
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -143,48 +146,39 @@ You can use the ``--fs-subjects-dir`` flag to specify a different location to sa
143146
FreeSurfer outputs.
144147
If precomputed results are found, they will be reused.
145148

146-
The *anatomical fast-track*
147-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
148-
Starting with version 20.1.0, *fMRIPrep* has a command-line argument (``--anat-derivatives <PATH>``)
149-
to indicate a path from which the preprocessed information derived from the T1w, T2w (if present) and
150-
FLAIR (if present) images.
151-
This feature was envisioned to help process very large multi-session datasets where the anatomical
152-
images can be averaged (i.e., anatomy is not expected to vary substantially across sessions).
153-
An example where this kind of processing would be useful is
154-
`My Connectome <https://openneuro.org/datasets/ds000031/>`__, a dataset that contains
155-
107 sessions for a single-subject.
156-
Most of these sessions contain anatomical information which, given the design of the dataset, can be averaged
157-
across sessions as no substantial changes should happen.
158-
In other words, the anatomical information of the dataset can be considered as *cross-sectional*.
159-
Before version 20.1.0, preprocessing this dataset would be hard for two limitations:
160-
161-
* if the dataset were to be processed in just one enormous job (be it in a commercial Cloud or
162-
:abbr:`HPC (high-performance computing)` resources), the amount of data to be processed surely
163-
would exceed the time limitations per job (and/or related issues, such as restarting from where
164-
it left before); or
165-
* if the processing were `split in sessions <https://github.com/nipreps/fmriprep/issues/1175>`__,
166-
then *fMRIPrep* would attempt to re-process the anatomical information for every session.
167-
168-
Because processing this emerging type of datasets (*densely sampled neuroimaging*) was impractical with
169-
*fMRIPrep*, the option ``--anat-derivatives`` will shortcut the whole anatomical processing.
170-
171-
.. danger::
172-
Using the *anatomical fast-track* (the ``--anat-derivatives`` argument) has important side-effects
173-
that risk the reproducibility and reliability of *fMRIPrep*.
174-
This flag breaks *fMRIPrep*'s internal tracing of provenance, and it trusts whatever input *fMRIPrep*
175-
is given (so long it is BIDS-Derivatives compliant and contains all the necessary files).
176-
177-
When reporting results obtained with ``--anat-derivatives``, please make sure you highlight this
178-
particular deviation from *fMRIPrep*, and clearly describe the alternative preprocessing of
179-
anatomical data.
180-
181-
.. attention::
182-
When the intention is to combine the *anatomical fast-track* with some advanced options that involve
183-
standard spaces (e.g., ``--cifti-output``), please make sure you include the
184-
``MNI152NLin6Asym`` space to the ``--output-spaces`` list in the first invocation of *fMRIPrep*
185-
(or *sMRIPrep*) from which the results are to be reused.
186-
Otherwise, a warning message indicating that *fMRIPrep*'s expectations were not met will be issued,
187-
and the pre-computed anatomical derivatives will not be reused.
149+
BIDS Derivatives reuse
150+
~~~~~~~~~~~~~~~~~~~~~~
151+
As of version 23.2.0, *fMRIPrep* can reuse precomputed derivatives that follow BIDS Derivatives
152+
conventions. To provide derivatives to *fMRIPrep*, use the ``--derivatives`` (``-d``) flag one
153+
or more times.
154+
155+
This mechanism replaces the earlier, more limited ``--anat-derivatives`` flag.
156+
157+
.. note::
158+
Derivatives reuse is considered *experimental*.
159+
160+
This feature has several intended use-cases:
161+
162+
* To enable fMRIPrep to be run in a "minimal" mode, where only the most essential
163+
derivatives are generated. This can be useful for large datasets where disk space
164+
is a concern, or for users who only need a subset of the derivatives. Further
165+
derivatives may be generated later, or by a different tool.
166+
* To enable fMRIPrep to be integrated into a larger processing pipeline, where
167+
other tools may generate derivatives that fMRIPrep can use in place of its own
168+
steps.
169+
* To enable users to substitute their own custom derivatives for those generated
170+
by fMRIPrep. For example, a user may wish to use a different brain extraction
171+
tool, or a different registration tool, and then use fMRIPrep to generate the
172+
remaining derivatives.
173+
* To enable complicated meta-workflows, where fMRIPrep is run multiple times
174+
with different options, and the results are combined. For example, the
175+
`My Connectome <https://openneuro.org/datasets/ds000031/>`__ dataset contains
176+
107 sessions for a single-subject. Processing of all sessions simultaneously
177+
would be impractical, but the anatomical processing can be done once, and
178+
then the functional processing can be done separately for each session.
179+
180+
See also the ``--level`` flag, which can be used to control which derivatives are
181+
generated.
188182

189183
Troubleshooting
190184
---------------
@@ -195,7 +189,7 @@ Information on how to customize and understand these files can be found on the
195189
page.
196190

197191
**Support and communication**.
198-
The documentation of this project is found here: https://fmriprep.readthedocs.org/en/latest/.
192+
The documentation of this project is found here: https://fmriprep.org/en/latest/.
199193

200194
All bugs, concerns and enhancement requests for this software can be submitted here:
201195
https://github.com/nipreps/fmriprep/issues.

docs/workflows.rst

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ is presented below:
3737
For example, ``anat_preproc_wf`` is a sub-workflow that is generated by the
3838
:func:`~smriprep.workflows.anatomical.init_anat_preproc_wf` (see below).
3939
Because each task and run of functional data is processed separately,
40-
:func:`~fmriprep.workflows.bold.base.init_func_preproc_wf` names the
40+
:func:`~fmriprep.workflows.bold.base.init_bold_wf` names the
4141
resulting workflows using input parameters, resulting in
4242
``func_preproc_task_{task}_run_{run}_wf``.
4343
* Datasinks begin with ``ds_``, and save files to the output directory.
@@ -287,19 +287,41 @@ from the ``aseg.mgz`` file as described in
287287

288288
BOLD preprocessing
289289
------------------
290-
:py:func:`~fmriprep.workflows.bold.base.init_func_preproc_wf`
290+
*fMRIPrep* performs a series of steps to preprocess :abbr:`BOLD (blood-oxygen level-dependent)`
291+
data. Broadly, these are split into fit and transform stages.
292+
293+
The following figures show the overall workflow graph and the ``bold_fit_wf``
294+
subgraph:
295+
296+
:py:func:`~fmriprep.workflows.bold.base.init_bold_wf`
291297

292298
.. workflow::
293299
:graph2use: orig
294300
:simple_form: yes
295301

296302
from fmriprep.workflows.tests import mock_config
297303
from fmriprep import config
298-
from fmriprep.workflows.bold.base import init_func_preproc_wf
304+
from fmriprep.workflows.bold.base import init_bold_wf
299305
with mock_config():
300306
bold_file = config.execution.bids_dir / 'sub-01' / 'func' \
301307
/ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
302-
wf = init_func_preproc_wf(str(bold_file))
308+
wf = init_bold_wf(bold_series=[str(bold_file)])
309+
310+
.. _bold_fit:
311+
312+
:py:func:`~fmriprep.workflows.bold.fit.init_bold_fit_wf`
313+
314+
.. workflow::
315+
:graph2use: orig
316+
:simple_form: yes
317+
318+
from fmriprep.workflows.tests import mock_config
319+
from fmriprep import config
320+
from fmriprep.workflows.bold.fit import init_bold_fit_wf
321+
with mock_config():
322+
bold_file = config.execution.bids_dir / 'sub-01' / 'func' \
323+
/ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
324+
wf = init_bold_fit_wf(bold_series=[str(bold_file)], fieldmap_id="fmap")
303325

304326
Preprocessing of :abbr:`BOLD (blood-oxygen level-dependent)` files is
305327
split into multiple sub-workflows described below.
@@ -308,31 +330,31 @@ split into multiple sub-workflows described below.
308330

309331
BOLD reference image estimation
310332
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311-
:py:func:`~niworkflows.func.util.init_bold_reference_wf`
333+
:py:func:`~fmriprep.workflows.bold.reference.init_raw_boldref_wf`
312334

313335
.. workflow::
314336
:graph2use: orig
315337
:simple_form: yes
316338

317-
from niworkflows.func.util import init_bold_reference_wf
318-
wf = init_bold_reference_wf(omp_nthreads=1)
339+
from fmriprep.workflows.bold.reference import init_raw_boldref_wf
340+
wf = init_raw_boldref_wf()
319341

320342
This workflow estimates a reference image for a
321-
:abbr:`BOLD (blood-oxygen level-dependent)` series.
322-
If a single-band reference ("sbref") image associated with the BOLD series is
323-
available, then it is used directly.
324-
If not, a reference image is estimated from the BOLD series as follows:
343+
:abbr:`BOLD (blood-oxygen level-dependent)` series as follows:
325344
When T1-saturation effects ("dummy scans" or non-steady state volumes) are
326345
detected, they are averaged and used as reference due to their
327346
superior tissue contrast.
328347
Otherwise, a median of motion corrected subset of volumes is used.
329348

330-
The reference image is then used to calculate a brain mask for the
331-
:abbr:`BOLD (blood-oxygen level-dependent)` signal using *NiWorkflows*'
332-
:py:func:`~niworkflows.func.util.init_enhance_and_skullstrip_bold_wf`.
333-
Further, the reference is fed to the :ref:`head-motion estimation
334-
workflow <bold_hmc>` and the :ref:`registration workflow to map
335-
BOLD series into the T1w image of the same subject <bold_reg>`.
349+
This reference is used for :ref:`head-motion estimation <bold_hmc>`.
350+
351+
For the :ref:`registration workflow <bold_reg>`, the reference image is
352+
either the above described reference image or a single-band reference,
353+
if one is found in the input dataset.
354+
In either case, this image is contrast-enhanced and skull-stripped
355+
(see :py:func:`~niworkflows.func.util.init_enhance_and_skullstrip_bold_wf`).
356+
If fieldmaps are present, the skull-stripped reference is corrected
357+
prior to registration.
336358

337359
.. figure:: _static/sub-01_task-balloonanalogrisktask_run-1_desc-rois_bold.svg
338360

@@ -418,14 +440,19 @@ Theory, methods and references are found within the
418440

419441
Pre-processed BOLD in native space
420442
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
421-
:py:func:`~fmriprep.workflows.bold.resampling.init_bold_preproc_trans_wf`
443+
:py:func:`~fmriprep.workflows.bold.fit.init_bold_native_wf`
422444

423445
.. workflow::
424446
:graph2use: orig
425447
:simple_form: yes
426448

427-
from fmriprep.workflows.bold import init_bold_preproc_trans_wf
428-
wf = init_bold_preproc_trans_wf(mem_gb=3, omp_nthreads=1)
449+
from fmriprep.workflows.tests import mock_config
450+
from fmriprep import config
451+
from fmriprep.workflows.bold.fit import init_bold_native_wf
452+
with mock_config():
453+
bold_file = config.execution.bids_dir / 'sub-01' / 'func' \
454+
/ 'sub-01_task-mixedgamblestask_run-01_bold.nii.gz'
455+
wf = init_bold_native_wf(bold_series=[str(bold_file)], fieldmap_id='fmap')
429456

430457
A new *preproc* :abbr:`BOLD (blood-oxygen level-dependent)` series is generated
431458
from the slice-timing corrected or the original data (if
@@ -442,16 +469,14 @@ Interpolation uses a Lanczos kernel.
442469

443470
EPI to T1w registration
444471
~~~~~~~~~~~~~~~~~~~~~~~
445-
:py:func:`~fmriprep.workflows.bold.registration.init_bold_reg_wf`
472+
:py:func:`~fmriprep.workflows.bold.registration.init_bbreg_wf`
446473

447474
.. workflow::
448-
:graph2use: orig
475+
:graph2use: hierarchical
449476
:simple_form: yes
450477

451-
from fmriprep.workflows.bold import init_bold_reg_wf
452-
wf = init_bold_reg_wf(
453-
freesurfer=True,
454-
mem_gb=1,
478+
from fmriprep.workflows.bold.registration import init_bbreg_wf
479+
wf = init_bbreg_wf(
455480
omp_nthreads=1,
456481
use_bbr=True,
457482
bold2t1w_dof=9,
@@ -478,23 +503,14 @@ original, affine registration.
478503

479504
Resampling BOLD runs onto standard spaces
480505
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
481-
:py:func:`~fmriprep.workflows.bold.resampling.init_bold_std_trans_wf`
506+
:py:func:`~fmriprep.workflows.bold.apply.init_bold_volumetric_resample_wf`
482507

483508
.. workflow::
484509
:graph2use: colored
485510
:simple_form: yes
486511

487-
from niworkflows.utils.spaces import SpatialReferences
488-
from fmriprep.workflows.bold import init_bold_std_trans_wf
489-
wf = init_bold_std_trans_wf(
490-
freesurfer=True,
491-
mem_gb=3,
492-
omp_nthreads=1,
493-
spaces=SpatialReferences(
494-
spaces=[('MNI152Lin', {}), ('MNIPediatricAsym', {'cohort': '6'})],
495-
checkpoint=True),
496-
multiecho=False,
497-
)
512+
from fmriprep.workflows.bold.apply import init_bold_volumetric_resample_wf
513+
wf = init_bold_volumetric_resample_wf(metadata={}, fieldmap_id='fmap')
498514

499515
This sub-workflow concatenates the transforms calculated upstream (see
500516
`Head-motion estimation`_, `Susceptibility Distortion Correction (SDC)`_ --if
@@ -523,7 +539,10 @@ EPI sampled to FreeSurfer surfaces
523539
wf = init_bold_surf_wf(
524540
mem_gb=1,
525541
surface_spaces=['fsnative', 'fsaverage5'],
526-
medial_surface_nan=False)
542+
medial_surface_nan=False,
543+
metadata={},
544+
output_dir='.',
545+
)
527546

528547
If FreeSurfer processing is enabled, the motion-corrected functional series
529548
(after single shot resampling to T1w space) is sampled to the
@@ -540,7 +559,7 @@ HCP Grayordinates
540559
:py:func:`~fmriprep.workflows.bold.resampling.init_bold_fsLR_resampling_wf`
541560

542561
.. workflow::
543-
:graph2use: colored
562+
:graph2use: orig
544563
:simple_form: yes
545564

546565
from fmriprep.workflows.bold.resampling import init_bold_fsLR_resampling_wf
@@ -595,6 +614,17 @@ T2*-driven echo combination
595614
~~~~~~~~~~~~~~~~~~~~~~~~~~~
596615
:py:func:`~fmriprep.workflows.bold.t2s.init_bold_t2s_wf`
597616

617+
.. workflow::
618+
:graph2use: colored
619+
:simple_form: yes
620+
621+
from fmriprep.workflows.bold.t2s import init_bold_t2s_wf
622+
wf = init_bold_t2s_wf(
623+
echo_times=[0.015, 0.030, 0.045],
624+
mem_gb=1,
625+
omp_nthreads=1,
626+
)
627+
598628
If multi-echo :abbr:`BOLD (blood-oxygen level-dependent)` data is supplied,
599629
this workflow uses the `tedana`_ `T2* workflow`_ to generate an adaptive T2* map
600630
and optimally weighted combination of all supplied single echo time series.

0 commit comments

Comments
 (0)