Пример #1
0
    def test_clone_trait(self):
        """ Method to test trait clone from string description.
        """
        # Test first to build trait description from nipype traits and then
        # to instanciate the trait
        to_test_fields = {
            "timing_units": "traits.Enum(('secs', 'scans'))",
            "bases": ("traits.Dict(traits.Enum(('hrf', 'fourier', "
                      "'fourier_han', 'gamma', 'fir')), traits.Any())"),
            "mask_image": "traits.File(Undefined)",
            "microtime_onset": "traits.Float()",
            "mask_threshold": ("traits.Either(traits.Enum(('-Inf',)), "
                               "traits.Float())")
        }
        i = spm.Level1Design()
        for field, result in six.iteritems(to_test_fields):

            # Test to build the trait expression
            trait = i.inputs.trait(field)
            expression = build_expression(trait)
            self.assertEqual(expression, result)

            # Try to clone the trait
            trait = eval_trait(expression)()
            self.assertEqual(build_expression(trait), result)

        to_test_fields = {
            "contrasts": (
                "traits.List(traits.Either(traits.Tuple(traits.Str(), "
                "traits.Enum(('T',)), traits.List(traits.Str()), "
                "traits.List(traits.Float())), traits.Tuple(traits.Str(), "
                "traits.Enum(('T',)), traits.List(traits.Str()), "
                "traits.List(traits.Float()), traits.List(traits.Float())), "
                "traits.Tuple(traits.Str(), traits.Enum(('F',)), "
                "traits.List(traits.Either(traits.Tuple(traits.Str(), "
                "traits.Enum(('T',)), traits.List(traits.Str()), "
                "traits.List(traits.Float())), traits.Tuple(traits.Str(), "
                "traits.Enum(('T',)), traits.List(traits.Str()), "
                "traits.List(traits.Float()), traits.List(traits.Float())"
                "))))))"),
            "use_derivs": "traits.Bool()"
        }
        i = spm.EstimateContrast()
        for field, result in six.iteritems(to_test_fields):

            # Test to build the trait expression
            trait = i.inputs.trait(field)
            expression = build_expression(trait)
            self.assertEqual(expression, result)

            # Try to clone the trait
            trait = eval_trait(expression)()
            self.assertEqual(build_expression(trait), result)

        # Test to clone some traits
        trait_description = ["Float", "Int"]
        handler = clone_trait(trait_description)
        trait = handler.as_ctrait()
        self.assertEqual(trait_description, trait_ids(trait))
Пример #2
0
    def clone_nipype_trait(nipype_trait):
        """ Create a new trait (cloned and converrted if necessary)
        from a nipype trait.

        Parameters
        ----------
        nipype_trait: trait
            the nipype trait we want to clone and convert if necessary.

        Returns
        -------
        process_trait: trait
            the cloned/converted trait that will be used in the process
            instance.
        """
        # Clone the nipype trait
        expression = build_expression(nipype_trait)
        process_trait = eval_trait(expression)

        # Copy some information from the nipype trait
        process_trait.desc = nipype_trait.desc
        process_trait.optional = not nipype_trait.mandatory
        process_trait._metadata = {}
        
        return process_trait
Пример #3
0
    def clone_nipype_trait(nipype_trait):
        """ Create a new trait (cloned and converrted if necessary)
        from a nipype trait.

        Parameters
        ----------
        nipype_trait: trait
            the nipype trait we want to clone and convert if necessary.

        Returns
        -------
        process_trait: trait
            the cloned/converted trait that will be used in the process
            instance.
        """
        # Clone the nipype trait
        expression = build_expression(nipype_trait)
        process_trait = eval_trait(expression)

        # Copy some information from the nipype trait
        process_trait.desc = nipype_trait.desc
        process_trait.optional = not nipype_trait.mandatory
        process_trait._metadata = {}

        return process_trait
Пример #4
0
    def test_clone_trait(self):
        """ Method to test trait clone from string description.
        """
        # Test first to build trait description from nipype traits and then
        # to instanciate the trait
        to_test_fields = {
            "timing_units":
            "traits.Enum(('secs', 'scans'))",
            "bases": ("traits.Dict(traits.Enum(('hrf', 'fourier', "
                      "'fourier_han', 'gamma', 'fir')), traits.Any())"),
            "mask_image":
            "traits.File(Undefined)",
            "microtime_onset":
            "traits.Float()",
            "mask_threshold": ("traits.Either(traits.Enum(('-Inf',)), "
                               "traits.Float())")
        }
        i = spm.Level1Design()
        for field, result in six.iteritems(to_test_fields):

            # Test to build the trait expression
            trait = i.inputs.trait(field)
            expression = build_expression(trait)
            self.assertEqual(expression, result)

            # Try to clone the trait
            trait = eval_trait(expression)()
            self.assertEqual(build_expression(trait), result)

        to_test_fields = {
            "contrasts":
            ("traits.List(traits.Either(traits.Tuple(traits.Str(), "
             "traits.Enum(('T',)), traits.List(traits.Str()), "
             "traits.List(traits.Float())), traits.Tuple(traits.Str(), "
             "traits.Enum(('T',)), traits.List(traits.Str()), "
             "traits.List(traits.Float()), traits.List(traits.Float())), "
             "traits.Tuple(traits.Str(), traits.Enum(('F',)), "
             "traits.List(traits.Either(traits.Tuple(traits.Str(), "
             "traits.Enum(('T',)), traits.List(traits.Str()), "
             "traits.List(traits.Float())), traits.Tuple(traits.Str(), "
             "traits.Enum(('T',)), traits.List(traits.Str()), "
             "traits.List(traits.Float()), traits.List(traits.Float())"
             "))))))"),
            "use_derivs":
            "traits.Bool()"
        }
        i = spm.EstimateContrast()
        for field, result in six.iteritems(to_test_fields):

            # Test to build the trait expression
            trait = i.inputs.trait(field)
            expression = build_expression(trait)
            self.assertEqual(expression, result)

            # Try to clone the trait
            trait = eval_trait(expression)()
            self.assertEqual(build_expression(trait), result)

        # Test to clone some traits
        trait_description = ["Float", "Int"]
        handler = clone_trait(trait_description)
        trait = handler.as_ctrait()
        self.assertEqual(trait_description, trait_ids(trait))