source: sasview/sansmodels/src/sans/models/TwoPowerLawModel.py @ 5eb663a

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 5eb663a was 3fc01c5, checked in by Jae Cho <jhjcho@…>, 12 years ago

fixing pylint warnings

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