def create(self): trainT1s = Node(interface=Select(), name='trainT1s') trainT2s = Node(interface=Select(), name='trainT2s') trainLabels = Node(interface=Select(), name='trainLabels') testT1s = Node(interface=Select(), name='testT1s') #intensityImages = Node(interface=Merge(2), name='intensityImages') jointFusion = Node(interface=JointFusion(), name='jointFusion') jointFusion.inputs.num_threads = -1 jointFusion.inputs.dimension = 3 jointFusion.inputs.modalities = 1 #TODO: verify 2 for T1/T2 jointFusion.inputs.method = "Joint[0.1,2]" # this does not work jointFusion.inputs.output_label_image = 'fusion_neuro2012_20.nii.gz' outputs = Node( interface=IdentityInterface(fields=['output_label_image']), run_without_submitting=True, name='outputspec') self.connect([ # Don't worry about T2s now per Regina # (trainT1s, intensityImages, [('out', 'in1')]), # (trainT2s, intensityImages, [('out', 'in2')]), (testT1s, jointFusion, [('out', 'target_image')]), (trainT1s, jointFusion, [('out', 'warped_intensity_images')]), (trainLabels, jointFusion, [('out', 'warped_label_images')]), (jointFusion, outputs, [('output_label_image', 'output_label_image')]), ])
def test_JointFusion_outputs(): output_map = dict(output_label_image=dict(), ) outputs = JointFusion.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def create(self): sampleT1s = Node(interface=Select(), name='sampleT1s') sampleT2s = Node(interface=Select(), name='sampleT2s') sampleLabels = Node(interface=Select(), name='sampleLabels') testT1s = Node(interface=Select(), name='testT1s') testT2s = Node(interface=Select(), name='testT2s') testLabels = Node(interface=Select(), name='testLabels') intensityImages = Node(interface=Merge(2), name='intensityImages') jointFusion = Node(interface=JointFusion(), name='jointFusion') jointFusion.inputs.dimension = 3 jointFusion.inputs.modalities = 1 #TODO: verify 2 for T1/T2 jointFusion.inputs.method = 'Joint[0.1, 2]' jointFusion.inputs.output_label_image = 'fusion_neuro2012_20.nii.gz' outputs = Node( interface=IdentityInterface(fields=['output_label_image']), run_without_submitting=True, name='outputspec') self.connect([ # Don't worry about T2s now per Regina # (sampleT1s, intensityImages, [('out', 'in1')]), # (sampleT2s, intensityImages, [('out', 'in2')]), # (intensityImages, jointFusion, [('out', 'warped_intensity_images')]), (sampleT1s, jointFusion, [('out', 'warped_intensity_images')]), #END: per Regina (sampleLabels, jointFusion, [('out', 'warped_label_images')]), (jointFusion, outputs, [('output_label_image', 'output_label_image')]), ])
def create(self): """ This function... :param self: :return: """ trainT1s = Node(interface=Select(), name="trainT1s") trainT2s = Node(interface=Select(), name="trainT2s") trainLabels = Node(interface=Select(), name="trainLabels") testT1s = Node(interface=Select(), name="testT1s") # intensityImages = Node(interface=Merge(2), name='intensityImages') jointFusion = Node(interface=JointFusion(), name="jointFusion") jointFusion.inputs.num_threads = -1 jointFusion.inputs.dimension = 3 jointFusion.inputs.modalities = 1 # TODO: verify 2 for T1/T2 jointFusion.inputs.method = "Joint[0.1,2]" # this does not work jointFusion.inputs.output_label_image = "fusion_neuro2012_20.nii.gz" outputs = Node( interface=IdentityInterface(fields=["output_label_image"]), run_without_submitting=True, name="outputspec", ) self.connect( [ # Don't worry about T2s now per Regina # (trainT1s, intensityImages, [('out', 'in1')]), # (trainT2s, intensityImages, [('out', 'in2')]), (testT1s, jointFusion, [("out", "target_image")]), (trainT1s, jointFusion, [("out", "warped_intensity_images")]), (trainLabels, jointFusion, [("out", "warped_label_images")]), (jointFusion, outputs, [("output_label_image", "output_label_image")]), ] )
def test_JointFusion_inputs(): input_map = dict( alpha=dict( requires=['method'], usedefault=True, ), args=dict(argstr='%s', ), atlas_group_id=dict(argstr='-gp %d...', ), atlas_group_weights=dict(argstr='-gpw %d...', ), beta=dict( requires=['method'], usedefault=True, ), dimension=dict( argstr='%d', mandatory=True, position=0, usedefault=True, ), environ=dict( nohash=True, usedefault=True, ), exclusion_region=dict(argstr='-x %s', ), ignore_exception=dict( nohash=True, usedefault=True, ), method=dict( argstr='-m %s', usedefault=True, ), modalities=dict( argstr='%d', mandatory=True, position=1, ), num_threads=dict( nohash=True, usedefault=True, ), output_label_image=dict( argstr='%s', mandatory=True, name_template='%s', output_name='output_label_image', position=-1, ), patch_radius=dict( argstr='-rp %s', maxlen=3, minlen=3, ), search_radius=dict( argstr='-rs %s', maxlen=3, minlen=3, ), target_image=dict( argstr='-tg %s...', mandatory=True, ), terminal_output=dict(nohash=True, ), warped_intensity_images=dict( argstr='-g %s...', mandatory=True, ), warped_label_images=dict( argstr='-l %s...', mandatory=True, ), ) inputs = JointFusion.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
def init_anat_seg_wf( age_months=None, anat_modality="T1w", template_dir=None, sloppy=False, omp_nthreads=1, name="anat_seg_wf", ): """ Calculate brain tissue segmentations from either: A) a collection of manually segmented templates B) FSL's FAST """ if anat_modality != "T1w": raise NotImplementedError( "Only T1w images are currently accepted for the segmentation workflow." ) wf = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=["anat_brain"]), name="inputnode") outputnode = pe.Node( niu.IdentityInterface(fields=["anat_aseg", "anat_dseg", "anat_tpms"]), name="outputnode", ) # Coerce segmentation labels to BIDS lut_anat_dseg = pe.Node(niu.Function(function=_apply_bids_lut), name="lut_anat_dseg") if template_dir is None: # Use FSL FAST for segmentations anat_dseg = pe.Node(fsl.FAST(segments=True, no_bias=True, probability_maps=True), name='anat_dseg', mem_gb=3) lut_anat_dseg.inputs.lut = (0, 3, 1, 2 ) # Maps: 0 -> 0, 3 -> 1, 1 -> 2, 2 -> 3. fast2bids = pe.Node(niu.Function(function=_probseg_fast2bids), name="fast2bids", run_without_submitting=True) wf.connect([ (inputnode, anat_dseg, [ ('anat_brain', 'in_files'), ]), (anat_dseg, lut_anat_dseg, [ ('partial_volume_map', 'in_dseg'), ]), (lut_anat_dseg, outputnode, [ ('out', 'anat_dseg'), ]), (anat_dseg, fast2bids, [ ('partial_volume_files', 'inlist'), ]), (fast2bids, outputnode, [ ('out', 'anat_tpms'), ]), ]) return wf # Otherwise, register to templates and run ANTs JointFusion lut_anat_dseg.inputs.lut = _aseg_to_three() tmpl_anats, tmpl_segs = _parse_segmentation_atlases( anat_modality, template_dir) # register to templates ants_params = "testing" if sloppy else "precise" # Register to each subject space norm = pe.MapNode( Registration(from_file=pkgr_fn( "niworkflows.data", f"antsBrainExtraction_{ants_params}.json")), name="norm", iterfield=["moving_image"], n_procs=omp_nthreads, mem_gb=DEFAULT_MEMORY_MIN_GB, ) norm.inputs.moving_image = tmpl_anats norm.inputs.float = True apply_atlas = pe.MapNode( ApplyTransforms( dimension=3, interpolation="NearestNeighbor", float=True, ), iterfield=["transforms", "input_image"], name="apply_atlas", ) apply_atlas.inputs.input_image = tmpl_anats apply_seg = pe.MapNode( ApplyTransforms(dimension=3, interpolation="MultiLabel"), # NearestNeighbor? name="apply_seg", iterfield=["transforms", "input_image"], ) apply_seg.inputs.input_image = tmpl_segs jointfusion = pe.Node( JointFusion( dimension=3, out_label_fusion="fusion_labels.nii.gz", num_threads=omp_nthreads, ), name="jointfusion", ) jf_label = pe.Node(niu.Function(function=_to_dtype), name="jf_label") # split each tissue into individual masks split_seg = pe.Node(niu.Function(function=_split_segments), name="split_seg") to_list = pe.Node(niu.Function(function=_to_list), name='to_list') # fmt: off wf.connect([ (inputnode, norm, [('anat_brain', 'fixed_image')]), (norm, apply_atlas, [('forward_transforms', 'transforms')]), (inputnode, apply_atlas, [('anat_brain', 'reference_image')]), (norm, apply_seg, [('forward_transforms', 'transforms')]), (inputnode, apply_seg, [('anat_brain', 'reference_image')]), (inputnode, to_list, [('anat_brain', 'in_file')]), (to_list, jointfusion, [('out', 'target_image')]), (apply_atlas, jointfusion, [('output_image', 'atlas_image')]), (apply_seg, jointfusion, [('output_image', 'atlas_segmentation_image') ]), (jointfusion, jf_label, [('out_label_fusion', 'in_file')]), (jf_label, outputnode, [('out', 'anat_aseg')]), (jf_label, lut_anat_dseg, [('out', 'in_dseg')]), (lut_anat_dseg, outputnode, [('out', 'anat_dseg')]), (lut_anat_dseg, split_seg, [('out', 'in_file')]), (split_seg, outputnode, [('out', 'anat_tpms')]), ]) # fmt: on return wf
def test_JointFusion_inputs(): input_map = dict(alpha=dict(requires=['method'], usedefault=True, ), args=dict(argstr='%s', ), atlas_group_id=dict(argstr='-gp %d...', ), atlas_group_weights=dict(argstr='-gpw %d...', ), beta=dict(requires=['method'], usedefault=True, ), dimension=dict(argstr='%d', mandatory=True, position=0, usedefault=True, ), environ=dict(nohash=True, usedefault=True, ), exclusion_region=dict(argstr='-x %s', ), ignore_exception=dict(nohash=True, usedefault=True, ), method=dict(argstr='-m %s', usedefault=True, ), modalities=dict(argstr='%d', mandatory=True, position=1, ), num_threads=dict(nohash=True, usedefault=True, ), output_label_image=dict(argstr='%s', mandatory=True, name_template='%s', output_name='output_label_image', position=-1, ), patch_radius=dict(argstr='-rp %s', maxlen=3, minlen=3, ), search_radius=dict(argstr='-rs %s', maxlen=3, minlen=3, ), target_image=dict(argstr='-tg %s...', mandatory=True, ), terminal_output=dict(nohash=True, ), warped_intensity_images=dict(argstr='-g %s...', mandatory=True, ), warped_label_images=dict(argstr='-l %s...', mandatory=True, ), ) inputs = JointFusion.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value