Changeset 32c0841 in sasview for guiframe/local_perspectives/plotting/SectorSlicer.py
- Timestamp:
- Nov 23, 2010 11:21:20 AM (14 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:
- a54e4be
- Parents:
- 4a2b054
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/SectorSlicer.py
rd955bf19 r32c0841 2 2 import math 3 3 import wx 4 from copy import deepcopy 5 4 #from copy import deepcopy 6 5 from BaseInteractor import _BaseInteractor 7 from sans.guicomm.events import NewPlotEvent, StatusEvent 8 from sans.guicomm.events import SlicerParameterEvent,EVT_SLICER_PARS 9 6 from sans.guicomm.events import NewPlotEvent 7 from sans.guicomm.events import StatusEvent 8 from sans.guicomm.events import SlicerParameterEvent 9 from sans.guicomm.events import EVT_SLICER_PARS 10 10 from sans.guiframe.dataFitting import Data1D 11 11 12 12 13 class SectorInteractor(_BaseInteractor): … … 14 15 Draw a sector slicer.Allow to performQ averaging on data 2D 15 16 """ 16 def __init__(self, base,axes,color='black', zorder=3):17 def __init__(self, base, axes, color='black', zorder=3): 17 18 18 19 _BaseInteractor.__init__(self, base, axes, color=color) … … 24 25 25 26 ## compute qmax limit to reset the graph 26 x = math.pow(max(self.base.data2D.xmax,math.fabs(self.base.data2D.xmin)),2) 27 y = math.pow(max(self.base.data2D.ymax,math.fabs(self.base.data2D.ymin)),2) 28 self.qmax= math.sqrt(x + y) 27 x = math.pow(max(self.base.data2D.xmax, 28 math.fabs(self.base.data2D.xmin)), 2) 29 y = math.pow(max(self.base.data2D.ymax, 30 math.fabs(self.base.data2D.ymin)), 2) 31 self.qmax = math.sqrt(x + y) 29 32 ## Number of points on the plot 30 33 self.nbins = 20 31 34 ## Angle of the middle line 32 self.theta2 = math.pi/335 self.theta2 = math.pi/3 33 36 ## Absolute value of the Angle between the middle line and any side line 34 self.phi=math.pi/12 35 37 self.phi = math.pi/12 36 38 ## Middle line 37 self.main_line = LineInteractor(self, self.base.subplot,color='blue', zorder=zorder, r=self.qmax, 39 self.main_line = LineInteractor(self, self.base.subplot, color='blue', 40 zorder=zorder, r=self.qmax, 38 41 theta= self.theta2) 39 42 self.main_line.qmax = self.qmax 40 43 ## Right Side line 41 self.right_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 42 r=self.qmax, 43 phi= -1*self.phi, 44 theta2=self.theta2) 44 self.right_line = SideInteractor(self, self.base.subplot, color='black', 45 zorder=zorder, r=self.qmax, 46 phi=-1*self.phi, theta2=self.theta2) 45 47 self.right_line.qmax = self.qmax 46 48 ## Left Side line 47 self.left_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 48 r=self.qmax, 49 phi= self.phi, 50 theta2=self.theta2) 49 self.left_line = SideInteractor(self, self.base.subplot, color='black', 50 zorder=zorder, r=self.qmax, 51 phi=self.phi, theta2=self.theta2) 51 52 self.left_line.qmax = self.qmax 52 53 ## draw the sector 53 54 self.update() 54 55 self._post_data() 55 56 56 ## Bind to slice parameter events 57 57 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 58 58 59 60 59 def _onEVT_SLICER_PARS(self, event): 61 60 """ … … 66 65 67 66 """ 68 wx.PostEvent(self.base.parent, StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 67 wx.PostEvent(self.base.parent, 68 StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 69 69 event.Skip() 70 70 if event.type == self.__class__.__name__: … … 99 99 """ 100 100 # Update locations 101 ## Check if the middle line was dragged and update the picture accordingly 101 ## Check if the middle line was dragged and 102 #update the picture accordingly 102 103 if self.main_line.has_move: 103 104 self.main_line.update() 104 self.right_line.update( delta=-self.left_line.phi/2,105 mline= self.main_line.theta)106 self.left_line.update( delta =self.left_line.phi/2,107 mline= self.main_line.theta)105 self.right_line.update(delta=-self.left_line.phi/2, 106 mline=self.main_line.theta) 107 self.left_line.update(delta=self.left_line.phi/2, 108 mline=self.main_line.theta) 108 109 ## Check if the left side has moved and update the slicer accordingly 109 110 if self.left_line.has_move: 110 111 self.main_line.update() 111 self.left_line.update( phi=None, delta=None, mline=self.main_line , 112 side=True, left=True ) 113 self.right_line.update( phi= self.left_line.phi, delta= None, 114 mline= self.main_line, side= True, 115 left=False, right= True ) 116 ## Check if the right side line has moved and update the slicer accordingly 112 self.left_line.update(phi=None, delta=None, mline=self.main_line, 113 side=True, left=True) 114 self.right_line.update(phi=self.left_line.phi, delta=None, 115 mline=self.main_line, side=True, 116 left=False, right=True) 117 ## Check if the right side line has moved and 118 #update the slicer accordingly 117 119 if self.right_line.has_move: 118 120 self.main_line.update() 119 self.right_line.update( 120 side=True, left=False, right=True 121 self.left_line.update( 122 mline=self.main_line, side=True, left=False 121 self.right_line.update(phi=None, delta=None, mline=self.main_line, 122 side=True, left=False, right=True) 123 self.left_line.update(phi=self.right_line.phi, delta=None, 124 mline=self.main_line, side=True, left=False) 123 125 124 126 def save(self, ev): … … 148 150 phimin = -self.left_line.phi + self.main_line.theta 149 151 phimax = self.left_line.phi + self.main_line.theta 150 151 if nbins==None: 152 if nbins == None: 152 153 nbins = 20 153 sect = SectorQ(r_min= 0.0, r_max= radius,154 phi_min= 155 phi_max= 154 sect = SectorQ(r_min=0.0, r_max=radius, 155 phi_min=phimin + math.pi, 156 phi_max=phimax + math.pi, nbins=nbins) 156 157 157 158 sector = sect(self.base.data2D) 158 159 ##Create 1D data resulting from average 159 160 160 if hasattr(sector, "dxl"):161 dxl = sector.dxl161 if hasattr(sector, "dxl"): 162 dxl = sector.dxl 162 163 else: 163 dxl = None164 if hasattr(sector, "dxw"):165 dxw = sector.dxw164 dxl = None 165 if hasattr(sector, "dxw"): 166 dxw = sector.dxw 166 167 else: 167 dxw= None 168 169 new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy) 168 dxw = None 169 new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy) 170 170 new_plot.dxl = dxl 171 171 new_plot.dxw = dxw 172 new_plot.name = "SectorQ" +"("+ self.base.data2D.name+")" 173 174 new_plot.source=self.base.data2D.source 172 new_plot.name = "SectorQ" + "(" + self.base.data2D.name + ")" 173 new_plot.source = self.base.data2D.source 175 174 #new_plot.info=self.base.data2D.info 176 175 new_plot.interactive = True 177 new_plot.detector = self.base.data2D.detector176 new_plot.detector = self.base.data2D.detector 178 177 # If the data file does not tell us what the axes are, just assume... 179 178 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 180 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")181 new_plot.group_id = "SectorQ" +self.base.data2D.name182 new_plot.id = "SectorQ" +self.base.data2D.name183 new_plot.is_data = True179 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 180 new_plot.group_id = "SectorQ" + self.base.data2D.name 181 new_plot.id = "SectorQ" + self.base.data2D.name 182 new_plot.is_data = True 184 183 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 185 title="SectorQ" +self.base.data2D.name))184 title="SectorQ" + self.base.data2D.name)) 186 185 187 186 def moveend(self, ev): … … 227 226 ## angle of the middle line 228 227 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 229 raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi) 230 228 msg = "Phi left and phi right are different" 229 msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 230 raise ValueError, msg 231 231 params["Phi"] = self.main_line.theta 232 232 params["Delta_Phi"] = math.fabs(self.left_line.phi) … … 243 243 """ 244 244 main = params["Phi"] 245 phi = math.fabs(params["Delta_Phi"] 245 phi = math.fabs(params["Delta_Phi"]) 246 246 self.nbins = int(params["nbins"]) 247 self.main_line.theta = main247 self.main_line.theta = main 248 248 ## Reset the slicer parameters 249 249 self.main_line.update() 250 self.right_line.update( phi=phi,delta=None, mline=self.main_line, 251 side=True, right=True ) 252 self.left_line.update( phi=phi, delta=None, mline=self.main_line, side=True ) 250 self.right_line.update(phi=phi, delta=None, mline=self.main_line, 251 side=True, right=True) 252 self.left_line.update(phi=phi, delta=None, 253 mline=self.main_line, side=True) 253 254 ## post the new corresponding data 254 255 self._post_data(nbins=self.nbins) … … 278 279 279 280 """ 280 def __init__(self,base,axes,color='black', zorder=5, r=1.0,phi=math.pi/4, theta2= math.pi/3): 281 281 def __init__(self, base, axes, color='black', zorder=5, r=1.0, 282 phi=math.pi/4, theta2= math.pi/3): 283 """ 284 """ 282 285 _BaseInteractor.__init__(self, base, axes, color=color) 283 286 ## Initialize the class … … 287 290 ## the x-axis 288 291 self.save_theta = theta2 + phi 289 self.theta = theta2 + phi292 self.theta = theta2 + phi 290 293 ## the value of the middle line angle with respect to the x-axis 291 294 self.theta2 = theta2 … … 294 297 ## phi is the phase between the current line and the middle line 295 298 self.phi = phi 296 297 299 ## End points polar coordinates 298 x1 = self.radius*math.cos(self.theta)299 y1 = self.radius*math.sin(self.theta)300 x2 = -1*self.radius*math.cos(self.theta)301 y2 = -1*self.radius*math.sin(self.theta)300 x1 = self.radius * math.cos(self.theta) 301 y1 = self.radius * math.sin(self.theta) 302 x2 = -1 * self.radius * math.cos(self.theta) 303 y2 = -1 * self.radius * math.sin(self.theta) 302 304 ## defining a new marker 303 305 try: 304 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',306 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 305 307 marker='s', markersize=10, 306 308 color=self.color, alpha=0.6, 307 309 pickradius=5, label="pick", 308 zorder=zorder,# Prefer this to other lines309 visible=True)[0]310 # Prefer this to other lines 311 zorder=zorder, visible=True)[0] 310 312 except: 311 313 self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 312 314 marker='s', markersize=10, 313 315 color=self.color, alpha=0.6, 314 label="pick", 315 visible=True)[0] 316 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 317 message += "Get the SVN version that is at least as recent as June 1, 2007" 318 owner=self.base.base.parent 319 wx.PostEvent(owner, StatusEvent(status="sectorSlicer: %s"%message)) 316 label="pick", visible=True)[0] 317 message = "\nTHIS PROTOTYPE NEEDS THE LATEST" 318 message += " VERSION OF MATPLOTLIB\n Get the SVN version that" 319 message += " is at least as recent as June 1, 2007" 320 owner = self.base.base.parent 321 wx.PostEvent(owner, 322 StatusEvent(status="sectorSlicer: %s" % message)) 320 323 321 324 ## Defining the current line 322 self.line = self.axes.plot([x1, x2],[y1,y2],325 self.line = self.axes.plot([x1, x2], [y1, y2], 323 326 linestyle='-', marker='', 324 color=self.color, 325 visible=True)[0] 327 color=self.color, visible=True)[0] 326 328 ## Flag to differentiate the left line from the right line motion 327 self.left_moving =False329 self.left_moving = False 328 330 ## Flag to define a motion 329 self.has_move =False331 self.has_move = False 330 332 ## connecting markers and draw the picture 331 333 self.connect_markers([self.inner_marker, self.line]) … … 364 366 """ 365 367 #print "update left or right ", self.has_move 366 self.left_moving =left367 theta3 =0368 if phi != None:369 self.phi = phi370 if delta ==None:368 self.left_moving = left 369 theta3 = 0 370 if phi != None: 371 self.phi = phi 372 if delta == None: 371 373 delta = 0 372 374 if right: 373 self.phi = -1 *math.fabs(self.phi)375 self.phi = -1 * math.fabs(self.phi) 374 376 #delta=-delta 375 377 else: 376 self.phi = math.fabs(self.phi)378 self.phi = math.fabs(self.phi) 377 379 if side: 378 self.theta =mline.theta + self.phi380 self.theta = mline.theta + self.phi 379 381 380 if mline !=None :381 if delta !=0:382 self.theta2 = mline +delta382 if mline != None : 383 if delta != 0: 384 self.theta2 = mline + delta 383 385 else: 384 386 self.theta2 = mline.theta 385 if delta ==0:386 theta3 =self.theta+delta387 if delta == 0: 388 theta3 = self.theta + delta 387 389 else: 388 theta3=self.theta2+delta 389 390 x1= self.radius*math.cos(theta3) 391 y1= self.radius*math.sin(theta3) 392 x2= -1*self.radius*math.cos(theta3) 393 y2= -1*self.radius*math.sin(theta3) 394 395 self.inner_marker.set(xdata=[x1/2.5],ydata=[y1/2.5]) 396 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 390 theta3 = self.theta2 + delta 391 x1 = self.radius * math.cos(theta3) 392 y1 = self.radius * math.sin(theta3) 393 x2 = -1 * self.radius * math.cos(theta3) 394 y2 = -1 * self.radius * math.sin(theta3) 395 self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5]) 396 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 397 397 398 398 def save(self, ev): … … 401 401 can restore on Esc. 402 402 """ 403 self.save_theta = self.theta403 self.save_theta = self.theta 404 404 self.base.freeze_axes() 405 405 … … 407 407 """ 408 408 """ 409 self.has_move =False409 self.has_move = False 410 410 self.base.moveend(ev) 411 411 … … 420 420 Process move to a new position, making sure that the move is allowed. 421 421 """ 422 self.theta = math.atan2(y,x)423 self.has_move =True422 self.theta = math.atan2(y, x) 423 self.has_move = True 424 424 #ToDo: Simplify below 425 425 if not self.left_moving: 426 if self.theta2-self.theta <= 0 and self.theta2>0:#>= self.theta2: 426 if self.theta2 - self.theta <= 0 and self.theta2 > 0: 427 self.restore() 428 return 429 elif self.theta2 < 0 and self.theta < 0 and \ 430 self.theta-self.theta2 >= 0: 431 self.restore() 432 return 433 elif self.theta2 < 0 and self.theta > 0 and \ 434 (self.theta2 + 2 * math.pi - self.theta) >= math.pi/2: 427 435 #print "my theta", self.theta 428 436 self.restore() 429 437 return 430 elif self.theta2 < 0 and self.theta < 0 and self.theta-self.theta2 >= 0: 431 self.restore() 432 return 433 elif self.theta2 < 0 and self.theta > 0 and self.theta2+2*math.pi-self.theta >=math.pi/2: 438 elif self.theta2 < 0 and self.theta < 0 and \ 439 (self.theta2 - self.theta) >= math.pi/2: 434 440 #print "my theta", self.theta 435 441 self.restore() 436 442 return 437 elif self.theta2 < 0 and self.theta < 0 and self.theta2-self.theta >=math.pi/2: 438 #print "my theta", self.theta 439 self.restore() 440 return 441 elif self.theta2>0 and (self.theta2-self.theta >= math.pi/2 or (self.theta2-self.theta >= math.pi/2)):#<= self.theta2 -math.pi/2: 443 elif self.theta2 > 0 and (self.theta2-self.theta >= math.pi/2 or \ 444 (self.theta2-self.theta >= math.pi/2)): 442 445 #print "self theta encore" 443 446 self.restore() … … 445 448 else: 446 449 #print "left move" 447 if self.theta < 0 and self.theta+math.pi*2-self.theta2<= 0:450 if self.theta < 0 and (self.theta + math.pi*2-self.theta2) <= 0: 448 451 self.restore() 449 452 return 450 elif self.theta2 < 0 and self.theta-self.theta2<= 0:453 elif self.theta2 < 0 and (self.theta-self.theta2) <= 0: 451 454 self.restore() 452 455 return 453 elif self.theta > 0 and self.theta-self.theta2 <= 0:456 elif self.theta > 0 and self.theta-self.theta2 <= 0: 454 457 #print "my theta", self.theta 455 458 self.restore() 456 459 return 457 elif self.theta-self.theta2 >= math.pi/2 or (self.theta+math.pi*2-self.theta2 >= math.pi/2 and self.theta<0 and self.theta2>0): 460 elif self.theta-self.theta2 >= math.pi/2 or \ 461 ((self.theta + math.pi * 2 - self.theta2) >= math.pi/2 and \ 462 self.theta < 0 and self.theta2 > 0): 458 463 #print "self theta encore" 459 464 self.restore() 460 465 return 461 466 462 self.phi= math.fabs(self.theta2 - self.theta) 463 if self.phi>math.pi: 464 self.phi= 2*math.pi-math.fabs(self.theta2 - self.theta) 465 467 self.phi = math.fabs(self.theta2 - self.theta) 468 if self.phi > math.pi: 469 self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta) 466 470 self.base.base.update() 467 471 … … 491 495 Select an annulus through a 2D plot 492 496 """ 493 def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta=math.pi/4): 497 def __init__(self, base, axes, color='black', 498 zorder=5, r=1.0, theta=math.pi/4): 494 499 """ 495 500 """ … … 503 508 self.scale = 10.0 504 509 # Inner circle 505 x1 = self.radius*math.cos(self.theta)506 y1 = self.radius*math.sin(self.theta)507 x2 = -1*self.radius*math.cos(self.theta)508 y2 = -1*self.radius*math.sin(self.theta)510 x1 = self.radius * math.cos(self.theta) 511 y1 = self.radius * math.sin(self.theta) 512 x2 = -1*self.radius * math.cos(self.theta) 513 y2 = -1*self.radius * math.sin(self.theta) 509 514 try: 510 515 # Inner circle marker 511 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',516 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 512 517 marker='s', markersize=10, 513 518 color=self.color, alpha=0.6, 514 519 pickradius=5, label="pick", 515 zorder=zorder, # Prefer this to other lines 520 # Prefer this to other lines 521 zorder=zorder, 516 522 visible=True)[0] 517 523 except: 518 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',524 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 519 525 marker='s', markersize=10, 520 526 color=self.color, alpha=0.6, 521 527 label="pick", 522 528 visible=True)[0] 523 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"524 message += " Get the SVN version that is at least as recent as June 1, 2007"525 526 self.line = self.axes.plot([x1, x2],[y1,y2],529 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 530 message += " OF MATPLOTLIB\n Get the SVN version that is at" 531 message += " least as recent as June 1, 2007" 532 self.line = self.axes.plot([x1, x2], [y1, y2], 527 533 linestyle='-', marker='', 528 color=self.color, 529 visible=True)[0] 534 color=self.color, visible=True)[0] 530 535 self.npts = 20 531 self.has_move =False536 self.has_move = False 532 537 self.connect_markers([self.inner_marker, self.line]) 533 538 self.update() … … 556 561 """ 557 562 558 if theta != None:559 self.theta = theta560 x1 = self.radius*math.cos(self.theta)561 y1 = self.radius*math.sin(self.theta)562 x2 = -1*self.radius*math.cos(self.theta)563 y2 = -1*self.radius*math.sin(self.theta)564 565 self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5])566 self.line.set(xdata=[x1, x2], ydata=[y1,y2])563 if theta != None: 564 self.theta = theta 565 x1 = self.radius * math.cos(self.theta) 566 y1 = self.radius * math.sin(self.theta) 567 x2 = -1 * self.radius * math.cos(self.theta) 568 y2 = -1 * self.radius * math.sin(self.theta) 569 570 self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5]) 571 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 567 572 568 573 def save(self, ev): … … 577 582 """ 578 583 """ 579 self.has_move =False584 self.has_move = False 580 585 self.base.moveend(ev) 581 586 … … 590 595 Process move to a new position, making sure that the move is allowed. 591 596 """ 592 self.theta = math.atan2(y,x)593 self.has_move =True597 self.theta = math.atan2(y, x) 598 self.has_move = True 594 599 self.base.base.update() 595 600
Note: See TracChangeset
for help on using the changeset viewer.