Skip to content
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
17 changes: 9 additions & 8 deletions ants/segmentation/atropos.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def atropos(a, x, i='Kmeans[3]', m='[0.2,1x1]', c='[5,0]',
usually 0 (priors used for initialization only), 0.25 or 0.5.

kwargs : keyword arguments
more parameters, see Atropos help in ANTs
more parameters, see Atropos help in ANTs. Options set via function arguments
should not be repeated in kwargs.

Returns
-------
Expand Down Expand Up @@ -111,31 +112,31 @@ def atropos(a, x, i='Kmeans[3]', m='[0.2,1x1]', c='[5,0]',
myargs = {
'd': mydim,
'a': a,
'm-MULTINAME-0': m,
'o': outs,
'c': c,
'm-MULTINAME-1': m,
'm': m,
'i': i,
'x': mymask
}
for k, v in kwargs.items():
myargs[k] = v

elif isinstance(a, (list, tuple)):
if len(a) > 6:
print('more than 6 input images not really supported, using first 6')
a = a[:6]
myargs = {
'd': mydim,
'm-MULTINAME-0': m,
'o': outs,
'c': c,
'm-MULTINAME-1': m,
'm': m,
'i': i,
'x': mymask
}
for aa_idx, aa in enumerate(a):
myargs['a-MULTINAME-%i'%aa_idx] = aa
else:
raise ValueError('atropos: a must be an ANTsImage or list/tuple of ANTsImage types')

for k, v in kwargs.items():
myargs[k] = v

processed_args = process_arguments(myargs)
libfn = get_lib_fn('Atropos')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ def test_joint_fusion_preserves_basename_in_directory(self):

class TestModule_atropos(unittest.TestCase):

def test_kwargs_forwarded_for_single_and_multiple_inputs(self):
module = importlib.import_module('ants.segmentation.atropos')
image = ants.from_numpy(np.ones((4, 4), dtype=np.float32))
for inputs in (image, [image], (image,), [image, image], (image, image)):
count = len(inputs) if isinstance(inputs, (list, tuple)) else 1
with self.subTest(container=type(inputs).__name__, count=count):
native = Mock(side_effect=RuntimeError('stop before native execution'))
with patch.object(module, 'get_lib_fn', return_value=native):
with self.assertRaisesRegex(RuntimeError, 'stop before native execution'):
ants.atropos(inputs, image, v=1, **{'likelihood-model': 'Gaussian'})
args = native.call_args.args[0]
self.assertIn('-v', args)
self.assertEqual(args[args.index('-v') + 1], '1')
self.assertIn('--likelihood-model', args)
self.assertEqual(args[args.index('--likelihood-model') + 1], 'Gaussian')

def setUp(self):
pass

Expand Down
Loading