Changeset 3477478 in sasview for src/sas/plottools/transform.py
- Timestamp:
- Mar 5, 2015 10:38:29 AM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b9dbd6b
- Parents:
- 2df0b74
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/transform.py
r79492222 r3477478 1 1 import math 2 3 2 3 4 4 def toX(x, y=None): 5 5 """ 6 6 This function is used to load value on Plottable.View 7 7 8 8 :param x: Float value 9 9 10 10 :return: x 11 11 12 12 """ 13 13 return x … … 17 17 """ 18 18 This function is used to load value on Plottable.View 19 19 20 20 :param x: Float value 21 21 22 22 :return: x 23 23 24 24 """ 25 25 if not x > 0: … … 32 32 """ 33 33 This function is used to load value on Plottable.View 34 34 35 35 Calculate x^(2) 36 37 :param x: float value 38 36 37 :param x: float value 38 39 39 """ 40 40 return x * x … … 45 45 This function is used to load value on Plottable.View 46 46 Calculate square root of x 47 48 :param x: float value 49 47 48 :param x: float value 49 50 50 """ 51 51 if not x >= 0: … … 58 58 """ 59 59 This function is used to load value on Plottable.View 60 60 61 61 Calculate x^(4) 62 63 :param x: float value 64 62 63 :param x: float value 64 65 65 """ 66 66 return x * x * x * x … … 71 71 This function is used to load value on Plottable.View 72 72 Calculate square root of x 73 74 :param x: float value 75 73 74 :param x: float value 75 76 76 """ 77 77 if not x >= 0: … … 79 79 else: 80 80 return math.sqrt(math.sqrt(x)) 81 81 82 82 83 83 def toLogX(x, y=None): … … 85 85 This function is used to load value on Plottable.View 86 86 calculate log x 87 88 :param x: float value 89 87 88 :param x: float value 89 90 90 """ 91 91 if not x > 0: … … 93 93 else: 94 94 return math.log(x) 95 95 96 96 def toOneOverX(x, y=None): 97 97 """ 98 98 """ 99 99 if x != 0: 100 return 1 /x100 return 1 / x 101 101 else: 102 102 raise ValueError, "cannot divide by zero" 103 104 103 104 105 105 def toOneOverSqrtX(y, x=None): 106 106 """ 107 107 """ 108 108 if y > 0: 109 return 1 /math.sqrt(y)109 return 1 / math.sqrt(y) 110 110 else: 111 111 raise ValueError, "transform.toOneOverSqrtX: cannot be computed" 112 113 112 113 114 114 def toLogYX2(y, x): 115 115 """ 116 116 """ 117 if (y * (x **2)) > 0:118 return math.log(y * (x **2))117 if (y * (x ** 2)) > 0: 118 return math.log(y * (x ** 2)) 119 119 else: 120 120 raise ValueError, "transform.toLogYX2: cannot be computed" 121 122 121 122 123 123 def toLogYX4(y, x): 124 124 """ 125 125 """ 126 126 if (math.pow(x, 4) * y) > 0: 127 return math.log(math.pow(x, 4) * y)128 else: 129 raise ValueError, "transform.toLogYX4: input error"130 131 127 return math.log(math.pow(x, 4) * y) 128 else: 129 raise ValueError, "transform.toLogYX4: input error" 130 131 132 132 def toYX4(y, x): 133 133 """ … … 144 144 This function is used to load value on Plottable.View 145 145 calculate log x 146 147 :param x: float value 148 146 147 :param x: float value 148 149 149 """ 150 150 if not (x * y) > 0: … … 157 157 """ 158 158 calculate error of x**2 159 160 :param x: float value 161 :param dx: float value 162 159 160 :param x: float value 161 :param dx: float value 162 163 163 """ 164 164 if dx == None: … … 170 170 """ 171 171 calculate error of x**2 172 173 :param x: float value 174 :param dx: float value 175 172 173 :param x: float value 174 :param dx: float value 175 176 176 """ 177 177 if dx == None: … … 183 183 """ 184 184 calculate error of x**2 185 186 :param x: float value 187 :param dx: float value 188 185 186 :param x: float value 187 :param dx: float value 188 189 189 """ 190 190 if dx != None: … … 193 193 else: 194 194 return 0.0 195 196 195 196 197 197 def errFromX2(x, y=None, dx=None, dy=None): 198 198 """ 199 199 calculate error of sqrt(x) 200 201 :param x: float value 202 :param dx: float value 203 204 """ 205 if (x > 0):206 if (dx != None):200 201 :param x: float value 202 :param dx: float value 203 204 """ 205 if x > 0: 206 if dx != None: 207 207 err = dx / (2 * math.sqrt(x)) 208 208 else: … … 217 217 """ 218 218 calculate error of x**4 219 220 :param x: float value 221 :param dx: float value 222 223 """ 224 if 219 220 :param x: float value 221 :param dx: float value 222 223 """ 224 if dx != None: 225 225 err = 4 * math.pow(x, 3) * dx 226 226 return math.fabs(err) 227 227 else: 228 228 return 0.0 229 230 229 230 231 231 def errFromX4(x, y=None, dx=None, dy=None): 232 232 """ 233 233 calculate error of x^1/4 234 235 :param x: float value 236 :param dx: float value 237 238 """ 239 if (x > 0):240 if (dx != None):241 err = dx / (4 * math.pow(x, 3 /4))234 235 :param x: float value 236 :param dx: float value 237 238 """ 239 if x > 0: 240 if dx != None: 241 err = dx / (4 * math.pow(x, 3 / 4)) 242 242 else: 243 243 err = 0 … … 246 246 msg = "transform.errFromX4: can't compute error of negative x" 247 247 raise ValueError, msg 248 249 248 249 250 250 def errToLog10X(x, y=None, dx=None, dy=None): 251 251 """ 252 252 calculate error of Log(x) 253 254 :param x: float value 255 :param dx: float value 256 257 """ 258 if dx == None: 259 dx = 0 260 253 254 :param x: float value 255 :param dx: float value 256 257 """ 258 if dx == None: 259 dx = 0 260 261 261 # Check that the point on the graph is positive 262 262 # within errors … … 270 270 raise ValueError, "errToLogX: divide by zero" 271 271 return dx 272 273 272 273 274 274 def errToLogX(x, y=None, dx=None, dy=None): 275 275 """ 276 276 calculate error of Log(x) 277 278 :param x: float value 279 :param dx: float value 280 281 """ 282 if dx == None: 283 dx = 0 284 277 278 :param x: float value 279 :param dx: float value 280 281 """ 282 if dx == None: 283 dx = 0 284 285 285 # Check that the x point on the graph is zero 286 286 if x != 0: 287 dx = dx /x287 dx = dx / x 288 288 else: 289 289 raise ValueError, "errToLogX: divide by zero" … … 298 298 if dy == None: 299 299 dy = 0 300 err = math.sqrt((2 * x * y * dx) **2 + ((x**2) * dy)**2)300 err = math.sqrt((2 * x * y * dx) ** 2 + ((x ** 2) * dy) ** 2) 301 301 return err 302 303 302 303 304 304 def errToLogXY(x, y, dx=None, dy=None): 305 305 """ 306 306 calculate error of Log(xy) 307 307 308 """ 309 # Check that the point on the graph is positive 310 # within errors 311 if not (x - dx) > 0 or not (y - dy) > 0: 312 msg = "Transformation does not accept point " 313 msg += " that are consistent with zero." 314 raise ValueError, msg 315 if x != 0 and y != 0: 316 if dx == None: 317 dx = 0 318 if dy == None: 319 dy = 0 320 err = (dx / x) ** 2 + (dy / y) ** 2 321 else: 322 raise ValueError, "cannot compute this error" 323 324 return math.sqrt(math.fabs(err)) 325 326 327 def errToLogYX2(x, y, dx=None, dy=None): 328 """ 329 calculate error of Log(yx**2) 330 331 """ 332 # Check that the point on the graph is positive 333 # within errors 334 if not (x - dx) > 0 or not (y - dy) > 0: 335 msg = "Transformation does not accept point" 336 msg += " that are consistent with zero." 337 raise ValueError, msg 338 if x > 0 and y > 0: 339 if dx == None: 340 dx = 0 341 if dy == None: 342 dy = 0 343 err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 344 else: 345 raise ValueError, "cannot compute this error" 346 return math.sqrt(math.fabs(err)) 347 348 349 def errOneOverX(x, y=None, dx=None, dy=None): 350 """ 351 calculate error on 1/x 352 353 """ 354 if x != 0: 355 if dx == None: 356 dx = 0 357 err = dx / x ** 2 358 else: 359 raise ValueError, "Cannot compute this error" 360 return math.fabs(err) 361 362 363 def errOneOverSqrtX(x, y=None, dx=None, dy=None): 364 """ 365 Calculate error on 1/sqrt(x) 366 367 """ 368 if x > 0: 369 if dx == None: 370 dx = 0 371 err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 372 else: 373 raise ValueError, "Cannot compute this error" 374 return math.fabs(err) 375 376 377 def errToLogYX4(x, y=None, dx=None, dy=None): 378 """ 379 error for ln(y*x^(4)) 380 381 :param x: float value 382 308 383 """ 309 384 # Check that the point on the graph is positive … … 313 388 msg += " that are consistent with zero." 314 389 raise ValueError, msg 315 if (x != 0) and (y != 0): 316 if dx == None: 317 dx = 0 318 if dy == None: 319 dy = 0 320 err = (dx/x)**2 + (dy/y)**2 321 else: 322 raise ValueError, "cannot compute this error" 323 324 return math.sqrt(math.fabs(err)) 325 326 327 def errToLogYX2(x, y, dx=None, dy=None): 328 """ 329 calculate error of Log(yx**2) 330 390 if dx == None: 391 dx = 0 392 if dy == None: 393 dy = 0 394 err = math.sqrt((4.0 * dx / x) ** 2 + (dy / y) ** 2) 395 return err 396 397 398 def errToYX4(x, y=None, dx=None, dy=None): 399 """ 400 error for (y*x^(4)) 401 402 :param x: float value 403 331 404 """ 332 405 # Check that the point on the graph is positive 333 406 # within errors 334 if (not (x - dx) > 0) or (not (y - dy) > 0): 335 msg = "Transformation does not accept point" 336 msg += " that are consistent with zero." 337 raise ValueError, msg 338 if (x > 0) and (y > 0): 339 if (dx == None): 340 dx = 0 341 if (dy == None): 342 dy = 0 343 err = (2.0*dx/x)**2 + (dy/y)**2 344 else: 345 raise ValueError, "cannot compute this error" 346 return math.sqrt(math.fabs(err)) 347 348 349 def errOneOverX(x, y=None, dx=None, dy=None): 350 """ 351 calculate error on 1/x 352 353 """ 354 if (x != 0): 355 if dx == None: 356 dx = 0 357 err = dx/x**2 358 else: 359 raise ValueError, "Cannot compute this error" 360 return math.fabs(err) 361 362 363 def errOneOverSqrtX(x, y=None, dx=None, dy=None): 364 """ 365 Calculate error on 1/sqrt(x) 366 367 """ 368 if (x > 0): 369 if dx == None: 370 dx = 0 371 err = -1/2*math.pow(x, -3.0/2.0) * dx 372 else: 373 raise ValueError, "Cannot compute this error" 374 return math.fabs(err) 375 376 377 def errToLogYX4(x, y=None, dx=None, dy=None): 378 """ 379 error for ln(y*x^(4)) 380 381 :param x: float value 382 383 """ 384 # Check that the point on the graph is positive 385 # within errors 386 if (not (x - dx) > 0) or (not (y - dy) > 0): 387 msg = "Transformation does not accept point " 388 msg += " that are consistent with zero." 389 raise ValueError, msg 407 390 408 if dx == None: 391 409 dx = 0 392 410 if dy == None: 393 411 dy = 0 394 err = math.sqrt(( 4.0 * dx/x)**2 + (dy/y)**2)412 err = math.sqrt((dy * pow(x, 4)) ** 2 + (4 * y * dx * math.pow(x, 3)) ** 2) 395 413 return err 396 397 398 def errToYX4(x, y=None, dx=None, dy=None):399 """400 error for (y*x^(4))401 402 :param x: float value403 404 """405 # Check that the point on the graph is positive406 # within errors407 408 if dx == None:409 dx = 0410 if dy == None:411 dy = 0412 err = math.sqrt((dy * pow(x, 4))**2 + (4 * y * dx * math.pow(x, 3))**2)413 return err
Note: See TracChangeset
for help on using the changeset viewer.