- Timestamp:
- Apr 1, 2008 5:45:29 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:
- 8cebf9b
- Parents:
- f79b054
- Location:
- guitools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r52b1f77 re2914b1 60 60 self.xscales ="" 61 61 self.yscales ="" 62 # keep track if the previous transformation 63 self.prevXtrans ="x" 64 self.prevYtrans ="Log(y)" 62 # keep track if the previous transformation of x and y in Property dialog 63 self.prevXtrans =" " 64 self.prevYtrans =" " 65 66 def setTrans(self,xtrans,ytrans): 67 """ 68 @param xtrans: set x transformation on Property dialog 69 @param ytrans: set y transformation on Property dialog 70 """ 71 self.prevXtrans =xtrans 72 self.prevYtrans =ytrans 65 73 66 74 def onFitting(self, event): 75 """ 76 when clicking on linear Fit on context menu , display Fitting Dialog 77 """ 67 78 list =[] 68 79 list = self.graph.returnPlottable() 69 80 from fitDialog import LinearFit 70 71 81 print len(list) 72 82 if len(list.keys())>0: … … 77 87 78 88 def _onProperties(self, event): 79 89 """ 90 when clicking on Properties on context menu ,The Property dialog is displayed 91 The user selects a transformation for x or y value and a new plot is displayed 92 """ 80 93 from PropertyDialog import Properties 81 94 dial = Properties(self, -1, 'Properties') 95 dial.setValues( self.prevXtrans, self.prevYtrans ) 82 96 if dial.ShowModal() == wx.ID_OK: 83 97 self.xscales, self.yscales = dial.getValues() … … 86 100 87 101 def toX(self,x): 102 """ 103 This function is used to load value on Plottable.View 104 @param x: Float value 105 @return x, 106 """ 88 107 return x 89 108 90 109 def toX2(self,x): 91 110 """ 111 This function is used to load value on Plottable.View 92 112 Calculate x^(2) 93 113 @param x: float value 94 114 """ 95 115 return math.pow(x,2) 116 96 117 def fromX2(self,x): 97 118 """ 119 This function is used to load value on Plottable.View 98 120 Calculate square root of x 99 121 @param x: float value 100 122 """ 101 if x >=0 : 123 if not x >=0 : 124 raise ValueError, "square root of a negative value " 125 else: 102 126 return math.sqrt(x) 103 else:104 return 0105 def toLogXY(self,x):106 """127 128 def toLogXY(self,x,y): 129 """ 130 This function is used to load value on Plottable.View 107 131 calculate log x 108 132 @param x: float value 109 133 """ 110 if x> 0:111 r eturn math.log(x)134 if not x*y > 0: 135 raise ValueError, "Log(X*Y)of a negative value " 112 136 else: 113 return 0 137 return math.log(x*y) 138 114 139 def fromLogXY(self,x): 115 140 """ 141 This function is used to load value on Plottable.View 116 142 Calculate e^(x) 117 143 @param x: float value 118 144 """ 119 if x.__class__.__name__ == 'list': 120 temp =[] 121 for x_i in x: 122 temp.append(math.exp(x_i)) 123 return temp 124 else: 125 return math.exp(x) 126 127 145 return math.exp(x*y) 146 128 147 def set_yscale(self, scale='linear'): 148 """ 149 Set the scale on Y-axis 150 @param scale: the scale of y-axis 151 """ 129 152 self.subplot.set_yscale(scale) 130 153 self.yscale = scale 131 154 132 155 def get_yscale(self): 156 """ 157 @return: Y-axis scale 158 """ 133 159 return self.yscale 134 160 135 161 def set_xscale(self, scale='linear'): 162 """ 163 Set the scale on x-axis 164 @param scale: the scale of x-axis 165 """ 136 166 self.subplot.set_xscale(scale) 137 167 self.xscale = scale 138 168 139 169 def get_xscale(self): 170 """ 171 @return: x-axis scale 172 """ 140 173 return self.xscale 141 174 … … 338 371 if ( self.xscales=="x" ): 339 372 if self.prevXtrans == "x^(2)": 340 item.transform_x( self.fromX2, self.errFunc )373 item.transform_x( self.fromX2, self.errFuncfromX2 ) 341 374 #elif self.prevXtrans == "Log(x)" 342 #item.transform_x( self.fromLogXY,self.errFunc )375 #item.transform_x( self.fromLogXY,self.errFuncfromX2 ) 343 376 print "Values of x",item.x[0:5] 344 377 print "Values of view x",item.view.x[0:5] … … 350 383 #item.transform_x( self.fromLogXY, self.errFunc ) 351 384 if self.prevXtrans != "x^(2)": 352 item.transform_x( self.toX2, self.errFunc )385 item.transform_x( self.toX2, self.errFuncToX2 ) 353 386 print "Values of x",item.x[0:5] 354 387 print "Values of view x^(2)",item.view.x[0:5] … … 358 391 if (self.xscales=="Log(x)" ): 359 392 if self.prevXtrans == "x^(2)": 360 item.transform_x( self.fromX2, self.errFunc )393 item.transform_x( self.fromX2, self.errFuncfromX2 ) 361 394 #elif self.prevXtrans == "Log(x)": 362 395 #item.transform_x( self.toLogXY, self.errFunc ) … … 367 400 if ( self.yscales=="y" ): 368 401 if self.prevYtrans == "y^(2)": 369 item.transform_y( self.toX2, self.errFunc )402 item.transform_y( self.toX2, self.errFuncToX2 ) 370 403 #elif self.prevXtrans == "Log(y)" 371 404 #item.transform_y( self.fromLogXY.errFunc ) … … 375 408 if ( self.yscales=="Log(y)" ): 376 409 if self.prevYtrans == "y^(2)": 377 item.transform_y( self.fromX2, self.errFunc )410 item.transform_y( self.fromX2, self.errFuncfromX2 ) 378 411 #elif self.prevYtrans != "Log(y)": 379 412 #item.transform_y( self.toLogXY, self.errFunc ) … … 386 419 #item.transform_y( self.fromLogXY, self.errFunc ) 387 420 if self.prevYtrans != "y^(2)": 388 item.transform_y( self.toX2, self.errFunc )421 item.transform_y( self.toX2, self.errFuncToX2 ) 389 422 self.set_yscale("linear") 390 423 self.graph.yaxis("\\rm{Intensity^{2}} ","cm^{-2}") … … 397 430 self.subplot.figure.canvas.draw_idle() 398 431 399 def errFunc(self,x): 400 """ 401 calculate log x 402 @param x: float value 403 """ 404 if x >=0: 405 return math.sqrt(x) 432 def errFuncToX2(self,x,dx=None): 433 """ 434 calculate error of x**2 435 @param x: float value 436 @param dx: float value 437 """ 438 if not dx == None: 439 return 2*x*dx 406 440 else: 407 return 0 408 409 441 raise ValueError, "Can't calculate the error" 442 def errFuncfromX2(self,x,dx=None): 443 """ 444 calculate error of sqrt(x) 445 @param x: float value 446 @param dx: float value 447 """ 448 if (x > 0) and (dx != None): 449 err= dx/2*math.sqrt(x) 450 451 else: 452 raise ValueError, "Can't calculate the error" 453 def errFuncToLogX(self,x,dx=None): 454 """ 455 calculate error of Log(xy) 456 @param x: float value 457 @param dx: float value 458 """ 459 if (x!=0) and ( dx != None): 460 err= dx/x 461 if err >= x: 462 err = 0.9*x 463 return err 464 elif x==0: 465 raise ValueError, "On calculate error: Can't divide by zero" 466 else: 467 raise ValueError, "Can't calculate the error" 468 469 def errFuncfromLogXY(self,x,dx=None): 470 """ 471 calculate error of sqrt(x) 472 @param x: float value 473 @param dx: float value 474 """ 475 if (x > 0) and (dx != None): 476 err= dx/2*math.sqrt(x) 477 if err >= x: 478 err = 0.9*x 479 return err 480 else: 481 raise ValueError, "Can't calculate the error" 482 410 483 def onFitDisplay(self, plottable): 484 """ 485 Add a new plottable into the graph .In this case this plottable will be used 486 to fit some data 487 @param plottable: the plottable to plot 488 """ 411 489 self.graph.add(plottable) 412 490 self.graph.render(self) -
guitools/PropertyDialog.py
r6cfe703 re2914b1 62 62 return self.xvalue.SetValue(x), self.yvalue.SetValue(y) 63 63 64 65 64 def getValues(self): 66 65 return self.xvalue.GetValue(), self.yvalue.GetValue() -
guitools/plottables.py
rf79b054 re2914b1 339 339 self.x= x 340 340 self.y = y 341 self.dx= x 342 self.dy = y 341 343 342 self.reset_view() 344 343
Note: See TracChangeset
for help on using the changeset viewer.