Changeset a07e72f in sasview for invariantview/perspectives/invariant
- Timestamp:
- Feb 28, 2011 4:07:14 PM (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:
- 243a8d4
- Parents:
- 6bbeacd4
- Location:
- invariantview/perspectives/invariant
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
invariantview/perspectives/invariant/invariant.py
rcb69775 ra07e72f 18 18 import logging 19 19 20 from DataLoader.data_info import Data1D as LoaderData1D 21 from sans.guiframe.dataFitting import Theory1D 20 22 21 from sans.guiframe.dataFitting import Data1D 23 24 22 from sans.guiframe.events import NewPlotEvent 25 from sans.guiframe. events import ERR_DATA23 from sans.guiframe.gui_style import GUIFRAME_ID 26 24 from .invariant_state import Reader as reader 27 25 from DataLoader.loader import Loader 28 26 from .invariant_panel import InvariantPanel 29 #from sans.guiframe.events import EVT_INVSTATE_UPDATE30 31 27 from sans.guiframe.plugin_base import PluginBase 32 28 … … 80 76 ## Save a reference to the parent 81 77 self.parent = parent 82 #add error back to the data83 self.parent.Bind(ERR_DATA, self._on_data_error)84 #self.parent.Bind(EVT_INVSTATE_UPDATE, self.on_set_state_helper)85 86 78 self.invariant_panel = InvariantPanel(parent=self.parent) 87 79 self.invariant_panel.set_manager(manager=self) … … 96 88 return [self.invariant_panel] 97 89 98 def get_context_menu(self, graph=None):90 def get_context_menu(self, plotpanel=None): 99 91 """ 100 92 This method is optional. … … 117 109 :return: a list of menu items with call-back function 118 110 """ 119 self.graph =graph111 graph = plotpanel.graph 120 112 invariant_option = "Compute invariant" 121 113 invariant_hint = "Will displays the invariant panel for" 122 114 invariant_hint += " futher computation" 123 124 for item in self.graph.plottables: 125 if item.name == graph.selected_plottable : 126 if issubclass(item.__class__, LoaderData1D): 127 128 if item.name != "$I_{obs}(q)$" and \ 129 item.name != " $P_{fit}(r)$": 130 if hasattr(item, "group_id"): 131 return [[invariant_option, 132 invariant_hint, 115 116 if graph.selected_plottable not in plotpanel.plots: 117 return [] 118 data = plotpanel.plots[graph.selected_plottable] 119 120 if not issubclass(data.__class__, Data1D): 121 name = data.__class__.__name__ 122 msg = "Invariant use only Data1D got: [%s] " % str(name) 123 raise ValueError, msg 124 125 if data.name != "$I_{obs}(q)$" and data.name != " $P_{fit}(r)$": 126 return [[invariant_option, invariant_hint, 133 127 self._compute_invariant]] 134 return [] 135 136 def copy_data(self, item, dy=None): 137 """ 138 receive a data 1D and the list of errors on dy 139 and create a new data1D data 140 """ 141 id = None 142 if hasattr(item,"id"): 143 id = item.id 144 145 data = Data1D(x=item.x, y=item.y, dx=None, dy=None) 146 data.copy_from_datainfo(item) 147 item.clone_without_data(clone=data) 148 data.dy = dy 149 data.name = item.name 150 data.title = item.title 151 152 ## allow to highlight data when plotted 153 data.interactive = item.interactive 154 ## when 2 data have the same id override the 1 st plotted 155 data.id = id 156 data.group_id = item.group_id 157 return data 158 159 def _on_data_error(self, event): 160 """ 161 receives and event from plotting plu-gins to store the data name and 162 their errors of y coordinates for 1Data hide and show error 163 """ 164 self.err_dy = event.err_dy 165 128 return [] 129 166 130 def _compute_invariant(self, event): 167 131 """ … … 170 134 self.panel = event.GetEventObject() 171 135 Plugin.on_perspective(self, event=event) 172 for plottable in self.panel.graph.plottables: 173 if plottable.name == self.panel.graph.selected_plottable: 174 ## put the errors values back to the model if the errors 175 ## were hiden before sending them to the fit engine 176 if len(self.err_dy) > 0: 177 dy = plottable.dy 178 if plottable.name in self.err_dy.iterkeys(): 179 dy = self.err_dy[plottable.name] 180 data = self.copy_data(plottable, dy) 181 else: 182 data = plottable 183 self.compute_helper(data=data) 136 id = self.panel.graph.selected_plottable 137 data = self.panel.plots[self.panel.graph.selected_plottable] 138 if data is None: 139 return 140 if not issubclass(data.__class__, Data1D): 141 name = data.__class__.__name__ 142 msg = "Invariant use only Data1D got: [%s] " % str(name) 143 raise ValueError, msg 144 self.compute_helper(data=data) 184 145 185 146 def set_data(self, data_list): … … 187 148 receive a list of data and compute invariant 188 149 """ 150 data = None 189 151 if len(data_list) > 1: 190 152 msg = "invariant panel does not allow multiple data!\n" … … 194 156 if dlg.ShowModal() == wx.ID_OK: 195 157 data = dlg.get_data() 196 if issubclass(data.__class__, LoaderData1D):197 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0],198 title=data_list[0].title))199 self.compute_helper(data_list[0])200 else:201 msg = "invariant cannot be computed for data of "202 msg += "type %s" % (data_list[0].__class__.__name__)203 wx.PostEvent(self.parent,204 StatusEvent(status=msg, info='error'))205 158 elif len(data_list) == 1: 206 if issubclass(data_list[0].__class__, LoaderData1D): 207 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0], 208 title=data_list[0].title)) 209 self.compute_helper(data_list[0]) 210 else: 211 msg = "invariant cannot be computed for" 212 msg += " data of type %s" % (data_list[0].__class__.__name__) 213 wx.PostEvent(self.parent, 214 StatusEvent(status=msg, info='error')) 215 216 159 data = data_list[0] 160 if data is None: 161 return 162 if issubclass(data.__class__, Data1D): 163 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 164 title=data.title)) 165 self.compute_helper(data) 166 else: 167 msg = "invariant cannot be computed for data of " 168 msg += "type %s" % (data.__class__.__name__) 169 wx.PostEvent(self.parent, 170 StatusEvent(status=msg, info='error')) 171 217 172 def clear_panel(self): 173 """ 174 """ 218 175 self.invariant_panel.clear_panel() 219 176 … … 311 268 #import copy 312 269 if data is None: 313 new_plot = Theory1D(x=[], y=[], dy=None) 270 id = str(self.__data.id) + name 271 self.__data.group_id 272 wx.PostEvent(self.parent, NewPlotEvent(id=id, 273 group_id=group_id, 274 remove=true)) 275 return 276 277 new_plot = Data1D(x=[], y=[], dy=None) 278 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 279 scale = self.invariant_panel.get_scale() 280 background = self.invariant_panel.get_background() 281 282 if scale != 0: 283 # Put back the sacle and bkg for plotting 284 data.y = (data.y + background)/scale 285 new_plot = Data1D(x=data.x, y=data.y, dy=None) 286 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 314 287 else: 315 scale = self.invariant_panel.get_scale() 316 background = self.invariant_panel.get_background() 317 318 if scale != 0: 319 # Put back the sacle and bkg for plotting 320 data.y = (data.y + background)/scale 321 new_plot = Theory1D(x=data.x, y=data.y, dy=None) 322 else: 323 msg = "Scale can not be zero." 324 raise ValueError, msg 325 288 msg = "Scale can not be zero." 289 raise ValueError, msg 290 if len(new_plot.x)== 0 : 291 return 292 326 293 new_plot.name = name 327 294 new_plot.xaxis(self.__data._xaxis, self.__data._xunit) 328 295 new_plot.yaxis(self.__data._yaxis, self.__data._yunit) 329 296 new_plot.group_id = self.__data.group_id 330 new_plot.id = s elf.__data.id+ name297 new_plot.id = str(self.__data.id) + name 331 298 new_plot.title = self.__data.title 332 299 # Save theory_data in a state -
invariantview/perspectives/invariant/invariant_panel.py
r97ec26b ra07e72f 364 364 name="Low-Q extrapolation") 365 365 except: 366 raise 366 367 self.inv_container.qstar_low = "ERROR" 367 368 self.inv_container.qstar_low_err = "ERROR" … … 393 394 name="High-Q extrapolation") 394 395 except: 396 raisee 395 397 self.inv_container.qstar_high = "ERROR" 396 398 self.inv_container.qstar_high_err = "ERROR"
Note: See TracChangeset
for help on using the changeset viewer.