Changeset b5de88e in sasview for src/sas/guiframe/local_perspectives/plotting/boxSlicer.py
- Timestamp:
- Mar 5, 2015 12:49:03 PM (10 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:
- 7d56795
- Parents:
- 824e488
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/boxSlicer.py
r79492222 rb5de88e 1 2 3 1 import wx 4 #import copy5 #from copy import deepcopy6 2 import math 7 3 import numpy … … 12 8 from BaseInteractor import _BaseInteractor 13 9 from sas.guiframe.dataFitting import Data1D 14 #import SlicerParameters15 10 16 11 … … 22 17 def __init__(self, base, axes, color='black', zorder=3): 23 18 _BaseInteractor.__init__(self, base, axes, color=color) 24 # # Class initialization19 # # Class initialization 25 20 self.markers = [] 26 21 self.axes = axes 27 # #connecting artist22 # #connecting artist 28 23 self.connect = self.base.connect 29 # # which direction is the preferred interaction direction24 # # which direction is the preferred interaction direction 30 25 self.direction = None 31 # # determine x y values26 # # determine x y values 32 27 self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), 33 28 math.fabs(self.base.data2D.xmin)) 34 29 self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), 35 math.fabs(self.base.data2D.xmin)) 36 # # when reach qmax reset the graph30 math.fabs(self.base.data2D.xmin)) 31 # # when reach qmax reset the graph 37 32 self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, 38 self.base.data2D.ymax, self.base.data2D.ymin) 39 # # Number of points on the plot33 self.base.data2D.ymax, self.base.data2D.ymin) 34 # # Number of points on the plot 40 35 self.nbins = 30 41 # # If True, I(|Q|) will be return, otherwise,42 # negative q-values are allowed43 self.fold = True 44 # # reference of the current Slab averaging36 # # If True, I(|Q|) will be return, otherwise, 37 # negative q-values are allowed 38 self.fold = True 39 # # reference of the current Slab averaging 45 40 self.averager = None 46 # # Create vertical and horizaontal lines for the rectangle41 # # Create vertical and horizaontal lines for the rectangle 47 42 self.vertical_lines = VerticalLines(self, 48 self.base.subplot, 49 color='blue', 43 self.base.subplot, 44 color='blue', 50 45 zorder=zorder, 51 y=self.y 46 y=self.y, 52 47 x=self.x) 53 48 self.vertical_lines.qmax = self.qmax 54 49 55 50 self.horizontal_lines = HorizontalLines(self, 56 self.base.subplot,57 color='green',58 zorder=zorder,59 x=self.x,60 y=self.y)51 self.base.subplot, 52 color='green', 53 zorder=zorder, 54 x=self.x, 55 y=self.y) 61 56 self.horizontal_lines.qmax = self.qmax 62 # # draw the rectangle and plost the data 1D resulting63 # # of averaging data2D57 # # draw the rectangle and plost the data 1D resulting 58 # # of averaging data2D 64 59 self.update() 65 60 self._post_data() 66 # # Bind to slice parameter events61 # # Bind to slice parameter events 67 62 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 68 63 … … 70 65 """ 71 66 receive an event containing parameters values to reset the slicer 72 73 :param event: event of type SlicerParameterEvent with params as 67 68 :param event: event of type SlicerParameterEvent with params as 74 69 attribute 75 70 """ … … 80 75 self.set_params(event.params) 81 76 self.base.update() 82 77 83 78 def update_and_post(self): 84 79 """ … … 87 82 self.update() 88 83 self._post_data() 89 84 90 85 def set_layer(self, n): 91 86 """ 92 87 Allow adding plot to the same panel 93 88 94 89 :param n: the number of layer 95 90 96 91 """ 97 92 self.layernum = n 98 93 self.update() 99 94 100 95 def clear(self): 101 96 """ … … 108 103 self.base.connect.clearall() 109 104 self.base.Unbind(EVT_SLICER_PARS) 110 105 111 106 def update(self): 112 107 """ … … 114 109 resetting the widgets. 115 110 """ 116 # #Update the slicer if an horizontal line is dragged111 # #Update the slicer if an horizontal line is dragged 117 112 if self.horizontal_lines.has_move: 118 113 self.horizontal_lines.update() 119 114 self.vertical_lines.update(y=self.horizontal_lines.y) 120 # #Update the slicer if a vertical line is dragged115 # #Update the slicer if a vertical line is dragged 121 116 if self.vertical_lines.has_move: 122 117 self.vertical_lines.update() 123 118 self.horizontal_lines.update(x=self.vertical_lines.x) 124 119 125 120 def save(self, ev): 126 121 """ … … 131 126 self.vertical_lines.save(ev) 132 127 self.horizontal_lines.save(ev) 133 128 134 129 def _post_data(self): 135 130 pass 136 131 137 132 def post_data(self, new_slab=None, nbins=None, direction=None): 138 133 """ 139 134 post data averaging in Qx or Qy given new_slab type 140 135 141 136 :param new_slab: slicer that determine with direction to average 142 137 :param nbins: the number of points plotted when averaging 143 138 :param direction: the direction of averaging 144 139 145 140 """ 146 141 if self.direction == None: 147 142 self.direction = direction 148 143 149 144 x_min = -1 * math.fabs(self.vertical_lines.x) 150 145 x_max = math.fabs(self.vertical_lines.x) 151 146 y_min = -1 * math.fabs(self.horizontal_lines.y) 152 147 y_max = math.fabs(self.horizontal_lines.y) 153 148 154 149 if nbins != None: 155 150 self.nbins = nbins … … 164 159 else: 165 160 x_low = math.fabs(x_min) 166 bin_width = (x_max + x_low) /self.nbins161 bin_width = (x_max + x_low) / self.nbins 167 162 elif self.direction == "Y": 168 163 if self.fold: … … 170 165 else: 171 166 y_low = math.fabs(y_min) 172 bin_width = (y_max + y_low) /self.nbins167 bin_width = (y_max + y_low) / self.nbins 173 168 else: 174 169 msg = "post data:no Box Average direction was supplied" 175 170 raise ValueError, msg 176 # # Average data2D given Qx or Qy171 # # Average data2D given Qx or Qy 177 172 box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 178 bin_width=bin_width)173 bin_width=bin_width) 179 174 box.fold = self.fold 180 175 boxavg = box(self.base.data2D) 181 # 3 Create Data1D to plot176 # 3 Create Data1D to plot 182 177 if hasattr(boxavg, "dxl"): 183 178 dxl = boxavg.dxl … … 189 184 dxw = None 190 185 new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) 191 new_plot.dxl 192 new_plot.dxw 186 new_plot.dxl = dxl 187 new_plot.dxw = dxw 193 188 new_plot.name = str(self.averager.__name__) + \ 194 189 "(" + self.base.data2D.name + ")" … … 196 191 new_plot.interactive = True 197 192 new_plot.detector = self.base.data2D.detector 198 # # If the data file does not tell us what the axes are, just assume...193 # # If the data file does not tell us what the axes are, just assume... 199 194 new_plot.xaxis("\\rm{Q}", "A^{-1}") 200 195 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") … … 205 200 new_plot.ytransform = 'y' 206 201 new_plot.yaxis("\\rm{Residuals} ", "/") 207 202 208 203 new_plot.group_id = "2daverage" + self.base.data2D.name 209 204 new_plot.id = (self.averager.__name__) + self.base.data2D.name 210 new_plot.is_data = True205 new_plot.is_data = True 211 206 self.base.parent.update_theory(data_id=self.base.data2D.id, \ 212 207 theory=new_plot) 213 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot,214 215 208 wx.PostEvent(self.base.parent, 209 NewPlotEvent(plot=new_plot, title=str(self.averager.__name__))) 210 216 211 def moveend(self, ev): 217 212 """ 218 213 Called after a dragging event. 219 Post the slicer new parameters and creates a new Data1D 214 Post the slicer new parameters and creates a new Data1D 220 215 corresponding to the new average 221 216 """ … … 228 223 # create the new data1D 229 224 self._post_data() 230 225 231 226 def restore(self): 232 227 """ … … 235 230 self.horizontal_lines.restore() 236 231 self.vertical_lines.restore() 237 232 238 233 def move(self, x, y, ev): 239 234 """ … … 241 236 """ 242 237 pass 243 238 244 239 def set_cursor(self, x, y): 245 240 pass 246 241 247 242 def get_params(self): 248 243 """ 249 244 Store a copy of values of parameters of the slicer into a dictionary. 250 245 251 246 :return params: the dictionary created 252 247 253 248 """ 254 249 params = {} … … 257 252 params["nbins"] = self.nbins 258 253 return params 259 254 260 255 def set_params(self, params): 261 256 """ 262 Receive a dictionary and reset the slicer with values contained 257 Receive a dictionary and reset the slicer with values contained 263 258 in the values of the dictionary. 264 265 :param params: a dictionary containing name of slicer parameters and 259 260 :param params: a dictionary containing name of slicer parameters and 266 261 values the user assigned to the slicer. 267 262 """ 268 263 self.x = float(math.fabs(params["x_max"])) 269 self.y = float(math.fabs(params["y_max"] 264 self.y = float(math.fabs(params["y_max"])) 270 265 self.nbins = params["nbins"] 271 266 272 267 self.horizontal_lines.update(x=self.x, y=self.y) 273 268 self.vertical_lines.update(x=self.x, y=self.y) 274 269 self.post_data(nbins=None) 275 270 276 271 def freeze_axes(self): 277 272 """ 278 273 """ 279 274 self.base.freeze_axes() 280 275 281 276 def thaw_axes(self): 282 277 """ … … 292 287 class HorizontalLines(_BaseInteractor): 293 288 """ 294 Draw 2 Horizontal lines centered on (0,0) that can move 289 Draw 2 Horizontal lines centered on (0,0) that can move 295 290 on the x- direction and in opposite direction 296 291 """ … … 299 294 """ 300 295 _BaseInteractor.__init__(self, base, axes, color=color) 301 # #Class initialization296 # #Class initialization 302 297 self.markers = [] 303 298 self.axes = axes 304 # # Saving the end points of two lines299 # # Saving the end points of two lines 305 300 self.x = x 306 301 self.save_x = x 307 302 308 303 self.y = y 309 304 self.save_y = y 310 ## Creating a marker 311 try: 312 # Inner circle marker 313 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 314 marker='s', markersize=10, 315 color=self.color, alpha=0.6, 316 pickradius=5, label="pick", 317 # Prefer this to other lines 318 zorder=zorder, 319 visible=True)[0] 320 except: 321 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 322 marker='s', markersize=10, 323 color=self.color, alpha=0.6, 324 label="pick", visible=True)[0] 325 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 326 message += "OF MATPLOTLIB\n Get the SVN version that" 327 message += " is at least as recent as June 1, 2007" 328 owner = self.base.base.parent 329 wx.PostEvent(owner, 330 StatusEvent(status="AnnulusSlicer: %s" % message)) 331 ## Define 2 horizontal lines 305 # # Creating a marker 306 # Inner circle marker 307 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 308 marker='s', markersize=10, 309 color=self.color, alpha=0.6, 310 pickradius=5, label="pick", 311 zorder=zorder, 312 visible=True)[0] 313 # # Define 2 horizontal lines 332 314 self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 333 linestyle='-', marker='',334 color=self.color, visible=True)[0]315 linestyle='-', marker='', 316 color=self.color, visible=True)[0] 335 317 self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], 336 linestyle='-', marker='',337 color=self.color, visible=True)[0]338 # # Flag to check the motion of the lines318 linestyle='-', marker='', 319 color=self.color, visible=True)[0] 320 # # Flag to check the motion of the lines 339 321 self.has_move = False 340 # # Connecting markers to mouse events and draw322 # # Connecting markers to mouse events and draw 341 323 self.connect_markers([self.top_line, self.inner_marker]) 342 324 self.update() … … 345 327 """ 346 328 Allow adding plot to the same panel 347 329 348 330 :param n: the number of layer 349 331 350 332 """ 351 333 self.layernum = n 352 334 self.update() 353 335 354 336 def clear(self): 355 337 """ … … 359 341 try: 360 342 self.inner_marker.remove() 361 self.top_line.remove() 343 self.top_line.remove() 362 344 self.bottom_line.remove() 363 345 except: … … 365 347 for item in range(len(self.axes.lines)): 366 348 del self.axes.lines[0] 367 349 368 350 def update(self, x=None, y=None): 369 351 """ 370 352 Draw the new roughness on the graph. 371 353 372 354 :param x: x-coordinates to reset current class x 373 355 :param y: y-coordinates to reset current class y 374 375 """ 376 # # Reset x, y- coordinates if send as parameters356 357 """ 358 # # Reset x, y- coordinates if send as parameters 377 359 if x != None: 378 360 self.x = numpy.sign(self.x) * math.fabs(x) 379 361 if y != None: 380 362 self.y = numpy.sign(self.y) * math.fabs(y) 381 # # Draw lines and markers363 # # Draw lines and markers 382 364 self.inner_marker.set(xdata=[0], ydata=[self.y]) 383 365 self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) 384 self.bottom_line.set(xdata=[self.x, -self.x], ydata=[-self.y, -self.y])385 366 self.bottom_line.set(xdata=[self.x, -self.x], ydata=[-self.y, -self.y]) 367 386 368 def save(self, ev): 387 369 """ … … 400 382 self.has_move = False 401 383 self.base.moveend(ev) 402 384 403 385 def restore(self): 404 386 """ … … 407 389 self.x = self.save_x 408 390 self.y = self.save_y 409 391 410 392 def move(self, x, y, ev): 411 393 """ … … 415 397 self.has_move = True 416 398 self.base.base.update() 417 418 399 400 419 401 class VerticalLines(_BaseInteractor): 420 402 """ … … 431 413 self.y = math.fabs(y) 432 414 self.save_y = y 433 try: 434 # Inner circle marker 435 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 436 marker='s', markersize=10, 437 color=self.color, alpha=0.6, 438 pickradius=5, label="pick", 439 # Prefer this to other lines 440 zorder=zorder, visible=True)[0] 441 except: 442 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 443 marker='s', markersize=10, 444 color=self.color, alpha=0.6, 445 label="pick", visible=True)[0] 446 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 447 message += " OF MATPLOTLIB\n Get the SVN version that is" 448 message += " at least as recent as June 1, 2007" 449 415 # Inner circle marker 416 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 417 marker='s', markersize=10, 418 color=self.color, alpha=0.6, 419 pickradius=5, label="pick", 420 zorder=zorder, visible=True)[0] 450 421 self.right_line = self.axes.plot([self.x, self.x], 451 [self.y 452 linestyle='-', marker='',453 color=self.color, visible=True)[0]422 [self.y, -self.y], 423 linestyle='-', marker='', 424 color=self.color, visible=True)[0] 454 425 self.left_line = self.axes.plot([-self.x, -self.x], 455 426 [self.y, -self.y], 456 linestyle='-', marker='',457 color=self.color, visible=True)[0]427 linestyle='-', marker='', 428 color=self.color, visible=True)[0] 458 429 self.has_move = False 459 430 self.connect_markers([self.right_line, self.inner_marker]) … … 463 434 """ 464 435 Allow adding plot to the same panel 465 436 466 437 :param n: the number of layer 467 438 468 439 """ 469 440 self.layernum = n 470 441 self.update() 471 442 472 443 def clear(self): 473 444 """ … … 487 458 """ 488 459 Draw the new roughness on the graph. 489 460 490 461 :param x: x-coordinates to reset current class x 491 462 :param y: y-coordinates to reset current class y 492 493 """ 494 # # reset x, y -coordinates if given as parameters463 464 """ 465 # # reset x, y -coordinates if given as parameters 495 466 if x != None: 496 467 self.x = numpy.sign(self.x) * math.fabs(x) 497 468 if y != None: 498 469 self.y = numpy.sign(self.y) * math.fabs(y) 499 # # draw lines and markers500 self.inner_marker.set(xdata=[self.x], ydata=[0]) 501 self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 502 self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 503 470 # # draw lines and markers 471 self.inner_marker.set(xdata=[self.x], ydata=[0]) 472 self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 473 self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 474 504 475 def save(self, ev): 505 476 """ … … 510 481 self.save_y = self.y 511 482 self.base.freeze_axes() 512 483 513 484 def moveend(self, ev): 514 485 """ … … 518 489 self.has_move = False 519 490 self.base.moveend(ev) 520 491 521 492 def restore(self): 522 493 """ … … 525 496 self.x = self.save_x 526 497 self.y = self.save_y 527 498 528 499 def move(self, x, y, ev): 529 500 """ … … 533 504 self.x = x 534 505 self.base.base.update() 535 536 506 507 537 508 class BoxInteractorX(BoxInteractor): 538 509 """ … … 543 514 self.base = base 544 515 self._post_data() 545 516 546 517 def _post_data(self): 547 518 """ … … 549 520 """ 550 521 from sas.dataloader.manipulations import SlabX 551 self.post_data(SlabX, direction="X") 552 522 self.post_data(SlabX, direction="X") 523 553 524 554 525 class BoxInteractorY(BoxInteractor): … … 560 531 self.base = base 561 532 self._post_data() 562 533 563 534 def _post_data(self): 564 535 """ … … 566 537 """ 567 538 from sas.dataloader.manipulations import SlabY 568 self.post_data(SlabY, direction="Y") 569 570 539 self.post_data(SlabY, direction="Y") 540
Note: See TracChangeset
for help on using the changeset viewer.