source: sasview/src/sas/models/TwoLorentzianModel.py @ 06dfd39

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 06dfd39 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#!/usr/bin/env python
2"""
3TwoLorentzianModel function as a BaseComponent model
4"""
5
6from sas.models.BaseComponent import BaseComponent
7from numpy import power
8import math
9
10class TwoLorentzianModel(BaseComponent):
11    """
12    Class that evaluates a TwoLorentzianModel.
13    I(q) = II(q) = scale_1/(1.0 + pow((q*length_1),exponent_1))
14    + scale_2/(1.0 + pow((q*length_2),exponent_2) )+ background
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 = "TwoLorentzian"
25        self.description = """I(q) = scale_1/(1.0 + pow((q*length_1),exponent_1))
26             + scale_2/(1.0 + pow((q*length_2),exponent_2) )+ background
27             List of default parameters:
28             scale_1 = Lorentzian term scaling #1
29             length_1 = Lorentzian screening length #1 [A]
30             exponent_1 = Lorentzian exponent #1
31             scale_2 = Lorentzian term scaling #2
32             length_2 = Lorentzian screening length #2 [A]
33             exponent_2 = Lorentzian exponent #2
34             background = Incoherent background
35        """
36        ## Define parameters
37        self.params = {}
38        self.params['scale_1']  = 10.0
39        self.params['length_1']     = 100.0
40        self.params['exponent_1']     = 3.0
41        self.params['scale_2']  = 1.0
42        self.params['length_2']     = 10.0
43        self.params['exponent_2']     = 2.0
44        self.params['background']     = 0.1
45        ## Parameter details [units, min, max]
46        self.details = {}
47        self.details['scale_1'] = ['', None, None]
48        self.details['length_1'] = ['A', None, None]
49        self.details['exponent_1'] =  ['', None, None]
50        self.details['scale_2']  =  ['', None, None]
51        self.details['length_2']  =   ['A', None, None]
52        self.details['exponent_2']  =   ['', None, None]
53        self.details['background']   =  ['[1/cm]', None, None]
54
55        #list of parameter that cannot be fitted
56        self.fixed = [] 
57    def _twolorentzian(self, x):
58        """
59        Model definition
60        """
61        inten = self.params['scale_1']/(1.0 + \
62                power((x*self.params['length_1']),self.params['exponent_1']))
63        inten += self.params['scale_2']/(1.0 + \
64                power((x*self.params['length_2']),self.params['exponent_2']))
65        inten += self.params['background']
66
67        return inten 
68   
69    def run(self, x = 0.0):
70        """
71        Evaluate the model
72       
73        param x: input q-value (float or [float, float] as [r, theta])
74        return: (scattering value)
75        """
76        if x.__class__.__name__ == 'list':
77            return self._twolorentzian(x[0])
78        elif x.__class__.__name__ == 'tuple':
79            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
80        else:
81            return self._twolorentzian(x)
82   
83    def runXY(self, x = 0.0):
84        """
85        Evaluate the model
86       
87        param x: input q-value (float or [float, float] as [qx, qy])
88        return: scattering value
89        """
90        if x.__class__.__name__ == 'list':
91            q = math.sqrt(x[0]**2 + x[1]**2)
92            return self._twolorentzian(q)
93        elif x.__class__.__name__ == 'tuple':
94            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
95        else:
96            return self._twolorentzian(x)
Note: See TracBrowser for help on using the repository browser.