Changeset 0f6d05f8 in sasview for guiframe/local_perspectives
- Timestamp:
- Jan 14, 2009 12:04:11 AM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- d1dd9d4
- Parents:
- 47d10a2
- Location:
- guiframe/local_perspectives/plotting
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/Plotter2D.py
rac9a5f6 r0f6d05f8 394 394 self.onClearSlicer(event) 395 395 wx.PostEvent(self.parent, InternalEvent(slicer= BoxSum)) 396 from BoxParameters import SlicerParameterPanel396 from SlicerParameters import SlicerParameterPanel 397 397 398 398 dialog = SlicerParameterPanel(self.parent, -1, "Slicer Parameters") … … 448 448 wx.PostEvent(self.parent, StatusEvent(status="Image is in %s scale"%self.scale)) 449 449 450 451 452 453 450 """ 451 #TODO: this name should be changed to something more appropriate 452 # Don't forget that changing this name will mean changing code 453 # in plotting.py 454 455 # Update the plottable with the new data 456 457 #TODO: we should have a method to do this, 458 # something along the lines of: 459 # plottable1.update_data_from_plottable(plottable2) 460 461 self.plots[event.plot.name].xmin = event.plot.xmin 462 self.plots[event.plot.name].xmax = event.plot.xmax 463 self.plots[event.plot.name].ymin = event.plot.ymin 464 self.plots[event.plot.name].ymax = event.plot.ymax 465 self.plots[event.plot.name].data = event.plot.data 466 self.plots[event.plot.name].err_data = event.plot.err_data 467 """ -
guiframe/local_perspectives/plotting/SlicerParameters.py
ref0c170 r0f6d05f8 83 83 iy += 1 84 84 ix = 0 85 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 86 #self.bck.Add(text, (iy,ix), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 87 self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 88 ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 89 90 ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 91 92 ix = 1 93 ctl.SetValue(format_number(str(params[item]))) 94 self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 95 ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 96 self.parameters.append([item, ctl]) 97 #self.bck.Add(ctl, (iy,ix), flag=wx.TOP|wx.BOTTOM, border = 0) 98 self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 99 100 ix =3 101 self.bck.Add((20,20), (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 85 if not item in ["count","errors"]: 86 87 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 88 #self.bck.Add(text, (iy,ix), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 89 self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 90 ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 91 92 ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 93 94 ix = 1 95 ctl.SetValue(format_number(str(params[item]))) 96 self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 97 ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 98 self.parameters.append([item, ctl]) 99 #self.bck.Add(ctl, (iy,ix), flag=wx.TOP|wx.BOTTOM, border = 0) 100 self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 101 102 ix =3 103 self.bck.Add((20,20), (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 104 else: 105 text = wx.StaticText(self, -1, item+ " : ", style=wx.ALIGN_LEFT) 106 self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 107 ctl =wx.StaticText(self, -1, format_number(str(params[item])), style=wx.ALIGN_LEFT) 108 ix =1 109 self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 102 110 iy +=1 103 111 ix = 1 -
guiframe/local_perspectives/plotting/boxSlicer.py
rdd40217 r0f6d05f8 17 17 import wx 18 18 19 def find_intersection(a1= 2, a2= -0.5,b1= 1,b2= 1 ): 20 """ @ return x, y coordinates of an intersection between 2 lines 21 @param a1: the slope of the first line 22 @param a2 : the slope of the 2nd line 23 @param b1 : line intercept of the 1 st line 24 @param b2 : line intercept of the 2 nd ligne 25 @note 1st line equation is y= a1*x +b1 ; 2nd line equation is y= a2*x +b2 26 """ 27 x= ( b2- b1) /(a1- a2) 28 y= ( -a2*b1 + a1*b2 )/(a1 -a2) 29 return x, y 19 30 20 class BoxInteractor(_BaseInteractor): 31 21 """ … … 40 30 self.qmax = self.base.qmax 41 31 self.connect = self.base.connect 42 self.xmin= -1* x_min 43 self.ymin= -1* y_min 44 45 self.xmax= x_max 46 self.ymax= y_max 47 32 self.x= x_max 33 self.y= y_max 34 48 35 self.theta2= math.pi/3 49 36 ## Number of points on the plot … … 51 38 self.count=0 52 39 self.error=0 53 self.main_line = LineInteractor(self, self.base.subplot,color='orange', 54 zorder=zorder, ymin=y_min ,ymax=y_max, 55 theta= self.theta2) 56 self.main_line.qmax = self.base.qmax 40 57 41 self.left_line = VerticalLine(self, self.base.subplot,color='blue', 58 42 zorder=zorder, 59 mline= self.main_line, 60 ymin= self.ymin , 61 ymax= self.ymax , 62 xmin=self.xmin, 63 xmax=self.xmin, 64 theta2= self.theta2) 43 ymin= -self.y , 44 ymax= self.y , 45 xmin= -self.x, 46 xmax= -self.x) 65 47 self.left_line.qmax = self.base.qmax 66 48 67 49 self.right_line= VerticalLine(self, self.base.subplot,color='black', 68 50 zorder=zorder, 69 mline= self.main_line, 70 ymin= self.ymin , 71 ymax= self.ymax, 72 xmin= self.xmax, 73 xmax= self.xmax, 74 theta2= self.theta2) 51 ymin= -self.y , 52 ymax= self.y, 53 xmin= self.x, 54 xmax= self.x) 75 55 self.right_line.qmax = self.base.qmax 76 56 77 57 self.top_line= HorizontalLine(self, self.base.subplot,color='green', 78 58 zorder=zorder, 79 mline= self.main_line, 80 xmin=self.right_line.x1, 81 xmax=self.left_line.x1, 82 ymin=self.right_line.y1, 83 ymax=self.left_line.y1) 59 xmin= -self.x, 60 xmax= self.x, 61 ymin= self.y, 62 ymax= self.y) 84 63 self.top_line.qmax= self.base.qmax 85 64 86 65 self.bottom_line= HorizontalLine(self, self.base.subplot,color='gray', 87 66 zorder=zorder, 88 mline= self.main_line, 89 xmin=self.right_line.x2, 90 xmax=self.left_line.x2, 91 ymin=self.right_line.y2, 92 ymax=self.left_line.y2) 67 xmin= -self.x, 68 xmax= self.x, 69 ymin= -self.y, 70 ymax= -self.y) 93 71 self.bottom_line.qmax= self.base.qmax 94 72 95 73 self.update() 96 #self._post_data()74 self._post_data() 97 75 98 76 # Bind to slice parameter events … … 104 82 event.Skip() 105 83 if event.type == self.__class__.__name__: 106 #self.set_params(event.params)84 self.set_params(event.params) 107 85 self.base.update() 108 86 … … 127 105 def clear(self): 128 106 self.clear_markers() 129 130 131 self.main_line.clear() 107 self.left_line.clear() 108 self.right_line.clear() 109 self.top_line.clear() 110 self.bottom_line.clear() 132 111 #self.base.connect.disconnect() 133 112 self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) … … 139 118 """ 140 119 141 if self.main_line.has_move:142 143 self.main_line.update()144 self.left_line.update(145 xmin= self.xmin,146 xmax= self.xmin,147 ymin= self.ymin,148 ymax=self.ymax149 )150 self.right_line.update(151 xmin= self.xmax,152 xmax= self.xmax,153 ymin= self.ymin,154 ymax=self.ymax)155 self.top_line.update(xmin= self.right_line.x1,156 xmax= self.left_line.x1,157 ymin= self.right_line.y1,158 ymax= self.left_line.y1)159 self.bottom_line.update(xmin= self.right_line.x2,160 xmax= self.left_line.x2,161 ymin= self.right_line.y2,162 ymax= self.left_line.y2)163 120 if self.top_line.has_move: 164 print "top has moved",self.left_line.slope, self.top_line.slope 165 x2, y2= find_intersection(a1= self.left_line.slope, 166 a2= self.top_line.slope, 167 b1= self.left_line.b, 168 b2= self.top_line.b ) 169 print "x, y max: ",x2,y2 170 x1, y1= find_intersection(a1= self.right_line.slope, 171 a2= self.top_line.slope, 172 b1= self.right_line.b, 173 b2= self.top_line.b ) 174 print "x, y min: ",x1 ,y1 175 self.top_line.update(xmin= x2, 176 ymin= y2, 177 xmax= x1, 178 ymax= y1) 179 180 self.bottom_line.update(xmin= -x2, 181 ymin= -y2, 182 xmax= -x1, 183 ymax= -y1) 184 self.left_line.update(xmin= -x1, 185 ymin= -y1, 186 xmax= x2, 187 ymax= y2, 188 translation= True) 189 self.right_line.update( 190 xmin= -x2, 191 ymin= -y2, 192 xmax= x1, 193 ymax= y1, 194 translation= True) 195 print "top has moved",self.left_line.slope, self.top_line.slope 196 x2, y2= find_intersection(a1= self.main_line.slope, 197 a2= self.top_line.slope, 198 b1= self.main_line.b, 199 b2= self.top_line.b ) 200 print "main x, y max: ",x2,y2 201 x1, y1= find_intersection(a1= self.main_line.slope, 202 a2= self.bottom_line.slope, 203 b1= self.main_line.b, 204 b2= self.bottom_line.b ) 205 print "main x, y min: ",x1,y1 206 self.main_line.update(x1= -x2, 207 y1= -y2, 208 x2= x2, 209 y2= y2, 210 translation= True) 121 print"top has moved" 122 self.top_line.update() 123 self.bottom_line.update(ymin= -self.top_line.y1, 124 ymax= -self.top_line.y2) 125 self.left_line.update(ymin= -self.top_line.y1, 126 ymax= -self.top_line.y2) 127 self.right_line.update(ymin= -self.top_line.y1, 128 ymax= -self.top_line.y2) 129 211 130 if self.bottom_line.has_move: 212 213 print "bottom has moved",self.left_line.slope, self.bottom_line.slope 214 x2, y2= find_intersection(a1= self.left_line.slope, 215 a2= self.bottom_line.slope, 216 b1= self.left_line.b, 217 b2= self.bottom_line.b ) 218 print "x, y max: ",x2,y2 219 x1, y1= find_intersection(a1= self.right_line.slope, 220 a2= self.bottom_line.slope, 221 b1= self.right_line.b, 222 b2= self.bottom_line.b ) 223 print "x, y min: ",x1 ,y1 224 self.bottom_line.update(xmin= x2, 225 ymin= y2, 226 xmax= x1, 227 ymax= y1) 228 229 self.top_line.update(xmin= -x2, 230 ymin= -y2, 231 xmax= -x1, 232 ymax= -y1) 233 self.left_line.update(xmin= -x1, 234 ymin= -y1, 235 xmax= x2, 236 ymax= y2, 237 translation= True) 238 self.right_line.update( 239 xmin= -x2, 240 ymin= -y2, 241 xmax= x1, 242 ymax= y1, 243 translation= True) 244 print "bottom has moved",self.left_line.slope, self.bottom_line.slope 245 x2, y2= find_intersection(a1= self.main_line.slope, 246 a2= self.bottom_line.slope, 247 b1= self.main_line.b, 248 b2= self.bottom_line.b ) 249 print "main x, y max: ",x2,y2 250 x1, y1= find_intersection(a1= self.main_line.slope, 251 a2= self.top_line.slope, 252 b1= self.main_line.b, 253 b2= self.top_line.b ) 254 print "main x, y min: ",x1,y1 255 self.main_line.update(x1= -x2, 256 y1= -y2, 257 x2= x2, 258 y2= y2, 259 translation= True) 131 print "bottom has move" 132 self.bottom_line.update() 133 self.top_line.update(ymin= -self.bottom_line.y1, 134 ymax= -self.bottom_line.y2) 135 self.left_line.update(ymin= self.bottom_line.y1, 136 ymax= self.top_line.y1) 137 self.right_line.update(ymin= self.bottom_line.y1, 138 ymax=self.top_line.y1) 139 260 140 if self.left_line.has_move: 261 print "left_line has moved",self.left_line.slope, self.top_line.slope 262 x2, y2= find_intersection(a1= self.left_line.slope, 263 a2= self.top_line.slope, 264 b1= self.left_line.b, 265 b2= self.top_line.b ) 266 print "main x, y max: ",x2,y2 267 x1, y1= find_intersection(a1= self.left_line.slope, 268 a2= self.bottom_line.slope, 269 b1= self.left_line.b, 270 b2= self.bottom_line.b ) 271 self.left_line.update(xmin = x1, 272 xmax = x2, 273 ymin= y1, 274 ymax= y2, 275 translation=True) 276 277 self.right_line.update(xmin = -x1, 278 xmax = -x2, 279 ymin= -y1, 280 ymax= -y2, 281 translation=True) 282 283 self.bottom_line.update(xmin= x1, 284 ymin= y1, 285 xmax= -x2, 286 ymax= -y2) 287 288 self.top_line.update(xmin= x2, 289 ymin= y2, 290 xmax= -x1, 291 ymax= -y1) 292 print "initial xmin", self.xmin 293 self.xmin= math.sqrt(math.pow((self.main_line.x2 - self.left_line.x2),2)\ 294 +math.pow((self.main_line.y2 - self.left_line.y2),2)) 295 296 print "new xmin ", self.xmin, self.main_line.x2 , self.left_line.x2 141 142 self.left_line.update() 143 self.right_line.update(xmin = - self.left_line.x1, 144 xmax = - self.left_line.x1) 145 self.bottom_line.update(xmin= self.left_line.x1, 146 xmax= self.right_line.x1) 147 self.top_line.update(xmin= self.left_line.x1, 148 xmax= self.right_line.x1) 149 297 150 if self.right_line.has_move: 298 print "right_line has moved",self.right_line.slope, self.top_line.slope 299 x2, y2= find_intersection(a1= self.right_line.slope, 300 a2= self.top_line.slope, 301 b1= self.right_line.b, 302 b2= self.top_line.b ) 303 print "main x, y max: ",x2,y2 304 x1, y1= find_intersection(a1= self.right_line.slope, 305 a2= self.bottom_line.slope, 306 b1= self.right_line.b, 307 b2= self.bottom_line.b ) 308 self.right_line.update(xmin = x1, 309 xmax = x2, 310 ymin= y1, 311 ymax= y2, 312 translation=True) 313 314 self.left_line.update(xmin = -x1, 315 xmax = -x2, 316 ymin= -y1, 317 ymax= -y2, 318 translation=True) 319 320 self.bottom_line.update(xmin= x1, 321 ymin= y1, 322 xmax= -x2, 323 ymax= -y2) 324 325 self.top_line.update(xmin= x2, 326 ymin= y2, 327 xmax= -x1, 328 ymax= -y1) 151 152 self.right_line.update() 153 self.left_line.update(xmin = -self.right_line.x1, 154 xmax = -self.right_line.x1) 155 156 self.bottom_line.update(xmin= self.left_line.x1, 157 xmax= self.right_line.x1) 158 159 self.top_line.update(xmin= self.left_line.x1, 160 xmax= self.right_line.x1) 329 161 330 print "initial xmax", self.xmax 331 self.xmax= math.sqrt(math.pow((self.main_line.x2 - self.right_line.x2),2)\ 332 +math.pow((self.main_line.y2 - self.right_line.y2),2)) 333 print "new xmax",self.xmax 162 334 163 def save(self, ev): 335 164 """ … … 338 167 """ 339 168 self.base.freeze_axes() 340 self.inner_circle.save(ev) 341 self.outer_circle.save(ev) 169 self.left_line.save(ev) 170 self.right_line.save(ev) 171 self.top_line.save(ev) 172 self.bottom_line.save(ev) 342 173 343 174 def _post_data(self): 344 175 # Compute data 345 #data = self.base.data2D346 #from DataLoader.manipulations import Boxavg347 #radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2))348 #x_min= self.left_line.xmin349 #x_max= self.right_line.xmax350 #y_min= self.bottom_line.y351 #y_max= self.top_line.y352 #box = Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max)176 data = self.base.data2D 177 from DataLoader.manipulations import Boxavg 178 radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 179 x_min= self.left_line.x1 180 x_max= self.right_line.x1 181 y_min= self.bottom_line.y1 182 y_max= self.top_line.y1 183 box = Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 353 184 354 #self.count, self.error= box(self.base.data2D)355 356 print "post data"185 self.count, self.error= box(self.base.data2D) 186 187 #print "post data" 357 188 358 189 … … 363 194 event = SlicerParameters.SlicerParameterEvent() 364 195 event.type = self.__class__.__name__ 365 #event.params = self.get_params()196 event.params = self.get_params() 366 197 wx.PostEvent(self.base.parent, event) 367 198 … … 372 203 Restore the roughness for this layer. 373 204 """ 374 self.inner_circle.restore() 375 self.outer_circle.restore() 205 self.left_line.restore() 206 self.right_line.restore() 207 self.top_line.restore() 208 self.bottom_line.restore() 376 209 377 210 def move(self, x, y, ev): … … 386 219 def get_params(self): 387 220 params = {} 388 params["x 1"]= self.xmax389 params["y 1"]= self.ymin390 params["x2"]= self.xmin391 params[" y2"]= self.ymax392 params[" phi"] = self.main_line.theta221 params["x_max"]= math.fabs(self.right_line.x1) 222 params["y_max"]= math.fabs(self.top_line.x1) 223 224 params["errors"] = self.error 225 params["count"]= self.count 393 226 return params 394 227 395 228 def set_params(self, params): 396 self.xmax = params["x1"] 397 self.ymin = params["y1"] 398 self.xmin = params["x2"] 399 self.ymax = params["y2"] 400 theta = params["theta"] 401 print "theta setparams",theta 402 self.main_line.update(radius1= math.fabs(self.ymax), radius2= math.fabs(self.ymin), theta= theta) 403 self.left_line.update(xmin= -1*self.xmin) 404 self.right_line.update(xmin= self.xmax) 405 406 self.top_line.update(xmin= self.right_line.x1, 407 xmax= self.left_line.x1, 408 ymin= self.right_line.y1, 409 ymax= self.left_line.y1) 410 self.bottom_line.update(xmin= self.right_line.x2, 411 xmax= self.left_line.x2, 412 ymin= self.right_line.y2, 413 ymax= self.left_line.y2) 229 self.x = float(math.fabs(params["x_max"])) 230 self.y = float(math.fabs(params["y_max"] )) 231 232 self.left_line.update(xmin= -1*self.x, 233 xmax = -1*self.x, 234 ymin= -self.y, 235 ymax= self.y, 236 ) 237 self.right_line.update(xmin= self.x, 238 xmax = self.x, 239 ymin= -self.y, 240 ymax= self.y, 241 ) 242 self.top_line.update(xmin= -1*self.x, 243 xmax= self.x, 244 ymin= self.y, 245 ymax= self.y) 246 self.bottom_line.update(xmin= -1*self.x, 247 xmax= self.x, 248 ymin= -1*self.y, 249 ymax= -1*self.y) 414 250 self._post_data() 415 251 def freeze_axes(self): … … 427 263 """ 428 264 def __init__(self,base,axes,color='black', zorder=5,mline=None,ymin=None, ymax=None, y=0.5, 429 xmin=0.0,xmax=0.5, 430 theta2= math.pi/3 ): 265 xmin=0.0,xmax=0.5): 431 266 432 267 _BaseInteractor.__init__(self, base, axes, color=color) … … 445 280 self.save_y2= ymin 446 281 self.mline= mline 447 self.line = self.axes.plot([self.x1, self.x2],282 self.line = self.axes.plot([self.x1,-self.x1], 448 283 [self.y1,self.y2], 449 284 linestyle='-', marker='', … … 451 286 visible=True)[0] 452 287 453 self.slope= -1/math.tan(self.mline.theta)454 self.b= self.y1- self.slope* self.x1455 self.save_b= self.b456 print "slope from point",(self.y2- self.y1)/(self.x2- self.x1)457 print "my slope horizontal", self.slope458 print "b from point ", self.y2- self.slope*self.x2, self.b459 288 self.npts = 20 460 289 self.has_move=False … … 484 313 Draw the new roughness on the graph. 485 314 """ 486 self.slope= -1/math.tan(self.mline.theta)487 315 if xmin !=None: 488 self.x2 = xmin 489 if xmax !=None: 490 self.x1 = xmax 316 self.x1 = xmin 491 317 if ymin !=None: 492 self.y2 = ymin 493 if ymax != None: 494 self.y1 = ymax 495 self.b= self.y1- self.slope * self.x1 496 self.line.set(xdata=[self.x1,self.x2], 497 ydata=[self.y1,self.y2]) 318 self.y1 = ymin 319 self.line.set(xdata=[self.x1,-self.x1], 320 ydata=[self.y1,self.y1]) 498 321 499 322 … … 509 332 self.save_y1= self.y1 510 333 self.save_y2= self.y2 511 self.save_b= self.b334 512 335 513 336 self.base.freeze_axes() … … 526 349 self.y1 = self.save_y1 527 350 self.y2 = self.save_y2 528 self.b = self.save_b351 529 352 530 353 def move(self, x, y, ev): … … 532 355 Process move to a new position, making sure that the move is allowed. 533 356 """ 534 print "horizontal move x y " , x, y535 self. b = y - (-1/self.mline.slope) *x357 print "horizontal move x y " 358 self.y1= y 536 359 self.has_move=True 537 360 self.base.base.update() … … 561 384 """ 562 385 def __init__(self,base,axes,color='black', zorder=5, mline=None, ymin=0.0, 563 ymax=0.5,xmin=-0.5,xmax=0.5 ,564 theta2= math.pi/3):386 ymax=0.5,xmin=-0.5,xmax=0.5 387 ): 565 388 566 389 _BaseInteractor.__init__(self, base, axes, color=color) … … 568 391 self.axes = axes 569 392 570 self.theta2 = mline.theta 571 self.mline =mline 572 self.xmin= xmin 573 self.x1= mline.x1 + xmin*math.cos(math.pi/2 - self.theta2) 574 self.x2= mline.x2 + xmin*math.cos(math.pi/2 - self.theta2) 575 self.y1= mline.y1 - xmin*math.sin(math.pi/2 - self.theta2) 576 self.y2= mline.y2 - xmin*math.sin(math.pi/2 - self.theta2) 393 self.x1= xmax 394 self.x2= xmin 395 self.y1= ymax 396 self.y2= ymin 577 397 self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], 578 398 linestyle='-', marker='', … … 580 400 visible=True)[0] 581 401 582 583 self.slope= math.tan(self.mline.theta)584 print "vertical line intercetp ",self.y2- self.slope*self.x2, self.y1- self.slope* self.x1585 586 self.b = self.y1- self.slope* self.x1587 402 self.has_move=False 588 403 self.connect_markers([self.line]) … … 611 426 Draw the new roughness on the graph. 612 427 """ 613 614 self.slope= math.tan(self.mline.theta) 615 if translation: 616 if xmin!=None: 617 self.x2=xmin 618 self.xmin= xmin 619 if xmax!=None: 620 self.x1=xmax 621 if ymin!=None: 622 self.y2=ymin 623 if ymax!=None: 624 self.y1=ymax 625 self.line.set(xdata=[self.x1,self.x2], 626 ydata=[self.y1,self.y2]) 627 self.b= self.y1- self.slope * self.x1 628 return 629 630 self.x1= self.mline.x1 + self.xmin*math.cos(math.pi/2 - self.mline.theta) 631 self.x2= self.mline.x2 + self.xmin*math.cos(math.pi/2 - self.mline.theta) 632 self.y1= self.mline.y1 - self.xmin*math.sin(math.pi/2 - self.mline.theta) 633 self.y2= self.mline.y2 - self.xmin*math.sin(math.pi/2 - self.mline.theta) 634 self.line.set(xdata=[self.x1,self.x2], 635 ydata=[self.y1,self.y2]) 636 print "update slope ", (self.y2-self.y1)/(self.x2- self.x1) 637 #print "main slope", math.tan(self.mline.theta) 428 429 430 if xmin!=None: 431 self.x1=xmin 432 if ymin!=None: 433 self.y1=ymin 434 self.line.set(xdata=[self.x1,self.x1], 435 ydata=[self.y1,-self.y1]) 436 437 638 438 639 439 def save(self, ev): … … 671 471 672 472 # compute the b intercept of the vertical line 673 self. b=y - self.mline.slope *x473 self.x1= x 674 474 675 475 … … 703 503 704 504 705 class LineInteractor(_BaseInteractor):706 """707 Select an annulus through a 2D plot708 """709 def __init__(self,base,axes,color='black', zorder=5, ymin=1.0,ymax=1.0,theta=math.pi/4):710 711 _BaseInteractor.__init__(self, base, axes, color=color)712 self.markers = []713 self.axes = axes714 715 self.save_theta = theta716 self.theta= theta717 718 self.radius1 = math.fabs(ymax)719 self.radius2 = math.fabs(ymin)720 self.scale = 10.0721 722 # Inner circle723 self.x1= self.radius1*math.cos(self.theta)724 self.y1= self.radius1*math.sin(self.theta)725 self.x2= -1*self.radius2*math.cos(self.theta)726 self.y2= -1*self.radius2*math.sin(self.theta)727 728 self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2],729 linestyle='-', marker='',730 color=self.color,731 visible=True)[0]732 self.slope= math.tan(self.theta)733 self.b= math.fabs(self.y1- self.slope * self.x1)734 print "intercept main",math.fabs(self.y2- self.slope * self.x2),math.fabs(self.y1- self.slope * self.x1)735 self.npts = 20736 self.has_move=False737 self.connect_markers([self.line])738 self.update()739 740 def set_layer(self, n):741 742 self.layernum = n743 self.update()744 745 def clear(self):746 """747 Remove the line of the plot748 """749 self.clear_markers()750 try:751 self.line.remove()752 except:753 # Old version of matplotlib754 for item in range(len(self.axes.lines)):755 del self.axes.lines[0]756 757 758 759 def get_delta_angle(self):760 """761 return difference between initial angle and the final angle during762 rotation763 """764 return self.theta - self.save_theta765 766 def update(self,x1=None,767 y1=None,768 x2=None,769 y2=None,770 translation=False,771 xmin=None,vline=None, theta=None,radius1=None,radius2=None):772 """773 Draw a line given and angle relative to the x-axis and a radius774 @param theta: the angle realtive to the x-axis775 @param radius: the distance between the center and one end of the line776 """777 if translation:778 if x1 !=None:779 self.x1= x1780 if x2 !=None:781 self.x2= x2782 if y1 !=None:783 self.y1= y1784 if y2 !=None:785 self.y2= y2786 787 self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2])788 self.radius1= math.fabs(self.x1/math.cos(self.theta))789 self.radius2= math.fabs(self.x2/math.cos(self.theta))790 print "radius 1, radius2", self.radius1, self.radius2791 return792 793 if theta !=None:794 self.theta= theta795 if radius1 !=None:796 self.radius1 =radius1797 if radius2 !=None:798 self.radius2 =radius2799 print "update main line", math.degrees(self.theta),self.radius1, self.radius2800 print "smain radius 1 2", self.radius1, self.radius2801 self.x1= self.radius1*math.cos(self.theta)802 self.y1= self.radius1*math.sin(self.theta)803 self.x2= -1*self.radius2*math.cos(self.theta)804 self.y2= -1*self.radius2*math.sin(self.theta)805 print "init mainline sintercept ", self.y1 - math.tan(self.theta)*self.x1,\806 self.y2 - math.tan(self.theta)*self.x2807 print "main line slope ", (self.y2- self.y1)/(self.x2- self.x1)808 print "theta", math.tan(self.theta)809 self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2])810 811 812 813 def save(self, ev):814 """815 Remember the roughness for this layer and the next so that we816 can restore on Esc.817 """818 self.save_theta= self.theta819 self.base.freeze_axes()820 821 def moveend(self, ev):822 823 self.has_move=False824 self.base.moveend(ev)825 826 def restore(self):827 """828 Restore the roughness for this layer.829 """830 self.theta = self.save_theta831 832 def move(self, x, y, ev):833 """834 Process move to a new position, making sure that the move is allowed.835 """836 self.theta= math.atan2(y,x)837 self.slope= math.tan(self.theta)838 self.b= y - self.slope *x839 840 print "main move slope , theta, b", self.slope, self.theta, self.b841 842 #print "main_line previous theta --- next theta ",math.degrees(self.save_theta),math.degrees(self.theta)843 self.has_move=True844 self.base.base.update()845 846 847 def set_cursor(self, x, y):848 849 self.move(x, y, None)850 self.update()851 852 853 def get_params(self):854 """855 return params a dictionary containing values of paramters necessary to draw856 this line857 """858 params = {}859 params["ymax"] = self.radius1860 params["ymin"] = self.radius2861 params["theta"] = self.theta862 return params863 864 def set_params(self, params):865 """866 Draw the line given value contains by params867 @param params: dictionary containing name of parameters and their values868 """869 radius1 = params["ymax"]870 radius2 = params["ymin"]871 theta = params["theta"]872 self.update(x, theta= theta , radius1 = radius1 ,radius2 = radius2)873 874 875 876 877 -
guiframe/local_perspectives/plotting/boxSum.py
r92c2345 r0f6d05f8 221 221 params["y_min"] = self.bottom_line.y 222 222 params["y_max"] = self.top_line.y 223 223 params["count"] = self.count 224 params["errors"]= self.error 224 225 return params 225 226
Note: See TracChangeset
for help on using the changeset viewer.