Ejemplo n.º 1
0
    def __init__(self):
        """ Initialize ExtractReferenceB0Image class
        """
        # Inheritance
        super(ExtractReferenceB0Image, self).__init__()

        # Inputs
        self.add_trait(
            "dw_image",
            File(_Undefined(),
                 optional=False,
                 output=False,
                 exists=True,
                 desc="an existing diffusion weighted image"))
        self.add_trait(
            "bvals",
            File(_Undefined(),
                 optional=False,
                 output=False,
                 exists=True,
                 desc="the the diffusion b-values"))
        self.add_trait(
            "specified_index_of_ref_image",
            Int(_Undefined(),
                optional=True,
                output=False,
                desc="index of the reference b=0 volume"))

        # Outputs
        self.add_trait(
            "index_of_ref_image",
            Int(_Undefined(),
                output=True,
                desc="index of the reference b=0 volume"))
Ejemplo n.º 2
0
    def __init__(self):
        """ Initialize ExtractReferenceB0Image class
        """
        # Inheritance
        super(ExtractReferenceB0Image, self).__init__()

        # Inputs
        self.add_trait("dw_image", File(
            _Undefined(),
            optional=False,
            output=False,
            exists=True,
            desc="an existing diffusion weighted image"))
        self.add_trait("bvals", File(
            _Undefined(),
            optional=False,
            output=False,
            exists=True,
            desc="the the diffusion b-values"))
        self.add_trait("specified_index_of_ref_image", Int(
            _Undefined(),
            optional=True,
            output=False,
            desc="index of the reference b=0 volume"))

        # Outputs
        self.add_trait("index_of_ref_image", Int(
            _Undefined(),
            output=True,
            desc="index of the reference b=0 volume"))
Ejemplo n.º 3
0
    def pipeline_definition(self):
        """ Diffusion BET pipeline definition
        """

        # Create processes
        self.add_process("extractor",
                         "caps.diffusion_preproc.bet.ExtractReferenceB0Image")
        self.add_process("spliter",
                         "nipype.interfaces.fsl.Split",
                         make_optional=["terminal_output", "dimension"])
        self.add_process("picker",
                         "caps.utils.misc.Select")
        self.add_process("bet",
                         "caps.utils.bet.BET")

        # Export Inputs (automatic export of BET parameters)
        self.export_parameter("extractor", "dw_image")
        self.export_parameter("extractor", "bvals")
        self.export_parameter("extractor", "specified_index_of_ref_image")

        # Link inputs
        self.add_link("dw_image->spliter.in_file")

        # Link b0_extractor
        self.add_link("extractor.index_of_ref_image->picker.index")

        # Link spliter
        self.add_link("spliter._out_files->picker.inlist")

        # Link picker
        self.add_link("picker.outelement->bet.input_file")

        # Export outputs
        self.export_parameter("extractor", "index_of_ref_image")
        self.export_parameter("spliter", "_out_files",
                              pipeline_parameter="splited_images")
        self.export_parameter("picker", "outelement",
                              pipeline_parameter="ref_image")

        # dBET algorithm parameters
        self.dw_image = _Undefined()
        self.bvals = _Undefined()
        self.nodes["spliter"].process.dimension = "t"
Ejemplo n.º 4
0
    def pipeline_definition(self):
        """ Diffusion BET pipeline definition
        """

        # Create processes
        self.add_process("extractor",
                         "caps.diffusion_preproc.bet.ExtractReferenceB0Image")
        self.add_process("spliter",
                         "nipype.interfaces.fsl.Split",
                         make_optional=["terminal_output", "dimension"])
        self.add_process("picker", "caps.utils.misc.Select")
        self.add_process("bet", "caps.utils.bet.BET")

        # Export Inputs (automatic export of BET parameters)
        self.export_parameter("extractor", "dw_image")
        self.export_parameter("extractor", "bvals")
        self.export_parameter("extractor", "specified_index_of_ref_image")

        # Link inputs
        self.add_link("dw_image->spliter.in_file")

        # Link b0_extractor
        self.add_link("extractor.index_of_ref_image->picker.index")

        # Link spliter
        self.add_link("spliter._out_files->picker.inlist")

        # Link picker
        self.add_link("picker.outelement->bet.input_file")

        # Export outputs
        self.export_parameter("extractor", "index_of_ref_image")
        self.export_parameter("spliter",
                              "_out_files",
                              pipeline_parameter="splited_images")
        self.export_parameter("picker",
                              "outelement",
                              pipeline_parameter="ref_image")

        # dBET algorithm parameters
        self.dw_image = _Undefined()
        self.bvals = _Undefined()
        self.nodes["spliter"].process.dimension = "t"
Ejemplo n.º 5
0
def falsetoundefined(arr):
    """
    replace none with undefined
    """
    from traits.trait_base import _Undefined

    ret = []
    for val in arr:
        if not val:
            ret.append(_Undefined())
        else:
            ret.append(val)
    return ret
Ejemplo n.º 6
0
def firsttrait(obj):
    """
    get first element from iterable, or undefined

    :param obj: input list

    """
    try:
        return next(iter(obj))
    except TypeError:
        pass
    except StopIteration:
        pass
    from traits.trait_base import _Undefined

    return _Undefined()
Ejemplo n.º 7
0
    def set_parameter(self, name, value):
        """ Method to set a process instance trait value.

        For File and Directory traits the None value is replaced by the
        special _Undefined trait value.

        Parameters
        ----------
        name: str (mandatory)
            the trait name we want to modify
        value: object (mandatory)
            the trait value we want to set
        """
        # The None trait value is _Undefined, do the replacement
        if value is None:
            value = _Undefined()

        # Set the new trait value
        setattr(self, name, value)
Ejemplo n.º 8
0
    def set_parameter(self, name, value):
        """ Method to set a process instance trait value.

        For File and Directory traits the None value is replaced by the
        special _Undefined trait value.

        Parameters
        ----------
        name: str (mandatory)
            the trait name we want to modify
        value: object (mandatory)
            the trait value we want to set
        """
        # The None trait value is _Undefined, do the replacement
        if value is None:
            value = _Undefined()

        # Set the new trait value
        setattr(self, name, value)
Ejemplo n.º 9
0
TraitError: The 'vertical_gradient' trait of a BetInputSpec instance must be a float, but a value of <undefined> <class 'nipype.interfaces.traits._Undefined'> was specified.

So... in order to keep the same type but add the missing method, I
monkey patched.
"""


def length(self):
    return 0

##########################################################################
# Apply monkeypatch here
_Undefined.__len__ = length
##########################################################################

Undefined = _Undefined()


def isdefined(object):
    return not isinstance(object, _Undefined)


def has_metadata(trait, metadata, value=None, recursive=True):
    '''
    Checks if a given trait has a metadata (and optionally if it is set to particular value)
    '''
    count = 0
    if hasattr(trait, "_metadata") and metadata in list(trait._metadata.keys()) and (trait._metadata[metadata] == value or value is None):
        count += 1
    if recursive:
        if hasattr(trait, 'inner_traits'):
Ejemplo n.º 10
0
So... in order to keep the same type but add the missing method, I
monkey patched.
"""


def length(self):
    return 0


##########################################################################
# Apply monkeypatch here
_Undefined.__len__ = length
##########################################################################

Undefined = _Undefined()


def isdefined(object):
    return not isinstance(object, _Undefined)


def has_metadata(trait, metadata, value=None, recursive=True):
    '''
    Checks if a given trait has a metadata (and optionally if it is set to particular value)
    '''
    count = 0
    if hasattr(trait, "_metadata") and metadata in trait._metadata.keys() and (
            trait._metadata[metadata] == value or value == None):
        count += 1
    if recursive: