-
Notifications
You must be signed in to change notification settings - Fork 535
[ENH] Add interfaces wrapping DIPY worflows #2830
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
617a2a9
add DIPY to index
skoudoro 6e4af1f
dipy workflow to nipype
skoudoro cc45dd3
remove pdb
skoudoro de91a1b
setup default values
skoudoro 757a6f4
add some tests
skoudoro 9b1e928
from random dict to static test
skoudoro 63c1d7c
add skipif
skoudoro 1b4625f
Update nipype/interfaces/dipy/reconstruction.py
effigies ebe49d0
Update nipype/interfaces/dipy/tracks.py
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
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
from distutils.version import LooseVersion | ||
from ... import logging | ||
from .base import HAVE_DIPY, dipy_version, dipy_to_nipype_interface | ||
|
||
IFLOGGER = logging.getLogger('nipype.interface') | ||
|
||
if HAVE_DIPY and LooseVersion(dipy_version()) >= LooseVersion('0.15'): | ||
|
||
from dipy.workflows.align import ResliceFlow, SlrWithQbxFlow | ||
|
||
Reslice = dipy_to_nipype_interface("Reslice", ResliceFlow) | ||
StreamlineRegistration = dipy_to_nipype_interface("StreamlineRegistration", | ||
SlrWithQbxFlow) | ||
|
||
else: | ||
IFLOGGER.info("We advise you to upgrade DIPY version. This upgrade will" | ||
" activate Reslice, StreamlineRegistration.") |
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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import pytest | ||
from collections import namedtuple | ||
from ...base import traits, TraitedSpec, BaseInterfaceInputSpec | ||
from ..base import (convert_to_traits_type, create_interface_specs, | ||
dipy_to_nipype_interface, DipyBaseInterface, no_dipy) | ||
|
||
|
||
def test_convert_to_traits_type(): | ||
Params = namedtuple("Params", "traits_type is_file") | ||
Res = namedtuple("Res", "traits_type is_mandatory") | ||
l_entries = [Params('variable string', False), | ||
Params('variable int', False), | ||
Params('variable float', False), | ||
Params('variable bool', False), | ||
Params('variable complex', False), | ||
Params('variable int, optional', False), | ||
Params('variable string, optional', False), | ||
Params('variable float, optional', False), | ||
Params('variable bool, optional', False), | ||
Params('variable complex, optional', False), | ||
Params('string', False), Params('int', False), | ||
Params('string', True), Params('float', False), | ||
Params('bool', False), Params('complex', False), | ||
Params('string, optional', False), | ||
Params('int, optional', False), | ||
Params('string, optional', True), | ||
Params('float, optional', False), | ||
Params('bool, optional', False), | ||
Params('complex, optional', False), | ||
] | ||
l_expected = [Res(traits.ListStr, True), Res(traits.ListInt, True), | ||
Res(traits.ListFloat, True), Res(traits.ListBool, True), | ||
Res(traits.ListComplex, True), Res(traits.ListInt, False), | ||
Res(traits.ListStr, False), Res(traits.ListFloat, False), | ||
Res(traits.ListBool, False), Res(traits.ListComplex, False), | ||
Res(traits.Str, True), Res(traits.Int, True), | ||
Res(traits.File, True), Res(traits.Float, True), | ||
Res(traits.Bool, True), Res(traits.Complex, True), | ||
Res(traits.Str, False), Res(traits.Int, False), | ||
Res(traits.File, False), Res(traits.Float, False), | ||
Res(traits.Bool, False), Res(traits.Complex, False), | ||
] | ||
|
||
for entry, res in zip(l_entries, l_expected): | ||
traits_type, is_mandatory = convert_to_traits_type(entry.traits_type, | ||
entry.is_file) | ||
assert traits_type == res.traits_type | ||
assert is_mandatory == res.is_mandatory | ||
|
||
with pytest.raises(IOError): | ||
convert_to_traits_type("file, optional") | ||
|
||
|
||
def test_create_interface_specs(): | ||
new_interface = create_interface_specs("MyInterface") | ||
|
||
assert new_interface.__base__ == TraitedSpec | ||
assert isinstance(new_interface(), TraitedSpec) | ||
assert new_interface.__name__ == "MyInterface" | ||
assert not new_interface().get() | ||
|
||
new_interface = create_interface_specs("MyInterface", | ||
BaseClass=BaseInterfaceInputSpec) | ||
assert new_interface.__base__ == BaseInterfaceInputSpec | ||
assert isinstance(new_interface(), BaseInterfaceInputSpec) | ||
assert new_interface.__name__ == "MyInterface" | ||
assert not new_interface().get() | ||
|
||
params = [("params1", "string", ["my description"]), ("params2_files", "string", ["my description @"]), | ||
("params3", "int, optional", ["useful option"]), ("out_params", "string", ["my out description"])] | ||
|
||
new_interface = create_interface_specs("MyInterface", params=params, | ||
BaseClass=BaseInterfaceInputSpec) | ||
|
||
assert new_interface.__base__ == BaseInterfaceInputSpec | ||
assert isinstance(new_interface(), BaseInterfaceInputSpec) | ||
assert new_interface.__name__ == "MyInterface" | ||
current_params = new_interface().get() | ||
assert len(current_params) == 4 | ||
assert 'params1' in current_params.keys() | ||
assert 'params2_files' in current_params.keys() | ||
assert 'params3' in current_params.keys() | ||
assert 'out_params' in current_params.keys() | ||
|
||
|
||
@pytest.mark.skipif(no_dipy(), reason="DIPY is not installed") | ||
def test_dipy_to_nipype_interface(): | ||
from dipy.workflows.workflow import Workflow | ||
|
||
class DummyWorkflow(Workflow): | ||
|
||
@classmethod | ||
def get_short_name(cls): | ||
return 'dwf1' | ||
|
||
def run(self, in_files, param1=1, out_dir='', out_ref='out1.txt'): | ||
"""Workflow used to test basic workflows. | ||
|
||
Parameters | ||
---------- | ||
in_files : string | ||
fake input string param | ||
param1 : int, optional | ||
fake positional param (default 1) | ||
out_dir : string, optional | ||
fake output directory (default '') | ||
out_ref : string, optional | ||
fake out file (default out1.txt) | ||
|
||
References | ||
----------- | ||
dummy references | ||
|
||
""" | ||
return param1 | ||
|
||
new_specs = dipy_to_nipype_interface("MyModelSpec", DummyWorkflow) | ||
assert new_specs.__base__ == DipyBaseInterface | ||
assert isinstance(new_specs(), DipyBaseInterface) | ||
assert new_specs.__name__ == "MyModelSpec" | ||
assert hasattr(new_specs, 'input_spec') | ||
assert new_specs().input_spec.__base__ == BaseInterfaceInputSpec | ||
assert hasattr(new_specs, 'output_spec') | ||
assert new_specs().output_spec.__base__ == TraitedSpec | ||
assert hasattr(new_specs, '_run_interface') | ||
assert hasattr(new_specs, '_list_outputs') | ||
params_in = new_specs().inputs.get() | ||
params_out = new_specs()._outputs().get() | ||
assert len(params_in) == 4 | ||
assert 'in_files' in params_in.keys() | ||
assert 'param1' in params_in.keys() | ||
assert 'out_dir' in params_out.keys() | ||
assert 'out_ref' in params_out.keys() | ||
|
||
with pytest.raises(ValueError): | ||
new_specs().run() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_convert_to_traits_type() | ||
test_create_interface_specs() | ||
test_dipy_to_nipype_interface() |
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.
Uh oh!
There was an error while loading. Please reload this page.