source: sasview/sansmodels/src/sans/models/TeubnerStreyModel.py @ 8a25523

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 8a25523 was 1ed3834, checked in by Jae Cho <jhjcho@…>, 16 years ago

unit symbol Angst. back to A and re-organized model descriptions

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[829eee9]1#!/usr/bin/env python
2"""
3    Provide F(x) = 1/( scale + c1*(x)^(2)+  c2*(x)^(4)) + bkd
4    Teubner-Strey function as a BaseComponent model
5   
6"""
7
8from sans.models.BaseComponent import BaseComponent
9import math
10
11class TeubnerStreyModel(BaseComponent):
12   
13    """
14        Class that evaluates  the TeubnerStrey model.
15       
16        F(x) = 1/( scale + c1*(x)^(2)+  c2*(x)^(4)) + bkd
17       
18        The model has Four parameters:
19            scale  =  scale factor
20            c1     =  constant
21            c2     =  constant
22            bkd    =  incoherent background
23    """
24       
25    def __init__(self):
26        """ Initialization """
27       
28        # Initialize BaseComponent first, then sphere
29        BaseComponent.__init__(self)
30       
31        ## Name of the model
32        self.name = "Teubner Strey"
[753552d]33        self.description="""The TeubnerStrey model.
34        F(x) = 1/( scale + c1*(x)^(2)+  c2*(x)^(4)) + bkd
[1ed3834]35       
[753552d]36        The model has Four parameters:
37        scale  =  scale factor
38        c1     =  constant
39        c2     =  constant
40        bkd    =  incoherent background"""
[829eee9]41        ## Define parameters
42        self.params = {}
43        self.params['c1']     = -30.0
44        self.params['c2']     = 5000.0
45        self.params['scale']  = 0.1
[3db3895]46        self.params['background']    = 0.0
[829eee9]47
48        ## Parameter details [units, min, max]
49        self.details = {}
50        self.details['c1']    = ['', None, None ]
51        self.details['c2']    = ['', None, None ]
52        self.details['scale'] = ['', None, None]
[0824909]53        self.details['background']   = ['[1/cm]', None, None]
[988130c6]54        #list of parameter that cannot be fitted
55        self.fixed= []
[829eee9]56               
57    def _TeubnerStrey(self, x):
58        """
59            Evaluate  F(x) = 1/( scale + c1*(x)^(2)+  c2*(x)^(4)) + bkd
60           
61        """
62        return 1/( self.params['scale']+ self.params['c1'] * math.pow(x ,2)\
[f629e346]63                + self.params['c2'] * math.pow(x ,4) ) + self.params['background']
[829eee9]64       
65   
66    def run(self, x = 0.0):
67        """ Evaluate the model
[3db3895]68            @param x: input q-value (float or [float, float] as [r, theta])
[829eee9]69            @return: (PowerLaw value)
70        """
71        if x.__class__.__name__ == 'list':
[a55fac1]72            return self._TeubnerStrey(x[0])
[829eee9]73        elif x.__class__.__name__ == 'tuple':
74            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
75        else:
76            return self._TeubnerStrey(x)
77   
78    def runXY(self, x = 0.0):
79        """ Evaluate the model
[3db3895]80            @param x: input q-value (float or [float, float] as [qx, qy])
[829eee9]81            @return: PowerLaw value
82        """
83        if x.__class__.__name__ == 'list':
[a55fac1]84            q = math.sqrt(x[0]**2 + x[1]**2)
85            return self._TeubnerStrey(q)
[829eee9]86        elif x.__class__.__name__ == 'tuple':
87            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
88        else:
89            return self._TeubnerStrey(x)
90       
[3db3895]91    def teubnerStreyLengths(self):
[829eee9]92        """
93            Calculate the correlation length (L)
94            @return L: the correlation distance
95        """
[3db3895]96        return  math.pow( 1/2 * math.pow( (self.params['scale']/self.params['c2']), 1/2 )\
[829eee9]97                            +(self.params['c1']/(4*self.params['c2'])),-1/2 )
[3db3895]98    def teubnerStreyDistance(self):
[829eee9]99        """
100            Calculate the quasi-periodic repeat distance (D/(2*pi))
101            @return D: quasi-periodic repeat distance
102        """
[3db3895]103        return  math.pow( 1/2 * math.pow( (self.params['scale']/self.params['c2']), 1/2 )\
[829eee9]104                            -(self.params['c1']/(4*self.params['c2'])),-1/2 )
Note: See TracBrowser for help on using the repository browser.