source: sasview/src/sas/models/DisperseModel.py @ f66d9d1

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f66d9d1 was fd5ac0d, checked in by krzywon, 10 years ago

I have completed the removal of all SANS references.
I will build, run, and run all unit tests before pushing.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"""
2    Wrapper for the Disperser class extension
3"""
4from sas.models.BaseComponent import BaseComponent
5from sas_extension.c_models import Disperser
6   
7class DisperseModel(Disperser, BaseComponent):
8    """
9    Wrapper class for the Disperser extension
10    Python class that takes a model and averages its output
11    for a distribution of its parameters.
12     
13    The parameters to be varied are specified at instantiation time.
14    The distributions are Gaussian, with std deviations specified for
15    each parameter at instantiation time.
16   
17    Example: ::
18   
19        cyl = CylinderModel()
20        disp = DisperseModel(cyl, ['cyl_phi'], [0.3])
21        disp.run([0.01, 1.57])
22       
23    """
24       
25    def __init__(self, model, paramList, sigmaList):
26        """
27        Initialization
28       
29        :param model: Model to disperse [BaseComponent]
30        :param paramList: list of parameters to disperse [List of strings]
31        :param sigmaList: list of std deviations for Gaussian dispersion
32                    [List of floats]
33       
34        """
35       
36        # Initialize BaseComponent first, then sphere
37        BaseComponent.__init__(self)
38        Disperser.__init__(self, model, paramList, sigmaList)
39        ## Name of the model
40        self.name = model.name
41        ## Keep track of the underlying model
42        self.model = model
43        self.description =''
44        #list of parameter that cannot be fitted
45        self.fixed = []
46       
47    def clone(self):
48        """ Return a identical copy of self """
49        return DisperseModel(self.model, self.params['paramList'], 
50                             self.params['sigmaList']) 
51   
52    def setParam(self, name, value):
53        """
54            Set a parameter value
55            :param name: parameter name
56        """
57        if name.lower() in self.params:
58            BaseComponent.setParam(self, name, value)
59        else:
60            self.model.setParam(name, value)
61   
62    def getParam(self, name):
63        """
64            Get the value of the given parameter
65            :param name: parameter name
66        """
67        if name.lower() in self.params:
68            return BaseComponent.getParam(self, name)
69        else:
70            return self.model.getParam(name)
71   
72    def run(self, x = 0.0):
73        """
74            Evaluate the model
75            :param x: input q, or [q,phi]
76            :return: scattering function P(q)
77        """
78        return Disperser.run(self, x)
79           
80    def runXY(self, x = 0.0):
81        """
82            Evaluate the model
83            :param x: input q, or [q,phi]
84            :return: scattering function P(q)
85        """
86        return Disperser.runXY(self, x)
87   
88# End of file
Note: See TracBrowser for help on using the repository browser.