Changeset 2df0b74 in sasview for src/sas/plottools/LineModel.py
- Timestamp:
- Mar 5, 2015 11:17:05 AM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 3477478
- Parents:
- dca6188
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/LineModel.py
r79492222 r2df0b74 1 1 #!/usr/bin/env python 2 """ 3 Provide Line function (y= A + Bx) 2 """ 3 Provide Line function (y= A + Bx) 4 4 """ 5 5 … … 7 7 8 8 class LineModel(object): 9 """ 9 """ 10 10 Class that evaluates a linear model. 11 11 12 12 f(x) = A + Bx 13 13 14 14 List of default parameters: 15 15 A = 0.0 16 B = 0.0 16 B = 0.0 17 17 """ 18 18 19 19 def __init__(self): 20 20 """ Initialization """ 21 # # Name of the model21 # # Name of the model 22 22 self.name = "LineModel" 23 23 24 # # Define parameters24 # # Define parameters 25 25 self.params = {} 26 26 self.params['A'] = 1.0 27 27 self.params['B'] = 1.0 28 28 29 # # Parameter details [units, min, max]29 # # Parameter details [units, min, max] 30 30 self.details = {} 31 31 self.details['A'] = ['', None, None] 32 32 self.details['B'] = ['', None, None] 33 33 34 34 def getParam(self, name): 35 35 """ 36 Return parameter value 36 37 """ 37 38 return self.params[name.upper()] 38 39 39 40 def setParam(self, name, value): 40 41 """ 42 Set parameter value 41 43 """ 42 44 self.params[name.upper()] = value 43 45 44 46 def _line(self, x): 45 47 """ 46 48 Evaluate the function 47 49 48 50 :param x: x-value 49 51 50 52 :return: function value 51 53 52 54 """ 53 55 return self.params['A'] + (x * self.params['B']) 54 55 def run(self, x =0.0):56 """ 56 57 def run(self, x=0.0): 58 """ 57 59 Evaluate the model 58 60 59 61 :param x: simple value 60 62 61 63 :return: (Line value) 62 64 """ … … 65 67 self._line(x[0] * math.sin(x[1])) 66 68 elif x.__class__.__name__ == 'tuple': 67 msg 69 msg = "Tuples are not allowed as input to BaseComponent models" 68 70 raise ValueError, msg 69 71 else: 70 72 return self._line(x) 71 72 def runXY(self, x =0.0):73 """ 73 74 def runXY(self, x=0.0): 75 """ 74 76 Evaluate the model 75 77 76 78 :param x: simple value 77 79 78 80 :return: Line value 79 81 80 82 """ 81 83 if x.__class__.__name__ == 'list': … … 86 88 else: 87 89 return self._line(x) 88 89 90 if __name__ == "__main__":91 l = Line()92
Note: See TracChangeset
for help on using the changeset viewer.