1 | import math |
---|
2 | |
---|
3 | def toX(x,y=None): |
---|
4 | """ |
---|
5 | This function is used to load value on Plottable.View |
---|
6 | @param x: Float value |
---|
7 | @return x, |
---|
8 | """ |
---|
9 | return x |
---|
10 | |
---|
11 | def toX2(x,y=None): |
---|
12 | """ |
---|
13 | This function is used to load value on Plottable.View |
---|
14 | Calculate x^(2) |
---|
15 | @param x: float value |
---|
16 | """ |
---|
17 | return x*x |
---|
18 | |
---|
19 | def fromX2(x,y=None): |
---|
20 | """ |
---|
21 | This function is used to load value on Plottable.View |
---|
22 | Calculate square root of x |
---|
23 | @param x: float value |
---|
24 | """ |
---|
25 | if not x >=0 : |
---|
26 | raise ValueError, "square root of a negative value " |
---|
27 | else: |
---|
28 | return math.sqrt(x) |
---|
29 | |
---|
30 | def toLogX(x,y=None): |
---|
31 | """ |
---|
32 | This function is used to load value on Plottable.View |
---|
33 | calculate log x |
---|
34 | @param x: float value |
---|
35 | """ |
---|
36 | if not x > 0: |
---|
37 | raise ValueError, "Log(X)of a negative value " |
---|
38 | else: |
---|
39 | return math.log(x) |
---|
40 | |
---|
41 | def toOneOverX(x,y=None): |
---|
42 | if x !=0: |
---|
43 | return 1/x |
---|
44 | else: |
---|
45 | raise ValueError,"cannot divide by zero" |
---|
46 | |
---|
47 | def toOneOverSqrtX(y , x=None): |
---|
48 | if y > 0: |
---|
49 | return 1/math.sqrt(y) |
---|
50 | else: |
---|
51 | raise ValueError,"transform.toOneOverSqrtX: cannot be computed" |
---|
52 | |
---|
53 | |
---|
54 | def toLogYX2(y,x): |
---|
55 | if y*(x**2) >0: |
---|
56 | return math.log(y*(x**2)) |
---|
57 | else: |
---|
58 | raise ValueError,"transform.toLogYX2: cannot be computed" |
---|
59 | |
---|
60 | |
---|
61 | def toLogYX4(y, x): |
---|
62 | if math.pow(x,4)*y > 0: |
---|
63 | return math.log(math.pow(x,4)*y) |
---|
64 | else: |
---|
65 | raise ValueError,"transform.toLogYX4: input error" |
---|
66 | |
---|
67 | def toLogXY(y,x): |
---|
68 | """ |
---|
69 | This function is used to load value on Plottable.View |
---|
70 | calculate log x |
---|
71 | @param x: float value |
---|
72 | """ |
---|
73 | if not x*y > 0: |
---|
74 | raise ValueError, "Log(X*Y)of a negative value " |
---|
75 | else: |
---|
76 | return math.log(x*y) |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | def errToX(x,y=None,dx=None,dy=None): |
---|
81 | """ |
---|
82 | calculate error of x**2 |
---|
83 | @param x: float value |
---|
84 | @param dx: float value |
---|
85 | """ |
---|
86 | if dx==None: |
---|
87 | dx=0 |
---|
88 | return dx |
---|
89 | |
---|
90 | |
---|
91 | def errToX2(x,y=None,dx=None,dy=None): |
---|
92 | """ |
---|
93 | calculate error of x**2 |
---|
94 | @param x: float value |
---|
95 | @param dx: float value |
---|
96 | """ |
---|
97 | if dx != None: |
---|
98 | err = 2*x*dx |
---|
99 | return math.fabs(err) |
---|
100 | else: |
---|
101 | return 0.0 |
---|
102 | |
---|
103 | def errFromX2(x,y=None,dx=None,dy=None): |
---|
104 | """ |
---|
105 | calculate error of sqrt(x) |
---|
106 | @param x: float value |
---|
107 | @param dx: float value |
---|
108 | """ |
---|
109 | if (x > 0): |
---|
110 | if(dx != None): |
---|
111 | err = dx/(2*math.sqrt(x)) |
---|
112 | else: |
---|
113 | err = 0 |
---|
114 | return math.fabs(err) |
---|
115 | else: |
---|
116 | raise ValueError, "transform.errFromX2: can't compute error of negative x" |
---|
117 | |
---|
118 | def errToLog10X(x,y=None,dx=None,dy=None): |
---|
119 | """ |
---|
120 | calculate error of Log(x) |
---|
121 | @param x: float value |
---|
122 | @param dx: float value |
---|
123 | """ |
---|
124 | if dx==None: |
---|
125 | dx = 0 |
---|
126 | if x!=0: |
---|
127 | dx = dx/(x*math.log(10)) |
---|
128 | else: |
---|
129 | raise ValueError, "errToLogX: divide by zero" |
---|
130 | |
---|
131 | return dx |
---|
132 | |
---|
133 | def errToLogX(x,y=None,dx=None,dy=None): |
---|
134 | """ |
---|
135 | calculate error of Log(x) |
---|
136 | @param x: float value |
---|
137 | @param dx: float value |
---|
138 | """ |
---|
139 | if dx==None: |
---|
140 | dx = 0 |
---|
141 | if x!=0: |
---|
142 | dx = dx/x |
---|
143 | else: |
---|
144 | raise ValueError, "errToLogX: divide by zero" |
---|
145 | |
---|
146 | return dx |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | def errToYX2(x, y, dx=None, dy=None): |
---|
151 | if dx==None: |
---|
152 | dx=0 |
---|
153 | if dy==None: |
---|
154 | dy=0 |
---|
155 | err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2) |
---|
156 | return err |
---|
157 | |
---|
158 | def errToLogXY(x,y,dx=None, dy=None): |
---|
159 | """ |
---|
160 | calculate error of Log(xy) |
---|
161 | """ |
---|
162 | if (x!=0) and (y!=0): |
---|
163 | if dx == None: |
---|
164 | dx = 0 |
---|
165 | if dy == None: |
---|
166 | dy = 0 |
---|
167 | err = (dx/x)**2 + (dy/y)**2 |
---|
168 | else: |
---|
169 | raise ValueError, "cannot compute this error" |
---|
170 | |
---|
171 | return math.sqrt(math.fabs(err)) |
---|
172 | |
---|
173 | def errToLogYX2(x,y,dx=None, dy=None): |
---|
174 | """ |
---|
175 | calculate error of Log(yx**2) |
---|
176 | """ |
---|
177 | if (x > 0) and (y > 0): |
---|
178 | if (dx == None): |
---|
179 | dx = 0 |
---|
180 | if (dy == None): |
---|
181 | dy = 0 |
---|
182 | err = (2.0*dx/x)**2 + (dy/y)**2 |
---|
183 | else: |
---|
184 | raise ValueError, "cannot compute this error" |
---|
185 | |
---|
186 | return math.sqrt(math.fabs(err)) |
---|
187 | |
---|
188 | def errOneOverX(x,y=None,dx=None, dy=None): |
---|
189 | """ |
---|
190 | calculate error on 1/x |
---|
191 | """ |
---|
192 | if (x != 0): |
---|
193 | if dx ==None: |
---|
194 | dx= 0 |
---|
195 | err = dx/x**2 |
---|
196 | else: |
---|
197 | raise ValueError,"Cannot compute this error" |
---|
198 | |
---|
199 | return math.fabs(err) |
---|
200 | |
---|
201 | def errOneOverSqrtX(x,y=None, dx=None,dy=None): |
---|
202 | """ |
---|
203 | Calculate error on 1/sqrt(x) |
---|
204 | """ |
---|
205 | if (x >0): |
---|
206 | if dx==None: |
---|
207 | dx =0 |
---|
208 | err= -1/2*math.pow(x, -3.0/2.0)* dx |
---|
209 | else: |
---|
210 | raise ValueError, "Cannot compute this error" |
---|
211 | |
---|
212 | return math.fabs(err) |
---|
213 | |
---|
214 | def errToLogYX4(x,y=None,dx=None,dy=None): |
---|
215 | """ |
---|
216 | error for ln(y*x^(4)) |
---|
217 | @param x: float value |
---|
218 | """ |
---|
219 | if dx==None: |
---|
220 | dx=0 |
---|
221 | if dy==None: |
---|
222 | dy=0 |
---|
223 | err =math.sqrt((4.0*dx/x)**2 +(dy/y)**2) |
---|
224 | return err |
---|
225 | |
---|
226 | |
---|