Skip to content

Commit 5aa974d

Browse files
committed
rf: Replace disconnects with conditional connects, rename inu_n4_final
1 parent 4c8fe99 commit 5aa974d

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
@@ -777,7 +777,6 @@ def init_atropos_wf(
777777
(merge_tpms, copy_xform, [('out', 'out_tpms')]),
778778
(atropos, sel_wm, [('posteriors', 'inlist')]),
779779
(sel_wm, copy_xform_wm, [('out', 'wm_map')]),
780-
(copy_xform_wm, inu_n4_final, [('wm_map', 'weight_image')]),
781780
(inu_n4_final, copy_xform, [('output_image', 'bias_corrected'),
782781
('bias_image', 'bias_image')]),
783782
(copy_xform, apply_mask, [('bias_corrected', 'in_file'),
@@ -809,9 +808,6 @@ def _argmax(in_dice):
809808

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

812-
wf.disconnect([
813-
(copy_xform_wm, inu_n4_final, [('wm_map', 'weight_image')]),
814-
]) # fmt:skip
815811
wf.connect([
816812
(inputnode, apply_wm_prior, [('in_mask', 'in_mask'),
817813
('wm_prior', 'op2')]),
@@ -823,6 +819,8 @@ def _argmax(in_dice):
823819
(copy_xform_wm, apply_wm_prior, [('wm_map', 'op1')]),
824820
(apply_wm_prior, inu_n4_final, [('out', 'weight_image')]),
825821
]) # fmt:skip
822+
else:
823+
wf.connect([(copy_xform_wm, inu_n4_final, [('wm_map', 'weight_image')])])
826824
return wf
827825

828826

@@ -926,7 +924,7 @@ def init_n4_only_wf(
926924
thr_brainmask = pe.Node(Binarize(thresh_low=2), name='binarize')
927925

928926
# INU correction
929-
inu_n4_final = pe.MapNode(
927+
inu_n4 = pe.MapNode(
930928
N4BiasFieldCorrection(
931929
dimension=3,
932930
save_bias=True,
@@ -937,31 +935,28 @@ def init_n4_only_wf(
937935
bspline_fitting_distance=200,
938936
),
939937
n_procs=omp_nthreads,
940-
name='inu_n4_final',
938+
name='inu_n4',
941939
iterfield=['input_image'],
942940
)
943941

944942
# Check ANTs version
945943
try:
946-
inu_n4_final.inputs.rescale_intensities = True
944+
inu_n4.inputs.rescale_intensities = True
947945
except ValueError:
948946
warn(
949947
"N4BiasFieldCorrection's --rescale-intensities option was added in ANTS 2.1.0 "
950-
f'({inu_n4_final.interface.version} found.) Please consider upgrading.',
948+
f'({inu_n4.interface.version} found.) Please consider upgrading.',
951949
UserWarning,
952950
stacklevel=1,
953951
)
954952

955953
wf.connect([
956-
(inputnode, inu_n4_final, [('in_files', 'input_image')]),
954+
(inputnode, inu_n4, [('in_files', 'input_image')]),
957955
(inputnode, thr_brainmask, [(('in_files', _pop), 'in_file')]),
958956
(thr_brainmask, outputnode, [('out_mask', 'out_mask')]),
959-
(inu_n4_final, outputnode, [('output_image', 'out_file'),
960-
('output_image', 'bias_corrected'),
961-
('bias_image', 'bias_image')]),
962957
]) # fmt:skip
963958

964-
# If atropos refine, do in4 twice
959+
# If atropos refine, n4 is run a second time
965960
if atropos_refine:
966961
atropos_model = atropos_model or list(ATROPOS_MODELS[bids_suffix].values())
967962
atropos_wf = init_atropos_wf(
@@ -971,14 +966,9 @@ def init_n4_only_wf(
971966
in_segmentation_model=atropos_model,
972967
)
973968

974-
wf.disconnect([
975-
(inu_n4_final, outputnode, [('output_image', 'out_file'),
976-
('output_image', 'bias_corrected'),
977-
('bias_image', 'bias_image')]),
978-
]) # fmt:skip
979969
wf.connect([
980970
(inputnode, atropos_wf, [('in_files', 'inputnode.in_files')]),
981-
(inu_n4_final, atropos_wf, [('output_image', 'inputnode.in_corrected')]),
971+
(inu_n4, atropos_wf, [('output_image', 'inputnode.in_corrected')]),
982972
(thr_brainmask, atropos_wf, [('out_mask', 'inputnode.in_mask')]),
983973
(atropos_wf, outputnode, [
984974
('outputnode.out_file', 'out_file'),
@@ -988,6 +978,12 @@ def init_n4_only_wf(
988978
('outputnode.out_tpms', 'out_tpms'),
989979
]),
990980
]) # fmt:skip
981+
else:
982+
wf.connect([
983+
(inu_n4, outputnode, [('output_image', 'out_file'),
984+
('output_image', 'bias_corrected'),
985+
('bias_image', 'bias_image')]),
986+
]) # fmt:skip
991987

992988
return wf
993989

0 commit comments

Comments
 (0)