Changeset eba08f1a in sasview for guiframe/local_perspectives/plotting/AnnulusSlicer.py
- Timestamp:
- Mar 3, 2009 4:12:26 PM (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:
- fe2ade9
- Parents:
- 18a3ee9
- File:
-
- 1 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)
Note: See TracChangeset
for help on using the changeset viewer.