[831149e] | 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 | |
---|
[ad8bcd6] | 11 | def toX_pos(x,y=None): |
---|
| 12 | """ |
---|
| 13 | This function is used to load value on Plottable.View |
---|
| 14 | @param x: Float value |
---|
| 15 | @return x, |
---|
| 16 | """ |
---|
| 17 | if not x>0: |
---|
| 18 | raise ValueError, "Transformation only accepts positive values." |
---|
| 19 | else: |
---|
| 20 | return x |
---|
| 21 | |
---|
[831149e] | 22 | def toX2(x,y=None): |
---|
| 23 | """ |
---|
| 24 | This function is used to load value on Plottable.View |
---|
| 25 | Calculate x^(2) |
---|
| 26 | @param x: float value |
---|
| 27 | """ |
---|
| 28 | return x*x |
---|
| 29 | |
---|
| 30 | def fromX2(x,y=None): |
---|
| 31 | """ |
---|
| 32 | This function is used to load value on Plottable.View |
---|
| 33 | Calculate square root of x |
---|
| 34 | @param x: float value |
---|
| 35 | """ |
---|
| 36 | if not x >=0 : |
---|
| 37 | raise ValueError, "square root of a negative value " |
---|
| 38 | else: |
---|
| 39 | return math.sqrt(x) |
---|
[05da1f89] | 40 | |
---|
[831149e] | 41 | def toLogX(x,y=None): |
---|
| 42 | """ |
---|
| 43 | This function is used to load value on Plottable.View |
---|
| 44 | calculate log x |
---|
| 45 | @param x: float value |
---|
| 46 | """ |
---|
| 47 | if not x > 0: |
---|
[ad8bcd6] | 48 | raise ValueError, "Log(x)of a negative value " |
---|
[831149e] | 49 | else: |
---|
| 50 | return math.log(x) |
---|
| 51 | |
---|
| 52 | def toOneOverX(x,y=None): |
---|
| 53 | if x !=0: |
---|
| 54 | return 1/x |
---|
| 55 | else: |
---|
| 56 | raise ValueError,"cannot divide by zero" |
---|
[05da1f89] | 57 | |
---|
[f193585] | 58 | def toOneOverSqrtX(y , x=None): |
---|
[05da1f89] | 59 | if y > 0: |
---|
| 60 | return 1/math.sqrt(y) |
---|
| 61 | else: |
---|
| 62 | raise ValueError,"transform.toOneOverSqrtX: cannot be computed" |
---|
[831149e] | 63 | |
---|
[f193585] | 64 | |
---|
| 65 | def toLogYX2(y,x): |
---|
[831149e] | 66 | if y*(x**2) >0: |
---|
| 67 | return math.log(y*(x**2)) |
---|
| 68 | else: |
---|
[05da1f89] | 69 | raise ValueError,"transform.toLogYX2: cannot be computed" |
---|
[831149e] | 70 | |
---|
| 71 | |
---|
[f193585] | 72 | def toLogYX4(y, x): |
---|
[831149e] | 73 | if math.pow(x,4)*y > 0: |
---|
| 74 | return math.log(math.pow(x,4)*y) |
---|
[05da1f89] | 75 | else: |
---|
| 76 | raise ValueError,"transform.toLogYX4: input error" |
---|
[831149e] | 77 | |
---|
[f193585] | 78 | def toLogXY(y,x): |
---|
[831149e] | 79 | """ |
---|
| 80 | This function is used to load value on Plottable.View |
---|
| 81 | calculate log x |
---|
| 82 | @param x: float value |
---|
| 83 | """ |
---|
| 84 | if not x*y > 0: |
---|
| 85 | raise ValueError, "Log(X*Y)of a negative value " |
---|
| 86 | else: |
---|
| 87 | return math.log(x*y) |
---|
[8e44d51] | 88 | |
---|
[831149e] | 89 | |
---|
[46693050] | 90 | |
---|
[831149e] | 91 | def errToX(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 | """ |
---|
[f193585] | 97 | if dx==None: |
---|
| 98 | dx=0 |
---|
[831149e] | 99 | return dx |
---|
| 100 | |
---|
[ad8bcd6] | 101 | def errToX_pos(x,y=None,dx=None,dy=None): |
---|
| 102 | """ |
---|
| 103 | calculate error of x**2 |
---|
| 104 | @param x: float value |
---|
| 105 | @param dx: float value |
---|
| 106 | """ |
---|
| 107 | if dx==None: |
---|
| 108 | dx=0 |
---|
| 109 | |
---|
| 110 | # Check that the point on the graph is positive |
---|
| 111 | # within errors |
---|
| 112 | if not x-dx > 0: |
---|
| 113 | raise ValueError, "Transformation does not accept point that are consistent with zero." |
---|
| 114 | |
---|
| 115 | return dx |
---|
| 116 | |
---|
[831149e] | 117 | |
---|
| 118 | def errToX2(x,y=None,dx=None,dy=None): |
---|
| 119 | """ |
---|
| 120 | calculate error of x**2 |
---|
| 121 | @param x: float value |
---|
| 122 | @param dx: float value |
---|
| 123 | """ |
---|
| 124 | if dx != None: |
---|
| 125 | err = 2*x*dx |
---|
| 126 | return math.fabs(err) |
---|
| 127 | else: |
---|
| 128 | return 0.0 |
---|
[05da1f89] | 129 | |
---|
[831149e] | 130 | def errFromX2(x,y=None,dx=None,dy=None): |
---|
| 131 | """ |
---|
| 132 | calculate error of sqrt(x) |
---|
| 133 | @param x: float value |
---|
| 134 | @param dx: float value |
---|
| 135 | """ |
---|
| 136 | if (x > 0): |
---|
| 137 | if(dx != None): |
---|
| 138 | err = dx/(2*math.sqrt(x)) |
---|
| 139 | else: |
---|
| 140 | err = 0 |
---|
| 141 | return math.fabs(err) |
---|
[05da1f89] | 142 | else: |
---|
| 143 | raise ValueError, "transform.errFromX2: can't compute error of negative x" |
---|
| 144 | |
---|
[2e07e8f] | 145 | def errToLog10X(x,y=None,dx=None,dy=None): |
---|
| 146 | """ |
---|
| 147 | calculate error of Log(x) |
---|
| 148 | @param x: float value |
---|
| 149 | @param dx: float value |
---|
| 150 | """ |
---|
| 151 | if dx==None: |
---|
| 152 | dx = 0 |
---|
[ad8bcd6] | 153 | |
---|
| 154 | # Check that the point on the graph is positive |
---|
| 155 | # within errors |
---|
| 156 | if not x-dx > 0: |
---|
| 157 | raise ValueError, "Transformation does not accept point that are consistent with zero." |
---|
| 158 | |
---|
[2e07e8f] | 159 | if x!=0: |
---|
| 160 | dx = dx/(x*math.log(10)) |
---|
| 161 | else: |
---|
| 162 | raise ValueError, "errToLogX: divide by zero" |
---|
| 163 | |
---|
| 164 | return dx |
---|
[831149e] | 165 | |
---|
| 166 | def errToLogX(x,y=None,dx=None,dy=None): |
---|
| 167 | """ |
---|
| 168 | calculate error of Log(x) |
---|
| 169 | @param x: float value |
---|
| 170 | @param dx: float value |
---|
| 171 | """ |
---|
| 172 | if dx==None: |
---|
| 173 | dx = 0 |
---|
[ad8bcd6] | 174 | |
---|
| 175 | # Check that the point on the graph is positive |
---|
| 176 | # within errors |
---|
| 177 | if not x-dx > 0: |
---|
| 178 | raise ValueError, "Transformation does not accept point that are consistent with zero." |
---|
| 179 | |
---|
[46693050] | 180 | if x!=0: |
---|
| 181 | dx = dx/x |
---|
| 182 | else: |
---|
| 183 | raise ValueError, "errToLogX: divide by zero" |
---|
| 184 | |
---|
[831149e] | 185 | return dx |
---|
| 186 | |
---|
[2e014bf] | 187 | |
---|
[831149e] | 188 | |
---|
| 189 | def errToYX2(x, y, dx=None, dy=None): |
---|
| 190 | if dx==None: |
---|
| 191 | dx=0 |
---|
| 192 | if dy==None: |
---|
| 193 | dy=0 |
---|
| 194 | err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2) |
---|
| 195 | return err |
---|
| 196 | |
---|
| 197 | def errToLogXY(x,y,dx=None, dy=None): |
---|
| 198 | """ |
---|
| 199 | calculate error of Log(xy) |
---|
| 200 | """ |
---|
[ad8bcd6] | 201 | # Check that the point on the graph is positive |
---|
| 202 | # within errors |
---|
| 203 | if (not x-dx > 0) or (not y-dy > 0): |
---|
| 204 | raise ValueError, "Transformation does not accept point that are consistent with zero." |
---|
| 205 | |
---|
[831149e] | 206 | if (x!=0) and (y!=0): |
---|
| 207 | if dx == None: |
---|
| 208 | dx = 0 |
---|
| 209 | if dy == None: |
---|
| 210 | dy = 0 |
---|
| 211 | err = (dx/x)**2 + (dy/y)**2 |
---|
| 212 | else: |
---|
| 213 | raise ValueError, "cannot compute this error" |
---|
| 214 | |
---|
| 215 | return math.sqrt(math.fabs(err)) |
---|
| 216 | |
---|
| 217 | def errToLogYX2(x,y,dx=None, dy=None): |
---|
| 218 | """ |
---|
| 219 | calculate error of Log(yx**2) |
---|
| 220 | """ |
---|
[ad8bcd6] | 221 | # Check that the point on the graph is positive |
---|
| 222 | # within errors |
---|
| 223 | if (not x-dx > 0) or (not y-dy > 0): |
---|
| 224 | raise ValueError, "Transformation does not accept point that are consistent with zero." |
---|
| 225 | |
---|
[831149e] | 226 | if (x > 0) and (y > 0): |
---|
| 227 | if (dx == None): |
---|
| 228 | dx = 0 |
---|
| 229 | if (dy == None): |
---|
| 230 | dy = 0 |
---|
[05da1f89] | 231 | err = (2.0*dx/x)**2 + (dy/y)**2 |
---|
[831149e] | 232 | else: |
---|
| 233 | raise ValueError, "cannot compute this error" |
---|
| 234 | |
---|
| 235 | return math.sqrt(math.fabs(err)) |
---|
| 236 | |
---|
| 237 | def errOneOverX(x,y=None,dx=None, dy=None): |
---|
| 238 | """ |
---|
| 239 | calculate error on 1/x |
---|
| 240 | """ |
---|
| 241 | if (x != 0): |
---|
| 242 | if dx ==None: |
---|
| 243 | dx= 0 |
---|
[05da1f89] | 244 | err = dx/x**2 |
---|
[831149e] | 245 | else: |
---|
| 246 | raise ValueError,"Cannot compute this error" |
---|
| 247 | |
---|
| 248 | return math.fabs(err) |
---|
| 249 | |
---|
| 250 | def errOneOverSqrtX(x,y=None, dx=None,dy=None): |
---|
| 251 | """ |
---|
| 252 | Calculate error on 1/sqrt(x) |
---|
| 253 | """ |
---|
| 254 | if (x >0): |
---|
| 255 | if dx==None: |
---|
| 256 | dx =0 |
---|
[05da1f89] | 257 | err= -1/2*math.pow(x, -3.0/2.0)* dx |
---|
[831149e] | 258 | else: |
---|
| 259 | raise ValueError, "Cannot compute this error" |
---|
| 260 | |
---|
| 261 | return math.fabs(err) |
---|
[05da1f89] | 262 | |
---|
[8e44d51] | 263 | def errToLogYX4(x,y=None,dx=None,dy=None): |
---|
| 264 | """ |
---|
| 265 | error for ln(y*x^(4)) |
---|
| 266 | @param x: float value |
---|
| 267 | """ |
---|
[ad8bcd6] | 268 | # Check that the point on the graph is positive |
---|
| 269 | # within errors |
---|
| 270 | if (not x-dx > 0) or (not y-dy > 0): |
---|
| 271 | raise ValueError, "Transformation does not accept point that are consistent with zero." |
---|
| 272 | |
---|
[8e44d51] | 273 | if dx==None: |
---|
| 274 | dx=0 |
---|
| 275 | if dy==None: |
---|
| 276 | dy=0 |
---|
[05da1f89] | 277 | err =math.sqrt((4.0*dx/x)**2 +(dy/y)**2) |
---|
[8e44d51] | 278 | return err |
---|
[831149e] | 279 | |
---|
| 280 | |
---|