Exemplo n.º 1
0
def test_JointFusion_radius():
    at = JointFusion()
    set_radius = lambda attr,x,y,z: setattr(at.inputs, attr, [x, y, z])
    for attr in ['patch_radius', 'search_radius']:
        for x in range(5):
            set_radius(attr, x, x + 1, x**x)
            yield assert_equal, at._format_arg(attr, None, getattr(at.inputs, attr))[4:], '{0}x{1}x{2}'.format(x, x + 1, x**x)
Exemplo n.º 2
0
def test_JointFusion_radius():
    at = JointFusion()
    set_radius = lambda attr,x,y,z: setattr(at.inputs, attr, [x, y, z])
    for attr in ['patch_radius', 'search_radius']:
        for x in range(5):
            set_radius(attr, x, x + 1, x**x)
            yield assert_equal, at._format_arg(attr, None, getattr(at.inputs, attr))[4:], '{0}x{1}x{2}'.format(x, x + 1, x**x)
Exemplo n.º 3
0
def test_JointFusion_cmd():
    at = JointFusion()
    at.inputs.dimension = 3
    at.inputs.modalities = 1
    at.inputs.method = 'Joint[0.1,2]'
    at.inputs.output_label_image = 'fusion_labelimage_output.nii'
    warped_intensity_images = [example_data('im1.nii'),
                               example_data('im2.nii')]
    at.inputs.warped_intensity_images = warped_intensity_images
    segmentation_images = [example_data('segmentation0.nii.gz'),
                           example_data('segmentation1.nii.gz')]
    at.inputs.warped_label_images = segmentation_images
    T1_image = example_data('T1.nii')
    at.inputs.target_image = T1_image
    at.inputs.patch_radius = [3, 2, 1]
    at.inputs.search_radius = [1, 2, 3]
    expected_command = ('jointfusion 3 1 -m Joint[0.1,2] -rp 3x2x1 -rs 1x2x3'
                        ' -tg %s -g %s -g %s -l %s -l %s'
                        ' fusion_labelimage_output.nii') % (T1_image,
                                                            warped_intensity_images[0],
                                                            warped_intensity_images[1],
                                                            segmentation_images[0],
                                                            segmentation_images[1])
    assert at.cmdline == expected_command
    # setting intensity or labels with unequal lengths raises error
    with pytest.raises(AssertionError):
        at._format_arg('warped_intensity_images', InputMultiPath, warped_intensity_images + [example_data('im3.nii')])
Exemplo n.º 4
0
def test_JointFusion_cmd():
    at = JointFusion()
    at.inputs.dimension = 3
    at.inputs.modalities = 1
    at.inputs.method = 'Joint[0.1,2]'
    at.inputs.output_label_image = 'fusion_labelimage_output.nii'
    warped_intensity_images = [
        example_data('im1.nii'),
        example_data('im2.nii')
    ]
    at.inputs.warped_intensity_images = warped_intensity_images
    segmentation_images = [
        example_data('segmentation0.nii.gz'),
        example_data('segmentation1.nii.gz')
    ]
    at.inputs.warped_label_images = segmentation_images
    T1_image = example_data('T1.nii')
    at.inputs.target_image = T1_image
    at.inputs.patch_radius = [3, 2, 1]
    at.inputs.search_radius = [1, 2, 3]
    expected_command = ('jointfusion 3 1 -m Joint[0.1,2] -rp 3x2x1 -rs 1x2x3'
                        ' -tg %s -g %s -g %s -l %s -l %s'
                        ' fusion_labelimage_output.nii') % (
                            T1_image, warped_intensity_images[0],
                            warped_intensity_images[1], segmentation_images[0],
                            segmentation_images[1])
    assert at.cmdline == expected_command
    # setting intensity or labels with unequal lengths raises error
    with pytest.raises(AssertionError):
        at._format_arg('warped_intensity_images', InputMultiPath,
                       warped_intensity_images + [example_data('im3.nii')])
Exemplo n.º 5
0
def test_JointFusion_cmd():
    at = JointFusion()
    at.inputs.dimension = 3
    at.inputs.modalities = 1
    at.inputs.method = 'Joint[0.1,2]'
    at.inputs.output_label_image = 'fusion_labelimage_output.nii'
    at.inputs.warped_intensity_images = ['im1.nii', 'im2.nii']
    at.inputs.warped_label_images = [
        'segmentation0.nii.gz', 'segmentation1.nii.gz'
    ]
    at.inputs.target_image = 'T1.nii'
    at.inputs.patch_radius = [3, 2, 1]
    at.inputs.search_radius = [1, 2, 3]
    yield assert_equal, at.cmdline, 'jointfusion 3 1' + \
      ' -m Joint[0.1,2]' + \
      ' -rp 3x2x1' + \
      ' -rs 1x2x3' + \
      ' -tg T1.nii' + \
      ' -g im1.nii' + \
      ' -g im2.nii' + \
      ' -l segmentation0.nii.gz' + \
      ' -l segmentation1.nii.gz' + \
      ' fusion_labelimage_output.nii',
    "Command line generation failure", True
    # setting intensity or labels with unequal lengths raises error
    yield assert_raises, AssertionError, at._format_arg, 'warped_intensity_images', InputMultiPath, [
        'im1.nii', 'im2.nii', 'im3.nii'
    ]
Exemplo n.º 6
0
def test_JointFusion_dimension():
    at = JointFusion()
    set_dimension = lambda d: setattr(at.inputs, 'dimension', int(d))
    for d in range(2, 5):
        set_dimension(d)
        yield assert_equal, at.inputs.dimension, int(d)
    for d in [0, 1, 6, 7]:
        yield assert_raises, TraitError, set_dimension, d
Exemplo n.º 7
0
    def __init__(self,
                 atlas_segmentation_image=['path', 'path'],
                 atlas_image=[['path']],
                 target_image=['path'],
                 **options):

        from nipype.interfaces.ants import JointFusion
        at = JointFusion()
        at.inputs.warped_label_images = warped_label_images
        at.inputs.warped_intensity_images = warped_intensity_images
        at.inputs.output_label_image = output_label_image
        at.inputs.target_image = target_image
        at.inputs.modalities = modalities
        at.inputs.dimension = dimension
        for ef in options:
            setattr(at.inputs, ef, options[ef])
        self.res = at.run()
def test_JointFusion_dimension():
    at = JointFusion()
    set_dimension = lambda d: setattr(at.inputs, "dimension", int(d))
    for d in range(2, 5):
        set_dimension(d)
        assert at.inputs.dimension == int(d)
    for d in [0, 1, 6, 7]:
        with pytest.raises(TraitError):
            set_dimension(d)
Exemplo n.º 9
0
def test_JointFusion_method(a, b):
    at = JointFusion()
    set_method = lambda a, b: setattr(at.inputs, 'method', 'Joint[%.1f,%d]'.format(a, b))
    _a = a / 10.0
    set_method(_a, b)
    # set directly
    assert at.inputs.method == 'Joint[%.1f,%d]'.format(_a, b)
    aprime = _a + 0.1
    bprime = b + 1
    at.inputs.alpha = aprime
    at.inputs.beta = bprime
    # set with alpha/beta
    assert at.inputs.method == 'Joint[%.1f,%d]'.format(aprime, bprime)
Exemplo n.º 10
0
def test_JointFusion_method():
    at = JointFusion()
    set_method = lambda a, b: setattr(at.inputs, 'method', 'Joint[%.1f,%d]'.format(a, b))
    for a in range(10):
        _a = a / 10.0
        for b in range(10):
            set_method(_a, b)
            # set directly
            yield assert_equal, at.inputs.method, 'Joint[%.1f,%d]'.format(_a, b)
            aprime = _a + 0.1
            bprime = b + 1
            at.inputs.alpha = aprime
            at.inputs.beta = bprime
            # set with alpha/beta
            yield assert_equal, at.inputs.method, 'Joint[%.1f,%d]'.format(aprime, bprime)
Exemplo n.º 11
0
def test_JointFusion_modalities():
    at = JointFusion()
    set_modalities = lambda m: setattr(at.inputs, 'modalities', int(m))
    for m in range(1, 5):
        set_modalities(m)
        yield assert_equal, at.inputs.modalities, int(m)
Exemplo n.º 12
0
def test_JointFusion_radius(attr, x):
    at = JointFusion()
    setattr(at.inputs, attr, [x, x + 1, x**x])
    assert at._format_arg(attr, None, getattr(
        at.inputs, attr))[4:] == "{0}x{1}x{2}".format(x, x + 1, x**x)
Exemplo n.º 13
0
def test_JointFusion_modalities(m):
    at = JointFusion()
    setattr(at.inputs, "modalities", int(m))
    assert at.inputs.modalities == int(m)
Exemplo n.º 14
0
def test_JointFusion_radius(attr, x):
    at = JointFusion()
    setattr(at.inputs, attr, [x, x+1, x**x])
    assert at._format_arg(attr, None, getattr(at.inputs, attr))[4:] == '{0}x{1}x{2}'.format(x, x + 1, x**x)