[aaea3714] | 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 |
---|
[aaea3714] | 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!!! |
---|
[aaea3714] | 11 | |
---|
[80a6775] | 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!!! |
---|
[aaea3714] | 20 | """ |
---|
[80a6775] | 21 | ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """ |
---|
| 22 | ##DESCRIPTION OF MODEL PLUG-IN GOES HERE |
---|
[aaea3714] | 23 | |
---|
[80a6775] | 24 | ##EXAMPLE: Class that evaluates a polynomial model. |
---|
| 25 | """ |
---|
| 26 | ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " " |
---|
| 27 | ## TO RENAME YOUR MODEL |
---|
| 28 | name = "sin(poly)/(poly)" ## <----- NAME OF THE MODEL |
---|
| 29 | |
---|
| 30 | def __init__(self): ##DO NOT CHANGE THIS LINE!!! |
---|
[5062bbf] | 31 | """ |
---|
| 32 | Initialization |
---|
| 33 | """ |
---|
[80a6775] | 34 | Model1DPlugin.__init__(self, name=self.name) ##DO NOT CHANGE THIS LINE!!! |
---|
| 35 | |
---|
| 36 | ## EDIT PARAMETERS' NAMES AND VALUE |
---|
| 37 | ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS |
---|
| 38 | self.params = {} ##DO NOT CHANGE THIS LINE!!! |
---|
[aaea3714] | 39 | |
---|
[80a6775] | 40 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 41 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 42 | self.params['scale'] = 1.0 ## <----- |
---|
| 43 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 44 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 45 | self.params['A'] = 0.0 ## <----- |
---|
| 46 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 47 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 48 | self.params['B'] = 10.0 ## <----- |
---|
| 49 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 50 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 51 | self.params['C'] = 0.0 ## <----- |
---|
| 52 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 53 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 54 | self.params['D'] = 0.0 ## <----- |
---|
| 55 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 56 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 57 | self.params['E'] = 0.0 ## <----- |
---|
| 58 | ## YOU CAN MODIFY THELINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 59 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 60 | self.params['F'] = 0.0 ## <----- |
---|
[aaea3714] | 61 | |
---|
[80a6775] | 62 | ## STORING PARAMETERS [UNIT, MINIMUM VALUE, MAXIMUM VALUE] |
---|
| 63 | self.details = {} ##DO NOT CHANGE THIS LINE!!! |
---|
| 64 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 65 | ## ' ', TWO OTHER NUMBESR TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 66 | self.details['scale'] = ['',None, None] ## <----- |
---|
| 67 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 68 | ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 69 | self.details['A'] = ['', None, None] ## <----- |
---|
| 70 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 71 | ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 72 | self.details['B'] = ['', None, None] ## <----- |
---|
| 73 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 74 | ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 75 | self.details['C'] = ['', None, None] ## <----- |
---|
| 76 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 77 | ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 78 | self.details['D'] = ['', None, None] ## <----- |
---|
| 79 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 80 | ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 81 | self.details['E'] = ['', None, None] ## <----- |
---|
| 82 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ',WORD BETWEEN |
---|
| 83 | ## ' ', TWO OTHER NUMBERS TO NEW VALUE OR YOU CAN ALSO DELETE TH LINE |
---|
| 84 | self.details['F'] = ['', 0, 1e16] ## <----- |
---|
| 85 | ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """ """ ONLY!!!! |
---|
| 86 | self.description = """ |
---|
| 87 | scale * sin(F(x)/F(x)) \n where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5 |
---|
| 88 | """ ## <----- |
---|
[aaea3714] | 89 | |
---|
[80a6775] | 90 | def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!! |
---|
[5062bbf] | 91 | """ |
---|
| 92 | Evaluate the model |
---|
| 93 | |
---|
| 94 | :param x: input x |
---|
| 95 | |
---|
| 96 | :return: function value |
---|
| 97 | |
---|
[aaea3714] | 98 | """ |
---|
[80a6775] | 99 | ## ADD YOUR FUNCTION HERE. |
---|
| 100 | ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION. |
---|
[aaea3714] | 101 | |
---|
[80a6775] | 102 | ## IN THIS EXAMPLE THE FUNTION IS: |
---|
| 103 | ## scale * sin(F(x)/F(x)) \n where F(x)=A+B*x+C*x^2+D*x^3+E*x^4+F*x^5 |
---|
[aaea3714] | 104 | |
---|
[80a6775] | 105 | ## YOU CAN REWRITE OUR EXAMPLE WITH EVERYTING INSIDE " " : |
---|
| 106 | ## "RETURN self.params['scale']* (self.params['A'] + self.params['B']*x + \ |
---|
| 107 | ## self.params['C']* pow(x,2) + self.params['D']*pow(x,3)+\ |
---|
| 108 | ## self.params['E']*pow(x,4) +self.params['F']*pow(x,5) ) " |
---|
| 109 | |
---|
| 110 | ## NOTE: pow IS A FUNCTION IMPORTED FROM PYTHON MATH LIBRARY |
---|
| 111 | ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html |
---|
| 112 | ## OTHER FUNCTIONS ARE ALSO |
---|
| 113 | ### AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category |
---|
| 114 | ## numpy FUNCTIONS ARE FOR EXPERT USER |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | ## YOU CAN ERASE EVERYTHING BELLOW FOR YOUR OWN FUNCTION |
---|
| 118 | #Redefine parameters as local parameters |
---|
| 119 | a = self.params['A'] ## <----- |
---|
| 120 | b = self.params['B'] ## <----- |
---|
| 121 | c = self.params['C'] ## <----- |
---|
| 122 | d = self.params['D'] ## <----- |
---|
| 123 | e = self.params['E'] ## <----- |
---|
| 124 | f = self.params['F'] ## <----- |
---|
| 125 | scl = self.params['scale'] ## <----- |
---|
| 126 | ##THIS OUR FUNCTION TEMPLATE |
---|
[aaea3714] | 127 | poly = a + b*x + c*math.pow(x,2) + d*math.pow(x,3) \ |
---|
[80a6775] | 128 | + e*math.pow(x,4) +f*math.pow(x,5) ## <----- |
---|
[aaea3714] | 129 | |
---|
| 130 | #Remove a singular point (lim poly --> 0) for sin(poly)/poly |
---|
| 131 | #(Just note: In Python, indentation defines the belongings of 'if', 'for', and so on..) |
---|
[80a6775] | 132 | if poly == 0: ## <----- |
---|
| 133 | result = 1 ## <----- |
---|
| 134 | else: ## <----- |
---|
| 135 | result = sin(poly)/poly ## <----- |
---|
[aaea3714] | 136 | |
---|
[80a6775] | 137 | #Re-scale ## <----- |
---|
| 138 | result *=scl ## <----- |
---|
[aaea3714] | 139 | |
---|
[80a6775] | 140 | return result ## MODIFY ONLY RESULT. DON'T DELETE RETURN!!!! |
---|
[aaea3714] | 141 | |
---|