Changeset 18eba35 in sasview for guiframe/local_perspectives/plotting/boxSlicer.py
- Timestamp:
- Feb 24, 2009 11:46:12 AM (15 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:
- cce33b3
- Parents:
- 2a8fac1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/boxSlicer.py
r3b909b7 r18eba35 11 11 from BaseInteractor import _BaseInteractor 12 12 from copy import deepcopy 13 import math 13 import math, numpy 14 14 15 15 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS … … 22 22 Select an annulus through a 2D plot 23 23 """ 24 def __init__(self,base,axes,color='black', zorder=3, 25 x_min=0.0025, x_max=0.0025, y_min=0.0025, y_max=0.0025): 26 24 def __init__(self,base,axes,color='black', zorder=3): 27 25 _BaseInteractor.__init__(self, base, axes, color=color) 26 28 27 self.markers = [] 29 28 self.axes = axes 30 self.qmax = self.base.data2D.xmax29 31 30 self.connect = self.base.connect 31 32 32 self.x= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 33 33 self.y= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 34 35 self.theta2= math.pi/3 34 35 self.qmax = max(self.base.data2D.xmax,self.base.data2D.xmin, 36 self.base.data2D.ymax,self.base.data2D.ymin ) 37 36 38 ## Number of points on the plot 37 39 self.nbins = 30 … … 39 41 self.error=0 40 42 self.averager=None 41 self.left_line = VerticalLine(self, self.base.subplot,color='blue', 43 44 self.vertical_lines = VerticalLines(self, self.base.subplot,color='blue', 42 45 zorder=zorder, 43 ymin= -self.y , 44 ymax= self.y , 45 xmin= -self.x, 46 xmax= -self.x) 47 self.left_line.qmax = self.qmax 48 49 self.right_line= VerticalLine(self, self.base.subplot,color='black', 46 y= self.y , 47 x= self.x) 48 self.vertical_lines.qmax = self.qmax 49 50 self.horizontal_lines= HorizontalLines(self, self.base.subplot,color='green', 50 51 zorder=zorder, 51 ymin= -self.y , 52 ymax= self.y, 53 xmin= self.x, 54 xmax= self.x) 55 self.right_line.qmax = self.qmax 56 57 self.top_line= HorizontalLine(self, self.base.subplot,color='green', 58 zorder=zorder, 59 xmin= -self.x, 60 xmax= self.x, 61 ymin= self.y, 62 ymax= self.y) 63 self.top_line.qmax= self.qmax 64 65 self.bottom_line= HorizontalLine(self, self.base.subplot,color='gray', 66 zorder=zorder, 67 xmin= -self.x, 68 xmax= self.x, 69 ymin= -self.y, 70 ymax= -self.y) 71 self.bottom_line.qmax= self.qmax 52 x= self.x, 53 y= self.y) 54 self.horizontal_lines.qmax= self.qmax 55 56 72 57 73 58 self.update() … … 75 60 76 61 # Bind to slice parameter events 77 self.base. parent.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS)62 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 78 63 79 64 80 65 def _onEVT_SLICER_PARS(self, event): 81 #printEVT("AnnulusSlicer._onEVT_SLICER_PARS")66 wx.PostEvent(self.base.parent, StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 82 67 event.Skip() 83 68 if event.type == self.__class__.__name__: … … 106 91 self.averager=None 107 92 self.clear_markers() 108 self.left_line.clear() 109 self.right_line.clear() 110 self.top_line.clear() 111 self.bottom_line.clear() 112 #self.base.connect.disconnect() 113 self.base.parent.Unbind(EVT_SLICER_PARS) 93 self.horizontal_lines.clear() 94 self.vertical_lines.clear() 95 self.base.connect.clearall() 96 97 self.base.Unbind(EVT_SLICER_PARS) 114 98 115 99 def update(self): … … 118 102 resetting the widgets. 119 103 """ 120 121 if self.top_line.has_move: 122 #print"top has moved" 123 self.top_line.update() 124 self.bottom_line.update(ymin= -self.top_line.y1, 125 ymax= -self.top_line.y2) 126 self.left_line.update(ymin= -self.top_line.y1, 127 ymax= -self.top_line.y2) 128 self.right_line.update(ymin= -self.top_line.y1, 129 ymax= -self.top_line.y2) 130 131 if self.bottom_line.has_move: 132 #print "bottom has move" 133 self.bottom_line.update() 134 self.top_line.update(ymin= -self.bottom_line.y1, 135 ymax= -self.bottom_line.y2) 136 self.left_line.update(ymin= self.bottom_line.y1, 137 ymax= self.top_line.y1) 138 self.right_line.update(ymin= self.bottom_line.y1, 139 ymax=self.top_line.y1) 140 141 if self.left_line.has_move: 142 143 self.left_line.update() 144 self.right_line.update(xmin = - self.left_line.x1, 145 xmax = - self.left_line.x1) 146 self.bottom_line.update(xmin= self.left_line.x1, 147 xmax= self.right_line.x1) 148 self.top_line.update(xmin= self.left_line.x1, 149 xmax= self.right_line.x1) 150 151 if self.right_line.has_move: 152 153 self.right_line.update() 154 self.left_line.update(xmin = -self.right_line.x1, 155 xmax = -self.right_line.x1) 156 157 self.bottom_line.update(xmin= self.left_line.x1, 158 xmax= self.right_line.x1) 159 160 self.top_line.update(xmin= self.left_line.x1, 161 xmax= self.right_line.x1) 104 if self.horizontal_lines.has_move: 105 #print "top has moved" 106 self.horizontal_lines.update() 107 self.vertical_lines.update(y=self.horizontal_lines.y) 108 if self.vertical_lines.has_move: 109 #print "right has moved" 110 self.vertical_lines.update() 111 self.horizontal_lines.update(x=self.vertical_lines.x) 112 162 113 163 114 … … 168 119 """ 169 120 self.base.freeze_axes() 170 self.left_line.save(ev) 171 self.right_line.save(ev) 172 self.top_line.save(ev) 173 self.bottom_line.save(ev) 121 self.vertical_lines.save(ev) 122 self.horizontal_lines.save(ev) 123 174 124 def _post_data(self): 175 125 pass … … 178 128 def post_data(self,new_slab=None , nbins=None): 179 129 """ post data averaging in Q""" 180 x_min= min(self.left_line.x1, self.right_line.x1)181 x_max= ma x(self.left_line.x1, self.right_line.x1)182 183 y_min= min(self.top_line.y1, self.bottom_line.y1)184 y_max= ma x(self.top_line.y1, self.bottom_line.y1)130 x_min= -1*math.fabs(self.vertical_lines.x) 131 x_max= math.fabs(self.vertical_lines.x) 132 133 y_min= -1*math.fabs(self.horizontal_lines.y) 134 y_max= math.fabs(self.horizontal_lines.y) 185 135 186 136 if nbins !=None: … … 223 173 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 224 174 title=str(self.averager.__name__) )) 225 226 227 def _post_data(self): 228 # Compute data 229 data = self.base.data2D 230 from DataLoader.manipulations import Boxavg 231 radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 232 self.x= math.fabs(self.right_line.x1) 233 self.y= math.fabs(self.top_line.y1 ) 234 235 box = Boxavg (x_min=-self.x, x_max=self.x, y_min=-self.y, y_max=self.y) 236 237 self.count, self.error= box(self.base.data2D) 238 239 #print "post data" 175 240 176 241 177 … … 255 191 Restore the roughness for this layer. 256 192 """ 257 self.left_line.restore() 258 self.right_line.restore() 259 self.top_line.restore() 260 self.bottom_line.restore() 193 self.horizontal_lines.restore() 194 self.vertical_lines.restore() 195 261 196 262 197 def move(self, x, y, ev): … … 271 206 def get_params(self): 272 207 params = {} 273 params["x_max"]= math.fabs(self. right_line.x1)274 params["y_max"]= math.fabs(self. top_line.y1)208 params["x_max"]= math.fabs(self.vertical_lines.x) 209 params["y_max"]= math.fabs(self.horizontal_lines.y) 275 210 params["nbins"]= self.nbins 276 params["errors"] = self.error 277 params["count"]= self.count 211 278 212 return params 279 213 … … 283 217 self.y = float(math.fabs(params["y_max"] )) 284 218 self.nbins=params["nbins"] 285 self.left_line.update(xmin= -1*self.x, 286 xmax = -1*self.x, 287 ymin= -self.y, 288 ymax= self.y, 289 ) 290 self.right_line.update(xmin= self.x, 291 xmax = self.x, 292 ymin= -self.y, 293 ymax= self.y, 294 ) 295 self.top_line.update(xmin= -1*self.x, 296 xmax= self.x, 297 ymin= self.y, 298 ymax= self.y) 299 self.bottom_line.update(xmin= -1*self.x, 300 xmax= self.x, 301 ymin= -1*self.y, 302 ymax= -1*self.y) 303 219 220 self.horizontal_lines.update(x= self.x, y= self.y) 221 self.vertical_lines.update(x= self.x, y= self.y) 304 222 self.post_data( nbins=None) 223 224 305 225 def freeze_axes(self): 306 226 self.base.freeze_axes() … … 312 232 self.base.draw() 313 233 314 class HorizontalLine (_BaseInteractor):234 class HorizontalLines(_BaseInteractor): 315 235 """ 316 236 Select an annulus through a 2D plot 317 237 """ 318 def __init__(self,base,axes,color='black', zorder=5,mline=None,ymin=None, ymax=None, y=0.5, 319 xmin=0.0,xmax=0.5): 238 def __init__(self,base,axes,color='black', zorder=5,x=0.5, y=0.5): 320 239 321 240 _BaseInteractor.__init__(self, base, axes, color=color) 322 241 self.markers = [] 323 242 self.axes = axes 324 self.x1= xmax 325 self.save_x1= xmax 326 327 self.x2= xmin 328 self.save_x2= xmin 329 330 self.y1= ymax 331 self.save_y1= ymax 332 333 self.y2= ymin 334 self.save_y2= ymin 335 self.mline= mline 336 self.line = self.axes.plot([self.x1,-self.x1], 337 [self.y1,self.y2], 243 self.x= x 244 self.save_x= x 245 246 self.y= y 247 self.save_y= y 248 249 try: 250 # Inner circle marker 251 self.inner_marker = self.axes.plot([0],[self.y], linestyle='', 252 marker='s', markersize=10, 253 color=self.color, alpha=0.6, 254 pickradius=5, label="pick", 255 zorder=zorder, # Prefer this to other lines 256 visible=True)[0] 257 except: 258 self.inner_marker = self.axes.plot([0],[self.y], linestyle='', 259 marker='s', markersize=10, 260 color=self.color, alpha=0.6, 261 label="pick", 262 visible=True)[0] 263 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 264 message += "Get the SVN version that is at least as recent as June 1, 2007" 265 266 self.top_line = self.axes.plot([self.x,-self.x], 267 [self.y,self.y], 338 268 linestyle='-', marker='', 339 269 color=self.color, 340 270 visible=True)[0] 341 342 self.npts = 20 271 self.bottom_line = self.axes.plot([self.x,-self.x], 272 [-self.y,-self.y], 273 linestyle='-', marker='', 274 color=self.color, 275 visible=True)[0] 276 343 277 self.has_move=False 344 self.connect_markers([self. line])278 self.connect_markers([self.top_line, self.inner_marker]) 345 279 self.update() 346 280 … … 352 286 self.clear_markers() 353 287 try: 354 355 self.line.remove() 288 self.inner_marker.remove() 289 self.top_line.remove() 290 self.bottom_line.remove() 356 291 except: 357 292 # Old version of matplotlib … … 359 294 del self.axes.lines[0] 360 295 361 def get_radius(self):362 363 return 0364 296 365 def update(self,x min=None, xmax=None,ymin=None,ymax=None, mline=None,translation=False):297 def update(self,x=None,y=None): 366 298 """ 367 299 Draw the new roughness on the graph. 368 300 """ 369 if xmin !=None: 370 self.x1 = xmin 371 if ymin !=None: 372 self.y1 = ymin 373 self.line.set(xdata=[self.x1,-self.x1], 374 ydata=[self.y1,self.y1]) 375 301 if x!=None: 302 self.x = numpy.sign(self.x)*math.fabs(x) 303 if y !=None: 304 self.y = numpy.sign(self.y)*math.fabs(y) 305 self.inner_marker.set(xdata=[0],ydata=[self.y]) 306 307 self.top_line.set(xdata=[self.x,-self.x], 308 ydata=[self.y,self.y]) 309 self.bottom_line.set(xdata=[self.x,-self.x], 310 ydata=[-self.y, -self.y]) 376 311 377 312 … … 381 316 can restore on Esc. 382 317 """ 383 self.save_x1= self.x1 384 self.save_x2= self.x2 385 386 self.save_y1= self.y1 387 self.save_y2= self.y2 388 318 self.save_x= self.x 319 self.save_y= self.y 389 320 390 321 self.base.freeze_axes() … … 399 330 Restore the roughness for this layer. 400 331 """ 401 self.x1 = self.save_x1 402 self.x2 = self.save_x2 403 self.y1 = self.save_y1 404 self.y2 = self.save_y2 332 self.x = self.save_x 333 self.y = self.save_y 405 334 406 335 … … 410 339 """ 411 340 #print "horizontal move x y " 412 self.y 1= y341 self.y= y 413 342 self.has_move=True 414 343 self.base.base.update() 415 344 416 def set_cursor(self, x, y): 417 self.move(x, y, None) 418 self.update() 419 420 421 def get_params(self): 422 params = {} 423 params["radius"] = self.x1 424 #params["theta"] = self.xmax 425 return params 426 427 def set_params(self, params): 428 429 x = params["radius"] 430 self.set_cursor(x, self._inner_mouse_y) 431 432 433 434 435 class VerticalLine(_BaseInteractor): 345 346 347 348 349 class VerticalLines(_BaseInteractor): 436 350 """ 437 351 Select an annulus through a 2D plot 438 352 """ 439 def __init__(self,base,axes,color='black', zorder=5, mline=None, ymin=0.0, 440 ymax=0.5,xmin=-0.5,xmax=0.5 441 ): 353 def __init__(self,base,axes,color='black',zorder=5,x=0.5, y=0.5): 442 354 443 355 _BaseInteractor.__init__(self, base, axes, color=color) … … 445 357 self.axes = axes 446 358 447 self.x1= xmax 448 self.x2= xmin 449 self.y1= ymax 450 self.y2= ymin 451 self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], 359 self.x= math.fabs(x) 360 self.save_x= self.x 361 self.y= math.fabs(y) 362 self.save_y= y 363 364 try: 365 # Inner circle marker 366 self.inner_marker = self.axes.plot([self.x],[0], linestyle='', 367 marker='s', markersize=10, 368 color=self.color, alpha=0.6, 369 pickradius=5, label="pick", 370 zorder=zorder, # Prefer this to other lines 371 visible=True)[0] 372 except: 373 self.inner_marker = self.axes.plot([self.x],[0], linestyle='', 374 marker='s', markersize=10, 375 color=self.color, alpha=0.6, 376 label="pick", 377 visible=True)[0] 378 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 379 message += "Get the SVN version that is at least as recent as June 1, 2007" 380 381 self.right_line = self.axes.plot([self.x,self.x],[self.y,-self.y], 382 linestyle='-', marker='', 383 color=self.color, 384 visible=True)[0] 385 self.left_line = self.axes.plot([-self.x,-self.x],[self.y,-self.y], 452 386 linestyle='-', marker='', 453 387 color=self.color, … … 455 389 456 390 self.has_move=False 457 self.connect_markers([self. line])391 self.connect_markers([self.right_line, self.inner_marker]) 458 392 self.update() 459 393 … … 465 399 self.clear_markers() 466 400 try: 467 468 self.line.remove() 401 self.inner_marker.remove() 402 self.left_line.remove() 403 self.right_line.remove() 469 404 except: 470 405 # Old version of matplotlib 471 406 for item in range(len(self.axes.lines)): 472 407 del self.axes.lines[0] 473 474 475 def get_radius(self): 476 return 0 477 478 def update(self,xmin=None,xmax=None,ymin=None, ymax=None, opline=None,translation=False): 408 409 def update(self,x=None,y=None): 479 410 """ 480 411 Draw the new roughness on the graph. 481 412 """ 482 413 483 484 if xmin!=None: 485 self.x1=xmin 486 if ymin!=None: 487 self.y1=ymin 488 self.line.set(xdata=[self.x1,self.x1], 489 ydata=[self.y1,-self.y1]) 490 414 if x!=None: 415 self.x = numpy.sign(self.x)*math.fabs(x) 416 if y !=None: 417 self.y = numpy.sign(self.y)*math.fabs(y) 418 419 self.inner_marker.set(xdata=[self.x],ydata=[0]) 420 self.left_line.set(xdata=[-self.x,-self.x], 421 ydata=[self.y,-self.y]) 422 self.right_line.set(xdata=[self.x,self.x], 423 ydata=[self.y,-self.y]) 491 424 492 425 … … 496 429 can restore on Esc. 497 430 """ 498 self.save_x1= self.x1 499 self.save_x2= self.x2 500 self.save_y1= self.y1 501 self.save_y2= self.y2 431 self.save_x= self.x 432 self.save_y= self.y 502 433 503 434 self.base.freeze_axes() … … 512 443 Restore the roughness for this layer. 513 444 """ 514 self.x1 = self.save_x1 515 self.x2 = self.save_x2 516 self.y1 = self.save_y1 517 self.y2= self.save_y2 445 self.x = self.save_x 446 self.y = self.save_y 518 447 519 448 … … 523 452 """ 524 453 self.has_move=True 525 526 # compute the b intercept of the vertical line 527 self.x1= x 528 529 454 self.x= x 530 455 self.base.base.update() 531 456 532 533 def set_cursor(self, x, y): 534 self.move(x, y, None) 535 self.update() 536 537 538 def get_params(self): 539 params = {} 540 params["x"] = self.xmin 541 params["ymin"] = self.ymin 542 params["ymax"] = self.ymax 543 return params 544 545 def set_params(self, params): 546 """ 547 Draw a vertical line given some value of params 548 @param params: a dictionary containing value for x, ymin , ymax to draw 549 a vertical line 550 """ 551 x = params["x"] 552 ymin = params["ymin"] 553 ymax = params["ymax"] 554 #self.set_cursor(x, self._inner_mouse_y) 555 self.update(self,x =x,ymin =ymin, ymax =ymax) 457 556 458 557 459
Note: See TracChangeset
for help on using the changeset viewer.