source: sasview/sansmodels/src/sans/models/PorodModel.py @ eddff027

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 eddff027 was 1ed3834, checked in by Jae Cho <jhjcho@…>, 16 years ago

unit symbol Angst. back to A and re-organized model descriptions

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