Changeset e61a9b1 in sasview for src/sas/sasgui/perspectives/fitting
- Timestamp:
- Aug 17, 2017 10:01:11 AM (7 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.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. - Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
ra1b8fee r914c49d5 254 254 if not hasattr(self, "model_view"): 255 255 return 256 toggle_mode_on = self.model_view.IsEnabled() 256 toggle_mode_on = self.model_view.IsEnabled() or self.data is None 257 257 if toggle_mode_on: 258 258 if self.enable2D and not check_data_validity(self.data): -
src/sas/sasgui/perspectives/fitting/fitting.py
rfc6651c re61a9b1 383 383 '(Re)Load all models present in user plugin_models folder') 384 384 wx.EVT_MENU(owner, wx_id, self.load_plugin_models) 385 385 386 386 def set_edit_menu_helper(self, owner=None, menu=None): 387 387 """ … … 1734 1734 @param unsmeared_error: data error, rescaled to unsmeared model 1735 1735 """ 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, 1774 1773 fid=data.id) 1775 1776 1777 1774 if toggle_mode_on: 1775 wx.PostEvent(self.parent, 1776 NewPlotEvent(group_id=str(page_id) + " Model2D", 1778 1777 action="Hide")) 1779 1780 1781 1782 1778 else: 1779 if update_chisqr: 1780 wx.PostEvent(current_pg, 1781 Chi2UpdateEvent(output=self._cal_chisqr( 1783 1782 data=data, 1784 1783 fid=fid, 1785 1784 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: 1792 1796 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.") 1793 1800 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1794 except:1795 raise1796 1801 1797 1802 def _calc_exception(self, etype, value, tb): … … 1818 1823 that can be plot. 1819 1824 """ 1825 number_finite = np.count_nonzero(np.isfinite(image)) 1820 1826 np.nan_to_num(image) 1821 1827 new_plot = Data2D(image=image, err_image=data.err_data) … … 1876 1882 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1877 1883 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")) 1880 1895 1881 1896 def _draw_model2D(self, model, page_id, qmin, -
src/sas/sasgui/perspectives/fitting/models.py
ra1b8fee r8cec26b 156 156 try: 157 157 import compileall 158 compileall.compile_dir(dir=dir, ddir=dir, force= 1,158 compileall.compile_dir(dir=dir, ddir=dir, force=0, 159 159 quiet=report_problem) 160 160 except: … … 163 163 164 164 165 def _find Models(dir):165 def _find_models(): 166 166 """ 167 167 Find custom models 168 168 """ 169 169 # List of plugin objects 170 dir = find_plugins_dir()170 directory = find_plugins_dir() 171 171 # 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 174 174 logger.warning(msg) 175 175 return {} 176 176 177 plugin_log("looking for models in: %s" % str(dir ))178 # compile_file(dir) #always recompile the folder plugin179 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)) 180 180 181 181 plugins = {} 182 for filename in os.listdir(dir ):182 for filename in os.listdir(directory): 183 183 name, ext = os.path.splitext(filename) 184 184 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)) 186 186 try: 187 187 model = load_custom_model(path) … … 193 193 plugin_log(msg) 194 194 logger.warning("Failed to load plugin %r. See %s for details" 195 196 195 % (path, PLUGIN_LOG)) 196 197 197 return plugins 198 198 … … 264 264 temp = {} 265 265 if self.is_changed(): 266 return _find Models(dir)266 return _find_models() 267 267 logger.info("plugin model : %s" % str(temp)) 268 268 return temp … … 339 339 """ 340 340 self.plugins = [] 341 new_plugins = _find Models(dir)341 new_plugins = _find_models() 342 342 for name, plug in new_plugins.iteritems(): 343 343 for stored_name, stored_plug in self.stored_plugins.iteritems(): -
src/sas/sasgui/perspectives/fitting/model_thread.py
r7432acb r426df2e 71 71 (self.data.qy_data * self.data.qy_data)) 72 72 73 # For theory, qmax is based on 1d qmax 73 # For theory, qmax is based on 1d qmax 74 74 # so that must be mulitified by sqrt(2) to get actual max for 2d 75 75 index_model = (self.qmin <= radius) & (radius <= self.qmax) … … 91 91 self.data.qy_data[index_model] 92 92 ]) 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) 94 95 # output default is None 95 96 # This method is to distinguish between masked 96 97 #point(nan) and data point = 0. 97 output = output / output98 output[:] = np.NaN 98 99 # set value for self.mask==True, else still None to Plottools 99 100 output[index_model] = value … … 198 199 output[index] = self.model.evalDistribution(self.data.x[index]) 199 200 201 x=self.data.x[index] 202 y=output[index] 200 203 sq_values = None 201 204 pq_values = None 202 s_model = None203 p_model = None204 205 if isinstance(self.model, MultiplicationModel): 205 206 s_model = self.model.s_model 206 207 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 215 216 216 217 elapsed = time.time() - self.starttime 217 218 218 self.complete(x= self.data.x[index], y=output[index],219 self.complete(x=x, y=y, 219 220 page_id=self.page_id, 220 221 state=self.state,
Note: See TracChangeset
for help on using the changeset viewer.