Changeset fc2b91a in sasview
- Timestamp:
- Jun 18, 2008 6:07:18 PM (17 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:
- 4972de2
- Parents:
- ad8bcd6
- Location:
- guiframe
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_loader.py
rde9483d rfc2b91a 19 19 Load a 1D ascii file, with errors 20 20 """ 21 21 import numpy 22 22 if path and os.path.isfile(path): 23 23 24 file_x = []25 file_y = []26 file_dy = []24 file_x = numpy.zeros(0) 25 file_y = numpy.zeros(0) 26 file_dy = numpy.zeros(0) 27 27 28 28 input_f = open(path,'r') 29 29 buff = input_f.read() 30 30 lines = buff.split('\n') 31 32 has_dy = False 33 31 34 for line in lines: 32 35 try: … … 35 38 y = float(toks[1]) 36 39 if len(toks)==3: 40 has_dy = True 37 41 err = float(toks[2]) 38 42 else: 39 43 err = 0.0 40 file_x .append(x)41 file_y .append(y)42 file_dy .append(err)44 file_x = numpy.append(file_x, x) 45 file_y = numpy.append(file_y, y) 46 file_dy = numpy.append(file_dy, err) 43 47 except: 44 48 print "READ ERROR", line 45 49 50 if has_dy==False: 51 file_dy = None 52 46 53 return file_x, file_y, file_dy 47 54 return None, None, None 55 56 def plot_data(parent, path, name="Loaded Data"): 57 from sans.guicomm.events import NewPlotEvent 58 from sans.guitools.plottables import Data1D, Theory1D 59 x, y, dy = load_ascii_1D(path) 60 61 if dy==None: 62 new_plot = Theory1D(x, y) 63 else: 64 new_plot = Data1D(x, y, dy=dy) 65 new_plot.name = name 66 new_plot.interactive = True 67 68 # If the data file does not tell us what the axes are, just assume... 69 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 70 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 71 72 wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title="Loaded data")) -
guiframe/gui_manager.py
r2310d69 rfc2b91a 31 31 warnings.simplefilter("ignore") 32 32 33 import logging 33 34 34 35 class ViewerFrame(wx.Frame): … … 42 43 from local_perspectives.plotting import plotting 43 44 wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, size=(1000, 1000)) 45 46 # Logging info 47 logging.basicConfig(level=logging.DEBUG, 48 format='%(asctime)s %(levelname)s %(message)s', 49 filename='sans_app.log', 50 filemode='w') 44 51 45 52 path = os.path.dirname(__file__) … … 310 317 # File menu 311 318 filemenu = wx.Menu() 312 filemenu.Append(101,'&Quit', 'Exit') 319 320 id = wx.NewId() 321 filemenu.Append(id, '&Open', 'Open a file') 322 wx.EVT_MENU(self, id, self._on_open) 323 324 id = wx.NewId() 325 filemenu.Append(id,'&Quit', 'Exit') 326 wx.EVT_MENU(self, id, self.Close) 313 327 314 328 # Add sub menus … … 396 410 self.SetMenuBar(menubar) 397 411 398 # Bind handlers 399 wx.EVT_MENU(self, 101, self.Close) 412 400 413 401 414 def _on_status_event(self, evt): … … 430 443 self._mgr.Update() 431 444 432 445 def _on_open(self, event): 446 from data_loader import plot_data 447 path = self.choose_file() 448 449 if path and os.path.isfile(path): 450 plot_data(self, path) 451 452 453 433 454 def _onClose(self, event): 434 455 import sys -
guiframe/local_perspectives/plotting/plotting.py
r96f13a9 rfc2b91a 18 18 class PanelMenu(wx.Menu): 19 19 plots = None 20 graph = None 20 21 21 22 def set_plots(self, plots): 22 23 self.plots = plots 23 24 25 def set_graph(self, graph): 26 self.graph = graph 24 27 25 28 class View1DPanel(PlotPanel): … … 71 74 is_new = True 72 75 if event.plot.name in self.plots.keys(): 73 is_new = False 76 # Check whether the class of plottable changed 77 if not event.plot.__class__==self.plots[event.plot.name].__class__: 78 self.graph.delete(self.plots[event.plot.name]) 79 else: 80 is_new = False 74 81 75 82 if is_new: … … 103 110 slicerpop = PanelMenu() 104 111 slicerpop.set_plots(self.plots) 112 slicerpop.set_graph(self.graph) 105 113 106 114 # Option to save the data displayed 107 for plot in self.graph.plottables: 115 116 #for plot in self.graph.plottables: 117 if self.graph.selected_plottable in self.plots: 118 plot = self.plots[self.graph.selected_plottable] 108 119 id = wx.NewId() 109 120 name = plot.name … … 117 128 wx.EVT_MENU(self, id, self.onSaveImage) 118 129 119 slicerpop.AppendSeparator()130 120 131 item_list = self.parent.get_context_menu(self.graph) 121 if not item_list==None: 122 for item in item_list: 123 try: 124 id = wx.NewId() 125 slicerpop.Append(id, item[0], item[1]) 126 wx.EVT_MENU(self, id, item[2]) 127 except: 128 print sys.exc_value 129 print RuntimeError, "View1DPanel.onContextMenu: bad menu item" 132 if (not item_list==None) and (not len(item_list)==0): 133 slicerpop.AppendSeparator() 134 for item in item_list: 135 try: 136 id = wx.NewId() 137 slicerpop.Append(id, item[0], item[1]) 138 wx.EVT_MENU(self, id, item[2]) 139 except: 140 print sys.exc_value 141 print RuntimeError, "View1DPanel.onContextMenu: bad menu item" 130 142 131 143 slicerpop.AppendSeparator() … … 135 147 #wx.EVT_MENU(self, id, self._onToggleScale) 136 148 149 if self.graph.selected_plottable in self.plots: 150 if self.plots[self.graph.selected_plottable].__class__.__name__=="Theory1D": 151 id = wx.NewId() 152 slicerpop.Append(id, '&Add errors to data') 153 wx.EVT_MENU(self, id, self._on_add_errors) 154 137 155 id = wx.NewId() 138 156 slicerpop.Append(id, '&Change scale') … … 140 158 141 159 id = wx.NewId() 142 slicerpop.AppendSeparator()160 #slicerpop.AppendSeparator() 143 161 slicerpop.Append(id, '&Reset Graph') 144 162 wx.EVT_MENU(self, id, self.onResetGraph) … … 147 165 pos = self.ScreenToClient(pos) 148 166 self.PopupMenu(slicerpop, pos) 167 168 def _on_add_errors(self, evt): 169 """ 170 Compute reasonable errors for a data set without 171 errors and transorm the plottable to a Data1D 172 """ 173 import math 174 import numpy 175 from sans.guitools.plottables import Data1D 176 177 if not self.graph.selected_plottable == None: 178 length = len(self.plots[self.graph.selected_plottable].x) 179 dy = numpy.zeros(length) 180 for i in range(length): 181 dy[i] = math.sqrt(self.plots[self.graph.selected_plottable].y[i]) 182 183 new_plot = Data1D(self.plots[self.graph.selected_plottable].x, 184 self.plots[self.graph.selected_plottable].y, 185 dy=dy) 186 new_plot.interactive = True 187 new_plot.name = self.plots[self.graph.selected_plottable].name 188 label, unit = self.plots[self.graph.selected_plottable].get_xaxis() 189 new_plot.xaxis(label, unit) 190 label, unit = self.plots[self.graph.selected_plottable].get_yaxis() 191 new_plot.yaxis(label, unit) 192 193 self.graph.delete(self.plots[self.graph.selected_plottable]) 194 195 self.graph.add(new_plot) 196 self.plots[self.graph.selected_plottable]=new_plot 197 198 self.graph.render(self) 199 self.subplot.figure.canvas.draw_idle() 149 200 150 201 def _onSave(self, evt):
Note: See TracChangeset
for help on using the changeset viewer.