Changeset 47bf906 in sasview for src/sas


Ignore:
Timestamp:
Mar 20, 2018 3:23:43 PM (6 years ago)
Author:
krzywon
Branches:
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
Children:
e51e078
Parents:
d744767
Message:

Updates to P(r) perspective to properly switch between loaded data sets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py

    re90988c r47bf906  
    2929BACKGROUND_INPUT = 0.0 
    3030MAX_DIST = 140.0 
     31DICT_KEYS = ["Calculator", "PrPlot", "DataPlot", "DMaxWindow", 
     32             "Logic", "NFunc", "Estimates"] 
     33ESTIMATE_KEYS = ["nFunc", "??????", "Background"] 
     34 
    3135 
    3236# TODO: Modify plot references, don't just send new 
     
    5054 
    5155        self._manager = parent 
    52         self._model_item = QtGui.QStandardItem() 
    5356        self.communicate = GuiUtils.Communicate() 
    5457 
    5558        self.logic = InversionLogic() 
    56  
    57         # Reference to Dmax window 
    58         self.dmaxWindow = None 
    5959 
    6060        # The window should not close 
    6161        self._allow_close = False 
    6262 
     63        # Visible data set items 
    6364        # current QStandardItem showing on the panel 
    6465        self._data = None 
    6566        # current Data1D as referenced by self._data 
    6667        self._data_set = None 
    67  
    68         # p(r) calculator 
     68        # Reference to Dmax window for self._data 
     69        self.dmaxWindow = None 
     70        # p(r) calculator for self._data 
    6971        self._calculator = Invertor() 
    70         self._last_calculator = None 
     72        # Combo box index for self._data 
     73        self._data_index = 0 
     74        # plots of self._data 
     75        self.pr_plot = None 
     76        self.data_plot = None 
     77 
     78        # Calculation threads used by all data items 
    7179        self.calc_thread = None 
    7280        self.estimation_thread = None 
    7381 
    74         # Current data object in view 
    75         self._data_index = 0 
    76         # list mapping data to p(r) calculation 
     82        # Mapping for all data items 
     83        # TODO: {QStandardItem -> {params: [], plot: Plot, dmax: dMax, 
     84        # TODO: calculator: Invertor(), estimates: {}, data: Data1D, ...} 
     85        # list mapping data to all parameters 
    7786        self._data_list = {} 
    7887        if not isinstance(data, list): 
     
    8089        if data is not None: 
    8190            for datum in data_list: 
    82                 self._data_list[datum] = self._calculator.clone() 
    83  
    84         # dict of models for quick update after calculation 
    85         # {item:model} 
    86         self._models = {} 
     91                self._data_list[datum] = {DICT_KEYS[0]: self._calculator.clone(), 
     92                                          DICT_KEYS[4]: self.logic, 
     93                                          DICT_KEYS[5]: NUMBER_OF_TERMS, 
     94                                          DICT_KEYS[6]: {}} 
    8795 
    8896        self.calculateAllButton.setEnabled(False) 
    8997        self.calculateThisButton.setEnabled(False) 
    90  
    91         # plots for current data 
    92         self.pr_plot = None 
    93         self.data_plot = None 
    94         # plot references for all data in perspective 
    95         self.pr_plot_list = {} 
    96         self.data_plot_list = {} 
    9798 
    9899        self.model = QtGui.QStandardItemModel(self) 
     
    158159 
    159160        self.backgroundInput.editingFinished.connect( 
    160             lambda: self._calculator.set_est_bck(int(is_float(self.backgroundInput.text())))) 
     161            lambda: self._calculator.set_est_bck(is_float(self.backgroundInput.text()))) 
    161162        self.minQInput.editingFinished.connect( 
    162163            lambda: self._calculator.set_qmin(is_float(self.minQInput.text()))) 
     
    308309 
    309310    def displayChange(self): 
     311        """Switch to another item in the data list""" 
    310312        ref_item = self.dataList.itemData(self.dataList.currentIndex()) 
    311         self._model_item = ref_item 
     313        self.updateDataList(self._data) 
    312314        self.setCurrentData(ref_item) 
    313         self.setCurrentModel(ref_item) 
    314  
    315     def removeData(self): 
    316         """Remove the existing data reference from the P(r) Persepective""" 
    317         self._data_list.pop(self._data) 
    318         self.pr_plot_list.pop(self._data) 
    319         self.data_plot_list.pop(self._data) 
    320         if self.dmaxWindow is not None: 
    321             self.dmaxWindow = None 
    322         self.dataList.removeItem(self.dataList.currentIndex()) 
    323         self.dataList.setCurrentIndex(0) 
    324         # Last file removed 
    325         if not self._data_list: 
    326             self._data = None 
    327             self.pr_plot = None 
    328             self._data_set = None 
    329             self.calculateThisButton.setEnabled(False) 
    330             self.calculateAllButton.setEnabled(False) 
    331             self.explorerButton.setEnabled(False) 
    332315 
    333316    ###################################################################### 
    334317    # GUI Interaction Events 
    335  
    336     def setCurrentModel(self, ref_item): 
    337         '''update the current model with stored values''' 
    338         if ref_item in self._models: 
    339             self.model = self._models[ref_item] 
    340318 
    341319    def update_calculator(self): 
     
    355333            InversionWindow.__init__(self.parent(), list(self._data_list.keys())) 
    356334            exit(0) 
    357         # TODO: Only send plot first time - otherwise, update in complete 
    358335        if self.pr_plot is not None: 
    359336            title = self.pr_plot.name 
     
    363340            GuiUtils.updateModelItemWithPlot(self._data, self.data_plot, title) 
    364341        if self.dmaxWindow is not None: 
    365              self.dmaxWindow.pr_state = self._calculator 
    366              self.dmaxWindow.nfunc = self.getNFunc() 
    367  
     342            self.dmaxWindow.pr_state = self._calculator 
     343            self.dmaxWindow.nfunc = self.getNFunc() 
     344            self.dmaxWindow.modelChanged() 
    368345        self.mapper.toFirst() 
    369346 
     
    410387        if not isinstance(data_item, list): 
    411388            msg = "Incorrect type passed to the P(r) Perspective" 
    412             raise AttributeError 
     389            raise AttributeError(msg) 
    413390 
    414391        for data in data_item: 
     
    417394                return 
    418395            # Create initial internal mappings 
    419             self._data_list[data] = self._calculator.clone() 
    420396            self._data_set = GuiUtils.dataFromItem(data) 
    421             self.data_plot_list[data] = self.data_plot 
    422             self.pr_plot_list[data] = self.pr_plot 
     397            self.logic = InversionLogic(self._data_set) 
    423398            self.populateDataComboBox(self._data_set.filename, data) 
    424399            self.setCurrentData(data) 
     
    426401            # Estimate initial values from data 
    427402            self.performEstimate() 
    428             self.logic = InversionLogic(self._data_set) 
    429403 
    430404            # Estimate q range 
     
    432406            self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("{:.4g}".format(qmin))) 
    433407            self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("{:.4g}".format(qmax))) 
    434             self._models[data] = self.model 
    435             self.model_item = data 
    436  
     408            self._data_list[data] = {DICT_KEYS[0]: self._calculator.clone(), 
     409                                     DICT_KEYS[1]: self.data_plot, 
     410                                     DICT_KEYS[2]: self.pr_plot, 
     411                                     DICT_KEYS[4]: self.logic} 
    437412        self.enableButtons() 
     413 
     414    def updateDataList(self, dataRef): 
     415        """Save the current data state of the window into self._data_list""" 
     416        self._data_list[dataRef] = { 
     417        DICT_KEYS[0]: self._calculator, 
     418        DICT_KEYS[1]: self.pr_plot, 
     419        DICT_KEYS[2]: self.data_plot, 
     420        DICT_KEYS[3]: self.dmaxWindow 
     421        } 
    438422 
    439423    def getNFunc(self): 
     
    448432 
    449433    def setCurrentData(self, data_ref): 
    450         """Get the current data and display as necessary""" 
    451  
     434        """Get the data by reference and display as necessary""" 
    452435        if data_ref is None: 
    453436            return 
    454  
    455437        if not isinstance(data_ref, QtGui.QStandardItem): 
    456438            msg = "Incorrect type passed to the P(r) Perspective" 
    457439            raise AttributeError 
    458  
    459440        # Data references 
    460441        self._data = data_ref 
    461442        self._data_set = GuiUtils.dataFromItem(data_ref) 
    462         self._calculator = self._data_list[data_ref] 
    463         self.pr_plot = self.pr_plot_list[data_ref] 
    464         self.data_plot = self.data_plot_list[data_ref] 
     443        self._calculator = self._data_list[data_ref].get(DICT_KEYS[0]) 
     444        self.pr_plot = self._data_list[data_ref].get(DICT_KEYS[1]) 
     445        self.data_plot = self._data_list[data_ref].get(DICT_KEYS[2]) 
     446        self.dmaxWindow = self._data_list[data_ref].get(DICT_KEYS[3]) 
     447        self.logic = self._data_list[data_ref].get(DICT_KEYS[4]) 
     448        # TODO: Do the values need to be updated when _calculator is changed? 
     449 
     450    def removeData(self): 
     451        """Remove the existing data reference from the P(r) Persepective""" 
     452        if self.dmaxWindow is not None: 
     453            self.dmaxWindow = None 
     454        self.dataList.removeItem(self.dataList.currentIndex()) 
     455        # TODO: Remove plot references from higher level too? 
     456        self.dataList.setCurrentIndex(0) 
     457        # Last file removed 
     458        self._data_list.pop(self._data) 
     459        if not self._data_list: 
     460            self._data = None 
     461            self.pr_plot = None 
     462            self._data_set = None 
     463            self.logic = InversionLogic() 
     464            self.enableButtons() 
     465        self.displayChange() 
    465466 
    466467    ###################################################################### 
     
    575576        :param elapsed: computation time 
    576577        """ 
     578        # TODO: Add estimates to DICT_KEYS 
    577579        nterms, alpha, message, elapsed = output_tuple 
    578580        # Save useful info 
     
    621623        self._calculator = pr 
    622624        # Append data to data list 
    623         self._data_list[self._data] = self._calculator.clone() 
    624  
    625         # Update model dict 
    626         self._models[self.model_item] = self.model 
     625        self._data_list[self._data][DICT_KEYS[0]] = self._calculator.clone() 
    627626 
    628627        # Create new P(r) and fit plots 
    629628        if self.pr_plot is None: 
    630629            self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 
    631             self.pr_plot_list[self._data] = self.pr_plot 
     630            self._data_list[self._data][DICT_KEYS[1]] = self.pr_plot 
    632631        else: 
    633632            # FIXME: this should update the existing plot, not create a new one 
    634633            self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 
    635             self.pr_plot_list[self._data] = self.pr_plot 
     634            self._data_list[self._data][DICT_KEYS[1]] = self.pr_plot 
    636635        if self.data_plot is None: 
    637636            self.data_plot = self.logic.new1DPlot(out, self._calculator) 
    638             self.data_plot_list[self._data] = self.data_plot 
     637            self._data_list[self._data][DICT_KEYS[2]] = self.data_plot 
    639638        else: 
    640639            # FIXME: this should update the existing plot, not create a new one 
    641640            self.data_plot = self.logic.new1DPlot(out, self._calculator) 
    642             self.data_plot_list[self._data] = self.data_plot 
     641            self._data_list[self._data][DICT_KEYS[2]] = self.data_plot 
    643642 
    644643    def _threadError(self, error): 
Note: See TracChangeset for help on using the changeset viewer.