[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!!! |
---|
[316e231] | 20 | import os |
---|
| 21 | import sys |
---|
[96814e1] | 22 | ##PLEASE READ COMMENTS CAREFULLY !!! COMMENT ARE IN CAPITAL LETTERS AND AFTER ## |
---|
| 23 | ## THESE COMMENTS ARE THERE TO GUIDE YOU. YOU CAN REMOVE THEM ONLY WHEN YOU ARE |
---|
| 24 | ## CONFORTABLE ENOUGH WITH OUR MODEL PLUGIN OPTION |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | ## <----- SIGN DEFINES WHERE YOU CAN MODIFY THE CODE |
---|
| 28 | |
---|
| 29 | class Model(Model1DPlugin):##DO NOT CHANGE THIS LINE!!! |
---|
| 30 | """ |
---|
| 31 | ##YOU CAN BE MODIFY ANYTHING BETWEEN """ """ |
---|
| 32 | ##DESCRIPTION OF MODEL PLUG-IN GOES HERE |
---|
| 33 | |
---|
| 34 | ##EXAMPLE:Class that evaluates a cos(x) model. |
---|
| 35 | """ |
---|
[316e231] | 36 | name = "" |
---|
[96814e1] | 37 | |
---|
| 38 | def __init__(self): |
---|
| 39 | """ |
---|
| 40 | Initialization |
---|
| 41 | """ |
---|
| 42 | Model1DPlugin.__init__(self, name= self.name)##DO NOT CHANGE THIS LINE!!! |
---|
| 43 | |
---|
| 44 | ## EDIT PARAMETERS' NAMES AND VALUE |
---|
| 45 | ## DELETE MODIFIABLE LINE HERE WILL REDUCE THE NUMBER OF PARAMETERS |
---|
| 46 | self.params = {} ##DO NOT CHANGE THIS LINE!!! |
---|
[316e231] | 47 | # Set the name same as the file name |
---|
| 48 | self.name = self.get_fname() ##DO NOT CHANGE THIS LINE!!! |
---|
[96814e1] | 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 | |
---|
[316e231] | 88 | ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! |
---|
| 89 | def get_fname(self): |
---|
| 90 | """ |
---|
| 91 | Get the model name same as the file name |
---|
| 92 | """ |
---|
| 93 | path = sys._getframe().f_code.co_filename |
---|
| 94 | basename = os.path.basename(path) |
---|
| 95 | name, _ = os.path.splitext(basename) |
---|
| 96 | return name |
---|
| 97 | |
---|
[7c8d3093] | 98 | ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! |
---|
| 99 | if __name__ == "__main__": |
---|
| 100 | m= Model() |
---|
| 101 | out1 = m.runXY(0.0) |
---|
| 102 | out2 = m.runXY(0.01) |
---|
| 103 | isfine1 = numpy.isfinite(out1) |
---|
| 104 | isfine2 = numpy.isfinite(out2) |
---|
| 105 | print "Testing the value at Q = 0.0:" |
---|
| 106 | print out1, " : finite? ", isfine1 |
---|
| 107 | print "Testing the value at Q = 0.01:" |
---|
| 108 | print out2, " : finite? ", isfine2 |
---|
| 109 | if isfine1 and isfine2: |
---|
| 110 | print "===> Simple Test: Passed!" |
---|
| 111 | else: |
---|
| 112 | print "===> Simple Test: Failed!" |
---|