- Timestamp:
- Apr 9, 2008 6:19:25 PM (17 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:
- 7a03e65
- Parents:
- f52bea1
- Location:
- guitools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
rf52bea1 r3d3a0e5 148 148 else: 149 149 raise ValueError,"cannot be computed" 150 def toLogYX2(self ):150 def toLogYX2(self,x,y): 151 151 if y*(x**2) >0: 152 152 return math.log(y*(x**2)) 153 153 else: 154 154 raise ValueError,"cannot be computed" 155 156 157 def toYX2(self,x,y): 158 return (x**2)*y 159 160 161 def toXY(self,x,y): 162 return x*y 163 164 155 165 def toLogXY(self,x,y): 156 166 """ … … 432 442 name, units = item.get_yaxis() 433 443 self.graph.yaxis("%s^2" % name, "%s^{-2}" % units) 444 if ( self.yscales =="1/y"): 445 item.transform_y( self.toOneOverX ,self.errOneOverX ) 446 self.set_yscale("linear") 447 name, units = item.get_yaxis() 448 self.graph.yaxis("%s" % name, "%s" % units) 449 if ( self.yscales =="1/sqrt(y)" ): 450 item.transform_y( self.toOneOverSqrtX ,self.errOneOverSqrtX ) 451 self.set_yscale("linear") 452 name, units = item.get_yaxis() 453 self.graph.yaxis("%s" %name, "%s" % units) 454 if ( self.yscales =="Log(y*x)"): 455 item.transform_xy( self.toXY ,self.errToXY ) 456 self.set_yscale("log") 457 yname, yunits = item.get_yaxis() 458 xname, xunits = item.get_xaxis() 459 self.graph.yaxis("%s"+"*"+"%s" % (yname,xname), "%s^{-1}"+"*"+"s^{-1}" % (yunits,xunits)) 460 if ( self.yscales =="Log(y*x^(2)"): 461 item.transform_xy( self.toYX2 ,self.errToYX2 ) 462 self.set_yscale("log") 463 yname, yunits = item.get_yaxis() 464 xname, xunits = item.get_xaxis() 465 self.graph.yaxis("%s"+"*"+"%s^{2}" % (yname,xname), "%s^{-1}"+"*"+"s^{-2}" % (yunits,xunits)) 434 466 435 467 self.prevXtrans = self.xscales … … 500 532 501 533 return math.fabs(err) 534 def errToXY(self, x, y, dx=None, dy=None): 535 if dx==None: 536 dx=0 537 if dy==None: 538 dy=0 539 err =math.sqrt((y*dx)**2 +(x*dy)**2) 540 if err >= math.fabs(x): 541 err =0.9*x 542 return err 543 def errToYX2(self, x, y, dx=None, dy=None): 544 if dx==None: 545 dx=0 546 if dy==None: 547 dy=0 548 err =math.sqrt((2*x*y*dx)**2 +((x**2)*dy)**2) 549 if err >= math.fabs(x): 550 err =0.9*x 551 return err 502 552 503 553 def errToLogXY(self,x,y,dx=None, dy=None): … … 505 555 calculate error of Log(xy) 506 556 """ 507 if dx==None: 508 err = x*(dy**2)/y 509 elif dy==None: 510 err = y*(dx**2)/x 511 elif (x!=0) and (y!=0): 512 err = y*(dx**2)/x + x*(dy**2)/y 513 if err >= 0: 514 if math.sqrt(err)> x: 557 if (x!=0) and (y!=0): 558 if dx == None: 559 dx = 0 560 if dy == None: 561 dy = 0 562 err = (dx/x)**2 + (dy/y)**2 563 if math.sqrt(math.fabs(err)) >= math.fabs(x): 515 564 err= 0.9*x 516 return math.sqrt(err)517 565 else: 518 566 raise ValueError, "cannot compute this error" 567 568 return math.sqrt(math.fabs(err)) 569 570 def errToLogYX2(self,x,y,dx=None, dy=None): 571 """ 572 calculate error of Log(yx**2) 573 """ 574 if (x > 0) and (y > 0): 575 if (dx == None): 576 dx = 0 577 if (dy == None): 578 dy = 0 579 err = 4*(dx**2)/(x**2) + (dy**2)/(y**2) 580 if math.fabs(err) >= math.fabs(x): 581 err =0.9*x 582 else: 583 raise ValueError, "cannot compute this error" 584 585 return math.sqrt(math.fabs(err)) 586 587 def errOneOverX(self,x,dx): 588 """ 589 calculate error on 1/x 590 """ 591 if (x != 0) and (dx!=None): 592 if dx ==None: 593 dx= 0 594 err = -(dx)**2/x**2 595 else: 596 raise ValueError,"Cannot compute this error" 597 598 if math.fabs(err)>= math.fabs(x): 599 err= 0.9*x 600 return math.fabs(err) 601 602 def errOneOverSqrtX(self): 603 """ 604 Calculate error on 1/sqrt(x) 605 """ 606 if (x >0) and (dx!=None): 607 if dx==None: 608 dx =0 609 err= -1/2*math.pow(x, -3/2)* dx 610 if math.fabs(err)>= math.fabs(x): 611 err=0.9*x 612 else: 613 raise ValueError, "Cannot compute this error" 614 615 return math.fabs(err) 616 519 617 520 618 def onFitDisplay(self, plottable): -
guitools/plottables.py
rf52bea1 r3d3a0e5 391 391 self.view.transform_y(func, errfunc, self.y, self.dy) 392 392 393 def transform_xy(self,func,errfunc): 394 """ 395 @param func: reference to y transformation function 396 397 """ 398 self.view.transform_xy(func, errfunc, self.x, self.y,self.dx,self.dy) 399 393 400 def returnValuesOfView(self): 394 401 … … 460 467 else: 461 468 self.dy[i] = errfunc(y[i]) 469 def transform_xy(self, func, errfunc, x, y, dx, dy): 470 """ 471 Transforms the x, y, dx,and dy vectors and stores the output. 472 473 @param func: function to apply to the data 474 @param x: array of x values 475 @param dx: array of error values 476 @param y: array of y values 477 @param dy: array of error values 478 @param errfunc: function to apply to errors 479 """ 480 import copy 481 import numpy 482 # Sanity check 483 if dx and not len(x)==len(dx): 484 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 485 if dy and not len(y)==len(dy): 486 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 487 if not len(x)==len(y): 488 raise ValueError, "Plottable.View: Given x and y are not of the same length" 489 490 self.x = numpy.zeros(len(x)) 491 self.dx = numpy.zeros(len(x)) 492 self.y = numpy.zeros(len(y)) 493 self.dy = numpy.zeros(len(y)) 494 495 496 for i in range(len(y)): 497 self.y[i] = func(x[i],y[i]) 498 if (dx!=None) and (dy !=None): 499 self.dy[i] = errfunc(x[i], y[i], dx[i], dy[i]) 500 elif (dx != None): 501 self.dy[i] = errfunc(x[i], y[i], dx[i]) 502 elif (dy != None): 503 self.dy[i] = errfunc(x[i], y[i],dy[i]) 504 else: 505 self.dy[i] = errfunc(x[i], y[i]) 462 506 463 507 def returnXview(self): -
guitools/requirements.txt
rf52bea1 r3d3a0e5 51 51 52 52 2- There are additional y scales we need: y, y^2, log(y), 1/y, 1/sqrt(y), log(y * x), log(y * x^2) 53 [QUESTION] when plottong y=log(y*x) is the user allowed to do transformation on x at the same time 54 for example x---> log X with y=log(x*y) 55 [PROBLEM]WITH log(y * x), log(y * x^2) 53 56 54 57 3-[DONE] You should change the label according to what the user chose, and not hard-code them.
Note: See TracChangeset
for help on using the changeset viewer.