Changeset eba08f1a in sasview for guiframe/local_perspectives
- Timestamp:
- Mar 3, 2009 4:12:26 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:
- fe2ade9
- Parents:
- 18a3ee9
- Location:
- guiframe/local_perspectives/plotting
- Files:
-
- 6 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/AnnulusSlicer.py
r6d920cd reba08f1a 16 16 class AnnulusInteractor(_BaseInteractor): 17 17 """ 18 Select an annulus through a 2D plot 18 Select an annulus through a 2D plot. 19 This interactor is used to average 2D data with the region 20 defined by 2 radius. 21 this class is defined by 2 Ringinterators. 19 22 """ 20 23 def __init__(self,base,axes,color='black', zorder=3): … … 26 29 self.qmax = min(math.fabs(self.base.data2D.xmax),math.fabs(self.base.data2D.xmin)) #must be positive 27 30 self.connect = self.base.connect 28 29 31 30 32 ## Number of points on the plot 31 33 self.nbins = 20 … … 35 37 self.xmind=self.base.data2D.xmin 36 38 37 #self.sign=138 39 39 if (self.xmaxd+self.xmind)>0: 40 40 self.sign=1 … … 57 57 58 58 def _onEVT_SLICER_PARS(self, event): 59 """ 60 receive an event containing parameters values to reset the slicer 61 @param event: event of type SlicerParameterEvent with params as 62 attribute 63 """ 59 64 wx.PostEvent(self.base, StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 60 65 event.Skip() … … 63 68 self.base.update() 64 69 65 def update_and_post(self):66 self.update()67 self._post_data()68 69 def save_data(self, path, image, x, y):70 output = open(path, 'w')71 72 data_x, data_y = self.get_data(image, x, y)73 74 output.write("<phi> <average>\n")75 for i in range(len(data_x)):76 output.write("%g %g\n" % (data_x[i], data_y[i]))77 output.close()78 79 70 def set_layer(self, n): 71 """ 72 Allow adding plot to the same panel 73 @param n: the number of layer 74 """ 80 75 self.layernum = n 81 76 self.update() 82 77 83 78 def clear(self): 79 """ 80 Clear the slicer and all connected events related to this slicer 81 """ 84 82 self.clear_markers() 85 83 self.outer_circle.clear() 86 84 self.inner_circle.clear() 87 85 self.base.connect.clearall() 88 89 86 self.base.Unbind(EVT_SLICER_PARS) 90 87 88 91 89 def update(self): 92 90 """ 93 Respond to changes in the model by recalculating the profiles and94 resetting the widgets.91 Respond to changes in the model by recalculating the profiles and 92 resetting the widgets. 95 93 """ 96 94 # Update locations … … 98 96 self.outer_circle.update() 99 97 100 101 98 102 99 def save(self, ev): 103 100 """ 104 Remember the roughness for this layer and the next so that we105 can restore on Esc.101 Remember the roughness for this layer and the next so that we 102 can restore on Esc. 106 103 """ 107 104 self.base.freeze_axes() … … 110 107 111 108 def _post_data(self,nbins=None): 112 # Compute data 109 """ 110 Uses annulus parameters to plot averaged data into 1D data. 111 @param nbins: the number of points to plot 112 """ 113 #Data to average 113 114 data = self.base.data2D 114 115 # If we have no data, just return … … 117 118 118 119 from DataLoader.manipulations import SectorPhi 119 #radius = self.qmax#math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2))120 120 121 rmin= min(math.fabs(self.inner_circle.get_radius()), 121 122 math.fabs(self.outer_circle.get_radius())) 122 123 rmax = max(math.fabs(self.inner_circle.get_radius()), 123 124 math.fabs(self.outer_circle.get_radius())) 124 #print "rmin, rmax", rmin, rmax 125 #if the user does not specify the numbers of points to plot 126 # the default number will be nbins= 20 125 127 if nbins==None: 126 nbins = 20 128 self.nbins= 20 129 else: 130 self.nbins = nbins 131 ## create the data1D Q average of data2D 127 132 sect = SectorPhi(r_min=rmin , r_max= rmax, 128 phi_min=0, phi_max=2*math.pi , nbins=nbins) 129 130 133 phi_min=0, phi_max=2*math.pi , nbins=self.nbins) 131 134 sector = sect(self.base.data2D) 132 135 … … 144 147 new_plot.name = "SectorPhi" +"("+ self.base.data2D.name+")" 145 148 146 147 148 149 new_plot.source=self.base.data2D.source 149 150 #new_plot.info=self.base.data2D.info 151 150 152 new_plot.interactive = True 151 #print "loader output.detector",output.source152 153 new_plot.detector =self.base.data2D.detector 153 154 # If the data file does not tell us what the axes are, just assume... … … 162 163 163 164 164 165 166 165 def moveend(self, ev): 166 """ 167 Called when any dragging motion ends. 168 Post an event (type =SlicerParameterEvent) 169 to plotter 2D with a copy slicer parameters 170 Call _post_data method 171 """ 167 172 self.base.thaw_axes() 168 169 # Post paramters 173 # Post parameters to plotter 2D 170 174 event = SlicerParameterEvent() 171 175 event.type = self.__class__.__name__ 172 176 event.params = self.get_params() 173 #wx.PostEvent(self.base.parent, event)174 177 wx.PostEvent(self.base, event) 178 # create a 1D data plot 175 179 self._post_data() 176 180 … … 192 196 193 197 def get_params(self): 198 """ 199 Store a copy of values of parameters of the slicer into a dictionary. 200 @return params: the dictionary created 201 """ 194 202 params = {} 195 203 params["inner_radius"] = math.fabs(self.inner_circle._inner_mouse_x) … … 199 207 200 208 def set_params(self, params): 201 209 """ 210 Receive a dictionary and reset the slicer with values contained 211 in the values of the dictionary. 212 @param params: a dictionary containing name of slicer parameters and 213 values the user assigned to the slicer. 214 """ 202 215 inner = math.fabs(params["inner_radius"] ) 203 216 outer = math.fabs(params["outer_radius"] ) 204 217 self.nbins = int(params["nbins"]) 218 ## Update the picture 205 219 self.inner_circle.set_cursor(inner, self.inner_circle._inner_mouse_y) 206 220 self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y) 221 ## Post the data given the nbins entered by the user 207 222 self._post_data(self.nbins) 208 223 … … 219 234 class RingInteractor(_BaseInteractor): 220 235 """ 221 Select an annulus through a 2D plot 236 Draw a ring Given a radius 237 @param: the color of the line that defined the ring 238 @param r: the radius of the ring 239 @param sign: the direction of motion the the marker 222 240 """ 223 241 def __init__(self,base,axes,color='black', zorder=5, r=1.0,sign=1): … … 226 244 self.markers = [] 227 245 self.axes = axes 246 # Current radius of the ring 228 247 self._inner_mouse_x = r 248 #Value of the center of the ring 229 249 self._inner_mouse_y = 0 250 # previous value of that radius 230 251 self._inner_save_x = r 252 #Save value of the center of the ring 231 253 self._inner_save_y = 0 232 self.scale = 10.0254 #Class instantiating RingIterator class 233 255 self.base= base 256 #the direction of the motion of the marker 234 257 self.sign=sign 235 236 237 #print "sign",self.sign,self.sign*math.fabs(self._inner_mouse_x) 238 258 ## Create a marker 239 259 try: 240 260 # Inner circle marker … … 254 274 message += "Get the SVN version that is at least as recent as June 1, 2007" 255 275 256 #raise "Version error", message 257 258 # Inner circle 259 260 276 owner=self.base.base.parent 277 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 278 279 # Draw a circle 261 280 [self.inner_circle] = self.axes.plot([],[], 262 281 linestyle='-', marker='', 263 282 color=self.color) 283 # the number of points that make the ring line 264 284 self.npts = 40 265 285 … … 268 288 269 289 def set_layer(self, n): 290 """ 291 Allow adding plot to the same panel 292 @param n: the number of layer 293 """ 270 294 self.layernum = n 271 295 self.update() 272 296 273 297 def clear(self): 298 """ 299 Clear the slicer and all connected events related to this slicer 300 """ 274 301 self.clear_markers() 275 302 try: … … 284 311 285 312 def get_radius(self): 313 """ 314 @return self._inner_mouse_x: the current radius of the ring 315 """ 286 316 return self._inner_mouse_x 287 317 288 318 def update(self): 289 319 """ 290 Draw the new roughness on the graph.320 Draw the new roughness on the graph. 291 321 """ 292 322 # Plot inner circle … … 315 345 316 346 def moveend(self, ev): 347 """ 348 Called after a dragging motion 349 """ 317 350 self.base.moveend(ev) 318 351 … … 333 366 334 367 def set_cursor(self, x, y): 368 """ 369 draw the ring given x, y value 370 """ 335 371 self.move(x, y, None) 336 372 self.update() … … 338 374 339 375 def get_params(self): 376 """ 377 Store a copy of values of parameters of the slicer into a dictionary. 378 @return params: the dictionary created 379 """ 340 380 params = {} 341 381 params["radius"] = math.fabs(self._inner_mouse_x) … … 343 383 344 384 def set_params(self, params): 345 385 """ 386 Receive a dictionary and reset the slicer with values contained 387 in the values of the dictionary. 388 @param params: a dictionary containing name of slicer parameters and 389 values the user assigned to the slicer. 390 """ 346 391 x = params["radius"] 347 392 self.set_cursor(x, self._inner_mouse_y) -
guiframe/local_perspectives/plotting/Plotter2D.py
r6d920cd reba08f1a 237 237 slicerpop.Append(id, '&Box averaging in Qy') 238 238 wx.EVT_MENU(self, id, self.onBoxavgY) 239 if self.slicer !=None :239 if self.slicer !=None : 240 240 id = wx.NewId() 241 241 slicerpop.Append(id, '&Clear slicer') 242 242 wx.EVT_MENU(self, id, self.onClearSlicer) 243 244 id = wx.NewId()245 slicerpop.Append(id, '&Edit Slicer Parameters')246 wx.EVT_MENU(self, id, self._onEditSlicer)243 if self.slicer.__class__.__name__ !="BoxSum": 244 id = wx.NewId() 245 slicerpop.Append(id, '&Edit Slicer Parameters') 246 wx.EVT_MENU(self, id, self._onEditSlicer) 247 247 slicerpop.AppendSeparator() 248 248 249 250 249 id = wx.NewId() 251 250 slicerpop.Append(id, '&Toggle Linear/Log scale') 252 251 wx.EVT_MENU(self, id, self._onToggleScale) 253 252 254 255 253 pos = event.GetPosition() 256 254 pos = self.ScreenToClient(pos) -
guiframe/local_perspectives/plotting/boxSlicer.py
r18eba35 reba08f1a 20 20 class BoxInteractor(_BaseInteractor): 21 21 """ 22 Select an annulus through a 2D plot 22 BoxInteractor define a rectangle that return data1D average of Data2D 23 in a rectangle area defined by -x, x ,y, -y 23 24 """ 24 25 def __init__(self,base,axes,color='black', zorder=3): … … 38 39 ## Number of points on the plot 39 40 self.nbins = 30 40 self.count=0 41 self.error=0 41 42 42 self.averager=None 43 43 … … 53 53 y= self.y) 54 54 self.horizontal_lines.qmax= self.qmax 55 56 57 55 58 56 self.update() … … 459 457 460 458 class BoxInteractorX(BoxInteractor): 459 """ 460 Average in Qx direction 461 """ 461 462 def __init__(self,base,axes,color='black', zorder=3): 462 463 BoxInteractor.__init__(self, base, axes, color=color) … … 469 470 470 471 class BoxInteractorY(BoxInteractor): 472 """ 473 Average in Qy direction 474 """ 471 475 def __init__(self,base,axes,color='black', zorder=3): 472 476 BoxInteractor.__init__(self, base, axes, color=color) -
guiframe/local_perspectives/plotting/boxSum.py
r6d920cd reba08f1a 1 #TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it 2 # before pushing a new 1D data update. 3 4 # 5 #TODO: NEED MAJOR REFACTOR 6 # 7 8 9 # Debug printout 10 #from config import printEVT 1 2 3 4 import math 5 import wx 6 from copy import deepcopy 11 7 from BaseInteractor import _BaseInteractor 12 from copy import deepcopy13 import math14 15 #from Plotter1D import AddPlotEvent16 import SlicerParameters17 import wx18 19 8 from sans.guicomm.events import SlicerParamUpdateEvent,EVT_SLICER_PARS,StatusEvent 9 10 20 11 class BoxSum(_BaseInteractor): 21 12 """ 22 Select an annulus through a 2D plot 13 Boxsum Class: determine 2 rectangular area to compute the sum of pixel of 14 a Data. 15 Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 16 @param zorder: Artists with lower zorder values are drawn first. 17 @param x_min: the minimum value of the x coordinate 18 @param x_max: the maximum value of the x coordinate 19 @param y_min: the minimum value of the y coordinate 20 @param y_max: the maximum value of the y coordinate 21 23 22 """ 24 def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 23 def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, 24 x_max=0.008, y_min=0.0025, y_max=0.0025): 25 25 26 26 _BaseInteractor.__init__(self, base, axes, color=color) 27 ## class initialization 28 ## list of Boxsmun markers 27 29 self.markers = [] 28 30 self.axes = axes 31 ## connect the artist for the motion 32 self.connect = self.base.connect 33 ## when qmax is reached the selected line is reset the its previous value 29 34 self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 30 self.connect = self.base.connect35 ## Define the boxsum limits 31 36 self.xmin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 32 37 self.ymin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 33 #self.xmax= x_max 34 #self.ymax= y_max 38 35 39 self.xmax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 36 40 self.ymax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 37 # center of the figure41 ## center of the boxSum 38 42 self.center_x= 0.0002 39 43 self.center_y= 0.0003 40 41 44 ## Number of points on the plot 42 45 self.nbins = 20 46 ## Define initial result the summation 43 47 self.count=0 44 48 self.error=0 49 ## Flag to determine if the current figure has moved 50 ## set to False == no motion , set to True== motion 45 51 self.has_move= False 46 47 self.horizontal_lines= Horizontal _DoubleLine(self, self.base.subplot,color='blue',52 ## Create Boxsum edges 53 self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue', 48 54 zorder=zorder, 49 55 y= self.ymax, … … 53 59 self.horizontal_lines.qmax = self.qmax 54 60 55 self.vertical_lines= Vertical _DoubleLine(self, self.base.subplot,color='black',61 self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='black', 56 62 zorder=zorder, 57 63 y= self.ymax, … … 60 66 center_y= self.center_y) 61 67 self.vertical_lines.qmax = self.qmax 68 62 69 self.center= PointInteractor(self, self.base.subplot,color='grey', 63 70 zorder=zorder, 64 71 center_x= self.center_x, 65 72 center_y= self.center_y) 66 67 68 #self.connect_markers([]) 69 self.panel_name="" 73 ## Save the name of the slicer panel associate with this slicer 74 self.panel_name="" 75 ## Update and post slicer parameters 70 76 self.update() 71 77 self._post_data() 72 73 # Bind to slice parameter events 74 #print "box sum self.base.parent",self.base.parent 78 ## Bind to slice parameter events 75 79 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 76 80 81 77 82 def set_panel_name(self, name): 83 """ 84 Store the name of the panel associated to this slicer 85 @param name: the name of this panel 86 """ 78 87 self.panel_name= name 79 88 80 89 81 90 def _onEVT_SLICER_PARS(self, event): 91 """ 92 receive an event containing parameters values to reset the slicer 93 @param event: event of type SlicerParameterEvent with params as 94 attribute 95 """ 96 ## Post e message to declare what kind of event has being received 82 97 wx.PostEvent(self.base.parent, StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 83 #print "receiving value ",event.params84 98 event.Skip() 99 ## reset the slicer with the values contains the event.params dictionary 85 100 if event.type == self.__class__.__name__: 86 101 self.set_params(event.params) 87 102 self.base.update() 88 103 89 def update_and_post(self):90 self.update()91 self._post_data()92 93 def save_data(self, path, image, x, y):94 output = open(path, 'w')95 96 data_x, data_y = self.get_data(image, x, y)97 98 output.write("<phi> <average>\n")99 for i in range(len(data_x)):100 output.write("%g %g\n" % (data_x[i], data_y[i]))101 output.close()102 104 103 105 def set_layer(self, n): 106 """ 107 Allow adding plot to the same panel 108 @param n: the number of layer 109 """ 104 110 self.layernum = n 105 111 self.update() 106 112 113 107 114 def clear(self): 115 """ 116 Clear the slicer and all connected events related to this slicer 117 """ 108 118 self.clear_markers() 109 119 self.horizontal_lines.clear() … … 111 121 self.center.clear() 112 122 self.base.connect.clearall() 113 #self.base.connect.disconnect()114 123 self.base.Unbind(EVT_SLICER_PARS) 115 124 125 116 126 def update(self): 117 127 """ 118 Respond to changes in the model by recalculating the profiles and 119 resetting the widgets. 120 """ 128 Respond to changes in the model by recalculating the profiles and 129 resetting the widgets. 130 """ 131 ## check if the center point has moved and update the figure accordingly 121 132 if self.center.has_move: 122 #print "center has move"123 133 self.center.update() 124 134 self.horizontal_lines.update( center= self.center) 125 135 self.vertical_lines.update( center= self.center) 126 136 ## check if the horizontal lines have moved and update the figure accordingly 127 137 if self.horizontal_lines.has_move: 128 #print "top has moved"129 138 self.horizontal_lines.update() 130 139 self.vertical_lines.update(y1=self.horizontal_lines.y1, 131 140 y2=self.horizontal_lines.y2, 132 141 height= self.horizontal_lines.half_height ) 142 ## check if the vertical lines have moved and update the figure accordingly 133 143 if self.vertical_lines.has_move: 134 #print "right has moved"135 144 self.vertical_lines.update() 136 145 self.horizontal_lines.update(x1=self.vertical_lines.x1, … … 150 159 151 160 def _post_data(self): 152 # Compute data 153 print 154 161 """ 162 Get the limits of the boxsum and compute the sum of the pixel 163 contained in that region and the error on that sum 164 """ 165 ## Data 2D for which the pixel will be summed 155 166 data = self.base.data2D 156 from DataLoader.manipulations import Boxavg 157 #radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 167 ## the region of the summation 158 168 x_min= self.horizontal_lines.x2 159 169 x_max= self.horizontal_lines.x1 160 170 y_min= self.vertical_lines.y2 161 171 y_max= self.vertical_lines.y1 162 #print "xmin, xmax, ymin , ymax", x_min, x_max, y_min, y_max 172 ##computation of the sum and its error 173 from DataLoader.manipulations import Boxavg 163 174 box = Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 164 175 self.count, self.error = box(self.base.data2D) 165 #print "box_sum output",box(self.base.data2D) 176 166 177 167 178 def moveend(self, ev): 179 """ 180 After a dragging motion this function is called to compute 181 the error and the sum of pixel of a given data 2D 182 """ 168 183 self.base.thaw_axes() 169 # Post paramters184 ## compute error an d sum of data's pixel 170 185 self._post_data() 171 186 ## Create and event ( posted to guiframe)that set the 187 ##current slicer parameter to a panel of name self.panel_name 172 188 self.type= self.__class__.__name__ 173 189 params= self.get_params() … … 184 200 self.vertical_lines.restore() 185 201 self.center.restore() 202 203 186 204 def move(self, x, y, ev): 187 205 """ … … 189 207 """ 190 208 pass 209 191 210 192 211 def set_cursor(self, x, y): 193 212 pass 194 213 214 195 215 def get_params(self): 216 """ 217 Store a copy of values of parameters of the slicer into a dictionary. 218 @return params: the dictionary created 219 """ 196 220 params = {} 197 198 221 params["Width"] = math.fabs(self.vertical_lines.half_width)*2 199 222 params["Height"] = math.fabs(self.horizontal_lines.half_height)*2 200 201 223 params["center_x"] = self.center.x 202 224 params["center_y"] =self.center.y 203 225 params["count"] = self.count 204 226 params["errors"]= self.error 205 206 227 return params 207 228 … … 218 239 219 240 def set_params(self, params): 220 241 """ 242 Receive a dictionary and reset the slicer with values contained 243 in the values of the dictionary. 244 @param params: a dictionary containing name of slicer parameters and 245 values the user assigned to the slicer. 246 """ 221 247 x_max = math.fabs(params["Width"] )/2 222 248 y_max = math.fabs(params["Height"] )/2 … … 224 250 self.center_x=params["center_x"] 225 251 self.center_y=params["center_y"] 226 252 #update the slicer given values of params 227 253 self.center.update(center_x=self.center_x,center_y=self.center_y) 228 229 254 self.horizontal_lines.update(center= self.center, 230 255 width=x_max, … … 233 258 width=x_max, 234 259 height=y_max) 235 260 #compute the new error and sum given values of params 236 261 self._post_data() 237 262 … … 241 266 self.base.freeze_axes() 242 267 268 243 269 def thaw_axes(self): 244 270 self.base.thaw_axes() 245 271 272 246 273 def draw(self): 247 274 self.base.draw() 275 276 277 248 278 class PointInteractor(_BaseInteractor): 249 279 """ 250 Select an annulus through a 2D plot 280 Draw a point that can be dragged with the marker. 281 this class controls the motion the center of the BoxSum 251 282 """ 252 283 def __init__(self,base,axes,color='black', zorder=5, … … 255 286 256 287 _BaseInteractor.__init__(self, base, axes, color=color) 288 ## Initialization the class 257 289 self.markers = [] 258 290 self.axes = axes 259 # center 291 # center coordinates 260 292 self.x = center_x 261 293 self.y = center_y 262 294 ## saved value of the center coordinates 263 295 self.save_x = center_x 264 296 self.save_y = center_y 265 266 297 ## Create a marker 267 298 try: 268 299 self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', … … 280 311 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 281 312 message += "Get the SVN version that is at least as recent as June 1, 2007" 282 283 #raise "Version error", message284 285 # line313 owner=self.base.base.parent 314 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 315 316 ## Draw a point 286 317 self.center = self.axes.plot([self.x],[self.y], 287 318 linestyle='-', marker='', 288 319 color=self.color, 289 320 visible=True)[0] 290 291 self. npts = 30292 self.has_move=False321 ## Flag to determine the motion this point 322 self.has_move=False 323 ## connecting the marker to allow them to move 293 324 self.connect_markers([self.center_marker]) 294 self.update() 325 ## Update the figure 326 self.update() 327 295 328 296 329 def set_layer(self, n): 330 """ 331 Allow adding plot to the same panel 332 @param n: the number of layer 333 """ 297 334 self.layernum = n 298 335 self.update() 299 336 337 300 338 def clear(self): 339 """ 340 Clear this figure and its markers 341 """ 301 342 self.clear_markers() 302 343 try: … … 307 348 for item in range(len(self.axes.lines)): 308 349 del self.axes.lines[0] 309 310 def get_radius(self): 311 312 return 0 350 313 351 314 352 def update(self, center_x=None,center_y=None): 315 353 """ 316 Draw the new roughness on the graph.354 Draw the new roughness on the graph. 317 355 """ 318 356 if center_x !=None: self.x= center_x … … 323 361 324 362 325 326 327 363 def save(self, ev): 328 364 """ … … 332 368 self.save_x= self.x 333 369 self.save_y= self.y 334 335 370 self.base.freeze_axes() 371 336 372 337 373 def moveend(self, ev): … … 346 382 self.y= self.save_y 347 383 self.x= self.save_x 384 348 385 349 386 def move(self, x, y, ev): … … 357 394 self.base.base.update() 358 395 396 359 397 def set_cursor(self, x, y): 360 398 self.move(x, y, None) … … 366 404 params["x"] = self.x 367 405 params["y"] = self.y 368 369 406 return params 407 370 408 371 409 def set_params(self, params): … … 375 413 376 414 377 class Vertical _DoubleLine(_BaseInteractor):415 class VerticalDoubleLine(_BaseInteractor): 378 416 """ 379 Select an annulus through a 2D plot 417 Draw 2 vertical lines moving in opposite direction and centered on 418 a point (PointInteractor) 380 419 """ 381 420 def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, … … 384 423 385 424 _BaseInteractor.__init__(self, base, axes, color=color) 425 ## Initialization the class 386 426 self.markers = [] 387 427 self.axes = axes 388 # center428 ## Center coordinates 389 429 self.center_x = center_x 390 430 self.center_y = center_y 391 392 393 431 ## defined end points vertical lignes and their saved values 394 432 self.y1 = y + self.center_y 395 433 self.save_y1= self.y1 … … 405 443 self.x2= self.center_x - delta 406 444 self.save_x2 = self.x2 407 408 self.color =color409 445 ## save the color of the line 446 self.color = color 447 ## the height of the rectangle 410 448 self.half_height= math.fabs(y) 411 449 self.save_half_height= math.fabs(y) 412 450 ## the with of the rectangle 413 451 self.half_width= math.fabs(self.x1- self.x2)/2 414 452 self.save_half_width=math.fabs(self.x1- self.x2)/2 415 453 ## Create marker 416 454 try: 417 455 self.right_marker = self.axes.plot([self.x1],[0], linestyle='', … … 429 467 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 430 468 message += "Get the SVN version that is at least as recent as June 1, 2007" 431 432 #raise "Version error", message433 434 # line469 owner=self.base.base.parent 470 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 471 472 ## define the left and right lines of the rectangle 435 473 self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2], 436 474 linestyle='-', marker='', … … 441 479 color=self.color, 442 480 visible=True)[0] 443 444 self. npts = 30445 self.has_move=False481 ## Flag to determine if the lines have moved 482 self.has_move=False 483 ## connection the marker and draw the pictures 446 484 self.connect_markers([self.right_marker]) 447 485 self.update() … … 449 487 450 488 def set_layer(self, n): 489 """ 490 Allow adding plot to the same panel 491 @param n: the number of layer 492 """ 451 493 self.layernum = n 452 494 self.update() 453 495 496 454 497 def clear(self): 498 """ 499 Clear this figure and its markers 500 """ 455 501 self.clear_markers() 456 502 try: … … 462 508 for item in range(len(self.axes.lines)): 463 509 del self.axes.lines[0] 464 465 def get_radius(self): 466 467 return 0 510 468 511 469 512 def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None): 470 513 """ 471 Draw the new roughness on the graph. 472 """ 473 #print "self.half_height",self.half_height,self.half_width 514 Draw the new roughness on the graph. 515 @param x1: new maximum value of x coordinates 516 @param x2: new minimum value of x coordinates 517 @param y1: new maximum value of y coordinates 518 @param y2: new minimum value of y coordinates 519 @param width: is the width of the new rectangle 520 @param height: is the height of the new rectangle 521 @param center: provided x, y coordinates of the center point 522 """ 523 ## save the new height, witdh of the rectangle if given as a param 474 524 if width!=None: 475 525 self.half_width= width 476 526 if height!=None: 477 527 self.half_height= height 528 ## If new center coordinates are given draw the rectangle 529 ##given these value 478 530 if center!=None: 479 531 self.center_x= center.x 480 532 self.center_y= center.y 481 #print "vertical width",self.half_width ,self.center_x533 482 534 self.x1 = self.half_width + self.center_x 483 535 self.x2= -self.half_width + self.center_x … … 490 542 self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 491 543 return 544 ## if x1, y1, y2, y3 are given draw the rectangle with this value 492 545 if x1 !=None: 493 546 self.x1= x1 … … 498 551 if y2 !=None: 499 552 self.y2= y2 500 501 502 553 ## Draw 2 vertical lines and a marker 503 554 self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 504 555 self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) … … 518 569 519 570 self.save_half_height= self.half_height 520 #self.save_half_width = math.fabs(self.x1-self.x2)/2521 571 self.save_half_width = self.half_width 572 522 573 self.base.freeze_axes() 523 574 575 524 576 def moveend(self, ev): 525 577 """ 578 After a dragging motion reset the flag self.has_move to False 579 """ 526 580 self.has_move=False 527 581 self.base.moveend(ev) 528 582 583 529 584 def restore(self): 530 585 """ … … 538 593 539 594 self.half_height= self.save_half_height 540 #self.half_width= math.fabs(self.x1-self.x2)/2541 595 self.half_width= self.save_half_width 596 542 597 543 598 def move(self, x, y, ev): … … 550 605 551 606 self.half_width= math.fabs(self.x1-self.x2)/2 552 #print "Move vert: vertical width",self.half_width ,self.center_x607 553 608 self.has_move=True 554 609 self.base.base.update() 555 610 611 556 612 def set_cursor(self, x, y): 613 """ 614 Update the figure given x and y 615 """ 557 616 self.move(x, y, None) 558 617 self.update() … … 560 619 561 620 def get_params(self): 621 """ 622 Store a copy of values of parameters of the slicer into a dictionary. 623 @return params: the dictionary created 624 """ 562 625 params = {} 563 626 params["x"] = self.x1 … … 567 630 568 631 def set_params(self, params): 632 """ 633 Receive a dictionary and reset the slicer with values contained 634 in the values of the dictionary. 635 @param params: a dictionary containing name of slicer parameters and 636 values the user assigned to the slicer. 637 """ 569 638 x = params["x"] 570 639 y = params["y"] 571 640 self.update(x=x, y=y, center_x=None,center_y=None) 572 641 573 class Horizontal_DoubleLine(_BaseInteractor): 642 643 class HorizontalDoubleLine(_BaseInteractor): 574 644 """ 575 645 Select an annulus through a 2D plot … … 580 650 581 651 _BaseInteractor.__init__(self, base, axes, color=color) 652 ## Initialization the class 582 653 self.markers = [] 583 654 self.axes = axes 584 # center655 ## Center coordinates 585 656 self.center_x = center_x 586 657 self.center_y = center_y … … 623 694 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 624 695 message += "Get the SVN version that is at least as recent as June 1, 2007" 625 626 #raise "Version error", message627 628 # line696 owner=self.base.base.parent 697 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 698 699 # Define 2 horizotnal lines 629 700 self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1], 630 701 linestyle='-', marker='', … … 635 706 color=self.color, 636 707 visible=True)[0] 637 638 self.npts = 30 708 ## Flag to determine if the lines have moved 639 709 self.has_move=False 710 ## connection the marker and draw the pictures 640 711 self.connect_markers([self.top_marker]) 641 712 self.update() … … 643 714 644 715 def set_layer(self, n): 716 """ 717 Allow adding plot to the same panel 718 @param n: the number of layer 719 """ 645 720 self.layernum = n 646 721 self.update() 647 722 723 648 724 def clear(self): 725 """ 726 Clear this figure and its markers 727 """ 649 728 self.clear_markers() 650 729 try: … … 656 735 for item in range(len(self.axes.lines)): 657 736 del self.axes.lines[0] 658 659 def get_radius(self): 660 661 return 0 737 662 738 663 739 def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None): 664 740 """ 665 Draw the new roughness on the graph. 666 """ 667 #print "self.half_width",self.half_width 668 if width!=None: 669 self.half_width= width 670 if height!=None: 741 Draw the new roughness on the graph. 742 @param x1: new maximum value of x coordinates 743 @param x2: new minimum value of x coordinates 744 @param y1: new maximum value of y coordinates 745 @param y2: new minimum value of y coordinates 746 @param width: is the width of the new rectangle 747 @param height: is the height of the new rectangle 748 @param center: provided x, y coordinates of the center point 749 """ 750 ## save the new height, witdh of the rectangle if given as a param 751 if width != None: 752 self.half_width = width 753 if height!= None: 671 754 self.half_height= height 755 ## If new center coordinates are given draw the rectangle 756 ##given these value 672 757 if center!=None: 673 758 self.center_x= center.x … … 684 769 self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 685 770 return 771 ## if x1, y1, y2, y3 are given draw the rectangle with this value 686 772 if x1 !=None: 687 773 self.x1= x1 … … 692 778 if y2 !=None: 693 779 self.y2= y2 694 695 780 ## Draw 2 vertical lines and a marker 696 781 self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 697 782 self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) … … 699 784 700 785 701 702 786 def save(self, ev): 703 787 """ … … 717 801 718 802 def moveend(self, ev): 719 803 """ 804 After a dragging motion reset the flag self.has_move to False 805 """ 720 806 self.has_move=False 721 807 self.base.moveend(ev) 808 722 809 723 810 def restore(self): … … 732 819 self.half_height= self.save_half_height 733 820 self.half_width= self.save_half_width 821 734 822 735 823 def move(self, x, y, ev): … … 744 832 self.base.base.update() 745 833 834 746 835 def set_cursor(self, x, y): 836 """ 837 Update the figure given x and y 838 """ 747 839 self.move(x, y, None) 748 840 self.update() … … 750 842 751 843 def get_params(self): 844 """ 845 Store a copy of values of parameters of the slicer into a dictionary. 846 @return params: the dictionary created 847 """ 752 848 params = {} 753 849 params["x"] = self.x 754 850 params["y"] = self.y 755 756 851 return params 757 852 853 758 854 def set_params(self, params): 855 """ 856 Receive a dictionary and reset the slicer with values contained 857 in the values of the dictionary. 858 @param params: a dictionary containing name of slicer parameters and 859 values the user assigned to the slicer. 860 """ 759 861 x = params["x"] 760 862 y = params["y"] 761 863 self.update(x=x, y=y, center_x=None,center_y=None) 762 864 865 866 -
guiframe/local_perspectives/plotting/detector_dialog.py
r9a585d0 reba08f1a 8 8 from sans.guiframe.utils import format_number 9 9 from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent 10 11 10 12 class DetectorDialog(wx.Dialog): 11 13 """ … … 17 19 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 18 20 wx.Dialog.__init__(self,parent,id=1, *args, **kwds) 21 19 22 self.parent=base 20 23 self.label_xnpts = wx.StaticText(self, -1, "Detector width in pixels") … … 24 27 self.label_zmax = wx.StaticText(self, -1, "Max amplitude for color map (optional)") 25 28 self.label_beam = wx.StaticText(self, -1, "Beam stop radius in units of q") 26 #self.label_sym = wx.StaticText(self, -1, 'Use 4-fold symmetry') 27 28 # Npts, q max 29 #self.npts_ctl = wx.TextCtrl(self, -1, size=(60,20)) 30 #self.qmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 31 #self.beam_ctl = wx.TextCtrl(self, -1, size=(60,20)) 29 32 30 self.xnpts_ctl = wx.StaticText(self, -1, "") 33 31 self.ynpts_ctl = wx.StaticText(self, -1, "") … … 37 35 self.zmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) 38 36 self.zmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 39 #self.chk_sym = wx.CheckBox(self, -1, '') 40 37 41 38 self.static_line_3 = wx.StaticLine(self, -1) 42 39 … … 61 58 62 59 def checkValues(self, event): 60 """ 61 Check the valitidity of zmin and zmax value 62 zmax should be a float and zmin less than zmax 63 """ 63 64 flag = True 64 65 try: … … 97 98 98 99 def setContent(self, xnpts,ynpts, qmax, beam,zmin=None,zmax=None, sym=False): 100 """ 101 received value and displayed them 102 @param xnpts: the number of point of the x_bins of data 103 @param ynpts: the number of point of the y_bins of data 104 @param qmax: the maxmimum value of data pixel 105 @param beam : the radius of the beam 106 @param zmin: the value to get the minimum color 107 @param zmax: the value to get the maximum color 108 @param sym: 109 """ 99 110 self.xnpts_ctl.SetLabel(str(format_number(xnpts))) 100 111 self.ynpts_ctl.SetLabel(str(format_number(ynpts))) 101 112 self.qmax_ctl.SetLabel(str(format_number(qmax))) 102 113 self.beam_ctl.SetLabel(str(format_number(beam))) 103 #self.chk_sym.SetValue(sym)114 104 115 if zmin !=None: 105 116 self.zmin_ctl.SetValue(str(format_number(zmin))) … … 108 119 109 120 def getContent(self): 121 """ 122 @return event containing value to reset the detector of a given data 123 """ 110 124 event = self.Event() 111 #event.npts = int(self.npts_ctl.GetValue()) 112 #event.qmax = float(self.qmax_ctl.GetValue()) 113 #event.beam = float(self.beam_ctl.GetValue()) 114 #event.sym4 = self.chk_sym.GetValue() 115 125 116 126 t_min = self.zmin_ctl.GetValue() 117 127 t_max = self.zmax_ctl.GetValue() … … 137 147 138 148 def __set_properties(self): 149 """ 150 set proprieties of the dialog window 151 """ 139 152 self.SetTitle("Detector parameters") 140 153 self.SetSize((600, 595)) 141 154 155 142 156 def __do_layout(self): 157 """ 158 fill the dialog window . 159 """ 143 160 sizer_main = wx.BoxSizer(wx.VERTICAL) 144 161 sizer_button = wx.BoxSizer(wx.HORIZONTAL) … … 164 181 sizer_params.Add(self.zmax_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 165 182 iy += 1 166 #sizer_params.Add(self.label_sym, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 167 #sizer_params.Add(self.chk_sym, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 168 183 169 184 sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) 170 185 sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0)
Note: See TracChangeset
for help on using the changeset viewer.