source: sasview/src/sas/sasgui/plottools/LineModel.py @ 951701c

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 951701c 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
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
10                -PDB   July 10, 2016
[a9d5684]11"""
12
13import math
14
15class LineModel(object):
[2df0b74]16    """
[a9d5684]17    Class that evaluates a linear model.
[2df0b74]18
[dd5bf63]19    f(x) = Ax + B
[2df0b74]20
[a9d5684]21    List of default parameters:
[dd5bf63]22    A = 1.0
23    B = 1.0
[a9d5684]24    """
[2df0b74]25
[a9d5684]26    def __init__(self):
27        """ Initialization """
[2df0b74]28        # # Name of the model
[a9d5684]29        self.name = "LineModel"
30
[2df0b74]31        # # Define parameters
[a9d5684]32        self.params = {}
33        self.params['A'] = 1.0
34        self.params['B'] = 1.0
35
[2df0b74]36        # # Parameter details [units, min, max]
[a9d5684]37        self.details = {}
38        self.details['A'] = ['', None, None]
39        self.details['B'] = ['', None, None]
[2df0b74]40
[a9d5684]41    def getParam(self, name):
42        """
[2df0b74]43            Return parameter value
[a9d5684]44        """
45        return self.params[name.upper()]
[2df0b74]46
[a9d5684]47    def setParam(self, name, value):
48        """
[2df0b74]49            Set parameter value
[a9d5684]50        """
51        self.params[name.upper()] = value
[2df0b74]52
[a9d5684]53    def _line(self, x):
54        """
55        Evaluate the function
[2df0b74]56
[a9d5684]57        :param x: x-value
[2df0b74]58
[a9d5684]59        :return: function value
[2df0b74]60
[a9d5684]61        """
[dd5bf63]62        return  (self.params['A'] * x) + self.params['B']
[2df0b74]63
64    def run(self, x=0.0):
65        """
[a9d5684]66        Evaluate the model
[2df0b74]67
[dd5bf63]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
[a9d5684]74        :param x: simple value
[2df0b74]75
[a9d5684]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':
[2df0b74]82            msg = "Tuples are not allowed as input to BaseComponent models"
[a9d5684]83            raise ValueError, msg
84        else:
85            return self._line(x)
[2df0b74]86
87    def runXY(self, x=0.0):
88        """
[dd5bf63]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
[2df0b74]95
[a9d5684]96        :param x: simple value
[2df0b74]97
[a9d5684]98        :return: Line value
[2df0b74]99
[a9d5684]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.