source: sasview/sansmodels/src/sans/models/TwoPowerLawModel.py @ 6306f2f

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 6306f2f was 18695bf, checked in by Jae Cho <jhjcho@…>, 14 years ago

replaced math.pow to numpy.power since math.pow is not working with list of x values(remember we use the list in fitting for speed)

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[8f20419d]1#!/usr/bin/env python
2"""
3Provide I(q) = A*pow(qval,-1.0*m1) for q<=qc
4    =scale*pow(qval,-1.0*m2) for q>qc
5TwoPowerLaw function as a BaseComponent model
6"""
7
8from sans.models.BaseComponent import BaseComponent
[18695bf]9from numpy import power
[8f20419d]10
11class TwoPowerLawModel(BaseComponent):
12    """
13    Class that evaluates a TwoPowerLawModel.
14
15    I(q) = coef_A*pow(qval,-1.0*power1) for q<=qc
16        =C*pow(qval,-1.0*power2) for q>qc
17    where C=coef_A*pow(qc,-1.0*power1)/pow(qc,-1.0*power2).
18    List of default parameters:
19     coef_A = coefficient
20     power1 = (-) Power @ low Q
21     power2 = (-) Power @ high Q
22     qc = crossover Q-value
23     background = incoherent background
24    """
25       
26    def __init__(self):
27        """ Initialization """
28       
29        # Initialize BaseComponent first, then sphere
30        BaseComponent.__init__(self)
31       
32        ## Name of the model
33        self.name = "TwoPowerLaw"
34        self.description="""I(q) = coef_A*pow(qval,-1.0*power1) for q<=qc
35            =C*pow(qval,-1.0*power2) for q>qc
36            where C=coef_A*pow(qc,-1.0*power1)/pow(qc,-1.0*power2).
37             List of default parameters:
38             coef_A = coefficient
39             power1 = (-) Power @ low Q
40             power2 = (-) Power @ high Q
41             qc = crossover Q-value
42             background = incoherent background
43        """
44        ## Define parameters
45        self.params = {}
46        self.params['coef_A']  = 1.0
47        self.params['power1']     = 1.0
48        self.params['power2']  = 4.0
49        self.params['qc']     = 0.04
50        self.params['background']     = 0.0
51        ## Parameter details [units, min, max]
52        self.details = {}
53        self.details['coef_A'] = ['', None, None]
54        self.details['power1'] =  ['', None, None]
55        self.details['power2']  =  ['', None, None]
56        self.details['qc']  =   ['1/A', None, None]
57        self.details['background']   =  ['[1/cm]', None, None]
58
59        #list of parameter that cannot be fitted
60        self.fixed= [] 
61    def _twopowerlaw(self, x):
62        """
63        Model definition
64        """
65        qc= self.params['qc']
66        if(x<=qc):
[18695bf]67            inten = self.params['coef_A']*power(x,-1.0*self.params['power1'])
[8f20419d]68        else:
[18695bf]69            scale = self.params['coef_A']*power(qc,-1.0*self.params['power1']) \
70                                    / power(qc,-1.0*self.params['power2'])
71            inten = scale*power(x,-1.0*self.params['power2'])
[8f20419d]72        inten += self.params['background']
73
74        return inten 
75   
76    def run(self, x = 0.0):
77        """ Evaluate the model
78            @param x: input q-value (float or [float, float] as [r, theta])
79            @return: (guinier value)
80        """
81        if x.__class__.__name__ == 'list':
82            return self._twopowerlaw(x[0])
83        elif x.__class__.__name__ == 'tuple':
84            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
85        else:
86            return self._twopowerlaw(x)
87   
88    def runXY(self, x = 0.0):
89        """ Evaluate the model
90            @param x: input q-value (float or [float, float] as [qx, qy])
91            @return: guinier value
92        """
93        if x.__class__.__name__ == 'list':
94            q = math.sqrt(x[0]**2 + x[1]**2)
95            return self._twopowerlaw(q)
96        elif x.__class__.__name__ == 'tuple':
97            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
98        else:
99            return self._twopowerlaw(x)
Note: See TracBrowser for help on using the repository browser.