source: sasview/sansmodels/src/sans/models/DisperseModel.py @ 831149e

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 831149e was ae3ce4e, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Moving sansmodels to trunk

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