Changes in / [868846b:7b3f154] in sasview


Ignore:
Location:
src/sas/sasgui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/local_perspectives/plotting/plotting.py

    r235f514 r2d9526d  
    1414import wx 
    1515import sys 
     16from copy import deepcopy 
    1617from sas.sasgui.guiframe.events import EVT_NEW_PLOT 
    1718from sas.sasgui.guiframe.events import EVT_PLOT_QRANGE 
     
    275276                action_check = True 
    276277            else: 
     278                if action_string == 'update': 
     279                    # Update all existing plots of data with this ID 
     280                    for data in event.plots: 
     281                        for panel in self.plot_panels.values(): 
     282                            if data.id in panel.plots.keys(): 
     283                                plot_exists = True 
     284                                # Pass each panel it's own copy of the data 
     285                                # that's being updated, otherwise things like 
     286                                # colour and line thickness are unintentionally 
     287                                # synced across panels 
     288                                self.update_panel(deepcopy(data), panel) 
     289                    return 
     290                     
    277291                group_id = event.group_id 
    278                 if group_id in self.plot_panels.keys(): 
     292                if group_id in self.plot_panels: 
    279293                    #remove data from panel 
    280294                    if action_string == 'remove': 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    r489f53a r2d9526d  
    17421742            @param unsmeared_error: data error, rescaled to unsmeared model 
    17431743        """ 
    1744  
    17451744        number_finite = np.count_nonzero(np.isfinite(y)) 
    17461745        np.nan_to_num(y) 
     
    17481747                                         data_description=model.name, 
    17491748                                         data_id=str(page_id) + " " + data.name) 
     1749        plots_to_update = [] # List of plottables that have changed since last calculation 
     1750        # Create the new theories 
    17501751        if unsmeared_model is not None: 
    1751             self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 
     1752            unsmeared_model_plot = self.create_theory_1D(x, unsmeared_model,  
     1753                                  page_id, model, data, state, 
    17521754                                  data_description=model.name + " unsmeared", 
    17531755                                  data_id=str(page_id) + " " + data.name + " unsmeared") 
     1756            plots_to_update.append(unsmeared_model_plot) 
    17541757 
    17551758            if unsmeared_data is not None and unsmeared_error is not None: 
    1756                 self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 
     1759                unsmeared_data_plot = self.create_theory_1D(x, unsmeared_data,  
     1760                                      page_id, model, data, state, 
    17571761                                      data_description="Data unsmeared", 
    17581762                                      data_id="Data  " + data.name + " unsmeared", 
    17591763                                      dy=unsmeared_error) 
    1760         # Comment this out until we can get P*S models with correctly populated parameters 
    1761         #if sq_model is not None and pq_model is not None: 
    1762         #    self.create_theory_1D(x, sq_model, page_id, model, data, state, 
    1763         #                          data_description=model.name + " S(q)", 
    1764         #                          data_id=str(page_id) + " " + data.name + " S(q)") 
    1765         #    self.create_theory_1D(x, pq_model, page_id, model, data, state, 
    1766         #                          data_description=model.name + " P(q)", 
    1767         #                          data_id=str(page_id) + " " + data.name + " P(q)") 
     1764                plots_to_update.append(unsmeared_data_plot) 
     1765        if sq_model is not None and pq_model is not None: 
     1766            sq_id = str(page_id) + " " + data.name + " S(q)" 
     1767            sq_plot = self.create_theory_1D(x, sq_model, page_id, model, data, state, 
     1768                                  data_description=model.name + " S(q)", 
     1769                                  data_id=sq_id) 
     1770            plots_to_update.append(sq_plot) 
     1771            pq_id = str(page_id) + " " + data.name + " P(q)" 
     1772            pq_plot = self.create_theory_1D(x, pq_model, page_id, model, data, state, 
     1773                                  data_description=model.name + " P(q)", 
     1774                                  data_id=pq_id) 
     1775            plots_to_update.append(pq_plot) 
     1776        # Update the P(Q), S(Q) and unsmeared theory plots if they exist 
     1777        wx.PostEvent(self.parent, NewPlotEvent(plots=plots_to_update,  
     1778                                              action='update')) 
    17681779 
    17691780        current_pg = self.fit_panel.get_page_by_id(page_id) 
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    r7432acb r0f9ea1c  
    7171                    (self.data.qy_data * self.data.qy_data)) 
    7272 
    73         # For theory, qmax is based on 1d qmax  
     73        # For theory, qmax is based on 1d qmax 
    7474        # so that must be mulitified by sqrt(2) to get actual max for 2d 
    7575        index_model = (self.qmin <= radius) & (radius <= self.qmax) 
     
    9191                self.data.qy_data[index_model] 
    9292            ]) 
    93         output = np.zeros(len(self.data.qx_data)) 
     93        # Initialize output to NaN so masked elements do not get plotted. 
     94        output = np.empty_like(self.data.qx_data) 
    9495        # output default is None 
    9596        # This method is to distinguish between masked 
    9697        #point(nan) and data point = 0. 
    97         output = output / output 
     98        output[:] = np.NaN 
    9899        # set value for self.mask==True, else still None to Plottools 
    99100        output[index_model] = value 
     
    198199            output[index] = self.model.evalDistribution(self.data.x[index]) 
    199200 
     201        x=self.data.x[index] 
     202        y=output[index] 
    200203        sq_values = None 
    201204        pq_values = None 
    202         s_model = None 
    203         p_model = None 
    204205        if isinstance(self.model, MultiplicationModel): 
    205206            s_model = self.model.s_model 
    206207            p_model = self.model.p_model 
    207         elif hasattr(self.model, "get_composition_models"): 
    208             p_model, s_model = self.model.get_composition_models() 
    209  
    210         if p_model is not None and s_model is not None: 
    211             sq_values = np.zeros((len(self.data.x))) 
    212             pq_values = np.zeros((len(self.data.x))) 
    213             sq_values[index] = s_model.evalDistribution(self.data.x[index]) 
    214             pq_values[index] = p_model.evalDistribution(self.data.x[index]) 
     208            sq_values = s_model.evalDistribution(x) 
     209            pq_values = p_model.evalDistribution(x) 
     210        elif hasattr(self.model, "calc_composition_models"): 
     211            results = self.model.calc_composition_models(x) 
     212            if results is not None: 
     213                pq_values, sq_values = results 
     214 
    215215 
    216216        elapsed = time.time() - self.starttime 
    217217 
    218         self.complete(x=self.data.x[index], y=output[index], 
     218        self.complete(x=x, y=y, 
    219219                      page_id=self.page_id, 
    220220                      state=self.state, 
  • src/sas/sasgui/plottools/plottables.py

    r45dffa69 r2d9526d  
    239239    def replace(self, plottable): 
    240240        """Replace an existing plottable from the graph""" 
    241         selected_color = None 
     241        # If the user has set a custom color, ensure the new plot is the same color 
     242        selected_color = plottable.custom_color 
    242243        selected_plottable = None 
    243244        for p in self.plottables.keys(): 
    244245            if plottable.id == p.id: 
    245246                selected_plottable = p 
    246                 selected_color = self.plottables[p] 
     247                if selected_color is None: 
     248                    selected_color = self.plottables[p] 
    247249                break 
    248         if  selected_plottable is not None and selected_color is not None: 
     250        if selected_plottable is not None and selected_color is not None: 
    249251            del self.plottables[selected_plottable] 
     252            plottable.custom_color = selected_color 
    250253            self.plottables[plottable] = selected_color 
    251254 
Note: See TracChangeset for help on using the changeset viewer.