source: sasview/src/sas/models/PeakGaussModel.py @ 4ee041f

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 4ee041f was d430ee8, checked in by Paul Kienzle <pkienzle@…>, 9 years ago

correct width of peak gauss model by using floating point rather than integer division for ½

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