Changes in src/sas/sasgui/perspectives/fitting/fitting.py [a1b8fee:489f53a] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitting.py
ra1b8fee r489f53a 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() … … 361 369 'Add a new model function') 362 370 wx.EVT_MENU(owner, wx_id, self.make_new_model) 363 371 364 372 wx_id = wx.NewId() 365 373 self.edit_model_menu.Append(wx_id, 'Sum|Multi(p1, p2)', … … 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 # 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, 1765 title=str(title))) 1766 elif plot_result: 1767 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 1768 if data.id == top_data_id: 1769 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 1770 title=str(title))) 1771 caption = current_pg.window_caption 1772 self.page_finder[page_id].set_fit_tab_caption(caption=caption) 1773 1774 self.page_finder[page_id].set_theory_data(data=new_plot, 1744 1745 number_finite = np.count_nonzero(np.isfinite(y)) 1746 np.nan_to_num(y) 1747 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1748 data_description=model.name, 1749 data_id=str(page_id) + " " + data.name) 1750 if unsmeared_model is not None: 1751 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 1752 data_description=model.name + " unsmeared", 1753 data_id=str(page_id) + " " + data.name + " unsmeared") 1754 1755 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, 1757 data_description="Data unsmeared", 1758 data_id="Data " + data.name + " unsmeared", 1759 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)") 1768 1769 current_pg = self.fit_panel.get_page_by_id(page_id) 1770 title = new_plot.title 1771 batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 1772 if not batch_on: 1773 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 1774 elif plot_result: 1775 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 1776 if data.id == top_data_id: 1777 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=str(title))) 1778 caption = current_pg.window_caption 1779 self.page_finder[page_id].set_fit_tab_caption(caption=caption) 1780 1781 self.page_finder[page_id].set_theory_data(data=new_plot, 1775 1782 fid=data.id) 1776 1777 1778 1783 if toggle_mode_on: 1784 wx.PostEvent(self.parent, 1785 NewPlotEvent(group_id=str(page_id) + " Model2D", 1779 1786 action="Hide")) 1780 1781 1782 1783 1787 else: 1788 if update_chisqr: 1789 wx.PostEvent(current_pg, 1790 Chi2UpdateEvent(output=self._cal_chisqr( 1784 1791 data=data, 1785 1792 fid=fid, 1786 1793 weight=weight, 1787 page_id=page_id, 1788 index=index))) 1789 else: 1790 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1791 index=index, weight=weight) 1792 1794 page_id=page_id, 1795 index=index))) 1796 else: 1797 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1798 index=index, weight=weight) 1799 1800 if not number_finite: 1801 logger.error("Using the present parameters the model does not return any finite value. ") 1802 msg = "Computing Error: Model did not return any finite value." 1803 wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 1804 else: 1793 1805 msg = "Computation completed!" 1806 if number_finite != y.size: 1807 msg += ' PROBLEM: For some Q values the model returns non finite intensities!' 1808 logger.error("For some Q values the model returns non finite intensities.") 1794 1809 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1795 except:1796 raise1797 1810 1798 1811 def _calc_exception(self, etype, value, tb): … … 1819 1832 that can be plot. 1820 1833 """ 1834 number_finite = np.count_nonzero(np.isfinite(image)) 1821 1835 np.nan_to_num(image) 1822 1836 new_plot = Data2D(image=image, err_image=data.err_data) … … 1877 1891 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1878 1892 index=index, weight=weight) 1879 msg = "Computation completed!" 1880 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1893 1894 if not number_finite: 1895 logger.error("Using the present parameters the model does not return any finite value. ") 1896 msg = "Computing Error: Model did not return any finite value." 1897 wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 1898 else: 1899 msg = "Computation completed!" 1900 if number_finite != image.size: 1901 msg += ' PROBLEM: For some Qx,Qy values the model returns non finite intensities!' 1902 logger.error("For some Qx,Qy values the model returns non finite intensities.") 1903 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1881 1904 1882 1905 def _draw_model2D(self, model, page_id, qmin, … … 1912 1935 ## and may be the cause of other noted instabilities 1913 1936 ## 1914 ## -PDB August 12, 2014 1937 ## -PDB August 12, 2014 1915 1938 while self.calc_2D.isrunning(): 1916 1939 time.sleep(0.1) … … 1954 1977 if (self.calc_1D is not None) and self.calc_1D.isrunning(): 1955 1978 self.calc_1D.stop() 1956 ## stop just raises the flag -- the thread is supposed to 1979 ## stop just raises the flag -- the thread is supposed to 1957 1980 ## then kill itself but cannot. Paul Kienzle came up with 1958 1981 ## this fix to prevent threads from stepping on each other … … 1966 1989 ## a request to stop the computation. 1967 1990 ## It seems thus that the whole thread approach used here 1968 ## May need rethinking 1991 ## May need rethinking 1969 1992 ## 1970 1993 ## -PDB August 12, 2014 … … 2131 2154 residuals.dxw = None 2132 2155 residuals.ytransform = 'y' 2133 # For latter scale changes 2156 # For latter scale changes 2134 2157 residuals.xaxis('\\rm{Q} ', 'A^{-1}') 2135 2158 residuals.yaxis('\\rm{Residuals} ', 'normalized')
Note: See TracChangeset
for help on using the changeset viewer.