source: sasview/sansmodels/src/sans/models/BroadPeakModel.py @ c7a7e1b

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 c7a7e1b was 5385a9e, checked in by Jae Cho <jhjcho@…>, 14 years ago

Added missing brackets in the unit string

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#!/usr/bin/env python
2"""
3BroadPeakModel function as a BaseComponent model
4"""
5
6from sans.models.BaseComponent import BaseComponent
7from math import fabs
8from numpy import power
9
10class BroadPeakModel(BaseComponent):
11    """
12    Class that evaluates a BroadPeakModel.
13    I(q) = I(q) = scale_p/pow(qval,exponent)+scale_l/
14    (1.0 + pow((qval*length_l),exponent_l) )+ background
15    """
16       
17    def __init__(self):
18        """ Initialization """
19       
20        # Initialize BaseComponent first, then sphere
21        BaseComponent.__init__(self)
22        self.counter = 0
23        ## Name of the model
24        self.name = "BroadPeak"
25        self.description="""I(q) = scale_p/pow(q,exponent)+scale_l/
26        (1.0 + pow((fabs(q-q_peak)*length_l),exponent_l) )+ background
27             List of default parameters:
28             scale_p = Porod term scaling
29             exponent_p = Porod exponent
30             scale_l = Lorentzian term scaling
31             length_l = Lorentzian screening length [A]
32             q_peak = peak location [1/A]
33             exponent_l = Lorentzian exponent
34             background = Incoherent background
35        """
36        ## Define parameters
37        self.params = {}
38        self.params['scale_p']  = 1.0e-05
39        self.params['exponent_p']     = 3.0
40        self.params['scale_l']  = 10.0
41        self.params['length_l']     = 50.0
42        self.params['q_peak']     = 0.1
43        self.params['exponent_l']     = 2.0
44        self.params['background']     = 0.1
45        ## Parameter details [units, min, max]
46        self.details = {}
47        self.details['scale_p'] = ['', None, None]
48        self.details['exponent_p'] =  ['', None, None]
49        self.details['scale_l']  =  ['', None, None]
50        self.details['length_l']  =   ['[A]', None, None]
51        self.details['q_peak']  =  ['[1/A]', None, None]
52        self.details['exponent_l']  =   ['', None, None]
53        self.details['background']   =  ['[1/cm]', None, None]
54
55        #list of parameter that cannot be fitted
56        self.fixed= [] 
57    def _broadpeak(self, x):
58        """
59        Model definition
60        """
61        inten = self.params['scale_p']/pow(x,self.params['exponent_p'])
62        inten += self.params['scale_l']/(1.0 + \
63                power((fabs(x-self.params['q_peak'])*self.params['length_l']),\
64                    self.params['exponent_l']))
65
66        inten += self.params['background']
67       
68        return inten 
69   
70    def run(self, x = 0.0):
71        """
72        Evaluate the model
73       
74        param x: input q-value (float or [float, float] as [r, theta])
75        return: (scattering value)
76        """
77        if x.__class__.__name__ == 'list':
78            return self._broadpeak(x[0])
79        elif x.__class__.__name__ == 'tuple':
80            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
81        else:
82            return self._broadpeak(x)
83   
84    def runXY(self, x = 0.0):
85        """
86        Evaluate the model
87       
88        param x: input q-value (float or [float, float] as [qx, qy])
89        return: scattering value
90        """
91        if x.__class__.__name__ == 'list':
92            q = math.sqrt(x[0]**2 + x[1]**2)
93            return self._broadpeak(q)
94        elif x.__class__.__name__ == 'tuple':
95            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
96        else:
97            return self._broadpeak(x)
98       
99       
Note: See TracBrowser for help on using the repository browser.