- Timestamp:
- Apr 10, 2008 6:29:17 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:
- 370e587
- Parents:
- 3d3a0e5
- Location:
- guitools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r3d3a0e5 r7a03e65 63 63 self.prevXtrans =" " 64 64 self.prevYtrans =" " 65 65 66 def returnTrans(self): 66 67 return self.xscales,self.yscales … … 81 82 list = self.graph.returnPlottable() 82 83 from fitDialog import LinearFit 83 print len(list)84 84 85 if len(list.keys())>0: 85 86 first_item = list.keys()[0] … … 101 102 dial.Destroy() 102 103 103 def toX(self,x ):104 def toX(self,x,y=None): 104 105 """ 105 106 This function is used to load value on Plottable.View … … 109 110 return x 110 111 111 def toX2(self,x ):112 def toX2(self,x,y=None): 112 113 """ 113 114 This function is used to load value on Plottable.View … … 117 118 return x*x 118 119 119 def fromX2(self,x ):120 def fromX2(self,x,y=None): 120 121 """ 121 122 This function is used to load value on Plottable.View … … 127 128 else: 128 129 return math.sqrt(x) 129 def toLogX(self,x ):130 def toLogX(self,x,y=None): 130 131 """ 131 132 This function is used to load value on Plottable.View … … 138 139 return math.log(x) 139 140 140 def toOneOverX(self,x ):141 def toOneOverX(self,x,y=None): 141 142 if x !=0: 142 143 return 1/x 143 144 else: 144 145 raise ValueError,"cannot divide by zero" 145 def toOneOverSqrtX(self,x): 146 if x > 0: 147 return 1/math.sqrt(x) 148 else: 149 raise ValueError,"cannot be computed" 146 def toOneOverSqrtX(self,x=None,y=None): 147 if y!=None: 148 if y > 0: 149 return 1/math.sqrt(y) 150 else: 151 raise ValueError,"cannot be computed" 152 if x!= None: 153 if x > 0: 154 return 1/math.sqrt(x) 155 else: 156 raise ValueError,"cannot be computed" 157 150 158 def toLogYX2(self,x,y): 151 159 if y*(x**2) >0: … … 247 255 def onSaveImage(self, evt): 248 256 #figure.savefig 249 print "Save image not implemented"257 #print "Save image not implemented" 250 258 path = None 251 259 dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.png", wx.SAVE) … … 285 293 pos = self.ScreenToClient(pos) 286 294 self.PopupMenu(slicerpop, pos) 287 288 295 289 296 ## The following is plottable functionality … … 452 459 name, units = item.get_yaxis() 453 460 self.graph.yaxis("%s" %name, "%s" % units) 461 454 462 if ( self.yscales =="Log(y*x)"): 455 item.transform_ xy( self.toXY ,self.errToXY )456 self.set_yscale("l og")463 item.transform_y( self.toLogXY ,self.errToLogXY ) 464 self.set_yscale("linear") 457 465 yname, yunits = item.get_yaxis() 458 466 xname, xunits = item.get_xaxis() 459 self.graph.yaxis("%s "+"*"+"%s" % (yname,xname), "%s^{-1}"+"*"+"s^{-1}" % (yunits,xunits))467 self.graph.yaxis("%s%s" % (yname,xname), "%s^{-1}%s^{-1}" % (yunits,xunits)) 460 468 if ( self.yscales =="Log(y*x^(2)"): 461 item.transform_ xy( self.toYX2 ,self.errToYX2 )462 self.set_yscale("l og")469 item.transform_y( self.toYX2 ,self.errToYX2 ) 470 self.set_yscale("linear") 463 471 yname, yunits = item.get_yaxis() 464 472 xname, xunits = item.get_xaxis() 465 self.graph.yaxis("%s "+"*"+"%s^{2}" % (yname,xname), "%s^{-1}"+"*"+"s^{-2}" % (yunits,xunits))473 self.graph.yaxis("%s%s^{2}" % (yname,xname), "%s^{-1}%s^{-2}" % (yunits,xunits)) 466 474 467 475 self.prevXtrans = self.xscales … … 471 479 self.subplot.figure.canvas.draw_idle() 472 480 473 def errToX(self,x, dx=None):481 def errToX(self,x,y=None,dx=None,dy=None): 474 482 """ 475 483 calculate error of x**2 … … 477 485 @param dx: float value 478 486 """ 479 if (dx != None) and (math.fabs(dx) >= math.fabs(x)): 480 return math.fabs(0.9*x) 481 if dx==None: 482 return 0 483 return math.fabs(dx) 484 485 def errToX2(self,x,dx=None): 487 return dx 488 489 490 def errToX2(self,x,y=None,dx=None,dy=None): 486 491 """ 487 492 calculate error of x**2 … … 496 501 else: 497 502 return 0.0 498 def errFromX2(self,x, dx=None):503 def errFromX2(self,x,y=None,dx=None,dy=None): 499 504 """ 500 505 calculate error of sqrt(x) … … 514 519 return math.fabs(err) 515 520 516 def errToLogX(self,x, dx=None):517 """ 518 calculate error of Log(x y)521 def errToLogX(self,x,y=None,dx=None,dy=None): 522 """ 523 calculate error of Log(x) 519 524 @param x: float value 520 525 @param dx: float value 521 526 """ 522 if x!=0: 523 if dx==None: 524 #err = 1/x 525 err = 0 526 else: 527 err = dx/x 528 if math.fabs(err) >= math.fabs(x): 529 err = 0.9*x 530 else: 531 err = 0.9*x 532 533 return math.fabs(err) 527 if math.fabs(dx) >= math.fabs(x): 528 return 0.9*x 529 return dx 530 534 531 def errToXY(self, x, y, dx=None, dy=None): 535 532 if dx==None: … … 541 538 err =0.9*x 542 539 return err 540 543 541 def errToYX2(self, x, y, dx=None, dy=None): 544 542 if dx==None: … … 585 583 return math.sqrt(math.fabs(err)) 586 584 587 def errOneOverX(self,x, dx):585 def errOneOverX(self,x,y=None,dx=None, dy=None): 588 586 """ 589 587 calculate error on 1/x 590 588 """ 591 if (x != 0) and (dx!=None):589 if (x != 0): 592 590 if dx ==None: 593 591 dx= 0 … … 600 598 return math.fabs(err) 601 599 602 def errOneOverSqrtX(self ):600 def errOneOverSqrtX(self,x,y=None, dx=None,dy=None): 603 601 """ 604 602 Calculate error on 1/sqrt(x) 605 603 """ 606 if (x >0) and (dx!=None):604 if (x >0): 607 605 if dx==None: 608 606 dx =0 … … 625 623 self.graph.add(plottable) 626 624 self.graph.render(self) 625 self.subplot.figure.canvas.draw_idle() 627 626 self.graph.delete(plottable) 628 self.subplot.figure.canvas.draw_idle() 627 628 629 629 630 630 -
guitools/fitDialog.py
rf52bea1 r7a03e65 20 20 #dialog self plottable 21 21 self.plottable = plottable 22 23 22 24 23 #Dialog interface … … 100 99 Push a plottable to 101 100 """ 102 103 temp =[] 101 temp=[] 104 102 tempx=[] 105 103 tempy=[] 104 tempdy = [] 105 106 #Check if the field of Fit Dialog contain values and use the x max and min of the user 106 107 xmin = self._checkVal(self.tcXmin.GetValue()) 107 108 xmax = self._checkVal(self.tcXmax.GetValue()) … … 109 110 #store the values of View in x,y, dx,dy 110 111 x,y,dx,dy=self.plottable.returnValuesOfView() 112 # Receive transformations of x and y 111 113 self.xtrans,self.ytrans= self.transform() 114 # The x array min and max 115 _min = min(x) 116 _max = max(x) 117 118 119 if (xmin ==None)and (xmax == None): 120 #Display the min and the max of x on fit dialog fields 121 self.tcXmin.SetValue(str(min(x))) 122 self.tcXmax.SetValue(str(max(x))) 123 124 112 125 #Display the fittings values 113 126 default_A = self.model.getParam('A') … … 115 128 cstA = fittings.Parameter(self.model, 'A', default_A) 116 129 cstB = fittings.Parameter(self.model, 'B', default_B) 130 117 131 if self.ytrans == "Log(y)": 118 132 for y_i in y: 119 tempy.append(log(y_i)) 120 chisqr, out, cov = fittings.sansfit(self.model, 121 [cstA, cstB],x, tempy,dy,min(x),max(x)) 133 temp.append(math.log(y_i)) 134 tempdy.append(1.0) 135 if (xmin !=None and xmin>= _min) and (xmax != None and xmax<= _max): 136 chisqr, out, cov = fittings.sansfit(self.model, 137 [cstA, cstB],x, temp,tempdy,xmin,xmax) 138 else: 139 chisqr, out, cov = fittings.sansfit(self.model, 140 [cstA, cstB],x, temp,tempdy,_min,_max) 122 141 else : 123 chisqr, out, cov = fittings.sansfit(self.model, 124 [cstA, cstB],x, y,dy,min(x),max(x)) 142 if (xmin !=None and xmin >= _min) and (xmax != None and xmax <= _max): 143 chisqr, out, cov = fittings.sansfit(self.model, 144 [cstA, cstB],x, y,dy,xmin,xmax) 145 else: 146 chisqr, out, cov = fittings.sansfit(self.model, 147 [cstA, cstB],x, y,dy,_min,_max) 125 148 #Check that cov and out are iterable before displaying them 126 149 if cov ==None: … … 139 162 self.model.setParam('B', float(cstB)) 140 163 164 #Check if View contains a x array and makes transformation for y as a line to fit 141 165 if x != []: 142 if xmin !=None and xmax != None: 143 for j in range(len(x)): 144 if x[j] > xmin and x[j] < xmax: 145 temp.append(self.model.run(x[j])) 146 else: 147 # x has a default value in case the user doesn't load data 148 for x_i in x: 149 temp.append(self.model.run(x_i)) 150 self.tcXmin.SetValue(str(min(x))) 151 self.tcXmax.SetValue(str(max(x))) 152 xmin = self._checkVal(self.tcXmin.GetValue()) 153 xmax = self._checkVal(self.tcXmax.GetValue()) 154 155 self.file_data1.x =x 166 for j in range(len(x)): 167 if (xmin !=None)and (xmax != None): 168 if (x[j] > xmin and x[j] < xmax): 169 y_model = self.model.run(x[j]) 170 else: 171 # x has a default value in case the user doesn't load data 172 y_model = self.model.run(x[j]) 173 if self.ytrans == "Log(y)": 174 tempy.append(math.exp(y_model)) 175 else: 176 tempy.append(y_model) 177 156 178 # Create new data plottable with result 157 179 self.file_data1.y =[] 158 self.xtrans, self.ytrans= self.transform() 159 160 if self.ytrans == "Log(y)": 161 for x_i in x: 162 self.file_data1.y.append(exp(self.model.run(x_i))) 163 else: 164 self.file_data1.y =temp 180 self.file_data1.x =x 181 self.file_data1.y =tempy 165 182 self.file_data1.dx=None 166 183 self.file_data1.dy=None 167 184 185 #Load the view with the new values 168 186 self.file_data1.reset_view() 169 187 170 188 #Send the data to display to the PlotPanel 171 #172 189 self.push_data(self.file_data1) 190 173 191 # Display the fitting value on the Fit Dialog 174 192 self._onsetValues(cstA, cstB, errA,errB,chisqr) 175 193 176 194 def _onsetValues(self,cstA,cstB,errA,errB,Chi): 177 195 """ -
guitools/plottables.py
r3d3a0e5 r7a03e65 382 382 383 383 """ 384 self.view.transform_x(func, errfunc, self.x, self.dx)384 self.view.transform_x(func, errfunc, x=self.x, y=self.y, dx=self.dx, dy=self.dy) 385 385 386 386 def transform_y(self, func, errfunc): … … 389 389 390 390 """ 391 self.view.transform_y(func, errfunc, self.y, self.dy) 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) 391 self.view.transform_y(func, errfunc, self.y, self.x, self.dx, self.dy) 392 399 393 400 394 def returnValuesOfView(self): … … 418 412 self.dy = dy 419 413 420 def transform_x(self, func, errfunc, x, dx):414 def transform_x(self, func, errfunc, x,y=None,dx=None, dy=None): 421 415 """ 422 416 Transforms the x and dx vectors and stores the output. … … 429 423 import copy 430 424 import numpy 425 431 426 # Sanity check 427 has_y = False 432 428 if dx and not len(x)==len(dx): 433 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 434 429 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 430 # Check length of y array 431 if not y==None: 432 if not len(y)==len(x): 433 raise ValueError, "Plottable.View: Given y and x are not of the same length" 434 else: 435 has_y = True 436 if dy and not len(y)==len(dy): 437 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 435 438 436 439 self.x = numpy.zeros(len(x)) … … 438 441 439 442 for i in range(len(x)): 440 self.x[i] = func(x[i]) 441 if dx !=None: 442 self.dx[i] = errfunc(x[i], dx[i]) 443 if has_y: 444 self.x[i] = func(x[i],y[i]) 445 if (dx!=None) and (dy !=None): 446 self.dx[i] = errfunc(x[i], y[i], dx[i], dy[i]) 447 elif (dx != None): 448 self.dx[i] = errfunc(x[i], y[i], dx[i],0) 449 elif (dy != None): 450 self.dx[i] = errfunc(x[i], y[i],0,dy[i]) 451 else: 452 self.dx[i] = errfunc(x[i],y[i],0, 0) 443 453 else: 444 self.dx[i] = errfunc(x[i]) 445 def transform_y(self, func, errfunc, y, dy): 454 self.x[i] = func(x[i]) 455 if (dx != None): 456 self.dx[i] = errfunc(x[i], dx[i]) 457 else: 458 self.dx[i] = errfunc(x[i],None) 459 460 461 def transform_y(self, func, errfunc, y, x=None,dx=None,dy=None): 446 462 """ 447 Transforms the x and dxvectors and stores the output.463 Transforms the y and dy vectors and stores the output. 448 464 449 @param func: function to apply to the data 465 @param func: function to apply to the data y 466 @param x: array of x values 467 @param dx: array of error values 450 468 @param y: array of y values 451 469 @param dy: array of error values 452 @param errfunc: function to apply to errors 470 @param errfunc: function to apply to errors dy 453 471 """ 454 472 import copy 455 473 import numpy 456 474 # Sanity check 475 has_x = False 457 476 if dy and not len(y)==len(dy): 458 477 raise ValueError, "Plottable.View: Given y and dy are not of the same length" 478 # Check length of x array 479 if not x==None: 480 if not len(y)==len(x): 481 raise ValueError, "Plottable.View: Given y and x are not of the same length" 482 else: 483 has_x = True 484 if dx and not len(x)==len(dx): 485 raise ValueError, "Plottable.View: Given x and dx are not of the same length" 459 486 460 487 self.y = numpy.zeros(len(y)) … … 462 489 463 490 for i in range(len(y)): 464 self.y[i] = func(y[i]) 465 if dy !=None: 466 self.dy[i] = errfunc(y[i], dy[i]) 491 492 if has_x: 493 self.y[i] = func(y[i],x[i]) 494 if (dx!=None) and (dy !=None): 495 self.dy[i] = errfunc(y[i], x[i], dy[i], dx[i]) 496 elif (dx != None): 497 self.dy[i] = errfunc(y[i], x[i], 0, dx[i]) 498 elif (dy != None): 499 self.dy[i] = errfunc(y[i], x[i], dy[i], 0) 500 else: 501 self.dy[i] = errfunc(y[i], None) 467 502 else: 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. 503 self.y[i] = func(y[i]) 504 if (dy != None): 505 self.dy[i] = errfunc( y[i],dy[i]) 506 else: 507 self.dy[i] = errfunc( y[i],None) 472 508 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]) 506 509 507 510 def returnXview(self): 508 511 return self.x,self.y,self.dx,self.dy
Note: See TracChangeset
for help on using the changeset viewer.