source: sasview/sansmodels/src/sans/models/LorentzModel.py @ 0ec0405

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 0ec0405 was 988130c6, checked in by Gervaise Alina <gervyh@…>, 16 years ago

self.fixed field added in models but need to change wrapper generator

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2"""
3    Provide F(x) = scale/( 1 + (x*L)^2 ) + bkd
4    Lorentz (Ornstein-Zernicke) function as a BaseComponent model
5"""
6
7from sans.models.BaseComponent import BaseComponent
8import math
9
10class LorentzModel(BaseComponent):
11   
12    """
13        Class that evaluates a Lorentz (Ornstein-Zernicke) model.
14       
15        F(x) = scale/( 1 + (x*L)^2 ) + bkd
16       
17        The model has three parameters:
18            L     =  screen Length
19            scale  =  scale factor
20            bkd    =  incoherent background
21    """
22       
23    def __init__(self):
24        """ Initialization """
25       
26        # Initialize BaseComponent first, then sphere
27        BaseComponent.__init__(self)
28       
29        ## Name of the model
30        self.name = "Lorentz"
31        self.description="Lorentz (Ornstein-Zernicke) model.\n\
32        F(x) = scale/( 1 + (x*L)^2 ) + bkd \nThe model has three parameters:\n \
33        L     =  screen Length\n\
34        scale  =  scale factor\n\
35        bkd    =  incoherent background"
36        ## Define parameters
37        self.params = {}
38        self.params['length']      = 50.0
39        self.params['scale']       = 1.0
40        self.params['background']  = 0.0
41
42        ## Parameter details [units, min, max]
43        self.details = {}
44        self.details['length']     = ['A', None, None]
45        self.details['scale']      = ['', None, None]
46        self.details['background'] = ['cm-1', None, None]
47        #list of parameter that cannot be fitted
48        self.fixed= []     
49    def _lorentz(self, x):
50        """
51            Evaluate F(x) = scale/( 1 + (x*L)^2 ) + bkd
52           
53        """
54        return self.params['scale']/( 1 + math.pow((x * self.params['length']),2))\
55                + self.params['background']
56       
57   
58    def run(self, x = 0.0):
59        """ Evaluate the model
60            @param x: input q-value (float or [float, float] as [r, theta])
61            @return: (Lorentz value)
62        """
63        if x.__class__.__name__ == 'list':
64            return self._lorentz(x[0])
65        elif x.__class__.__name__ == 'tuple':
66            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
67        else:
68            return self._lorentz(x)
69   
70    def runXY(self, x = 0.0):
71        """ Evaluate the model
72            @param x: input q-value (float or [float, float] as [qx, qy])
73            @return: Lorentz value
74        """
75        if x.__class__.__name__ == 'list':
76            q = math.sqrt(x[0]**2 + x[1]**2)
77            return self._lorentz(q)
78        elif x.__class__.__name__ == 'tuple':
79            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
80        else:
81            return self._lorentz(x)
Note: See TracBrowser for help on using the repository browser.