Changeset 43345ab in sasview for src/sas/sasgui/perspectives/fitting
- Timestamp:
- Aug 21, 2017 10:50:05 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:
- 467068d
- Parents:
- e3f1fed (diff), d24e41d (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 rd24e41d 257 257 toks = os.path.splitext(label) 258 258 path = os.path.join(models.find_plugins_dir(), toks[0]) 259 message = "Are you sure you want to delete the file {}?".format(path) 260 dlg = wx.MessageDialog(self.frame, message, '', wx.YES_NO | wx.ICON_QUESTION) 261 if not dlg.ShowModal() == wx.ID_YES: 262 return 259 263 try: 260 264 for ext in ['.py', '.pyc']: 261 265 p_path = path + ext 266 if ext == '.pyc' and not os.path.isfile(path + ext): 267 # If model is invalid, .pyc file may not exist as model has 268 # never been compiled. Don't try and delete it 269 continue 262 270 os.remove(p_path) 263 271 self.update_custom_combo() … … 383 391 '(Re)Load all models present in user plugin_models folder') 384 392 wx.EVT_MENU(owner, wx_id, self.load_plugin_models) 385 393 386 394 def set_edit_menu_helper(self, owner=None, menu=None): 387 395 """ … … 1734 1742 @param unsmeared_error: data error, rescaled to unsmeared model 1735 1743 """ 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, 1744 number_finite = np.count_nonzero(np.isfinite(y)) 1745 np.nan_to_num(y) 1746 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1747 data_description=model.name, 1748 data_id=str(page_id) + " " + data.name) 1749 if unsmeared_model is not None: 1750 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 1751 data_description=model.name + " unsmeared", 1752 data_id=str(page_id) + " " + data.name + " unsmeared") 1753 1754 if unsmeared_data is not None and unsmeared_error is not None: 1755 self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 1756 data_description="Data unsmeared", 1757 data_id="Data " + data.name + " unsmeared", 1758 dy=unsmeared_error) 1759 # Comment this out until we can get P*S models with correctly populated parameters 1760 if sq_model is not None and pq_model is not None: 1761 self.create_theory_1D(x, sq_model, page_id, model, data, state, 1762 data_description=model.name + " S(q)", 1763 data_id=str(page_id) + " " + data.name + " S(q)") 1764 self.create_theory_1D(x, pq_model, page_id, model, data, state, 1765 data_description=model.name + " P(q)", 1766 data_id=str(page_id) + " " + data.name + " P(q)") 1767 1768 current_pg = self.fit_panel.get_page_by_id(page_id) 1769 title = new_plot.title 1770 batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 1771 if not batch_on: 1772 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 1773 elif plot_result: 1774 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 1775 if data.id == top_data_id: 1776 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 1777 caption = current_pg.window_caption 1778 self.page_finder[page_id].set_fit_tab_caption(caption=caption) 1779 1780 self.page_finder[page_id].set_theory_data(data=new_plot, 1774 1781 fid=data.id) 1775 1776 1777 1782 if toggle_mode_on: 1783 wx.PostEvent(self.parent, 1784 NewPlotEvent(group_id=str(page_id) + " Model2D", 1778 1785 action="Hide")) 1779 1780 1781 1782 1786 else: 1787 if update_chisqr: 1788 wx.PostEvent(current_pg, 1789 Chi2UpdateEvent(output=self._cal_chisqr( 1783 1790 data=data, 1784 1791 fid=fid, 1785 1792 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 1793 page_id=page_id, 1794 index=index))) 1795 else: 1796 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1797 index=index, weight=weight) 1798 1799 if not number_finite: 1800 logger.error("Using the present parameters the model does not return any finite value. ") 1801 msg = "Computing Error: Model did not return any finite value." 1802 wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 1803 else: 1792 1804 msg = "Computation completed!" 1805 if number_finite != y.size: 1806 msg += ' PROBLEM: For some Q values the model returns non finite intensities!' 1807 logger.error("For some Q values the model returns non finite intensities.") 1793 1808 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1794 except:1795 raise1796 1809 1797 1810 def _calc_exception(self, etype, value, tb): … … 1818 1831 that can be plot. 1819 1832 """ 1833 number_finite = np.count_nonzero(np.isfinite(image)) 1820 1834 np.nan_to_num(image) 1821 1835 new_plot = Data2D(image=image, err_image=data.err_data) … … 1876 1890 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1877 1891 index=index, weight=weight) 1878 msg = "Computation completed!" 1879 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1892 1893 if not number_finite: 1894 logger.error("Using the present parameters the model does not return any finite value. ") 1895 msg = "Computing Error: Model did not return any finite value." 1896 wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 1897 else: 1898 msg = "Computation completed!" 1899 if number_finite != image.size: 1900 msg += ' PROBLEM: For some Qx,Qy values the model returns non finite intensities!' 1901 logger.error("For some Qx,Qy values the model returns non finite intensities.") 1902 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1880 1903 1881 1904 def _draw_model2D(self, model, page_id, qmin, -
src/sas/sasgui/perspectives/fitting/models.py
ra1b8fee rb1c2011 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) 188 model.name = PLUGIN_NAME_BASE + model.name 188 if not model.name.count(PLUGIN_NAME_BASE): 189 model.name = PLUGIN_NAME_BASE + model.name 189 190 plugins[model.name] = model 190 191 except Exception: … … 193 194 plugin_log(msg) 194 195 logger.warning("Failed to load plugin %r. See %s for details" 195 196 196 % (path, PLUGIN_LOG)) 197 197 198 return plugins 198 199 … … 264 265 temp = {} 265 266 if self.is_changed(): 266 return _find Models(dir)267 return _find_models() 267 268 logger.info("plugin model : %s" % str(temp)) 268 269 return temp … … 297 298 for name, plug in self.stored_plugins.iteritems(): 298 299 self.model_dictionary[name] = plug 299 300 300 301 self._get_multifunc_models() 301 302 … … 339 340 """ 340 341 self.plugins = [] 341 new_plugins = _find Models(dir)342 new_plugins = _find_models() 342 343 for name, plug in new_plugins.iteritems(): 343 344 for stored_name, stored_plug in self.stored_plugins.iteritems(): -
src/sas/sasgui/perspectives/fitting/model_thread.py
r426df2e re3f1fed 211 211 results = self.model.calc_composition_models(x) 212 212 if results is not None: 213 sq_values = results[ 0]214 pq_values = results[ 1]213 sq_values = results[1] 214 pq_values = results[0] 215 215 216 216
Note: See TracChangeset
for help on using the changeset viewer.