Skip to content

Commit 4483782

Browse files
committed
rf: Replace disconnects with conditional connects, rename inu_n4_final
1 parent c6b110b commit 4483782

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

niworkflows/anat/ants.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ def init_atropos_wf(
776776
(merge_tpms, copy_xform, [('out', 'out_tpms')]),
777777
(atropos, sel_wm, [('posteriors', 'inlist')]),
778778
(sel_wm, copy_xform_wm, [('out', 'wm_map')]),
779-
(copy_xform_wm, inu_n4_final, [('wm_map', 'weight_image')]),
780779
(inu_n4_final, copy_xform, [('output_image', 'bias_corrected'),
781780
('bias_image', 'bias_image')]),
782781
(copy_xform, apply_mask, [('bias_corrected', 'in_file'),
@@ -808,9 +807,6 @@ def _argmax(in_dice):
808807

809808
apply_wm_prior = pe.Node(niu.Function(function=_improd), name='apply_wm_prior')
810809

811-
wf.disconnect([
812-
(copy_xform_wm, inu_n4_final, [('wm_map', 'weight_image')]),
813-
]) # fmt:skip
814810
wf.connect([
815811
(inputnode, apply_wm_prior, [('in_mask', 'in_mask'),
816812
('wm_prior', 'op2')]),
@@ -822,6 +818,8 @@ def _argmax(in_dice):
822818
(copy_xform_wm, apply_wm_prior, [('wm_map', 'op1')]),
823819
(apply_wm_prior, inu_n4_final, [('out', 'weight_image')]),
824820
]) # fmt:skip
821+
else:
822+
wf.connect([(copy_xform_wm, inu_n4_final, [('wm_map', 'weight_image')])])
825823
return wf
826824

827825

@@ -925,7 +923,7 @@ def init_n4_only_wf(
925923
thr_brainmask = pe.Node(Binarize(thresh_low=2), name='binarize')
926924

927925
# INU correction
928-
inu_n4_final = pe.MapNode(
926+
inu_n4 = pe.MapNode(
929927
N4BiasFieldCorrection(
930928
dimension=3,
931929
save_bias=True,
@@ -936,31 +934,28 @@ def init_n4_only_wf(
936934
bspline_fitting_distance=200,
937935
),
938936
n_procs=omp_nthreads,
939-
name='inu_n4_final',
937+
name='inu_n4',
940938
iterfield=['input_image'],
941939
)
942940

943941
# Check ANTs version
944942
try:
945-
inu_n4_final.inputs.rescale_intensities = True
943+
inu_n4.inputs.rescale_intensities = True
946944
except ValueError:
947945
warn(
948946
"N4BiasFieldCorrection's --rescale-intensities option was added in ANTS 2.1.0 "
949-
f'({inu_n4_final.interface.version} found.) Please consider upgrading.',
947+
f'({inu_n4.interface.version} found.) Please consider upgrading.',
950948
UserWarning,
951949
stacklevel=1,
952950
)
953951

954952
wf.connect([
955-
(inputnode, inu_n4_final, [('in_files', 'input_image')]),
953+
(inputnode, inu_n4, [('in_files', 'input_image')]),
956954
(inputnode, thr_brainmask, [(('in_files', _pop), 'in_file')]),
957955
(thr_brainmask, outputnode, [('out_mask', 'out_mask')]),
958-
(inu_n4_final, outputnode, [('output_image', 'out_file'),
959-
('output_image', 'bias_corrected'),
960-
('bias_image', 'bias_image')]),
961956
]) # fmt:skip
962957

963-
# If atropos refine, do in4 twice
958+
# If atropos refine, n4 is run a second time
964959
if atropos_refine:
965960
atropos_model = atropos_model or list(ATROPOS_MODELS[bids_suffix].values())
966961
atropos_wf = init_atropos_wf(
@@ -970,14 +965,9 @@ def init_n4_only_wf(
970965
in_segmentation_model=atropos_model,
971966
)
972967

973-
wf.disconnect([
974-
(inu_n4_final, outputnode, [('output_image', 'out_file'),
975-
('output_image', 'bias_corrected'),
976-
('bias_image', 'bias_image')]),
977-
]) # fmt:skip
978968
wf.connect([
979969
(inputnode, atropos_wf, [('in_files', 'inputnode.in_files')]),
980-
(inu_n4_final, atropos_wf, [('output_image', 'inputnode.in_corrected')]),
970+
(inu_n4, atropos_wf, [('output_image', 'inputnode.in_corrected')]),
981971
(thr_brainmask, atropos_wf, [('out_mask', 'inputnode.in_mask')]),
982972
(atropos_wf, outputnode, [
983973
('outputnode.out_file', 'out_file'),
@@ -987,6 +977,12 @@ def init_n4_only_wf(
987977
('outputnode.out_tpms', 'out_tpms'),
988978
]),
989979
]) # fmt:skip
980+
else:
981+
wf.connect([
982+
(inu_n4, outputnode, [('output_image', 'out_file'),
983+
('output_image', 'bias_corrected'),
984+
('bias_image', 'bias_image')]),
985+
]) # fmt:skip
990986

991987
return wf
992988

0 commit comments

Comments
 (0)