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 | import math ##DO NOT CHANGE THIS LINE!!! |
---|
10 | import numpy ##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 | ## DEFINE DEFAULT DETAILS |
---|
51 | self.set_details() ##DO NOT DELETE OR CHANGE THIS LINE!!! |
---|
52 | |
---|
53 | ## YOU CAN MODIFY THE LINE BELLOW.MODIFY WORDS BETWEEN """ """ ONLY!!!! |
---|
54 | self.description = "F(x)=A+Bcos(2x)+Csin(2x) " ## <----- |
---|
55 | |
---|
56 | def function(self, x = 0.0): ##DO NOT CHANGE THIS LINE!!! |
---|
57 | """ |
---|
58 | Evaluate the model |
---|
59 | |
---|
60 | :param x: input x |
---|
61 | |
---|
62 | :return: function value |
---|
63 | |
---|
64 | """ |
---|
65 | ## ADD YOUR FUNCTION HERE. |
---|
66 | ## REUSE THE PARAMETERS DEFINED PREVIOUSLY TO WRITE YOUR FUNCTION. |
---|
67 | |
---|
68 | ## IN THIS EXAMPLE THE FUNTION IS: |
---|
69 | ## A+Bcos(2x)+Csin(2x) |
---|
70 | ## YOU CAN USE math.sin or sin directly |
---|
71 | ## NOTE: sin, cos ARE FUNCTIONS IMPORTED FROM PYTHON MATH LIBRARY |
---|
72 | ## FOR MORE INFORMATION CHECK http://docs.python.org/library/math.html |
---|
73 | ## OTHER FUNCTIONS ARE ALSO |
---|
74 | ## AVAILABLE http://www.scipy.org/Numpy_Functions_by_Category |
---|
75 | ## numpy FUNCTIONS ARE FOR EXPERT USER |
---|
76 | |
---|
77 | return self.params['A']+self.params['B']*math.cos(2.0*x)+self.params['C']*math.sin(2.0*x) |
---|
78 | |
---|
79 | ## DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! |
---|
80 | if __name__ == "__main__": |
---|
81 | m= Model() |
---|
82 | out1 = m.runXY(0.0) |
---|
83 | out2 = m.runXY(0.01) |
---|
84 | isfine1 = numpy.isfinite(out1) |
---|
85 | isfine2 = numpy.isfinite(out2) |
---|
86 | print "Testing the value at Q = 0.0:" |
---|
87 | print out1, " : finite? ", isfine1 |
---|
88 | print "Testing the value at Q = 0.01:" |
---|
89 | print out2, " : finite? ", isfine2 |
---|
90 | if isfine1 and isfine2: |
---|
91 | print "===> Simple Test: Passed!" |
---|
92 | else: |
---|
93 | print "===> Simple Test: Failed!" |
---|