source: sasview/sansmodels/src/sans/models/Cos.py @ 17574ae

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 17574ae was 279e371, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Fixing code style problems

  • Property mode set to 100644
File size: 1.6 KB
Line 
1"""
2    Provide cos(x) function as a BaseComponent model
3"""
4
5from sans.models.BaseComponent import BaseComponent
6import math
7 
8class Cos(BaseComponent):
9    """
10        Class that evaluates a cos(x) model.
11    """
12       
13    def __init__(self):
14        """ Initialization """
15       
16        # Initialize BaseComponent first, then sphere
17        BaseComponent.__init__(self)
18       
19        ## Name of the model
20        self.name = "Cos"
21        self.description = 'F(x)=cos(x)'
22        ## Parameter details [units, min, max]
23        self.details = {}
24   
25    def clone(self):
26        """ Return a identical copy of self """
27        return Cos()
28   
29    def run(self, x = 0.0):
30        """ Evaluate the model
31            @param x: input x, or [x, phi] [radian]
32            @return: cos(x) or cos(x*cos(phi))*cos(x*cos(phi))
33        """
34        if x.__class__.__name__ == 'list':
35            return math.cos(x[0]*math.cos(x[1]))*math.cos(x[0]*math.sin(x[1]))
36        elif x.__class__.__name__ == 'tuple':
37            raise ValueError, "Tuples are not allowed as input to models"
38        else:
39            return math.cos(x)
40   
41    def runXY(self, x = 0.0):
42        """ Evaluate the model
43            @param x: input x, or [x, y] [radian]
44            @return: cos(x) or cos(x)*cos(y)
45        """
46        if x.__class__.__name__ == 'list':
47            return math.cos(x[0])*math.cos(x[1])
48        elif x.__class__.__name__ == 'tuple':
49            raise ValueError, "Tuples are not allowed as input to models"
50        else:
51            return math.cos(x)
52
Note: See TracBrowser for help on using the repository browser.