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