Changeset 3bdbfcc in sasview for src/sas/sasgui/guiframe/local_perspectives/plotting/SectorSlicer.py
- Timestamp:
- Feb 2, 2017 6:29:07 AM (7 years ago)
- Branches:
- 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
- Children:
- 965fbd8
- Parents:
- 5d89f43
- git-author:
- Piotr Rozyczko <rozyczko@…> (01/23/17 07:21:03)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (02/02/17 06:29:07)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/local_perspectives/plotting/SectorSlicer.py
rd85c194 r3bdbfcc 3 3 """ 4 4 import math 5 import wx 5 from PyQt4 import QtGui 6 from PyQt4 import QtCore 7 6 8 from BaseInteractor import _BaseInteractor 7 from sas.sasgui.guiframe.events import NewPlotEvent8 from sas.sasgui.guiframe.events import StatusEvent9 from sas.sasgui.guiframe.events import SlicerParameterEvent10 from sas.sasgui.guiframe.events import EVT_SLICER_PARS11 9 from sas.sasgui.guiframe.dataFitting import Data1D 12 13 14 class SectorInteractor(_BaseInteractor): 10 import sas.qtgui.GuiUtils as GuiUtils 11 from sas.qtgui.SlicerModel import SlicerModel 12 13 14 class SectorInteractor(_BaseInteractor, SlicerModel): 15 15 """ 16 16 Draw a sector slicer.Allow to performQ averaging on data 2D 17 17 """ 18 def __init__(self, base, axes, color='black', zorder=3):18 def __init__(self, base, axes, item=None, color='black', zorder=3): 19 19 20 20 _BaseInteractor.__init__(self, base, axes, color=color) 21 ## Class initialization 21 SlicerModel.__init__(self) 22 # Class initialization 22 23 self.markers = [] 23 24 self.axes = axes 24 ## connect the plot to event 25 self._item = item 26 # Connect the plot to event 25 27 self.connect = self.base.connect 26 28 27 # # compute qmax limit to reset the graph28 x = math.pow(max(self.base.data 2D.xmax,29 math.fabs(self.base.data 2D.xmin)), 2)30 y = math.pow(max(self.base.data 2D.ymax,31 math.fabs(self.base.data 2D.ymin)), 2)29 # Compute qmax limit to reset the graph 30 x = math.pow(max(self.base.data.xmax, 31 math.fabs(self.base.data.xmin)), 2) 32 y = math.pow(max(self.base.data.ymax, 33 math.fabs(self.base.data.ymin)), 2) 32 34 self.qmax = math.sqrt(x + y) 33 # #Number of points on the plot35 # Number of points on the plot 34 36 self.nbins = 20 35 # #Angle of the middle line37 # Angle of the middle line 36 38 self.theta2 = math.pi / 3 37 # #Absolute value of the Angle between the middle line and any side line39 # Absolute value of the Angle between the middle line and any side line 38 40 self.phi = math.pi / 12 39 # #Middle line40 self.main_line = LineInteractor(self, self. base.subplot, color='blue',41 # Middle line 42 self.main_line = LineInteractor(self, self.axes, color='blue', 41 43 zorder=zorder, r=self.qmax, 42 44 theta=self.theta2) 43 45 self.main_line.qmax = self.qmax 44 # #Right Side line45 self.right_line = SideInteractor(self, self. base.subplot, color='black',46 # Right Side line 47 self.right_line = SideInteractor(self, self.axes, color='black', 46 48 zorder=zorder, r=self.qmax, 47 49 phi=-1 * self.phi, theta2=self.theta2) 48 50 self.right_line.qmax = self.qmax 49 # #Left Side line50 self.left_line = SideInteractor(self, self. base.subplot, color='black',51 # Left Side line 52 self.left_line = SideInteractor(self, self.axes, color='black', 51 53 zorder=zorder, r=self.qmax, 52 54 phi=self.phi, theta2=self.theta2) 53 55 self.left_line.qmax = self.qmax 54 # #draw the sector56 # draw the sector 55 57 self.update() 56 58 self._post_data() 57 ## Bind to slice parameter events 58 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 59 60 def _onEVT_SLICER_PARS(self, event): 61 """ 62 receive an event containing parameters values to reset the slicer 63 64 :param event: event of type SlicerParameterEvent with params as 65 attribute 66 67 """ 68 wx.PostEvent(self.base.parent, 69 StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 70 event.Skip() 71 if event.type == self.__class__.__name__: 72 self.set_params(event.params) 73 self.base.update() 59 self.setModelFromParams() 74 60 75 61 def set_layer(self, n): 76 62 """ 77 63 Allow adding plot to the same panel 78 79 64 :param n: the number of layer 80 81 65 """ 82 66 self.layernum = n … … 92 76 self.right_line.clear() 93 77 self.base.connect.clearall() 94 self.base.Unbind(EVT_SLICER_PARS)95 78 96 79 def update(self): … … 100 83 """ 101 84 # Update locations 102 # #Check if the middle line was dragged and103 # update the picture accordingly85 # Check if the middle line was dragged and 86 # update the picture accordingly 104 87 if self.main_line.has_move: 105 88 self.main_line.update() … … 108 91 self.left_line.update(delta=self.left_line.phi / 2, 109 92 mline=self.main_line.theta) 110 # #Check if the left side has moved and update the slicer accordingly93 # Check if the left side has moved and update the slicer accordingly 111 94 if self.left_line.has_move: 112 95 self.main_line.update() … … 116 99 mline=self.main_line, side=True, 117 100 left=False, right=True) 118 ## Check if the right side line has moved and 119 #update the slicer accordingly 101 # Check if the right side line has moved and update the slicer accordingly 120 102 if self.right_line.has_move: 121 103 self.main_line.update() … … 130 112 can restore on Esc. 131 113 """ 132 self.base.freeze_axes()133 114 self.main_line.save(ev) 134 115 self.right_line.save(ev) … … 141 122 :param nbins: the number of point to plot for the average 1D data 142 123 """ 143 # # get the data2D to average144 data = self.base.data 2D124 # Get the data2D to average 125 data = self.base.data 145 126 # If we have no data, just return 146 127 if data == None: 147 128 return 148 # #Averaging129 # Averaging 149 130 from sas.sascalc.dataloader.manipulations import SectorQ 150 131 radius = self.qmax … … 157 138 phi_max=phimax + math.pi, nbins=nbins) 158 139 159 sector = sect(self.base.data 2D)160 # #Create 1D data resulting from average140 sector = sect(self.base.data) 141 # Create 1D data resulting from average 161 142 162 143 if hasattr(sector, "dxl"): … … 171 152 new_plot.dxl = dxl 172 153 new_plot.dxw = dxw 173 new_plot.name = "SectorQ" + "(" + self.base.data 2D.name + ")"174 new_plot. source = self.base.data2D.source175 #new_plot.info=self.base.data2D.info154 new_plot.name = "SectorQ" + "(" + self.base.data.name + ")" 155 new_plot.title = "SectorQ" + "(" + self.base.data.name + ")" 156 new_plot.source = self.base.data.source 176 157 new_plot.interactive = True 177 new_plot.detector = self.base.data 2D.detector178 # # If the data file does not tell us what the axes are, just assume...158 new_plot.detector = self.base.data.detector 159 # If the data file does not tell us what the axes are, just assume them. 179 160 new_plot.xaxis("\\rm{Q}", "A^{-1}") 180 161 new_plot.yaxis("\\rm{Intensity}", "cm^{-1}") 181 162 if hasattr(data, "scale") and data.scale == 'linear' and \ 182 self.base.data 2D.name.count("Residuals") > 0:163 self.base.data.name.count("Residuals") > 0: 183 164 new_plot.ytransform = 'y' 184 165 new_plot.yaxis("\\rm{Residuals} ", "/") 185 166 186 new_plot.group_id = "2daverage" + self.base.data 2D.name187 new_plot.id = "SectorQ" + self.base.data 2D.name167 new_plot.group_id = "2daverage" + self.base.data.name 168 new_plot.id = "SectorQ" + self.base.data.name 188 169 new_plot.is_data = True 189 self.base.parent.update_theory(data_id=data.id, theory=new_plot) 190 wx.PostEvent(self.base.parent, 191 NewPlotEvent(plot=new_plot, title="SectorQ" + self.base.data2D.name)) 170 variant_plot = QtCore.QVariant(new_plot) 171 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 172 173 if self.update_model: 174 self.setModelFromParams() 175 self.draw() 192 176 193 177 def moveend(self, ev): … … 195 179 Called a dragging motion ends.Get slicer event 196 180 """ 197 self.base.thaw_axes() 198 ## Post parameters 199 event = SlicerParameterEvent() 200 event.type = self.__class__.__name__ 201 event.params = self.get_params() 202 ## Send slicer paramers to plotter2D 203 wx.PostEvent(self.base, event) 181 # Post parameters 182 self._post_data(self.nbins) 204 183 205 184 def restore(self): … … 222 201 pass 223 202 224 def get _params(self):203 def getParams(self): 225 204 """ 226 205 Store a copy of values of parameters of the slicer into a dictionary. 227 228 206 :return params: the dictionary created 229 230 207 """ 231 208 params = {} 232 # #Always make sure that the left and the right line are at phi233 # #angle of the middle line209 # Always make sure that the left and the right line are at phi 210 # angle of the middle line 234 211 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 235 212 msg = "Phi left and phi right are different" … … 241 218 return params 242 219 243 def set _params(self, params):220 def setParams(self, params): 244 221 """ 245 222 Receive a dictionary and reset the slicer with values contained … … 253 230 self.nbins = int(params["nbins"]) 254 231 self.main_line.theta = main 255 # #Reset the slicer parameters232 # Reset the slicer parameters 256 233 self.main_line.update() 257 234 self.right_line.update(phi=phi, delta=None, mline=self.main_line, … … 259 236 self.left_line.update(phi=phi, delta=None, 260 237 mline=self.main_line, side=True) 261 # # post the new corresponding data238 # Post the new corresponding data 262 239 self._post_data(nbins=self.nbins) 263 264 def freeze_axes(self):265 """266 """267 self.base.freeze_axes()268 269 def thaw_axes(self):270 """271 """272 self.base.thaw_axes()273 240 274 241 def draw(self): … … 291 258 """ 292 259 _BaseInteractor.__init__(self, base, axes, color=color) 293 # #Initialize the class260 # Initialize the class 294 261 self.markers = [] 295 262 self.axes = axes 296 # #compute the value of the angle between the current line and297 # #the x-axis263 # compute the value of the angle between the current line and 264 # the x-axis 298 265 self.save_theta = theta2 + phi 299 266 self.theta = theta2 + phi 300 # #the value of the middle line angle with respect to the x-axis267 # the value of the middle line angle with respect to the x-axis 301 268 self.theta2 = theta2 302 # #Radius to find polar coordinates this line's endpoints269 # Radius to find polar coordinates this line's endpoints 303 270 self.radius = r 304 # #phi is the phase between the current line and the middle line271 # phi is the phase between the current line and the middle line 305 272 self.phi = phi 306 # #End points polar coordinates273 # End points polar coordinates 307 274 x1 = self.radius * math.cos(self.theta) 308 275 y1 = self.radius * math.sin(self.theta) 309 276 x2 = -1 * self.radius * math.cos(self.theta) 310 277 y2 = -1 * self.radius * math.sin(self.theta) 311 # # defining a new marker278 # Defining a new marker 312 279 self.inner_marker = self.axes.plot([x1 / 2.5], [y1 / 2.5], linestyle='', 313 280 marker='s', markersize=10, … … 316 283 zorder=zorder, visible=True)[0] 317 284 318 # #Defining the current line285 # Defining the current line 319 286 self.line = self.axes.plot([x1, x2], [y1, y2], 320 287 linestyle='-', marker='', 321 288 color=self.color, visible=True)[0] 322 # #Flag to differentiate the left line from the right line motion289 # Flag to differentiate the left line from the right line motion 323 290 self.left_moving = False 324 # #Flag to define a motion291 # Flag to define a motion 325 292 self.has_move = False 326 # #connecting markers and draw the picture293 # connecting markers and draw the picture 327 294 self.connect_markers([self.inner_marker, self.line]) 328 295 … … 330 297 """ 331 298 Allow adding plot to the same panel 332 333 299 :param n: the number of layer 334 335 300 """ 336 301 self.layernum = n … … 359 324 360 325 """ 361 #print "update left or right ", self.has_move362 326 self.left_moving = left 363 327 theta3 = 0 … … 396 360 """ 397 361 self.save_theta = self.theta 398 self.base.freeze_axes()399 362 400 363 def moveend(self, ev): … … 416 379 self.theta = math.atan2(y, x) 417 380 self.has_move = True 418 #ToDo: Simplify below419 381 if not self.left_moving: 420 382 if self.theta2 - self.theta <= 0 and self.theta2 > 0: … … 464 426 self.update() 465 427 466 def get _params(self):428 def getParams(self): 467 429 """ 468 430 """ … … 472 434 return params 473 435 474 def set _params(self, params):436 def setParams(self, params): 475 437 """ 476 438 """ … … 554 516 """ 555 517 self.save_theta = self.theta 556 self.base.freeze_axes()557 518 558 519 def moveend(self, ev): … … 582 543 self.update() 583 544 584 def get _params(self):545 def getParams(self): 585 546 """ 586 547 """ … … 590 551 return params 591 552 592 def set _params(self, params):553 def setParams(self, params): 593 554 """ 594 555 """
Note: See TracChangeset
for help on using the changeset viewer.