source: sasview/src/sas/models/TwoPowerLawModel.py @ c81f9b6

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 c81f9b6 was ac7be54, checked in by Paul Kienzle <pkienzle@…>, 10 years ago

fix sphinx errors in api manual

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