source: sasview/sansmodels/src/sans/models/DABModel.py @ ccb7363

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 ccb7363 was 8d97277, checked in by Jae Cho <jhjcho@…>, 15 years ago

changed scale definition to be uncorrelated with length: due to the recent NIST code changes

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[829eee9]1#!/usr/bin/env python
2"""
[3db3895]3    Provide F(x) = scale/( 1 + (x*L)^2 )^(2) + background
[829eee9]4    DAB (Debye Anderson Brumberger) function as a BaseComponent model
5"""
6
7from sans.models.BaseComponent import BaseComponent
8import math
9
10class DABModel(BaseComponent):
11   
12    """
13        Class that evaluates a DAB model.
14       
[8d97277]15        F(x) = scale*(L^3)/( 1 + (x*L)^2 )^(2) + background
[829eee9]16       
17        The model has three parameters:
[3db3895]18            L             =  Correlation Length
19            scale         =  scale factor
20            background    =  incoherent background
[829eee9]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
[3db3895]30        self.name = "DAB_Model"
[8d97277]31        self.description="""F(x) = scale*(L^3)/( 1 + (x*L)^2 )^(2) + background
[753552d]32       
33        The model has three parameters:
34        L             =  Correlation Length
35        scale         =  scale factor
36        background    =  incoherent background"""
[829eee9]37        ## Define parameters
38        self.params = {}
[3db3895]39        self.params['length']             = 50.0
40        self.params['scale']              = 1.0
41        self.params['background']         = 0.0
[829eee9]42
43        ## Parameter details [units, min, max]
44        self.details = {}
[1ed3834]45        self.details['length']            = ['[A]', None, None]
[3db3895]46        self.details['scale']             = ['', None, None]
[0824909]47        self.details['background']        = ['[1/cm]', None, None]
[988130c6]48        #list of parameter that cannot be fitted
49        self.fixed= []     
[829eee9]50    def _DAB(self, x):
51        """
[8d97277]52            Evaluate  F(x) = (scale*L^3)/( 1 + (x*L)^2 )^(2) + background
[829eee9]53           
54        """
[8d97277]55        # According to SRK (Igor/NIST code: 6 JUL 2009  changed definition of 'scale' to be uncorrelated with 'length')
56        return self.params['scale']*math.pow(self.params['length'],3)/math.pow(( 1 + math.pow(x * self.params['length'],2)),2) \
[3db3895]57         + self.params['background']
[829eee9]58       
59   
60    def run(self, x = 0.0):
61        """ Evaluate the model
[3db3895]62            @param x: input q-value (float or [float, float] as [r, theta])
[829eee9]63            @return: (DAB value)
64        """
65        if x.__class__.__name__ == 'list':
[a55fac1]66            return self._DAB(x[0])
[829eee9]67        elif x.__class__.__name__ == 'tuple':
68            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
69        else:
70            return self._DAB(x)
71   
72    def runXY(self, x = 0.0):
73        """ Evaluate the model
[3db3895]74            @param x: input q-value (float or [float, float] as [qx, qy])
[829eee9]75            @return: DAB value
76        """
77        if x.__class__.__name__ == 'list':
[a55fac1]78            q = math.sqrt(x[0]**2 + x[1]**2)
79            return self._DAB(q)
[829eee9]80        elif x.__class__.__name__ == 'tuple':
81            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
82        else:
83            return self._DAB(x)
Note: See TracBrowser for help on using the repository browser.