- Timestamp:
- Jan 5, 2009 5:45:49 PM (16 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:
- cd68f8c
- Parents:
- b461b6d7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/boxSlicer.py
rb319def8 r8ff3ec1 28 28 self.qmax = self.base.qmax 29 29 self.connect = self.base.connect 30 self.xmin=x_min 31 self.ymin=y_min 32 self.xmax=x_max 33 self.ymax=y_max 30 self.xmin= -1* x_min 31 self.ymin= -1* y_min 32 self.xmax= x_max 33 self.ymax= y_max 34 35 self.theta2= math.pi/2 34 36 ## Number of points on the plot 35 37 self.nbins = 20 36 38 self.count=0 37 39 self.error=0 38 #self.theta3= 2*self.theta2 -self.theta1 39 # Inner circle 40 self.main_line = LineInteractor(self, self.base.subplot,color='orange', zorder=zorder, r=self.qmax, 41 theta= self.theta2) 42 self.main_line.qmax = self.base.qmax 43 40 44 self.left_line = VerticalLine(self, self.base.subplot,color='blue', zorder=zorder, 41 ymin=-1*self.ymin, ymax=self.ymax, 42 xmin=-1*self.xmin,xmax=-1*self.xmax) 45 ymin= self.ymin, ymax= self.ymax, 46 x= self.xmin, 47 theta2= self.theta2) 43 48 self.left_line.qmax = self.base.qmax 44 49 45 50 self.right_line= VerticalLine(self, self.base.subplot,color='black', zorder=zorder, 46 ymin=-1*self.ymin, ymax=self.ymax, 47 xmin=self.xmin,xmax=self.xmax) 51 ymin= self.ymin, ymax= self.ymax, 52 x=self.xmax, 53 theta2= self.theta2) 48 54 self.right_line.qmax = self.base.qmax 49 55 50 56 self.top_line= HorizontalLine(self, self.base.subplot,color='green', zorder=zorder, 51 ymin=self.ymax, ymax=self.ymax, 52 xmin=-1*self.xmax,xmax=self.xmax) 57 y= self.ymax, 58 xmin= self.xmin, xmax= self.xmax, 59 theta2= self.theta2) 53 60 self.top_line.qmax = self.base.qmax 54 61 55 62 self.bottom_line= HorizontalLine(self, self.base.subplot,color='red', zorder=zorder, 56 ymin=-1*self.ymin, ymax=-1*self.ymin, 57 xmin=-1*self.xmin,xmax=self.xmin) 63 y =self.ymin, 64 xmin= self.xmin, xmax= self.xmax, 65 theta2= self.theta2) 58 66 self.bottom_line.qmax = self.base.qmax 59 67 #self.outer_circle.set_cursor(self.base.qmax/1.8, 0) … … 98 106 self.top_line.clear() 99 107 self.bottom_line.clear() 108 self.main_line.clear() 100 109 #self.base.connect.disconnect() 101 110 self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) … … 106 115 resetting the widgets. 107 116 """ 108 self.left_line.update() 109 self.right_line.update() 110 self.top_line.update() 111 self.bottom_line.update() 117 118 if self.main_line.has_move: 119 print "main has move" 120 self.main_line.update() 121 self.left_line.update(mline= self.main_line) 122 self.right_line.update(mline= self.main_line) 123 self.top_line.update(mline= self.main_line) 124 self.bottom_line.update(mline= self.main_line) 125 112 126 if self.left_line.has_move: 113 127 print "left has moved" … … 129 143 print "bottom has moved" 130 144 self.bottom_line.update() 131 self.top_line.update() 132 #self.top_line.update(ymin= -1*self.bottom_line.y ,ymax=-1*self.bottom_line.y) 145 self.top_line.update(y= -1*self.top_line.y) 133 146 self.left_line.update( ymin= self.bottom_line.y ,ymax= self.top_line.y) 134 147 self.right_line.update(ymin= self.bottom_line.y ,ymax= self.top_line.y) … … 137 150 print "top has moved" 138 151 self.top_line.update() 139 #self.bottom_line.update() 140 self.bottom_line.update(y min= -1*self.top_line.y ,ymax=-1*self.top_line.y)152 #self.bottom_line.update()xmin=None, xmax=None,y=None, mline=None): 153 self.bottom_line.update(y= -1*self.top_line.y ) 141 154 self.left_line.update(ymin= self.bottom_line.y ,ymax= self.top_line.y) 142 155 self.right_line.update(ymin= self.bottom_line.y ,ymax= self.top_line.y) … … 203 216 params["count"] = self.count 204 217 params["error"] = self.error 218 params["phi"] = self.main_line.theta 205 219 return params 206 220 … … 211 225 y_min = params["y_min"] 212 226 y_max = params["y_max"] 213 227 theta = params["theta"] 214 228 215 229 self.left_line.update(ymin= y_min ,ymax= y_max) … … 217 231 self.top_line.update( xmin= x_min ,xmax= xmax) 218 232 self.bottom_line.update(xmin= xmin ,xmax= xmax) 233 self.main_line.update(theta) 234 219 235 self._post_data() 220 236 def freeze_axes(self): … … 231 247 Select an annulus through a 2D plot 232 248 """ 233 def __init__(self,base,axes,color='black', zorder=5, ymin=0.0, ymax=0.5,xmin=0.0,xmax=0.5): 249 def __init__(self,base,axes,color='black', zorder=5, y=0.5, 250 xmin=0.0,xmax=0.5, 251 theta2= math.pi/3 ): 234 252 235 253 _BaseInteractor.__init__(self, base, axes, color=color) … … 237 255 self.axes = axes 238 256 239 self.y=y min240 self.save_y=y min257 self.y=y 258 self.save_y=y 241 259 242 260 self.xmin=xmin … … 244 262 self.xmax=xmax 245 263 self.save_xmax=xmax 264 self.theta2= theta2 265 self.radius1= math.sqrt(math.pow(self.xmin, 2)+ math.pow(self.y, 2)) 266 self.radius2= math.sqrt(math.pow(self.xmax, 2)+ math.pow(self.y, 2)) 267 268 269 #print "phi and theta2", math.degrees(math.atan2(self.y, self.xmax)) 270 271 self.theta_right= math.atan2(self.y,self.xmin) 272 self.theta_left= math.atan2(self.y,self.xmax) 273 274 self.phi_left= self.theta_left - self.theta2 275 self.phi_right= self.theta_right - self.theta2 276 #print "phi left right", math.degrees(self.phi_left),math.degrees(self.phi_right) 277 print "theta left right ", math.degrees(self.theta_left),math.degrees(self.theta_right) 246 278 247 279 self.line = self.axes.plot([self.xmin,self.xmax],[self.y,self.y], 280 linestyle='-', marker='', 281 color=self.color, 282 visible=True)[0] 283 284 285 self.npts = 20 286 self.has_move=False 287 self.connect_markers([self.line]) 288 self.update() 289 290 def set_layer(self, n): 291 self.layernum = n 292 self.update() 293 294 def clear(self): 295 self.clear_markers() 296 try: 297 298 self.line.remove() 299 except: 300 # Old version of matplotlib 301 for item in range(len(self.axes.lines)): 302 del self.axes.lines[0] 303 304 def get_radius(self): 305 306 return 0 307 308 def update(self,xmin=None, xmax=None,y=None, mline=None): 309 """ 310 Draw the new roughness on the graph. 311 """ 312 #print "update main line", self.has_move 313 if xmin !=None: 314 self.xmin=xmin 315 if xmax !=None: 316 self.xmax=xmax 317 if y !=None: 318 self.y = y 319 if mline !=None: 320 self.theta2= mline.theta 321 delta = mline.get_delta_angle() 322 # rotation 323 x1 = self.radius1 * math.cos(self.phi_left + delta) 324 y1= self.radius1 * math.sin(self.phi_left + delta) 325 326 x2= -1*self.radius2 * math.cos( self.phi_right + delta) 327 y2= -1*self.radius2 * math.sin(self.phi_right + delta) 328 329 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 330 print "Horizontal: update ",math.degrees(self.phi_left +delta),math.degrees(self.phi_right+delta) 331 print x1,x2,y1,y2 332 333 else: 334 self.line.set(xdata=[self.xmin,self.xmax], ydata=[self.y,self.y]) 335 336 337 338 def save(self, ev): 339 """ 340 Remember the roughness for this layer and the next so that we 341 can restore on Esc. 342 """ 343 self.save_xmin= self.xmin 344 self.save_xmax= self.xmax 345 346 self.save_y= self.y 347 self.base.freeze_axes() 348 349 def moveend(self, ev): 350 351 self.has_move=False 352 self.base.moveend(ev) 353 354 def restore(self): 355 """ 356 Restore the roughness for this layer. 357 """ 358 self.ymin = self.save_ymin 359 self.ymax = self.save_ymax 360 361 def move(self, x, y, ev): 362 """ 363 Process move to a new position, making sure that the move is allowed. 364 """ 365 self.y=y 366 367 368 self.has_move=True 369 self.base.base.update() 370 371 def set_cursor(self, x, y): 372 self.move(x, y, None) 373 self.update() 374 375 376 def get_params(self): 377 params = {} 378 params["radius"] = self.xmin 379 params["theta"] = self.xmax 380 return params 381 382 def set_params(self, params): 383 384 x = params["radius"] 385 self.set_cursor(x, self._inner_mouse_y) 386 387 388 389 390 class VerticalLine(_BaseInteractor): 391 """ 392 Select an annulus through a 2D plot 393 """ 394 def __init__(self,base,axes,color='black', zorder=5, ymin=0.0, 395 ymax=0.5,x= 0.5, 396 theta2= math.pi/3 ): 397 398 _BaseInteractor.__init__(self, base, axes, color=color) 399 self.markers = [] 400 self.axes = axes 401 # x coordinate of the vertical line 402 self.x = x 403 self.save_x = x 404 # minimum value of y coordinate of the vertical line 405 self.ymin = ymin 406 self.save_ymin = ymin 407 # maximum value of y coordinate of the vertical line 408 self.ymax=ymax 409 self.save_ymax=ymax 410 #insure rotation 411 self.radius1= math.sqrt(math.pow(self.x, 2)+ math.pow(self.ymin, 2)) 412 self.radius2= math.sqrt(math.pow(self.x, 2)+ math.pow(self.ymax, 2)) 413 414 415 self.theta_down = math.atan2(self.ymin, self.x) 416 self.theta_up = math.atan2(self.ymax, self.x) 417 self.theta2= theta2 418 419 self.phi_down= self.theta_down - self.theta2 420 self.phi_up= self.theta_up - self.theta2 421 print "phi up down", math.degrees(self.phi_up),math.degrees(self.phi_down) 422 print "theta up down ", math.degrees(self.theta_up),math.degrees(self.theta_down) 423 # Draw vertical line 424 self.line = self.axes.plot([self.x,self.x],[self.ymin,self.ymax], 425 linestyle='-', marker='', 426 color=self.color, 427 visible=True)[0] 428 429 self.npts = 20 430 # Check vertical line motion 431 self.has_move=False 432 self.connect_markers([self.line]) 433 self.update() 434 435 def set_layer(self, n): 436 self.layernum = n 437 self.update() 438 439 def clear(self): 440 self.clear_markers() 441 try: 442 443 self.line.remove() 444 except: 445 # Old version of matplotlib 446 for item in range(len(self.axes.lines)): 447 del self.axes.lines[0] 448 449 def get_radius(self): 450 return 0 451 452 def update(self,x=None,ymin=None, ymax=None, mline=None): 453 """ 454 Draw the new roughness on the graph. 455 """ 456 if x!=None: 457 self.x = x 458 if ymin !=None: 459 self.ymin = ymin 460 if ymax !=None: 461 self.ymax = ymax 462 if mline !=None: 463 self.theta2= mline.theta 464 delta = mline.get_delta_angle() 465 # rotation 466 x1 = self.radius1 * math.cos(self.phi_down + delta) 467 y1= self.radius1 * math.sin(self.phi_down + delta) 468 469 x2= -1*self.radius2 * math.cos( self.phi_up + delta) 470 y2= -1*self.radius2 * math.sin(self.phi_up + delta) 471 472 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 473 474 else: 475 self.line.set(xdata=[self.x,self.x], ydata=[self.ymin,self.ymax]) 476 477 478 479 def save(self, ev): 480 """ 481 Remember the roughness for this layer and the next so that we 482 can restore on Esc. 483 """ 484 self.save_x= self.x 485 self.save_ymin= self.ymin 486 self.save_ymax= self.ymax 487 488 self.base.freeze_axes() 489 490 def moveend(self, ev): 491 492 self.has_move=False 493 self.base.moveend(ev) 494 495 def restore(self): 496 """ 497 Restore the roughness for this layer. 498 """ 499 self.x = self.save_x 500 501 self.ymin=self.save_ymin 502 self.ymax=self.save_ymax 503 def move(self, x, y, ev): 504 """ 505 Process move to a new position, making sure that the move is allowed. 506 """ 507 self.x = x 508 self.has_move=True 509 self.base.base.update() 510 511 512 def set_cursor(self, x, y): 513 self.move(x, y, None) 514 self.update() 515 516 517 def get_params(self): 518 params = {} 519 params["x"] = self.xmin 520 params["ymin"] = self.ymin 521 params["ymax"] = self.ymax 522 return params 523 524 def set_params(self, params): 525 """ 526 Draw a vertical line given some value of params 527 @param params: a dictionary containing value for x, ymin , ymax to draw 528 a vertical line 529 """ 530 x = params["x"] 531 ymin = params["ymin"] 532 ymax = params["ymax"] 533 #self.set_cursor(x, self._inner_mouse_y) 534 self.update(self,x =x,ymin =ymin, ymax =ymax) 535 536 537 538 class LineInteractor(_BaseInteractor): 539 """ 540 Select an annulus through a 2D plot 541 """ 542 def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta=math.pi/4): 543 544 _BaseInteractor.__init__(self, base, axes, color=color) 545 self.markers = [] 546 self.axes = axes 547 548 self.save_theta = theta 549 self.theta= theta 550 551 self.radius = r 552 553 self.scale = 10.0 554 555 # Inner circle 556 x1= self.radius*math.cos(self.theta) 557 y1= self.radius*math.sin(self.theta) 558 x2= -1*self.radius*math.cos(self.theta) 559 y2= -1*self.radius*math.sin(self.theta) 560 561 self.line = self.axes.plot([x1,x2],[y1,y2], 248 562 linestyle='-', marker='', 249 563 color=self.color, … … 256 570 257 571 def set_layer(self, n): 572 258 573 self.layernum = n 259 574 self.update() 260 575 261 576 def clear(self): 577 """ 578 Remove the line of the plot 579 """ 262 580 self.clear_markers() 263 581 try: 264 265 582 self.line.remove() 266 583 except: … … 271 588 272 589 273 def get_radius(self): 274 275 return 0 276 277 def update(self,xmin=None, xmax=None,ymin=None, ymax=None): 278 """ 279 Draw the new roughness on the graph. 280 """ 281 #print "update main line", self.has_move 282 if xmin !=None: 283 self.xmin=xmin 284 if xmax !=None: 285 self.xmax=xmax 286 if ymin !=None: 287 self.y=ymin 288 if ymax !=None: 289 self.y = ymax 290 self.line.set(xdata=[self.xmin,self.xmax], ydata=[self.y,self.y]) 590 def get_delta_angle(self): 591 """ 592 return difference between initial angle and the final angle during 593 rotation 594 """ 595 return self.theta - self.save_theta 596 597 def update(self, theta=None,radius=None): 598 """ 599 Draw a line given and angle relative to the x-axis and a radius 600 @param theta: the angle realtive to the x-axis 601 @param radius: the distance between the center and one end of the line 602 """ 603 604 if theta !=None: 605 self.theta= theta 606 if radius !=None: 607 self.radius =radius 608 print "update main line", math.degrees(self.theta) 609 x1= self.radius*math.cos(self.theta) 610 y1= self.radius*math.sin(self.theta) 611 x2= -1*self.radius*math.cos(self.theta) 612 y2= -1*self.radius*math.sin(self.theta) 613 614 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 291 615 292 616 … … 297 621 can restore on Esc. 298 622 """ 299 self.save_xmin= self.xmin 300 self.save_xmax= self.xmax 301 302 self.save_y= self.y 623 self.save_theta= self.theta 303 624 self.base.freeze_axes() 304 625 … … 312 633 Restore the roughness for this layer. 313 634 """ 314 self.ymin = self.save_ymin 315 self.ymax = self.save_ymax 635 self.theta = self.save_theta 316 636 317 637 def move(self, x, y, ev): … … 319 639 Process move to a new position, making sure that the move is allowed. 320 640 """ 321 self.y=y 322 323 641 self.theta= math.atan2(y,x) 642 #print "main_line previous theta --- next theta ",math.degrees(self.save_theta),math.degrees(self.theta) 324 643 self.has_move=True 325 644 self.base.base.update() 326 645 646 327 647 def set_cursor(self, x, y): 648 328 649 self.move(x, y, None) 329 650 self.update() … … 331 652 332 653 def get_params(self): 654 """ 655 return params a dictionary containing values of paramters necessary to draw 656 this line 657 """ 333 658 params = {} 334 params["radius"] = self. xmin335 params["theta"] = self. xmax659 params["radius"] = self.radius 660 params["theta"] = self.theta 336 661 return params 337 662 338 663 def set_params(self, params): 339 340 x = params["radius"] 341 self.set_cursor(x, self._inner_mouse_y) 342 343 344 345 346 class VerticalLine(_BaseInteractor): 347 """ 348 Select an annulus through a 2D plot 349 """ 350 def __init__(self,base,axes,color='black', zorder=5, ymin=0.0, ymax=0.5,xmin=0.0,xmax=0.5): 351 352 _BaseInteractor.__init__(self, base, axes, color=color) 353 self.markers = [] 354 self.axes = axes 355 356 self.x=xmin 357 self.save_x=xmin 358 359 self.ymin=ymin 360 self.save_ymin=ymin 361 self.ymax=ymax 362 self.save_ymax=ymax 363 364 self.line = self.axes.plot([self.x,self.x],[self.ymin,self.ymax], 365 linestyle='-', marker='', 366 color=self.color, 367 visible=True)[0] 368 369 self.npts = 20 370 self.has_move=False 371 self.connect_markers([self.line]) 372 self.update() 373 374 def set_layer(self, n): 375 self.layernum = n 376 self.update() 377 378 def clear(self): 379 self.clear_markers() 380 try: 381 382 self.line.remove() 383 except: 384 # Old version of matplotlib 385 for item in range(len(self.axes.lines)): 386 del self.axes.lines[0] 387 388 389 390 def get_radius(self): 391 392 return 0 393 394 def update(self,xmin=None, xmax=None,ymin=None, ymax=None): 395 """ 396 Draw the new roughness on the graph. 397 """ 398 399 if xmin !=None: 400 self.x=xmin 401 if xmin !=None: 402 self.x=xmax 403 if ymin !=None: 404 self.ymin=ymin 405 if ymax !=None: 406 self.ymax=ymax 407 print "update vertical line", self.has_move,[self.x,self.x], [self.ymin,self.ymax] 408 self.line.set(xdata=[self.x,self.x], ydata=[self.ymin,self.ymax]) 409 410 411 412 def save(self, ev): 413 """ 414 Remember the roughness for this layer and the next so that we 415 can restore on Esc. 416 """ 417 self.save_x= self.x 418 419 self.save_ymin= self.ymin 420 self.save_ymax= self.ymax 421 self.base.freeze_axes() 422 423 def moveend(self, ev): 424 425 self.has_move=False 426 self.base.moveend(ev) 427 428 def restore(self): 429 """ 430 Restore the roughness for this layer. 431 """ 432 self.x = self.save_x 433 434 self.ymin=self.save_ymin 435 self.ymax=self.save_ymax 436 def move(self, x, y, ev): 437 """ 438 Process move to a new position, making sure that the move is allowed. 439 """ 440 self.x=x 441 442 443 444 self.has_move=True 445 self.base.base.update() 446 447 def set_cursor(self, x, y): 448 self.move(x, y, None) 449 self.update() 450 451 452 def get_params(self): 453 params = {} 454 params["radius"] = self.xmin 455 params["theta"] = self.xmax 456 params["radius"] = self.xmin 457 params["theta"] = self.xmax 458 return params 459 460 def set_params(self, params): 461 462 x = params["radius"] 463 self.set_cursor(x, self._inner_mouse_y) 464 465 466 467 664 """ 665 Draw the line given value contains by params 666 @param params: dictionary containing name of parameters and their values 667 """ 668 radius = params["radius"] 669 theta = params["theta"] 670 self.update(x, theta= theta , radius = radius ) 671 672 673 674 675
Note: See TracChangeset
for help on using the changeset viewer.