Changeset f193585 in sasview
- Timestamp:
- Apr 28, 2008 5:48:59 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:
- 6ed101a
- Parents:
- 9e8dc22
- Location:
- guitools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r8035b82 rf193585 10 10 import transform 11 11 from canvas import FigureCanvas 12 from matplotlib.widgets import RectangleSelector 13 from pylab import gca, gcf 14 12 15 #TODO: make the plottables interactive 13 16 … … 49 52 sizer.Add(self.canvas,1,wx.EXPAND) 50 53 self.SetSizer(sizer) 51 54 52 55 # Graph object to manage the plottables 53 56 self.graph = Graph() … … 88 91 if len(list.keys())>0: 89 92 first_item = list.keys()[0] 90 #print first_item, list[first_item].__class__.__name__91 93 dlg = LinearFit( None, first_item, self.onFitDisplay,self.returnTrans, -1, 'Fitting') 92 94 dlg.ShowModal() … … 172 174 173 175 174 176 177 178 def onselect(self,event1, event2): 179 print"went here" 180 from matplotlib.widgets import RectangleSelector 181 from pylab import show, gca, gcf 182 183 'event1 and event2 are the press and release events' 184 x1, y1 = event1.xdata, event1.ydata 185 x2, y2 = event2.xdata, event2.ydata 186 print "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2) 187 print " The button you used were: ",event1.button, event2.button 188 gca().set_xlim([x1,x2]) 189 gca().set_ylim([y1,y2]) 190 gcf().canvas.draw_idle() 191 192 # drawtype is 'box' or 'line' or 'none' 193 LS = RectangleSelector(self.subplot, onselect,drawtype='box',useblit=True) 194 show() 195 196 197 198 175 199 def onSaveImage(self, evt): 176 200 #figure.savefig … … 241 265 self.subplot.clear() 242 266 self.subplot.hold(True) 243 244 267 245 268 def render(self): 246 269 """Commit the plot after all objects are drawn""" … … 330 353 list =[] 331 354 list = self.graph.returnPlottable() 355 332 356 for item in list: 357 item.getTransform(self.xscales,self.yscales) 333 358 if ( self.xscales=="x" ): 334 item.transform_x( transform.toX,transform.errToX ) 359 item.returnTransformationx(transform.toX,transform.errToX) 360 335 361 self.set_xscale("linear") 336 362 name, units = item.get_xaxis() … … 338 364 339 365 if ( self.xscales=="x^(2)" ): 340 item. transform_x( transform.toX2,transform.errToX2)366 item.returnTransformationx(transform.toX2,transform.errToX2) 341 367 self.set_xscale('linear') 342 368 name, units = item.get_xaxis() … … 344 370 345 371 if (self.xscales=="log10(x)" ): 346 item. transform_x( transform.toX, transform.errToX)372 item.returnTransformationx(transform.toX,transform.errToX) 347 373 self.set_xscale("log") 348 name, units = item.get_xaxis() 349 item.check_data_PlottableX() 374 name, units = item.get_xaxis() 350 375 self.graph.xaxis("Log10 %s" % name, "%s^{-1}" % units) 351 376 352 377 if ( self.yscales=="ln(y)" ): 353 item.transform_y( transform.toLogX, transform.errToLogX ) 354 self.set_yscale("linear") 355 name, units = item.get_yaxis() 378 item.returnTransformationy(transform.toLogX,transform.errToLogX) 379 self.set_yscale("linear") 380 name, units = item.get_yaxis() 381 item.check_data_PlottableY() 356 382 self.graph.yaxis("log %s" % name, "%s^{-1}" % units) 357 383 358 384 if ( self.yscales=="y" ): 359 item. transform_y( transform.toX, transform.errToX)385 item.returnTransformationy(transform.toX,transform.errToX) 360 386 self.set_yscale("linear") 361 387 name, units = item.get_yaxis() … … 363 389 364 390 if ( self.yscales=="log10(y)" ): 365 item.transform_y( transform.toX, transform.errToLogX) 391 item.returnTransformationy(transform.toX,transform.errToX) 392 item.check_data_PlottableY() 366 393 self.set_yscale("log") 367 394 name, units = item.get_yaxis() 395 self.graph.yaxis("Log10 %s" % name, "%s^{-1}" % units) 396 397 if ( self.yscales=="y^(2)" ): 398 item.returnTransformationy( transform.toX2,transform.errToX2 ) 399 self.set_yscale("linear") 400 name, units = item.get_yaxis() 401 self.graph.yaxis("%s^2" % name, "%s^{-2}" % units) 402 403 if ( self.yscales =="1/y"): 404 item.returnTransformationy(transform.toOneOverX,transform.errOneOverX ) 405 self.set_yscale("linear") 406 name, units = item.get_yaxis() 407 self.graph.yaxis("%s" % name, "%s" % units) 408 409 if ( self.yscales =="1/sqrt(y)" ): 410 item.returnTransformationy(transform.toOneOverSqrtX,transform.errOneOverSqrtX ) 411 self.set_yscale("linear") 412 name, units = item.get_yaxis() 368 413 item.check_data_PlottableY() 369 self.graph.yaxis("Log10 %s" % name, "%s^{-1}" % units)370 371 if ( self.yscales=="y^(2)" ):372 item.transform_y( transform.toX2, transform.errToX2 )373 self.set_yscale("linear")374 name, units = item.get_yaxis()375 self.graph.yaxis("%s^2" % name, "%s^{-2}" % units)376 377 if ( self.yscales =="1/y"):378 item.transform_y( transform.toOneOverX , transform.errOneOverX )379 self.set_yscale("linear")380 name, units = item.get_yaxis()381 self.graph.yaxis("%s" % name, "%s" % units)382 383 if ( self.yscales =="1/sqrt(y)" ):384 item.transform_y( transform.toOneOverSqrtX ,transform.errOneOverSqrtX )385 self.set_yscale("linear")386 name, units = item.get_yaxis()387 414 self.graph.yaxis("%s" %name, "%s" % units) 388 415 389 416 if ( self.yscales =="ln(y*x)"): 390 item. transform_y( transform.toLogXY ,transform.errToLogXY)417 item.returnTransformationy( transform.toLogXY,transform.errToLogXY) 391 418 self.set_yscale("linear") 392 419 yname, yunits = item.get_yaxis() … … 395 422 396 423 if ( self.yscales =="ln(y*x^(2))"): 397 item. transform_y( transform.toLogYX2 ,transform.errToLogYX2)424 item.returnTransformationy( transform.toLogYX2,transform.errToLogYX2) 398 425 self.set_yscale("linear") 399 426 yname, yunits = item.get_yaxis() 400 427 xname, xunits = item.get_xaxis() 428 item.check_data_PlottableY() 401 429 self.graph.yaxis("Log %s%s^{2}" % (yname,xname), "%s^{-1}%s^{-2}" % (yunits,xunits)) 402 430 403 431 if ( self.yscales =="ln(y*x^(4))"): 404 item. transform_y( transform.toLogYX4 ,transform.errToLogYX4)432 item.returnTransformationy(transform.toLogYX4,transform.errToLogYX4) 405 433 self.set_yscale("linear") 406 434 yname, yunits = item.get_yaxis() … … 409 437 410 438 if ( self.viewModel == "Guinier lny vs x^(2)"): 411 412 item.transform_x( transform.toX2,transform.errToX2 ) 439 item.returnTransformationx(transform.toX2,transform.errToX2) 413 440 self.set_xscale('linear') 414 441 name, units = item.get_xaxis() 415 442 self.graph.xaxis("%s^{2}" % name, "%s^{-2}" % units) 416 417 item.transform_y( transform.toLogX, transform.errToLogX ) 443 item.returnTransformationy(transform.toLogX,transform.errToLogX ) 418 444 self.set_yscale("linear") 419 445 name, units = item.get_yaxis() 420 446 self.graph.yaxis("$Log %s$" % name, "%s^{-1}" % units) 447 421 448 #item.name = self.yscales+" vs " +self.xscales 422 449 self.prevXtrans = self.xscales 423 450 self.prevYtrans = self.yscales 424 451 item.transformView() 425 452 self.graph.render(self) 426 453 self.subplot.figure.canvas.draw_idle() 427 454 428 def onFitDisplay(self, plottable ,xmin,xmax):455 def onFitDisplay(self, plottable): 429 456 """ 430 457 Add a new plottable into the graph .In this case this plottable will be used … … 432 459 @param plottable: the plottable to plot 433 460 """ 434 list =[]435 tempx=[]436 tempy=[]437 tempdx=[]438 tempdy=[]439 #Stored plotted plottable in a new plottable440 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 print"went here"449 item.reducedXrange(xmin,xmax)450 else:451 item.originalXrange()452 453 454 461 #Add the data to fit 455 plottable.reset_view()462 456 463 self.graph.add(plottable) 457 464 self.graph.render(self) … … 459 466 self.subplot.figure.canvas.draw_idle() 460 467 self.graph.delete(plottable) 461 462 463 464 468 469 470 465 471 class NoRepaintCanvas(FigureCanvasWxAgg): 466 472 """We subclass FigureCanvasWxAgg, overriding the _onPaint method, so that -
guitools/canvas.py
r2bf92f2 rf193585 2 2 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, _convert_agg_to_wx_bitmap 3 3 from matplotlib.backends.backend_agg import FigureCanvasAgg 4 from matplotlib.backend_bases import MouseEvent 4 5 5 6 class FigureCanvas(FigureCanvasWxAgg): … … 19 20 # doesn't behave as nicely. 20 21 self.idletimer = wx.CallLater(1,self._onDrawIdle) 22 # Support for mouse wheel 23 self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel) 24 21 25 22 26 def draw_idle(self, *args, **kwargs): … … 46 50 else: 47 51 self._isRendered = False 52 def _onMouseWheel(self, evt): 53 """Translate mouse wheel events into matplotlib events""" 54 # Determine mouse location 55 x = evt.GetX() 56 y = self.figure.bbox.height - evt.GetY() 57 58 # Convert delta/rotation/rate into a floating point step size 59 delta = evt.GetWheelDelta() 60 rotation = evt.GetWheelRotation() 61 rate = evt.GetLinesPerAction() 62 #print "delta,rotation,rate",delta,rotation,rate 63 step = rate*float(rotation)/delta 64 65 # Convert to mpl event 66 evt.Skip() 67 self.scroll_event(x, y, step, guiEvent=evt) 68 69 def scroll_event(self, x, y, step=1, guiEvent=None): 70 """ 71 Backend derived classes should call this function on any 72 scroll wheel event. x,y are the canvas coords: 0,0 is lower, 73 left. button and key are as defined in MouseEvent 74 """ 75 button = 'up' if step >= 0 else 'down' 76 self._button = button 77 s = 'scroll_event' 78 event = MouseEvent(s, self, x, y, button, self._key, guiEvent=guiEvent) 79 setattr(event,'step',step) 80 self.callbacks.process(s, event) 81 48 82 49 83 def _onPaint(self, evt): … … 64 98 65 99 evt.Skip() 66 100 -
guitools/fitDialog.py
r46693050 rf193585 140 140 self.file_data1 = Theory1D(x=[], y=[], dy=None) 141 141 self.file_data1.name = "Fit" 142 142 # Receive transformations of x and y 143 self.xtrans,self.ytrans= self.transform() 143 144 def _onFit(self ,event): 144 145 """ … … 152 153 tempdy = [] 153 154 154 #Check if the field of Fit Dialog contain values and use the x max and min of the user155 xmin,xmax = self._checkVal(self.FXmin.GetValue(),self.FXmax.GetValue())156 155 #store the values of View in x,y, dx,dy 157 156 x,y,dx,dy=self.plottable.returnValuesOfView() … … 162 161 # makes transformation for y as a line to fit 163 162 if x != []: 164 xminView=self.floatTransform(xmin) 165 xmaxView=self.floatTransform(xmax) 166 167 # Store the transformed values of view x, y,dy in variables before the fit 168 if self.ytrans.lower() == "log10(y)": 169 for y_i in y: 170 tempy.append(math.log10(y_i)) 171 else: 172 tempy = y 173 if self.xtrans.lower() == "log10(x)": 174 for x_i in x: 175 tempx.append(math.log10(x_i)) 176 else: 177 tempx = x 178 179 for y_i in y: 180 dy = 1/y_i 181 if dy >= y_i: 182 dy = 0.9*y_i 183 tempdy.append(dy) 184 185 #Find the fitting parameters 186 chisqr, out, cov = fittings.sansfit(self.model, 187 [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 163 if(self.checkFitValues(self.FXmin) == True): 164 #Check if the field of Fit Dialog contain values and use the x max and min of the user 165 xmin,xmax = self._checkVal(self.FXmin.GetValue(),self.FXmax.GetValue()) 166 xminView=self.floatTransform(xmin) 167 xmaxView=self.floatTransform(xmax) 168 169 # Store the transformed values of view x, y,dy in variables before the fit 170 if self.ytrans.lower() == "log10(y)": 171 if (self.xtrans.lower() == "log10(x)"): 172 for i in range(len(x)): 173 if x[i]>=xmin: 174 tempy.append(math.log10(y[i])) 175 tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 176 else: 177 for y_i in y: 178 tempy.append(math.log10(y_i)) 179 tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 180 else: 181 tempy = y 182 tempdy = dy 183 184 if (self.xtrans.lower() == "log10(x)"): 185 for x_i in x: 186 if x_i >= xmin: 187 tempx.append(math.log10(x_i)) 188 else: 189 tempx = x 190 191 #for y_i in y: 192 # dy = math.sqrt(math.fabs(y_i)) 193 # if dy >= y_i: 194 # dy = 0.9*y_i 195 # tempdy.append(dy) 196 197 #Find the fitting parameters 198 199 chisqr, out, cov = fittings.sansfit(self.model, 200 [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 201 print "this out",out 202 #Check that cov and out are iterable before displaying them 203 if cov ==None: 204 errA =0.0 205 errB =0.0 206 else: 207 errA= math.sqrt(cov[0][0]) 208 errB= math.sqrt(cov[1][1]) 209 if out==None: 210 cstA=0.0 211 cstB=0.0 212 else: 213 cstA=out[0] 214 cstB=out[1] 215 # Reset model with the right values of A and B 216 self.model.setParam('A', float(cstA)) 217 self.model.setParam('B', float(cstB)) 218 219 tempx = [] 220 tempy = [] 221 y_model = 0.0 222 # load tempy with the minimum transformation 223 224 if self.xtrans == "log10(x)": 225 y_model = self.model.run(math.log10(xmin)) 226 tempx.append(xmin) 227 else: 228 y_model = self.model.run(xminView) 229 tempx.append(xminView) 230 231 if self.ytrans == "log10(y)": 232 tempy.append(math.pow(10,y_model)) 233 print "tempy",tempy 234 else: 235 tempy.append(y_model) 236 237 # load tempy with the maximum transformation 238 if self.xtrans == "log10(x)": 239 y_model = self.model.run(math.log10(xmax)) 240 tempx.append(xmax) 241 else: 242 y_model = self.model.run(xmaxView) 243 tempx.append(xmaxView) 244 245 if self.ytrans == "log10(y)": 246 tempy.append(math.pow(10,y_model)) 247 else: 248 tempy.append(y_model) 249 250 # Create new data plottable with result 251 self.file_data1.x =[] 252 self.file_data1.y =[] 253 self.file_data1.x =tempx 254 self.file_data1.y =tempy 255 self.file_data1.dx=None 256 self.file_data1.dy=None 257 #Load the view with the new values 258 self.file_data1.reset_view() 259 260 #Send the data to display to the PlotPanel 261 self.push_data(self.file_data1) 262 263 # Display the fitting value on the Fit Dialog 264 self._onsetValues(cstA, cstB, errA,errB,chisqr) 188 265 189 #Check that cov and out are iterable before displaying them190 if cov ==None:191 errA =0.0192 errB =0.0193 else:194 errA= math.sqrt(cov[0][0])195 errB= math.sqrt(cov[1][1])196 if out==None:197 cstA=0.0198 cstB=0.0199 else:200 cstA=out[0]201 cstB=out[1]202 # Reset model with the right values of A and B203 self.model.setParam('A', float(cstA))204 self.model.setParam('B', float(cstB))205 206 tempx = []207 tempy = []208 y_model = 0.0209 # load tempy with the minimum transformation210 211 if self.xtrans == "log10(x)":212 y_model = self.model.run(math.log10(xmin))213 tempx.append(xmin)214 else:215 y_model = self.model.run(xminView)216 tempx.append(xminView)217 218 if self.ytrans == "log10(y)":219 tempy.append(math.pow(10,y_model))220 else:221 tempy.append(y_model)222 223 # load tempy with the maximum transformation224 if self.xtrans == "log10(x)":225 y_model = self.model.run(math.log10(xmax))226 tempx.append(xmax)227 else:228 y_model = self.model.run(xmaxView)229 tempx.append(xmaxView)230 231 if self.ytrans == "log10(y)":232 tempy.append(math.pow(10,y_model))233 else:234 tempy.append(y_model)235 236 # Create new data plottable with result237 self.file_data1.x =[]238 self.file_data1.y =[]239 self.file_data1.x =tempx240 self.file_data1.y =tempy241 self.file_data1.dx=None242 self.file_data1.dy=None243 #Load the view with the new values244 self.file_data1.reset_view()245 246 #Send the data to display to the PlotPanel247 self.push_data(self.file_data1,xminView, xmaxView)248 249 # Display the fitting value on the Fit Dialog250 self._onsetValues(cstA, cstB, errA,errB,chisqr)251 252 266 def _onsetValues(self,cstA,cstB,errA,errB,Chi): 253 267 """ … … 291 305 return transform.toX(x) 292 306 293 if ( self.xtrans=="x^(2)" ): 307 if ( self.xtrans=="x^(2)" ): 294 308 return transform.toX2(x) 295 309 … … 299 313 else: 300 314 raise ValueError,"cannot compute log of a negative number" 315 316 def checkFitValues(self,item): 317 """ 318 Check the validity of input values 319 """ 320 flag = True 321 value = item.GetValue() 322 # Check for possible values entered 323 if (self.xtrans=="log10(x)"): 324 if (float(value) > 0): 325 item.SetBackgroundColour(wx.WHITE) 326 item.Refresh() 327 else: 328 flag = False 329 item.SetBackgroundColour("pink") 330 item.Refresh() 331 332 return flag 301 333 302 334 -
guitools/plottables.py
r46693050 rf193585 42 42 import copy 43 43 import numpy 44 import math 44 45 45 46 if 'any' not in dir(__builtins__): … … 181 182 else: 182 183 self.color =0 184 183 185 184 186 def reset(self): … … 361 363 ##Use the following if @classmethod doesn't work 362 364 # labels = classmethod(labels) 363 365 def getTransform(self,transx,transy): 366 self.view.transx = transx 367 self.view.transy = transy 368 364 369 def __init__(self): 365 370 self.view = View() … … 417 422 418 423 def returnValuesOfView(self): 419 420 424 return self.view.returnXview() 425 421 426 def check_data_PlottableX(self): 422 427 self.view.check_data_logX() 428 423 429 def check_data_PlottableY(self): 424 430 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) 431 def returnTransformationx(self,transx,transdx): 432 self.view.returntransformx(transx,transdx) 433 def returnTransformationy(self,transy,transdy): 434 self.view.returntransformy(transy,transdy) 435 429 436 class View: 430 437 """ … … 447 454 self.DXreel = self.dx 448 455 self.DYreel = self.dy 449 456 self.transx ="" 457 self.transy ="" 458 self.funcx= None 459 self.funcy= None 460 self.funcdx= None 461 self.funcdy= None 462 450 463 def transform_x(self, func, errfunc, x,y=None,dx=None, dy=None): 451 464 """ … … 474 487 self.x = [] 475 488 self.dx = [] 476 489 tempy=[] 490 tempdy=[] 491 print "this is initial value of y transformed",self.y 492 print "this is initial value of dy transformed",self.dy 477 493 for i in range(len(x)): 478 494 if has_y: 479 495 try: 480 496 xtemp = func(x[i],y[i]) 481 482 497 tempy.append(self.funcy.y[i]) 498 tempdy.append(self.funcdy.dy[i]) 483 499 if (dx!=None) and (dy !=None): 484 500 dxtemp = errfunc(x[i], y[i], dx[i], dy[i]) … … 489 505 else: 490 506 dxtemp = errfunc(x[i],y[i],0, 0) 491 492 507 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 508 self.dx.append(dxtemp) 499 509 except: 510 if len(tempy)>0: 511 del tempy[len(tempy)-1] 512 del tempdy[len(tempdy)-1] 500 513 print "View.transform_x: skipping point %g" % x[i] 501 print sys.exc_value 502 503 514 print sys.exc_value 504 515 else: 505 516 try: 506 517 xtemp = func(x[i]) 518 tempy.append(self.funcy.y[i]) 519 tempdy.append(self.funcdy.dy[i]) 507 520 if (dx != None): 508 521 dxtemp = errfunc(x[i], dx[i]) … … 510 523 dxtemp = errfunc(x[i],None) 511 524 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 525 self.dx.append(dxtemp) 518 526 except: 527 if len(tempy)>0: 528 del tempy[len(tempy)-1] 529 del tempdy[len(tempdy)-1] 519 530 print "View.transform_x: skipping point %g" % x[i] 520 531 print sys.exc_value 521 522 532 self.y=tempy 533 self.dy=tempdy 534 self.Xreel = [] 535 self.DXreel=[] 536 def returntransformx(self,funcx,funcdx): 537 self.funcx= funcx 538 self.funcdx= funcdx 539 540 def returntransformy(self,funcy,funcdy): 541 self.funcy= funcy 542 self.funcdy= funcdy 523 543 def transform_y(self, func, errfunc, y, x=None,dx=None,dy=None): 524 544 """ … … 547 567 self.y = [] 548 568 self.dy = [] 549 569 tempx=[] 570 tempdx=[] 571 print "this is initial value of x transformed",self.x 572 print "this is initial value of dx transformed",self.dx 550 573 for i in range(len(y)): 551 574 … … 553 576 try: 554 577 tempy = func(y[i],x[i]) 578 tempx.append(self.funcx.x[i]) 579 tempdx.append(self.funcdx.x[i]) 555 580 if (dx!=None) and (dy !=None): 556 581 tempdy = errfunc(y[i], x[i], dy[i], dx[i]) … … 563 588 self.y.append(tempy) 564 589 self.dy.append(tempdy) 565 self.Yreel = []566 self.DYreel=[]567 self.Yreel = self.y568 self.DYreel = self.dy569 590 except: 591 if len(tempx)>0: 592 del tempx[len(tempx)-1] 593 del tempdx[len(tempdx)-1] 570 594 print "View.transform_y: skipping point %g" % y[i] 571 595 print sys.exc_value … … 574 598 try: 575 599 tempy = func(y[i]) 600 tempx.append(self.funcx.x[i]) 601 tempdx.append(self.funcdx.dx[i]) 576 602 if (dy != None): 577 603 tempdy = errfunc( y[i],dy[i]) … … 579 605 tempdy = errfunc( y[i],None) 580 606 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 607 self.dy.append(tempdy) 586 608 except: 609 if len(tempx)>0: 610 del tempx[len(tempx)-1] 611 del tempdx[len(tempdx)-1] 587 612 print "View.transform_y: skipping point %g" % y[i] 588 613 print sys.exc_value 589 590 591 614 615 self.x = tempx 616 self.dx = tempdx 617 self.Yreel = [] 618 self.DYreel=[] 619 self.Yreel = self.y 620 self.DYreel = self.dy 621 print "this is x length",self.x 622 print "this is y length",self.y 623 print "this is dx length",self.dx 624 print "this is dy length",self.dy 592 625 def returnXview(self): 593 626 return self.x,self.y,self.dx,self.dy 594 627 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 628 650 629 def reelXrange(self): 651 630 self.x= self.Xreel … … 653 632 self.dx= self.DXreel 654 633 self.dy= self.DYreel 655 656 634 657 635 def check_data_logX(self): … … 660 638 tempy=[] 661 639 tempdy=[] 662 663 for i in range(len(self.x)): 640 if self.transx=="log10(x)" : 641 for i in range(len(self.x)): 642 try: 643 if (self.x[i]> 0): 644 645 tempx.append(self.x[i]) 646 tempdx.append(self.dx[i]) 647 tempy.append(self.y[i]) 648 tempdy.append(self.dy[i]) 649 except: 650 #print "View.transform_x: skipping point %g" %self.x[i] 651 print sys.exc_value 652 pass 653 if (self.transx == "x"): 654 if (self.transy == "ln(y*x)"): 655 try: 656 if (self.y[i]*self.x[i]> 0): 657 tempx.append(self.x[i]) 658 tempdx.append(self.dx[i]) 659 tempy.append(self.y[i]) 660 tempdy.append(self.dy[i]) 661 except: 662 #print "View.transform_x: skipping point %g" %self.x[i] 663 print sys.exc_value 664 pass 665 if(self.transy =="ln(y*x^(2))")or(self.transy =="ln(y*x^(4))"): 666 print "this is y transform",self.y 667 print "this is x transform",self.x 664 668 try: 665 if (self.x[i]> 0): 666 669 if (self.y[i]> 0 )and (self.x[i]!=0): 667 670 tempx.append(self.x[i]) 668 671 tempdx.append(self.dx[i]) … … 672 675 #print "View.transform_x: skipping point %g" %self.x[i] 673 676 print sys.exc_value 674 pass 675 677 pass 676 678 self.x=[] 677 679 self.dx=[] … … 682 684 self.dx=tempdx 683 685 self.dy=tempdy 686 684 687 def check_data_logY(self): 685 688 tempx=[] … … 687 690 tempy=[] 688 691 tempdy=[] 689 690 692 for i in range(len(self.x)): 693 if (self.transy == "ln(y)") or (self.transy == "log10(y)" )or\ 694 (self.transy =="1/sqrt(y)") : 695 try: 696 if (self.y[i]> 0): 697 tempx.append(self.x[i]) 698 tempdx.append(self.dx[i]) 699 tempy.append(self.y[i]) 700 tempdy.append(self.dy[i]) 701 except: 702 #print "View.transform_x: skipping point %g" %self.x[i] 703 print sys.exc_value 704 pass 705 if(self.transy == "1/y"): 706 try: 707 if (self.y[i]!=0): 708 tempx.append(self.x[i]) 709 tempdx.append(self.dx[i]) 710 tempy.append(self.y[i]) 711 tempdy.append(self.dy[i]) 712 except: 713 #print "View.transform_x: skipping point %g" %self.x[i] 714 print sys.exc_value 715 pass 716 if (self.transx == "x"): 717 if (self.transy == "ln(y*x)"): 718 try: 719 if (self.y[i]*self.x[i]> 0): 720 tempx.append(self.x[i]) 721 tempdx.append(self.dx[i]) 722 tempy.append(self.y[i]) 723 tempdy.append(self.dy[i]) 724 except: 725 #print "View.transform_x: skipping point %g" %self.x[i] 726 print sys.exc_value 727 pass 728 if(self.transy =="ln(y*x^(2))")or(self.transy =="ln(y*x^(4))"): 729 print "this is y transform",self.y 730 print "this is x transform",self.x 691 731 try: 692 if (self.y[i]> 0): 693 732 if (self.y[i]> 0 )and (self.x[i]!= 0): 694 733 tempx.append(self.x[i]) 695 734 tempdx.append(self.dx[i]) … … 699 738 #print "View.transform_x: skipping point %g" %self.x[i] 700 739 print sys.exc_value 701 pass 740 pass 702 741 703 742 self.x=[] … … 735 774 def render(self,plot,**kw): 736 775 plot.points(self.view.x,self.view.y,dx=self.view.dx,dy=self.view.dy,**kw) 737 #plot.points(self.x,self.y,dx=self.dx,dy=self.dy,**kw)776 738 777 739 778 def changed(self): -
guitools/transform.py
r46693050 rf193585 43 43 else: 44 44 raise ValueError,"cannot divide by zero" 45 def toOneOverSqrtX( x=None,y=None):45 def toOneOverSqrtX(y , x=None): 46 46 if y!=None: 47 47 if y > 0: … … 49 49 else: 50 50 raise ValueError,"cannot be computed" 51 if x!= None: 52 if x > 0: 53 return 1/math.sqrt(x) 54 else: 55 raise ValueError,"cannot be computed" 56 57 def toLogYX2(x,y): 51 52 53 def toLogYX2(y,x): 58 54 if y*(x**2) >0: 59 55 return math.log(y*(x**2)) … … 62 58 63 59 64 def toLogYX4( x, y):60 def toLogYX4(y, x): 65 61 if math.pow(x,4)*y > 0: 66 62 return math.log(math.pow(x,4)*y) 67 63 68 def toLogXY( x,y):64 def toLogXY(y,x): 69 65 """ 70 66 This function is used to load value on Plottable.View … … 85 81 @param dx: float value 86 82 """ 83 if dx==None: 84 dx=0 87 85 return dx 88 86
Note: See TracChangeset
for help on using the changeset viewer.