- Timestamp:
- Apr 23, 2008 12:36:40 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:
- 863607a
- Parents:
- 35891ce
- Location:
- guitools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r35891ce r46693050 64 64 # keep track if the previous transformation of x and y in Property dialog 65 65 self.prevXtrans =" " 66 66 67 self.prevYtrans =" " 67 68 … … 343 344 344 345 if (self.xscales=="log10(x)" ): 345 item.transform_x( transform.toX, transform.errTo LogX )346 item.transform_x( transform.toX, transform.errToX ) 346 347 self.set_xscale("log") 347 348 name, units = item.get_xaxis() 349 item.check_data_Plottable() 348 350 self.graph.xaxis("Log10 %s" % name, "%s^{-1}" % units) 349 351 … … 364 366 self.set_yscale("log") 365 367 name, units = item.get_yaxis() 368 #item.check_data_Plottable() 366 369 self.graph.yaxis("Log10 %s" % name, "%s^{-1}" % units) 367 370 … … 392 395 393 396 if ( self.yscales =="ln(y*x^(2))"): 394 item.transform_y( transform.to YX2 ,transform.errToLogYX2 )397 item.transform_y( transform.toLogYX2 ,transform.errToLogYX2 ) 395 398 self.set_yscale("linear") 396 399 yname, yunits = item.get_yaxis() … … 415 418 self.set_yscale("linear") 416 419 name, units = item.get_yaxis() 417 self.graph.yaxis(" Log %s" % name, "%s^{-1}" % units)420 self.graph.yaxis("$Log %s$" % name, "%s^{-1}" % units) 418 421 #item.name = self.yscales+" vs " +self.xscales 419 422 self.prevXtrans = self.xscales … … 422 425 self.graph.render(self) 423 426 self.subplot.figure.canvas.draw_idle() 424 def onFitDisplay(self, plottable): 427 428 def onFitDisplay(self, plottable,xmin,xmax): 425 429 """ 426 430 Add a new plottable into the graph .In this case this plottable will be used … … 428 432 @param plottable: the plottable to plot 429 433 """ 434 list =[] 435 tempx=[] 436 tempy=[] 437 tempdx=[] 438 tempdy=[] 439 #Stored plotted plottable in a new plottable 440 list = self.graph.returnPlottable() 441 if len(list.keys())>0: 442 for item in list: 443 if self.graph.isPlotted(item)== True: 444 x,y,dx,dy = item.returnValuesOfView() 445 if((min(x) < xmin )and( max(x) > xmax ))\ 446 or ((min(x) <= xmin )and( max(x) > xmax ))\ 447 or((min(x) < xmin )and( max(x) >= xmax )): 448 item.reducedXrange(xmin,xmax) 449 else: 450 item.originalXrange() 451 452 453 #Add the data to fit 430 454 plottable.reset_view() 431 455 self.graph.add(plottable) … … 434 458 self.subplot.figure.canvas.draw_idle() 435 459 self.graph.delete(plottable) 460 436 461 437 462 -
guitools/fitDialog.py
r8e44d51 r46693050 245 245 246 246 #Send the data to display to the PlotPanel 247 self.push_data(self.file_data1 )247 self.push_data(self.file_data1,xminView, xmaxView) 248 248 249 249 # Display the fitting value on the Fit Dialog -
guitools/plottables.py
r8e44d51 r46693050 218 218 p.render(plot,color=self.plottables[p],symbol=0,label=labels[p]) 219 219 plot.render() 220 221 def clear(self,plot): 222 plot.clear() 220 223 221 224 def __init__(self,**kw): … … 375 378 """ Reload view with new value to plot""" 376 379 self.view = self.View(self.x, self.y, self.dx, self.dy) 377 380 #save the initial value 381 self.view.Xreel = self.view.x 382 self.view.Yreel = self.view.y 383 self.view.DXreel = self.view.dx 384 self.view.DYreel = self.view.dy 378 385 379 386 … … 412 419 413 420 return self.view.returnXview() 414 421 def check_data_PlottableX(self): 422 self.view.check_data_logX() 423 def check_data_PlottableY(self): 424 self.view.check_data_logY() 425 def originalXrange(self): 426 self.view.reelXrange() 427 def reducedXrange(self,min,max): 428 self.view.reduceXrange(min, max) 415 429 class View: 416 430 """ … … 421 435 dx = None 422 436 dy = None 437 423 438 424 439 def __init__(self, x=None, y=None, dx=None, dy=None): … … 427 442 self.dx = dx 428 443 self.dy = dy 429 444 #to change x range to the reel range 445 self.Xreel = self.x 446 self.Yreel = self.y 447 self.DXreel = self.dx 448 self.DYreel = self.dy 449 430 450 def transform_x(self, func, errfunc, x,y=None,dx=None, dy=None): 431 451 """ … … 452 472 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 453 473 454 self.x = numpy.zeros(len(x))455 self.dx = numpy.zeros(len(x))474 self.x = [] 475 self.dx = [] 456 476 457 477 for i in range(len(x)): 458 478 if has_y: 459 self.x[i] = func(x[i],y[i]) 460 if (dx!=None) and (dy !=None): 461 self.dx[i] = errfunc(x[i], y[i], dx[i], dy[i]) 462 elif (dx != None): 463 self.dx[i] = errfunc(x[i], y[i], dx[i],0) 464 elif (dy != None): 465 self.dx[i] = errfunc(x[i], y[i],0,dy[i]) 466 else: 467 self.dx[i] = errfunc(x[i],y[i],0, 0) 479 try: 480 xtemp = func(x[i],y[i]) 481 482 483 if (dx!=None) and (dy !=None): 484 dxtemp = errfunc(x[i], y[i], dx[i], dy[i]) 485 elif (dx != None): 486 dxtemp = errfunc(x[i], y[i], dx[i],0) 487 elif (dy != None): 488 dxtemp = errfunc(x[i], y[i],0,dy[i]) 489 else: 490 dxtemp = errfunc(x[i],y[i],0, 0) 491 492 self.x.append(xtemp) 493 self.dx.append(dxtemp) 494 self.Xreel = [] 495 self.DXreel=[] 496 self.Xreel = self.x 497 self.DXreel = self.dx 498 499 except: 500 print "View.transform_x: skipping point %g" % x[i] 501 print sys.exc_value 502 503 468 504 else: 469 self.x[i] = func(x[i]) 470 if (dx != None): 471 self.dx[i] = errfunc(x[i], dx[i]) 472 else: 473 self.dx[i] = errfunc(x[i],None) 505 try: 506 xtemp = func(x[i]) 507 if (dx != None): 508 dxtemp = errfunc(x[i], dx[i]) 509 else: 510 dxtemp = errfunc(x[i],None) 511 self.x.append(xtemp) 512 self.dx.append(dxtemp) 513 self.Xreel = [] 514 self.DXreel=[] 515 self.Xreel = self.x 516 self.DXreel = self.dx 517 518 except: 519 print "View.transform_x: skipping point %g" % x[i] 520 print sys.exc_value 474 521 475 522 … … 498 545 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 499 546 500 self.y = numpy.zeros(len(y))501 self.dy = numpy.zeros(len(y))547 self.y = [] 548 self.dy = [] 502 549 503 550 for i in range(len(y)): 504 551 505 552 if has_x: 506 self.y[i] = func(y[i],x[i]) 507 if (dx!=None) and (dy !=None): 508 self.dy[i] = errfunc(y[i], x[i], dy[i], dx[i]) 509 elif (dx != None): 510 self.dy[i] = errfunc(y[i], x[i], 0, dx[i]) 511 elif (dy != None): 512 self.dy[i] = errfunc(y[i], x[i], dy[i], 0) 513 else: 514 self.dy[i] = errfunc(y[i], None) 553 try: 554 tempy = func(y[i],x[i]) 555 if (dx!=None) and (dy !=None): 556 tempdy = errfunc(y[i], x[i], dy[i], dx[i]) 557 elif (dx != None): 558 tempdy = errfunc(y[i], x[i], 0, dx[i]) 559 elif (dy != None): 560 tempdy = errfunc(y[i], x[i], dy[i], 0) 561 else: 562 tempdy = errfunc(y[i], None) 563 self.y.append(tempy) 564 self.dy.append(tempdy) 565 self.Yreel = [] 566 self.DYreel=[] 567 self.Yreel = self.y 568 self.DYreel = self.dy 569 except: 570 print "View.transform_y: skipping point %g" % y[i] 571 print sys.exc_value 572 515 573 else: 516 self.y[i] = func(y[i]) 517 if (dy != None): 518 self.dy[i] = errfunc( y[i],dy[i]) 519 else: 520 self.dy[i] = errfunc( y[i],None) 521 522 574 try: 575 tempy = func(y[i]) 576 if (dy != None): 577 tempdy = errfunc( y[i],dy[i]) 578 else: 579 tempdy = errfunc( y[i],None) 580 self.y.append(tempy) 581 self.dy.append(tempdy) 582 self.Yreel = [] 583 self.DYreel=[] 584 self.Yreel = self.y 585 self.DYreel = self.dy 586 except: 587 print "View.transform_y: skipping point %g" % y[i] 588 print sys.exc_value 589 590 591 523 592 def returnXview(self): 524 593 return self.x,self.y,self.dx,self.dy 525 594 526 def returnValueOfView(self,i): 527 print"this is i:",i 528 if i in range(len(self.x)): 529 print self.x[i] 530 return self.x[i] 595 def checkMin(self,x,min,pos=None): 596 if pos==None: 597 pos=0 598 for i in range(len(self.x)): 599 if not min in x:# The user enters a value not in x 600 if x[i] > min: 601 index= i-1 602 print "this is index",index 603 return index1 604 else: 605 index=i 606 print"the user enter a value inside x",index 607 return index 608 else: 609 index= pos 610 return index 611 612 def checkMax(self,x,max,pos=None): 613 if pos==None: 614 pos=0 615 for i in range(len(self.x)): 616 if not max in x:# The user enters a value not in x 617 if x[i] >max: 618 619 index= i-1 620 return index 621 else: 622 index=i 623 return index 624 else: 625 index= pos 626 return index 627 628 def reduceXrange(self,min,max): 629 630 # to change the x range to the user range 631 self.Xscale = [] 632 self.Yscale = [] 633 self.DXscale = [] 634 self.DYscale = [] 635 indexmin =self.checkMin(self.x,min,None) 636 indexmax =self.checkMin(self.x,max,None) 637 for i in range(len(self.x)): 638 if( self.x[i] >=self.x[indexmin])and( self.x[i] <= max): 639 self.Xscale.append(self.x[i]) 640 self.Yscale.append(self.y[i]) 641 self.DXscale.append(self.dx[i]) 642 self.DYscale.append(self.dy[i]) 643 print self.Xscale 644 self.x= self.Xscale 645 self.y= self.Yscale 646 self.dx= self.DXscale 647 self.dy= self.DYscale 648 649 650 def reelXrange(self): 651 self.x= self.Xreel 652 self.y= self.Yreel 653 self.dx= self.DXreel 654 self.dy= self.DYreel 655 656 657 def check_data_logX(self): 658 tempx=[] 659 tempdx=[] 660 tempy=[] 661 tempdy=[] 662 663 for i in range(len(self.x)): 664 try: 665 if (self.x[i]> 0): 666 667 tempx.append(self.x[i]) 668 tempdx.append(self.dx[i]) 669 tempy.append(self.y[i]) 670 tempdy.append(self.dy[i]) 671 except: 672 #print "View.transform_x: skipping point %g" %self.x[i] 673 print sys.exc_value 674 pass 675 676 self.x=[] 677 self.dx=[] 678 self.y=[] 679 self.dy=[] 680 self.x=tempx 681 self.y=tempy 682 self.dx=tempdx 683 self.dy=tempdy 684 def check_data_logY(self): 685 tempx=[] 686 tempdx=[] 687 tempy=[] 688 tempdy=[] 689 690 for i in range(len(self.x)): 691 try: 692 if (self.y[i]> 0): 693 694 tempx.append(self.x[i]) 695 tempdx.append(self.dx[i]) 696 tempy.append(self.y[i]) 697 tempdy.append(self.dy[i]) 698 except: 699 #print "View.transform_x: skipping point %g" %self.x[i] 700 print sys.exc_value 701 pass 702 703 self.x=[] 704 self.dx=[] 705 self.y=[] 706 self.dy=[] 707 self.x=tempx 708 self.y=tempy 709 self.dx=tempdx 710 self.dy=tempdy 711 712 531 713 532 714 class Data1D(Plottable): -
guitools/transform.py
r8e44d51 r46693050 61 61 raise ValueError,"cannot be computed" 62 62 63 64 def toYX2(x,y):65 return (x**2)*y66 67 68 def toXY(x,y):69 return x*y70 63 71 64 def toLogYX4(x, y): … … 84 77 return math.log(x*y) 85 78 86 def fromLogXY(self,x): 87 """ 88 This function is used to load value on Plottable.View 89 Calculate e^(x) 90 @param x: float value 91 """ 92 return math.exp(x*y) 93 94 95 79 80 96 81 def errToX(x,y=None,dx=None,dy=None): 97 82 """ … … 142 127 if dx==None: 143 128 dx = 0 129 if x!=0: 130 dx = dx/x 131 else: 132 raise ValueError, "errToLogX: divide by zero" 133 144 134 if math.fabs(dx) >= math.fabs(x): 145 return 0.9*x 135 dx = 0.9*x 136 146 137 return dx 147 138
Note: See TracChangeset
for help on using the changeset viewer.