Skip to content

fix:test & fix bug using aux functions in connect #1405

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 3 commits into from
Mar 19, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
145 changes: 71 additions & 74 deletions nipype/interfaces/petpvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,8 @@
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
>>> os.chdir(datadir)

Nipype interface for PETPVC.

PETPVC is a software from the Nuclear Medicine Department
of the UCL University Hospital, London, UK.

Its source code is here: https://github.com/UCL/PETPVC

The methods that it implement are explained here:
K. Erlandsson, I. Buvat, P. H. Pretorius, B. A. Thomas, and B. F. Hutton,
"A review of partial volume correction techniques for emission tomography
and their applications in neurology, cardiology and oncology," Phys. Med.
Biol., vol. 57, no. 21, p. R119, 2012.

There is a publication waiting to be accepted for this software tool.


Its command line help shows this:

-i --input < filename >
= PET image file
-o --output < filename >
= Output file
[ -m --mask < filename > ]
= Mask image file
-p --pvc < keyword >
= Desired PVC method
-x < X >
= The full-width at half maximum in mm along x-axis
-y < Y >
= The full-width at half maximum in mm along y-axis
-z < Z >
= The full-width at half maximum in mm along z-axis
[ -d --debug ]
= Prints debug information
[ -n --iter [ Val ] ]
= Number of iterations
With: Val (Default = 10)
[ -k [ Val ] ]
= Number of deconvolution iterations
With: Val (Default = 10)
[ -a --alpha [ aval ] ]
= Alpha value
With: aval (Default = 1.5)
[ -s --stop [ stopval ] ]
= Stopping criterion
With: stopval (Default = 0.01)

----------------------------------------------
Technique - keyword

Geometric transfer matrix - "GTM"
Labbe approach - "LABBE"
Richardson-Lucy - "RL"
Van-Cittert - "VC"
Region-based voxel-wise correction - "RBV"
RBV with Labbe - "LABBE+RBV"
RBV with Van-Cittert - "RBV+VC"
RBV with Richardson-Lucy - "RBV+RL"
RBV with Labbe and Van-Cittert - "LABBE+RBV+VC"
RBV with Labbe and Richardson-Lucy- "LABBE+RBV+RL"
Multi-target correction - "MTC"
MTC with Labbe - "LABBE+MTC"
MTC with Van-Cittert - "MTC+VC"
MTC with Richardson-Lucy - "MTC+RL"
MTC with Labbe and Van-Cittert - "LABBE+MTC+VC"
MTC with Labbe and Richardson-Lucy- "LABBE+MTC+RL"
Iterative Yang - "IY"
Iterative Yang with Van-Cittert - "IY+VC"
Iterative Yang with Richardson-Lucy - "IY+RL"
Muller Gartner - "MG"
Muller Gartner with Van-Cittert - "MG+VC"
Muller Gartner with Richardson-Lucy - "MG+RL"

"""

from __future__ import print_function
from __future__ import division

Expand Down Expand Up @@ -144,6 +71,76 @@ class PETPVCOutputSpec(TraitedSpec):
class PETPVC(CommandLine):
""" Use PETPVC for partial volume correction of PET images.

PETPVC is a software from the Nuclear Medicine Department
of the UCL University Hospital, London, UK.

Its source code is here: https://github.com/UCL/PETPVC

The methods that it implement are explained here:
K. Erlandsson, I. Buvat, P. H. Pretorius, B. A. Thomas, and B. F. Hutton,
"A review of partial volume correction techniques for emission tomography
and their applications in neurology, cardiology and oncology," Phys. Med.
Biol., vol. 57, no. 21, p. R119, 2012.

There is a publication waiting to be accepted for this software tool.

Its command line help shows this:

-i --input < filename >
= PET image file
-o --output < filename >
= Output file
[ -m --mask < filename > ]
= Mask image file
-p --pvc < keyword >
= Desired PVC method
-x < X >
= The full-width at half maximum in mm along x-axis
-y < Y >
= The full-width at half maximum in mm along y-axis
-z < Z >
= The full-width at half maximum in mm along z-axis
[ -d --debug ]
= Prints debug information
[ -n --iter [ Val ] ]
= Number of iterations
With: Val (Default = 10)
[ -k [ Val ] ]
= Number of deconvolution iterations
With: Val (Default = 10)
[ -a --alpha [ aval ] ]
= Alpha value
With: aval (Default = 1.5)
[ -s --stop [ stopval ] ]
= Stopping criterion
With: stopval (Default = 0.01)

----------------------------------------------
Technique - keyword

Geometric transfer matrix - "GTM"
Labbe approach - "LABBE"
Richardson-Lucy - "RL"
Van-Cittert - "VC"
Region-based voxel-wise correction - "RBV"
RBV with Labbe - "LABBE+RBV"
RBV with Van-Cittert - "RBV+VC"
RBV with Richardson-Lucy - "RBV+RL"
RBV with Labbe and Van-Cittert - "LABBE+RBV+VC"
RBV with Labbe and Richardson-Lucy- "LABBE+RBV+RL"
Multi-target correction - "MTC"
MTC with Labbe - "LABBE+MTC"
MTC with Van-Cittert - "MTC+VC"
MTC with Richardson-Lucy - "MTC+RL"
MTC with Labbe and Van-Cittert - "LABBE+MTC+VC"
MTC with Labbe and Richardson-Lucy- "LABBE+MTC+RL"
Iterative Yang - "IY"
Iterative Yang with Van-Cittert - "IY+VC"
Iterative Yang with Richardson-Lucy - "IY+RL"
Muller Gartner - "MG"
Muller Gartner with Van-Cittert - "MG+VC"
Muller Gartner with Richardson-Lucy - "MG+RL"

Examples
--------
>>> from ..testing import example_data
Expand Down
55 changes: 54 additions & 1 deletion nipype/interfaces/tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def increment_array(in_array):
f2 = pe.MapNode(utility.Function(input_names=['in_array'], output_names=['out_array'], function=increment_array), name='increment_array', iterfield=['in_array'])

wf.connect(f1, 'random_array', f2, 'in_array')

wf.run()

# Clean up
Expand Down Expand Up @@ -167,3 +166,57 @@ def test_csvReader():
yield assert_equal, out.outputs.column_1, ['hello', 'world', 'goodbye']
yield assert_equal, out.outputs.column_2, ['300.1', '5', '0.3']
os.unlink(name)


def test_aux_connect_function():
""" This tests excution nodes with multiple inputs and auxiliary
function inside the Workflow connect function.
"""
tempdir = os.path.realpath(mkdtemp())
origdir = os.getcwd()
os.chdir(tempdir)

wf = pe.Workflow(name="test_workflow")

def _gen_tuple(size):
return [1, ] * size

def _sum_and_sub_mul(a, b, c):
return (a+b)*c, (a-b)*c

def _inc(x):
return x + 1

params = pe.Node(utility.IdentityInterface(fields=['size', 'num']), name='params')
params.inputs.num = 42
params.inputs.size = 1

gen_tuple = pe.Node(utility.Function(input_names=['size'],
output_names=['tuple'],
function=_gen_tuple),
name='gen_tuple')

ssm = pe.Node(utility.Function(input_names=['a', 'b', 'c'],
output_names=['sum', 'sub'],
function=_sum_and_sub_mul),
name='sum_and_sub_mul')

split = pe.Node(utility.Split(splits=[1, 1],
squeeze=True),
name='split')


wf.connect([
(params, gen_tuple, [(("size", _inc), "size")]),
(params, ssm, [(("num", _inc), "c")]),
(gen_tuple, split, [("tuple", "inlist")]),
(split, ssm, [(("out1", _inc), "a"),
("out2", "b"),
]),
])

wf.run()

# Clean up
os.chdir(origdir)
shutil.rmtree(tempdir)
2 changes: 1 addition & 1 deletion nipype/pipeline/engine/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def _configure_exec_nodes(self, graph):
node.input_source = {}
for edge in graph.in_edges_iter(node):
data = graph.get_edge_data(*edge)
for sourceinfo, field in sorted(data['connect']):
for sourceinfo, field in data['connect']:
node.input_source[field] = \
(op.join(edge[0].output_dir(),
'result_%s.pklz' % edge[0].name),
Expand Down