Changeset c039589 in sasview for src/sas/guiframe/local_perspectives/plotting/Plotter2D.py
- Timestamp:
- Mar 5, 2015 2:37:00 PM (9 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:
- b40ad40
- Parents:
- 090e07e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/Plotter2D.py
r79492222 rc039589 3 3 #This software was developed by the University of Tennessee as part of the 4 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 5 #project funded by the US National Science Foundation. 6 6 # 7 7 #See the license text in license.txt … … 15 15 import math 16 16 import numpy 17 import logging 17 18 from sas.plottools.PlotPanel import PlotPanel 18 19 from sas.plottools.plottables import Graph 19 20 from sas.plottools.TextDialog import TextDialog 20 from sas.guiframe.events import StatusEvent 21 from sas.guiframe.events import StatusEvent 21 22 from sas.guiframe.events import NewPlotEvent 22 23 from sas.guiframe.events import PanelOnFocusEvent … … 25 26 from sas.guiframe.local_perspectives.plotting.binder import BindArtist 26 27 from Plotter1D import ModelPanel1D 27 from sas.plottools.toolbar import NavigationToolBar 28 from sas.plottools.toolbar import NavigationToolBar 28 29 from matplotlib.font_manager import FontProperties 29 30 from graphAppearance import graphAppearance … … 46 47 def __init__(self, canvas, parent=None): 47 48 NavigationToolBar.__init__(self, canvas=canvas, parent=parent) 48 49 49 50 def delete_option(self): 50 51 """ … … 52 53 """ 53 54 #delete reset button 54 self.DeleteToolByPos(0) 55 self.DeleteToolByPos(0) 55 56 #delete dragging 56 self.DeleteToolByPos(2) 57 self.DeleteToolByPos(2) 57 58 #delete unwanted button that configures subplot parameters 58 59 self.DeleteToolByPos(4) 59 60 60 61 def add_option(self): 61 62 """ … … 65 66 id_context = wx.NewId() 66 67 context_tip = 'Graph Menu' 67 context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 68 self.InsertSimpleTool(0, id_context, context, 69 context_tip, context_tip) 70 wx.EVT_TOOL(self, id_context, self.parent.onToolContextMenu) 68 context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 69 self.InsertSimpleTool(0, id_context, context, context_tip, context_tip) 70 wx.EVT_TOOL(self, id_context, self.parent.onToolContextMenu) 71 71 self.InsertSeparator(1) 72 72 #add print button 73 73 id_print = wx.NewId() 74 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 75 self.AddSimpleTool(id_print, print_bmp, 76 'Print', 'Activate printing') 74 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 75 self.AddSimpleTool(id_print, print_bmp, 'Print', 'Activate printing') 77 76 wx.EVT_TOOL(self, id_print, self.on_print) 78 79 77 78 80 79 class ModelPanel2D(ModelPanel1D): 81 80 """ 82 81 Plot panel for use with the GUI manager 83 82 """ 84 83 85 84 ## Internal name for the AUI manager 86 85 window_name = "plotpanel" … … 92 91 ## Group ID 93 92 group_id = None 94 95 96 def __init__(self, parent, id=-1, data2d=None, color =None,93 94 95 def __init__(self, parent, id=-1, data2d=None, color=None, 97 96 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 98 97 """ … … 106 105 ## Dictionary containing Plottables 107 106 self.plots = {} 108 ## Save reference of the current plotted 107 ## Save reference of the current plotted 109 108 self.data2D = data2d 110 109 ## Unique ID (from gui_manager) … … 120 119 ## Reference to the current slicer 121 120 self.slicer = None 122 ## event to send slicer info 121 ## event to send slicer info 123 122 self.Bind(EVT_INTERNAL, self._onEVT_INTERNAL) 124 123 125 124 self.axes_frozen = False 126 125 ## panel that contains result from slicer motion (ex: Boxsum info) … … 129 128 self.title_font = None 130 129 self.title_color = 'black' 131 ## Graph 130 ## Graph 132 131 self.graph = Graph() 133 132 self.graph.xaxis("\\rm{Q}", 'A^{-1}') 134 133 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 135 134 self.graph.render(self) 136 ## store default value of zmin and zmax 135 ## store default value of zmin and zmax 137 136 self.default_zmin_ctl = self.zmin_2D 138 137 self.default_zmax_ctl = self.zmax_2D … … 145 144 if event == None: 146 145 return 147 event.Skip() 148 149 def onLeftDown(self, event): 146 event.Skip() 147 148 def onLeftDown(self, event): 150 149 """ 151 150 left button down and ready to drag 152 151 153 152 """ 154 153 # Check that the LEFT button was pressed 155 PlotPanel.onLeftDown(self, event) 154 PlotPanel.onLeftDown(self, event) 156 155 ax = event.inaxes 157 156 if ax != None: 158 157 # data coordinate position 159 pos_x = "%8.3g" % event.xdata160 pos_y = "%8.3g" % event.ydata158 pos_x = "%8.3g" % event.xdata 159 pos_y = "%8.3g" % event.ydata 161 160 position = "x: %s y: %s" % (pos_x, pos_y) 162 161 wx.PostEvent(self.parent, StatusEvent(status=position)) … … 164 163 self._manager.set_panel_on_focus(self) 165 164 wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 166 165 167 166 def add_toolbar(self): 168 167 """ … … 174 173 # On Windows platform, default window size is incorrect, so set 175 174 # toolbar width to figure width. 176 tw, th = self.toolbar.GetSizeTuple()177 fw, fh= self.canvas.GetSizeTuple()175 _, th = self.toolbar.GetSizeTuple() 176 fw, _ = self.canvas.GetSizeTuple() 178 177 self.toolbar.SetSize(wx.Size(fw, th)) 179 self.sizer.Add(self.toolbar, 0, wx.LEFT |wx.EXPAND)178 self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) 180 179 # update the axes menu on the toolbar 181 180 self.toolbar.update() 182 181 183 182 def plot_data(self, data): 184 183 """ 185 184 Data is ready to be displayed 186 185 187 186 :TODO: this name should be changed to something more appropriate 188 187 Don't forget that changing this name will mean changing code 189 188 in plotting.py 190 189 191 190 :param event: data event 192 191 """ 193 192 xlo = None 194 193 xhi = None 195 ylo = None 194 ylo = None 196 195 yhi = None 197 196 if data.__class__.__name__ == 'Data1D': … … 207 206 else: 208 207 self.plots[data.id] = data 209 self.graph.add(self.plots[data.id]) 208 self.graph.add(self.plots[data.id]) 210 209 # update qmax with the new xmax of data plotted 211 self.qmax = data.xmax 210 self.qmax = data.xmax 212 211 self.slicer = None 213 212 # Check axis labels 214 213 #TODO: Should re-factor this 215 ## render the graph with its new content 214 ## render the graph with its new content 216 215 #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 217 if len(data.detector) < 1: 216 if len(data.detector) < 1: 218 217 if len(data._xunit) < 1 and len(data._yunit) < 1: 219 218 data._xaxis = '\\rm{x}' … … 224 223 self.graph.xaxis(data._xaxis, data._xunit) 225 224 self.graph.yaxis(data._yaxis, data._yunit) 226 if self._is_changed_legend_label: 227 225 if self._is_changed_legend_label: 226 data.label = self.title_label 228 227 if data.label == None: 229 data.label = data.name 228 data.label = data.name 230 229 if not self.title_font: 231 230 self.graph.title(data.label) … … 240 239 fontproperties=self.title_font, 241 240 color=self.title_color) 242 self.subplot.figure.canvas.draw_idle() 243 ## store default value of zmin and zmax 241 self.subplot.figure.canvas.draw_idle() 242 ## store default value of zmin and zmax 244 243 self.default_zmin_ctl = self.zmin_2D 245 244 self.default_zmax_ctl = self.zmax_2D … … 247 246 return 248 247 # Recover the x,y limits 249 if (xlo and xhi and ylo and yhi) != None:250 if (xlo > data.xmin and xhi < data.xmax and\251 ylo > data.ymin and yhi < data.ymax ):252 self.subplot.set_xlim((xlo, xhi)) 253 self.subplot.set_ylim((ylo, yhi)) 254 else: 248 if xlo and xhi and ylo and yhi: 249 if xlo > data.xmin and xhi < data.xmax and \ 250 ylo > data.ymin and yhi < data.ymax: 251 self.subplot.set_xlim((xlo, xhi)) 252 self.subplot.set_ylim((ylo, yhi)) 253 else: 255 254 self.toolbar.update() 256 255 self.is_zoomed = False … … 276 275 self.xaxis_label = xname 277 276 self.xaxis_unit = xunits 278 self.xaxis(xname, xunits, self.xaxis_font, 277 self.xaxis(xname, xunits, self.xaxis_font, 279 278 self.xaxis_color, self.xaxis_tick) 280 self.yaxis(yname, yunits, self.yaxis_font, 279 self.yaxis(yname, yunits, self.yaxis_font, 281 280 self.yaxis_color, self.yaxis_tick) 282 281 283 282 def onContextMenu(self, event): 284 283 """ 285 284 2D plot context menu 286 285 287 286 :param event: wx context event 288 287 289 288 """ 290 289 slicerpop = PanelMenu() 291 290 slicerpop.set_plots(self.plots) 292 291 slicerpop.set_graph(self.graph) 293 294 id = wx.NewId()295 slicerpop.Append( id, '&Save Image')296 wx.EVT_MENU(self, id, self.onSaveImage)297 298 id = wx.NewId()299 slicerpop.Append( id,'&Print Image', 'Print image')300 wx.EVT_MENU(self, id, self.onPrint)301 302 id = wx.NewId()303 slicerpop.Append( id,'&Print Preview', 'Print preview')304 wx.EVT_MENU(self, id, self.onPrinterPreview)305 306 id = wx.NewId()307 slicerpop.Append( id, '&Copy to Clipboard', 'Copy to the clipboard')308 wx.EVT_MENU(self, id, self.OnCopyFigureMenu)292 293 wx_id = wx.NewId() 294 slicerpop.Append(wx_id, '&Save Image') 295 wx.EVT_MENU(self, wx_id, self.onSaveImage) 296 297 wx_id = wx.NewId() 298 slicerpop.Append(wx_id, '&Print Image', 'Print image') 299 wx.EVT_MENU(self, wx_id, self.onPrint) 300 301 wx_id = wx.NewId() 302 slicerpop.Append(wx_id, '&Print Preview', 'Print preview') 303 wx.EVT_MENU(self, wx_id, self.onPrinterPreview) 304 305 wx_id = wx.NewId() 306 slicerpop.Append(wx_id, '&Copy to Clipboard', 'Copy to the clipboard') 307 wx.EVT_MENU(self, wx_id, self.OnCopyFigureMenu) 309 308 slicerpop.AppendSeparator() 310 309 # saving data 311 310 plot = self.data2D 312 id = wx.NewId() 313 name = plot.name 314 slicerpop.Append(id, "&Data Info" ) 315 wx.EVT_MENU(self, id, self._onDataShow) 316 317 id = wx.NewId() 318 name = plot.name 319 slicerpop.Append(id, "&Save as a File (DAT)" ) 320 self.action_ids[str(id)] = plot 321 wx.EVT_MENU(self, id, self._onSave) 311 wx_id = wx.NewId() 312 slicerpop.Append(wx_id, "&Data Info") 313 wx.EVT_MENU(self, wx_id, self._onDataShow) 314 315 wx_id = wx.NewId() 316 slicerpop.Append(wx_id, "&Save as a File (DAT)") 317 self.action_ids[str(wx_id)] = plot 318 wx.EVT_MENU(self, wx_id, self._onSave) 322 319 323 320 slicerpop.AppendSeparator() 324 if len(self.data2D.detector) == 1: 325 321 if len(self.data2D.detector) == 1: 326 322 item_list = self.parent.get_current_context_menu(self) 327 323 if (not item_list == None) and (not len(item_list) == 0) and\ 328 self.data2D.name.split(" ")[0] != 'Residuals': 324 self.data2D.name.split(" ")[0] != 'Residuals': 329 325 # The line above; Not for trunk 330 326 for item in item_list: 331 327 try: 332 id = wx.NewId()333 slicerpop.Append( id, item[0], item[1])334 wx.EVT_MENU(self, id, item[2])328 wx_id = wx.NewId() 329 slicerpop.Append(wx_id, item[0], item[1]) 330 wx.EVT_MENU(self, wx_id, item[2]) 335 331 except: 336 332 msg = "ModelPanel1D.onContextMenu: " 337 msg += "bad menu item %s" %sys.exc_value333 msg += "bad menu item %s" % sys.exc_value 338 334 wx.PostEvent(self.parent, StatusEvent(status=msg)) 339 pass340 335 slicerpop.AppendSeparator() 341 342 id = wx.NewId()343 slicerpop.Append( id, '&Perform Circular Average')344 wx.EVT_MENU(self, id, self.onCircular) \336 337 wx_id = wx.NewId() 338 slicerpop.Append(wx_id, '&Perform Circular Average') 339 wx.EVT_MENU(self, wx_id, self.onCircular) \ 345 340 # For Masked Data 346 341 if not plot.mask.all(): 347 id = wx.NewId()348 slicerpop.Append( id, '&Masked Circular Average')349 wx.EVT_MENU(self, id, self.onMaskedCircular)350 id = wx.NewId()351 slicerpop.Append( id, '&Sector [Q View]')352 wx.EVT_MENU(self, id, self.onSectorQ)353 id = wx.NewId()354 slicerpop.Append( id, '&Annulus [Phi View ]')355 wx.EVT_MENU(self, id, self.onSectorPhi)356 id = wx.NewId()357 slicerpop.Append( id, '&Box Sum')358 wx.EVT_MENU(self, id, self.onBoxSum)359 id = wx.NewId()360 slicerpop.Append( id, '&Box Averaging in Qx')361 wx.EVT_MENU(self, id, self.onBoxavgX)362 id = wx.NewId()363 slicerpop.Append( id, '&Box Averaging in Qy')364 wx.EVT_MENU(self, id, self.onBoxavgY)342 wx_id = wx.NewId() 343 slicerpop.Append(wx_id, '&Masked Circular Average') 344 wx.EVT_MENU(self, wx_id, self.onMaskedCircular) 345 wx_id = wx.NewId() 346 slicerpop.Append(wx_id, '&Sector [Q View]') 347 wx.EVT_MENU(self, wx_id, self.onSectorQ) 348 wx_id = wx.NewId() 349 slicerpop.Append(wx_id, '&Annulus [Phi View ]') 350 wx.EVT_MENU(self, wx_id, self.onSectorPhi) 351 wx_id = wx.NewId() 352 slicerpop.Append(wx_id, '&Box Sum') 353 wx.EVT_MENU(self, wx_id, self.onBoxSum) 354 wx_id = wx.NewId() 355 slicerpop.Append(wx_id, '&Box Averaging in Qx') 356 wx.EVT_MENU(self, wx_id, self.onBoxavgX) 357 wx_id = wx.NewId() 358 slicerpop.Append(wx_id, '&Box Averaging in Qy') 359 wx.EVT_MENU(self, wx_id, self.onBoxavgY) 365 360 if self.slicer != None: 366 id = wx.NewId()367 slicerpop.Append( id, '&Clear Slicer')368 wx.EVT_MENU(self, id, self.onClearSlicer)369 if self.slicer.__class__.__name__ 370 id = wx.NewId()371 slicerpop.Append( id, '&Edit Slicer Parameters')372 wx.EVT_MENU(self, id, self._onEditSlicer)373 slicerpop.AppendSeparator() 374 375 id = wx.NewId()376 slicerpop.Append( id, '&Edit Graph Label', 'Edit Graph Label')377 wx.EVT_MENU(self, id, self.onEditLabels)361 wx_id = wx.NewId() 362 slicerpop.Append(wx_id, '&Clear Slicer') 363 wx.EVT_MENU(self, wx_id, self.onClearSlicer) 364 if self.slicer.__class__.__name__ != "BoxSum": 365 wx_id = wx.NewId() 366 slicerpop.Append(wx_id, '&Edit Slicer Parameters') 367 wx.EVT_MENU(self, wx_id, self._onEditSlicer) 368 slicerpop.AppendSeparator() 369 370 wx_id = wx.NewId() 371 slicerpop.Append(wx_id, '&Edit Graph Label', 'Edit Graph Label') 372 wx.EVT_MENU(self, wx_id, self.onEditLabels) 378 373 slicerpop.AppendSeparator() 379 374 380 375 # ILL mod here 381 376 382 id = wx.NewId()383 slicerpop.Append( id, '&Modify graph appearance','Modify graph appearance')384 wx.EVT_MENU(self, id, self.modifyGraphAppearance)377 wx_id = wx.NewId() 378 slicerpop.Append(wx_id, '&Modify graph appearance', 'Modify graph appearance') 379 wx.EVT_MENU(self, wx_id, self.modifyGraphAppearance) 385 380 slicerpop.AppendSeparator() 386 381 387 388 389 id = wx.NewId() 390 slicerpop.Append(id, '&2D Color Map') 391 wx.EVT_MENU(self, id, self._onEditDetector) 382 wx_id = wx.NewId() 383 slicerpop.Append(wx_id, '&2D Color Map') 384 wx.EVT_MENU(self, wx_id, self._onEditDetector) 392 385 slicerpop.AppendSeparator() 393 394 id = wx.NewId() 395 slicerpop.Append(id, '&Toggle Linear/Log Scale') 396 wx.EVT_MENU(self, id, self._onToggleScale) 397 398 386 387 wx_id = wx.NewId() 388 slicerpop.Append(wx_id, '&Toggle Linear/Log Scale') 389 wx.EVT_MENU(self, wx_id, self._onToggleScale) 390 399 391 slicerpop.AppendSeparator() 400 id = wx.NewId()401 slicerpop.Append( id, '&Window Title')402 wx.EVT_MENU(self, id, self.onChangeCaption)403 392 wx_id = wx.NewId() 393 slicerpop.Append(wx_id, '&Window Title') 394 wx.EVT_MENU(self, wx_id, self.onChangeCaption) 395 404 396 try: 405 397 pos_evt = event.GetPosition() … … 409 401 pos = (pos_x, pos_y + 5) 410 402 self.PopupMenu(slicerpop, pos) 411 412 403 413 404 def onEditLabels(self, event): 414 405 """ … … 443 434 color=self.title_color) 444 435 self._is_changed_legend_label = True 445 self.subplot.figure.canvas.draw_idle() 436 self.subplot.figure.canvas.draw_idle() 446 437 except: 438 msg = "Add Text: Error. Check your property values..." 439 logging.error(msg) 447 440 if self.parent != None: 448 from sas.guiframe.events import StatusEvent 449 msg= "Add Text: Error. Check your property values..." 450 wx.PostEvent(self.parent, StatusEvent(status = msg )) 451 else: 452 raise 441 wx.PostEvent(self.parent, StatusEvent(status=msg)) 453 442 dial.Destroy() 454 443 455 444 def _onEditDetector(self, event): 456 445 """ 457 446 Allow to view and edits detector parameters 458 447 459 448 :param event: wx.menu event 460 449 461 450 """ 462 451 import detector_dialog 463 dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent,464 reset_zmin_ctl=self.default_zmin_ctl,465 reset_zmax_ctl = self.default_zmax_ctl,cmap=self.cmap)452 dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent, 453 reset_zmin_ctl=self.default_zmin_ctl, 454 reset_zmax_ctl=self.default_zmax_ctl, cmap=self.cmap) 466 455 ## info of current detector and data2D 467 456 xnpts = len(self.data2D.x_bins) … … 470 459 ymax = max(self.data2D.ymin, self.data2D.ymax) 471 460 qmax = math.sqrt(math.pow(xmax, 2) + math.pow(ymax, 2)) 472 beam = self.data2D.xmin473 461 ## set dialog window content 474 dialog.setContent(xnpts=xnpts, ynpts=ynpts,qmax=qmax,475 476 zmin =self.zmin_2D,477 zmax =self.zmax_2D)462 dialog.setContent(xnpts=xnpts, ynpts=ynpts, qmax=qmax, 463 beam=self.data2D.xmin, 464 zmin=self.zmin_2D, 465 zmax=self.zmax_2D) 478 466 if dialog.ShowModal() == wx.ID_OK: 479 467 evt = dialog.getContent() … … 486 474 qx_data=self.data2D.qx_data, 487 475 qy_data=self.data2D.qy_data, 488 xmin= 489 xmax= 490 ymin= 491 ymax= 492 zmin= 493 zmax= 494 cmap= 476 xmin=self.data2D.xmin, 477 xmax=self.data2D.xmax, 478 ymin=self.data2D.ymin, 479 ymax=self.data2D.ymax, 480 zmin=self.zmin_2D, 481 zmax=self.zmax_2D, 482 cmap=self.cmap, 495 483 color=0, symbol=0, label=self.data2D.name) 496 484 self.subplot.figure.canvas.draw_idle() 497 485 498 486 def freeze_axes(self): 499 487 """ 500 488 """ 501 489 self.axes_frozen = True 502 490 503 491 def thaw_axes(self): 504 492 """ 505 493 """ 506 494 self.axes_frozen = False 507 508 def onMouseMotion(self, event):495 496 def onMouseMotion(self, event): 509 497 """ 510 498 """ 511 499 pass 512 500 513 501 def onWheel(self, event): 514 502 """ 515 503 """ 516 pass 517 504 pass 505 518 506 def update(self, draw=True): 519 507 """ 520 Respond to changes in the model by recalculating the 508 Respond to changes in the model by recalculating the 521 509 profiles and resetting the widgets. 522 510 """ 523 511 self.draw_plot() 524 512 525 513 def _getEmptySlicerEvent(self): 526 514 """ 527 create an empty slicervent 515 create an empty slicervent 528 516 """ 529 517 return SlicerEvent(type=None, params=None, obj_class=None) 530 518 531 519 def _onEVT_INTERNAL(self, event): 532 520 """ 533 521 Draw the slicer 534 522 535 523 :param event: wx.lib.newevent (SlicerEvent) containing slicer 536 524 parameter 537 525 538 526 """ 539 527 self._setSlicer(event.slicer) 540 528 541 529 def _setSlicer(self, slicer): 542 530 """ 543 531 Clear the previous slicer and create a new one.Post an internal 544 532 event. 545 533 546 534 :param slicer: slicer class to create 547 535 548 536 """ 549 537 ## Clear current slicer 550 if not self.slicer == None: 551 self.slicer.clear() 552 ## Create a new slicer 538 if not self.slicer == None: 539 self.slicer.clear() 540 ## Create a new slicer 553 541 self.slicer_z += 1 554 542 self.slicer = slicer(self, self.subplot, zorder=self.slicer_z) … … 558 546 self.update() 559 547 self.slicer.update() 560 msg = "Plotter2D._setSlicer %s" %self.slicer.__class__.__name__548 msg = "Plotter2D._setSlicer %s" % self.slicer.__class__.__name__ 561 549 wx.PostEvent(self.parent, StatusEvent(status=msg)) 562 550 # Post slicer event … … 566 554 event.params = self.slicer.get_params() 567 555 wx.PostEvent(self, event) 568 556 569 557 def onMaskedCircular(self, event): 570 558 """ 571 559 perform circular averaging on Data2D with mask if it exists 572 560 573 561 :param event: wx.menu event 574 562 575 563 """ 576 564 self.onCircular(event, True) 577 565 578 566 def onCircular(self, event, ismask=False): 579 567 """ 580 568 perform circular averaging on Data2D 581 569 582 570 :param event: wx.menu event 583 571 584 572 """ 585 573 # Find the best number of bins … … 588 576 from sas.dataloader.manipulations import CircularAverage 589 577 ## compute the maximum radius of data2D 590 self.qmax = max(math.fabs(self.data2D.xmax), 578 self.qmax = max(math.fabs(self.data2D.xmax), 591 579 math.fabs(self.data2D.xmin)) 592 580 self.ymax = max(math.fabs(self.data2D.ymax), 593 581 math.fabs(self.data2D.ymin)) 594 self.radius = math.sqrt(math.pow(self.qmax, 2) + math.pow(self.ymax, 2))582 self.radius = math.sqrt(math.pow(self.qmax, 2) + math.pow(self.ymax, 2)) 595 583 ##Compute beam width 596 bin_width = (self.qmax + self.qmax) /npt584 bin_width = (self.qmax + self.qmax) / npt 597 585 ## Create data1D circular average of data2D 598 Circle = CircularAverage(r_min=0, r_max=self.radius, 586 Circle = CircularAverage(r_min=0, r_max=self.radius, 599 587 bin_width=bin_width) 600 588 circ = Circle(self.data2D, ismask=ismask) … … 617 605 new_plot.interactive = True 618 606 new_plot.detector = self.data2D.detector 619 607 620 608 ## If the data file does not tell us what the axes are, just assume... 621 609 new_plot.xaxis("\\rm{Q}", "A^{-1}") … … 627 615 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 628 616 629 new_plot.group_id = "2daverage" 617 new_plot.group_id = "2daverage" + self.data2D.name 630 618 new_plot.id = "Circ avg " + self.data2D.name 631 619 new_plot.is_data = True 632 620 self.parent.update_theory(data_id=self.data2D.id, \ 633 621 theory=new_plot) 634 wx.PostEvent(self.parent, 622 wx.PostEvent(self.parent, 635 623 NewPlotEvent(plot=new_plot, title=new_plot.name)) 636 624 637 625 def _onEditSlicer(self, event): 638 626 """ 639 Is available only when a slicer is drawn.Create a dialog 627 Is available only when a slicer is drawn.Create a dialog 640 628 window where the user can enter value to reset slicer 641 629 parameters. 642 630 643 631 :param event: wx.menu event 644 632 645 633 """ 646 634 if self.slicer != None: … … 648 636 dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") 649 637 dialog.set_slicer(self.slicer.__class__.__name__, 650 self.slicer.get_params())638 self.slicer.get_params()) 651 639 if dialog.ShowModal() == wx.ID_OK: 652 dialog.Destroy() 653 640 dialog.Destroy() 641 654 642 def onSectorQ(self, event): 655 643 """ … … 659 647 self.onClearSlicer(event) 660 648 wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) 661 649 662 650 def onSectorPhi(self, event): 663 651 """ … … 667 655 self.onClearSlicer(event) 668 656 wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) 669 657 670 658 def onBoxSum(self, event): 671 659 """ … … 675 663 self.onClearSlicer(event) 676 664 self.slicer_z += 1 677 self.slicer = 665 self.slicer = BoxSum(self, self.subplot, zorder=self.slicer_z) 678 666 self.subplot.set_ylim(self.data2D.ymin, self.data2D.ymax) 679 667 self.subplot.set_xlim(self.data2D.xmin, self.data2D.xmax) … … 681 669 self.slicer.update() 682 670 ## Value used to initially set the slicer panel 683 type = self.slicer.__class__.__name__684 671 params = self.slicer.get_params() 685 672 ## Create a new panel to display results of summation of Data2D … … 687 674 win = MDIFrame(self.parent, None, 'None', (100, 200)) 688 675 new_panel = SlicerPanel(parent=win, id=-1, 689 base=self, type=type,690 691 676 base=self, type=self.slicer.__class__.__name__, 677 params=params, style=wx.RAISED_BORDER) 678 692 679 new_panel.window_caption = self.slicer.__class__.__name__ + " " + \ 693 680 str(self.data2D.name) 694 new_panel.window_name = self.slicer.__class__.__name__ + " " + \681 new_panel.window_name = self.slicer.__class__.__name__ + " " + \ 695 682 str(self.data2D.name) 696 683 ## Store a reference of the new created panel 697 684 698 685 ## save the window_caption of the new panel in the current slicer 699 686 self.slicer.set_panel_name(name=new_panel.window_caption) 700 ## post slicer panel to guiframe to display it 687 ## post slicer panel to guiframe to display it 701 688 from sas.guiframe.events import SlicerPanelEvent 702 689 703 690 win.set_panel(new_panel) 704 691 new_panel.frame = win 705 692 wx.PostEvent(self.parent, SlicerPanelEvent(panel=new_panel, 706 693 main_panel=self)) 707 694 wx.CallAfter(new_panel.frame.Show) 708 695 self.panel_slicer = new_panel 709 710 def onBoxavgX(self, event):696 697 def onBoxavgX(self, event): 711 698 """ 712 699 Perform 2D data averaging on Qx 713 700 Create a new slicer . 714 701 715 702 :param event: wx.menu event 716 703 """ … … 718 705 self.onClearSlicer(event) 719 706 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) 720 721 def onBoxavgY(self, event):707 708 def onBoxavgY(self, event): 722 709 """ 723 710 Perform 2D data averaging on Qy 724 711 Create a new slicer . 725 712 726 713 :param event: wx.menu event 727 714 728 715 """ 729 716 from boxSlicer import BoxInteractorY 730 717 self.onClearSlicer(event) 731 718 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) 732 719 733 720 def onClearSlicer(self, event): 734 721 """ … … 742 729 event = self._getEmptySlicerEvent() 743 730 wx.PostEvent(self, event) 744 731 745 732 def _onSave(self, evt): 746 733 """ 747 734 Save a data set to a dat(text) file 748 735 749 736 :param evt: Menu event 750 751 """ 752 id = str(evt.GetId())737 738 """ 739 event_id = str(evt.GetId()) 753 740 if self.parent != None: 754 741 self._default_save_location = self.parent._default_save_location … … 757 744 default_name = default_name.split('.')[0] 758 745 default_name += "_out" 759 if id in self.action_ids: 760 path = None 746 if event_id in self.action_ids: 761 747 self.parent.save_data2d(self.data2D, default_name) 762 748 763 749 def _onDataShow(self, evt): 764 750 """ 765 751 Show the data set in text 766 752 767 753 :param evt: Menu event 768 754 769 755 """ 770 756 menu = evt.GetEventObject() 771 id = evt.GetId()772 self.set_selected_from_menu(menu, id)757 event_id = evt.GetId() 758 self.set_selected_from_menu(menu, event_id) 773 759 data = self.plots[self.graph.selected_plottable] 774 760 default_name = data.label … … 778 764 if self.parent != None: 779 765 self.parent.show_data2d(data, default_name) 780 781 782 def modifyGraphAppearance(self,e): 783 self.graphApp = graphAppearance(self,'Modify graph appearance', 784 legend=False) 785 786 787 788 self.graphApp.setDefaults(self.grid_on,self.legend_on, 789 self.xaxis_label,self.yaxis_label, 790 self.xaxis_unit,self.yaxis_unit, 791 self.xaxis_font,self.yaxis_font, 792 find_key(self.get_loc_label(),self.legendLoc), 793 self.xcolor,self.ycolor, 794 self.is_xtick, self.is_ytick) 766 767 def modifyGraphAppearance(self, e): 768 self.graphApp = graphAppearance(self, 'Modify graph appearance', legend=False) 769 self.graphApp.setDefaults(self.grid_on, self.legend_on, 770 self.xaxis_label, self.yaxis_label, 771 self.xaxis_unit, self.yaxis_unit, 772 self.xaxis_font, self.yaxis_font, 773 find_key(self.get_loc_label(), self.legendLoc), 774 self.xcolor, self.ycolor, 775 self.is_xtick, self.is_ytick) 795 776 self.graphApp.Bind(wx.EVT_CLOSE, self.on_graphApp_close) 796 797 798 def on_graphApp_close(self,e):799 # gets values from graph appearance dialog and sends them off800 #to modify the plot801 777 778 def on_graphApp_close(self, e): 779 """ 780 Gets values from graph appearance dialog and sends them off 781 to modify the plot 782 """ 802 783 self.onGridOnOff(self.graphApp.get_togglegrid()) 803 804 805 784 self.xaxis_label = self.graphApp.get_xlab() 806 785 self.yaxis_label = self.graphApp.get_ylab() … … 809 788 self.xaxis_font = self.graphApp.get_xfont() 810 789 self.yaxis_font = self.graphApp.get_yfont() 811 self.is_xtick = 812 self.is_ytick = 790 self.is_xtick = self.graphApp.get_xtick_check() 791 self.is_ytick = self.graphApp.get_ytick_check() 813 792 if self.is_xtick: 814 793 self.xaxis_tick = self.xaxis_font … … 816 795 self.yaxis_tick = self.yaxis_font 817 796 818 self.xaxis(self.xaxis_label, self.xaxis_unit, 819 self.graphApp.get_xfont(), self.graphApp.get_xcolor(), 797 self.xaxis(self.xaxis_label, self.xaxis_unit, 798 self.graphApp.get_xfont(), self.graphApp.get_xcolor(), 820 799 self.xaxis_tick) 821 self.yaxis(self.yaxis_label, self.yaxis_unit, 800 self.yaxis(self.yaxis_label, self.yaxis_unit, 822 801 self.graphApp.get_yfont(), self.graphApp.get_ycolor(), 823 802 self.yaxis_tick)
Note: See TracChangeset
for help on using the changeset viewer.