source: sasview/src/sas/sasgui/plottools/LineModel.py @ 4109bd5

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 4109bd5 was dd5bf63, checked in by butler, 8 years ago

close #590. A lot of problems were caused by LineModel? and LinerFit?
having different equations (ax+b vs a+bx). Further errors in
calculations, particularly of uncertainties were fixed. The fact that
the fits to not account for smearing was verified and a warning added.
Code was also modified to update the qmin and qmax to match changes in
the transformed xmin xmax. Lots of documentation was added and the
fitdialog layout was cleaned up considerably. This is now usable though
the design of the user interface (and the whole design of linear fits)
could use a rethink.

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