-
Notifications
You must be signed in to change notification settings - Fork 28
rf: Allow callers to pass a pre-computed epi2anat transform for SyN #485
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
Draft
effigies
wants to merge
6
commits into
main
Choose a base branch
from
syn-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6627730
rf: Deprecate unused t1w_inversion argument
effigies b513e98
rf: Allow callers to pass a pre-computed epi2anat transform for SyN
effigies e9de921
sty: flake8
effigies 560ac91
docker: Remove unused c3d_affine_tool
effigies 9b369f9
docker: Add dev stage that does not require building a wheel
effigies 6d0b2e2
Merge branch 'master' into syn-refactor
effigies 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 hidden or 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 hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -342,8 +342,9 @@ | |||||
debug=False, | ||||||
name="syn_preprocessing_wf", | ||||||
omp_nthreads=1, | ||||||
coregister=True, | ||||||
auto_bold_nss=False, | ||||||
t1w_inversion=False, | ||||||
t1w_inversion=None, | ||||||
sd_prior=True, | ||||||
): | ||||||
""" | ||||||
|
@@ -365,11 +366,15 @@ | |||||
Name for this workflow | ||||||
omp_nthreads : :obj:`int` | ||||||
Parallelize internal tasks across the number of CPUs given by this option. | ||||||
coregister: :class:`bool` | ||||||
Run BOLD-to-Anat coregistration. If set to ``False``, ``epi2anat_xfm`` must be | ||||||
provided. | ||||||
auto_bold_nss : :obj:`bool` | ||||||
Set up the reference workflow to automatically execute nonsteady states detection | ||||||
of BOLD images. | ||||||
t1w_inversion : :obj:`bool` | ||||||
Run T1w intensity inversion so that it looks more like a T2 contrast. | ||||||
(DEPRECATED. Does nothing.) | ||||||
sd_prior : :obj:`bool` | ||||||
Enable using a prior map to regularize the SyN cost function. | ||||||
|
||||||
|
@@ -418,6 +423,13 @@ | |||||
from ...interfaces.utils import Deoblique, DenoiseImage | ||||||
from ...interfaces.brainmask import BrainExtraction, BinaryDilation | ||||||
|
||||||
if t1w_inversion is not None: | ||||||
import warnings | ||||||
warnings.warn( | ||||||
"The `t1w_inversion` argument is deprecated and does nothing.", | ||||||
DeprecationWarning, | ||||||
) | ||||||
|
||||||
workflow = Workflow(name=name) | ||||||
|
||||||
inputnode = pe.Node( | ||||||
|
@@ -429,6 +441,7 @@ | |||||
"in_anat", | ||||||
"mask_anat", | ||||||
"std2anat_xfm", | ||||||
"epi2anat_xfm", | ||||||
] | ||||||
), | ||||||
name="inputnode", | ||||||
|
@@ -476,28 +489,44 @@ | |||||
DenoiseImage(copy_header=True), name="ref_anat", n_procs=omp_nthreads | ||||||
) | ||||||
|
||||||
epi2anat = pe.Node( | ||||||
Registration(from_file=data.load("affine.json")), | ||||||
name="epi2anat", | ||||||
n_procs=omp_nthreads, | ||||||
) | ||||||
epi2anat.inputs.output_warped_image = debug | ||||||
epi2anat.inputs.output_inverse_warped_image = debug | ||||||
if debug: | ||||||
epi2anat.inputs.args = "--write-interval-volumes 5" | ||||||
|
||||||
def _remove_first_mask(in_file): | ||||||
if not isinstance(in_file, list): | ||||||
in_file = [in_file] | ||||||
|
||||||
in_file.insert(0, "NULL") | ||||||
return in_file | ||||||
|
||||||
anat_dilmsk = pe.Node(BinaryDilation(), name="anat_dilmsk") | ||||||
epi_dilmsk = pe.Node(BinaryDilation(), name="epi_dilmsk") | ||||||
|
||||||
sampling_ref = pe.Node(GenerateSamplingReference(), name="sampling_ref") | ||||||
|
||||||
if coregister: | ||||||
epi2anat = pe.Node( | ||||||
Registration(from_file=data.load("affine.json")), | ||||||
name="epi2anat", | ||||||
n_procs=omp_nthreads, | ||||||
) | ||||||
epi2anat.inputs.output_warped_image = debug | ||||||
epi2anat.inputs.output_inverse_warped_image = debug | ||||||
if debug: | ||||||
epi2anat.inputs.args = "--write-interval-volumes 5" | ||||||
|
||||||
def _remove_first_mask(in_file): | ||||||
if not isinstance(in_file, list): | ||||||
in_file = [in_file] | ||||||
|
||||||
in_file.insert(0, "NULL") | ||||||
return in_file | ||||||
|
||||||
workflow.connect([ | ||||||
(ref_anat, epi2anat, [("output_image", "fixed_image")]), | ||||||
(anat_dilmsk, epi2anat, [("out_file", "fixed_image_masks")]), | ||||||
(deob_epi, epi2anat, [("out_file", "moving_image")]), | ||||||
(epi_dilmsk, epi2anat, [ | ||||||
(("out_file", _remove_first_mask), "moving_image_masks")]), | ||||||
(epi2anat, anat2epi, [("forward_transforms", "transforms")]), | ||||||
(epi2anat, mask2epi, [("forward_transforms", "transforms")]), | ||||||
]) # fmt:skip | ||||||
else: | ||||||
workflow.connect([ | ||||||
(inputnode, anat2epi, [("epi2anat_xfm", "transforms")]), | ||||||
(inputnode, mask2epi, [("epi2anat_xfm", "transforms")]), | ||||||
]) | ||||||
|
||||||
if sd_prior: | ||||||
# Mapping & preparing prior knowledge | ||||||
# Concatenate transform files: | ||||||
|
@@ -523,12 +552,20 @@ | |||||
|
||||||
workflow.connect([ | ||||||
(inputnode, transform_list, [("std2anat_xfm", "in2")]), | ||||||
(epi2anat, transform_list, [("forward_transforms", "in1")]), | ||||||
(transform_list, prior2epi, [("out", "transforms")]), | ||||||
(sampling_ref, prior2epi, [("out_file", "reference_image")]), | ||||||
(prior2epi, outputnode, [("output_image", "sd_prior")]), | ||||||
]) # fmt:skip | ||||||
|
||||||
if coregister: | ||||||
workflow.connect([ | ||||||
(epi2anat, transform_list, [("forward_transforms", "in1")]), | ||||||
]) # fmt:skip | ||||||
else: | ||||||
workflow.connect([ | ||||||
(inputnode, transform_list, [("epi2anat_xfm", "in1")]), | ||||||
]) | ||||||
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.
Suggested change
|
||||||
|
||||||
else: | ||||||
# no prior to be used | ||||||
# MG: Future goal is to allow using alternative mappings | ||||||
|
@@ -548,16 +585,9 @@ | |||||
(clip_anat, ref_anat, [("out_file", "input_image")]), | ||||||
(deob_epi, epi_brain, [("out_file", "in_file")]), | ||||||
(epi_brain, epi_dilmsk, [("out_mask", "in_file")]), | ||||||
(ref_anat, epi2anat, [("output_image", "fixed_image")]), | ||||||
(anat_dilmsk, epi2anat, [("out_file", "fixed_image_masks")]), | ||||||
(deob_epi, epi2anat, [("out_file", "moving_image")]), | ||||||
(epi_dilmsk, epi2anat, [ | ||||||
(("out_file", _remove_first_mask), "moving_image_masks")]), | ||||||
(deob_epi, sampling_ref, [("out_file", "fixed_image")]), | ||||||
(ref_anat, anat2epi, [("output_image", "input_image")]), | ||||||
(epi2anat, anat2epi, [("forward_transforms", "transforms")]), | ||||||
(sampling_ref, anat2epi, [("out_file", "reference_image")]), | ||||||
(epi2anat, mask2epi, [("forward_transforms", "transforms")]), | ||||||
(sampling_ref, mask2epi, [("out_file", "reference_image")]), | ||||||
(mask2epi, mask_dtype, [("output_image", "in_file")]), | ||||||
(anat2epi, outputnode, [("output_image", "anat_ref")]), | ||||||
|
This file contains hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,8 @@ | |||||
# | ||||||
"""Test fieldmap-less SDC-SyN.""" | ||||||
import json | ||||||
|
||||||
import acres | ||||||
import pytest | ||||||
from nipype.pipeline import engine as pe | ||||||
|
||||||
|
@@ -30,8 +32,15 @@ | |||||
|
||||||
@pytest.mark.veryslow | ||||||
@pytest.mark.slow | ||||||
@pytest.mark.parametrize("sd_prior", [True, False]) | ||||||
def test_syn_wf(tmpdir, datadir, workdir, outdir, sloppy_mode, sd_prior): | ||||||
@pytest.mark.parametrize( | ||||||
("n_bold", "coregister", "sd_prior"), | ||||||
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.
Suggested change
|
||||||
[ | ||||||
(1, True, True), | ||||||
# Switch to False once we have a transform in tests/data | ||||||
(2, True, False), | ||||||
] | ||||||
) | ||||||
def test_syn_wf(tmpdir, datadir, workdir, outdir, sloppy_mode, n_bold, coregister, sd_prior): | ||||||
"""Build and run an SDC-SyN workflow.""" | ||||||
derivs_path = datadir / "ds000054" / "derivatives" | ||||||
smriprep = derivs_path / "smriprep-0.6" / "sub-100185" / "anat" | ||||||
|
@@ -42,8 +51,8 @@ def test_syn_wf(tmpdir, datadir, workdir, outdir, sloppy_mode, sd_prior): | |||||
omp_nthreads=4, | ||||||
debug=sloppy_mode, | ||||||
auto_bold_nss=True, | ||||||
t1w_inversion=True, | ||||||
sd_prior=sd_prior, | ||||||
coregister=coregister, | ||||||
) | ||||||
prep_wf.inputs.inputnode.in_epis = [ | ||||||
str( | ||||||
|
@@ -60,10 +69,10 @@ def test_syn_wf(tmpdir, datadir, workdir, outdir, sloppy_mode, sd_prior): | |||||
/ "func" | ||||||
/ "sub-100185_task-machinegame_run-02_bold.nii.gz" | ||||||
), | ||||||
] | ||||||
][:n_bold] | ||||||
prep_wf.inputs.inputnode.in_meta = [ | ||||||
json.loads((datadir / "ds000054" / "task-machinegame_bold.json").read_text()), | ||||||
] * 2 | ||||||
] * n_bold | ||||||
prep_wf.inputs.inputnode.std2anat_xfm = str( | ||||||
smriprep / "sub-100185_from-MNI152NLin2009cAsym_to-T1w_mode-image_xfm.h5" | ||||||
) | ||||||
|
@@ -73,6 +82,11 @@ def test_syn_wf(tmpdir, datadir, workdir, outdir, sloppy_mode, sd_prior): | |||||
prep_wf.inputs.inputnode.mask_anat = str( | ||||||
smriprep / "sub-100185_desc-brain_mask.nii.gz" | ||||||
) | ||||||
if not coregister: | ||||||
test_data = acres.Loader('sdcflows.tests') | ||||||
prep_wf.inputs.inputnode.epi_ref = str( | ||||||
test_data('data/anat2epi_xfm.txt') | ||||||
) | ||||||
|
||||||
syn_wf = init_syn_sdc_wf( | ||||||
debug=sloppy_mode, | ||||||
|
Oops, something went wrong.
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.
Do you want to push these updates independently of the rest of the PR?