Skip to content

Commit 11ea1c2

Browse files
committed
[skip ds210][skip ds054][skip tests] switch n_volumes* to skip_vols and use nonsteady calculation from bold_reference_wf (review by effigies)
1 parent b9e5ff4 commit 11ea1c2

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

fmriprep/interfaces/confounds.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _run_interface(self, runtime):
9494

9595
class ICAConfoundsInputSpec(BaseInterfaceInputSpec):
9696
in_directory = Directory(mandatory=True, desc='directory where ICA derivatives are found')
97-
n_volumes = traits.Int(desc='number of non steady state volumes identified')
97+
skip_vols = traits.Int(desc='number of non steady state volumes identified')
9898
ignore_aroma_err = traits.Bool(False, usedefault=True, desc='ignore ICA-AROMA errors')
9999

100100

@@ -112,7 +112,7 @@ class ICAConfounds(SimpleInterface):
112112

113113
def _run_interface(self, runtime):
114114
aroma_confounds, motion_ics_out, melodic_mix_out = _get_ica_confounds(
115-
self.inputs.in_directory, self.inputs.n_volumes, newpath=runtime.cwd)
115+
self.inputs.in_directory, self.inputs.skip_vols, newpath=runtime.cwd)
116116

117117
if aroma_confounds is not None:
118118
self._results['aroma_confounds'] = aroma_confounds
@@ -199,7 +199,7 @@ def _adjust_indices(left_df, right_df):
199199
return combined_out, confounds_list
200200

201201

202-
def _get_ica_confounds(ica_out_dir, n_volumes, newpath=None):
202+
def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):
203203
if newpath is None:
204204
newpath = os.getcwd()
205205

@@ -219,8 +219,8 @@ def _get_ica_confounds(ica_out_dir, n_volumes, newpath=None):
219219
melodic_mix_arr = np.loadtxt(melodic_mix, ndmin=2)
220220

221221
# pad melodic_mix_arr with rows of zeros corresponding to number non steadystate volumes
222-
if n_volumes > 0:
223-
zeros = np.zeros([n_volumes, melodic_mix_arr.shape[1]])
222+
if skip_vols > 0:
223+
zeros = np.zeros([skip_vols, melodic_mix_arr.shape[1]])
224224
melodic_mix_arr = np.vstack([zeros, melodic_mix_arr])
225225

226226
# save melodic_mix_arr

fmriprep/workflows/bold/base.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from nipype.interfaces.fsl import Split as FSLSplit
1919
from nipype.pipeline import engine as pe
2020
from nipype.interfaces import utility as niu
21-
from nipype.algorithms import confounds as nac
2221

2322
from ...interfaces import (
2423
DerivativesDataSink,
@@ -425,9 +424,6 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
425424
omp_nthreads=omp_nthreads,
426425
use_compression=False)
427426

428-
# get non steady-state volumes
429-
non_steady_state = pe.Node(nac.NonSteadyStateDetector(), name='non_steady_state')
430-
431427
# get confounds
432428
bold_confounds_wf = init_bold_confs_wf(
433429
mem_gb=mem_gb['largemem'],
@@ -529,18 +525,15 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
529525
('outputnode.out_warp', 'inputnode.fieldwarp'),
530526
('outputnode.bold_mask', 'inputnode.bold_mask')]),
531527
(bold_sdc_wf, summary, [('outputnode.method', 'distortion_correction')]),
532-
# Calculate nonsteady state
533-
(bold_bold_trans_wf, non_steady_state, [
534-
('outputnode.bold', 'in_file')]),
535528
# Connect bold_confounds_wf
536529
(inputnode, bold_confounds_wf, [('t1_tpms', 'inputnode.t1_tpms'),
537530
('t1_mask', 'inputnode.t1_mask')]),
538531
(bold_hmc_wf, bold_confounds_wf, [
539532
('outputnode.movpar_file', 'inputnode.movpar_file')]),
540533
(bold_reg_wf, bold_confounds_wf, [
541534
('outputnode.itk_t1_to_bold', 'inputnode.t1_bold_xform')]),
542-
(non_steady_state, bold_confounds_wf, [
543-
('n_volumes_to_discard', 'inputnode.n_volumes_to_discard')]),
535+
(bold_reference_wf, bold_confounds_wf, [
536+
('outputnode.skip_vols', 'inputnode.skip_vols')]),
544537
(bold_confounds_wf, outputnode, [
545538
('outputnode.confounds_file', 'confounds'),
546539
]),
@@ -739,8 +732,8 @@ def init_func_preproc_wf(bold_file, ignore, freesurfer,
739732
('outputnode.bold_mask', 'inputnode.bold_mask')]),
740733
(bold_sdc_wf, ica_aroma_wf, [
741734
('outputnode.out_warp', 'inputnode.fieldwarp')]),
742-
(non_steady_state, ica_aroma_wf, [
743-
('n_volumes_to_discard', 'inputnode.n_volumes_to_discard')]),
735+
(bold_reference_wf, ica_aroma_wf, [
736+
('outputnode.skip_vols', 'inputnode.skip_vols')]),
744737
(bold_confounds_wf, join, [
745738
('outputnode.confounds_file', 'in_file')]),
746739
(ica_aroma_wf, join,

fmriprep/workflows/bold/confounds.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
9292
BOLD series mask
9393
movpar_file
9494
SPM-formatted motion parameters file
95-
n_volumes_to_discard
95+
skip_vols
9696
number of non steady state volumes
9797
t1_mask
9898
Mask of the skull-stripped template image
@@ -138,7 +138,7 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
138138
placed within the corresponding confounds file.
139139
"""
140140
inputnode = pe.Node(niu.IdentityInterface(
141-
fields=['bold', 'bold_mask', 'movpar_file', 'n_volumes_to_discard',
141+
fields=['bold', 'bold_mask', 'movpar_file', 'skip_vols',
142142
't1_mask', 't1_tpms', 't1_bold_xform']),
143143
name='inputnode')
144144
outputnode = pe.Node(niu.IdentityInterface(
@@ -253,13 +253,13 @@ def _pick_wm(files):
253253

254254
# tCompCor
255255
(inputnode, tcompcor, [('bold', 'realigned_file')]),
256-
(inputnode, tcompcor, [('n_volumes_to_discard', 'ignore_initial_volumes')]),
256+
(inputnode, tcompcor, [('skip_vols', 'ignore_initial_volumes')]),
257257
(tcc_tfm, tcc_msk, [('output_image', 'roi_file')]),
258258
(tcc_msk, tcompcor, [('out', 'mask_files')]),
259259

260260
# aCompCor
261261
(inputnode, acompcor, [('bold', 'realigned_file')]),
262-
(inputnode, acompcor, [('n_volumes_to_discard', 'ignore_initial_volumes')]),
262+
(inputnode, acompcor, [('skip_vols', 'ignore_initial_volumes')]),
263263
(acc_tfm, acc_msk, [('output_image', 'roi_file')]),
264264
(acc_msk, acompcor, [('out', 'mask_files')]),
265265

@@ -466,7 +466,7 @@ def init_ica_aroma_wf(template, metadata, mem_gb, omp_nthreads,
466466
Affine transform from ``ref_bold_brain`` to T1 space (ITK format)
467467
movpar_file
468468
SPM-formatted motion parameters file
469-
n_volumes_to_discard
469+
skip_vols
470470
number of non steady state volumes
471471
name_source
472472
BOLD series NIfTI file
@@ -506,7 +506,7 @@ def init_ica_aroma_wf(template, metadata, mem_gb, omp_nthreads,
506506
'itk_bold_to_t1',
507507
't1_2_mni_forward_transform',
508508
'name_source',
509-
'n_volumes_to_discard',
509+
'skip_vols',
510510
'bold_split',
511511
'bold_mask',
512512
'hmc_xforms',
@@ -584,7 +584,7 @@ def _getbtthresh(medianval):
584584
('fieldwarp', 'inputnode.fieldwarp')]),
585585
(inputnode, ica_aroma, [('movpar_file', 'motion_parameters')]),
586586
(inputnode, rm_non_steady_state, [
587-
('n_volumes_to_discard', 'n_volumes')]),
587+
('skip_vols', 'skip_vols')]),
588588
(bold_mni_trans_wf, rm_non_steady_state, [
589589
('outputnode.bold_mni', 'bold_file')]),
590590
(bold_mni_trans_wf, calc_median_val, [
@@ -613,7 +613,7 @@ def _getbtthresh(medianval):
613613
# generate tsvs from ICA-AROMA
614614
(ica_aroma, ica_aroma_confound_extraction, [('out_dir', 'in_directory')]),
615615
(inputnode, ica_aroma_confound_extraction, [
616-
('n_volumes_to_discard', 'n_volumes')]),
616+
('skip_vols', 'skip_vols')]),
617617
# output for processing and reporting
618618
(ica_aroma_confound_extraction, outputnode, [('aroma_confounds', 'aroma_confounds'),
619619
('aroma_noise_ics', 'aroma_noise_ics'),
@@ -624,15 +624,15 @@ def _getbtthresh(medianval):
624624
(bold_mni_trans_wf, add_non_steady_state, [
625625
('outputnode.bold_mni', 'bold_file')]),
626626
(inputnode, add_non_steady_state, [
627-
('n_volumes_to_discard', 'n_volumes')]),
627+
('skip_vols', 'skip_vols')]),
628628
(add_non_steady_state, outputnode, [('bold_add', 'nonaggr_denoised_file')]),
629629
(ica_aroma, ds_report_ica_aroma, [('out_report', 'in_file')]),
630630
])
631631

632632
return workflow
633633

634634

635-
def _remove_volumes(bold_file, n_volumes):
635+
def _remove_volumes(bold_file, skip_vols):
636636
import nibabel as nb
637637
from nipype.utils.filemanip import fname_presuffix
638638

@@ -641,11 +641,11 @@ def _remove_volumes(bold_file, n_volumes):
641641
bold_data = bold_img.get_data()
642642

643643
# cut off the beginning volumes
644-
bold_data_cut = bold_data[..., n_volumes:]
644+
bold_data_cut = bold_data[..., skip_vols:]
645645

646646
# modify header with new shape (fewer volumes)
647647
data_shape = list(bold_img.header.get_data_shape())
648-
data_shape[-1] -= n_volumes
648+
data_shape[-1] -= skip_vols
649649
bold_img.header.set_data_shape(tuple(data_shape))
650650

651651
# save the resulting bold file
@@ -654,8 +654,8 @@ def _remove_volumes(bold_file, n_volumes):
654654
return out
655655

656656

657-
def _add_volumes(bold_file, bold_cut_file, n_volumes):
658-
"""prepend n_volumes from bold_file onto bold_cut_file"""
657+
def _add_volumes(bold_file, bold_cut_file, skip_vols):
658+
"""prepend skip_vols from bold_file onto bold_cut_file"""
659659
import nibabel as nb
660660
from nipype.utils.filemanip import fname_presuffix
661661

@@ -665,8 +665,8 @@ def _add_volumes(bold_file, bold_cut_file, n_volumes):
665665
bold_cut_img = nb.load(bold_cut_file)
666666
bold_cut_data = bold_cut_img.get_data()
667667

668-
# assign everything from n_volumes foward to bold_cut_data
669-
bold_data[..., n_volumes:] = bold_cut_data
668+
# assign everything from skip_vols foward to bold_cut_data
669+
bold_data[..., skip_vols:] = bold_cut_data
670670

671671
out = fname_presuffix(bold_cut_file, suffix='_addnonsteady')
672672
bold_img.__class__(bold_data, bold_img.affine, bold_img.header).to_filename(out)

0 commit comments

Comments
 (0)