Changeset a07e72f in sasview for invariantview


Ignore:
Timestamp:
Feb 28, 2011 4:07:14 PM (13 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

remove other type of data into sansview

Location:
invariantview/perspectives/invariant
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • invariantview/perspectives/invariant/invariant.py

    rcb69775 ra07e72f  
    1818import logging 
    1919 
    20 from DataLoader.data_info import Data1D as LoaderData1D 
    21 from sans.guiframe.dataFitting import Theory1D 
     20 
    2221from sans.guiframe.dataFitting import Data1D 
    23  
    2422from sans.guiframe.events import NewPlotEvent 
    25 from sans.guiframe.events import ERR_DATA 
     23from sans.guiframe.gui_style import GUIFRAME_ID 
    2624from .invariant_state import Reader as reader 
    2725from DataLoader.loader import Loader 
    2826from .invariant_panel import InvariantPanel 
    29 #from sans.guiframe.events import EVT_INVSTATE_UPDATE 
    30  
    3127from sans.guiframe.plugin_base import PluginBase 
    3228 
     
    8076        ## Save a reference to the parent 
    8177        self.parent = parent 
    82         #add error back to the data 
    83         self.parent.Bind(ERR_DATA, self._on_data_error) 
    84         #self.parent.Bind(EVT_INVSTATE_UPDATE, self.on_set_state_helper) 
    85          
    8678        self.invariant_panel = InvariantPanel(parent=self.parent) 
    8779        self.invariant_panel.set_manager(manager=self) 
     
    9688        return [self.invariant_panel] 
    9789   
    98     def get_context_menu(self, graph=None): 
     90    def get_context_menu(self, plotpanel=None): 
    9991        """ 
    10092        This method is optional. 
     
    117109        :return: a list of menu items with call-back function 
    118110        """ 
    119         self.graph = graph 
     111        graph = plotpanel.graph 
    120112        invariant_option = "Compute invariant" 
    121113        invariant_hint = "Will displays the invariant panel for" 
    122114        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,  
    133127                                        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 
    166130    def _compute_invariant(self, event):     
    167131        """ 
     
    170134        self.panel = event.GetEventObject() 
    171135        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) 
    184145                 
    185146    def set_data(self, data_list): 
     
    187148        receive a list of data and compute invariant 
    188149        """ 
     150        data = None 
    189151        if len(data_list) > 1: 
    190152            msg = "invariant panel does not allow multiple data!\n" 
     
    194156            if dlg.ShowModal() == wx.ID_OK: 
    195157                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')) 
    205158        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     
    217172    def clear_panel(self): 
     173        """ 
     174        """ 
    218175        self.invariant_panel.clear_panel() 
    219176         
     
    311268        #import copy 
    312269        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 
    314287        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         
    326293        new_plot.name = name 
    327294        new_plot.xaxis(self.__data._xaxis, self.__data._xunit) 
    328295        new_plot.yaxis(self.__data._yaxis, self.__data._yunit) 
    329296        new_plot.group_id = self.__data.group_id 
    330         new_plot.id = self.__data.id + name 
     297        new_plot.id = str(self.__data.id) + name 
    331298        new_plot.title = self.__data.title 
    332299        # Save theory_data in a state 
  • invariantview/perspectives/invariant/invariant_panel.py

    r97ec26b ra07e72f  
    364364                                           name="Low-Q extrapolation") 
    365365            except: 
     366                raise 
    366367                self.inv_container.qstar_low = "ERROR" 
    367368                self.inv_container.qstar_low_err = "ERROR" 
     
    393394                                           name="High-Q extrapolation") 
    394395            except: 
     396                raisee 
    395397                self.inv_container.qstar_high = "ERROR" 
    396398                self.inv_container.qstar_high_err = "ERROR" 
Note: See TracChangeset for help on using the changeset viewer.