source: sasview/sansmodels/src/sans/models/DebyeModel.py @ 831149e

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 831149e was f629e346, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Updated tests to reflect proper math (took test funcs from Igor). Still need to look into incoherence btw Igor docs and Igor code!

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[829eee9]1#!/usr/bin/env python
2"""
[3db3895]3    Provide F(x) = 2( exp(-x) + x - 1 )/x**2
4    with x = (q*R_g)**2
5   
[829eee9]6    Debye function as a BaseComponent model
7"""
8
9from sans.models.BaseComponent import BaseComponent
10import math
11
12class DebyeModel(BaseComponent):
13   
14    """
15        Class that evaluates a Debye model.
16       
[3db3895]17        F(x) = 2( exp(-x) + x - 1 )/x**2
18        with x = (q*R_g)**2
[829eee9]19       
20        The model has three parameters:
21            Rg     =  radius of gyration
22            scale  =  scale factor
23            bkd    =  Constant background
24    """
25       
26    def __init__(self):
27        """ Initialization """
28       
29        # Initialize BaseComponent first, then sphere
30        BaseComponent.__init__(self)
31       
32        ## Name of the model
33        self.name = "Debye"
34
35        ## Define parameters
36        self.params = {}
[3db3895]37        self.params['rg']          = 50.0
38        self.params['scale']       = 1.0
39        self.params['background']  = 0.0
[829eee9]40
41        ## Parameter details [units, min, max]
42        self.details = {}
[3db3895]43        self.details['rg']         = ['', None, None]
44        self.details['scale']      = ['', None, None]
45        self.details['background'] = ['', None, None]
[829eee9]46               
47    def _debye(self, x):
48        """
49            Evaluate F(x)= scale * D + bkd
50            has 2 internal parameters :
[3db3895]51                    D = 2 * (exp(-y) + y - 1)/y**2
[829eee9]52                    y = (x * Rg)^(2)
53        """
[3db3895]54        # Note that a zero denominator value will raise
55        # an exception
[f629e346]56        y = (x * self.params['rg'])**2.0
57        D = 2.0*( math.exp(-y) + y -1.0 )/y**2.0
[3db3895]58        return self.params['scale']* D + self.params['background']
[829eee9]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: (debye value)
64        """
65        if x.__class__.__name__ == 'list':
66            return self._debye(x[0]*math.cos(x[1]))*self._debye(x[0]*math.sin(x[1]))
67        elif x.__class__.__name__ == 'tuple':
68            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
69        else:
70            return self._debye(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: debye value
76        """
77        if x.__class__.__name__ == 'list':
78            return self._debye(x[0])*self._debye(x[1])
79        elif x.__class__.__name__ == 'tuple':
80            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
81        else:
82            return self._debye(x)
Note: See TracBrowser for help on using the repository browser.