source: sasview/src/sas/models/PeakGaussModel.py @ 24d3a40

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 24d3a40 was ac7be54, checked in by Paul Kienzle <pkienzle@…>, 10 years ago

fix sphinx errors in api manual

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