Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Enable smoothing at any analysis level #135

Merged
merged 16 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by Neurodocker version 0.4.3-6-g12a2b6f
# Timestamp: 2019-02-28 22:10:25 UTC
#
#
# Thank you for using Neurodocker. If you discover any issues
# or ways to improve this software, please submit an issue or
# pull request on our GitHub repository:
#
#
effigies marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/kaczmarj/neurodocker

FROM neurodebian@sha256:5fbbad8c68525b588a459092254094436aae9dc1f3920f8d871a03053b10377c
Expand Down Expand Up @@ -100,7 +100,7 @@ RUN bash -c "source activate neuro \
&& sync

RUN bash -c "source activate neuro \
&& pip install --no-cache-dir -e \
&& pip install --no-use-pep517 --no-cache-dir -e \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fixing this in #136.

'/src/fitlins[all]'" \
&& rm -rf ~/.cache/pip/* \
&& sync \
Expand Down
5 changes: 3 additions & 2 deletions fitlins/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ def get_parser():
help="use BOLD files with the provided description label")

g_prep = parser.add_argument_group('Options for preprocessing BOLD series')
g_prep.add_argument('-s', '--smoothing', action='store', metavar="TYPE:FWHM",
g_prep.add_argument('-s', '--smoothing', action='store', metavar="TYPE:FWHM:LEVEL",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the levels to be named, e.g. run, session, etc. So instead of -s iso:5:1, it would be -s run:iso:5.

It doesn't seem likely that we'll want to smooth multiple times, does it?

help="Smooth BOLD series with FWHM mm kernel prior to fitting. "
"Valid types: iso (isotropic); "
"e.g. `--smothing iso:5` will use an isotropic 5mm FWHM kernel")
"e.g. `--smoothing iso:5:1` will use an isotropic 5mm"
"FWHM at the first level.")
adelavega marked this conversation as resolved.
Show resolved Hide resolved

g_perfm = parser.add_argument_group('Options to handle performance')
g_perfm.add_argument('--n-cpus', action='store', default=0, type=int,
Expand Down
8 changes: 6 additions & 2 deletions fitlins/interfaces/nistats.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class FirstLevelModelInputSpec(BaseInterfaceInputSpec):
smoothing_fwhm = traits.Float(desc='Full-width half max (FWHM) in mm for smoothing in mask')



class FirstLevelModelOutputSpec(TraitedSpec):
contrast_maps = traits.List(File)
contrast_metadata = traits.List(traits.Dict)
Expand Down Expand Up @@ -127,6 +126,7 @@ class SecondLevelModelInputSpec(BaseInterfaceInputSpec):
stat_files = traits.List(traits.List(File(exists=True)), mandatory=True)
stat_metadata = traits.List(traits.List(traits.Dict), mandatory=True)
contrast_info = traits.List(traits.Dict, mandatory=True)
smoothing_fwhm = traits.Float(desc='Full-width half max (FWHM) in mm for smoothing in mask')


class SecondLevelModelOutputSpec(TraitedSpec):
Expand All @@ -151,7 +151,11 @@ class SecondLevelModel(NistatsBaseInterface, SimpleInterface):
output_spec = SecondLevelModelOutputSpec

def _run_interface(self, runtime):
model = level2.SecondLevelModel()
smoothing_fwhm = self.inputs.smoothing_fwhm
if not isdefined(smoothing_fwhm):
smoothing_fwhm = None

model = level2.SecondLevelModel(smoothing_fwhm=smoothing_fwhm)
contrast_maps = []
contrast_metadata = []

Expand Down
10 changes: 7 additions & 3 deletions fitlins/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, analysis_level, space,
name='getter')

if smoothing:
smoothing_params = smoothing.split(':', 1)
smoothing_params = smoothing.split(':', 2)
effigies marked this conversation as resolved.
Show resolved Hide resolved
if smoothing_params[0] != 'iso':
raise ValueError(f"Unknown smoothing type {smoothing_params[0]}")
smoothing_fwhm = float(smoothing_params[1])
smoothing_level = int(smoothing_params[1])
if smoothing_level < 0:
smoothing_level = len(model_dict['Steps']) - smoothing_level

l1_model = pe.MapNode(
FirstLevelModel(),
iterfield=['session_info', 'contrast_info', 'bold_file', 'mask_file'],
name='l1_model')
if smoothing:
l1_model.inputs.smoothing_fwhm = smoothing_fwhm

# Set up common patterns
image_pattern = 'reports/[sub-{subject}/][ses-{session}/]figures/[run-{run}/]' \
Expand Down Expand Up @@ -159,6 +160,9 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, analysis_level, space,

level = 'l{:d}'.format(ix + 1)

if smoothing and smoothing_level == ix:
model.inputs.smoothing_fwhm = smoothing_fwhm

# TODO: No longer used at higher level, suggesting we can simply return
# entities from loader as a single list
select_entities = pe.Node(
Expand Down