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

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 02879ea was 8f20419d, checked in by Jae Cho <jhjcho@…>, 14 years ago

more models and some tests

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