Example #1
0
    def initByName(self, name, *args, **kwargs):
        """
        intialise composite function of named type.
        E.g. "ProductFunction"
        This function would be protected in c++
        and should not be called directly except
        by :meth:`__init__` functions of this class
        and subclasses.

        :param name:   name of class calling this.
        :param args:   names of functions in composite function
        :param kwargs: any parameters or attributes that must be passed to the
                       composite function itself.
        """
        if len(args) == 1 and  not isinstance(args[0], FunctionWrapper):
            # We have a composite function to wrap
            self.fun = args[0]
        else:
            self.fun = FunctionFactory.createCompositeFunction(name)

            # Add the functions, checking for Composite & Product functions
            for a in args:
                if not isinstance(a, int):
                    if isinstance(a, CompositeFunctionWrapper):
                        if self.pureAddition:
                            self.pureAddition = a.pureAddition
                        if self.pureMultiplication:
                            self.pureMultiplication = a.pureMultiplication
                    functionToAdd = FunctionFactory.createInitialized(a.fun.__str__())
                    self.fun.add(functionToAdd)
        self.init_paramgeters_and_attributes(**kwargs)
Example #2
0
    def initByName(self, name, *args, **kwargs):
        """
        intialise composite function of named type.
        E.g. "ProductFunction"
        This function would be protected in c++
        and should not be called directly except
        by :meth:`__init__` functions of this class
        and subclasses.

        :param name:   name of class calling this.
        :param args:   names of functions in composite function
        :param kwargs: any parameters or attributes that must be passed to the
                       composite function itself.
        """
        if len(args) == 1 and not isinstance(args[0], FunctionWrapper):
            # We have a composite function to wrap
            self.fun = args[0]
        else:
            self.fun = FunctionFactory.createCompositeFunction(name)

            # Add the functions, checking for Composite & Product functions
            for a in args:
                if not isinstance(a, int):
                    if isinstance(a, CompositeFunctionWrapper):
                        if self.pureAddition:
                            self.pureAddition = a.pureAddition
                        if self.pureMultiplication:
                            self.pureMultiplication = a.pureMultiplication
                    functionToAdd = FunctionFactory.createInitialized(
                        a.fun.__str__())
                    self.fun.add(functionToAdd)
        self.init_paramgeters_and_attributes(**kwargs)
    def setUpClass(cls):
        delta = 0.33
        x = np.linspace(0., 15., 100)
        x_offset = np.linspace(delta / 2, 15. + delta / 2, 100)
        x_offset_neg = np.linspace(-delta / 2, 15. - delta / 2, 100)

        testFunction = GausOsc(Frequency=1.5, A=0.22)
        y1 = testFunction(x_offset_neg)
        y2 = testFunction(x_offset)
        y = y1 / 2 + y2 / 2
        ws = CreateWorkspace(x, y)

        convolution = FunctionFactory.createCompositeFunction('Convolution')
        innerFunction = FunctionFactory.createInitialized('name=GausOsc,A=0.2,Sigma=0.2,Frequency=1,Phi=0')
        deltaFunctions = FunctionFactory.createInitialized(
            '(name=DeltaFunction,Height=0.5,Centre={},ties=(Height=0.5,Centre={});name=DeltaFunction,Height=0.5,'
            'Centre={},ties=(Height=0.5,Centre={}))'.format(
                -delta / 2, -delta / 2, delta / 2, delta / 2))
        convolution.setAttributeValue('FixResolution', False)
        convolution.add(innerFunction)
        convolution.add(deltaFunctions)

        MultiDomainSingleFunction = FunctionFactory.createInitializedMultiDomainFunction(
            'name=GausOsc,A=0.2,Sigma=0.2,Frequency=1,Phi=0', 2)
        MultiDomainConvolutionFunction = FunctionFactory.createInitializedMultiDomainFunction(str(convolution), 2)

        DoublePulseFit(Function=MultiDomainSingleFunction, InputWorkspace=ws, InputWorkspace_1=ws, CreateOutput=True,
                       PulseOffset=delta, StartX=0.0, EndX=15.0, Output='DoublePulseFit', MaxIterations=1)
        Fit(Function=MultiDomainConvolutionFunction, InputWorkspace=ws, InputWorkspace_1=ws, CreateOutput=True,
            StartX=0.0, EndX=15.0, Output='Fit', MaxIterations=1)