-
Notifications
You must be signed in to change notification settings - Fork 32
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
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2bacc6d
Add smoothing level to CLI, and pass down
adelavega e808838
Pass smoothing kernel to nistats
adelavega 305c6d6
Fix typo
adelavega 78e2f39
Don't use pep 517
adelavega 587261d
Merge branch 'enh/smoothing' of github.com:adelavega/fitlins into enh…
adelavega 257c08e
Check number of steps for -1 smoothing level
adelavega e5cca09
Merge branch 'master' into enh/smoothing
adelavega 5551cef
Check out Dockerfile from master
adelavega dc5c4c5
Use step level string instead of integer
adelavega c606ad7
Merge master
adelavega 7762d90
Update fitlins/cli/run.py
effigies db5c6b8
Update fitlins/workflows/base.py
effigies e1264f0
Parse new smoothing options, wit backwards compatability
adelavega 6be8b4f
Check if smoothing_level equals step number
adelavega 03aac9e
Merge branch 'master' into enh/smoothing
adelavega e6ab269
Stylistic improvements to smoothing logic
adelavega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from pathlib import Path | ||
import warnings | ||
from nipype.pipeline import engine as pe | ||
from nipype.interfaces import utility as niu | ||
# from nipype.interfaces import fsl | ||
|
@@ -59,17 +60,37 @@ 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
|
||
smoothing_fwhm = float(smoothing_params[0]) | ||
if smoothing_fwhm == 'iso': | ||
warnings.warn( | ||
"The order of arguments for smoothing will" | ||
"change in the next release.", FutureWarning) | ||
smoothing_level = 'l1' | ||
smoothing_fwhm = smoothing_params[1] | ||
else: | ||
if len(smoothing_params) > 1: | ||
smoothing_level = smoothing_params[1] | ||
else: | ||
smoothing_level = 'l1' | ||
|
||
if len(smoothing_params) > 2: | ||
if smoothing_params[2] != 'iso': | ||
raise ValueError( | ||
f"Unknown smoothing type {smoothing_params[1]}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again have a bunch of little comments, so here's a replacement for L63-L80: smoothing_params = smoothing.split(':', 2)
# Convert old style and warn; this should turn into an (informative) error around 0.5.0
if smoothing_params[0] == 'iso':
smoothing_params = (smoothing_params[1], 'l1', smoothing_params[0])
warnings.warn(
"The format for smoothing arguments has changed. Please use "
f"{':'.join(smoothing_params)} instead of {smoothing}.", FutureWarning)
# Add defaults to simplify later logic
if len(smoothing_params) == 1:
smoothing_params.extend(('l1', 'iso'))
elif len(smoothing_params) == 2:
smoothing_params.append('iso')
smoothing_fwhm, smoothing_level, smoothing_type = smoothing_params
smoothing_fwhm = float(smoothing_fwhm)
if smoothing_type not in ('iso'):
raise ValueError(f"Unknown smoothing type {smoothing_type}") |
||
|
||
# Check that smmoothing level exists in model | ||
if (smoothing_level.startswith("l") and | ||
int(smoothing_level.strip("l")) > len(model_dict)): | ||
raise ValueError("Invalid smoothing level {smoothing_level}") | ||
elif (smoothing_level not in | ||
[step['Level'] for step in model_dict['Steps']]): | ||
raise ValueError(f"Invalid smoothing level {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}/]' \ | ||
|
@@ -161,6 +182,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 or smoothing_level == level): | ||
effigies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple minor comments, in particular the default should be
l1
and the metavar should use square brackets to indicate optional components. I also think we skip around a little bit and want to restructure the help text, so here's the whole thing rewritten:Feel free to edit for clarity.