source: sasview/src/sas/models/PorodModel.py @ 686fd10

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 686fd10 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1"""
2    Provide I(q) = C/q^4,
3    Porod function as a BaseComponent model
4"""
5from sas.models.BaseComponent import BaseComponent
6import math
7
8class PorodModel(BaseComponent):
9    """
10        Class that evaluates a Porod model.
11        I(q) = scale/q^4 +background
12    """
13       
14    def __init__(self):
15        """ Initialization """
16       
17        # Initialize BaseComponent first, then sphere
18        BaseComponent.__init__(self)
19       
20        ## Name of the model
21        self.name = "PorodModel"
22
23        ## Define parameters
24        self.params = {}
25        self.params['scale'] = 1.0
26        self.params['background'] = 0.0
27        self.description = """The Porod model.
28        I(q) = scale/q^4 +background"""
29
30        ## Parameter details [units, min, max]
31        self.details = {}
32        self.details['scale']      = ['[1/(cm A^4)]', None, None]
33        self.details['background'] = ['[1/cm]', None, None]
34        #list of parameter that cannot be fitted
35        self.fixed = []
36               
37    def _porod(self, x):
38        """
39            Evaluate Porod function
40            :param x: q-value
41        """
42        return self.params['scale']/x**4.0 + self.params['background']
43   
44    def run(self, x = 0.0):
45        """ Evaluate the model
46            @param x: input q-value (float or [float, float] as [r, theta])
47            @return: (porod value)
48        """
49        if x.__class__.__name__ == 'list':
50            return self._porod(x[0])
51        elif x.__class__.__name__ == 'tuple':
52            raise ValueError, "Tuples are not allowed as input to models"
53        else:
54            return self._porod(x)
55   
56    def runXY(self, x = 0.0):
57        """ Evaluate the model
58            @param x: input q-value (float or [float, float] as [qx, qy])
59            @return: porod value
60        """
61        if x.__class__.__name__ == 'list':
62            q = math.sqrt(x[0]**2 + x[1]**2)
63            return self._porod(q)
64        elif x.__class__.__name__ == 'tuple':
65            raise ValueError, "Tuples are not allowed as input to models"
66        else:
67            return self._porod(x)
Note: See TracBrowser for help on using the repository browser.