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 10 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
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="LEVEL:TYPE:FWHM",
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 dataset:iso:5` 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
7 changes: 6 additions & 1 deletion fitlins/interfaces/nistats.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class SecondLevelModelInputSpec(BaseInterfaceInputSpec):
variance_maps = traits.List(traits.List(File(exists=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 Down Expand Up @@ -171,7 +172,11 @@ class SecondLevelModel(NistatsBaseInterface, SimpleInterface):

def _run_interface(self, runtime):
from nistats import second_level_model as level2
model = level2.SecondLevelModel()
smoothing_fwhm = self.inputs.smoothing_fwhm
if not isdefined(smoothing_fwhm):
smoothing_fwhm = None
model = level2.SecondLevelModel(smoothing_fwhm=smoothing_fwhm)

effect_maps = []
variance_maps = []
stat_maps = []
Expand Down
14 changes: 8 additions & 6 deletions fitlins/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, analysis_level, space,
name='getter')

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

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 +158,9 @@ def init_fitlins_wf(bids_dir, derivatives, out_dir, analysis_level, space,

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

if smoothing and smoothing_level == step:
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