Skip to content

Commit 8bf0180

Browse files
authored
Merge pull request #1040 from oesteban/enh/mni-2mm-resolution
[ENH] Revise resampling grid for template outputs
2 parents 83c4f1e + db57fd9 commit 8bf0180

File tree

8 files changed

+91
-39
lines changed

8 files changed

+91
-39
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ jobs:
330330
--debug --write-graph --use-syn-sdc --use-aroma \
331331
--ignore-aroma-denoising-errors --mem_mb 4096 \
332332
--output-space T1w template fsaverage5 \
333+
--template-resampling-grid native \
333334
--nthreads 2 -vv
334335
sudo find /tmp/ds005/work -not -name "*.svg" -not -name "*.html" -not -name "*.rst" \
335336
-not -name "*.mat" -not -name "*.lta" -type f -delete
@@ -416,6 +417,7 @@ jobs:
416417
/tmp/data/ds054 /tmp/ds054/derivatives participant \
417418
--fs-no-reconall --debug --force-syn \
418419
--output-space T1w template \
420+
--template-resampling-grid 2mm \
419421
--mem_mb 4096 --nthreads 2 -vv
420422
- run:
421423
name: Checking outputs of fMRIPrep
@@ -519,6 +521,7 @@ jobs:
519521
--config $PWD/nipype.cfg -w /tmp/ds000210/work \
520522
/tmp/data/ds000210 /tmp/ds000210/derivatives participant \
521523
--fs-no-reconall --t2s-coreg --use-syn-sdc \
524+
--template-resampling-grid native \
522525
--debug --write-graph --mem_mb 4096 --nthreads 2 -vv
523526
- run:
524527
name: Checking outputs of fMRIPrep

docs/workflows.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ is presented below:
4545
fmap_demean=True,
4646
use_syn=True,
4747
force_syn=True,
48-
output_grid_ref=None,
48+
template_out_grid='native',
4949
use_aroma=False,
5050
ignore_aroma_err=False)
5151

@@ -241,7 +241,7 @@ BOLD preprocessing
241241
fmap_demean=True,
242242
use_syn=True,
243243
force_syn=True,
244-
output_grid_ref=None,
244+
template_out_grid='native',
245245
use_aroma=False,
246246
ignore_aroma_err=False)
247247

@@ -449,7 +449,7 @@ EPI to MNI transformation
449449
template='MNI152NLin2009cAsym',
450450
mem_gb=1,
451451
omp_nthreads=1,
452-
output_grid_ref=None)
452+
template_out_grid='native')
453453

454454
This sub-workflow concatenates the transforms calculated upstream (see
455455
`Head-motion estimation`_, `Susceptibility Distortion Correction (SDC)`_ --if
@@ -461,6 +461,16 @@ It also maps the T1w-based mask to MNI space.
461461
Transforms are concatenated and applied all at once, with one interpolation (Lanczos)
462462
step, so as little information is lost as possible.
463463

464+
The output space grid can be specified using the ``template_out_grid`` argument.
465+
This option accepts the following (``str``) values:
466+
467+
* ``'native'``: the original resolution of the BOLD image will be used.
468+
* ``'1mm'``: uses the 1:math:`\times`1:math:`\times`1 [mm] version of the template.
469+
* ``'2mm'``: uses the 2:math:`\times`2:math:`\times`2 [mm] version of the template.
470+
* **Path to arbitrary reference file**: the output will be resampled on a grid with
471+
same resolution as this reference.
472+
473+
464474
EPI sampled to FreeSurfer surfaces
465475
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
466476
:mod:`fmriprep.workflows.bold.resampling.init_bold_surf_wf`

fmriprep/cli/run.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,15 @@ def get_parser():
132132
choices=['MNI152NLin2009cAsym'], default='MNI152NLin2009cAsym',
133133
help='volume template space (default: MNI152NLin2009cAsym)')
134134
g_conf.add_argument(
135-
'--output-grid-reference', required=False, action='store', default=None,
136-
help='Grid reference image for resampling BOLD files to volume template space. '
135+
'--output-grid-reference', required=False, action='store',
136+
help='Deprecated after FMRIPREP 1.0.8. Please use --template-resampling-grid instead.')
137+
g_conf.add_argument(
138+
'--template-resampling-grid', required=False, action='store', default='native',
139+
help='Keyword ("native", "1mm", or "2mm") or path to an existing file. '
140+
'Allows to define a reference grid for the resampling of BOLD images in template '
141+
'space. Keyword "native" will use the original BOLD grid as reference. '
142+
'Keywords "1mm" and "2mm" will use the corresponding isotropic template '
143+
'resolutions. If a path is given, the grid of that image will be used. '
137144
'It determines the field of view and resolution of the output images, '
138145
'but is not used in normalization.')
139146
g_conf.add_argument(
@@ -416,6 +423,13 @@ def build_workflow(opts, retval):
416423
uuid=run_uuid)
417424
)
418425

426+
template_out_grid = opts.template_resampling_grid
427+
if opts.output_grid_reference is not None:
428+
logger.warning(
429+
'Option --output-grid-reference is deprecated, please use '
430+
'--template-resampling-grid')
431+
template_out_grid = template_out_grid or opts.output_grid_reference
432+
419433
retval['workflow'] = init_fmriprep_wf(
420434
subject_list=subject_list,
421435
task_id=opts.task_id,
@@ -435,7 +449,7 @@ def build_workflow(opts, retval):
435449
output_spaces=opts.output_space,
436450
template=opts.template,
437451
medial_surface_nan=opts.medial_surface_nan,
438-
output_grid_ref=opts.output_grid_reference,
452+
template_out_grid=template_out_grid,
439453
hires=opts.hires,
440454
use_bbr=opts.use_bbr,
441455
bold2t1w_dof=opts.bold2t1w_dof,

fmriprep/workflows/base.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
3535
omp_nthreads, skull_strip_template, work_dir, output_dir, bids_dir,
3636
freesurfer, output_spaces, template, medial_surface_nan, hires,
3737
use_bbr, bold2t1w_dof, fmap_bspline, fmap_demean, use_syn, force_syn,
38-
use_aroma, ignore_aroma_err, output_grid_ref):
38+
use_aroma, ignore_aroma_err, template_out_grid):
3939
"""
4040
This workflow organizes the execution of FMRIPREP, with a sub-workflow for
4141
each subject.
@@ -78,7 +78,7 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
7878
force_syn=True,
7979
use_aroma=False,
8080
ignore_aroma_err=False,
81-
output_grid_ref=None)
81+
template_out_grid='native')
8282
8383
8484
Parameters
@@ -148,8 +148,9 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
148148
Perform ICA-AROMA on MNI-resampled functional series
149149
ignore_aroma_err : bool
150150
Do not fail on ICA-AROMA errors
151-
output_grid_ref : str or None
152-
Path of custom reference image for normalization
151+
template_out_grid : str
152+
Keyword ('native', '1mm' or '2mm') or path of custom reference
153+
image for normalization
153154
154155
"""
155156
fmriprep_wf = pe.Workflow(name='fmriprep_wf')
@@ -190,7 +191,7 @@ def init_fmriprep_wf(subject_list, task_id, run_uuid,
190191
fmap_demean=fmap_demean,
191192
use_syn=use_syn,
192193
force_syn=force_syn,
193-
output_grid_ref=output_grid_ref,
194+
template_out_grid=template_out_grid,
194195
use_aroma=use_aroma,
195196
ignore_aroma_err=ignore_aroma_err)
196197

@@ -213,7 +214,7 @@ def init_single_subject_wf(subject_id, task_id, name,
213214
omp_nthreads, skull_strip_template, reportlets_dir, output_dir,
214215
bids_dir, freesurfer, output_spaces, template, medial_surface_nan,
215216
hires, use_bbr, bold2t1w_dof, fmap_bspline, fmap_demean, use_syn,
216-
force_syn, output_grid_ref, use_aroma, ignore_aroma_err):
217+
force_syn, template_out_grid, use_aroma, ignore_aroma_err):
217218
"""
218219
This workflow organizes the preprocessing pipeline for a single subject.
219220
It collects and reports information about the subject, and prepares
@@ -255,7 +256,7 @@ def init_single_subject_wf(subject_id, task_id, name,
255256
fmap_demean=True,
256257
use_syn=True,
257258
force_syn=True,
258-
output_grid_ref=None,
259+
template_out_grid='native',
259260
use_aroma=False,
260261
ignore_aroma_err=False)
261262
@@ -322,8 +323,9 @@ def init_single_subject_wf(subject_id, task_id, name,
322323
If fieldmaps are present and enabled, this is not run, by default.
323324
force_syn : bool
324325
**Temporary**: Always run SyN-based SDC
325-
output_grid_ref : str or None
326-
Path of custom reference image for normalization
326+
template_out_grid : str
327+
Keyword ('native', '1mm' or '2mm') or path of custom reference
328+
image for normalization
327329
use_aroma : bool
328330
Perform ICA-AROMA on MNI-resampled functional series
329331
ignore_aroma_err : bool
@@ -437,7 +439,7 @@ def init_single_subject_wf(subject_id, task_id, name,
437439
use_syn=use_syn,
438440
force_syn=force_syn,
439441
debug=debug,
440-
output_grid_ref=output_grid_ref,
442+
template_out_grid=template_out_grid,
441443
use_aroma=use_aroma,
442444
ignore_aroma_err=ignore_aroma_err)
443445

fmriprep/workflows/bold/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
5151
output_spaces, template, output_dir, omp_nthreads,
5252
fmap_bspline, fmap_demean, use_syn, force_syn,
5353
use_aroma, ignore_aroma_err, medial_surface_nan,
54-
debug, low_mem, output_grid_ref, layout=None):
54+
debug, low_mem, template_out_grid, layout=None):
5555
"""
5656
This workflow controls the functional preprocessing stages of FMRIPREP.
5757
@@ -78,7 +78,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
7878
use_syn=True,
7979
force_syn=True,
8080
low_mem=False,
81-
output_grid_ref=None,
81+
template_out_grid='native',
8282
medial_surface_nan=False,
8383
use_aroma=False,
8484
ignore_aroma_err=False)
@@ -136,8 +136,9 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
136136
Enable debugging outputs
137137
low_mem : bool
138138
Write uncompressed .nii files in some cases to reduce memory usage
139-
output_grid_ref : str or None
140-
Path of custom reference image for normalization
139+
template_out_grid : str
140+
Keyword ('native', '1mm' or '2mm') or path of custom reference
141+
image for normalization
141142
layout : BIDSLayout
142143
BIDSLayout structure to enable metadata retrieval
143144
@@ -565,7 +566,7 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
565566
template=template,
566567
mem_gb=mem_gb['resampled'],
567568
omp_nthreads=omp_nthreads,
568-
output_grid_ref=output_grid_ref,
569+
template_out_grid=template_out_grid,
569570
use_compression=not (low_mem and use_aroma),
570571
use_fieldwarp=fmaps is not None,
571572
name='bold_mni_trans_wf'

fmriprep/workflows/bold/resampling.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ def select_target(subject_id, space):
161161

162162
def init_bold_mni_trans_wf(template, mem_gb, omp_nthreads,
163163
name='bold_mni_trans_wf',
164-
output_grid_ref=None, use_compression=True,
164+
template_out_grid='2mm',
165+
use_compression=True,
165166
use_fieldwarp=False):
166167
"""
167168
This workflow samples functional images to the MNI template in a "single shot"
@@ -175,7 +176,7 @@ def init_bold_mni_trans_wf(template, mem_gb, omp_nthreads,
175176
wf = init_bold_mni_trans_wf(template='MNI152NLin2009cAsym',
176177
mem_gb=3,
177178
omp_nthreads=1,
178-
output_grid_ref=None)
179+
template_out_grid='native')
179180
180181
**Parameters**
181182
@@ -187,8 +188,9 @@ def init_bold_mni_trans_wf(template, mem_gb, omp_nthreads,
187188
Maximum number of threads an individual process may use
188189
name : str
189190
Name of workflow (default: ``bold_mni_trans_wf``)
190-
output_grid_ref : str or None
191-
Path of custom reference image for normalization
191+
template_out_grid : str
192+
Keyword ('native', '1mm' or '2mm') or path of custom reference
193+
image for normalization.
192194
use_compression : bool
193195
Save registered BOLD series as ``.nii.gz``
194196
use_fieldwarp : bool
@@ -292,14 +294,19 @@ def _aslist(in_value):
292294
(merge, outputnode, [('out_file', 'bold_mni')]),
293295
])
294296

295-
if output_grid_ref is None:
297+
if template_out_grid == 'native':
296298
workflow.connect([
297299
(gen_ref, mask_mni_tfm, [('out_file', 'reference_image')]),
298300
(gen_ref, bold_to_mni_transform, [('out_file', 'reference_image')]),
299301
])
302+
elif template_out_grid == '1mm' or template_out_grid == '2mm':
303+
mask_mni_tfm.inputs.reference_image = op.join(
304+
nid.get_dataset(template_str), '%s_brainmask.nii.gz' % template_out_grid)
305+
bold_to_mni_transform.inputs.reference_image = op.join(
306+
nid.get_dataset(template_str), '%s_T1.nii.gz' % template_out_grid)
300307
else:
301-
mask_mni_tfm.inputs.reference_image = output_grid_ref
302-
bold_to_mni_transform.inputs.reference_image = output_grid_ref
308+
mask_mni_tfm.inputs.reference_image = template_out_grid
309+
bold_to_mni_transform.inputs.reference_image = template_out_grid
303310
return workflow
304311

305312

fmriprep/workflows/tests/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_single_subject_wf(self, _):
3838
ignore_aroma_err=False,
3939
use_syn=True,
4040
force_syn=True,
41-
output_grid_ref=None)
41+
template_out_grid='native')
4242
wfbasic.write_graph()
4343
self._assert_mandatory_inputs_set(wfbasic)
4444

wrapper/fmriprep_docker.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import re
2323
import subprocess
24+
from warnings import warn
2425

2526
standard_library.install_aliases()
2627

@@ -168,8 +169,8 @@ def merge_help(wrapper_help, target_help):
168169

169170
# Make sure we're not clobbering options we don't mean to
170171
overlap = set(w_flags).intersection(t_flags)
171-
expected_overlap = set(['h', 'version', 'w', 'output-grid-reference',
172-
'fs-license-file'])
172+
expected_overlap = set(['h', 'version', 'w', 'template-resampling-grid',
173+
'output-grid-reference', 'fs-license-file'])
173174
assert overlap == expected_overlap, "Clobbering options: {}".format(
174175
', '.join(overlap - expected_overlap))
175176

@@ -244,10 +245,18 @@ def get_parser():
244245
'Standard options that require mapping files into the container')
245246
g_wrap.add_argument('-w', '--work-dir', action='store',
246247
help='path where intermediate results should be stored')
247-
g_wrap.add_argument('--output-grid-reference', required=False, action='store',
248-
type=os.path.abspath,
249-
help='Grid reference image for resampling BOLD files to volume template '
250-
'space.')
248+
g_wrap.add_argument(
249+
'--output-grid-reference', required=False, action='store', type=os.path.abspath,
250+
help='Deprecated after FMRIPREP 1.0.8. Please use --template-resampling-grid instead.')
251+
g_wrap.add_argument(
252+
'--template-resampling-grid', required=False, action='store', type=str,
253+
help='Keyword ("native", "1mm", or "2mm") or path to an existing file. '
254+
'Allows to define a reference grid for the resampling of BOLD images in template '
255+
'space. Keyword "native" will use the original BOLD grid as reference. '
256+
'Keywords "1mm" and "2mm" will use the corresponding isotropic template '
257+
'resolutions. If a path is given, the grid of that image will be used. '
258+
'It determines the field of view and resolution of the output images, '
259+
'but is not used in normalization.')
251260
g_wrap.add_argument(
252261
'--fs-license-file', metavar='PATH', type=os.path.abspath,
253262
default=os.getenv('FS_LICENSE', None),
@@ -370,10 +379,16 @@ def main():
370379
command.extend(['-v', ':'.join((opts.config,
371380
'/root/.nipype/nipype.cfg', 'ro'))])
372381

373-
if opts.output_grid_reference:
374-
target = '/imports/' + os.path.basename(opts.output_grid_reference)
375-
command.extend(['-v', ':'.join((opts.output_grid_reference, target, 'ro'))])
376-
unknown_args.extend(['--output-grid-reference', target])
382+
template_target = opts.template_resampling_grid or opts.output_grid_reference
383+
if template_target is not None:
384+
if opts.output_grid_reference is not None:
385+
warn('Option --output-grid-reference is deprecated, please use '
386+
'--template-resampling-grid', DeprecationWarning)
387+
if template_target not in ['native', '2mm' '1mm']:
388+
target = '/imports/' + os.path.basename(template_target)
389+
command.extend(['-v', ':'.join((os.path.abspath(
390+
template_target), target, 'ro'))])
391+
unknown_args.extend(['--template-resampling-grid', template_target])
377392

378393
if opts.shell:
379394
command.append('--entrypoint=bash')

0 commit comments

Comments
 (0)