[96814e1] | 1 | """ |
---|
| 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 |
---|
| 7 | """ |
---|
| 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!!! |
---|
| 11 | |
---|
| 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 |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | ## <----- SIGN DEFINES WHERE YOU CAN MODIFY THE CODE |
---|
| 18 | |
---|
| 19 | class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!! |
---|
| 20 | """ |
---|
| 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. |
---|
| 25 | """ |
---|
| 26 | |
---|
| 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 |
---|
| 30 | |
---|
| 31 | def __init__(self): |
---|
| 32 | """ |
---|
| 33 | Initialization |
---|
| 34 | """ |
---|
| 35 | Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!! |
---|
| 36 | |
---|
| 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 ## <----- |
---|
| 49 | |
---|
| 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) " ## <----- |
---|
| 63 | |
---|
| 64 | def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!! |
---|
| 65 | """ |
---|
| 66 | Evaluate the model |
---|
| 67 | |
---|
| 68 | :param x: input x |
---|
| 69 | |
---|
| 70 | :return: function value |
---|
| 71 | |
---|
| 72 | """ |
---|
| 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) |
---|
| 86 | |
---|