Changeset 32c0841 in sasview for guiframe/local_perspectives/plotting
- Timestamp:
- Nov 23, 2010 11:21:20 AM (14 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:
- a54e4be
- Parents:
- 4a2b054
- Location:
- guiframe/local_perspectives/plotting
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/AnnulusSlicer.py
r83f4445 r32c0841 8 8 import math 9 9 import wx 10 from copy import deepcopy10 #from copy import deepcopy 11 11 # Debug printout 12 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 12 from sans.guicomm.events import NewPlotEvent 13 from sans.guicomm.events import StatusEvent 14 from sans.guicomm.events import SlicerParameterEvent 15 from sans.guicomm.events import EVT_SLICER_PARS 13 16 from BaseInteractor import _BaseInteractor 14 17 from sans.guiframe.dataFitting import Data1D … … 21 24 this class is defined by 2 Ringinterators. 22 25 """ 23 def __init__(self, base,axes,color='black', zorder=3):26 def __init__(self, base, axes, color='black', zorder=3): 24 27 25 28 _BaseInteractor.__init__(self, base, axes, color=color) 26 29 self.markers = [] 27 30 self.axes = axes 28 self.base= base 29 self.qmax = min(math.fabs(self.base.data2D.xmax),math.fabs(self.base.data2D.xmin)) #must be positive 31 self.base = base 32 self.qmax = min(math.fabs(self.base.data2D.xmax), 33 math.fabs(self.base.data2D.xmin)) #must be positive 30 34 self.connect = self.base.connect 31 35 32 36 ## Number of points on the plot 33 37 self.nbins = 20 34 35 38 #Cursor position of Rings (Left(-1) or Right(1)) 36 self.xmaxd =self.base.data2D.xmax37 self.xmind =self.base.data2D.xmin38 39 if (self.xmaxd +self.xmind)>0:40 self.sign =139 self.xmaxd = self.base.data2D.xmax 40 self.xmind = self.base.data2D.xmin 41 42 if (self.xmaxd + self.xmind) > 0: 43 self.sign = 1 41 44 else: 42 self.sign=-1 43 45 self.sign = -1 44 46 # Inner circle 45 self.inner_circle = RingInteractor(self, self.base.subplot, zorder=zorder, r=self.qmax/2.0,sign=self.sign) 47 self.inner_circle = RingInteractor(self, self.base.subplot, 48 zorder=zorder, 49 r=self.qmax/2.0, sign=self.sign) 46 50 self.inner_circle.qmax = self.qmax 47 self.outer_circle = RingInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax/1.8,sign=self.sign) 48 self.outer_circle.qmax = self.qmax*1.2 49 51 self.outer_circle = RingInteractor(self, self.base.subplot, 52 zorder=zorder+1, r=self.qmax/1.8, 53 sign=self.sign) 54 self.outer_circle.qmax = self.qmax * 1.2 50 55 self.update() 51 56 self._post_data() … … 62 67 63 68 """ 64 wx.PostEvent(self.base, StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 69 wx.PostEvent(self.base, 70 StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 65 71 event.Skip() 66 72 if event.type == self.__class__.__name__: … … 106 112 self.outer_circle.save(ev) 107 113 108 def _post_data(self, nbins=None):114 def _post_data(self, nbins=None): 109 115 """ 110 116 Uses annulus parameters to plot averaged data into 1D data. … … 120 126 121 127 from DataLoader.manipulations import Ring 122 123 rmin= min(math.fabs(self.inner_circle.get_radius()), 128 rmin = min(math.fabs(self.inner_circle.get_radius()), 124 129 math.fabs(self.outer_circle.get_radius())) 125 130 rmax = max(math.fabs(self.inner_circle.get_radius()), … … 127 132 #if the user does not specify the numbers of points to plot 128 133 # the default number will be nbins= 20 129 if nbins ==None:130 self.nbins = 20134 if nbins == None: 135 self.nbins = 20 131 136 else: 132 137 self.nbins = nbins 133 138 ## create the data1D Q average of data2D 134 sect = Ring(r_min=rmin , r_max=rmax, nbins=self.nbins)139 sect = Ring(r_min=rmin, r_max=rmax, nbins=self.nbins) 135 140 sector = sect(self.base.data2D) 136 137 138 if hasattr(sector,"dxl"): 139 dxl= sector.dxl 141 142 if hasattr(sector, "dxl"): 143 dxl = sector.dxl 140 144 else: 141 dxl = None142 if hasattr(sector, "dxw"):143 dxw = sector.dxw145 dxl = None 146 if hasattr(sector, "dxw"): 147 dxw = sector.dxw 144 148 else: 145 dxw = None146 147 new_plot = Data1D(x=(sector.x-math.pi)*180/math.pi,y=sector.y,dy=sector.dy)149 dxw = None 150 new_plot = Data1D(x=(sector.x - math.pi) * 180/math.pi, 151 y=sector.y, dy=sector.dy) 148 152 new_plot.dxl = dxl 149 153 new_plot.dxw = dxw 150 154 new_plot.name = "AnnulusPhi" +"("+ self.base.data2D.name+")" 151 155 152 new_plot.source =self.base.data2D.source156 new_plot.source = self.base.data2D.source 153 157 #new_plot.info=self.base.data2D.info 154 155 158 new_plot.interactive = True 156 new_plot.detector = self.base.data2D.detector159 new_plot.detector = self.base.data2D.detector 157 160 # If the data file does not tell us what the axes are, just assume... 158 161 new_plot.xaxis("\\rm{\phi}", 'degrees') 159 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")160 new_plot.group_id = "AnnulusPhi" +self.base.data2D.name161 new_plot.id = "AnnulusPhi"+self.base.data2D.name162 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 163 new_plot.group_id = "AnnulusPhi" + self.base.data2D.name 164 new_plot.id = "AnnulusPhi" + self.base.data2D.name 162 165 #new_plot.is_data= True 163 164 new_plot.xtransform="x" 165 new_plot.ytransform="y" 166 new_plot.xtransform = "x" 167 new_plot.ytransform = "y" 166 168 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 167 title="AnnulusPhi" 169 title="AnnulusPhi")) 168 170 169 171 def moveend(self, ev): … … 221 223 222 224 """ 223 inner = math.fabs(params["inner_radius"] 224 outer = math.fabs(params["outer_radius"] 225 inner = math.fabs(params["inner_radius"]) 226 outer = math.fabs(params["outer_radius"]) 225 227 self.nbins = int(params["nbins"]) 226 228 ## Update the picture … … 250 252 Draw a ring Given a radius 251 253 """ 252 def __init__(self, base,axes,color='black', zorder=5, r=1.0,sign=1):254 def __init__(self, base, axes, color='black', zorder=5, r=1.0, sign=1): 253 255 """ 254 256 :param: the color of the line that defined the ring … … 269 271 self._inner_save_y = 0 270 272 #Class instantiating RingIterator class 271 self.base = base273 self.base = base 272 274 #the direction of the motion of the marker 273 self.sign =sign275 self.sign = sign 274 276 ## Create a marker 275 277 try: 276 278 # Inner circle marker 277 self.inner_marker = self.axes.plot([self.sign*math.fabs(self._inner_mouse_x)],[0], linestyle='', 279 x_value = [self.sign * math.fabs(self._inner_mouse_x)] 280 self.inner_marker = self.axes.plot(x_value, 281 [0], 282 linestyle='', 278 283 marker='s', markersize=10, 279 284 color=self.color, alpha=0.6, 280 285 pickradius=5, label="pick", 281 zorder=zorder, # Prefer this to other lines286 zorder=zorder, 282 287 visible=True)[0] 283 288 except: 284 self.inner_marker = self.axes.plot([self.sign*math.fabs(self._inner_mouse_x)],[0], linestyle='', 289 x_value = [self.sign * math.fabs(self._inner_mouse_x)] 290 self.inner_marker = self.axes.plot(x_value, 291 [0], 292 linestyle='', 285 293 marker='s', markersize=10, 286 294 color=self.color, alpha=0.6, 287 295 label="pick", 288 296 visible=True)[0] 289 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 290 message += "Get the SVN version that is at least as recent as June 1, 2007" 291 292 owner=self.base.base.parent 293 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 297 message = "\nTHIS PROTOTYPE NEEDS THE LATEST" 298 message += " VERSION OF MATPLOTLIB\n" 299 message += "Get the SVN version that is at " 300 message += " least as recent as June 1, 2007" 301 302 owner = self.base.base.parent 303 wx.PostEvent(owner, 304 StatusEvent(status="AnnulusSlicer: %s" % message)) 294 305 295 306 # Draw a circle 296 [self.inner_circle] = self.axes.plot([], [],307 [self.inner_circle] = self.axes.plot([], [], 297 308 linestyle='-', marker='', 298 309 color=self.color) … … 340 351 y = [] 341 352 for i in range(self.npts): 342 phi = 2.0 *math.pi/(self.npts-1)*i343 344 xval = 1.0 *self._inner_mouse_x*math.cos(phi)345 yval = 1.0 *self._inner_mouse_x*math.sin(phi)353 phi = 2.0 * math.pi / (self.npts - 1) * i 354 355 xval = 1.0 * self._inner_mouse_x * math.cos(phi) 356 yval = 1.0 * self._inner_mouse_x * math.sin(phi) 346 357 347 358 x.append(xval) 348 359 y.append(yval) 349 360 350 self.inner_marker.set(xdata=[self.sign*math.fabs(self._inner_mouse_x)],ydata=[0]) 361 self.inner_marker.set(xdata=[self.sign*math.fabs(self._inner_mouse_x)], 362 ydata=[0]) 351 363 self.inner_circle.set_data(x, y) 352 364 … … 416 428 Draw a ring Given a radius 417 429 """ 418 def __init__(self, base,axes,color='grey', zorder=3, side=None):430 def __init__(self, base, axes, color='grey', zorder=3, side=None): 419 431 """ 420 432 … … 427 439 self.markers = [] 428 440 self.axes = axes 429 self.base = base441 self.base = base 430 442 self.is_inside = side 431 self.qmax = min(math.fabs(self.base.data.xmax),math.fabs(self.base.data.xmin)) #must be positive 443 self.qmax = min(math.fabs(self.base.data.xmax), 444 math.fabs(self.base.data.xmin)) #must be positive 432 445 self.connect = self.base.connect 433 446 434 447 #Cursor position of Rings (Left(-1) or Right(1)) 435 self.xmaxd =self.base.data.xmax436 self.xmind =self.base.data.xmin437 438 if (self.xmaxd +self.xmind)>0:439 self.sign =1448 self.xmaxd = self.base.data.xmax 449 self.xmind = self.base.data.xmin 450 451 if (self.xmaxd + self.xmind) > 0: 452 self.sign = 1 440 453 else: 441 self.sign=-1 442 454 self.sign = -1 443 455 # Inner circle 444 self.outer_circle = RingInteractor(self, self.base.subplot, 'blue', zorder=zorder+1, r=self.qmax/1.8,sign=self.sign) 445 self.outer_circle.qmax = self.qmax*1.2 446 456 self.outer_circle = RingInteractor(self, self.base.subplot, 'blue', 457 zorder=zorder+1, r=self.qmax/1.8, 458 sign=self.sign) 459 self.outer_circle.qmax = self.qmax * 1.2 447 460 self.update() 448 461 self._post_data() … … 458 471 attribute 459 472 """ 460 wx.PostEvent(self.base, StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 473 wx.PostEvent(self.base, 474 StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 461 475 event.Skip() 462 476 if event.type == self.__class__.__name__: … … 518 532 from DataLoader.manipulations import Ringcut 519 533 520 rmin = 0534 rmin = 0 521 535 rmax = math.fabs(self.outer_circle.get_radius()) 522 536 523 537 ## create the data1D Q average of data2D 524 mask = Ringcut(r_min=rmin 538 mask = Ringcut(r_min=rmin, r_max= rmax) 525 539 526 540 if self.is_inside: 527 out = (mask(data) ==False)541 out = (mask(data) == False) 528 542 else: 529 543 out = (mask(data)) -
guiframe/local_perspectives/plotting/Arc.py
r83f4445 r32c0841 5 5 6 6 from BaseInteractor import _BaseInteractor 7 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 7 from sans.guicomm.events import NewPlotEvent 8 from sans.guicomm.events import StatusEvent 9 from sans.guicomm.events import SlicerParameterEvent 10 from sans.guicomm.events import EVT_SLICER_PARS 8 11 9 12 … … 12 15 Select an annulus through a 2D plot 13 16 """ 14 def __init__(self, base,axes,color='black', zorder=5, r=1.0,theta1=math.pi/8,15 theta 2=math.pi/4):17 def __init__(self, base, axes, color='black', zorder=5, r=1.0, 18 theta1=math.pi/8, theta2=math.pi/4): 16 19 17 20 _BaseInteractor.__init__(self, base, axes, color=color) … … 26 29 self.scale = 10.0 27 30 28 self.theta1 =theta129 self.theta2 =theta230 self.radius = r31 [self.arc] = self.axes.plot([], [],31 self.theta1 = theta1 32 self.theta2 = theta2 33 self.radius = r 34 [self.arc] = self.axes.plot([], [], 32 35 linestyle='-', marker='', 33 36 color=self.color) 34 37 self.npts = 20 35 self.has_move = False38 self.has_move = False 36 39 self.connect_markers([self.arc]) 37 40 self.update() … … 58 61 """ 59 62 """ 60 radius =math.sqrt(math.pow(self._mouse_x, 2)+math.pow(self._mouse_y, 2)) 63 radius = math.sqrt(math.pow(self._mouse_x, 2) + \ 64 math.pow(self._mouse_y, 2)) 61 65 return radius 62 66 63 def update(self, theta1=None,theta2=None, nbins=None, r=None):67 def update(self, theta1=None, theta2=None, nbins=None, r=None): 64 68 """ 65 69 """ … … 67 71 x = [] 68 72 y = [] 69 if theta1 !=None: 70 self.theta1= theta1 71 if theta2 !=None: 72 self.theta2= theta2 73 74 print "ring update theta1 theta2", math.degrees(self.theta1), math.degrees(self.theta2) 75 while self.theta2 < self.theta1: self.theta2 += 2*math.pi 76 while self.theta2 >= self.theta1+2*math.pi: self.theta2 -= 2*math.pi 77 73 if theta1 != None: 74 self.theta1 = theta1 75 if theta2 != None: 76 self.theta2 = theta2 77 #print "ring update theta1 theta2", math.degrees(self.theta1), 78 #math.degrees(self.theta2) 79 while self.theta2 < self.theta1: 80 self.theta2 += (2 * math.pi) 81 while self.theta2 >= (self.theta1 + 2 * math.pi): 82 self.theta2 -= (2 * math.pi) 78 83 npts = int((self.theta2 - self.theta1)/(math.pi/120)) 79 84 80 if r ==None: 81 self.radius= math.sqrt(math.pow(self._mouse_x, 2)+math.pow(self._mouse_y, 2)) 85 if r == None: 86 self.radius = math.sqrt(math.pow(self._mouse_x, 2) + \ 87 math.pow(self._mouse_y, 2)) 82 88 else: 83 self.radius= r 84 89 self.radius = r 85 90 for i in range(self.npts): 86 87 phi =(self.theta2-self.theta1)/(self.npts-1)*i +self.theta1 88 89 xval = 1.0*self.radius*math.cos(phi) 90 yval = 1.0*self.radius*math.sin(phi) 91 phi = (self.theta2 - self.theta1)/(self.npts - 1) * i + self.theta1 92 xval = 1.0 * self.radius * math.cos(phi) 93 yval = 1.0 * self.radius * math.sin(phi) 91 94 92 95 x.append(xval) 93 96 y.append(yval) 94 95 97 #self.marker.set(xdata=[self._mouse_x],ydata=[0]) 96 98 self.arc.set_data(x, y) 97 99 98 99 100 def save(self, ev): 100 101 """ … … 106 107 #self._save_x = ev.xdata 107 108 #self._save_y = ev.ydata 108 109 109 self.base.freeze_axes() 110 110 … … 112 112 """ 113 113 """ 114 self.has_move = False114 self.has_move = False 115 115 116 116 event = SlicerParameterEvent() 117 117 event.type = self.__class__.__name__ 118 118 event.params = self.get_params() 119 print "in arc moveend params",self.get_params()119 #print "in arc moveend params",self.get_params() 120 120 #wx.PostEvent(self.base.base.parent, event) 121 122 121 self.base.moveend(ev) 123 122 … … 136 135 self._mouse_x = x 137 136 self._mouse_y = y 138 self.has_move = True137 self.has_move = True 139 138 self.base.base.update() 140 139 141 def set_cursor(self, radius, phi_min, phi_max,nbins):140 def set_cursor(self, radius, phi_min, phi_max, nbins): 142 141 """ 143 142 """ 144 self.theta1 = phi_min145 self.theta2 = phi_max143 self.theta1 = phi_min 144 self.theta2 = phi_max 146 145 self.update(nbins=nbins, r=radius) 147 148 146 149 147 def get_params(self): 150 148 """ -
guiframe/local_perspectives/plotting/AzimutSlicer.py
r83f4445 r32c0841 11 11 import wx 12 12 from copy import deepcopy 13 14 13 from BaseInteractor import _BaseInteractor 15 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 16 14 from sans.guicomm.events import NewPlotEvent 15 from sans.guicomm.events import StatusEvent 16 from sans.guicomm.events import SlicerParameterEvent 17 from sans.guicomm.events import EVT_SLICER_PARS 17 18 18 19 … … 21 22 Select an annulus through a 2D plot 22 23 """ 23 def __init__(self, base,axes,color='black', zorder=3):24 def __init__(self, base, axes, color='black', zorder=3): 24 25 """ 25 26 """ … … 32 33 ## Number of points on the plot 33 34 self.nbins = 20 34 theta1 =math.pi/835 theta2 =math.pi/236 theta1 =2*math.pi/337 theta2 =-2*math.pi/338 r1 =self.qmax/2.039 r2 =self.qmax/1.835 theta1 = math.pi/8 36 theta2 = math.pi/2 37 theta1 = 2 * math.pi/3 38 theta2 = -2 * math.pi/3 39 r1 = self.qmax/2.0 40 r2 = self.qmax/1.8 40 41 41 42 # Inner circle 42 43 from Arc import ArcInteractor 43 self.inner_circle = ArcInteractor(self, self.base.subplot, zorder=zorder, r=self.qmax/2.0,theta1= theta1, 44 self.inner_circle = ArcInteractor(self, self.base.subplot, 45 zorder=zorder, 46 r=self.qmax/2.0, 47 theta1=theta1, 44 48 theta2=theta2) 45 49 self.inner_circle.qmax = self.qmax 46 self.outer_circle = ArcInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax/1.8,theta1= theta1, 50 self.outer_circle = ArcInteractor(self, self.base.subplot, 51 zorder=zorder+1, 52 r=self.qmax/1.8, 53 theta1=theta1, 47 54 theta2=theta2) 48 self.outer_circle.qmax = self.qmax *1.255 self.outer_circle.qmax = self.qmax * 1.2 49 56 #self.outer_circle.set_cursor(self.base.qmax/1.8, 0) 50 57 from Edge import RadiusInteractor 51 self.right_edge= RadiusInteractor(self, self.base.subplot, zorder=zorder+1, 58 self.right_edge= RadiusInteractor(self, self.base.subplot, 59 zorder=zorder+1, 52 60 arc1=self.inner_circle, 53 61 arc2=self.outer_circle, 54 62 theta=theta1) 55 self.left_edge= RadiusInteractor(self, self.base.subplot, zorder=zorder+1, 63 self.left_edge= RadiusInteractor(self, self.base.subplot, 64 zorder=zorder+1, 56 65 arc1=self.inner_circle, 57 66 arc2=self.outer_circle, … … 75 84 """ 76 85 output = open(path, 'w') 77 78 86 data_x, data_y = self.get_data(image, x, y) 79 87 … … 109 117 #print "inner circle has moved" 110 118 self.inner_circle.update() 111 r1 =self.inner_circle.get_radius()112 r2 =self.outer_circle.get_radius()113 self.right_edge.update(r1, r2)114 self.left_edge.update(r1, r2)119 r1 = self.inner_circle.get_radius() 120 r2 = self.outer_circle.get_radius() 121 self.right_edge.update(r1, r2) 122 self.left_edge.update(r1, r2) 115 123 if self.outer_circle.has_move: 116 124 #print "outer circle has moved" 117 125 self.outer_circle.update() 118 r1 =self.inner_circle.get_radius()119 r2 =self.outer_circle.get_radius()120 self.left_edge.update(r1, r2)121 self.right_edge.update(r1, r2)126 r1 = self.inner_circle.get_radius() 127 r2 = self.outer_circle.get_radius() 128 self.left_edge.update(r1, r2) 129 self.right_edge.update(r1, r2) 122 130 if self.right_edge.has_move: 123 131 #print "right edge has moved" 124 132 self.right_edge.update() 125 self.inner_circle.update(theta1=self.right_edge.get_angle(), theta2=None) 126 self.outer_circle.update(theta1=self.right_edge.get_angle(), theta2=None) 133 self.inner_circle.update(theta1=self.right_edge.get_angle(), 134 theta2=None) 135 self.outer_circle.update(theta1=self.right_edge.get_angle(), 136 theta2=None) 127 137 if self.left_edge.has_move: 128 138 #print "left Edge has moved" 129 139 self.left_edge.update() 130 self.inner_circle.update(theta1=None, theta2=self.left_edge.get_angle()) 131 self.outer_circle.update(theta1=None, theta2=self.left_edge.get_angle()) 140 self.inner_circle.update(theta1=None, 141 theta2=self.left_edge.get_angle()) 142 self.outer_circle.update(theta1=None, 143 theta2=self.left_edge.get_angle()) 132 144 133 134 145 def save(self, ev): 135 146 """ … … 149 160 """ post data averaging in Q""" 150 161 if self.inner_circle.get_radius() < self.outer_circle.get_radius(): 151 rmin =self.inner_circle.get_radius()152 rmax =self.outer_circle.get_radius()162 rmin = self.inner_circle.get_radius() 163 rmax = self.outer_circle.get_radius() 153 164 else: 154 rmin =self.outer_circle.get_radius()155 rmax =self.inner_circle.get_radius()165 rmin = self.outer_circle.get_radius() 166 rmax = self.inner_circle.get_radius() 156 167 if self.right_edge.get_angle() < self.left_edge.get_angle(): 157 phimin =self.right_edge.get_angle()158 phimax =self.left_edge.get_angle()168 phimin = self.right_edge.get_angle() 169 phimax = self.left_edge.get_angle() 159 170 else: 160 phimin =self.left_edge.get_angle()161 phimax =self.right_edge.get_angle()162 163 # print "phimin, phimax, rmin ,rmax",math.degrees(phimin),math.degrees(phimax), rmin ,rmax171 phimin = self.left_edge.get_angle() 172 phimax = self.right_edge.get_angle() 173 #print "phimin, phimax, rmin ,rmax",math.degrees(phimin), 174 # math.degrees(phimax), rmin ,rmax 164 175 #from DataLoader.manipulations import SectorQ 165 176 166 sect = new_sector(r_min=rmin, r_max=rmax, phi_min=phimin, phi_max=phimax) 177 sect = new_sector(r_min=rmin, r_max=rmax, 178 phi_min=phimin, phi_max=phimax) 167 179 sector = sect(self.base.data2D) 168 180 169 181 from sans.guiframe.dataFitting import Data1D 170 if hasattr(sector, "dxl"):171 dxl = sector.dxl182 if hasattr(sector, "dxl"): 183 dxl = sector.dxl 172 184 else: 173 dxl = None174 if hasattr(sector, "dxw"):175 dxw = sector.dxw185 dxl = None 186 if hasattr(sector, "dxw"): 187 dxw = sector.dxw 176 188 else: 177 dxw= None 178 179 new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy,dxl=dxl,dxw=dxw) 180 new_plot.name = str(new_sector.__name__) +"("+ self.base.data2D.name+")" 181 182 183 184 new_plot.source=self.base.data2D.source 189 dxw = None 190 new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy, 191 dxl=dxl, dxw=dxw) 192 new_plot.name = str(new_sector.__name__) + \ 193 "("+ self.base.data2D.name+")" 194 new_plot.source = self.base.data2D.source 185 195 new_plot.interactive = True 186 196 #print "loader output.detector",output.source 187 new_plot.detector = self.base.data2D.detector197 new_plot.detector = self.base.data2D.detector 188 198 # If the data file does not tell us what the axes are, just assume... 189 199 new_plot.xaxis("\\rm{Q}", 'rad') 190 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 191 new_plot.group_id = str(new_sector.__name__)+self.base.data2D.name 192 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 193 title=str(new_sector.__name__) )) 194 200 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 201 new_plot.group_id = str(new_sector.__name__) + self.base.data2D.name 202 wx.PostEvent(self.base.parent, 203 NewPlotEvent(plot=new_plot, title=str(new_sector.__name__))) 195 204 196 205 def moveend(self, ev): 197 206 #self.base.thaw_axes() 198 207 199 208 # Post paramters 200 209 #event = SlicerParameterEvent() 201 210 #event.type = self.__class__.__name__ … … 271 280 """ 272 281 """ 273 def __init__(self, base,axes,color='black', zorder=3):282 def __init__(self, base, axes, color='black', zorder=3): 274 283 """ 275 284 """ … … 282 291 """ 283 292 from DataLoader.manipulations import SectorQ 284 self.post_data(SectorQ 293 self.post_data(SectorQ) 285 294 286 295 … … 288 297 """ 289 298 """ 290 def __init__(self, base,axes,color='black', zorder=3):299 def __init__(self, base, axes, color='black', zorder=3): 291 300 """ 292 301 """ -
guiframe/local_perspectives/plotting/BaseInteractor.py
r83f4445 r32c0841 40 40 41 41 """ 42 def __init__(self, base,axes,color='black'):42 def __init__(self, base, axes, color='black'): 43 43 """ 44 44 """ … … 46 46 self.axes = axes 47 47 self.color = color 48 self.clickx = None 49 self.clicky = None 50 self.markers = [] 48 51 49 52 def clear_markers(self): … … 52 55 """ 53 56 for h in self.markers: h.remove() 54 if self.markers: self.base.connect.clear(*self.markers) 57 if self.markers: 58 self.base.connect.clear(*self.markers) 55 59 self.markers = [] 56 60 … … 75 79 pass 76 80 77 def connect_markers(self, markers):81 def connect_markers(self, markers): 78 82 """ 79 83 Connect markers to callbacks … … 111 115 later restore(). 112 116 """ 113 self.clickx, self.clicky = ev.xdata,ev.ydata117 self.clickx, self.clicky = ev.xdata, ev.ydata 114 118 self.save(ev) 115 119 return True … … 126 130 the mouse leaves the window. 127 131 """ 128 inside, prop= self.axes.contains(ev)132 inside, _ = self.axes.contains(ev) 129 133 if inside: 130 self.clickx, self.clicky = ev.xdata,ev.ydata131 self.move(ev.xdata, ev.ydata,ev)134 self.clickx, self.clicky = ev.xdata, ev.ydata 135 self.move(ev.xdata, ev.ydata, ev) 132 136 else: 133 137 self.restore() … … 145 149 self.restore() 146 150 elif ev.key in ['up', 'down', 'right', 'left']: 147 dx,dy = self.dpixel(self.clickx,self.clicky,nudge=ev.control) 148 if ev.key == 'up': self.clicky += dy 149 elif ev.key == 'down': self.clicky -= dy 150 elif ev.key == 'right': self.clickx += dx 151 dx, dy = self.dpixel(self.clickx, self.clicky, nudge=ev.control) 152 if ev.key == 'up': 153 self.clicky += dy 154 elif ev.key == 'down': 155 self.clicky -= dy 156 elif ev.key == 'right': 157 self.clickx += dx 151 158 else: self.clickx -= dx 152 self.move(self.clickx, self.clicky,ev)159 self.move(self.clickx, self.clicky, ev) 153 160 else: 154 161 return False … … 156 163 return True 157 164 158 def dpixel(self, x,y,nudge=False):165 def dpixel(self, x, y, nudge=False): 159 166 """ 160 167 Return the step size in data coordinates for a small … … 164 171 """ 165 172 ax = self.axes 166 px, py = ax.transData.inverse_xy_tup((x,y))173 px, py = ax.transData.inverse_xy_tup((x, y)) 167 174 if nudge: 168 nx, ny = ax.transData.xy_tup((px+0.2,py+0.2))175 nx, ny = ax.transData.xy_tup((px+0.2, py+0.2)) 169 176 else: 170 nx, ny = ax.transData.xy_tup((px+1.,py+1.))171 dx, dy = nx-x,ny-y172 return dx, dy177 nx, ny = ax.transData.xy_tup((px+1.0, py+1.0)) 178 dx, dy = nx-x, ny-y 179 return dx, dy 173 180 -
guiframe/local_perspectives/plotting/Edge.py
rd955bf19 r32c0841 1 1 2 2 import math 3 import wx 4 from copy import deepcopy 5 3 #import wx 4 #from copy import deepcopy 6 5 from BaseInteractor import _BaseInteractor 7 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 6 #from sans.guicomm.events import NewPlotEvent 7 #from sans.guicomm.events import StatusEvent 8 #from sans.guicomm.events import SlicerParameterEvent 9 #from sans.guicomm.events import EVT_SLICER_PARS 8 10 9 11 10 11 12 12 class RadiusInteractor(_BaseInteractor): 13 13 """ 14 14 Select an annulus through a 2D plot 15 15 """ 16 def __init__(self,base,axes,color='black', zorder=5, arc1=None,arc2=None, 17 theta=math.pi/8): 18 16 def __init__(self, base, axes, color='black', zorder=5, arc1=None, 17 arc2=None, theta=math.pi/8): 18 """ 19 """ 19 20 _BaseInteractor.__init__(self, base, axes, color=color) 20 21 self.markers = [] 21 22 self.axes = axes 22 23 23 self.r1 = arc1.get_radius() 24 24 self.r2 = arc2.get_radius() 25 25 #print "radius init", self.r1, self.r2 26 self.theta =theta27 self.save_theta = theta26 self.theta = theta 27 self.save_theta = theta 28 28 #self.scale = 10.0 29 self.move_stop =False30 self.theta_left =None31 self.theta_right =None32 self.arc1 = arc133 self.arc2 =arc229 self.move_stop = False 30 self.theta_left = None 31 self.theta_right = None 32 self.arc1 = arc1 33 self.arc2 = arc2 34 34 #raise "Version error", message 35 x1 = self.r1*math.cos(self.theta)36 y1 = self.r1*math.sin(self.theta)37 x2 = self.r2*math.cos(self.theta)38 y2 = self.r2*math.sin(self.theta)39 self.line = self.axes.plot([x1, x2],[y1,y2],35 x1 = self.r1 * math.cos(self.theta) 36 y1 = self.r1 * math.sin(self.theta) 37 x2 = self.r2 * math.cos(self.theta) 38 y2 = self.r2 * math.sin(self.theta) 39 self.line = self.axes.plot([x1, x2], [y1, y2], 40 40 linestyle='-', marker='', 41 41 color=self.color, 42 42 visible=True)[0] 43 self.phi = theta43 self.phi = theta 44 44 self.npts = 20 45 self.has_move = False45 self.has_move = False 46 46 self.connect_markers([self.line]) 47 47 self.update() 48 49 48 50 49 def set_layer(self, n): … … 60 59 try: 61 60 self.line.remove() 62 63 61 except: 64 62 # Old version of matplotlib … … 71 69 return self.theta 72 70 73 def update(self, r1=None, r2=None, theta=None):71 def update(self, r1=None, r2=None, theta=None): 74 72 """ 75 73 Draw the new roughness on the graph. … … 79 77 if r2 != None: 80 78 self.r2 = r2 81 if theta !=None: 82 self.theta= theta 83 79 if theta != None: 80 self.theta = theta 84 81 #print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) 85 x1= self.r1*math.cos(self.theta) 86 y1= self.r1*math.sin(self.theta) 87 x2= self.r2*math.cos(self.theta) 88 y2= self.r2*math.sin(self.theta) 89 90 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 82 x1 = self.r1 * math.cos(self.theta) 83 y1 = self.r1 * math.sin(self.theta) 84 x2 = self.r2 * math.cos(self.theta) 85 y2 = self.r2 * math.sin(self.theta) 86 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 91 87 92 93 88 def save(self, ev): 94 89 """ … … 96 91 can restore on Esc. 97 92 """ 98 self.save_theta = math.atan2(ev.y,ev.x)93 self.save_theta = math.atan2(ev.y,ev.x) 99 94 #self.save_theta= self.theta 100 95 self.base.freeze_axes() … … 103 98 """ 104 99 """ 105 self.has_move = False100 self.has_move = False 106 101 self.base.moveend(ev) 107 102 108 def restore(self ):103 def restore(self, ev): 109 104 """ 110 105 Restore the roughness for this layer. … … 116 111 Process move to a new position, making sure that the move is allowed. 117 112 """ 118 self.theta = math.atan2(y,x)119 self.has_move = True113 self.theta = math.atan2(y, x) 114 self.has_move = True 120 115 self.base.base.update() 121 116 122 def set_cursor(self, r_min, r_max, theta):117 def set_cursor(self, r_min, r_max, theta): 123 118 """ 124 119 """ 125 self.theta = theta126 self.r1 = r_min127 self.r2 =r_max120 self.theta = theta 121 self.r1 = r_min 122 self.r2 = r_max 128 123 self.update() 129 124 -
guiframe/local_perspectives/plotting/Plotter1D.py
r3c44c66 r32c0841 18 18 import numpy 19 19 import time 20 21 20 import danse.common.plottools 22 21 from danse.common.plottools.PlotPanel import PlotPanel … … 24 23 from sans.guiframe import dataFitting 25 24 from sans.guicomm.events import EVT_NEW_PLOT 26 from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent,ErrorDataEvent 27 from sans.guicomm.events import RemoveDataEvent, AddManyDataEvent 25 from sans.guicomm.events import StatusEvent 26 from sans.guicomm.events import NewPlotEvent 27 from sans.guicomm.events import SlicerEvent 28 from sans.guicomm.events import ErrorDataEvent 29 from sans.guicomm.events import RemoveDataEvent 30 from sans.guicomm.events import AddManyDataEvent 28 31 from sans.guiframe.utils import PanelMenu 29 32 from sans.guiframe.dataFitting import Data1D … … 31 34 from binder import BindArtist 32 35 33 34 36 DEFAULT_QMAX = 0.05 35 37 DEFAULT_QSTEP = 0.001 36 38 DEFAULT_BEAM = 0.005 37 BIN_WIDTH = 139 BIN_WIDTH = 1 38 40 39 41 … … 53 55 group_id = None 54 56 55 def __init__(self, parent, id = -1, color = None,\56 dpi = None, style =wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):57 def __init__(self, parent, id=-1, color = None, 58 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 57 59 """ 58 60 Initialize the panel 59 61 """ 60 PlotPanel.__init__(self, parent, id = id, style = style, **kwargs) 61 62 PlotPanel.__init__(self, parent, id=id, style=style, **kwargs) 62 63 ## Reference to the parent window 63 64 self.parent = parent … … 65 66 self.plots = {} 66 67 ## save errors dy for each data plotted 67 self.err_dy ={}68 self.err_dy = {} 68 69 ## flag to determine if the hide or show context menu item should 69 70 ## be displayed 70 self.errors_hide =False71 self.errors_hide = False 71 72 ## Unique ID (from gui_manager) 72 73 self.uid = None … … 78 79 self.graph = Graph() 79 80 self.graph.xaxis("\\rm{Q}", 'A^{-1}') 80 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}")81 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 81 82 self.graph.render(self) 82 83 83 def set_data(self, list= []):84 def set_data(self, list=None): 84 85 """ 85 86 """ 86 87 pass 87 88 88 89 89 def _reset(self): … … 100 100 101 101 :param event: data event 102 103 102 """ 104 103 #TODO: Check for existence of plot attribute 105 104 # Check whether this is a replot. If we ask for a replot 106 105 # and the plottable no longer exists, ignore the event. 107 if hasattr(event, "update") and event.update ==True \106 if hasattr(event, "update") and event.update == True \ 108 107 and event.plot.name not in self.plots.keys(): 109 108 return 110 111 109 if hasattr(event, "reset"): 112 110 self._reset() 113 114 111 # Check whether the plottable is empty 115 is_empty = len(event.plot.x) ==0112 is_empty = len(event.plot.x) == 0 116 113 117 114 is_new = True … … 123 120 else: 124 121 # Check whether the class of plottable changed 125 if not event.plot.__class__ ==self.plots[event.plot.name].__class__:122 if not event.plot.__class__ == self.plots[event.plot.name].__class__: 126 123 #overwrite a plottable using the same name 127 124 self.graph.delete(self.plots[event.plot.name]) … … 134 131 # a new plottable overwrites a plotted one using the same id 135 132 for plottable in self.plots.itervalues(): 136 if hasattr(event.plot, "id") and hasattr(plottable, "id"):133 if hasattr(event.plot, "id") and hasattr(plottable, "id"): 137 134 #remove the existing plot and same id and same name 138 if event.plot.id==plottable.id and event.plot.name== plottable.name: 135 if event.plot.id == plottable.id and \ 136 event.plot.name == plottable.name: 139 137 self.graph.delete(plottable) 140 138 … … 146 144 self.plots[event.plot.name].y = event.plot.y 147 145 self.plots[event.plot.name].dy = event.plot.dy 148 if hasattr(event.plot, 'dx') and hasattr(self.plots[event.plot.name], 'dx'): 146 if hasattr(event.plot, 'dx') and \ 147 hasattr(self.plots[event.plot.name], 'dx'): 149 148 self.plots[event.plot.name].dx = event.plot.dx 150 149 … … 186 185 187 186 """ 187 selected_plot = self.plots[self.graph.selected_plottable] 188 188 ## Check if there is a selected graph to remove 189 189 if not self.graph.selected_plottable == None and\ 190 190 self.graph.selected_plottable in self.plots.keys(): 191 color=self.graph.plottables[self.plots[self.graph.selected_plottable]] 192 193 event = RemoveDataEvent(data =self.plots[self.graph.selected_plottable]) 191 color = self.graph.plottables[selected_plot] 192 event = RemoveDataEvent(data=selected_plot) 194 193 wx.PostEvent(self.parent, event) 195 self.graph.delete(sel f.plots[self.graph.selected_plottable])196 del sel f.plots[self.graph.selected_plottable]194 self.graph.delete(selected_plot) 195 del selected_plot 197 196 ## increment graph color 198 197 self.graph.color += color … … 209 208 slicerpop = PanelMenu() 210 209 slicerpop.set_plots(self.plots) 211 slicerpop.set_graph(self.graph) 212 210 slicerpop.set_graph(self.graph) 213 211 # Various plot options 214 212 id = wx.NewId() 215 slicerpop.Append(id, '&Save image', 'Save image as PNG')213 slicerpop.Append(id, '&Save image', 'Save image as PNG') 216 214 wx.EVT_MENU(self, id, self.onSaveImage) 217 218 215 id = wx.NewId() 219 slicerpop.Append(id, '&Print image', 'Print image ')216 slicerpop.Append(id, '&Print image', 'Print image ') 220 217 wx.EVT_MENU(self, id, self.onPrint) 221 222 218 id = wx.NewId() 223 slicerpop.Append(id, '&Print Preview', 'image preview for print')219 slicerpop.Append(id, '&Print Preview', 'image preview for print') 224 220 wx.EVT_MENU(self, id, self.onPrinterPreview) 225 226 221 slicerpop.AppendSeparator() 227 222 item_list = self.parent.get_context_menu(self.graph) 228 229 if (not item_list==None) and (not len(item_list)==0): 223 if (not item_list == None) and (not len(item_list) == 0): 230 224 for item in item_list: 231 225 try: … … 234 228 wx.EVT_MENU(self, id, item[2]) 235 229 except: 236 wx.PostEvent(self.parent, StatusEvent(status=\ 237 "ModelPanel1D.onContextMenu: bad menu item %s"%sys.exc_value)) 230 msg = "ModelPanel1D.onContextMenu: " 231 msg += "bad menu item %s"%sys.exc_value 232 wx.PostEvent(self.parent, StatusEvent(status=msg)) 238 233 pass 239 234 slicerpop.AppendSeparator() … … 243 238 id = wx.NewId() 244 239 name = plot.name 245 246 240 slicerpop.Append(id, "&Save points" ) 247 241 self.action_ids[str(id)] = plot 248 242 wx.EVT_MENU(self, id, self._onSave) 249 250 243 id = wx.NewId() 251 244 slicerpop.Append(id, "Remove %s curve" % name) … … 255 248 # Option to hide 256 249 #TODO: implement functionality to hide a plottable (legend click) 257 258 250 if self.graph.selected_plottable in self.plots: 259 selected_plot= self.plots[self.graph.selected_plottable] 260 251 selected_plot = self.plots[self.graph.selected_plottable] 261 252 id = wx.NewId() 262 253 slicerpop.Append(id, '&Linear fit') 263 254 wx.EVT_MENU(self, id, self.onFitting) 264 265 255 slicerpop.AppendSeparator() 266 267 256 id = wx.NewId() 268 257 slicerpop.Append(id, '&Change scale') 269 258 wx.EVT_MENU(self, id, self._onProperties) 270 271 259 id = wx.NewId() 272 260 slicerpop.Append(id, '&Reset Graph') 273 261 wx.EVT_MENU(self, id, self.onResetGraph) 274 275 262 pos = event.GetPosition() 276 263 pos = self.ScreenToClient(pos) 277 264 self.PopupMenu(slicerpop, pos) 278 279 265 280 266 def _on_remove_errors(self, evt): … … 293 279 name =self.plots[self.graph.selected_plottable].name 294 280 dy = self.plots[self.graph.selected_plottable].dy 295 self.err_dy[name] = dy281 self.err_dy[name] = dy 296 282 ## Create a new dy for a new plottable 297 import numpy283 #import numpy 298 284 dy = numpy.zeros(len(self.plots[self.graph.selected_plottable].y)) 299 285 selected_plot = self.plots[self.graph.selected_plottable] 300 286 301 if selected_plot.__class__.__name__ =="Data1D":287 if selected_plot.__class__.__name__ == "Data1D": 302 288 # Make sure that we can pass a basic Data1D 303 289 dxl = None … … 307 293 if hasattr(selected_plot, "dxw"): 308 294 dxw = selected_plot.dxw 309 new_plot = Data1D( x=selected_plot.x, 310 y= selected_plot.y, 311 dx=selected_plot.dx, 312 dy=dy) 313 new_plot.dxl = dxl 314 new_plot.dxw = dxw 315 316 else: 317 new_plot = Theory1D(x=selected_plot.x,y=selected_plot.y,dy=dy) 295 new_plot = Data1D(x=selected_plot.x, y=selected_plot.y, 296 dx=selected_plot.dx, dy=dy) 297 new_plot.dxl = dxl 298 new_plot.dxw = dxw 299 else: 300 new_plot = Theory1D(x=selected_plot.x, 301 y=selected_plot.y, dy=dy) 318 302 new_plot.interactive = True 319 303 self.errors_hide = True … … 321 305 if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 322 306 new_plot.group_id = self.plots[self.graph.selected_plottable].group_id 323 if hasattr(self.plots[self.graph.selected_plottable], "id"):307 if hasattr(self.plots[self.graph.selected_plottable], "id"): 324 308 new_plot.id = self.plots[self.graph.selected_plottable].id 325 309 else: … … 333 317 new_plot.yaxis(label, unit) 334 318 ## save the color of the selected plottable before it is deleted 335 color =self.graph.plottables[self.plots[self.graph.selected_plottable]]319 color = self.graph.plottables[self.plots[self.graph.selected_plottable]] 336 320 self.graph.delete(self.plots[self.graph.selected_plottable]) 337 321 ## add newly created plottable to the graph with the save color 338 322 self.graph.color += color 339 self.graph.add(new_plot,color) 340 ## transforming the view of the new data into the same of the previous data 323 self.graph.add(new_plot, color) 324 ## transforming the view of the new data into the same of 325 #the previous data 341 326 self._onEVT_FUNC_PROPERTY() 342 327 ## save the plot 343 self.plots[self.graph.selected_plottable] =new_plot328 self.plots[self.graph.selected_plottable] = new_plot 344 329 ## Render the graph 345 330 self.graph.render(self) 346 331 self.subplot.figure.canvas.draw_idle() 347 348 332 event = ErrorDataEvent(err_dy=self.err_dy) 349 333 wx.PostEvent(self.parent, event) … … 366 350 length = len(self.plots[self.graph.selected_plottable].x) 367 351 dy = numpy.zeros(length) 368 369 selected_plot= self.plots[self.graph.selected_plottable] 370 352 selected_plot = self.plots[self.graph.selected_plottable] 371 353 try: 372 354 dy = self.err_dy[selected_plot.name] 373 374 355 except: 375 #for i in range(length): 376 #dy[i] = math.sqrt(self.plots[self.graph.selected_plottable].y[i]) 377 if hasattr(selected_plot,"dy"): 378 dy= selected_plot.dy 356 if hasattr(selected_plot, "dy"): 357 dy = selected_plot.dy 379 358 else: 380 359 dy = numpy.zeros(selected_plot.dy) 381 382 360 ## Create a new plottable data1D 383 if selected_plot.__class__.__name__ =="Data1D":361 if selected_plot.__class__.__name__ == "Data1D": 384 362 # Make sure that we can pass a basic Data1D 385 363 dxl = None … … 389 367 if hasattr(selected_plot, "dxw"): 390 368 dxw = selected_plot.dxw 391 new_plot = Data1D( 392 y= 369 new_plot = Data1D(x=selected_plot.x, 370 y=selected_plot.y, 393 371 dx=selected_plot.dx, 394 372 dy=dy) 395 373 new_plot.dxl = dxl 396 new_plot.dxw = dxw 397 374 new_plot.dxw = dxw 398 375 else: 399 376 ## Create a new plottable Theory1D 400 new_plot = Theory1D(x=selected_plot.x,y=selected_plot.y,dy=dy) 401 377 new_plot = Theory1D(x=selected_plot.x, y=selected_plot.y, dy=dy) 402 378 new_plot.interactive = True 403 379 new_plot.name = self.plots[self.graph.selected_plottable].name … … 422 398 ## add newly created plottable to the graph with the save color 423 399 self.graph.add(new_plot, color) 424 ## transforming the view of the new data into the same of the previous data 400 ## transforming the view of the new data into the same of 401 # the previous data 425 402 self._onEVT_FUNC_PROPERTY() 426 403 ## save the plot … … 443 420 out = open(path, 'w') 444 421 has_errors = True 445 if data.dy ==None or data.dy==[]:422 if data.dy == None or data.dy == []: 446 423 has_errors = False 447 448 424 # Sanity check 449 425 if has_errors: 450 426 try: 451 427 if len(data.y) != len(data.dy): 452 453 428 has_errors = False 454 429 except: 455 430 has_errors = False 456 457 431 if has_errors: 458 432 out.write("<X> <Y> <dY>\n") … … 468 442 out.write("%g %g\n" % (data.x[i], 469 443 data.y[i])) 470 471 444 out.close() 472 445 try: … … 489 462 "CanSAS 1D files(*.xml)|*.xml" 490 463 dlg = wx.FileDialog(self, "Choose a file", 491 self._default_save_location, "",wildcard , wx.SAVE) 464 self._default_save_location, 465 "", wildcard , wx.SAVE) 492 466 493 467 if dlg.ShowModal() == wx.ID_OK: … … 495 469 mypath = os.path.basename(path) 496 470 497 #TODO: This is bad design. The DataLoader is designed to recognize extensions. 498 # It should be a simple matter of calling the .save(file, data, '.xml') method 471 #TODO: This is bad design. The DataLoader is designed 472 #to recognize extensions. 473 # It should be a simple matter of calling the . 474 #save(file, data, '.xml') method 499 475 # of the DataLoader.loader.Loader class. 500 476 from DataLoader.loader import Loader … … 502 478 loader = Loader() 503 479 data = self.plots[self.graph.selected_plottable] 504 format =".txt"480 format = ".txt" 505 481 if os.path.splitext(mypath)[1].lower() == format: 506 482 self._onsaveTXT( path) 507 508 format= ".xml" 509 if os.path.splitext(mypath)[1].lower() ==format: 510 loader.save( path, data, format) 483 format = ".xml" 484 if os.path.splitext(mypath)[1].lower() == format: 485 loader.save(path, data, format) 511 486 try: 512 487 self._default_save_location = os.path.dirname(path) -
guiframe/local_perspectives/plotting/Plotter2D.py
rd955bf19 r32c0841 12 12 13 13 import wx 14 import sys, math 14 import sys 15 import math 15 16 import pylab 16 17 17 import danse.common.plottools 18 18 from danse.common.plottools.PlotPanel import PlotPanel … … 20 20 from sans.guicomm.events import EVT_NEW_PLOT 21 21 from sans.guicomm.events import EVT_SLICER_PARS 22 from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent 22 from sans.guicomm.events import StatusEvent 23 from sans.guicomm.events import NewPlotEvent 24 from sans.guicomm.events import SlicerEvent 23 25 from sans.guiframe.utils import PanelMenu 24 26 from binder import BindArtist 25 27 from Plotter1D import ModelPanel1D 26 28 from danse.common.plottools.toolbar import NavigationToolBar 27 29 from sans.guiframe.dataFitting import Data1D 28 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 29 30 30 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 31 31 32 32 DEFAULT_QMAX = 0.05 … … 34 34 DEFAULT_BEAM = 0.005 35 35 BIN_WIDTH = 1.0 36 from danse.common.plottools.toolbar import NavigationToolBar 36 37 37 38 38 class NavigationToolBar2D(NavigationToolBar): … … 81 81 82 82 83 def __init__(self, parent, id = -1,data2d=None, color = None,\84 dpi = None, style =wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):83 def __init__(self, parent, id=-1, data2d=None, color = None, 84 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 85 85 """ 86 86 Initialize the panel 87 87 """ 88 ModelPanel1D.__init__(self, parent, id = id, style =style, **kwargs)88 ModelPanel1D.__init__(self, parent, id=id, style=style, **kwargs) 89 89 90 90 ## Reference to the parent window … … 111 111 self.axes_frozen = False 112 112 ## panel that contains result from slicer motion (ex: Boxsum info) 113 self.panel_slicer=None 114 113 self.panel_slicer = None 115 114 ## Graph 116 115 self.graph = Graph() 117 116 self.graph.xaxis("\\rm{Q}", 'A^{-1}') 118 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}")117 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 119 118 self.graph.render(self) 120 119 ## store default value of zmin and zmax … … 127 126 """ 128 127 self.enable_toolbar = True 129 130 self.toolbar = NavigationToolBar2D(parent=self,canvas=self.canvas) 128 self.toolbar = NavigationToolBar2D(parent=self, canvas=self.canvas) 131 129 self.toolbar.Realize() 132 133 130 # On Windows platform, default window size is incorrect, so set 134 131 # toolbar width to figure width. 135 132 tw, th = self.toolbar.GetSizeTuple() 136 133 fw, fh = self.canvas.GetSizeTuple() 137 138 134 self.toolbar.SetSize(wx.Size(fw, th)) 139 self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) 140 135 self.sizer.Add(self.toolbar, 0, wx.LEFT|wx.EXPAND) 141 136 # update the axes menu on the toolbar 142 137 self.toolbar.update() … … 159 154 # Check whether this is a replot. If we ask for a replot 160 155 # and the plottable no longer exists, ignore the event. 161 if hasattr(event, "update") and event.update ==True \156 if hasattr(event, "update") and event.update == True \ 162 157 and event.plot.name not in self.plots.keys(): 163 158 return 164 165 159 if hasattr(event, "reset"): 166 160 self._reset() … … 168 162 if event.plot.name in self.plots.keys(): 169 163 # Check whether the class of plottable changed 170 if not event.plot.__class__ ==self.plots[event.plot.name].__class__:164 if not event.plot.__class__ == self.plots[event.plot.name].__class__: 171 165 #overwrite a plottable using the same name 172 166 self.graph.delete(self.plots[event.plot.name]) … … 179 173 for plottable in self.plots.itervalues(): 180 174 if hasattr(event.plot,"id"): 181 if event.plot.id ==plottable.id:175 if event.plot.id == plottable.id: 182 176 self.graph.delete(plottable) 183 177 … … 200 194 self.plots[event.plot.name].err_data = event.plot.err_data 201 195 # update qmax with the new xmax of data plotted 202 self.qmax = event.plot.xmax203 204 self.slicer = None196 self.qmax = event.plot.xmax 197 198 self.slicer = None 205 199 # Check axis labels 206 200 #TODO: Should re-factor this … … 209 203 #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 210 204 if len(self.data2D.detector) < 1: 211 if len(event.plot._xunit) < 1 and len(event.plot._yunit) < 1:205 if len(event.plot._xunit) < 1 and len(event.plot._yunit) < 1: 212 206 event.plot._xaxis = '\\rm{x}' 213 207 event.plot._yaxis = '\\rm{y}' 214 208 event.plot._xunit = 'pixel' 215 209 event.plot._yunit = 'pixel' 216 217 210 self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 218 211 self.graph.yaxis(event.plot._yaxis, event.plot._yunit) … … 224 217 self.default_zmax_ctl = self.zmax_2D 225 218 226 227 219 def onContextMenu(self, event): 228 220 """ … … 241 233 242 234 id = wx.NewId() 243 slicerpop.Append(id,'&Print image', 'Print image 235 slicerpop.Append(id,'&Print image', 'Print image') 244 236 wx.EVT_MENU(self, id, self.onPrint) 245 237 … … 252 244 253 245 item_list = self.parent.get_context_menu(self.graph) 254 if (not item_list ==None) and (not len(item_list)==0):255 256 for item in item_list:257 try:258 id = wx.NewId()259 slicerpop.Append(id, item[0], item[1])260 wx.EVT_MENU(self, id, item[2])261 except:262 wx.PostEvent(self.parent, StatusEvent(status=\263 "ModelPanel1D.onContextMenu: bad menu item %s"%sys.exc_value))264 265 246 if (not item_list == None) and (not len(item_list) == 0): 247 for item in item_list: 248 try: 249 id = wx.NewId() 250 slicerpop.Append(id, item[0], item[1]) 251 wx.EVT_MENU(self, id, item[2]) 252 except: 253 msg = "ModelPanel1D.onContextMenu: " 254 msg += "bad menu item %s"%sys.exc_value 255 wx.PostEvent(self.parent, StatusEvent(status=msg)) 256 pass 257 slicerpop.AppendSeparator() 266 258 267 259 id = wx.NewId() 268 260 slicerpop.Append(id, '&Perform circular average') 269 261 wx.EVT_MENU(self, id, self.onCircular) 270 271 262 id = wx.NewId() 272 263 slicerpop.Append(id, '&Sector [Q view]') 273 264 wx.EVT_MENU(self, id, self.onSectorQ) 274 275 265 id = wx.NewId() 276 266 slicerpop.Append(id, '&Annulus [Phi view ]') 277 267 wx.EVT_MENU(self, id, self.onSectorPhi) 278 279 268 id = wx.NewId() 280 269 slicerpop.Append(id, '&Box Sum') 281 270 wx.EVT_MENU(self, id, self.onBoxSum) 282 283 271 id = wx.NewId() 284 272 slicerpop.Append(id, '&Box averaging in Qx') 285 273 wx.EVT_MENU(self, id, self.onBoxavgX) 286 287 274 id = wx.NewId() 288 275 slicerpop.Append(id, '&Box averaging in Qy') 289 276 wx.EVT_MENU(self, id, self.onBoxavgY) 290 291 if self.slicer !=None : 277 if self.slicer != None: 292 278 id = wx.NewId() 293 279 slicerpop.Append(id, '&Clear slicer') 294 280 wx.EVT_MENU(self, id, self.onClearSlicer) 295 296 if self.slicer.__class__.__name__ !="BoxSum": 281 if self.slicer.__class__.__name__ != "BoxSum": 297 282 id = wx.NewId() 298 283 slicerpop.Append(id, '&Edit Slicer Parameters') 299 284 wx.EVT_MENU(self, id, self._onEditSlicer) 300 301 285 slicerpop.AppendSeparator() 302 303 286 id = wx.NewId() 304 287 slicerpop.Append(id, '&Detector Parameters') 305 wx.EVT_MENU(self, id, self._onEditDetector) 306 307 288 wx.EVT_MENU(self, id, self._onEditDetector) 308 289 id = wx.NewId() 309 290 slicerpop.Append(id, '&Toggle Linear/Log scale') 310 291 wx.EVT_MENU(self, id, self._onToggleScale) 311 312 292 pos = event.GetPosition() 313 293 pos = self.ScreenToClient(pos) 314 294 self.PopupMenu(slicerpop, pos) 315 295 316 317 296 def _onEditDetector(self, event): 318 297 """ … … 322 301 323 302 """ 324 325 303 import detector_dialog 326 327 304 dialog = detector_dialog.DetectorDialog(self, -1,base=self.parent, 328 305 reset_zmin_ctl =self.default_zmin_ctl, … … 333 310 xmax = max(self.data2D.xmin, self.data2D.xmax) 334 311 ymax = max(self.data2D.ymin, self.data2D.ymax) 335 qmax = math.sqrt(math.pow(xmax, 2)+math.pow(ymax,2))312 qmax = math.sqrt(math.pow(xmax, 2) + math.pow(ymax, 2)) 336 313 beam = self.data2D.xmin 337 338 314 ## set dialog window content 339 315 dialog.setContent(xnpts=xnpts,ynpts=ynpts,qmax=qmax, … … 345 321 self.zmin_2D = evt.zmin 346 322 self.zmax_2D = evt.zmax 347 self.cmap= evt.cmap 348 323 self.cmap = evt.cmap 349 324 dialog.Destroy() 350 325 ## Redraw the current image 351 self.image(data= 326 self.image(data=self.data2D.data, 352 327 qx_data=self.data2D.qx_data, 353 328 qy_data=self.data2D.qy_data, … … 359 334 zmax= self.zmax_2D, 360 335 cmap= self.cmap, 361 color=0, symbol=0,label=self.data2D.name)#'data2D')336 color=0, symbol=0, label=self.data2D.name) 362 337 self.subplot.figure.canvas.draw_idle() 363 338 364 365 366 339 def freeze_axes(self): 367 340 """ … … 395 368 create an empty slicervent 396 369 """ 397 return SlicerEvent(type=None, 398 params=None, 399 obj_class=None) 370 return SlicerEvent(type=None, params=None, obj_class=None) 400 371 401 372 def _onEVT_INTERNAL(self, event): … … 417 388 418 389 """ 419 420 390 ## Clear current slicer 421 391 if not self.slicer == None: … … 429 399 self.update() 430 400 self.slicer.update() 431 wx.PostEvent(self.parent, StatusEvent(status=\432 "Plotter2D._setSlicer %s"%self.slicer.__class__.__name__))401 msg = "Plotter2D._setSlicer %s"%self.slicer.__class__.__name__ 402 wx.PostEvent(self.parent, StatusEvent(status=msg)) 433 403 # Post slicer event 434 404 event = self._getEmptySlicerEvent() 435 405 event.type = self.slicer.__class__.__name__ 436 437 406 event.obj_class = self.slicer.__class__ 438 407 event.params = self.slicer.get_params() 439 408 wx.PostEvent(self, event) 440 409 441 442 410 def onCircular(self, event): 443 411 """ … … 447 415 448 416 """ 449 450 417 from DataLoader.manipulations import CircularAverage 451 418 ## compute the maximum radius of data2D 452 self.qmax= max(math.fabs(self.data2D.xmax),math.fabs(self.data2D.xmin)) 453 self.ymax=max(math.fabs(self.data2D.ymax),math.fabs(self.data2D.ymin)) 454 self.radius= math.sqrt( math.pow(self.qmax,2)+math.pow(self.ymax,2)) 419 self.qmax = max(math.fabs(self.data2D.xmax), 420 math.fabs(self.data2D.xmin)) 421 self.ymax = max(math.fabs(self.data2D.ymax), 422 math.fabs(self.data2D.ymin)) 423 self.radius = math.sqrt(math.pow(self.qmax, 2)+ math.pow(self.ymax, 2)) 455 424 ##Compute beam width 456 bin_width = (self.qmax + self.qmax)/100425 bin_width = (self.qmax + self.qmax)/100 457 426 ## Create data1D circular average of data2D 458 Circle = CircularAverage( r_min=0, r_max=self.radius, bin_width=bin_width) 427 Circle = CircularAverage(r_min=0, r_max=self.radius, 428 bin_width=bin_width) 459 429 circ = Circle(self.data2D) 460 461 430 from sans.guiframe.dataFitting import Data1D 462 if hasattr(circ, "dxl"):463 dxl = circ.dxl431 if hasattr(circ, "dxl"): 432 dxl = circ.dxl 464 433 else: 465 dxl = None466 if hasattr(circ, "dxw"):467 dxw = circ.dxw434 dxl = None 435 if hasattr(circ, "dxw"): 436 dxw = circ.dxw 468 437 else: 469 dxw= None 470 471 new_plot = Data1D(x=circ.x,y=circ.y,dy=circ.dy) 472 new_plot.dxl=dxl 473 new_plot.dxw=dxw 474 new_plot.name = "Circ avg "+ self.data2D.name 475 new_plot.source=self.data2D.source 476 #new_plot.info=self.data2D.info 438 dxw = None 439 new_plot = Data1D(x=circ.x, y=circ.y, dy=circ.dy) 440 new_plot.dxl = dxl 441 new_plot.dxw = dxw 442 new_plot.name = "Circ avg " + self.data2D.name 443 new_plot.source = self.data2D.source 444 #new_plot.info = self.data2D.info 477 445 new_plot.interactive = True 478 new_plot.detector = self.data2D.detector446 new_plot.detector = self.data2D.detector 479 447 ## If the data file does not tell us what the axes are, just assume... 480 new_plot.xaxis("\\rm{Q}","A^{-1}") 481 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 482 new_plot.group_id = "Circ avg "+ self.data2D.name 483 new_plot.id = "Circ avg "+ self.data2D.name 484 new_plot.is_data= True 485 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 448 new_plot.xaxis("\\rm{Q}", "A^{-1}") 449 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 450 new_plot.group_id = "Circ avg " + self.data2D.name 451 new_plot.id = "Circ avg " + self.data2D.name 452 new_plot.is_data = True 453 wx.PostEvent(self.parent, 454 NewPlotEvent(plot=new_plot, title=new_plot.name)) 486 455 487 456 def _onEditSlicer(self, event): … … 494 463 495 464 """ 496 if self.slicer != None:465 if self.slicer != None: 497 466 from SlicerParameters import SlicerParameterPanel 498 467 dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") … … 508 477 from SectorSlicer import SectorInteractor 509 478 self.onClearSlicer(event) 510 wx.PostEvent(self, InternalEvent(slicer= 479 wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) 511 480 512 481 def onSectorPhi(self, event): … … 516 485 from AnnulusSlicer import AnnulusInteractor 517 486 self.onClearSlicer(event) 518 wx.PostEvent(self, InternalEvent(slicer= 487 wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) 519 488 520 489 def onBoxSum(self, event): … … 523 492 from boxSum import BoxSum 524 493 self.onClearSlicer(event) 525 526 494 self.slicer_z += 1 527 495 self.slicer = BoxSum(self, self.subplot, zorder=self.slicer_z) 528 529 496 self.subplot.set_ylim(self.data2D.ymin, self.data2D.ymax) 530 497 self.subplot.set_xlim(self.data2D.xmin, self.data2D.xmax) 531 532 498 self.update() 533 499 self.slicer.update() … … 537 503 ## Create a new panel to display results of summation of Data2D 538 504 from slicerpanel import SlicerPanel 539 new_panel = SlicerPanel(parent= self.parent, id= -1, 540 base= self, type= type, 541 params= params, style= wx.RAISED_BORDER) 542 543 new_panel.window_caption=self.slicer.__class__.__name__+" "+ str(self.data2D.name) 544 new_panel.window_name = self.slicer.__class__.__name__+" "+ str(self.data2D.name) 505 new_panel = SlicerPanel(parent=self.parent, id=-1, 506 base=self, type=type, 507 params=params, style=wx.RAISED_BORDER) 508 509 new_panel.window_caption = self.slicer.__class__.__name__ + " " + \ 510 str(self.data2D.name) 511 new_panel.window_name = self.slicer.__class__.__name__+ " " + \ 512 str(self.data2D.name) 545 513 ## Store a reference of the new created panel 546 self.panel_slicer = new_panel514 self.panel_slicer = new_panel 547 515 ## save the window_caption of the new panel in the current slicer 548 self.slicer.set_panel_name( name=new_panel.window_caption)516 self.slicer.set_panel_name(name=new_panel.window_caption) 549 517 ## post slicer panel to guiframe to display it 550 518 from sans.guicomm.events import SlicerPanelEvent 551 wx.PostEvent(self.parent, SlicerPanelEvent (panel=self.panel_slicer,552 main_panel 519 wx.PostEvent(self.parent, SlicerPanelEvent(panel=self.panel_slicer, 520 main_panel=self)) 553 521 554 522 def onBoxavgX(self,event): … … 561 529 from boxSlicer import BoxInteractorX 562 530 self.onClearSlicer(event) 563 wx.PostEvent(self, InternalEvent(slicer= 531 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) 564 532 565 533 def onBoxavgY(self,event): … … 573 541 from boxSlicer import BoxInteractorY 574 542 self.onClearSlicer(event) 575 wx.PostEvent(self, InternalEvent(slicer= 543 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) 576 544 577 545 def onClearSlicer(self, event): … … 579 547 Clear the slicer on the plot 580 548 """ 581 if not self.slicer ==None:549 if not self.slicer == None: 582 550 self.slicer.clear() 583 551 self.subplot.figure.canvas.draw() 584 552 self.slicer = None 585 586 553 # Post slicer None event 587 554 event = self._getEmptySlicerEvent() -
guiframe/local_perspectives/plotting/SectorSlicer.py
rd955bf19 r32c0841 2 2 import math 3 3 import wx 4 from copy import deepcopy 5 4 #from copy import deepcopy 6 5 from BaseInteractor import _BaseInteractor 7 from sans.guicomm.events import NewPlotEvent, StatusEvent 8 from sans.guicomm.events import SlicerParameterEvent,EVT_SLICER_PARS 9 6 from sans.guicomm.events import NewPlotEvent 7 from sans.guicomm.events import StatusEvent 8 from sans.guicomm.events import SlicerParameterEvent 9 from sans.guicomm.events import EVT_SLICER_PARS 10 10 from sans.guiframe.dataFitting import Data1D 11 11 12 12 13 class SectorInteractor(_BaseInteractor): … … 14 15 Draw a sector slicer.Allow to performQ averaging on data 2D 15 16 """ 16 def __init__(self, base,axes,color='black', zorder=3):17 def __init__(self, base, axes, color='black', zorder=3): 17 18 18 19 _BaseInteractor.__init__(self, base, axes, color=color) … … 24 25 25 26 ## compute qmax limit to reset the graph 26 x = math.pow(max(self.base.data2D.xmax,math.fabs(self.base.data2D.xmin)),2) 27 y = math.pow(max(self.base.data2D.ymax,math.fabs(self.base.data2D.ymin)),2) 28 self.qmax= math.sqrt(x + y) 27 x = math.pow(max(self.base.data2D.xmax, 28 math.fabs(self.base.data2D.xmin)), 2) 29 y = math.pow(max(self.base.data2D.ymax, 30 math.fabs(self.base.data2D.ymin)), 2) 31 self.qmax = math.sqrt(x + y) 29 32 ## Number of points on the plot 30 33 self.nbins = 20 31 34 ## Angle of the middle line 32 self.theta2 = math.pi/335 self.theta2 = math.pi/3 33 36 ## Absolute value of the Angle between the middle line and any side line 34 self.phi=math.pi/12 35 37 self.phi = math.pi/12 36 38 ## Middle line 37 self.main_line = LineInteractor(self, self.base.subplot,color='blue', zorder=zorder, r=self.qmax, 39 self.main_line = LineInteractor(self, self.base.subplot, color='blue', 40 zorder=zorder, r=self.qmax, 38 41 theta= self.theta2) 39 42 self.main_line.qmax = self.qmax 40 43 ## Right Side line 41 self.right_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 42 r=self.qmax, 43 phi= -1*self.phi, 44 theta2=self.theta2) 44 self.right_line = SideInteractor(self, self.base.subplot, color='black', 45 zorder=zorder, r=self.qmax, 46 phi=-1*self.phi, theta2=self.theta2) 45 47 self.right_line.qmax = self.qmax 46 48 ## Left Side line 47 self.left_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 48 r=self.qmax, 49 phi= self.phi, 50 theta2=self.theta2) 49 self.left_line = SideInteractor(self, self.base.subplot, color='black', 50 zorder=zorder, r=self.qmax, 51 phi=self.phi, theta2=self.theta2) 51 52 self.left_line.qmax = self.qmax 52 53 ## draw the sector 53 54 self.update() 54 55 self._post_data() 55 56 56 ## Bind to slice parameter events 57 57 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 58 58 59 60 59 def _onEVT_SLICER_PARS(self, event): 61 60 """ … … 66 65 67 66 """ 68 wx.PostEvent(self.base.parent, StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 67 wx.PostEvent(self.base.parent, 68 StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 69 69 event.Skip() 70 70 if event.type == self.__class__.__name__: … … 99 99 """ 100 100 # Update locations 101 ## Check if the middle line was dragged and update the picture accordingly 101 ## Check if the middle line was dragged and 102 #update the picture accordingly 102 103 if self.main_line.has_move: 103 104 self.main_line.update() 104 self.right_line.update( delta=-self.left_line.phi/2,105 mline= self.main_line.theta)106 self.left_line.update( delta =self.left_line.phi/2,107 mline= self.main_line.theta)105 self.right_line.update(delta=-self.left_line.phi/2, 106 mline=self.main_line.theta) 107 self.left_line.update(delta=self.left_line.phi/2, 108 mline=self.main_line.theta) 108 109 ## Check if the left side has moved and update the slicer accordingly 109 110 if self.left_line.has_move: 110 111 self.main_line.update() 111 self.left_line.update( phi=None, delta=None, mline=self.main_line , 112 side=True, left=True ) 113 self.right_line.update( phi= self.left_line.phi, delta= None, 114 mline= self.main_line, side= True, 115 left=False, right= True ) 116 ## Check if the right side line has moved and update the slicer accordingly 112 self.left_line.update(phi=None, delta=None, mline=self.main_line, 113 side=True, left=True) 114 self.right_line.update(phi=self.left_line.phi, delta=None, 115 mline=self.main_line, side=True, 116 left=False, right=True) 117 ## Check if the right side line has moved and 118 #update the slicer accordingly 117 119 if self.right_line.has_move: 118 120 self.main_line.update() 119 self.right_line.update( 120 side=True, left=False, right=True 121 self.left_line.update( 122 mline=self.main_line, side=True, left=False 121 self.right_line.update(phi=None, delta=None, mline=self.main_line, 122 side=True, left=False, right=True) 123 self.left_line.update(phi=self.right_line.phi, delta=None, 124 mline=self.main_line, side=True, left=False) 123 125 124 126 def save(self, ev): … … 148 150 phimin = -self.left_line.phi + self.main_line.theta 149 151 phimax = self.left_line.phi + self.main_line.theta 150 151 if nbins==None: 152 if nbins == None: 152 153 nbins = 20 153 sect = SectorQ(r_min= 0.0, r_max= radius,154 phi_min= 155 phi_max= 154 sect = SectorQ(r_min=0.0, r_max=radius, 155 phi_min=phimin + math.pi, 156 phi_max=phimax + math.pi, nbins=nbins) 156 157 157 158 sector = sect(self.base.data2D) 158 159 ##Create 1D data resulting from average 159 160 160 if hasattr(sector, "dxl"):161 dxl = sector.dxl161 if hasattr(sector, "dxl"): 162 dxl = sector.dxl 162 163 else: 163 dxl = None164 if hasattr(sector, "dxw"):165 dxw = sector.dxw164 dxl = None 165 if hasattr(sector, "dxw"): 166 dxw = sector.dxw 166 167 else: 167 dxw= None 168 169 new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy) 168 dxw = None 169 new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy) 170 170 new_plot.dxl = dxl 171 171 new_plot.dxw = dxw 172 new_plot.name = "SectorQ" +"("+ self.base.data2D.name+")" 173 174 new_plot.source=self.base.data2D.source 172 new_plot.name = "SectorQ" + "(" + self.base.data2D.name + ")" 173 new_plot.source = self.base.data2D.source 175 174 #new_plot.info=self.base.data2D.info 176 175 new_plot.interactive = True 177 new_plot.detector = self.base.data2D.detector176 new_plot.detector = self.base.data2D.detector 178 177 # If the data file does not tell us what the axes are, just assume... 179 178 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 180 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")181 new_plot.group_id = "SectorQ" +self.base.data2D.name182 new_plot.id = "SectorQ" +self.base.data2D.name183 new_plot.is_data = True179 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 180 new_plot.group_id = "SectorQ" + self.base.data2D.name 181 new_plot.id = "SectorQ" + self.base.data2D.name 182 new_plot.is_data = True 184 183 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 185 title="SectorQ" +self.base.data2D.name))184 title="SectorQ" + self.base.data2D.name)) 186 185 187 186 def moveend(self, ev): … … 227 226 ## angle of the middle line 228 227 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 229 raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi) 230 228 msg = "Phi left and phi right are different" 229 msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 230 raise ValueError, msg 231 231 params["Phi"] = self.main_line.theta 232 232 params["Delta_Phi"] = math.fabs(self.left_line.phi) … … 243 243 """ 244 244 main = params["Phi"] 245 phi = math.fabs(params["Delta_Phi"] 245 phi = math.fabs(params["Delta_Phi"]) 246 246 self.nbins = int(params["nbins"]) 247 self.main_line.theta = main247 self.main_line.theta = main 248 248 ## Reset the slicer parameters 249 249 self.main_line.update() 250 self.right_line.update( phi=phi,delta=None, mline=self.main_line, 251 side=True, right=True ) 252 self.left_line.update( phi=phi, delta=None, mline=self.main_line, side=True ) 250 self.right_line.update(phi=phi, delta=None, mline=self.main_line, 251 side=True, right=True) 252 self.left_line.update(phi=phi, delta=None, 253 mline=self.main_line, side=True) 253 254 ## post the new corresponding data 254 255 self._post_data(nbins=self.nbins) … … 278 279 279 280 """ 280 def __init__(self,base,axes,color='black', zorder=5, r=1.0,phi=math.pi/4, theta2= math.pi/3): 281 281 def __init__(self, base, axes, color='black', zorder=5, r=1.0, 282 phi=math.pi/4, theta2= math.pi/3): 283 """ 284 """ 282 285 _BaseInteractor.__init__(self, base, axes, color=color) 283 286 ## Initialize the class … … 287 290 ## the x-axis 288 291 self.save_theta = theta2 + phi 289 self.theta = theta2 + phi292 self.theta = theta2 + phi 290 293 ## the value of the middle line angle with respect to the x-axis 291 294 self.theta2 = theta2 … … 294 297 ## phi is the phase between the current line and the middle line 295 298 self.phi = phi 296 297 299 ## End points polar coordinates 298 x1 = self.radius*math.cos(self.theta)299 y1 = self.radius*math.sin(self.theta)300 x2 = -1*self.radius*math.cos(self.theta)301 y2 = -1*self.radius*math.sin(self.theta)300 x1 = self.radius * math.cos(self.theta) 301 y1 = self.radius * math.sin(self.theta) 302 x2 = -1 * self.radius * math.cos(self.theta) 303 y2 = -1 * self.radius * math.sin(self.theta) 302 304 ## defining a new marker 303 305 try: 304 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',306 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 305 307 marker='s', markersize=10, 306 308 color=self.color, alpha=0.6, 307 309 pickradius=5, label="pick", 308 zorder=zorder,# Prefer this to other lines309 visible=True)[0]310 # Prefer this to other lines 311 zorder=zorder, visible=True)[0] 310 312 except: 311 313 self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 312 314 marker='s', markersize=10, 313 315 color=self.color, alpha=0.6, 314 label="pick", 315 visible=True)[0] 316 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 317 message += "Get the SVN version that is at least as recent as June 1, 2007" 318 owner=self.base.base.parent 319 wx.PostEvent(owner, StatusEvent(status="sectorSlicer: %s"%message)) 316 label="pick", visible=True)[0] 317 message = "\nTHIS PROTOTYPE NEEDS THE LATEST" 318 message += " VERSION OF MATPLOTLIB\n Get the SVN version that" 319 message += " is at least as recent as June 1, 2007" 320 owner = self.base.base.parent 321 wx.PostEvent(owner, 322 StatusEvent(status="sectorSlicer: %s" % message)) 320 323 321 324 ## Defining the current line 322 self.line = self.axes.plot([x1, x2],[y1,y2],325 self.line = self.axes.plot([x1, x2], [y1, y2], 323 326 linestyle='-', marker='', 324 color=self.color, 325 visible=True)[0] 327 color=self.color, visible=True)[0] 326 328 ## Flag to differentiate the left line from the right line motion 327 self.left_moving =False329 self.left_moving = False 328 330 ## Flag to define a motion 329 self.has_move =False331 self.has_move = False 330 332 ## connecting markers and draw the picture 331 333 self.connect_markers([self.inner_marker, self.line]) … … 364 366 """ 365 367 #print "update left or right ", self.has_move 366 self.left_moving =left367 theta3 =0368 if phi != None:369 self.phi = phi370 if delta ==None:368 self.left_moving = left 369 theta3 = 0 370 if phi != None: 371 self.phi = phi 372 if delta == None: 371 373 delta = 0 372 374 if right: 373 self.phi = -1 *math.fabs(self.phi)375 self.phi = -1 * math.fabs(self.phi) 374 376 #delta=-delta 375 377 else: 376 self.phi = math.fabs(self.phi)378 self.phi = math.fabs(self.phi) 377 379 if side: 378 self.theta =mline.theta + self.phi380 self.theta = mline.theta + self.phi 379 381 380 if mline !=None :381 if delta !=0:382 self.theta2 = mline +delta382 if mline != None : 383 if delta != 0: 384 self.theta2 = mline + delta 383 385 else: 384 386 self.theta2 = mline.theta 385 if delta ==0:386 theta3 =self.theta+delta387 if delta == 0: 388 theta3 = self.theta + delta 387 389 else: 388 theta3=self.theta2+delta 389 390 x1= self.radius*math.cos(theta3) 391 y1= self.radius*math.sin(theta3) 392 x2= -1*self.radius*math.cos(theta3) 393 y2= -1*self.radius*math.sin(theta3) 394 395 self.inner_marker.set(xdata=[x1/2.5],ydata=[y1/2.5]) 396 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 390 theta3 = self.theta2 + delta 391 x1 = self.radius * math.cos(theta3) 392 y1 = self.radius * math.sin(theta3) 393 x2 = -1 * self.radius * math.cos(theta3) 394 y2 = -1 * self.radius * math.sin(theta3) 395 self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5]) 396 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 397 397 398 398 def save(self, ev): … … 401 401 can restore on Esc. 402 402 """ 403 self.save_theta = self.theta403 self.save_theta = self.theta 404 404 self.base.freeze_axes() 405 405 … … 407 407 """ 408 408 """ 409 self.has_move =False409 self.has_move = False 410 410 self.base.moveend(ev) 411 411 … … 420 420 Process move to a new position, making sure that the move is allowed. 421 421 """ 422 self.theta = math.atan2(y,x)423 self.has_move =True422 self.theta = math.atan2(y, x) 423 self.has_move = True 424 424 #ToDo: Simplify below 425 425 if not self.left_moving: 426 if self.theta2-self.theta <= 0 and self.theta2>0:#>= self.theta2: 426 if self.theta2 - self.theta <= 0 and self.theta2 > 0: 427 self.restore() 428 return 429 elif self.theta2 < 0 and self.theta < 0 and \ 430 self.theta-self.theta2 >= 0: 431 self.restore() 432 return 433 elif self.theta2 < 0 and self.theta > 0 and \ 434 (self.theta2 + 2 * math.pi - self.theta) >= math.pi/2: 427 435 #print "my theta", self.theta 428 436 self.restore() 429 437 return 430 elif self.theta2 < 0 and self.theta < 0 and self.theta-self.theta2 >= 0: 431 self.restore() 432 return 433 elif self.theta2 < 0 and self.theta > 0 and self.theta2+2*math.pi-self.theta >=math.pi/2: 438 elif self.theta2 < 0 and self.theta < 0 and \ 439 (self.theta2 - self.theta) >= math.pi/2: 434 440 #print "my theta", self.theta 435 441 self.restore() 436 442 return 437 elif self.theta2 < 0 and self.theta < 0 and self.theta2-self.theta >=math.pi/2: 438 #print "my theta", self.theta 439 self.restore() 440 return 441 elif self.theta2>0 and (self.theta2-self.theta >= math.pi/2 or (self.theta2-self.theta >= math.pi/2)):#<= self.theta2 -math.pi/2: 443 elif self.theta2 > 0 and (self.theta2-self.theta >= math.pi/2 or \ 444 (self.theta2-self.theta >= math.pi/2)): 442 445 #print "self theta encore" 443 446 self.restore() … … 445 448 else: 446 449 #print "left move" 447 if self.theta < 0 and self.theta+math.pi*2-self.theta2<= 0:450 if self.theta < 0 and (self.theta + math.pi*2-self.theta2) <= 0: 448 451 self.restore() 449 452 return 450 elif self.theta2 < 0 and self.theta-self.theta2<= 0:453 elif self.theta2 < 0 and (self.theta-self.theta2) <= 0: 451 454 self.restore() 452 455 return 453 elif self.theta > 0 and self.theta-self.theta2 <= 0:456 elif self.theta > 0 and self.theta-self.theta2 <= 0: 454 457 #print "my theta", self.theta 455 458 self.restore() 456 459 return 457 elif self.theta-self.theta2 >= math.pi/2 or (self.theta+math.pi*2-self.theta2 >= math.pi/2 and self.theta<0 and self.theta2>0): 460 elif self.theta-self.theta2 >= math.pi/2 or \ 461 ((self.theta + math.pi * 2 - self.theta2) >= math.pi/2 and \ 462 self.theta < 0 and self.theta2 > 0): 458 463 #print "self theta encore" 459 464 self.restore() 460 465 return 461 466 462 self.phi= math.fabs(self.theta2 - self.theta) 463 if self.phi>math.pi: 464 self.phi= 2*math.pi-math.fabs(self.theta2 - self.theta) 465 467 self.phi = math.fabs(self.theta2 - self.theta) 468 if self.phi > math.pi: 469 self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta) 466 470 self.base.base.update() 467 471 … … 491 495 Select an annulus through a 2D plot 492 496 """ 493 def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta=math.pi/4): 497 def __init__(self, base, axes, color='black', 498 zorder=5, r=1.0, theta=math.pi/4): 494 499 """ 495 500 """ … … 503 508 self.scale = 10.0 504 509 # Inner circle 505 x1 = self.radius*math.cos(self.theta)506 y1 = self.radius*math.sin(self.theta)507 x2 = -1*self.radius*math.cos(self.theta)508 y2 = -1*self.radius*math.sin(self.theta)510 x1 = self.radius * math.cos(self.theta) 511 y1 = self.radius * math.sin(self.theta) 512 x2 = -1*self.radius * math.cos(self.theta) 513 y2 = -1*self.radius * math.sin(self.theta) 509 514 try: 510 515 # Inner circle marker 511 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',516 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 512 517 marker='s', markersize=10, 513 518 color=self.color, alpha=0.6, 514 519 pickradius=5, label="pick", 515 zorder=zorder, # Prefer this to other lines 520 # Prefer this to other lines 521 zorder=zorder, 516 522 visible=True)[0] 517 523 except: 518 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='',524 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 519 525 marker='s', markersize=10, 520 526 color=self.color, alpha=0.6, 521 527 label="pick", 522 528 visible=True)[0] 523 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"524 message += " Get the SVN version that is at least as recent as June 1, 2007"525 526 self.line = self.axes.plot([x1, x2],[y1,y2],529 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 530 message += " OF MATPLOTLIB\n Get the SVN version that is at" 531 message += " least as recent as June 1, 2007" 532 self.line = self.axes.plot([x1, x2], [y1, y2], 527 533 linestyle='-', marker='', 528 color=self.color, 529 visible=True)[0] 534 color=self.color, visible=True)[0] 530 535 self.npts = 20 531 self.has_move =False536 self.has_move = False 532 537 self.connect_markers([self.inner_marker, self.line]) 533 538 self.update() … … 556 561 """ 557 562 558 if theta != None:559 self.theta = theta560 x1 = self.radius*math.cos(self.theta)561 y1 = self.radius*math.sin(self.theta)562 x2 = -1*self.radius*math.cos(self.theta)563 y2 = -1*self.radius*math.sin(self.theta)564 565 self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5])566 self.line.set(xdata=[x1, x2], ydata=[y1,y2])563 if theta != None: 564 self.theta = theta 565 x1 = self.radius * math.cos(self.theta) 566 y1 = self.radius * math.sin(self.theta) 567 x2 = -1 * self.radius * math.cos(self.theta) 568 y2 = -1 * self.radius * math.sin(self.theta) 569 570 self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5]) 571 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 567 572 568 573 def save(self, ev): … … 577 582 """ 578 583 """ 579 self.has_move =False584 self.has_move = False 580 585 self.base.moveend(ev) 581 586 … … 590 595 Process move to a new position, making sure that the move is allowed. 591 596 """ 592 self.theta = math.atan2(y,x)593 self.has_move =True597 self.theta = math.atan2(y, x) 598 self.has_move = True 594 599 self.base.base.update() 595 600 -
guiframe/local_perspectives/plotting/SlicerParameters.py
rd955bf19 r32c0841 3 3 import wx 4 4 import wx.lib.newevent 5 from copy import deepcopy 5 #from copy import deepcopy 6 from sans.guicomm.events import EVT_SLICER_PARS 7 from sans.guiframe.utils import format_number 8 from sans.guicomm.events import EVT_SLICER 9 from sans.guicomm.events import SlicerParameterEvent 6 10 7 from sans.guiframe.utils import format_number8 from sans.guicomm.events import EVT_SLICER,EVT_SLICER_PARS,SlicerParameterEvent9 11 10 12 class SlicerParameterPanel(wx.Dialog): … … 26 28 self.listeners = [] 27 29 self.parameters = [] 28 self.bck = wx.GridBagSizer(5, 5)30 self.bck = wx.GridBagSizer(5, 5) 29 31 self.SetSizer(self.bck) 30 31 title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)32 self.bck.Add(title, (0, 0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)33 32 label = "Right-click on 2D plot for slicer options" 33 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 34 self.bck.Add(title, (0, 0), (1, 2), 35 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 34 36 # Bindings 35 37 self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) … … 44 46 """ 45 47 event.Skip() 46 if event.obj_class ==None:48 if event.obj_class == None: 47 49 self.set_slicer(None, None) 48 50 else: … … 55 57 self.bck.Clear(True) 56 58 self.type = type 57 58 if type==None:59 title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT)60 self.bck.Add(title, (0, 0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)61 59 if type == None: 60 label = "Right-click on 2D plot for slicer options" 61 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 62 self.bck.Add(title, (0, 0), (1, 2), 63 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 62 64 else: 63 title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT) 64 self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 65 title = wx.StaticText(self, -1, 66 "Slicer Parameters", style=wx.ALIGN_LEFT) 67 self.bck.Add(title, (0, 0), (1, 2), 68 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 65 69 ix = 0 66 70 iy = 0 … … 68 72 keys = params.keys() 69 73 keys.sort() 70 71 74 for item in keys: 72 75 iy += 1 73 76 ix = 0 74 if not item in ["count","errors"]: 75 77 if not item in ["count", "errors"]: 76 78 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 77 self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 78 ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 79 80 ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 81 79 self.bck.Add(text, (iy, ix), (1, 1), 80 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 81 ctl = wx.TextCtrl(self, -1, size=(80, 20), 82 style=wx.TE_PROCESS_ENTER) 83 hint_msg = "Modify the value of %s to change" 84 hint_msg += " the 2D slicer" % item 85 ctl.SetToolTipString(hint_msg) 82 86 ix = 1 83 87 ctl.SetValue(format_number(str(params[item]))) … … 85 89 ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 86 90 self.parameters.append([item, ctl]) 87 self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 88 89 ix =3 90 self.bck.Add((20,20), (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 91 self.bck.Add(ctl, (iy, ix), (1, 1), 92 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 93 ix = 3 94 self.bck.Add((20, 20), (iy, ix), (1, 1), 95 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 91 96 else: 92 text = wx.StaticText(self, -1, item+ " : ", style=wx.ALIGN_LEFT) 93 self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 94 ctl =wx.StaticText(self, -1, format_number(str(params[item])), style=wx.ALIGN_LEFT) 95 ix =1 96 self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 97 iy +=1 97 text = wx.StaticText(self, -1, item + " : ", 98 style=wx.ALIGN_LEFT) 99 self.bck.Add(text, (iy, ix), (1, 1), 100 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 101 ctl = wx.StaticText(self, -1, 102 format_number(str(params[item])), 103 style=wx.ALIGN_LEFT) 104 ix = 1 105 self.bck.Add(ctl, (iy, ix), (1, 1), 106 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 107 iy += 1 98 108 ix = 1 99 self.bck.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 109 self.bck.Add((20, 20), (iy, ix), (1, 1), 110 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 100 111 self.bck.Layout() 101 112 self.bck.Fit(self) … … 111 122 for item in self.parameters: 112 123 if item[0] in evt.params: 113 item[1].SetValue("%-5.3g" % evt.params[item[0]])124 item[1].SetValue("%-5.3g" % evt.params[item[0]]) 114 125 item[1].Refresh() 115 126 … … 131 142 item[1].Refresh() 132 143 133 if has_error ==False:144 if has_error == False: 134 145 # Post parameter event 135 146 ##parent hier is plotter2D -
guiframe/local_perspectives/plotting/binder.py
r83f4445 r32c0841 10 10 # TODO: without imposing structure on prop. 11 11 12 artist=None 13 prop={} 14 def __init__(self,artist=None,prop={}): 15 self.artist,self.prop = artist,self.prop 16 def __eq__(self,other): 12 artist = None 13 prop = {} 14 def __init__(self, artist=None, prop={}): 15 self.artist, self.prop = artist, self.prop 16 17 def __eq__(self, other): 17 18 return self.artist is other.artist 18 def __ne__(self,other): 19 20 def __ne__(self, other): 19 21 return self.artist is not other.artist 22 20 23 def __nonzero__(self): 21 24 return self.artist is not None … … 28 31 # TODO: is no way to recognized whether shift is held down when the mouse 29 32 # TODO: first clicks on the the application window. 30 control, shift,alt,meta=False,False,False,False33 control, shift, alt, meta = False, False, False, False 31 34 32 35 # Track doubleclick … … 35 38 36 39 # Mouse/keyboard events we can bind to 37 events = ['enter','leave','motion','click','dclick','drag','release',38 'scroll', 'key','keyup']40 events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 41 'scroll', 'key', 'keyup'] 39 42 # TODO: Need our own event structure 40 41 def __init__(self,figure): 43 def __init__(self, figure): 42 44 canvas = figure.canvas 43 44 45 # Link to keyboard/mouse 45 46 try: 46 47 self._connections = [ 47 canvas.mpl_connect('motion_notify_event', self._onMotion),48 canvas.mpl_connect('button_press_event', self._onClick),49 canvas.mpl_connect('button_release_event', self._onRelease),50 canvas.mpl_connect('key_press_event', self._onKey),51 canvas.mpl_connect('key_release_event', self._onKeyRelease),52 canvas.mpl_connect('scroll_event', self._onScroll)48 canvas.mpl_connect('motion_notify_event', self._onMotion), 49 canvas.mpl_connect('button_press_event', self._onClick), 50 canvas.mpl_connect('button_release_event', self._onRelease), 51 canvas.mpl_connect('key_press_event', self._onKey), 52 canvas.mpl_connect('key_release_event', self._onKeyRelease), 53 canvas.mpl_connect('scroll_event', self._onScroll) 53 54 ] 54 55 except: 55 print "bypassing scroll_event: wrong matplotlib version"56 #print "bypassing scroll_event: wrong matplotlib version" 56 57 self._connections = [ 57 canvas.mpl_connect('motion_notify_event', self._onMotion),58 canvas.mpl_connect('button_press_event', self._onClick),59 canvas.mpl_connect('button_release_event', self._onRelease),60 canvas.mpl_connect('key_press_event', self._onKey),61 canvas.mpl_connect('key_release_event', self._onKeyRelease),58 canvas.mpl_connect('motion_notify_event', self._onMotion), 59 canvas.mpl_connect('button_press_event', self._onClick), 60 canvas.mpl_connect('button_release_event', self._onRelease), 61 canvas.mpl_connect('key_press_event', self._onKey), 62 canvas.mpl_connect('key_release_event', self._onKeyRelease), 62 63 ] 63 64 65 64 # Turn off picker if it hasn't already been done 66 65 try: … … 69 68 except: 70 69 pass 71 72 70 self.canvas = canvas 73 71 self.figure = figure … … 82 80 83 81 """ 84 85 82 for h in artists: 86 83 for a in self.events: 87 if h in self._actions[a]: del self._actions[a][h] 88 if h in self._artists: self._artists.remove(h) 89 if self._current.artist in artists: self._current = Selection() 90 if self._hasclick.artist in artists: self._hasclick = Selection() 91 if self._haskey.artist in artists: self._haskey = Selection() 84 if h in self._actions[a]: 85 del self._actions[a][h] 86 if h in self._artists: 87 self._artists.remove(h) 88 if self._current.artist in artists: 89 self._current = Selection() 90 if self._hasclick.artist in artists: 91 self._hasclick = Selection() 92 if self._haskey.artist in artists: 93 self._haskey = Selection() 92 94 93 95 def clearall(self): … … 101 103 for action in self.events: 102 104 self._actions[action] = {} 103 104 105 # Need activity state 105 106 self._artists = [] … … 113 114 """ 114 115 try: 115 for cid in self._connections: self.canvas.mpl_disconnect(cid) 116 for cid in self._connections: 117 self.canvas.mpl_disconnect(cid) 116 118 except: 117 119 pass … … 121 123 self.disconnect() 122 124 123 def __call__(self, trigger,artist,action):125 def __call__(self, trigger, artist, action): 124 126 """Register a callback for an artist to a particular trigger event. 125 127 … … 173 175 :TODO: Attach multiple callbacks to the same event? 174 176 :TODO: Clean up interaction with toolbar modes 175 :TODO: push/pushclear/pop context so that binding changes for the duration 177 :TODO: push/pushclear/pop context so that binding changes 178 for the duration 176 179 :TODO: e.g., to support ? context sensitive help 177 180 … … 179 182 # Check that the trigger is valid 180 183 if trigger not in self._actions: 181 raise ValueError,"%s invalid --- valid triggers are %s"\ 182 %(trigger,", ".join(self.events)) 183 184 raise ValueError, "%s invalid --- valid triggers are %s" \ 185 % (trigger, ", ".join(self.events)) 184 186 # Register the trigger callback 185 self._actions[trigger][artist] =action186 #print "==> added",artist,[artist],"to",trigger,":", self._actions[trigger].keys()187 187 self._actions[trigger][artist] = action 188 #print "==> added",artist,[artist],"to",trigger,":", 189 #self._actions[trigger].keys() 188 190 # Maintain a list of all artists 189 191 if artist not in self._artists: 190 192 self._artists.append(artist) 191 193 192 def trigger(self, actor,action,ev):194 def trigger(self, actor, action, ev): 193 195 """ 194 196 Trigger a particular event for the artist. Fallback to axes, … … 196 198 """ 197 199 if action not in self.events: 198 raise ValueError, "Trigger expects "+", ".join(self.events) 199 200 raise ValueError, "Trigger expects " + ", ".join(self.events) 200 201 # Tag the event with modifiers 201 for mod in ('alt','control','shift','meta'): 202 setattr(ev,mod,getattr(self,mod)) 203 setattr(ev,'artist',None) 204 setattr(ev,'action',action) 205 setattr(ev,'prop',{}) 206 207 # Fallback scheme. If the event does not return false, pass to parent. 202 for mod in ('alt', 'control', 'shift', 'meta'): 203 setattr(ev, mod, getattr(self, mod)) 204 setattr(ev, 'artist', None) 205 setattr(ev, 'action', action) 206 setattr(ev, 'prop', {}) 207 # Fallback scheme. If the event does not return false, pass to parent. 208 208 processed = False 209 artist, prop = actor.artist,actor.prop209 artist, prop = actor.artist, actor.prop 210 210 if artist in self._actions[action]: 211 ev.artist, ev.prop = artist,prop211 ev.artist, ev.prop = artist, prop 212 212 processed = self._actions[action][artist](ev) 213 213 if not processed and ev.inaxes in self._actions[action]: 214 ev.artist, ev.prop = ev.inaxes,{}214 ev.artist, ev.prop = ev.inaxes, {} 215 215 processed = self._actions[action][ev.inaxes](ev) 216 216 if not processed and self.figure in self._actions[action]: 217 ev.artist, ev.prop = self.figure,{}217 ev.artist, ev.prop = self.figure, {} 218 218 processed = self._actions[action][self.figure](ev) 219 219 if not processed and 'all' in self._actions[action]: 220 ev.artist, ev.prop = None,{}220 ev.artist, ev.prop = None, {} 221 221 processed = self._actions[action]['all'](ev) 222 222 return processed … … 228 228 """ 229 229 # TODO: sort by zorder of axes then by zorder within axes 230 self._artists.sort(cmp=lambda x, y: cmp(y.zorder,x.zorder))230 self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 231 231 # print "search"," ".join([str(h) for h in self._artists]) 232 232 found = Selection() … … 243 243 inside = False 244 244 if inside: 245 found.artist, found.prop = artist,prop245 found.artist, found.prop = artist, prop 246 246 break 247 247 #print "found",found.artist … … 249 249 # TODO: how to check if prop is equal? 250 250 if found != self._current: 251 self.trigger(self._current, 'leave',event)252 self.trigger(found, 'enter',event)251 self.trigger(self._current, 'leave', event) 252 self.trigger(found, 'enter', event) 253 253 self._current = found 254 255 254 return found 256 255 257 def _onMotion(self, event):256 def _onMotion(self, event): 258 257 """ 259 258 Track enter/leave/motion through registered artists; all … … 271 270 transform = self._hasclick.artist.get_transform() 272 271 #x,y = event.xdata,event.ydata 273 x, y = event.x,event.y272 x, y = event.x, event.y 274 273 try: 275 x, y = transform.inverted().transform_point((x, y))274 x, y = transform.inverted().transform_point((x, y)) 276 275 277 276 except: 278 x, y = transform.inverse_xy_tup((x,y))279 event.xdata, event.ydata = x,y280 self.trigger(self._hasclick, 'drag',event)277 x, y = transform.inverse_xy_tup((x, y)) 278 event.xdata, event.ydata = x, y 279 self.trigger(self._hasclick, 'drag', event) 281 280 else: 282 281 found = self._find_current(event) 283 282 #print "found",found.artist 284 self.trigger(found, 'motion',event)285 286 def _onClick(self, event):283 self.trigger(found, 'motion', event) 284 285 def _onClick(self, event): 287 286 """ 288 287 Process button click … … 322 321 # recommendation is that users should define click if they have 323 322 # drag or release on the artist. 324 self.trigger(found, action,event)323 self.trigger(found, action, event) 325 324 self._hasclick = found 326 325 327 def _onDClick(self, event):326 def _onDClick(self, event): 328 327 """ 329 328 Process button double click … … 338 337 else: 339 338 found = self._find_current(event) 340 self.trigger(found, 'dclick',event)339 self.trigger(found, 'dclick', event) 341 340 self._hasclick = found 342 341 343 def _onRelease(self, event):342 def _onRelease(self, event): 344 343 """ 345 344 Process release release 346 345 """ 347 self.trigger(self._hasclick, 'release',event)346 self.trigger(self._hasclick, 'release', event) 348 347 self._hasclick = Selection() 349 348 350 def _onKey(self, event):349 def _onKey(self, event): 351 350 """ 352 351 Process key click … … 359 358 # TODO: architecture a la Tk? 360 359 # TODO: Do modifiers cause a grab? Does the artist see the modifiers? 361 if event.key in ('alt', 'meta','control','shift'):362 setattr(self, event.key,True)360 if event.key in ('alt', 'meta', 'control', 'shift'): 361 setattr(self, event.key, True) 363 362 return 364 363 … … 367 366 else: 368 367 found = self._find_current(event) 369 self.trigger(found, 'key',event)368 self.trigger(found, 'key', event) 370 369 self._haskey = found 371 370 372 def _onKeyRelease(self, event):371 def _onKeyRelease(self, event): 373 372 """ 374 373 Process key release 375 374 """ 376 if event.key in ('alt', 'meta','control','shift'):377 setattr(self, event.key,False)375 if event.key in ('alt', 'meta', 'control', 'shift'): 376 setattr(self, event.key, False) 378 377 return 379 380 378 if self._haskey: 381 self.trigger(self._haskey, 'keyup',event)379 self.trigger(self._haskey, 'keyup', event) 382 380 self._haskey = Selection() 383 381 384 def _onScroll(self, event):382 def _onScroll(self, event): 385 383 """ 386 384 Process scroll event 387 385 """ 388 386 found = self._find_current(event) 389 self.trigger(found, 'scroll',event)390 387 self.trigger(found, 'scroll', event) 388 -
guiframe/local_perspectives/plotting/boxMask.py
r83f4445 r32c0841 3 3 4 4 import math 5 import wx6 from copy import deepcopy5 #import wx 6 #from copy import deepcopy 7 7 from BaseInteractor import _BaseInteractor 8 from boxSum import PointInteractor,VerticalDoubleLine,HorizontalDoubleLine 9 from sans.guicomm.events import SlicerParamUpdateEvent 8 from boxSum import PointInteractor 9 from boxSum import VerticalDoubleLine 10 from boxSum import HorizontalDoubleLine 11 #from sans.guicomm.events import SlicerParamUpdateEvent 10 12 11 13 … … 24 26 25 27 """ 26 def __init__(self, base,axes,color='black', zorder=3, side=None,28 def __init__(self, base, axes, color='black', zorder=3, side=None, 27 29 x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 28 30 """ 31 """ 29 32 _BaseInteractor.__init__(self, base, axes, color=color) 30 33 ## class initialization … … 35 38 ## connect the artist for the motion 36 39 self.connect = self.base.connect 37 ## when qmax is reached the selected line is reset the its previous value 40 ## when qmax is reached the selected line is reset 41 #the its previous value 38 42 self.qmax = min(self.base.data.xmax, self.base.data.xmin) 39 43 ## Define the box limits 40 self.xmin= -1* 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 41 self.ymin= -1* 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 42 43 self.xmax= 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 44 self.ymax= 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 44 self.xmin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 45 math.fabs(self.base.data.xmin)) 46 self.ymin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 47 math.fabs(self.base.data.xmin)) 48 self.xmax = 0.5 * min(math.fabs(self.base.data.xmax), 49 math.fabs(self.base.data.xmin)) 50 self.ymax = 0.5 * min(math.fabs(self.base.data.xmax), 51 math.fabs(self.base.data.xmin)) 45 52 ## center of the box 46 self.center_x = 0.000247 self.center_y = 0.000353 self.center_x = 0.0002 54 self.center_y = 0.0003 48 55 ## Number of points on the plot 49 56 self.nbins = 20 50 57 ## Define initial result the summation 51 self.count =052 self.error =058 self.count = 0 59 self.error = 0 53 60 self.data = self.base.data 54 61 ## Flag to determine if the current figure has moved 55 62 ## set to False == no motion , set to True== motion 56 self.has_move = False63 self.has_move = False 57 64 ## Create Box edges 58 self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue', 65 self.horizontal_lines = HorizontalDoubleLine(self, 66 self.base.subplot, 67 color='blue', 59 68 zorder=zorder, 60 y=self.ymax,61 x=self.xmax,62 center_x=self.center_x,63 center_y=self.center_y)69 y=self.ymax, 70 x=self.xmax, 71 center_x=self.center_x, 72 center_y=self.center_y) 64 73 self.horizontal_lines.qmax = self.qmax 65 74 66 self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='grey', 67 zorder=zorder, 68 y= self.ymax, 69 x= self.xmax, 70 center_x= self.center_x, 71 center_y= self.center_y) 75 self.vertical_lines = VerticalDoubleLine(self, 76 self.base.subplot, 77 color='grey', 78 zorder=zorder, 79 y=self.ymax, 80 x=self.xmax, 81 center_x=self.center_x, 82 center_y=self.center_y) 72 83 self.vertical_lines.qmax = self.qmax 73 84 74 self.center= PointInteractor(self, self.base.subplot,color='grey', 75 zorder=zorder, 76 center_x= self.center_x, 77 center_y= self.center_y) 85 self.center = PointInteractor(self, 86 self.base.subplot,color='grey', 87 zorder=zorder, 88 center_x=self.center_x, 89 center_y=self.center_y) 78 90 ## Save the name of the slicer panel associate with this slicer 79 self.panel_name =""91 self.panel_name = "" 80 92 ## Update and post slicer parameters 81 93 self.update() 82 94 self._post_data() 83 84 95 85 96 def clear(self): 86 97 """ … … 99 110 resetting the widgets. 100 111 """ 101 # #check if the center point has moved and update the figure accordingly112 # check if the center point has moved and update the figure accordingly 102 113 if self.center.has_move: 103 114 self.center.update() 104 self.horizontal_lines.update( center= self.center) 105 self.vertical_lines.update( center= self.center) 106 ## check if the horizontal lines have moved and update the figure accordingly 115 self.horizontal_lines.update(center=self.center) 116 self.vertical_lines.update(center=self.center) 117 ## check if the horizontal lines have moved and update 118 # the figure accordingly 107 119 if self.horizontal_lines.has_move: 108 120 self.horizontal_lines.update() 109 121 self.vertical_lines.update(y1=self.horizontal_lines.y1, 110 122 y2=self.horizontal_lines.y2, 111 height= self.horizontal_lines.half_height ) 112 ## check if the vertical lines have moved and update the figure accordingly 123 height=self.horizontal_lines.half_height) 124 ## check if the vertical lines have moved and update 125 # the figure accordingly 113 126 if self.vertical_lines.has_move: 114 127 self.vertical_lines.update() … … 140 153 mask = data.mask 141 154 ## the region of the summation 142 x_min = self.horizontal_lines.x2143 x_max = self.horizontal_lines.x1144 y_min = self.vertical_lines.y2145 y_max = self.vertical_lines.y1155 x_min = self.horizontal_lines.x2 156 x_max = self.horizontal_lines.x1 157 y_min = self.vertical_lines.y2 158 y_max = self.vertical_lines.y1 146 159 mask = Boxcut(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 147 160 148 161 if self.is_inside: 149 out = (mask(data) ==False)162 out = (mask(data) == False) 150 163 else: 151 164 out = (mask(data)) … … 187 200 """ 188 201 params = {} 189 params["Width"] = math.fabs(self.vertical_lines.half_width) *2190 params["Height"] = math.fabs(self.horizontal_lines.half_height) *2202 params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 203 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 191 204 params["center_x"] = self.center.x 192 params["center_y"] = self.center.y205 params["center_y"] = self.center.y 193 206 return params 194 207 … … 209 222 """ 210 223 x_max = math.fabs(params["Width"] )/2 211 y_max = math.fabs(params["Height"] 212 213 self.center_x =params["center_x"]214 self.center_y =params["center_y"]224 y_max = math.fabs(params["Height"])/2 225 226 self.center_x = params["center_x"] 227 self.center_y = params["center_y"] 215 228 #update the slicer given values of params 216 self.center.update(center_x=self.center_x, center_y=self.center_y)217 self.horizontal_lines.update(center= 229 self.center.update(center_x=self.center_x, center_y=self.center_y) 230 self.horizontal_lines.update(center=self.center, 218 231 width=x_max, 219 232 height=y_max) 220 self.vertical_lines.update(center= 233 self.vertical_lines.update(center=self.center, 221 234 width=x_max, 222 235 height=y_max) … … 230 243 self.base.thaw_axes() 231 244 232 233 245 def draw(self): 234 246 self.base.update() … … 236 248 class inner_BoxMask(BoxMask): 237 249 def __call__(self): 238 self.base.data.mask=(self._post_data()==False) 239 250 self.base.data.mask = (self._post_data()==False) 251 252 -
guiframe/local_perspectives/plotting/boxSlicer.py
rd955bf19 r32c0841 2 2 3 3 import wx 4 import copy5 from copy import deepcopy4 #import copy 5 #from copy import deepcopy 6 6 import math 7 7 import numpy 8 9 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 8 from sans.guicomm.events import NewPlotEvent 9 from sans.guicomm.events import StatusEvent 10 from sans.guicomm.events import SlicerParameterEvent 11 from sans.guicomm.events import EVT_SLICER_PARS 10 12 from BaseInteractor import _BaseInteractor 11 13 from sans.guiframe.dataFitting import Data1D 12 13 import SlicerParameters 14 #import SlicerParameters 14 15 15 16 … … 19 20 in a rectangle area defined by -x, x ,y, -y 20 21 """ 21 def __init__(self, base,axes,color='black', zorder=3):22 def __init__(self, base, axes, color='black', zorder=3): 22 23 _BaseInteractor.__init__(self, base, axes, color=color) 23 24 ## Class initialization … … 27 28 self.connect = self.base.connect 28 29 ## determine x y values 29 self.x= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 30 self.y= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 30 self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), 31 math.fabs(self.base.data2D.xmin)) 32 self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), 33 math.fabs(self.base.data2D.xmin)) 31 34 ## when reach qmax reset the graph 32 self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin,33 self.base.data2D.ymax, self.base.data2D.ymin)35 self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, 36 self.base.data2D.ymax, self.base.data2D.ymin) 34 37 ## Number of points on the plot 35 38 self.nbins = 30 36 ## If True, I(|Q|) will be return, otherwise, negative q-values are allowed 39 ## If True, I(|Q|) will be return, otherwise, 40 #negative q-values are allowed 37 41 self.fold = True 38 42 ## reference of the current Slab averaging 39 self.averager =None43 self.averager = None 40 44 ## Create vertical and horizaontal lines for the rectangle 41 self.vertical_lines = VerticalLines(self, self.base.subplot,color='blue', 42 zorder=zorder, 43 y= self.y , 44 x= self.x) 45 self.vertical_lines = VerticalLines(self, 46 self.base.subplot, 47 color='blue', 48 zorder=zorder, 49 y=self.y , 50 x=self.x) 45 51 self.vertical_lines.qmax = self.qmax 46 52 47 self.horizontal_lines= HorizontalLines(self, self.base.subplot,color='green', 48 zorder=zorder, 49 x= self.x, 50 y= self.y) 51 self.horizontal_lines.qmax= self.qmax 53 self.horizontal_lines = HorizontalLines(self, 54 self.base.subplot, 55 color='green', 56 zorder=zorder, 57 x=self.x, 58 y=self.y) 59 self.horizontal_lines.qmax = self.qmax 52 60 ## draw the rectangle and plost the data 1D resulting 53 61 ## of averaging data2D … … 57 65 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 58 66 59 60 67 def _onEVT_SLICER_PARS(self, event): 61 68 """ … … 65 72 attribute 66 73 """ 67 wx.PostEvent(self.base.parent, StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 74 wx.PostEvent(self.base.parent, 75 StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 68 76 event.Skip() 69 77 if event.type == self.__class__.__name__: 70 78 self.set_params(event.params) 71 79 self.base.update() 72 73 80 74 81 def update_and_post(self): 75 82 """ … … 93 100 Clear the slicer and all connected events related to this slicer 94 101 """ 95 self.averager =None102 self.averager = None 96 103 self.clear_markers() 97 104 self.horizontal_lines.clear() … … 100 107 self.base.Unbind(EVT_SLICER_PARS) 101 108 102 103 109 def update(self): 104 110 """ … … 110 116 self.horizontal_lines.update() 111 117 self.vertical_lines.update(y=self.horizontal_lines.y) 112 113 118 ##Update the slicer if a vertical line is dragged 114 119 if self.vertical_lines.has_move: … … 128 133 pass 129 134 130 def post_data(self, new_slab=None , nbins=None, direction=None):135 def post_data(self, new_slab=None, nbins=None, direction=None): 131 136 """ 132 137 post data averaging in Qx or Qy given new_slab type … … 137 142 138 143 """ 139 x_min = -1*math.fabs(self.vertical_lines.x)140 x_max = math.fabs(self.vertical_lines.x)141 142 y_m in= -1*math.fabs(self.horizontal_lines.y)143 y_max= math.fabs(self.horizontal_lines.y)144 145 if nbins !=None:146 self.nbins147 if self.averager==None:148 if new_slab ==None:149 raise ValueError, "post data:cannot average , averager is empty"150 self.averager = new_slab144 x_min = -1 * math.fabs(self.vertical_lines.x) 145 x_max = math.fabs(self.vertical_lines.x) 146 y_min = -1 * math.fabs(self.horizontal_lines.y) 147 y_max = math.fabs(self.horizontal_lines.y) 148 149 if nbins != None: 150 self.nbins = nbins 151 if self.averager == None: 152 if new_slab == None: 153 msg = "post data:cannot average , averager is empty" 154 raise ValueError, msg 155 self.averager = new_slab 151 156 if direction == "X": 152 if self.fold: x_low = 0 153 else: x_low = math.fabs(x_min) 154 bin_width= (x_max + x_low)/self.nbins 157 if self.fold: 158 x_low = 0 159 else: 160 x_low = math.fabs(x_min) 161 bin_width = (x_max + x_low)/self.nbins 155 162 else: 156 if self.fold: y_low = 0 157 else: y_low = math.fabs(y_min) 158 bin_width= (y_max + y_low)/self.nbins 163 if self.fold: 164 y_low = 0 165 else: 166 y_low = math.fabs(y_min) 167 bin_width = (y_max + y_low)/self.nbins 159 168 ## Average data2D given Qx or Qy 160 box = self.averager( 169 box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 161 170 bin_width=bin_width) 162 171 box.fold = self.fold 163 172 boxavg = box(self.base.data2D) 164 173 #3 Create Data1D to plot 165 166 if hasattr(boxavg,"dxl"): 167 dxl= boxavg.dxl 174 if hasattr(boxavg, "dxl"): 175 dxl = boxavg.dxl 168 176 else: 169 dxl = None170 if hasattr(boxavg, "dxw"):171 dxw =boxavg.dxw177 dxl = None 178 if hasattr(boxavg, "dxw"): 179 dxw = boxavg.dxw 172 180 else: 173 dxw= None 174 175 new_plot = Data1D(x=boxavg.x,y=boxavg.y,dy=boxavg.dy) 181 dxw = None 182 new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) 176 183 new_plot.dxl = dxl 177 184 new_plot.dxw = dxw 178 new_plot.name = str(self.averager.__name__) + "("+ self.base.data2D.name+")"179 180 new_plot.source =self.base.data2D.source185 new_plot.name = str(self.averager.__name__) + \ 186 "(" + self.base.data2D.name + ")" 187 new_plot.source = self.base.data2D.source 181 188 new_plot.interactive = True 182 new_plot.detector = self.base.data2D.detector189 new_plot.detector = self.base.data2D.detector 183 190 # If the data file does not tell us what the axes are, just assume... 184 191 new_plot.xaxis("\\rm{Q}", '\\AA^{-1}') 185 192 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 186 new_plot.group_id = str(self.averager.__name__) +self.base.data2D.name193 new_plot.group_id = str(self.averager.__name__) + self.base.data2D.name 187 194 new_plot.id = str(self.averager.__name__) 188 195 #new_plot.is_data= True 189 190 196 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 191 title=str(self.averager.__name__)))197 title=str(self.averager.__name__))) 192 198 193 199 def moveend(self, ev): … … 230 236 """ 231 237 params = {} 232 params["x_max"] = math.fabs(self.vertical_lines.x)233 params["y_max"] = math.fabs(self.horizontal_lines.y)234 params["nbins"] = self.nbins238 params["x_max"] = math.fabs(self.vertical_lines.x) 239 params["y_max"] = math.fabs(self.horizontal_lines.y) 240 params["nbins"] = self.nbins 235 241 return params 236 242 … … 245 251 self.x = float(math.fabs(params["x_max"])) 246 252 self.y = float(math.fabs(params["y_max"] )) 247 self.nbins =params["nbins"]248 249 self.horizontal_lines.update(x= self.x, y=self.y)250 self.vertical_lines.update(x= self.x, y=self.y)251 self.post_data( 253 self.nbins = params["nbins"] 254 255 self.horizontal_lines.update(x=self.x, y=self.y) 256 self.vertical_lines.update(x=self.x, y=self.y) 257 self.post_data(nbins=None) 252 258 253 259 def freeze_axes(self): … … 272 278 on the x- direction and in opposite direction 273 279 """ 274 def __init__(self,base,axes,color='black', zorder=5,x=0.5, y=0.5): 275 280 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5): 281 """ 282 """ 276 283 _BaseInteractor.__init__(self, base, axes, color=color) 277 284 ##Class initialization … … 279 286 self.axes = axes 280 287 ## Saving the end points of two lines 281 self.x = x282 self.save_x = x283 284 self.y = y285 self.save_y = y288 self.x = x 289 self.save_x = x 290 291 self.y = y 292 self.save_y = y 286 293 ## Creating a marker 287 294 try: 288 295 # Inner circle marker 289 self.inner_marker = self.axes.plot([0], [self.y], linestyle='',296 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 290 297 marker='s', markersize=10, 291 298 color=self.color, alpha=0.6, 292 299 pickradius=5, label="pick", 293 zorder=zorder, # Prefer this to other lines 300 # Prefer this to other lines 301 zorder=zorder, 294 302 visible=True)[0] 295 303 except: 296 self.inner_marker = self.axes.plot([0], [self.y], linestyle='',304 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 297 305 marker='s', markersize=10, 298 306 color=self.color, alpha=0.6, 299 label="pick", 300 visible=True)[0]301 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"302 message += " Get the SVN version thatis at least as recent as June 1, 2007"303 owner =self.base.base.parent304 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message))305 307 label="pick", visible=True)[0] 308 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 309 message += "OF MATPLOTLIB\n Get the SVN version that" 310 message += " is at least as recent as June 1, 2007" 311 owner = self.base.base.parent 312 wx.PostEvent(owner, 313 StatusEvent(status="AnnulusSlicer: %s" % message)) 306 314 ## Define 2 horizontal lines 307 self.top_line = self.axes.plot([self.x,-self.x], 308 [self.y,self.y], 315 self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 309 316 linestyle='-', marker='', 310 color=self.color, 311 visible=True)[0] 312 self.bottom_line = self.axes.plot([self.x,-self.x], 313 [-self.y,-self.y], 317 color=self.color, visible=True)[0] 318 self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], 314 319 linestyle='-', marker='', 315 color=self.color, 316 visible=True)[0] 320 color=self.color, visible=True)[0] 317 321 ## Flag to check the motion of the lines 318 self.has_move =False322 self.has_move = False 319 323 ## Connecting markers to mouse events and draw 320 324 self.connect_markers([self.top_line, self.inner_marker]) 321 325 self.update() 322 323 326 324 327 def set_layer(self, n): … … 346 349 del self.axes.lines[0] 347 350 348 def update(self, x=None,y=None):351 def update(self, x=None, y=None): 349 352 """ 350 353 Draw the new roughness on the graph. … … 355 358 """ 356 359 ## Reset x, y- coordinates if send as parameters 357 if x !=None:358 self.x = numpy.sign(self.x) *math.fabs(x)359 if y != None:360 self.y = numpy.sign(self.y) *math.fabs(y)360 if x != None: 361 self.x = numpy.sign(self.x) * math.fabs(x) 362 if y != None: 363 self.y = numpy.sign(self.y) * math.fabs(y) 361 364 ## Draw lines and markers 362 self.inner_marker.set(xdata=[0],ydata=[self.y]) 363 self.top_line.set(xdata=[self.x,-self.x], 364 ydata=[self.y,self.y]) 365 self.bottom_line.set(xdata=[self.x,-self.x], 366 ydata=[-self.y, -self.y]) 365 self.inner_marker.set(xdata=[0], ydata=[self.y]) 366 self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) 367 self.bottom_line.set(xdata=[self.x,-self.x], ydata=[-self.y, -self.y]) 367 368 368 369 def save(self, ev): … … 371 372 can restore on Esc. 372 373 """ 373 self.save_x = self.x374 self.save_y = self.y374 self.save_x = self.x 375 self.save_y = self.y 375 376 self.base.freeze_axes() 376 377 … … 380 381 to specify the end of dragging motion 381 382 """ 382 self.has_move =False383 self.has_move = False 383 384 self.base.moveend(ev) 384 385 … … 394 395 Process move to a new position, making sure that the move is allowed. 395 396 """ 396 self.y = y397 self.has_move =True397 self.y = y 398 self.has_move = True 398 399 self.base.base.update() 399 400 … … 403 404 Select an annulus through a 2D plot 404 405 """ 405 def __init__(self,base,axes,color='black',zorder=5,x=0.5, y=0.5): 406 406 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5): 407 """ 408 """ 407 409 _BaseInteractor.__init__(self, base, axes, color=color) 408 410 self.markers = [] 409 411 self.axes = axes 410 411 self.x= math.fabs(x) 412 self.save_x= self.x 413 self.y= math.fabs(y) 414 self.save_y= y 415 412 self.x = math.fabs(x) 413 self.save_x = self.x 414 self.y = math.fabs(y) 415 self.save_y = y 416 416 try: 417 417 # Inner circle marker 418 self.inner_marker = self.axes.plot([self.x], [0], linestyle='',418 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 419 419 marker='s', markersize=10, 420 420 color=self.color, alpha=0.6, 421 421 pickradius=5, label="pick", 422 zorder=zorder,# Prefer this to other lines423 visible=True)[0]422 # Prefer this to other lines 423 zorder=zorder, visible=True)[0] 424 424 except: 425 self.inner_marker = self.axes.plot([self.x], [0], linestyle='',425 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 426 426 marker='s', markersize=10, 427 427 color=self.color, alpha=0.6, 428 label="pick", 429 visible=True)[0]430 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n"431 message += " Get the SVN version that isat least as recent as June 1, 2007"428 label="pick", visible=True)[0] 429 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 430 message += " OF MATPLOTLIB\n Get the SVN version that is" 431 message += " at least as recent as June 1, 2007" 432 432 433 self.right_line = self.axes.plot([self.x,self.x],[self.y,-self.y], 433 self.right_line = self.axes.plot([self.x, self.x], 434 [self.y , -self.y], 434 435 linestyle='-', marker='', 435 color=self.color, 436 visible=True)[0]437 self.left_line = self.axes.plot([-self.x,-self.x],[self.y,-self.y],436 color=self.color, visible=True)[0] 437 self.left_line = self.axes.plot([-self.x, -self.x], 438 [self.y, -self.y], 438 439 linestyle='-', marker='', 439 color=self.color, 440 visible=True)[0] 441 442 self.has_move=False 440 color=self.color, visible=True)[0] 441 self.has_move = False 443 442 self.connect_markers([self.right_line, self.inner_marker]) 444 443 self.update() 445 446 444 447 445 def set_layer(self, n): … … 469 467 del self.axes.lines[0] 470 468 471 def update(self, x=None,y=None):469 def update(self, x=None, y=None): 472 470 """ 473 471 Draw the new roughness on the graph. … … 478 476 """ 479 477 ## reset x, y -coordinates if given as parameters 480 if x !=None:481 self.x = numpy.sign(self.x) *math.fabs(x)482 if y != None:483 self.y = numpy.sign(self.y) *math.fabs(y)478 if x != None: 479 self.x = numpy.sign(self.x) * math.fabs(x) 480 if y != None: 481 self.y = numpy.sign(self.y) * math.fabs(y) 484 482 ## draw lines and markers 485 self.inner_marker.set(xdata=[self.x],ydata=[0]) 486 self.left_line.set(xdata=[-self.x,-self.x], 487 ydata=[self.y,-self.y]) 488 self.right_line.set(xdata=[self.x,self.x], 489 ydata=[self.y,-self.y]) 483 self.inner_marker.set(xdata=[self.x], ydata=[0]) 484 self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 485 self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 490 486 491 487 def save(self, ev): … … 503 499 to specify the end of dragging motion 504 500 """ 505 self.has_move =False501 self.has_move = False 506 502 self.base.moveend(ev) 507 503 … … 517 513 Process move to a new position, making sure that the move is allowed. 518 514 """ 519 self.has_move =True520 self.x = x515 self.has_move = True 516 self.x = x 521 517 self.base.base.update() 522 518 … … 526 522 Average in Qx direction 527 523 """ 528 def __init__(self, base,axes,color='black', zorder=3):524 def __init__(self, base, axes, color='black', zorder=3): 529 525 BoxInteractor.__init__(self, base, axes, color=color) 530 self.base =base526 self.base = base 531 527 self._post_data() 532 528 533 534 529 def _post_data(self): 535 530 """ … … 537 532 """ 538 533 from DataLoader.manipulations import SlabX 539 self.post_data(SlabX, direction 534 self.post_data(SlabX, direction="X") 540 535 541 536 … … 544 539 Average in Qy direction 545 540 """ 546 def __init__(self, base,axes,color='black', zorder=3):541 def __init__(self, base, axes, color='black', zorder=3): 547 542 BoxInteractor.__init__(self, base, axes, color=color) 548 self.base =base543 self.base = base 549 544 self._post_data() 550 545 … … 554 549 """ 555 550 from DataLoader.manipulations import SlabY 556 self.post_data(SlabY, direction 557 558 551 self.post_data(SlabY, direction="Y") 552 553 -
guiframe/local_perspectives/plotting/boxSum.py
r6c0568b r32c0841 6 6 from copy import deepcopy 7 7 from BaseInteractor import _BaseInteractor 8 from sans.guicomm.events import SlicerParamUpdateEvent,EVT_SLICER_PARS,StatusEvent 8 from sans.guicomm.events import SlicerParamUpdateEvent 9 from sans.guicomm.events import EVT_SLICER_PARS 10 from sans.guicomm.events import StatusEvent 9 11 10 12 11 13 class BoxSum(_BaseInteractor): 12 14 """ 13 Boxsum Class: determine 2 rectangular area to compute the sum of pixel of14 a Data.15 Boxsum Class: determine 2 rectangular area to compute 16 the sum of pixel of a Data. 15 17 Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 16 18 @param zorder: Artists with lower zorder values are drawn first. … … 21 23 22 24 """ 23 def __init__(self, base,axes,color='black', zorder=3, x_min=0.008,25 def __init__(self, base, axes, color='black', zorder=3, x_min=0.008, 24 26 x_max=0.008, y_min=0.0025, y_max=0.0025): 25 27 """ 28 """ 26 29 _BaseInteractor.__init__(self, base, axes, color=color) 27 30 ## class initialization … … 34 37 self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 35 38 ## Define the boxsum limits 36 self.xmin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 37 self.ymin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 38 39 self.xmax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 40 self.ymax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 39 self.xmin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 40 math.fabs(self.base.data2D.xmin)) 41 self.ymin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 42 math.fabs( elf.base.data2D.xmin)) 43 self.xmax = 0.5 * min(math.fabs(self.base.data2D.xmax), 44 math.fabs(self.base.data2D.xmin)) 45 self.ymax = 0.5 * min(math.fabs(self.base.data2D.xmax), 46 math.fabs(self.base.data2D.xmin)) 41 47 ## center of the boxSum 42 self.center_x = 0.000243 self.center_y = 0.000348 self.center_x = 0.0002 49 self.center_y = 0.0003 44 50 ## Number of points on the plot 45 51 self.nbins = 20 46 52 ## Define initial result the summation 47 self.count =048 self.error =053 self.count = 0 54 self.error = 0 49 55 ## Flag to determine if the current figure has moved 50 56 ## set to False == no motion , set to True== motion 51 self.has_move = False57 self.has_move = False 52 58 ## Create Boxsum edges 53 self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue', 59 self.horizontal_lines= HorizontalDoubleLine(self, 60 self.base.subplot, 61 color='blue', 54 62 zorder=zorder, 55 y=self.ymax,56 x=self.xmax,57 center_x=self.center_x,58 center_y=self.center_y)63 y=self.ymax, 64 x=self.xmax, 65 center_x=self.center_x, 66 center_y=self.center_y) 59 67 self.horizontal_lines.qmax = self.qmax 60 68 61 self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='black', 62 zorder=zorder, 63 y= self.ymax, 64 x= self.xmax, 65 center_x= self.center_x, 66 center_y= self.center_y) 69 self.vertical_lines= VerticalDoubleLine(self, 70 self.base.subplot, 71 color='black', 72 zorder=zorder, 73 y=self.ymax, 74 x=self.xmax, 75 center_x=self.center_x, 76 center_y=self.center_y) 67 77 self.vertical_lines.qmax = self.qmax 68 78 69 self.center= PointInteractor(self, self.base.subplot,color='grey', 70 zorder=zorder, 79 self.center= PointInteractor(self, 80 self.base.subplot,color='grey', 81 zorder=zorder, 71 82 center_x= self.center_x, 72 83 center_y= self.center_y) 73 84 ## Save the name of the slicer panel associate with this slicer 74 self.panel_name =""85 self.panel_name = "" 75 86 ## Update and post slicer parameters 76 87 self.update() … … 79 90 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 80 91 81 82 92 def set_panel_name(self, name): 83 93 """ … … 85 95 @param name: the name of this panel 86 96 """ 87 self.panel_name= name 88 97 self.panel_name = name 89 98 90 99 def _onEVT_SLICER_PARS(self, event): … … 95 104 """ 96 105 ## Post e message to declare what kind of event has being received 97 wx.PostEvent(self.base.parent, StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 106 wx.PostEvent(self.base.parent, 107 StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 98 108 event.Skip() 99 109 ## reset the slicer with the values contains the event.params dictionary … … 102 112 self.base.update() 103 113 104 105 114 def set_layer(self, n): 106 115 """ 107 108 @param n: the number of layer116 Allow adding plot to the same panel 117 :param n: the number of layer 109 118 """ 110 119 self.layernum = n 111 120 self.update() 112 121 113 114 122 def clear(self): 115 123 """ 116 124 Clear the slicer and all connected events related to this slicer 117 125 """ 118 126 self.clear_markers() … … 123 131 self.base.Unbind(EVT_SLICER_PARS) 124 132 125 126 133 def update(self): 127 134 """ 128 129 135 Respond to changes in the model by recalculating the profiles and 136 resetting the widgets. 130 137 """ 131 138 ## check if the center point has moved and update the figure accordingly … … 134 141 self.horizontal_lines.update( center= self.center) 135 142 self.vertical_lines.update( center= self.center) 136 ## check if the horizontal lines have moved and update the figure accordingly 143 ## check if the horizontal lines have moved and 144 #update the figure accordingly 137 145 if self.horizontal_lines.has_move: 138 146 self.horizontal_lines.update() 139 147 self.vertical_lines.update(y1=self.horizontal_lines.y1, 140 148 y2=self.horizontal_lines.y2, 141 height= self.horizontal_lines.half_height ) 142 ## check if the vertical lines have moved and update the figure accordingly 149 height=self.horizontal_lines.half_height) 150 ## check if the vertical lines have moved and 151 #update the figure accordingly 143 152 if self.vertical_lines.has_move: 144 153 self.vertical_lines.update() … … 147 156 width=self.vertical_lines.half_width) 148 157 149 150 158 def save(self, ev): 151 159 """ … … 160 168 def _post_data(self): 161 169 """ 162 163 170 Get the limits of the boxsum and compute the sum of the pixel 171 contained in that region and the error on that sum 164 172 """ 165 173 ## Data 2D for which the pixel will be summed 166 174 data = self.base.data2D 167 175 ## the region of the summation 168 x_min = self.horizontal_lines.x2169 x_max = self.horizontal_lines.x1170 y_min = self.vertical_lines.y2171 y_max = self.vertical_lines.y1176 x_min = self.horizontal_lines.x2 177 x_max = self.horizontal_lines.x1 178 y_min = self.vertical_lines.y2 179 y_max = self.vertical_lines.y1 172 180 ##computation of the sum and its error 173 from DataLoader.manipulations import 174 box = Boxavg 181 from DataLoader.manipulations import Boxavg 182 box = Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 175 183 self.count, self.error = box(self.base.data2D) 176 177 184 178 185 def moveend(self, ev): 179 186 """ … … 186 193 ## Create and event ( posted to guiframe)that set the 187 194 ##current slicer parameter to a panel of name self.panel_name 188 self.type= self.__class__.__name__ 189 params= self.get_params() 190 event = SlicerParamUpdateEvent(type=self.type, params=params, 191 panel_name= self.panel_name) 195 self.type = self.__class__.__name__ 196 params = self.get_params() 197 event = SlicerParamUpdateEvent(type=self.type, 198 params=params, 199 panel_name=self.panel_name) 192 200 wx.PostEvent(self.base.parent, event) 193 201 194 195 202 def restore(self): 196 203 """ … … 201 208 self.center.restore() 202 209 203 204 210 def move(self, x, y, ev): 205 211 """ … … 208 214 pass 209 215 210 211 216 def set_cursor(self, x, y): 217 """ 218 """ 212 219 pass 213 220 214 215 221 def get_params(self): 216 222 """ 217 218 @return params: the dictionary created223 Store a copy of values of parameters of the slicer into a dictionary. 224 :return params: the dictionary created 219 225 """ 220 226 params = {} 221 params["Width"] = math.fabs(self.vertical_lines.half_width) *2222 params["Height"] = math.fabs(self.horizontal_lines.half_height) *2227 params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 228 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 223 229 params["center_x"] = self.center.x 224 params["center_y"] = self.center.y230 params["center_y"] = self.center.y 225 231 params["count"] = self.count 226 params["errors"] = self.error232 params["errors"] = self.error 227 233 return params 228 234 229 230 235 def get_result(self): 231 236 """ 232 237 return the result of box summation 233 238 """ 234 result ={}239 result = {} 235 240 result["count"] = self.count 236 241 result["error"] = self.error 237 242 return result 238 243 239 240 244 def set_params(self, params): 241 245 """ 242 243 244 @param params: a dictionary containing name of slicer parameters and246 Receive a dictionary and reset the slicer with values contained 247 in the values of the dictionary. 248 :param params: a dictionary containing name of slicer parameters and 245 249 values the user assigned to the slicer. 246 250 """ … … 248 252 y_max = math.fabs(params["Height"] )/2 249 253 250 self.center_x =params["center_x"]251 self.center_y =params["center_y"]254 self.center_x = params["center_x"] 255 self.center_y = params["center_y"] 252 256 #update the slicer given values of params 253 self.center.update(center_x=self.center_x,center_y=self.center_y) 254 self.horizontal_lines.update(center= self.center, 255 width=x_max, 256 height=y_max) 257 self.vertical_lines.update(center= self.center, 258 width=x_max, 259 height=y_max) 257 self.center.update(center_x=self.center_x, center_y=self.center_y) 258 self.horizontal_lines.update(center=self.center, 259 width=x_max, height=y_max) 260 self.vertical_lines.update(center=self.center, 261 width=x_max, height=y_max) 260 262 #compute the new error and sum given values of params 261 263 self._post_data() 262 264 263 264 265 265 def freeze_axes(self): 266 """ 267 """ 266 268 self.base.freeze_axes() 267 269 268 269 270 def thaw_axes(self): 271 """ 272 """ 270 273 self.base.thaw_axes() 271 274 272 273 275 def draw(self): 276 """ 277 """ 274 278 self.base.draw() 275 279 … … 278 282 class PointInteractor(_BaseInteractor): 279 283 """ 280 281 284 Draw a point that can be dragged with the marker. 285 this class controls the motion the center of the BoxSum 282 286 """ 283 def __init__(self, base,axes,color='black', zorder=5,284 center_ x= 0.0,285 center_y= 0.0):286 287 def __init__(self, base, axes, color='black', zorder=5, center_x=0.0, 288 center_y=0.0): 289 """ 290 """ 287 291 _BaseInteractor.__init__(self, base, axes, color=color) 288 292 ## Initialization the class … … 301 305 color=self.color, alpha=0.6, 302 306 pickradius=5, label="pick", 303 zorder=zorder, # Prefer this to other lines 307 # Prefer this to other lines 308 zorder=zorder, 304 309 visible=True)[0] 305 310 except: … … 309 314 label="pick", 310 315 visible=True)[0] 311 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 312 message += "Get the SVN version that is at least as recent as June 1, 2007" 313 owner=self.base.base.parent 314 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 315 316 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 317 message += " OF MATPLOTLIB.\n Get the SVN version that is " 318 message += "at least as recent as June 1, 2007" 319 owner = self.base.base.parent 320 wx.PostEvent(owner, 321 StatusEvent(status="AnnulusSlicer: %s" % message)) 316 322 ## Draw a point 317 self.center = self.axes.plot([self.x], [self.y],323 self.center = self.axes.plot([self.x], [self.y], 318 324 linestyle='-', marker='', 319 325 color=self.color, 320 326 visible=True)[0] 321 327 ## Flag to determine the motion this point 322 self.has_move =False328 self.has_move = False 323 329 ## connecting the marker to allow them to move 324 330 self.connect_markers([self.center_marker]) … … 326 332 self.update() 327 333 328 329 334 def set_layer(self, n): 330 335 """ … … 334 339 self.layernum = n 335 340 self.update() 336 337 341 338 342 def clear(self): … … 349 353 del self.axes.lines[0] 350 354 351 352 355 def update(self, center_x=None,center_y=None): 353 356 """ 354 357 Draw the new roughness on the graph. 355 358 """ 356 if center_x !=None: self.x= center_x 357 if center_y !=None: self.y= center_y 358 359 if center_x != None: 360 self.x = center_x 361 if center_y != None: 362 self.y = center_y 359 363 self.center_marker.set(xdata=[self.x], ydata=[self.y]) 360 364 self.center.set(xdata=[self.x], ydata=[self.y]) 361 365 362 363 366 def save(self, ev): 364 367 """ … … 366 369 can restore on Esc. 367 370 """ 368 self.save_x = self.x369 self.save_y = self.y371 self.save_x = self.x 372 self.save_y = self.y 370 373 self.base.freeze_axes() 371 372 374 373 375 def moveend(self, ev): 374 376 """ 377 """ 375 378 self.has_move=False 376 379 self.base.moveend(ev) … … 380 383 Restore the roughness for this layer. 381 384 """ 382 self.y= self.save_y 383 self.x= self.save_x 384 385 385 self.y = self.save_y 386 self.x = self.save_x 387 386 388 def move(self, x, y, ev): 387 389 """ 388 390 Process move to a new position, making sure that the move is allowed. 389 391 """ 390 self.x= x 391 self.y= y 392 393 self.has_move=True 392 self.x = x 393 self.y = y 394 self.has_move = True 394 395 self.base.base.update() 395 396 396 397 397 def set_cursor(self, x, y): 398 """ 399 """ 398 400 self.move(x, y, None) 399 401 self.update() 400 401 402 402 403 def get_params(self): 404 """ 405 """ 403 406 params = {} 404 407 params["x"] = self.x … … 406 409 return params 407 410 408 409 411 def set_params(self, params): 412 """ 413 """ 410 414 center_x = params["x"] 411 415 center_y = params["y"] 412 self.update(center_x=center_x, center_y=center_y)416 self.update(center_x=center_x, center_y=center_y) 413 417 414 418 … … 418 422 a point (PointInteractor) 419 423 """ 420 def __init__(self, base,axes,color='black', zorder=5, x=0.5,y=0.5,421 center_x= 0.0,422 center_y= 0.0):423 424 def __init__(self, base, axes, color='black', zorder=5, x=0.5,y=0.5, 425 center_x=0.0, center_y=0.0): 426 """ 427 """ 424 428 _BaseInteractor.__init__(self, base, axes, color=color) 425 429 ## Initialization the class … … 430 434 self.center_y = center_y 431 435 ## defined end points vertical lignes and their saved values 432 self.y1 436 self.y1 = y + self.center_y 433 437 self.save_y1= self.y1 434 438 435 delta = self.y1- self.center_y436 self.y2 = self.center_y - delta437 self.save_y2 = self.y2438 439 self.x1 439 delta = self.y1 - self.center_y 440 self.y2 = self.center_y - delta 441 self.save_y2 = self.y2 442 443 self.x1 = x + self.center_x 440 444 self.save_x1 = self.x1 441 445 442 delta = self.x1- self.center_x443 self.x2 = self.center_x - delta446 delta = self.x1 - self.center_x 447 self.x2 = self.center_x - delta 444 448 self.save_x2 = self.x2 445 449 ## save the color of the line 446 450 self.color = color 447 451 ## the height of the rectangle 448 self.half_height = math.fabs(y)449 self.save_half_height = math.fabs(y)452 self.half_height = math.fabs(y) 453 self.save_half_height = math.fabs(y) 450 454 ## the with of the rectangle 451 self.half_width = math.fabs(self.x1- self.x2)/2452 self.save_half_width =math.fabs(self.x1- self.x2)/2455 self.half_width = math.fabs(self.x1- self.x2)/2 456 self.save_half_width = math.fabs(self.x1- self.x2)/2 453 457 ## Create marker 454 458 try: … … 457 461 color=self.color, alpha=0.6, 458 462 pickradius=5, label="pick", 459 zorder=zorder,# Prefer this to other lines460 visible=True)[0]463 # Prefer this to other lines 464 zorder=zorder, visible=True)[0] 461 465 except: 462 466 self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 463 467 marker='s', markersize=10, 464 468 color=self.color, alpha=0.6, 465 label="pick", 466 visible=True)[0] 467 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 468 message += "Get the SVN version that is at least as recent as June 1, 2007" 469 owner=self.base.base.parent 470 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 469 label="pick", visible=True)[0] 470 message = "\nTHIS PROTOTYPE NEEDS THE LATEST " 471 message += "VERSION OF MATPLOTLIB\n Get the SVN version that" 472 message += " is at least as recent as June 1, 2007" 473 owner = self.base.base.parent 474 wx.PostEvent(owner, 475 StatusEvent(status="AnnulusSlicer: %s" % message)) 471 476 472 477 ## define the left and right lines of the rectangle 473 self.right_line = self.axes.plot([self.x1, self.x1],[self.y1,self.y2],478 self.right_line = self.axes.plot([self.x1, self.x1], [self.y1, self.y2], 474 479 linestyle='-', marker='', 475 color=self.color, 476 visible=True)[0] 477 self.left_line = self.axes.plot([self.x2,self.x2],[self.y1,self.y2], 480 color=self.color, visible=True)[0] 481 self.left_line = self.axes.plot([self.x2, self.x2], [self.y1, self.y2], 478 482 linestyle='-', marker='', 479 color=self.color, 480 visible=True)[0] 483 color=self.color, visible=True)[0] 481 484 ## Flag to determine if the lines have moved 482 self.has_move =False485 self.has_move = False 483 486 ## connection the marker and draw the pictures 484 487 self.connect_markers([self.right_marker]) 485 488 self.update() 486 489 487 488 490 def set_layer(self, n): 489 491 """ 490 491 @param n: the number of layer492 Allow adding plot to the same panel 493 :param n: the number of layer 492 494 """ 493 495 self.layernum = n 494 496 self.update() 495 497 496 497 498 def clear(self): 498 499 """ 499 500 Clear this slicer and its markers 500 501 """ 501 502 self.clear_markers() … … 509 510 del self.axes.lines[0] 510 511 511 512 def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None):513 """ 514 515 @param x1: new maximum value of x coordinates516 @param x2: new minimum value of x coordinates517 @param y1: new maximum value of y coordinates518 @param y2: new minimum value of y coordinates519 @param width: is the width of the new rectangle520 @param height: is the height of the new rectangle521 @param center: provided x, y coordinates of the center point512 def update(self, x1=None, x2=None, y1=None, y2=None,width=None, 513 height=None, center=None): 514 """ 515 Draw the new roughness on the graph. 516 :param x1: new maximum value of x coordinates 517 :param x2: new minimum value of x coordinates 518 :param y1: new maximum value of y coordinates 519 :param y2: new minimum value of y coordinates 520 :param width: is the width of the new rectangle 521 :param height: is the height of the new rectangle 522 :param center: provided x, y coordinates of the center point 522 523 """ 523 524 ## save the new height, witdh of the rectangle if given as a param 524 if width !=None:525 self.half_width = width526 if height !=None:527 self.half_height = height525 if width != None: 526 self.half_width = width 527 if height != None: 528 self.half_height = height 528 529 ## If new center coordinates are given draw the rectangle 529 530 ##given these value 530 if center!=None: 531 self.center_x= center.x 532 self.center_y= center.y 533 531 if center != None: 532 self.center_x = center.x 533 self.center_y = center.y 534 534 self.x1 = self.half_width + self.center_x 535 535 self.x2= -self.half_width + self.center_x 536 537 536 self.y1 = self.half_height + self.center_y 538 537 self.y2= -self.half_height + self.center_y 539 538 540 self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 541 self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 542 self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 539 self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 540 self.right_line.set(xdata=[self.x1, self.x1], 541 ydata=[self.y1, self.y2]) 542 self.left_line.set(xdata=[self.x2, self.x2], 543 ydata=[self.y1, self.y2]) 543 544 return 544 545 ## if x1, y1, y2, y3 are given draw the rectangle with this value 545 if x1 != None:546 self.x1 = x1547 if x2 != None:548 self.x2 = x2549 if y1 != None:550 self.y1 = y1551 if y2 != None:552 self.y2 = y2546 if x1 != None: 547 self.x1 = x1 548 if x2 != None: 549 self.x2 = x2 550 if y1 != None: 551 self.y1 = y1 552 if y2 != None: 553 self.y2 = y2 553 554 ## Draw 2 vertical lines and a marker 554 self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 555 self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 556 self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 557 555 self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 556 self.right_line.set(xdata=[self.x1, self.x1], ydata=[self.y1, self.y2]) 557 self.left_line.set(xdata=[self.x2, self.x2], ydata=[self.y1, self.y2]) 558 558 559 559 def save(self, ev): … … 562 562 can restore on Esc. 563 563 """ 564 self.save_x2= self.x2 565 self.save_y2= self.y2 566 567 self.save_x1= self.x1 568 self.save_y1= self.y1 569 570 self.save_half_height= self.half_height 564 self.save_x2 = self.x2 565 self.save_y2 = self.y2 566 self.save_x1 = self.x1 567 self.save_y1 = self.y1 568 self.save_half_height = self.half_height 571 569 self.save_half_width = self.half_width 572 573 570 self.base.freeze_axes() 574 571 575 576 572 def moveend(self, ev): 577 573 """ 578 574 After a dragging motion reset the flag self.has_move to False 579 575 """ 580 self.has_move =False576 self.has_move = False 581 577 self.base.moveend(ev) 582 578 583 584 579 def restore(self): 585 580 """ 586 581 Restore the roughness for this layer. 587 582 """ 588 self.y2= self.save_y2 589 self.x2= self.save_x2 590 591 self.y1= self.save_y1 592 self.x1= self.save_x1 593 594 self.half_height= self.save_half_height 595 self.half_width= self.save_half_width 596 583 self.y2 = self.save_y2 584 self.x2 = self.save_x2 585 self.y1 = self.save_y1 586 self.x1 = self.save_x1 587 self.half_height = self.save_half_height 588 self.half_width = self.save_half_width 597 589 598 590 def move(self, x, y, ev): … … 600 592 Process move to a new position, making sure that the move is allowed. 601 593 """ 602 self.x1= x 603 delta= self.x1- self.center_x 604 self.x2= self.center_x - delta 605 606 self.half_width= math.fabs(self.x1-self.x2)/2 607 608 self.has_move=True 594 self.x1 = x 595 delta = self.x1 - self.center_x 596 self.x2 = self.center_x - delta 597 self.half_width = math.fabs(self.x1 - self.x2)/2 598 self.has_move = True 609 599 self.base.base.update() 610 600 611 612 601 def set_cursor(self, x, y): 613 602 """ … … 616 605 self.move(x, y, None) 617 606 self.update() 618 619 607 620 608 def get_params(self): … … 626 614 params["x"] = self.x1 627 615 params["y"] = self.y1 628 629 616 return params 630 617 … … 638 625 x = params["x"] 639 626 y = params["y"] 640 self.update(x=x, y=y, center_x=None, center_y=None)627 self.update(x=x, y=y, center_x=None, center_y=None) 641 628 642 629 … … 645 632 Select an annulus through a 2D plot 646 633 """ 647 def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, 648 center_x= 0.0, 649 center_y= 0.0): 634 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 635 center_x=0.0, center_y=0.0): 650 636 651 637 _BaseInteractor.__init__(self, base, axes, color=color) … … 656 642 self.center_x = center_x 657 643 self.center_y = center_y 658 659 self.y1 = y + self.center_y 660 self.save_y1= self.y1 661 662 delta= self.y1- self.center_y 663 self.y2= self.center_y - delta 664 self.save_y2= self.y2 665 666 self.x1 = x + self.center_x 644 self.y1 = y + self.center_y 645 self.save_y1 = self.y1 646 delta = self.y1 - self.center_y 647 self.y2 = self.center_y - delta 648 self.save_y2 = self.y2 649 self.x1 = x + self.center_x 667 650 self.save_x1 = self.x1 668 669 delta= self.x1- self.center_x 670 self.x2= self.center_x - delta 651 delta = self.x1 - self.center_x 652 self.x2 = self.center_x - delta 671 653 self.save_x2 = self.x2 672 673 self.color=color 674 654 self.color = color 675 655 self.half_height= math.fabs(y) 676 self.save_half_height= math.fabs(y) 677 678 self.half_width= math.fabs(x) 679 self.save_half_width=math.fabs(x) 680 656 self.save_half_height = math.fabs(y) 657 self.half_width = math.fabs(x) 658 self.save_half_width = math.fabs(x) 681 659 try: 682 self.top_marker = self.axes.plot([0], [self.y1], linestyle='',660 self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 683 661 marker='s', markersize=10, 684 662 color=self.color, alpha=0.6, 685 pickradius=5, label="pick", 686 zorder=zorder,# Prefer this to other lines687 visible=True)[0]663 pickradius=5, label="pick", 664 # Prefer this to other lines 665 zorder=zorder, visible=True)[0] 688 666 except: 689 self.top_marker = self.axes.plot([0], [self.y1], linestyle='',667 self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 690 668 marker='s', markersize=10, 691 669 color=self.color, alpha=0.6, 692 label="pick", 693 visible=True)[0] 694 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 695 message += "Get the SVN version that is at least as recent as June 1, 2007" 696 owner=self.base.base.parent 697 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 670 label="pick", visible=True)[0] 671 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 672 message += "OF MATPLOTLIB\n Get the SVN version " 673 message += "that is at least as recent as June 1, 2007" 674 owner = self.base.base.parent 675 wx.PostEvent(owner, 676 StatusEvent(status="AnnulusSlicer: %s" % message)) 698 677 699 678 # Define 2 horizotnal lines 700 self.top_line = self.axes.plot([self.x1, -self.x1],[self.y1,self.y1],679 self.top_line = self.axes.plot([self.x1, -self.x1], [self.y1, self.y1], 701 680 linestyle='-', marker='', 702 color=self.color, 703 visible=True)[0]704 self.bottom_line = self.axes.plot([self.x1,-self.x1],[self.y2,self.y2],681 color=self.color, visible=True)[0] 682 self.bottom_line = self.axes.plot([self.x1, -self.x1], 683 [self.y2, self.y2], 705 684 linestyle='-', marker='', 706 color=self.color, 707 visible=True)[0] 685 color=self.color, visible=True)[0] 708 686 ## Flag to determine if the lines have moved 709 self.has_move =False687 self.has_move = False 710 688 ## connection the marker and draw the pictures 711 689 self.connect_markers([self.top_marker]) 712 690 self.update() 713 691 714 715 692 def set_layer(self, n): 716 693 """ … … 720 697 self.layernum = n 721 698 self.update() 722 723 699 724 700 def clear(self): … … 736 712 del self.axes.lines[0] 737 713 738 739 def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None):740 """ 741 742 @param x1: new maximum value of x coordinates743 @param x2: new minimum value of x coordinates744 @param y1: new maximum value of y coordinates745 @param y2: new minimum value of y coordinates746 @param width: is the width of the new rectangle747 @param height: is the height of the new rectangle748 @param center: provided x, y coordinates of the center point714 def update(self, x1=None, x2=None, y1=None, y2=None, 715 width=None, height=None, center=None): 716 """ 717 Draw the new roughness on the graph. 718 :param x1: new maximum value of x coordinates 719 :param x2: new minimum value of x coordinates 720 :param y1: new maximum value of y coordinates 721 :param y2: new minimum value of y coordinates 722 :param width: is the width of the new rectangle 723 :param height: is the height of the new rectangle 724 :param center: provided x, y coordinates of the center point 749 725 """ 750 726 ## save the new height, witdh of the rectangle if given as a param … … 752 728 self.half_width = width 753 729 if height!= None: 754 self.half_height = height730 self.half_height = height 755 731 ## If new center coordinates are given draw the rectangle 756 732 ##given these value 757 if center!=None: 758 self.center_x= center.x 759 self.center_y= center.y 760 733 if center != None: 734 self.center_x = center.x 735 self.center_y = center.y 761 736 self.x1 = self.half_width + self.center_x 762 self.x2 = -self.half_width + self.center_x737 self.x2 = -self.half_width + self.center_x 763 738 764 739 self.y1 = self.half_height + self.center_y 765 self.y2 = -self.half_height + self.center_y740 self.y2 = -self.half_height + self.center_y 766 741 767 self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 768 self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) 769 self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 742 self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 743 self.top_line.set(xdata=[self.x1, self.x2], 744 ydata=[self.y1, self.y1]) 745 self.bottom_line.set(xdata=[self.x1, self.x2], 746 ydata=[self.y2, self.y2]) 770 747 return 771 748 ## if x1, y1, y2, y3 are given draw the rectangle with this value 772 if x1 != None:773 self.x1 = x1774 if x2 != None:775 self.x2 = x2776 if y1 != None:777 self.y1 = y1778 if y2 != None:779 self.y2 = y2749 if x1 != None: 750 self.x1 = x1 751 if x2 != None: 752 self.x2 = x2 753 if y1 != None: 754 self.y1 = y1 755 if y2 != None: 756 self.y2 = y2 780 757 ## Draw 2 vertical lines and a marker 781 self.top_marker.set(xdata=[self.center_x], ydata=[self.y1])782 self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1,self.y1])783 self.bottom_line.set(xdata=[self.x1, self.x2], ydata=[self.y2,self.y2])758 self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 759 self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1, self.y1]) 760 self.bottom_line.set(xdata=[self.x1, self.x2], ydata=[self.y2, self.y2]) 784 761 785 786 762 def save(self, ev): 787 763 """ … … 789 765 can restore on Esc. 790 766 """ 791 self.save_x2= self.x2 792 self.save_y2= self.y2 793 794 self.save_x1= self.x1 795 self.save_y1= self.y1 796 797 self.save_half_height= self.half_height 767 self.save_x2 = self.x2 768 self.save_y2 = self.y2 769 self.save_x1 = self.x1 770 self.save_y1 = self.y1 771 self.save_half_height = self.half_height 798 772 self.save_half_width = self.half_width 799 773 self.base.freeze_axes() 800 801 774 802 775 def moveend(self, ev): 803 776 """ 804 805 """ 806 self.has_move =False777 After a dragging motion reset the flag self.has_move to False 778 """ 779 self.has_move = False 807 780 self.base.moveend(ev) 808 781 809 810 782 def restore(self): 811 783 """ 812 784 Restore the roughness for this layer. 813 785 """ 814 self.y2= self.save_y2 815 self.x2= self.save_x2 816 817 self.y1= self.save_y1 818 self.x1= self.save_x1 819 self.half_height= self.save_half_height 820 self.half_width= self.save_half_width 821 786 self.y2 = self.save_y2 787 self.x2 = self.save_x2 788 self.y1 = self.save_y1 789 self.x1 = self.save_x1 790 self.half_height = self.save_half_height 791 self.half_width = self.save_half_width 822 792 823 793 def move(self, x, y, ev): … … 825 795 Process move to a new position, making sure that the move is allowed. 826 796 """ 827 self.y1 = y828 delta = self.y1- self.center_y829 self.y2 = self.center_y - delta830 self.half_height = math.fabs(self.y1)-self.center_y831 self.has_move =True797 self.y1 = y 798 delta = self.y1 - self.center_y 799 self.y2 = self.center_y - delta 800 self.half_height = math.fabs(self.y1) - self.center_y 801 self.has_move = True 832 802 self.base.base.update() 833 834 803 835 804 def set_cursor(self, x, y): 836 805 """ … … 840 809 self.update() 841 810 842 843 811 def get_params(self): 844 812 """ 845 846 @return params: the dictionary created813 Store a copy of values of parameters of the slicer into a dictionary. 814 :return params: the dictionary created 847 815 """ 848 816 params = {} … … 851 819 return params 852 820 853 854 821 def set_params(self, params): 855 822 """ 856 857 858 @param params: a dictionary containing name of slicer parameters and823 Receive a dictionary and reset the slicer with values contained 824 in the values of the dictionary. 825 :param params: a dictionary containing name of slicer parameters and 859 826 values the user assigned to the slicer. 860 827 """ -
guiframe/local_perspectives/plotting/detector_dialog.py
rd955bf19 r32c0841 8 8 import sys 9 9 from sans.guiframe.utils import format_number 10 from sans.guicomm.events import StatusEvent ,NewPlotEvent 10 from sans.guicomm.events import StatusEvent 11 from sans.guicomm.events import NewPlotEvent 11 12 12 13 import matplotlib 13 14 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas 14 from matplotlib import pyplot, mpl, pylab 15 from matplotlib import pyplot 16 from matplotlib import mpl 17 from matplotlib import pylab 15 18 #FONT size 16 if sys.platform.count("win32") >0:19 if sys.platform.count("win32") > 0: 17 20 FONT_VARIANT = 0 18 21 else: 19 22 FONT_VARIANT = 1 20 23 21 DEFAULT_CMAP = pylab.cm.jet24 DEFAULT_CMAP = pylab.cm.jet 22 25 23 26 class DetectorDialog(wx.Dialog): … … 26 29 """ 27 30 28 def __init__(self,parent,id=1,base=None,dpi = None,cmap=DEFAULT_CMAP, 29 reset_zmin_ctl = None,reset_zmax_ctl = None, *args, **kwds): 31 def __init__(self, parent, id=1, base=None, dpi=None, 32 cmap=DEFAULT_CMAP, reset_zmin_ctl = None, 33 reset_zmax_ctl = None, *args, **kwds): 30 34 """ 31 35 """ 32 36 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 33 wx.Dialog.__init__(self,parent,id=1, *args, **kwds) 34 37 wx.Dialog.__init__(self, parent, id=1, *args, **kwds) 35 38 self.SetWindowVariant(variant=FONT_VARIANT) 36 self.parent =base39 self.parent = base 37 40 self.dpi = dpi 38 41 self.cmap = cmap 39 40 self.reset_zmin_ctl= reset_zmin_ctl 41 self.reset_zmax_ctl= reset_zmax_ctl 42 42 self.reset_zmin_ctl = reset_zmin_ctl 43 self.reset_zmax_ctl = reset_zmax_ctl 43 44 self.label_xnpts = wx.StaticText(self, -1, "Detector width in pixels") 44 45 self.label_ynpts = wx.StaticText(self, -1, "Detector Height in pixels") 45 46 self.label_qmax = wx.StaticText(self, -1, "Q max") 46 self.label_zmin = wx.StaticText(self, -1, "Min amplitude for color map (optional)") 47 self.label_zmax = wx.StaticText(self, -1, "Max amplitude for color map (optional)") 48 self.label_beam = wx.StaticText(self, -1, "Beam stop radius in units of q") 49 47 self.label_zmin = wx.StaticText(self, -1, 48 "Min amplitude for color map (optional)") 49 self.label_zmax = wx.StaticText(self, -1, 50 "Max amplitude for color map (optional)") 51 self.label_beam = wx.StaticText(self, -1, 52 "Beam stop radius in units of q") 50 53 self.xnpts_ctl = wx.StaticText(self, -1, "") 51 54 self.ynpts_ctl = wx.StaticText(self, -1, "") 52 55 self.qmax_ctl = wx.StaticText(self, -1, "") 53 56 self.beam_ctl = wx.StaticText(self, -1, "") 54 55 self.zmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) 57 self.zmin_ctl = wx.TextCtrl(self, -1, size=(60, 20)) 56 58 self.zmin_ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 57 self.zmax_ctl = wx.TextCtrl(self, -1, size=(60, 20))59 self.zmax_ctl = wx.TextCtrl(self, -1, size=(60, 20)) 58 60 self.zmax_ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 59 60 61 self.static_line_3 = wx.StaticLine(self, -1) 61 62 62 self.button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 63 self.button_reset = wx.Button(self, wx.NewId(), "Reset")63 self.button_reset = wx.Button(self, wx.NewId(), "Reset") 64 64 self.Bind(wx.EVT_BUTTON, self.resetValues, self.button_reset) 65 65 self.button_OK = wx.Button(self, wx.ID_OK, "OK") 66 66 self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_OK) 67 68 67 self.__set_properties() 69 68 self.__do_layout() 70 71 69 self.Fit() 72 70 … … 80 78 zmin = 0 81 79 zmax = 0 82 cmap = None80 cmap = None 83 81 sym4 = False 84 82 … … 90 88 widget = event.GetEventObject() 91 89 # Select the whole control, after this event resolves 92 wx.CallAfter(widget.SetSelection, -1,-1) 93 return 90 wx.CallAfter(widget.SetSelection, -1, -1) 94 91 95 92 def resetValues(self, event): … … 98 95 """ 99 96 try: 100 zmin = self.reset_zmin_ctl101 zmax = self.reset_zmax_ctl102 if zmin ==None:103 zmin = ""104 if zmax ==None:105 zmax = ""97 zmin = self.reset_zmin_ctl 98 zmax = self.reset_zmax_ctl 99 if zmin == None: 100 zmin = "" 101 if zmax == None: 102 zmax = "" 106 103 self.zmin_ctl.SetValue(str(zmin)) 107 104 self.zmax_ctl.SetValue(str(zmax)) … … 110 107 self._on_select_cmap(event=None) 111 108 except: 112 msg ="error occurs while resetting Detector: %s"%sys.exc_value 113 wx.PostEvent(self.parent,StatusEvent(status= msg )) 114 109 msg = "error occurs while resetting Detector: %s" % sys.exc_value 110 wx.PostEvent(self.parent, StatusEvent(status=msg)) 115 111 116 112 def checkValues(self, event): … … 121 117 flag = True 122 118 try: 123 value =self.zmin_ctl.GetValue()124 if value and float( value) ==0.0:119 value = self.zmin_ctl.GetValue() 120 if value and float( value) == 0.0: 125 121 flag = False 126 wx.PostEvent(self.parent, StatusEvent(status="Enter number greater than zero")) 122 wx.PostEvent(self.parent, 123 StatusEvent(status="Enter number greater than zero")) 127 124 self.zmin_ctl.SetBackgroundColour("pink") 128 125 self.zmin_ctl.Refresh() … … 136 133 self.zmin_ctl.Refresh() 137 134 try: 138 value =self.zmax_ctl.GetValue()139 if value and float(value) ==0.0:135 value = self.zmax_ctl.GetValue() 136 if value and float(value) == 0.0: 140 137 flag = False 141 wx.PostEvent(self.parent, StatusEvent(status="Enter number greater than zero")) 138 wx.PostEvent(self.parent, 139 StatusEvent(status="Enter number greater than zero")) 142 140 self.zmax_ctl.SetBackgroundColour("pink") 143 141 self.zmax_ctl.Refresh() … … 150 148 self.zmax_ctl.SetBackgroundColour("pink") 151 149 self.zmax_ctl.Refresh() 152 153 150 if flag: 154 151 event.Skip(True) 155 152 156 def setContent(self, xnpts,ynpts, qmax, beam,zmin=None,zmax=None, sym=False): 153 def setContent(self, xnpts, ynpts, qmax, beam, 154 zmin=None, zmax=None, sym=False): 157 155 """ 158 156 received value and displayed them … … 171 169 self.qmax_ctl.SetLabel(str(format_number(qmax))) 172 170 self.beam_ctl.SetLabel(str(format_number(beam))) 173 174 if zmin !=None: 171 if zmin != None: 175 172 self.zmin_ctl.SetValue(str(format_number(zmin))) 176 if zmax != None:173 if zmax != None: 177 174 self.zmax_ctl.SetValue(str(format_number(zmax))) 178 175 … … 182 179 """ 183 180 event = self.Event() 184 185 181 t_min = self.zmin_ctl.GetValue() 186 182 t_max = self.zmax_ctl.GetValue() 187 183 v_min = None 188 184 v_max = None 189 190 if len(t_min.lstrip())>0: 185 if len(t_min.lstrip()) > 0: 191 186 try: 192 187 v_min = float(t_min) 193 188 except: 194 189 v_min = None 195 196 if len(t_max.lstrip())>0: 190 if len(t_max.lstrip()) > 0: 197 191 try: 198 192 v_max = float(t_max) 199 193 except: 200 194 v_max = None 201 202 195 event.zmin = v_min 203 196 event.zmax = v_max 204 event.cmap= self.cmap 205 197 event.cmap = self.cmap 206 198 return event 207 199 … … 213 205 self.SetSize((600, 595)) 214 206 215 216 207 def __do_layout(self): 217 208 """ … … 220 211 sizer_main = wx.BoxSizer(wx.VERTICAL) 221 212 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 222 sizer_params = wx.GridBagSizer(5, 5)213 sizer_params = wx.GridBagSizer(5, 5) 223 214 sizer_colormap = wx.BoxSizer(wx.VERTICAL) 224 sizer_selection = wx.BoxSizer(wx.HORIZONTAL)215 sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 225 216 226 217 iy = 0 227 sizer_params.Add(self.label_xnpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 228 sizer_params.Add(self.xnpts_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 229 iy += 1 230 sizer_params.Add(self.label_ynpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 231 sizer_params.Add(self.ynpts_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 232 iy += 1 233 sizer_params.Add(self.label_qmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 234 sizer_params.Add(self.qmax_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 235 iy += 1 236 sizer_params.Add(self.label_beam, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 237 sizer_params.Add(self.beam_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 238 iy += 1 239 sizer_params.Add(self.label_zmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 240 sizer_params.Add(self.zmin_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 241 iy += 1 242 sizer_params.Add(self.label_zmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 243 sizer_params.Add(self.zmax_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 244 iy += 1 245 246 self.fig = mpl.figure.Figure(dpi=self.dpi, figsize=(4,1)) 247 218 sizer_params.Add(self.label_xnpts, (iy, 0), (1, 1), 219 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 220 sizer_params.Add(self.xnpts_ctl, (iy, 1), (1, 1), 221 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 222 iy += 1 223 sizer_params.Add(self.label_ynpts, (iy, 0), (1, 1), 224 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 225 sizer_params.Add(self.ynpts_ctl, (iy, 1), (1, 1), 226 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 227 iy += 1 228 sizer_params.Add(self.label_qmax, (iy, 0), (1, 1), 229 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 230 sizer_params.Add(self.qmax_ctl, (iy, 1), (1, 1), 231 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 232 iy += 1 233 sizer_params.Add(self.label_beam, (iy, 0), (1, 1), 234 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 235 sizer_params.Add(self.beam_ctl, (iy, 1), (1, 1), 236 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 237 iy += 1 238 sizer_params.Add(self.label_zmin, (iy, 0), (1, 1), 239 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 240 sizer_params.Add(self.zmin_ctl, (iy, 1), (1, 1), 241 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 242 iy += 1 243 sizer_params.Add(self.label_zmax, (iy, 0), (1, 1), 244 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 245 sizer_params.Add(self.zmax_ctl, (iy, 1), (1, 1), 246 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 247 iy += 1 248 self.fig = mpl.figure.Figure(dpi=self.dpi, figsize=(4, 1)) 248 249 self.ax1 = self.fig.add_axes([0.05, 0.65, 0.9, 0.15]) 249 250 250 self.norm = mpl.colors.Normalize(vmin=0, vmax=100) 251 251 self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, … … 254 254 self.cb1.set_label('Detector Colors') 255 255 self.canvas = Canvas(self, -1, self.fig) 256 sizer_colormap.Add(self.canvas,0, wx.LEFT | wx.EXPAND,5) 257 256 sizer_colormap.Add(self.canvas, 0, wx.LEFT | wx.EXPAND,5) 258 257 self.cmap_selector = wx.ComboBox(self, -1) 259 258 self.cmap_selector.SetValue(str(self.cmap.name)) 260 259 maps = sorted(m for m in pylab.cm.datad if not m.endswith("_r")) 261 260 262 for i,m in enumerate(maps): 263 261 for i, m in enumerate(maps): 264 262 self.cmap_selector.Append(str(m), pylab.get_cmap(m)) 265 263 266 wx.EVT_COMBOBOX(self.cmap_selector,-1, self._on_select_cmap) 267 sizer_selection.Add(wx.StaticText(self,-1,"Select Cmap: "),0, wx.LEFT|wx.ADJUST_MINSIZE,5) 264 wx.EVT_COMBOBOX(self.cmap_selector, -1, self._on_select_cmap) 265 sizer_selection.Add(wx.StaticText(self, -1,"Select Cmap: "), 0, 266 wx.LEFT|wx.ADJUST_MINSIZE, 5) 268 267 sizer_selection.Add(self.cmap_selector, 0, wx.EXPAND|wx.ALL, 10) 269 270 268 sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) 271 272 269 sizer_main.Add(sizer_selection, 0, wx.EXPAND|wx.ALL, 10) 273 270 sizer_main.Add(sizer_colormap, 1, wx.EXPAND|wx.ALL, 10) 274 271 sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) 275 276 sizer_button.Add(self.button_reset,0, wx.LEFT|wx.ADJUST_MINSIZE, 100) 272 sizer_button.Add(self.button_reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 100) 277 273 sizer_button.Add(self.button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 278 sizer_button.Add(self.button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)279 274 sizer_button.Add(self.button_Cancel, 0, 275 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 280 276 sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 281 277 self.SetAutoLayout(True) … … 289 285 display a new cmap 290 286 """ 291 cmap_name = self.cmap_selector.GetCurrentSelection()292 current_cmap = self.cmap_selector.GetClientData( cmap_name)293 self.cmap = current_cmap287 cmap_name = self.cmap_selector.GetCurrentSelection() 288 current_cmap = self.cmap_selector.GetClientData(cmap_name) 289 self.cmap = current_cmap 294 290 self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 295 norm= self.norm, 296 orientation='horizontal') 291 norm=self.norm, orientation='horizontal') 297 292 self.canvas.draw() 298 293 … … 306 301 dialog = DetectorDialog(None, -1, "") 307 302 self.SetTopWindow(dialog) 308 dialog.setContent(xnpts=128, ynpts=128, qmax=20,309 beam=20, zmin=2,zmax=60, sym=False)303 dialog.setContent(xnpts=128, ynpts=128, qmax=20, 304 beam=20, zmin=2, zmax=60, sym=False) 310 305 print dialog.ShowModal() 311 306 evt = dialog.getContent() 312 if hasattr(evt, "npts"):313 print "number of point: ", evt.npts307 if hasattr(evt, "npts"): 308 print "number of point: ", evt.npts 314 309 if hasattr(evt,"qmax"): 315 print "qmax: ", evt.qmax310 print "qmax: ", evt.qmax 316 311 dialog.Destroy() 317 312 return 1 … … 322 317 app = MyApp(0) 323 318 app.MainLoop() 324 325 ##### end of testing code ##################################################### 319 -
guiframe/local_perspectives/plotting/masking.py
r0aee80d r32c0841 18 18 import wx 19 19 import sys 20 21 import copy,numpy 20 import pylab 21 from pylab import gca 22 from pylab import gcf 23 import math 24 import re 25 import copy 26 import numpy 22 27 from danse.common.plottools.PlotPanel import PlotPanel 23 28 from danse.common.plottools.plottables import Graph … … 26 31 from boxMask import BoxMask 27 32 from sectorMask import SectorMask 28 from sans.guicomm.events import SlicerEvent, StatusEvent 29 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 30 from pylab import gca, gcf 31 import math,pylab,re 32 DEFAULT_CMAP= pylab.cm.jet 33 33 from sans.guicomm.events import SlicerEvent 34 from sans.guicomm.events import StatusEvent 35 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 36 37 DEFAULT_CMAP = pylab.cm.jet 34 38 _BOX_WIDTH = 76 35 39 _STATICBOX_WIDTH = 400 … … 37 41 38 42 #SLD panel size 39 if sys.platform.count("win32") >0:43 if sys.platform.count("win32") > 0: 40 44 _STATICBOX_WIDTH = 380 41 45 PANEL_SIZE = 420 … … 47 51 48 52 49 50 53 class MaskPanel(wx.Dialog): 51 54 """ … … 58 61 ## Flag to tell the AUI manager to put this panel in the center pane 59 62 CENTER_PANE = True 60 def __init__(self, parent=None,base=None,data =None, id = -1, *args, **kwds): 63 def __init__(self, parent=None, base=None, 64 data=None, id=-1, *args, **kwds): 61 65 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 62 kwds["size"] = wx.Size(_STATICBOX_WIDTH*2,PANEL_SIZE) 63 wx.Dialog.__init__(self, parent, id = id, *args, **kwds) 66 kwds["size"] = wx.Size(_STATICBOX_WIDTH * 2, PANEL_SIZE) 67 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 68 64 69 if data != None: 65 66 70 #Font size 67 kwds = []71 kwds = [] 68 72 self.SetWindowVariant(variant=FONT_VARIANT) 69 70 self.SetTitle("Mask Editor for "+ data.name) 73 self.SetTitle("Mask Editor for " + data.name) 71 74 self.parent = base 72 75 self.data = data … … 79 82 self.slicer = None 80 83 self.slicer_z = 5 81 82 84 self.data.interactive = True 83 85 ## when 2 data have the same id override the 1 st plotted 84 86 self.name = self.data.name 85 86 87 # Panel for 2D plot 87 self.plotpanel = Maskplotpanel(self, -1, style=wx.TRANSPARENT_WINDOW) 88 self.plotpanel = Maskplotpanel(self, -1, 89 style=wx.TRANSPARENT_WINDOW) 88 90 self.cmap = DEFAULT_CMAP 89 91 ## Create Artist and bind it 90 92 self.subplot = self.plotpanel.subplot 91 93 self.connect = BindArtist(self.subplot.figure) 92 93 94 self._setup_layout() 94 self.newplot =Data2D(image=self.data.data)95 self.newplot = Data2D(image=self.data.data) 95 96 self.newplot.setValues(self.data) 96 97 self.plotpanel.add_image(self.newplot) … … 108 109 mssg += 'The data range can not be completely masked... \n\r' 109 110 mssg += msg 110 wx.MessageBox(mssg, 'Error', wx.OK | 111 wx.ICON_ERROR) 111 wx.MessageBox(mssg, 'Error', wx.OK | wx.ICON_ERROR) 112 112 113 113 def _setup_layout(self): … … 116 116 """ 117 117 shape = "Select a Shape for Masking:" 118 119 118 # panel 120 sizer = wx.GridBagSizer(10,10) 121 119 sizer = wx.GridBagSizer(10, 10) 122 120 #---------inputs---------------- 123 121 #inputbox = wx.StaticBox(self, -1, "Draw Mask") 124 122 shape_txt = wx.StaticText(self, -1, shape) 125 sizer.Add(shape_txt, (1, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=5) 126 123 sizer.Add(shape_txt, (1, 1), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=5) 127 124 #innersector_x_txt = wx.StaticText(self, -1, 'Inner Sector') 128 self.innersector_rb = wx.RadioButton(self, -1,"Double Wings") 129 self.Bind(wx.EVT_RADIOBUTTON,self.onInnerSectorMask , id=self.innersector_rb.GetId()) 130 sizer.Add(self.innersector_rb, (2, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 131 125 self.innersector_rb = wx.RadioButton(self, -1, "Double Wings") 126 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerSectorMask, 127 id=self.innersector_rb.GetId()) 128 sizer.Add(self.innersector_rb, (2, 1), 129 flag=wx.RIGHT|wx.BOTTOM, border=5) 132 130 #innersector_x_txt = wx.StaticText(self, -1, 'Inner Sector') 133 self.innercircle_rb = wx.RadioButton(self, -1,"Circular Disk") 134 self.Bind(wx.EVT_RADIOBUTTON,self.onInnerRingMask , id=self.innercircle_rb.GetId()) 135 sizer.Add(self.innercircle_rb, (3, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 136 137 self.innerbox_rb = wx.RadioButton(self, -1,"Rectangular Disk") 138 self.Bind(wx.EVT_RADIOBUTTON,self.onInnerBoxMask , id=self.innerbox_rb.GetId()) 139 sizer.Add(self.innerbox_rb, (4, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 140 131 self.innercircle_rb = wx.RadioButton(self, -1, "Circular Disk") 132 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerRingMask, 133 id=self.innercircle_rb.GetId()) 134 sizer.Add(self.innercircle_rb, (3, 1), 135 flag=wx.RIGHT|wx.BOTTOM, border=5) 136 137 self.innerbox_rb = wx.RadioButton(self, -1, "Rectangular Disk") 138 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerBoxMask, 139 id=self.innerbox_rb.GetId()) 140 sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 141 141 #outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 142 self.outersector_rb = wx.RadioButton(self, -1,"Double Wing Window") 143 self.Bind(wx.EVT_RADIOBUTTON,self.onOuterSectorMask , id=self.outersector_rb.GetId()) 144 sizer.Add(self.outersector_rb, (5, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 142 self.outersector_rb = wx.RadioButton(self, -1, "Double Wing Window") 143 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask, 144 id=self.outersector_rb.GetId()) 145 sizer.Add(self.outersector_rb, (5, 1), 146 flag=wx.RIGHT|wx.BOTTOM, border=5) 145 147 146 148 #outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 147 self.outercircle_rb = wx.RadioButton(self, -1,"Circular Window") 148 self.Bind(wx.EVT_RADIOBUTTON,self.onOuterRingMask , id=self.outercircle_rb.GetId()) 149 sizer.Add(self.outercircle_rb, (6, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 150 149 self.outercircle_rb = wx.RadioButton(self, -1, "Circular Window") 150 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterRingMask, 151 id=self.outercircle_rb.GetId()) 152 sizer.Add(self.outercircle_rb, (6, 1), 153 flag=wx.RIGHT|wx.BOTTOM, border=5) 151 154 #outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 152 self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window")153 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask , id=self.outerbox_rb.GetId())154 sizer.Add(self.outerbox_rb, (7, 1),flag=wx.RIGHT | wx.BOTTOM, border=5)155 155 self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window") 156 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask, 157 id=self.outerbox_rb.GetId()) 158 sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 156 159 self.innercircle_rb.SetValue(False) 157 160 self.outercircle_rb.SetValue(False) … … 160 163 self.innersector_rb.SetValue(False) 161 164 self.outersector_rb.SetValue(False) 162 163 sizer.Add(self.plotpanel,(0, 2), (13, 13), wx.EXPAND | wx.LEFT|wx.RIGHT, 15)165 sizer.Add(self.plotpanel, (0, 2), (13, 13), 166 wx.EXPAND|wx.LEFT|wx.RIGHT, 15) 164 167 165 168 #-----Buttons------------1 166 169 id = wx.NewId() 167 168 170 button_add = wx.Button(self, id, "Add") 169 171 button_add.SetToolTipString("Add the mask drawn.") 170 button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id =button_add.GetId())172 button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId()) 171 173 sizer.Add(button_add, (13, 7)) 172 173 174 id = wx.NewId() 174 175 button_erase = wx.Button(self, id, "Erase") 175 176 button_erase.SetToolTipString("Erase the mask drawn.") 176 button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, id = button_erase.GetId()) 177 button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, 178 id=button_erase.GetId()) 177 179 sizer.Add(button_erase, (13, 8)) 178 179 180 id = wx.NewId() 180 181 button_reset = wx.Button(self, id, "Reset") 181 182 button_reset.SetToolTipString("Reset the mask.") 182 button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, id = button_reset.GetId())183 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT | wx.BOTTOM, border=15)184 183 button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, 184 id=button_reset.GetId()) 185 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT|wx.BOTTOM, border=15) 185 186 id = wx.NewId() 186 187 button_reset = wx.Button(self, id, "Clear") 187 188 button_reset.SetToolTipString("Clear all mask.") 188 button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, id = button_reset.GetId())189 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT | wx.BOTTOM, border=15)190 189 button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, 190 id=button_reset.GetId()) 191 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT|wx.BOTTOM, border=15) 191 192 sizer.AddGrowableCol(3) 192 193 sizer.AddGrowableRow(2) 193 194 self.SetSizerAndFit(sizer) 194 195 195 self.Centre() 196 196 self.Show(True) 197 197 198 199 def onInnerBoxMask(self,event=None): 198 def onInnerBoxMask(self, event=None): 200 199 """ 201 200 Call Draw Box Slicer and get mask inside of the box … … 203 202 #get ready for next evt 204 203 event.Skip() 205 from boxMask import BoxMask 206 if event !=None: 207 self.onClearSlicer(event) 208 209 self.slicer_z += 1 210 self.slicer = BoxMask(self, self.subplot, zorder=self.slicer_z, side=True) 211 204 #from boxMask import BoxMask 205 if event != None: 206 self.onClearSlicer(event) 207 self.slicer_z += 1 208 self.slicer = BoxMask(self, self.subplot, 209 zorder=self.slicer_z, side=True) 212 210 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 213 211 self.subplot.set_xlim(self.data.xmin, self.data.xmax) … … 215 213 self.slicer_mask = self.slicer.update() 216 214 217 218 def onOuterBoxMask(self,event=None): 215 def onOuterBoxMask(self, event=None): 219 216 """ 220 217 Call Draw Box Slicer and get mask outside of the box 221 218 """ 222 219 event.Skip() 223 from boxMask import BoxMask 224 if event !=None: 225 self.onClearSlicer(event) 226 227 self.slicer_z += 1 228 self.slicer = BoxMask(self, self.subplot, zorder=self.slicer_z, side=False) 229 220 #from boxMask import BoxMask 221 if event != None: 222 self.onClearSlicer(event) 223 self.slicer_z += 1 224 self.slicer = BoxMask(self, self.subplot, 225 zorder=self.slicer_z, side=False) 230 226 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 231 227 self.subplot.set_xlim(self.data.xmin, self.data.xmax) … … 233 229 self.slicer_mask = self.slicer.update() 234 230 235 236 def onInnerSectorMask(self,event=None): 231 def onInnerSectorMask(self, event=None): 237 232 """ 238 233 Call Draw Sector Slicer and get mask inside of the sector … … 240 235 event.Skip() 241 236 from sectorMask import SectorMask 242 if event != None:237 if event != None: 243 238 self.onClearSlicer(event) 244 245 self.slicer _z += 1246 self.slicer = SectorMask(self, self.subplot,zorder=self.slicer_z, side=True)239 self.slicer_z += 1 240 self.slicer = SectorMask(self, self.subplot, 241 zorder=self.slicer_z, side=True) 247 242 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 248 243 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 249 250 244 self.update() 251 245 self.slicer_mask = self.slicer.update() 252 246 253 254 247 def onOuterSectorMask(self,event=None): 255 248 """ … … 258 251 event.Skip() 259 252 from sectorMask import SectorMask 260 if event != None:253 if event != None: 261 254 self.onClearSlicer(event) 262 263 self.slicer _z += 1264 self.slicer = SectorMask(self, self.subplot,zorder=self.slicer_z, side=False)255 self.slicer_z += 1 256 self.slicer = SectorMask(self, self.subplot, 257 zorder=self.slicer_z, side=False) 265 258 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 266 259 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 267 268 260 self.update() 269 261 self.slicer_mask = self.slicer.update() 270 262 271 272 263 def onInnerRingMask(self, event=None): 273 264 """ … … 276 267 event.Skip() 277 268 from AnnulusSlicer import CircularMask 278 if event != None:269 if event != None: 279 270 self.onClearSlicer(event) 280 281 self.slicer _z += 1282 self.slicer = CircularMask(self,self.subplot,zorder=self.slicer_z, side=True)271 self.slicer_z += 1 272 self.slicer = CircularMask(self,self.subplot, 273 zorder=self.slicer_z, side=True) 283 274 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 284 275 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 285 286 276 self.update() 287 277 self.slicer_mask = self.slicer.update() 288 278 289 290 279 def onOuterRingMask(self, event=None): 291 280 """ … … 294 283 event.Skip() 295 284 from AnnulusSlicer import CircularMask 296 if event != None:285 if event != None: 297 286 self.onClearSlicer(event) 298 299 self.slicer _z += 1300 self.slicer = CircularMask(self,self.subplot,zorder=self.slicer_z, side=False)287 self.slicer_z += 1 288 self.slicer = CircularMask(self,self.subplot, 289 zorder=self.slicer_z, side=False) 301 290 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 302 291 self.subplot.set_xlim(self.data.xmin, self.data.xmax) … … 308 297 Add new mask to old mask 309 298 """ 310 if not self.slicer ==None:299 if not self.slicer == None: 311 300 data = Data2D() 312 301 data = self.data 313 302 self.slicer_mask = self.slicer.update() 314 303 data.mask = self.data.mask & self.slicer_mask 315 316 304 self._check_display_mask(data.mask, event) 317 305 … … 334 322 mask = self.data.mask 335 323 mask[self.slicer_mask==False] = True 336 337 324 self._check_display_mask(mask, event) 338 325 … … 342 329 """ 343 330 self.slicer_z += 1 344 self.slicer = BoxMask(self, self.subplot, zorder=self.slicer_z, side=True) 331 self.slicer = BoxMask(self, self.subplot, 332 zorder=self.slicer_z, side=True) 345 333 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 346 334 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 347 348 335 mask = copy.deepcopy(self.default_mask) 349 336 self.data.mask = mask 350 351 337 # update mask plot 352 338 self._check_display_mask(mask, event) … … 357 343 """ 358 344 self.slicer_z += 1 359 self.slicer = BoxMask(self, self.subplot, zorder=self.slicer_z, side=True) 345 self.slicer = BoxMask(self, self.subplot, 346 zorder=self.slicer_z, side=True) 360 347 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 361 348 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 362 363 349 #mask = copy.deepcopy(self.default_mask) 364 350 mask = numpy.ones(len(self.data.mask), dtype=bool) 365 351 self.data.mask = mask 366 367 352 # update mask plot 368 353 self._check_display_mask(mask, event) … … 372 357 Clear the slicer on the plot 373 358 """ 374 if not self.slicer ==None:359 if not self.slicer == None: 375 360 self.slicer.clear() 376 361 self.subplot.figure.canvas.draw() … … 396 381 self.update() 397 382 self.slicer.update() 398 wx.PostEvent(self.parent, StatusEvent(status=\399 "Plotter2D._setSlicer %s"%self.slicer.__class__.__name__))383 msg = "Plotter2D._setSlicer %s"%self.slicer.__class__.__name__ 384 wx.PostEvent(self.parent, StatusEvent(status=msg)) 400 385 # Post slicer event 401 386 event = self._getEmptySlicerEvent() 402 387 event.type = self.slicer.__class__.__name__ 403 404 388 event.obj_class = self.slicer.__class__ 405 389 event.params = self.slicer.get_params() … … 424 408 """ 425 409 # the case of liitle numbers of True points 426 if (len(mask[mask]) <10 and self.data !=None):410 if (len(mask[mask]) < 10 and self.data != None): 427 411 self.ShowMessage() 428 412 mask = copy.deepcopy(self.mask) … … 430 414 else: 431 415 self.mask = mask 432 433 416 # make temperary data to plot 434 417 temp_mask = numpy.zeros(len(mask)) … … 445 428 self.slicer.clear() 446 429 self.slicer = None 447 448 430 # Post slicer None event 449 431 event = self._getEmptySlicerEvent() 450 432 wx.PostEvent(self, event) 451 452 #replot453 ##This method not alway updating the plot(?): use manual plot454 #self.newplot=Data2D(image=temp_data.data)455 #self.newplot.setValues(temp_data)456 #self.plotpanel.add_image(self.newplot)457 458 433 459 434 ##use this method … … 466 441 zmin = min(self.data.data[self.data.data>0]) 467 442 #plot 468 plot = self.plotpanel.image(data= 443 plot = self.plotpanel.image(data=temp_mask, 469 444 qx_data=self.data.qx_data, 470 445 qy_data=self.data.qy_data, 471 xmin= 472 xmax= 473 ymin= 474 ymax= 475 zmin= 476 zmax= 477 cmap= 478 color=0, symbol=0,label=self.data.name)446 xmin=self.data.xmin, 447 xmax=self.data.xmax, 448 ymin=self.data.ymin, 449 ymax=self.data.ymax, 450 zmin=zmin, 451 zmax=zmax, 452 cmap=self.cmap, 453 color=0, symbol=0, label=self.data.name) 479 454 # axis labels 480 455 self.plotpanel.axes[0].set_xlabel('$\\rm{Q}_{x}(A^{-1})$') 481 456 self.plotpanel.axes[0].set_ylabel('$\\rm{Q}_{y}(A^{-1})$') 482 483 457 self.plotpanel.render() 484 458 self.plotpanel.subplot.figure.canvas.draw_idle() 485 486 459 487 460 def _getEmptySlicerEvent(self): … … 495 468 self.innercircle_rb.SetValue(False) 496 469 self.outercircle_rb.SetValue(False) 497 498 470 return SlicerEvent(type=None, 499 471 params=None, 500 472 obj_class=None) 501 473 502 def _draw_model(self, event):474 def _draw_model(self, event): 503 475 """ 504 476 on_close, update the model2d plot … … 516 488 self.plotpanel.axes_frozen = False 517 489 518 def onMouseMotion(self, event):490 def onMouseMotion(self, event): 519 491 """ 520 492 """ … … 529 501 """ 530 502 """ 531 def __init__(self, parent, id = -1, color = None, dpi =None, **kwargs):503 def __init__(self, parent, id=-1, color=None, dpi=None, **kwargs): 532 504 """ 533 505 """ … … 604 576 """ 605 577 # Initialize the Frame object 606 wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850))607 578 wx.Frame.__init__(self, parent, id, title, 579 wx.DefaultPosition, wx.Size(950, 850)) 608 580 # Panel for 1D plot 609 self.plotpanel 581 self.plotpanel = Maskplotpanel(self, -1, style=wx.RAISED_BORDER) 610 582 611 583 class ViewApp(wx.App): -
guiframe/local_perspectives/plotting/plotting.py
r4e9583c r32c0841 92 92 pass 93 93 94 95 94 def _on_plot_event(self, event): 96 95 """ … … 111 110 if hasattr(event.plot, "group_id"): 112 111 ## if same group_id used the same panel to plot 113 if not event.plot.group_id ==None \114 and event.plot.group_id ==panel.group_id:112 if not event.plot.group_id == None \ 113 and event.plot.group_id == panel.group_id: 115 114 is_available = True 116 117 115 panel._onEVT_1DREPLOT(event) 118 116 self.parent.show_panel(panel.uid) … … 120 118 # Check that the plot panel has no group ID 121 119 ## Use a panel with group_id ==None to plot 122 123 if panel.group_id==None: 120 if panel.group_id == None: 124 121 is_available = True 125 122 panel._onEVT_1DREPLOT(event) 126 123 self.parent.show_panel(panel.uid) 127 128 124 # Create a new plot panel if none was available 129 125 if not is_available: 130 126 #print"event.plot",hasattr(event.plot,'data') 131 if not hasattr(event.plot, 'data'):127 if not hasattr(event.plot, 'data'): 132 128 from Plotter1D import ModelPanel1D 133 129 ## get the data representation label of the data to plot 134 130 ## when even the user select "change scale" 135 if hasattr(event.plot, "xtransform"):131 if hasattr(event.plot, "xtransform"): 136 132 xtransform = event.plot.xtransform 137 133 else: 138 xtransform = None134 xtransform = None 139 135 140 if hasattr(event.plot, "ytransform"):141 ytransform =event.plot.ytransform136 if hasattr(event.plot, "ytransform"): 137 ytransform = event.plot.ytransform 142 138 else: 143 ytransform =None139 ytransform = None 144 140 ## create a plotpanel for 1D Data 145 new_panel = ModelPanel1D(self.parent, -1,xtransform=xtransform, 146 ytransform=ytransform, style=wx.RAISED_BORDER) 147 141 new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform, 142 ytransform=ytransform, style=wx.RAISED_BORDER) 148 143 else: 149 144 ##Create a new plotpanel for 2D data 150 145 from Plotter2D import ModelPanel2D 151 new_panel = ModelPanel2D(self.parent, id = -1, data2d=event.plot,style=wx.RAISED_BORDER)152 146 new_panel = ModelPanel2D(self.parent, id = -1, 147 data2d=event.plot, style=wx.RAISED_BORDER) 153 148 ## Set group ID if available 154 149 ## Assign data properties to the new create panel 155 150 group_id_str = '' 156 151 if hasattr(event.plot, "group_id"): 157 if not event.plot.group_id ==None:152 if not event.plot.group_id == None: 158 153 new_panel.group_id = event.plot.group_id 159 154 group_id_str = ' [%s]' % event.plot.group_id 160 161 155 if hasattr(event, "title"): 162 156 new_panel.window_caption = event.title 163 157 new_panel.window_name = event.title 164 165 158 event_id = self.parent.popup_panel(new_panel) 166 159 #remove the default item in the menu 167 160 if len(self.plot_panels) == 0: 168 161 self.menu.RemoveItem(self.menu.FindItemByPosition(0)) 169 170 162 self.menu.Append(event_id, new_panel.window_caption, 171 163 "Show %s plot panel" % new_panel.window_caption) -
guiframe/local_perspectives/plotting/sectorMask.py
rd955bf19 r32c0841 2 2 import math 3 3 import wx 4 from copy import deepcopy 5 4 #from copy import deepcopy 6 5 from BaseInteractor import _BaseInteractor 7 from SectorSlicer import SideInteractor, LineInteractor 6 from SectorSlicer import SideInteractor 7 from SectorSlicer import LineInteractor 8 8 from sans.guicomm.events import SlicerParameterEvent 9 9 … … 12 12 Draw a sector slicer.Allow to find the data 2D inside of the sector lines 13 13 """ 14 def __init__(self,base,axes,color='gray', zorder=3, side = False): 15 14 def __init__(self, base, axes, color='gray', zorder=3, side=False): 15 """ 16 """ 16 17 _BaseInteractor.__init__(self, base, axes, color=color) 17 18 ## Class initialization … … 23 24 24 25 ## compute qmax limit to reset the graph 25 x = math.pow(max(self.base.data.xmax,math.fabs(self.base.data.xmin)),2) 26 y = math.pow(max(self.base.data.ymax,math.fabs(self.base.data.ymin)),2) 27 self.qmax= math.sqrt(x + y) 26 x = math.pow(max(self.base.data.xmax, 27 math.fabs(self.base.data.xmin)), 2) 28 y = math.pow(max(self.base.data.ymax, 29 math.fabs(self.base.data.ymin)), 2) 30 self.qmax = math.sqrt(x + y) 28 31 ## Number of points on the plot 29 32 self.nbins = 20 30 33 ## Angle of the middle line 31 self.theta2 = math.pi/334 self.theta2 = math.pi/3 32 35 ## Absolute value of the Angle between the middle line and any side line 33 self.phi =math.pi/1236 self.phi = math.pi/12 34 37 35 38 ## Middle line 36 self.main_line = LineInteractor(self, self.base.subplot, color='blue', zorder=zorder, r=self.qmax,37 theta=self.theta2)39 self.main_line = LineInteractor(self, self.base.subplot, color='blue', 40 zorder=zorder, r=self.qmax, theta=self.theta2) 38 41 self.main_line.qmax = self.qmax 39 42 ## Right Side line 40 self.right_line= SideInteractor(self, self.base.subplot,color='gray', zorder=zorder, 41 r=self.qmax, 42 phi= -1*self.phi, 43 theta2=self.theta2) 43 self.right_line = SideInteractor(self, self.base.subplot, color='gray', 44 zorder=zorder, r=self.qmax, phi= -1*self.phi, 45 theta2=self.theta2) 44 46 self.right_line.qmax = self.qmax 45 47 ## Left Side line 46 self.left_line= SideInteractor(self, self.base.subplot,color='gray', zorder=zorder, 47 r=self.qmax, 48 phi= self.phi, 49 theta2=self.theta2) 48 self.left_line = SideInteractor(self, self.base.subplot, color='gray', 49 zorder=zorder, r=self.qmax, phi= self.phi, 50 theta2=self.theta2) 50 51 self.left_line.qmax = self.qmax 51 52 ## draw the sector 52 53 self.update() 53 54 self._post_data() 54 55 55 56 56 def clear(self): … … 65 65 #self.base.Unbind(EVT_SLICER_PARS) 66 66 67 68 67 def update(self): 69 68 """ … … 72 71 """ 73 72 # Update locations 74 ## Check if the middle line was dragged and update the picture accordingly 73 ## Check if the middle line was dragged and 74 #update the picture accordingly 75 75 if self.main_line.has_move: 76 76 self.main_line.update() 77 self.right_line.update( delta=-self.left_line.phi/2,78 mline= self.main_line.theta)79 self.left_line.update( delta =self.left_line.phi/2,80 mline= self.main_line.theta)77 self.right_line.update(delta=-self.left_line.phi/2, 78 mline=self.main_line.theta) 79 self.left_line.update(delta=self.left_line.phi/2, 80 mline=self.main_line.theta) 81 81 ## Check if the left side has moved and update the slicer accordingly 82 82 if self.left_line.has_move: 83 83 self.main_line.update() 84 self.left_line.update( 84 self.left_line.update(phi=None, delta=None, mline=self.main_line , 85 85 side=True, left=True ) 86 self.right_line.update( phi= self.left_line.phi, delta= None, 87 mline= self.main_line, side= True, 88 left=False, right= True ) 89 ## Check if the right side line has moved and update the slicer accordingly 86 self.right_line.update(phi=self.left_line.phi, delta=None, 87 mline=self.main_line, side=True, 88 left=False, right=True) 89 ## Check if the right side line has moved and 90 #update the slicer accordingly 90 91 if self.right_line.has_move: 91 92 self.main_line.update() 92 self.right_line.update( 93 side=True, left=False, right=True 94 self.left_line.update( 95 mline=self.main_line, side=True, left=False 93 self.right_line.update(phi=None, delta=None, mline=self.main_line, 94 side=True, left=False, right=True) 95 self.left_line.update(phi=self.right_line.phi, delta=None, 96 mline=self.main_line, side=True, left=False) 96 97 #if self.is_inside != None: 97 98 out = self._post_data() … … 125 126 phimax = self.left_line.phi + self.main_line.theta 126 127 127 mask = Sectorcut(phi_min= phimin, phi_max= phimax) 128 128 mask = Sectorcut(phi_min=phimin, phi_max=phimax) 129 129 if self.is_inside: 130 out = (mask(data) ==False)130 out = (mask(data) == False) 131 131 else: 132 132 out = (mask(data)) … … 147 147 self._post_data() 148 148 149 150 149 def restore(self): 151 150 """ … … 162 161 pass 163 162 164 165 163 def set_cursor(self, x, y): 166 164 pass 167 168 165 169 166 def get_params(self): … … 178 175 ## angle of the middle line 179 176 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 180 raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi) 181 177 msg = "Phi left and phi right are " 178 msg += "different %f, %f" % (self.left_line.phi, 179 self.right_line.phi) 180 raise ValueError, msg 182 181 params["Phi"] = self.main_line.theta 183 182 params["Delta_Phi"] = math.fabs(self.left_line.phi) … … 193 192 """ 194 193 main = params["Phi"] 195 phi = math.fabs(params["Delta_Phi"] 196 197 self.main_line.theta = main194 phi = math.fabs(params["Delta_Phi"]) 195 196 self.main_line.theta = main 198 197 ## Reset the slicer parameters 199 198 self.main_line.update() 200 self.right_line.update( phi=phi,delta=None, mline=self.main_line, 201 side=True, right=True ) 202 self.left_line.update( phi=phi, delta=None, mline=self.main_line, side=True ) 199 self.right_line.update(phi=phi, delta=None, mline=self.main_line, 200 side=True, right=True) 201 self.left_line.update(phi=phi, delta=None, 202 mline=self.main_line, side=True) 203 203 ## post the new corresponding data 204 204 self._post_data() -
guiframe/local_perspectives/plotting/slicerpanel.py
rd955bf19 r32c0841 3 3 import wx 4 4 import wx.lib.newevent 5 from copy import deepcopy 6 5 #from copy import deepcopy 7 6 from sans.guiframe.utils import format_number 8 from sans.guicomm.events import SlicerParameterEvent,EVT_SLICER_PARS,EVT_SLICER 9 7 from sans.guicomm.events import SlicerParameterEvent 8 from sans.guicomm.events import EVT_SLICER_PARS 9 from sans.guicomm.events import EVT_SLICER 10 10 11 11 … … 20 20 ## Title to appear on top of the window 21 21 window_caption = "Slicer Panel" 22 23 22 CENTER_PANE = False 24 23 25 def __init__(self, parent,id=-1,type=None,base=None, params={}, *args, **kwargs): 26 wx.Panel.__init__(self, parent,id, *args, **kwargs) 24 def __init__(self, parent, id=-1, type=None, base=None, 25 params=None, *args, **kwargs): 26 wx.Panel.__init__(self, parent, id, *args, **kwargs) 27 27 ## Initialization of the class 28 self.base= base 28 self.base = base 29 if params is None: 30 params = {} 29 31 self.params = params 30 32 self.parent = parent … … 32 34 self.listeners = [] 33 35 self.parameters = [] 34 35 self.bck = wx.GridBagSizer(5,5) 36 self.bck = wx.GridBagSizer(5, 5) 36 37 self.SetSizer(self.bck) 37 if type==None and params==None: 38 title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT) 39 self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 38 if type == None and params == None: 39 label = "Right-click on 2D plot for slicer options" 40 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 41 self.bck.Add(title, (0, 0), (1, 2), 42 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 40 43 else: 41 self.set_slicer( 44 self.set_slicer(type, params) 42 45 ## Bindings 43 46 self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) 44 47 self.parent.Bind(EVT_SLICER_PARS, self.onParamChange) 45 46 48 47 49 def onEVT_SLICER(self, event): … … 54 56 """ 55 57 event.Skip() 56 if event.obj_class ==None:58 if event.obj_class == None: 57 59 self.set_slicer(None, None) 58 60 else: … … 65 67 self.bck.Clear(True) 66 68 self.type = type 67 if type==None: 68 title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT) 69 self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 69 if type == None: 70 label = "Right-click on 2D plot for slicer options" 71 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 72 self.bck.Add(title, (0, 0), (1, 2), 73 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 70 74 else: 71 title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT) 72 self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 73 75 title = wx.StaticText(self, -1, "Slicer Parameters", 76 style=wx.ALIGN_LEFT) 77 self.bck.Add(title, (0, 0), (1, 2), 78 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 74 79 n = 1 75 80 self.parameters = [] 76 81 keys = params.keys() 77 82 keys.sort() 78 79 83 for item in keys: 80 if not 84 if not item.lower() in ["errors", "count"]: 81 85 n += 1 82 86 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 83 self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 84 ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 85 ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 87 self.bck.Add(text, (n-1, 0), 88 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 89 ctl = wx.TextCtrl(self, -1, size=(80, 20), 90 style=wx.TE_PROCESS_ENTER) 91 hint_msg = "Modify the value of %s to change " 92 hint_msg += "the 2D slicer" % item 93 ctl.SetToolTipString(hint_msg) 86 94 ctl.SetValue(str(format_number(params[item]))) 87 88 95 self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 89 96 ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 90 97 ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 91 92 98 self.parameters.append([item, ctl]) 93 self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border =0)99 self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border=0) 94 100 for item in keys: 95 101 if item.lower() in ["errors", "count"]: 96 102 n += 1 97 text = wx.StaticText(self, -1, item+": ", style=wx.ALIGN_LEFT) 98 self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 99 ctl = wx.StaticText(self, -1, str(format_number(params[item])), style=wx.ALIGN_LEFT) 103 text = wx.StaticText(self, -1, item + ": ", 104 style=wx.ALIGN_LEFT) 105 self.bck.Add(text, (n-1, 0), 106 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 107 border=15) 108 ctl = wx.StaticText(self, -1, 109 str(format_number(params[item])), 110 style=wx.ALIGN_LEFT) 100 111 ctl.SetToolTipString("Result %s" % item) 101 self.bck.Add(ctl, (n-1,1), flag=wx.TOP|wx.BOTTOM, border = 0) 102 112 self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border=0) 103 113 self.bck.Layout() 104 114 #self.bck.Fit(self) … … 113 123 widget = evt.GetEventObject() 114 124 # Select the whole control, after this event resolves 115 wx.CallAfter(widget.SetSelection, -1, -1)125 wx.CallAfter(widget.SetSelection, -1, -1) 116 126 return 117 118 127 119 128 def onParamChange(self, evt): … … 145 154 item[1].Refresh() 146 155 147 if has_error ==False:156 if has_error == False: 148 157 # Post parameter event 149 158 ## base is guiframe is this case
Note: See TracChangeset
for help on using the changeset viewer.