Changeset 80a6775 in sasview for sansview/plugins/testmodel.py
- Timestamp:
- Jul 1, 2010 5:09:55 PM (14 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:
- 733e90b
- Parents:
- 38eee13
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/plugins/testmodel.py
r5062bbf r80a6775 1 1 """ 2 2 Test plug-in model 3 These are links of available functions: 4 5 http://docs.python.org/library/math.html 6 http://www.scipy.org/Numpy_Functions_by_Category 3 7 """ 4 from sans.models.pluginmodel import Model1DPlugin 8 from sans.models.pluginmodel import Model1DPlugin ##DO NOT CHANGE THIS LINE!!! 9 from math import * ##DO NOT CHANGE THIS LINE!!! 10 from numpy import * ##DO NOT CHANGE THIS LINE!!! 5 11 6 import math 12 ##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## 13 ## THESE COMMENTS ARE THERE TO GUIDE YOU. YOU CAN REMOVE THEM ONLY WHEN YOU ARE 14 ## CONFORTABLE ENOUGH WITH OUR MODEL PLUGIN OPTION 7 15 8 16 9 # Your model HAS to be called Model 10 class Model(Model1DPlugin): 17 ## <----- SIGN DEFINES WHERE YOU CAN MODIFY THE CODE 18 19 class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!! 11 20 """ 12 Class that evaluates a cos(x) model. 21 ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """ 22 ##DESCRIPTION OF MODEL PLUG-IN GOES HERE 23 24 ##EXAMPLE:Class that evaluates a cos(x) model. 13 25 """ 14 26 15 ## Name of the model 16 name = "A+Bcos(2x)+Csin(2x)" 27 ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " " 28 ## TO RENAME YOUR MODEL 29 name = "A+Bcos(2x)+Csin(2x)" ## <----- NAME OF THE MODEL 17 30 18 31 def __init__(self): … … 20 33 Initialization 21 34 """ 22 Model1DPlugin.__init__(self, name= self.name) 35 Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!! 23 36 24 ## Parameters definition and defaults 25 self.params = {} 26 self.params['A'] = 1.0 27 self.params['B'] = 1.0 28 self.params['C'] = 10.0 37 ## EDIT PARAMETERS' NAMES AND VALUE 38 ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS 39 self.params = {} ##DO NOT CHANGE THIS LINE!!! 40 ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER 41 ## YOU CAN ALSO DELETE THIS LINE 42 self.params['A'] = 1.0 ## <----- 43 ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER 44 ## YOU CAN ALSO DELETE THIS LINE 45 self.params['B'] = 1.0 ## <----- 46 ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER 47 ## YOU CAN ALSO DELETE THIS LINE 48 self.params['C'] = 10.0 ## <----- 29 49 30 ## Parameter details [units, min, max] 31 self.details = {} 32 self.details['A'] = ['', -1e16, 1e16] 33 self.details['B'] = ['', -1e16, 1e16] 34 self.details['C'] = ['', -1e16, 1e16] 35 self.description = "F(x)=A+Bcos(2x)+Csin(2x) " 50 ## STORING PARAMETERS [UNIT, MINIMUM VALUE, MAXIMUM VALUE] 51 self.details = {} ##DO NOT CHANGE THIS LINE!!! 52 ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 53 ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE 54 self.details['A'] = ['', -1e16, 1e16] ## <----- 55 ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 56 ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE 57 self.details['B'] = ['', -1e16, 1e16] ## <----- 58 ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN 59 ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE 60 self.details['C'] = ['', -1e16, 1e16] ## <----- 61 ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """ """ ONLY!!!! 62 self.description = "F(x)=A+Bcos(2x)+Csin(2x) " ## <----- 36 63 37 def function(self, x = 0.0): 64 def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!! 38 65 """ 39 66 Evaluate the model … … 44 71 45 72 """ 46 return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) 73 ## ADD YOUR FUNCTION HERE. 74 ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION. 75 76 ## IN THIS EXAMPLE THE FUNTION IS: 77 ## A+Bcos(2x)+Csin(2x) 78 ## YOU CAN USE math.sin or sin directly 79 ## NOTE: sin, cos ARE FUNCTIONS IMPORTED FROM PYTHON MATH LIBRARY 80 ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html 81 ## OTHER FUNCTIONS ARE ALSO 82 ## AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category 83 ## numpy FUNCTIONS ARE FOR EXPERT USER 84 85 return self.params['A']+self.params['B']*cos(2.0*x)+self.params['C']*math.sin(2.0*x) 47 86
Note: See TracChangeset
for help on using the changeset viewer.