Changeset 34ae302 in sasview
- Timestamp:
- Apr 30, 2008 5:47:33 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:
- bbec827
- Parents:
- eca05c8
- Location:
- guitools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r47f695c9 r34ae302 35 35 # TODO: use proper scale transformers 36 36 if scale=='log': 37 lo,hi = log10(lo),log10(hi)38 if pt is not None: pt = log10(pt)37 lo,hi = math.log10(lo),math.log10(hi) 38 if pt is not None: pt = math.log10(pt) 39 39 40 40 # Compute delta from axis range * %, or 1-% if persent is negative … … 53 53 # Convert transformed values back to the original scale 54 54 if scale=='log': 55 lo,hi = pow(10.,lo),pow(10.,hi) 55 lo,hi = math.pow(10.,lo),math.pow(10.,hi) 56 print "check y axis rescale" 56 57 57 58 return (lo,hi) … … 108 109 """ 109 110 ax = event.inaxes 111 110 112 step = event.step 111 113 … … 123 125 xdata,ydata = None,None 124 126 x,y = event.x,event.y 127 125 128 for ax in self.axes: 126 129 insidex,_ = ax.xaxis.contains(event) 127 130 if insidex: 128 131 xdata,_ = ax.transAxes.inverse_xy_tup((x,y)) 129 #print "xaxis",x,"->",xdata132 print "xaxis",x,"->",xdata 130 133 insidey,_ = ax.yaxis.contains(event) 131 134 if insidey: 132 135 _,ydata = ax.transAxes.inverse_xy_tup((x,y)) 133 #print "yaxis",y,"->",ydata136 print "yaxis",y,"->",ydata 134 137 if xdata is not None: 135 138 lo,hi = ax.get_xlim() 136 lo,hi = _rescale(lo,hi,step,bal=xdata )139 lo,hi = _rescale(lo,hi,step,bal=xdata,scale=ax.get_xscale()) 137 140 ax.set_xlim((lo,hi)) 138 141 if ydata is not None: 139 142 lo,hi = ax.get_ylim() 140 lo,hi = _rescale(lo,hi,step,bal=ydata )143 lo,hi = _rescale(lo,hi,step,bal=ydata,scale=ax.get_yscale()) 141 144 ax.set_ylim((lo,hi)) 142 145 … … 173 176 The user selects a transformation for x or y value and a new plot is displayed 174 177 """ 175 from PropertyDialog import Properties 176 dial = Properties(self, -1, 'Properties') 177 dial.setValues( self.prevXtrans, self.prevYtrans,self.viewModel ) 178 if dial.ShowModal() == wx.ID_OK: 179 self.xscales, self.yscales,self.viewModel = dial.getValues() 180 if self.viewModel =="Guinier lny vs x^(2)": 181 self.xscales="x^(2)" 182 self.yscales="ln(y)" 183 self.viewModel = "--" 184 dial.setValues( self.xscales, self.yscales,self.viewModel ) 185 self._onEVT_FUNC_PROPERTY() 186 dial.Destroy() 178 list =[] 179 list = self.graph.returnPlottable() 180 if len(list.keys())>0: 181 first_item = list.keys()[0] 182 if first_item.x !=[]: 183 from PropertyDialog import Properties 184 dial = Properties(self, -1, 'Properties') 185 dial.setValues( self.prevXtrans, self.prevYtrans,self.viewModel ) 186 if dial.ShowModal() == wx.ID_OK: 187 self.xscales, self.yscales,self.viewModel = dial.getValues() 188 if self.viewModel =="Guinier lny vs x^(2)": 189 self.xscales="x^(2)" 190 self.yscales="ln(y)" 191 self.viewModel = "--" 192 dial.setValues( self.xscales, self.yscales,self.viewModel ) 193 self._onEVT_FUNC_PROPERTY() 194 dial.Destroy() 195 187 196 188 197 def set_yscale(self, scale='linear'): … … 284 293 slicerpop.Append(317, '&Linear Fit') 285 294 wx.EVT_MENU(self, 317, self.onFitting) 295 296 slicerpop.AppendSeparator() 297 slicerpop.Append(318, '&Reset Graph') 298 wx.EVT_MENU(self, 318, self.onResetGraph) 286 299 287 300 pos = event.GetPosition() … … 426 439 self.set_xscale("log") 427 440 name, units = item.get_xaxis() 428 self.graph.xaxis(" Log10%s" % name, "%s^{-1}" % units)441 self.graph.xaxis("\log_{10}\ \ %s" % name, "%s^{-1}" % units) 429 442 430 443 if ( self.yscales=="ln(y)" ): … … 432 445 self.set_yscale("linear") 433 446 name, units = item.get_yaxis() 434 self.graph.yaxis("log %s" % name, "%s^{-1}" % units)447 self.graph.yaxis("log\ \ %s" % name, "%s^{-1}" % units) 435 448 436 449 if ( self.yscales=="y" ): … … 444 457 self.set_yscale("log") 445 458 name, units = item.get_yaxis() 446 self.graph.yaxis(" Log10%s" % name, "%s^{-1}" % units)459 self.graph.yaxis("\log_{10}\ \ %s" % name, "%s^{-1}" % units) 447 460 448 461 if ( self.yscales=="y^(2)" ): … … 450 463 self.set_yscale("linear") 451 464 name, units = item.get_yaxis() 452 self.graph.yaxis("%s^ 2" % name, "%s^{-2}" % units)465 self.graph.yaxis("%s^{2}" % name, "%s^{-2}" % units) 453 466 454 467 if ( self.yscales =="1/y"): … … 456 469 self.set_yscale("linear") 457 470 name, units = item.get_yaxis() 458 self.graph.yaxis("%s" % name, " %s" % units)471 self.graph.yaxis("%s" % name, "\ \%s" % units) 459 472 460 473 if ( self.yscales =="1/sqrt(y)" ): … … 462 475 self.set_yscale("linear") 463 476 name, units = item.get_yaxis() 464 self.graph.yaxis(" %s" %name, "%s" % units)477 self.graph.yaxis("\sqrt{%s}" %name, "%s" % units) 465 478 466 479 if ( self.yscales =="ln(y*x)"): … … 469 482 yname, yunits = item.get_yaxis() 470 483 xname, xunits = item.get_xaxis() 471 self.graph.yaxis(" Log %s%s" % (yname,xname), "%s^{-1}%s^{-1}" % (yunits,xunits))484 self.graph.yaxis("log\ %s %s" % (yname,xname), "%s^{-1}%s^{-1}" % (yunits,xunits)) 472 485 473 486 if ( self.yscales =="ln(y*x^(2))"): … … 502 515 self.subplot.figure.canvas.draw_idle() 503 516 504 def onFitDisplay(self, plottable ):517 def onFitDisplay(self, plottable,xmin,xmax): 505 518 """ 506 519 Add a new plottable into the graph .In this case this plottable will be used … … 508 521 @param plottable: the plottable to plot 509 522 """ 523 list =[] 524 list = self.graph.returnPlottable() 525 for item in list: 526 item.onFitRange(xmin,xmax) 510 527 #Add the data to fit 511 512 528 self.graph.add(plottable) 513 529 self.graph.render(self) … … 516 532 self.graph.delete(plottable) 517 533 518 534 def onResetGraph(self,event): 535 list =[] 536 list = self.graph.returnPlottable() 537 for item in list: 538 item.onReset() 539 self.graph.render(self) 540 self.subplot.figure.canvas.draw_idle() 519 541 520 542 class NoRepaintCanvas(FigureCanvasWxAgg): -
guitools/fitDialog.py
rf193585 r34ae302 171 171 if (self.xtrans.lower() == "log10(x)"): 172 172 for i in range(len(x)): 173 if x[i]>= xmin:173 if x[i]>= math.log10(xmin): 174 174 tempy.append(math.log10(y[i])) 175 175 tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 176 176 else: 177 for y_i in y:178 tempy.append(math.log10(y _i))177 for i in range(len(y)): 178 tempy.append(math.log10(y[i])) 179 179 tempdy.append(transform.errToLogX(y[i],0,dy[i],0)) 180 180 else: … … 184 184 if (self.xtrans.lower() == "log10(x)"): 185 185 for x_i in x: 186 if x_i >= xmin:186 if x_i >= math.log10(xmin): 187 187 tempx.append(math.log10(x_i)) 188 188 else: … … 196 196 197 197 #Find the fitting parameters 198 199 chisqr, out, cov = fittings.sansfit(self.model, 198 if (self.xtrans.lower() == "log10(x)"): 199 chisqr, out, cov = fittings.sansfit(self.model, [self.cstA, self.cstB], 200 tempx, tempy,tempdy,math.log10(xmin),math.log10(xmax)) 201 else: 202 chisqr, out, cov = fittings.sansfit(self.model, 200 203 [self.cstA, self.cstB],tempx, tempy,tempdy,xminView,xmaxView) 201 204 print "this out",out … … 259 262 260 263 #Send the data to display to the PlotPanel 261 self.push_data(self.file_data1 )264 self.push_data(self.file_data1,xminView,xmaxView) 262 265 263 266 # Display the fitting value on the Fit Dialog … … 310 313 if (self.xtrans=="log10(x)" ): 311 314 if x >0: 312 return math.log10(x)315 return x 313 316 else: 314 317 raise ValueError,"cannot compute log of a negative number" -
guitools/plottables.py
r47f695c9 r34ae302 53 53 if not cond: return False 54 54 return True 55 55 def error_msg(msg, parent=None): 56 """ 57 Signal an error condition -- in a GUI, popup a error dialog 58 """ 59 # Code brought with minor podifications from mpl.backends.backend_wx 60 # Copyright (C) Jeremy O'Donoghue & John Hunter, 2003-4 61 dialog =wx.MessageDialog(parent = parent, 62 message = msg, 63 caption = 'Polplot error', 64 style=wx.OK | wx.CENTRE) 65 dialog.ShowModal() 66 dialog.Destroy() 67 return None 56 68 # Graph structure for holding multiple plottables 57 69 class Graph: … … 383 395 """ Reload view with new value to plot""" 384 396 self.view = self.View(self.x, self.y, self.dx, self.dy) 385 397 self.view.Xreel = self.view.x 398 self.view.Yreel = self.view.y 399 self.view.DXreel = self.view.dx 400 self.view.DYreel = self.view.dy 386 401 def render(self,plot): 387 402 """The base class makes sure the correct units are being used for … … 412 427 def check_data_PlottableY(self): 413 428 self.view.check_data_logY() 429 414 430 def returnTransformationx(self,transx,transdx): 415 431 self.view.returntransformx(transx,transdx) 432 416 433 def returnTransformationy(self,transy,transdy): 417 434 self.view.returntransformy(transy,transdy) 418 435 def onReset(self): 436 self.view.onResetView() 437 def onFitRange(self,xmin,xmax): 438 self.view.onFitRangeView(xmin,xmax) 419 439 class View: 420 440 """ … … 432 452 self.dx = dx 433 453 self.dy = dy 434 454 #to change x range to the reel range 455 self.Xreel = self.x 456 self.Yreel = self.y 457 self.DXreel = self.dx 458 self.DYreel = self.dy 459 435 460 self.transx ="" 436 461 self.transy ="" 462 # function to transform x and y 437 463 self.funcx= None 438 464 self.funcy= None … … 463 489 self.dx = [] 464 490 self.dy = [] 465 491 tempx=[] 492 tempy=[] 466 493 if dx==None: 467 494 dx=numpy.zeros(len(x)) … … 481 508 self.dy.append(tempdy) 482 509 except: 510 tempx=x[i] 511 tempy=y[i] 483 512 print "View.transform: skipping point x %g" % x[i] 484 513 print "View.transform: skipping point y %g" % y[i] 485 514 print "View.transform: skipping point dy %g" % dy[i] 515 486 516 print sys.exc_value 487 print len(self.x) 488 print len(self.dx) 489 print len(self.y) 490 print len(self.dy) 517 491 518 # Sanity check 492 519 if not (len(self.x)==len(self.dx))and(len(self.x)==len(self.dy))\ … … 495 522 self.check_data_logX() 496 523 self.check_data_logY() 497 print len(self.x) 498 print len(self.dx) 499 print len(self.y) 500 print len(self.dy) 524 self.Xreel = self.x 525 self.Yreel = self.y 526 self.DXreel = self.dx 527 self.DYreel = self.dy 528 def onResetView(self): 529 self.x=self.Xreel 530 self.y=self.Yreel 531 self.dx=self.DXreel 532 self.dy=self.DYreel 501 533 def returntransformx(self,funcx,funcdx): 502 534 self.funcx= funcx … … 574 606 self.dy=tempdy 575 607 576 608 def onFitRangeView(self,xmin,xmax): 609 tempx=[] 610 tempdx=[] 611 tempy=[] 612 tempdy=[] 613 for i in range(len(self.x)): 614 if ( self.x[i] >= xmin ) and ( self.x[i] <= xmax ): 615 tempx.append(self.x[i]) 616 tempdx.append(self.dx[i]) 617 tempy.append(self.y[i]) 618 tempdy.append(self.dy[i]) 619 self.x=tempx 620 self.y=tempy 621 self.dx=tempdx 622 self.dy=tempdy 577 623 578 624 class Data1D(Plottable):
Note: See TracChangeset
for help on using the changeset viewer.