source: sasview/src/sas/sasgui/plottools/LineModel.py @ 87d44c7

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 87d44c7 was ec8886e, checked in by smk78, 8 years ago

Attempt to rectify some docstring errors

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[a9d5684]1#!/usr/bin/env python
[2df0b74]2"""
[dd5bf63]3Provide Line function (y= Ax + B). Until July 10, 2016 this function provided
4(y= A + Bx).  This however was contrary to all the other code using it which
5assumed (y= mx+b) or in this nomenclature (y=Ax + B). This lead to some
6contortions in the code and worse incorrect calculations until now for at least
7some of the functions.  This seemed the easiest to fix particularly since this
8function should disappear in a future iteration (see notes in fitDialog)
9
[ec8886e]10PDB   July 10, 2016
11
[a9d5684]12"""
13
14import math
15
16class LineModel(object):
[2df0b74]17    """
[a9d5684]18    Class that evaluates a linear model.
[2df0b74]19
[dd5bf63]20    f(x) = Ax + B
[2df0b74]21
[a9d5684]22    List of default parameters:
[dd5bf63]23    A = 1.0
24    B = 1.0
[a9d5684]25    """
[2df0b74]26
[a9d5684]27    def __init__(self):
28        """ Initialization """
[2df0b74]29        # # Name of the model
[a9d5684]30        self.name = "LineModel"
31
[2df0b74]32        # # Define parameters
[a9d5684]33        self.params = {}
34        self.params['A'] = 1.0
35        self.params['B'] = 1.0
36
[2df0b74]37        # # Parameter details [units, min, max]
[a9d5684]38        self.details = {}
39        self.details['A'] = ['', None, None]
40        self.details['B'] = ['', None, None]
[2df0b74]41
[a9d5684]42    def getParam(self, name):
43        """
[2df0b74]44            Return parameter value
[a9d5684]45        """
46        return self.params[name.upper()]
[2df0b74]47
[a9d5684]48    def setParam(self, name, value):
49        """
[2df0b74]50            Set parameter value
[a9d5684]51        """
52        self.params[name.upper()] = value
[2df0b74]53
[a9d5684]54    def _line(self, x):
55        """
56        Evaluate the function
[2df0b74]57
[a9d5684]58        :param x: x-value
[2df0b74]59
[a9d5684]60        :return: function value
[2df0b74]61
[a9d5684]62        """
[dd5bf63]63        return  (self.params['A'] * x) + self.params['B']
[2df0b74]64
65    def run(self, x=0.0):
66        """
[a9d5684]67        Evaluate the model
[2df0b74]68
[dd5bf63]69        :note: This is the function called by fitDialog to calculate the
70        the y(xmin) and y(xmax), but the only difference between this and
71        runXY is when the if statement is true. I however cannot see what that
72        function is for.  It needs to be documented here or removed.
[ec8886e]73        PDB 7/10/16
[dd5bf63]74
[a9d5684]75        :param x: simple value
[2df0b74]76
[a9d5684]77        :return: (Line value)
78        """
79        if x.__class__.__name__ == 'list':
80            return self._line(x[0] * math.cos(x[1])) * \
81                                self._line(x[0] * math.sin(x[1]))
82        elif x.__class__.__name__ == 'tuple':
[2df0b74]83            msg = "Tuples are not allowed as input to BaseComponent models"
[a9d5684]84            raise ValueError, msg
85        else:
86            return self._line(x)
[2df0b74]87
88    def runXY(self, x=0.0):
89        """
[dd5bf63]90        Evaluate the model.
91       
92        :note: This is to be what is called by fitDialog for the actual fit
93        but the only difference between this and run is when the if
94        statement is true. I however cannot see what that function
[ec8886e]95        is for.  It needs to be documented here or removed. PDB 7/10/16
[2df0b74]96
[a9d5684]97        :param x: simple value
[2df0b74]98
[a9d5684]99        :return: Line value
[2df0b74]100
[a9d5684]101        """
102        if x.__class__.__name__ == 'list':
103            return self._line(x[0]) * self._line(x[1])
104        elif x.__class__.__name__ == 'tuple':
105            msg = "Tuples are not allowed as input to BaseComponent models"
106            raise ValueError, msg
107        else:
108            return self._line(x)
Note: See TracBrowser for help on using the repository browser.