[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 | """ |
---|
[22b1d38] | 8 | |
---|
[e9bd127] | 9 | """ |
---|
[22b1d38] | 10 | ## ***************************************************************************** |
---|
[e9bd127] | 11 | Please select the 'Compile' from the menubar after the modification and saving. |
---|
| 12 | Note that we recommend to save the file as a different file name. |
---|
| 13 | Otherwise, it could be removed in the future on re-installation of the SansView. |
---|
[22b1d38] | 14 | ## ***************************************************************************** |
---|
[e9bd127] | 15 | """ |
---|
[22b1d38] | 16 | |
---|
[96814e1] | 17 | from sans.models.pluginmodel import Model1DPlugin ##DO NOT CHANGE THIS LINE!!! |
---|
[7c8d3093] | 18 | import math ##DO NOT CHANGE THIS LINE!!! |
---|
| 19 | import numpy ##DO NOT CHANGE THIS LINE!!! |
---|
[96814e1] | 20 | |
---|
| 21 | ##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## |
---|
| 22 | ## THESE COMMENTS ARE THERE TO GUIDE YOU. YOU CAN REMOVE THEM ONLY WHEN YOU ARE |
---|
| 23 | ## CONFORTABLE ENOUGH WITH OUR MODEL PLUGIN OPTION |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | ## <----- SIGN DEFINES WHERE YOU CAN MODIFY THE CODE |
---|
| 27 | |
---|
| 28 | class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!! |
---|
| 29 | """ |
---|
| 30 | ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """ |
---|
| 31 | ##DESCRIPTION OF MODEL PLUG-IN GOES HERE |
---|
| 32 | |
---|
| 33 | ##EXAMPLE:Class that evaluates a cos(x) model. |
---|
| 34 | """ |
---|
| 35 | |
---|
| 36 | ## YOU CAN MODIFY THE LINE BELLOW. CHANGE ONLY WORDS BETWEEN " " |
---|
| 37 | ## TO RENAME YOUR MODEL |
---|
| 38 | name = "A+Bcos(2x)+Csin(2x)" ## <----- NAME OF THE MODEL |
---|
| 39 | |
---|
| 40 | def __init__(self): |
---|
| 41 | """ |
---|
| 42 | Initialization |
---|
| 43 | """ |
---|
| 44 | Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!! |
---|
| 45 | |
---|
| 46 | ## EDIT PARAMETERS' NAMES AND VALUE |
---|
| 47 | ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS |
---|
| 48 | self.params = {} ##DO NOT CHANGE THIS LINE!!! |
---|
| 49 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 50 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 51 | self.params['A'] = 1.0 ## <----- |
---|
| 52 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 53 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 54 | self.params['B'] = 1.0 ## <----- |
---|
| 55 | ## YOU CAN MODIFY THE LINE BELLOW.CHANGE WORD BETWEEN ' ' AND NUMBER |
---|
| 56 | ## YOU CAN ALSO DELETE THIS LINE |
---|
| 57 | self.params['C'] = 10.0 ## <----- |
---|
| 58 | |
---|
[ed8fa6a3] | 59 | ## DEFINE DEFAULT DETAILS |
---|
| 60 | self.set_details() ##DO NOT DELETE OR CHANGE THIS LINE!!! |
---|
| 61 | |
---|
[96814e1] | 62 | ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """ """ ONLY!!!! |
---|
[ed8fa6a3] | 63 | self.description = "F(x)=A+Bcos(2x)+Csin(2x) " ## <----- |
---|
[96814e1] | 64 | |
---|
| 65 | def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!! |
---|
| 66 | """ |
---|
| 67 | Evaluate the model |
---|
| 68 | |
---|
| 69 | :param x: input x |
---|
| 70 | |
---|
| 71 | :return: function value |
---|
| 72 | |
---|
| 73 | """ |
---|
| 74 | ## ADD YOUR FUNCTION HERE. |
---|
| 75 | ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION. |
---|
| 76 | |
---|
| 77 | ## IN THIS EXAMPLE THE FUNTION IS: |
---|
| 78 | ## A+Bcos(2x)+Csin(2x) |
---|
| 79 | ## YOU CAN USE math.sin or sin directly |
---|
| 80 | ## NOTE: sin, cos ARE FUNCTIONS IMPORTED FROM PYTHON MATH LIBRARY |
---|
| 81 | ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html |
---|
| 82 | ## OTHER FUNCTIONS ARE ALSO |
---|
| 83 | ## AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category |
---|
| 84 | ## numpy FUNCTIONS ARE FOR EXPERT USER |
---|
| 85 | |
---|
[7c8d3093] | 86 | return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) |
---|
| 87 | |
---|
| 88 | ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! |
---|
| 89 | if __name__ == "__main__": |
---|
| 90 | m= Model() |
---|
| 91 | out1 = m.runXY(0.0) |
---|
| 92 | out2 = m.runXY(0.01) |
---|
| 93 | isfine1 = numpy.isfinite(out1) |
---|
| 94 | isfine2 = numpy.isfinite(out2) |
---|
| 95 | print "Testing the value at Q = 0.0:" |
---|
| 96 | print out1, " : finite? ", isfine1 |
---|
| 97 | print "Testing the value at Q = 0.01:" |
---|
| 98 | print out2, " : finite? ", isfine2 |
---|
| 99 | if isfine1 and isfine2: |
---|
| 100 | print "===> Simple Test: Passed!" |
---|
| 101 | else: |
---|
| 102 | print "===> Simple Test: Failed!" |
---|