Skip to content

Commit

Permalink
Use GenericLabel and set nprocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 4, 2024
1 parent c58d678 commit 9fed90c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
54 changes: 54 additions & 0 deletions src/fmripost_rapidtide/interfaces/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Miscellaneous interfaces for fmriprep-rapidtide."""

from nipype.interfaces.base import (
isdefined,
traits,
)
from nipype.utils.filemanip import fname_presuffix
from niworkflows.interfaces.fixes import (
FixHeaderApplyTransforms,
_FixTraitApplyTransformsInputSpec,
)


class _ApplyTransformsInputSpec(_FixTraitApplyTransformsInputSpec):
# Nipype's version doesn't have GenericLabel
interpolation = traits.Enum(
'Linear',
'NearestNeighbor',
'CosineWindowedSinc',
'WelchWindowedSinc',
'HammingWindowedSinc',
'LanczosWindowedSinc',
'MultiLabel',
'Gaussian',
'BSpline',
'GenericLabel',
argstr='%s',
usedefault=True,
)


class ApplyTransforms(FixHeaderApplyTransforms):
"""A modified version of FixHeaderApplyTransforms from niworkflows.
The niworkflows version of ApplyTransforms "fixes the resampled image header
to match the xform of the reference image".
This modification overrides the allowed interpolation values,
since FixHeaderApplyTransforms doesn't support GenericLabel,
which is preferred over MultiLabel.
"""

input_spec = _ApplyTransformsInputSpec

def _run_interface(self, runtime):
if not isdefined(self.inputs.output_image):
self.inputs.output_image = fname_presuffix(
self.inputs.input_image,
suffix='_trans.nii.gz',
newpath=runtime.cwd,
use_ext=False,
)

runtime = super(ApplyTransforms, self)._run_interface(runtime)
return runtime
6 changes: 6 additions & 0 deletions src/fmripost_rapidtide/interfaces/rapidtide.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ class _RapidtideInputSpec(CommandLineInputSpec):
argstr='--autorespdelete',
mandatory=False,
)
nprocs = traits.Int(
default=1,
usedefault=True,
argstr='--nprocs %d',
mandatory=False,
)


class _RapidtideOutputSpec(TraitedSpec):
Expand Down
3 changes: 2 additions & 1 deletion src/fmripost_rapidtide/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,11 @@ def init_single_run_wf(bold_file):
# Resample to MNI152NLin6Asym:res-2, for rapidtide denoising
from fmriprep.workflows.bold.apply import init_bold_volumetric_resample_wf
from fmriprep.workflows.bold.stc import init_bold_stc_wf
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.interfaces.header import ValidateImage
from templateflow.api import get as get_template

from fmripost_rapidtide.interfaces.misc import ApplyTransforms

workflow.__desc__ += """\
Raw BOLD series were resampled to MNI152NLin6Asym:res-2, for rapidtide denoising.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/fmripost_rapidtide/workflows/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def init_carpetplot_wf(
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from templateflow.api import get as get_template

from fmripost_rapidtide.config import DEFAULT_MEMORY_MIN_GB
from fmripost_rapidtide.interfaces import DerivativesDataSink
from fmripost_rapidtide.interfaces.confounds import FMRISummary
from fmripost_rapidtide.interfaces.misc import ApplyTransforms

inputnode = pe.Node(
niu.IdentityInterface(
Expand Down
2 changes: 1 addition & 1 deletion src/fmripost_rapidtide/workflows/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
from fmriprep.utils.bids import dismiss_echo
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.utils.images import dseg_label

from fmripost_rapidtide.config import DEFAULT_MEMORY_MIN_GB
from fmripost_rapidtide.interfaces.bids import DerivativesDataSink
from fmripost_rapidtide.interfaces.misc import ApplyTransforms


def init_func_fit_reports_wf(
Expand Down
3 changes: 2 additions & 1 deletion src/fmripost_rapidtide/workflows/rapidtide.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def init_rapidtide_wf(
rapidtide = pe.Node(
Rapidtide(
outputname='rapidtide',
denoising=True,
datatstep=metadata['RepetitionTime'],
autosync=config.workflow.autosync,
filterband=config.workflow.filterband,
Expand Down Expand Up @@ -169,9 +168,11 @@ def init_rapidtide_wf(
outputlevel=config.workflow.outputlevel,
territorymap=config.workflow.territorymap or Undefined,
autorespdelete=config.workflow.autorespdelete,
nprocs=config.nipype.omp_nthreads,
),
name='rapidtide',
mem_gb=mem_gb['largemem'],
n_procs=config.nipype.omp_nthreads,
)
workflow.connect([
(inputnode, rapidtide, [
Expand Down

0 comments on commit 9fed90c

Please sign in to comment.