From 5407f0a2dbf35beff8d694bf8e416a4cb40cb3da Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Sat, 28 Apr 2018 23:26:20 -0400 Subject: [PATCH 1/6] moved origins to zero prior to any reslicing (this avoids a problem present in some images where the volume gets truncated upon reslicing) --- nipype/workflows/dmri/dtitk/tensor_registration.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index c4d3d32484..21224da902 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -75,7 +75,9 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', fields=['out_file', 'out_file_xfm', 'fixed_resliced', 'moving_resliced']), name='outputnode') - + origin_node_fixed = pe.Node(dtitk.TVAdjustVoxSp(origin=(0, 0, 0)), + name='origin_node_fixed') + origin_node_moving = origin_node_fixed.clone(name='origin_node_moving') reslice_node_pow2 = pe.Node(dtitk.TVResample( origin=(0, 0, 0), array_size=params['array_size']), @@ -96,10 +98,12 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', wf = pe.Workflow(name=name) # Reslice input images - wf.connect(inputnode, 'fixed_file', reslice_node_pow2, 'in_file') + wf.connect(inputnode, 'fixed_file', origin_node_fixed, 'in_file') + wf.connect(origin_node_fixed, 'out_file', reslice_node_pow2, 'in_file') wf.connect(reslice_node_pow2, 'out_file', reslice_node_moving, 'target_file') - wf.connect(inputnode, 'moving_file', reslice_node_moving, 'in_file') + wf.connect(inputnode, 'moving_file', origin_node_moving, 'in_file') + wf.connect(origin_node_moving, 'out_file', reslice_node_moving, 'in_file') # Rigid registration wf.connect(reslice_node_pow2, 'out_file', rigid_node, 'fixed_file') wf.connect(reslice_node_moving, 'out_file', rigid_node, 'moving_file') From ac3286d435b1744a5c15bab309b6b397cbbd8dea Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Tue, 15 May 2018 17:30:45 -0700 Subject: [PATCH 2/6] reslice output image to match input fixed --- nipype/workflows/dmri/dtitk/tensor_registration.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index 21224da902..c9120703df 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -55,7 +55,8 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', (Rigid and Affine follwed by Diffeomorphic) Note: the requirements for a diffeomorphic registration specify that the dimension 0 is a power of 2 so images are resliced prior to - registration + registration. Remember to move origin and reslice prior to applying xfm to + another file Example ------- @@ -94,6 +95,8 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', compose_xfm_node = pe.Node(dtitk.ComposeXfm(), name='compose_xfm_node') apply_xfm_node = pe.Node(dtitk.DiffeoSymTensor3DVol(), name='apply_xfm_node') + reslice_node_to_input = pe.Node(dtitk.TVResample(), + name='reslice_node_to_input') wf = pe.Workflow(name=name) @@ -122,8 +125,11 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', # Apply transform wf.connect(reslice_node_moving, 'out_file', apply_xfm_node, 'in_file') wf.connect(compose_xfm_node, 'out_file', apply_xfm_node, 'transform') + # Reslice to match original fixed input image + wf.connect(apply_xfm_node, 'out_file', reslice_node_to_input, 'in_file') + wf.connect(inputnode, 'fixed_file', reslice_node_to_input, 'target_file') # Send to output - wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') + wf.connect(reslice_node_to_input, 'out_file', outputnode, 'out_file') wf.connect(compose_xfm_node, 'out_file', outputnode, 'out_file_xfm') wf.connect(reslice_node_pow2, 'out_file', outputnode, 'fixed_resliced') wf.connect(reslice_node_moving, 'out_file', outputnode, 'moving_resliced') From 5d238c0b2c4289db153df9ba302399adc9ec4c86 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 23 May 2018 11:24:16 -0700 Subject: [PATCH 3/6] added apply_xfm workflow --- .../dmri/dtitk/tensor_registration.py | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index c9120703df..76179862a2 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -56,7 +56,7 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', Note: the requirements for a diffeomorphic registration specify that the dimension 0 is a power of 2 so images are resliced prior to registration. Remember to move origin and reslice prior to applying xfm to - another file + another file! Example ------- @@ -135,3 +135,45 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', wf.connect(reslice_node_moving, 'out_file', outputnode, 'moving_resliced') return wf + + +def apply_diffeo(name='ApplyDiffeo', params={'array_size': (128, 128, 64)}): + + """ + Workflow that applies a dtitk diffeomorphic registration to a scalar volume + by moving the origin and reslicing, then applying the transform. + + Example + ------- + + >>> from nipype.workflows.dmri.dtitk.tensor_registration import apply_diffeo + >>> app_diffeo = diffeomorphic_tensor_pipeline() + >>> app_diffeo.inputs.inputnode.moving_file = 'im1.nii' + >>> app_diffeo.inputs.inputnode.xfm_file = 'im_warp.df.nii' + >>> app_diffeo.run() # doctest: +SKIP + + + """ + inputnode = pe.Node(niu.IdentityInterface( + fields=['moving_file', 'xfm_file']), + name='inputnode') + outputnode = pe.Node(niu.IdentityInterface( + fields=['out_file']), + name='outputnode') + origin_node = pe.Node(dtitk.TVAdjustVoxSp(origin=(0, 0, 0)), + name='origin_node') + reslice_node_pow2 = pe.Node(dtitk.TVResample( + origin=(0, 0, 0), + array_size=params['array_size']), + name='reslice_node_pow2') + apply_xfm_node = pe.Node(dtitk.DiffeoScalarVol(), name='apply_xfm_node') + + wf = pe.Workflow(name=name) + + wf.connect(inputnode, 'moving_file', origin_node, 'in_file') + wf.connect(origin_node, 'out_file', reslice_node_pow2, 'in_file') + wf.connect(reslice_node_pow2, 'out_file', apply_xfm_node, 'in_file') + wf.connect(inputnode, 'xfm_file', apply_xfm_node, 'transform') + wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') + + return wf From 73abfda46bcf9eac99eb6f80f3d052be8ff3f790 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Wed, 23 May 2018 13:47:37 -0700 Subject: [PATCH 4/6] nonlinear wf works with nonzero origin images --- nipype/workflows/dmri/dtitk/tensor_registration.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index 76179862a2..b6e3f73862 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -95,11 +95,16 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', compose_xfm_node = pe.Node(dtitk.ComposeXfm(), name='compose_xfm_node') apply_xfm_node = pe.Node(dtitk.DiffeoSymTensor3DVol(), name='apply_xfm_node') + adjust_vs_node_to_input = pe.Node(dtitk.TVAdjustVoxSp(), + name='adjust_vs_node_to_input') reslice_node_to_input = pe.Node(dtitk.TVResample(), name='reslice_node_to_input') + input_fa = pe.Node(dtitk.TVtool(in_flag='fa'), name='input_fa') wf = pe.Workflow(name=name) + # calculate input FA image for origin reference + wf.connect(inputnode, 'fixed_file', input_fa, 'in_file') # Reslice input images wf.connect(inputnode, 'fixed_file', origin_node_fixed, 'in_file') wf.connect(origin_node_fixed, 'out_file', reslice_node_pow2, 'in_file') @@ -125,9 +130,11 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', # Apply transform wf.connect(reslice_node_moving, 'out_file', apply_xfm_node, 'in_file') wf.connect(compose_xfm_node, 'out_file', apply_xfm_node, 'transform') - # Reslice to match original fixed input image - wf.connect(apply_xfm_node, 'out_file', reslice_node_to_input, 'in_file') - wf.connect(inputnode, 'fixed_file', reslice_node_to_input, 'target_file') + # Move origin and reslice to match original fixed input image + wf.connect(apply_xfm_node, 'out_file', adjust_vs_node_to_input, 'in_file') + wf.connect(input_fa, 'out_file', adjust_vs_node_to_input, 'target_file') + wf.connect(adjust_vs_node_to_input, 'out_file', reslice_node_to_input, 'in_file') + wf.connect(input_fa, 'out_file', reslice_node_to_input, 'target_file') # Send to output wf.connect(reslice_node_to_input, 'out_file', outputnode, 'out_file') wf.connect(compose_xfm_node, 'out_file', outputnode, 'out_file_xfm') From fe3c97e7955589f02ba64d6ee4cc2fce6f36974b Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 24 May 2018 09:32:59 -0700 Subject: [PATCH 5/6] specs --- nipype/interfaces/dcm2nii.py | 2 +- nipype/tests/test_nipype.py | 2 +- nipype/workflows/dmri/dtitk/tensor_registration.py | 11 +++++------ tools/checkspecs.py | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/nipype/interfaces/dcm2nii.py b/nipype/interfaces/dcm2nii.py index 1fd12e0930..3fa657fab3 100644 --- a/nipype/interfaces/dcm2nii.py +++ b/nipype/interfaces/dcm2nii.py @@ -264,7 +264,7 @@ class Dcm2niixInputSpec(CommandLineInputSpec): position=-1, copyfile=False, mandatory=True, - desc=('A set of filenames to be converted. Note that the current ' + desc=('A set of filenames to be converted. Note that the current ' 'version (1.0.20180328) of dcm2niix converts any files in the ' 'directory. To only convert specific files they should be in an ' 'isolated directory'), diff --git a/nipype/tests/test_nipype.py b/nipype/tests/test_nipype.py index 31558fba5b..01fd081bc9 100644 --- a/nipype/tests/test_nipype.py +++ b/nipype/tests/test_nipype.py @@ -12,7 +12,7 @@ def test_nipype_info(): assert exception_not_raised -@pytest.mark.skipif(not get_nipype_gitversion(), +@pytest.mark.skipif(not get_nipype_gitversion(), reason="not able to get version from get_nipype_gitversion") def test_git_hash(): # removing the first "g" from gitversion diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index b6e3f73862..6100b06c7e 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -52,7 +52,7 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', params={'array_size': (128, 128, 64)}): """ Workflow that performs a diffeomorphic registration - (Rigid and Affine follwed by Diffeomorphic) + (Rigid and Affine followed by Diffeomorphic) Note: the requirements for a diffeomorphic registration specify that the dimension 0 is a power of 2 so images are resliced prior to registration. Remember to move origin and reslice prior to applying xfm to @@ -143,7 +143,7 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', return wf - +''' def apply_diffeo(name='ApplyDiffeo', params={'array_size': (128, 128, 64)}): """ @@ -167,10 +167,9 @@ def apply_diffeo(name='ApplyDiffeo', params={'array_size': (128, 128, 64)}): outputnode = pe.Node(niu.IdentityInterface( fields=['out_file']), name='outputnode') - origin_node = pe.Node(dtitk.TVAdjustVoxSp(origin=(0, 0, 0)), + origin_node = pe.Node(dtitk.SVAdjustVoxSp(origin=(0, 0, 0)), name='origin_node') - reslice_node_pow2 = pe.Node(dtitk.TVResample( - origin=(0, 0, 0), + reslice_node_pow2 = pe.Node(dtitk.SVResample( array_size=params['array_size']), name='reslice_node_pow2') apply_xfm_node = pe.Node(dtitk.DiffeoScalarVol(), name='apply_xfm_node') @@ -183,4 +182,4 @@ def apply_diffeo(name='ApplyDiffeo', params={'array_size': (128, 128, 64)}): wf.connect(inputnode, 'xfm_file', apply_xfm_node, 'transform') wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') - return wf + return wf''' diff --git a/tools/checkspecs.py b/tools/checkspecs.py index 273a707950..e282728c8e 100644 --- a/tools/checkspecs.py +++ b/tools/checkspecs.py @@ -287,7 +287,7 @@ def test_specs(self, uri): and "requires" not in trait.__dict__\ and "xor" not in trait.__dict__: if trait.trait_type.__class__.__name__ is "Range"\ - and trait.default == trait.trait_type._low: + and trait.default == trait.trait_type._low: continue bad_specs.append( [uri, c, 'Inputs', traitname, 'default value is set, no value for usedefault']) From 9545859cc94c222edbad4958c420de9c0f7eee74 Mon Sep 17 00:00:00 2001 From: kesshijordan Date: Thu, 24 May 2018 09:34:12 -0700 Subject: [PATCH 6/6] removed non-functional wf --- .../dmri/dtitk/tensor_registration.py | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/nipype/workflows/dmri/dtitk/tensor_registration.py b/nipype/workflows/dmri/dtitk/tensor_registration.py index 6100b06c7e..faae608a44 100644 --- a/nipype/workflows/dmri/dtitk/tensor_registration.py +++ b/nipype/workflows/dmri/dtitk/tensor_registration.py @@ -142,44 +142,3 @@ def diffeomorphic_tensor_pipeline(name='DiffeoTen', wf.connect(reslice_node_moving, 'out_file', outputnode, 'moving_resliced') return wf - -''' -def apply_diffeo(name='ApplyDiffeo', params={'array_size': (128, 128, 64)}): - - """ - Workflow that applies a dtitk diffeomorphic registration to a scalar volume - by moving the origin and reslicing, then applying the transform. - - Example - ------- - - >>> from nipype.workflows.dmri.dtitk.tensor_registration import apply_diffeo - >>> app_diffeo = diffeomorphic_tensor_pipeline() - >>> app_diffeo.inputs.inputnode.moving_file = 'im1.nii' - >>> app_diffeo.inputs.inputnode.xfm_file = 'im_warp.df.nii' - >>> app_diffeo.run() # doctest: +SKIP - - - """ - inputnode = pe.Node(niu.IdentityInterface( - fields=['moving_file', 'xfm_file']), - name='inputnode') - outputnode = pe.Node(niu.IdentityInterface( - fields=['out_file']), - name='outputnode') - origin_node = pe.Node(dtitk.SVAdjustVoxSp(origin=(0, 0, 0)), - name='origin_node') - reslice_node_pow2 = pe.Node(dtitk.SVResample( - array_size=params['array_size']), - name='reslice_node_pow2') - apply_xfm_node = pe.Node(dtitk.DiffeoScalarVol(), name='apply_xfm_node') - - wf = pe.Workflow(name=name) - - wf.connect(inputnode, 'moving_file', origin_node, 'in_file') - wf.connect(origin_node, 'out_file', reslice_node_pow2, 'in_file') - wf.connect(reslice_node_pow2, 'out_file', apply_xfm_node, 'in_file') - wf.connect(inputnode, 'xfm_file', apply_xfm_node, 'transform') - wf.connect(apply_xfm_node, 'out_file', outputnode, 'out_file') - - return wf'''