Changeset e61a9b1 in sasview for src/sas/sasgui/perspectives


Ignore:
Timestamp:
Aug 17, 2017 8:01:11 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
d24e41d
Parents:
fc6651c (diff), bc04647 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into FixingTicket741

Location:
src/sas/sasgui/perspectives/fitting
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/basepage.py

    ra1b8fee r914c49d5  
    254254        if not hasattr(self, "model_view"): 
    255255            return 
    256         toggle_mode_on = self.model_view.IsEnabled() 
     256        toggle_mode_on = self.model_view.IsEnabled() or self.data is None 
    257257        if toggle_mode_on: 
    258258            if self.enable2D and not check_data_validity(self.data): 
  • src/sas/sasgui/perspectives/fitting/fitting.py

    rfc6651c re61a9b1  
    383383          '(Re)Load all models present in user plugin_models folder') 
    384384        wx.EVT_MENU(owner, wx_id, self.load_plugin_models) 
    385     
     385 
    386386    def set_edit_menu_helper(self, owner=None, menu=None): 
    387387        """ 
     
    17341734            @param unsmeared_error: data error, rescaled to unsmeared model 
    17351735        """ 
    1736         try: 
    1737             np.nan_to_num(y) 
    1738             new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 
    1739                                              data_description=model.name, 
    1740                                              data_id=str(page_id) + " " + data.name) 
    1741             if unsmeared_model is not None: 
    1742                 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 
    1743                                       data_description=model.name + " unsmeared", 
    1744                                       data_id=str(page_id) + " " + data.name + " unsmeared") 
    1745  
    1746                 if unsmeared_data is not None and unsmeared_error is not None: 
    1747                     self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 
    1748                                           data_description="Data unsmeared", 
    1749                                           data_id="Data  " + data.name + " unsmeared", 
    1750                                           dy=unsmeared_error) 
    1751             if sq_model is not None and pq_model is not None: 
    1752                 self.create_theory_1D(x, sq_model, page_id, model, data, state, 
    1753                                       data_description=model.name + " S(q)", 
    1754                                       data_id=str(page_id) + " " + data.name + " S(q)") 
    1755                 self.create_theory_1D(x, pq_model, page_id, model, data, state, 
    1756                                       data_description=model.name + " P(q)", 
    1757                                       data_id=str(page_id) + " " + data.name + " P(q)") 
    1758  
    1759             current_pg = self.fit_panel.get_page_by_id(page_id) 
    1760             title = new_plot.title 
    1761             batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 
    1762             if not batch_on: 
    1763                 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
    1764                                             title=str(title))) 
    1765             elif plot_result: 
    1766                 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 
    1767                 if data.id == top_data_id: 
    1768                     wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 
    1769                                             title=str(title))) 
    1770             caption = current_pg.window_caption 
    1771             self.page_finder[page_id].set_fit_tab_caption(caption=caption) 
    1772  
    1773             self.page_finder[page_id].set_theory_data(data=new_plot, 
     1736        number_finite = np.count_nonzero(np.isfinite(y)) 
     1737        np.nan_to_num(y) 
     1738        new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 
     1739                                         data_description=model.name, 
     1740                                         data_id=str(page_id) + " " + data.name) 
     1741        if unsmeared_model is not None: 
     1742            self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 
     1743                                  data_description=model.name + " unsmeared", 
     1744                                  data_id=str(page_id) + " " + data.name + " unsmeared") 
     1745 
     1746            if unsmeared_data is not None and unsmeared_error is not None: 
     1747                self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 
     1748                                      data_description="Data unsmeared", 
     1749                                      data_id="Data  " + data.name + " unsmeared", 
     1750                                      dy=unsmeared_error) 
     1751        # Comment this out until we can get P*S models with correctly populated parameters 
     1752        if sq_model is not None and pq_model is not None: 
     1753            self.create_theory_1D(x, sq_model, page_id, model, data, state, 
     1754                                  data_description=model.name + " S(q)", 
     1755                                  data_id=str(page_id) + " " + data.name + " S(q)") 
     1756            self.create_theory_1D(x, pq_model, page_id, model, data, state, 
     1757                                  data_description=model.name + " P(q)", 
     1758                                  data_id=str(page_id) + " " + data.name + " P(q)") 
     1759 
     1760        current_pg = self.fit_panel.get_page_by_id(page_id) 
     1761        title = new_plot.title 
     1762        batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 
     1763        if not batch_on: 
     1764            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 
     1765        elif plot_result: 
     1766            top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 
     1767            if data.id == top_data_id: 
     1768                wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 
     1769        caption = current_pg.window_caption 
     1770        self.page_finder[page_id].set_fit_tab_caption(caption=caption) 
     1771 
     1772        self.page_finder[page_id].set_theory_data(data=new_plot, 
    17741773                                                      fid=data.id) 
    1775             if toggle_mode_on: 
    1776                 wx.PostEvent(self.parent, 
    1777                              NewPlotEvent(group_id=str(page_id) + " Model2D", 
     1774        if toggle_mode_on: 
     1775            wx.PostEvent(self.parent, 
     1776                         NewPlotEvent(group_id=str(page_id) + " Model2D", 
    17781777                                          action="Hide")) 
    1779             else: 
    1780                 if update_chisqr: 
    1781                     wx.PostEvent(current_pg, 
    1782                                  Chi2UpdateEvent(output=self._cal_chisqr( 
     1778        else: 
     1779            if update_chisqr: 
     1780                wx.PostEvent(current_pg, 
     1781                             Chi2UpdateEvent(output=self._cal_chisqr( 
    17831782                                                                data=data, 
    17841783                                                                fid=fid, 
    17851784                                                                weight=weight, 
    1786                                                             page_id=page_id, 
    1787                                                             index=index))) 
    1788                 else: 
    1789                     self._plot_residuals(page_id=page_id, data=data, fid=fid, 
    1790                                          index=index, weight=weight) 
    1791  
     1785                                                                page_id=page_id, 
     1786                                                                index=index))) 
     1787            else: 
     1788                self._plot_residuals(page_id=page_id, data=data, fid=fid, 
     1789                                     index=index, weight=weight) 
     1790 
     1791        if not number_finite: 
     1792            logger.error("Using the present parameters the model does not return any finite value. ") 
     1793            msg = "Computing Error: Model did not return any finite value." 
     1794            wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 
     1795        else: 
    17921796            msg = "Computation  completed!" 
     1797            if number_finite != y.size: 
     1798                msg += ' PROBLEM: For some Q values the model returns non finite intensities!' 
     1799                logger.error("For some Q values the model returns non finite intensities.") 
    17931800            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    1794         except: 
    1795             raise 
    17961801 
    17971802    def _calc_exception(self, etype, value, tb): 
     
    18181823        that can be plot. 
    18191824        """ 
     1825        number_finite = np.count_nonzero(np.isfinite(image)) 
    18201826        np.nan_to_num(image) 
    18211827        new_plot = Data2D(image=image, err_image=data.err_data) 
     
    18761882                self._plot_residuals(page_id=page_id, data=data, fid=fid, 
    18771883                                      index=index, weight=weight) 
    1878         msg = "Computation  completed!" 
    1879         wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
     1884 
     1885        if not number_finite: 
     1886            logger.error("Using the present parameters the model does not return any finite value. ") 
     1887            msg = "Computing Error: Model did not return any finite value." 
     1888            wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 
     1889        else: 
     1890            msg = "Computation  completed!" 
     1891            if number_finite != image.size: 
     1892                msg += ' PROBLEM: For some Qx,Qy values the model returns non finite intensities!' 
     1893                logger.error("For some Qx,Qy values the model returns non finite intensities.") 
     1894            wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 
    18801895 
    18811896    def _draw_model2D(self, model, page_id, qmin, 
  • src/sas/sasgui/perspectives/fitting/models.py

    ra1b8fee r8cec26b  
    156156    try: 
    157157        import compileall 
    158         compileall.compile_dir(dir=dir, ddir=dir, force=1, 
     158        compileall.compile_dir(dir=dir, ddir=dir, force=0, 
    159159                               quiet=report_problem) 
    160160    except: 
     
    163163 
    164164 
    165 def _findModels(dir): 
     165def _find_models(): 
    166166    """ 
    167167    Find custom models 
    168168    """ 
    169169    # List of plugin objects 
    170     dir = find_plugins_dir() 
     170    directory = find_plugins_dir() 
    171171    # Go through files in plug-in directory 
    172     if not os.path.isdir(dir): 
    173         msg = "SasView couldn't locate Model plugin folder %r." % dir 
     172    if not os.path.isdir(directory): 
     173        msg = "SasView couldn't locate Model plugin folder %r." % directory 
    174174        logger.warning(msg) 
    175175        return {} 
    176176 
    177     plugin_log("looking for models in: %s" % str(dir)) 
    178     #compile_file(dir)  #always recompile the folder plugin 
    179     logger.info("plugin model dir: %s" % str(dir)) 
     177    plugin_log("looking for models in: %s" % str(directory)) 
     178    # compile_file(directory)  #always recompile the folder plugin 
     179    logger.info("plugin model dir: %s" % str(directory)) 
    180180 
    181181    plugins = {} 
    182     for filename in os.listdir(dir): 
     182    for filename in os.listdir(directory): 
    183183        name, ext = os.path.splitext(filename) 
    184184        if ext == '.py' and not name == '__init__': 
    185             path = os.path.abspath(os.path.join(dir, filename)) 
     185            path = os.path.abspath(os.path.join(directory, filename)) 
    186186            try: 
    187187                model = load_custom_model(path) 
     
    193193                plugin_log(msg) 
    194194                logger.warning("Failed to load plugin %r. See %s for details" 
    195                                 % (path, PLUGIN_LOG)) 
    196              
     195                               % (path, PLUGIN_LOG)) 
     196 
    197197    return plugins 
    198198 
     
    264264        temp = {} 
    265265        if self.is_changed(): 
    266             return  _findModels(dir) 
     266            return  _find_models() 
    267267        logger.info("plugin model : %s" % str(temp)) 
    268268        return temp 
     
    339339        """ 
    340340        self.plugins = [] 
    341         new_plugins = _findModels(dir) 
     341        new_plugins = _find_models() 
    342342        for name, plug in  new_plugins.iteritems(): 
    343343            for stored_name, stored_plug in self.stored_plugins.iteritems(): 
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    r7432acb r426df2e  
    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                sq_values = results[0] 
     214                pq_values = results[1] 
     215 
    215216 
    216217        elapsed = time.time() - self.starttime 
    217218 
    218         self.complete(x=self.data.x[index], y=output[index], 
     219        self.complete(x=x, y=y, 
    219220                      page_id=self.page_id, 
    220221                      state=self.state, 
Note: See TracChangeset for help on using the changeset viewer.