source: sasview/src/sas/models/Cos.py @ a728658

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 a728658 was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[279e371]1"""
2    Provide cos(x) function as a BaseComponent model
[ae3ce4e]3"""
4
[79492222]5from sas.models.BaseComponent import BaseComponent
[ae3ce4e]6import math
7 
8class Cos(BaseComponent):
[279e371]9    """
10        Class that evaluates a cos(x) model.
[ae3ce4e]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"
[279e371]21        self.description = 'F(x)=cos(x)'
[ae3ce4e]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':
[279e371]37            raise ValueError, "Tuples are not allowed as input to models"
[ae3ce4e]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':
[279e371]49            raise ValueError, "Tuples are not allowed as input to models"
[ae3ce4e]50        else:
51            return math.cos(x)
[279e371]52
Note: See TracBrowser for help on using the repository browser.