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

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 a55fac1 was a55fac1, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Modified 2D non-shape models to be the same as 1D when not defined otherwise

  • Property mode set to 100644
File size: 1.9 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       
31
32        ## Parameter details [units, min, max]
33        self.details = {}
34        self.details['scale']      = ['', None, None]
35        self.details['background'] = ['', None, None]
36     
37               
38    def _porod(self, x):
39        return self.params['scale']/x**4.0 + self.params['background']
40   
41    def run(self, x = 0.0):
42        """ Evaluate the model
43            @param x: input q-value (float or [float, float] as [r, theta])
44            @return: (porod value)
45        """
46        if x.__class__.__name__ == 'list':
47            return self._porod(x[0])
48        elif x.__class__.__name__ == 'tuple':
49            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
50        else:
51            return self._porod(x)
52   
53    def runXY(self, x = 0.0):
54        """ Evaluate the model
55            @param x: input q-value (float or [float, float] as [qx, qy])
56            @return: porod value
57        """
58        if x.__class__.__name__ == 'list':
59            q = math.sqrt(x[0]**2 + x[1]**2)
60            return self._porod(q)
61        elif x.__class__.__name__ == 'tuple':
62            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
63        else:
64            return self._porod(x)
Note: See TracBrowser for help on using the repository browser.