Changes in src/sas/sasgui/perspectives/fitting/fitting.py [489f53a:a1b8fee] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitting.py
r489f53a ra1b8fee 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 return263 259 try: 264 260 for ext in ['.py', '.pyc']: 265 261 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 has268 # never been compiled. Don't try and delete it269 continue270 262 os.remove(p_path) 271 263 self.update_custom_combo() … … 369 361 'Add a new model function') 370 362 wx.EVT_MENU(owner, wx_id, self.make_new_model) 371 363 372 364 wx_id = wx.NewId() 373 365 self.edit_model_menu.Append(wx_id, 'Sum|Multi(p1, p2)', … … 391 383 '(Re)Load all models present in user plugin_models folder') 392 384 wx.EVT_MENU(owner, wx_id, self.load_plugin_models) 393 385 394 386 def set_edit_menu_helper(self, owner=None, menu=None): 395 387 """ … … 1742 1734 @param unsmeared_error: data error, rescaled to unsmeared model 1743 1735 """ 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, 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, 1782 1775 fid=data.id) 1783 if toggle_mode_on:1784 wx.PostEvent(self.parent,1785 NewPlotEvent(group_id=str(page_id) + " Model2D",1776 if toggle_mode_on: 1777 wx.PostEvent(self.parent, 1778 NewPlotEvent(group_id=str(page_id) + " Model2D", 1786 1779 action="Hide")) 1787 else:1788 if update_chisqr:1789 wx.PostEvent(current_pg,1790 Chi2UpdateEvent(output=self._cal_chisqr(1780 else: 1781 if update_chisqr: 1782 wx.PostEvent(current_pg, 1783 Chi2UpdateEvent(output=self._cal_chisqr( 1791 1784 data=data, 1792 1785 fid=fid, 1793 1786 weight=weight, 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: 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 1805 1793 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.")1809 1794 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1795 except: 1796 raise 1810 1797 1811 1798 def _calc_exception(self, etype, value, tb): … … 1832 1819 that can be plot. 1833 1820 """ 1834 number_finite = np.count_nonzero(np.isfinite(image))1835 1821 np.nan_to_num(image) 1836 1822 new_plot = Data2D(image=image, err_image=data.err_data) … … 1891 1877 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1892 1878 index=index, weight=weight) 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")) 1879 msg = "Computation completed!" 1880 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1904 1881 1905 1882 def _draw_model2D(self, model, page_id, qmin, … … 1935 1912 ## and may be the cause of other noted instabilities 1936 1913 ## 1937 ## -PDB August 12, 2014 1914 ## -PDB August 12, 2014 1938 1915 while self.calc_2D.isrunning(): 1939 1916 time.sleep(0.1) … … 1977 1954 if (self.calc_1D is not None) and self.calc_1D.isrunning(): 1978 1955 self.calc_1D.stop() 1979 ## stop just raises the flag -- the thread is supposed to 1956 ## stop just raises the flag -- the thread is supposed to 1980 1957 ## then kill itself but cannot. Paul Kienzle came up with 1981 1958 ## this fix to prevent threads from stepping on each other … … 1989 1966 ## a request to stop the computation. 1990 1967 ## It seems thus that the whole thread approach used here 1991 ## May need rethinking 1968 ## May need rethinking 1992 1969 ## 1993 1970 ## -PDB August 12, 2014 … … 2154 2131 residuals.dxw = None 2155 2132 residuals.ytransform = 'y' 2156 # For latter scale changes 2133 # For latter scale changes 2157 2134 residuals.xaxis('\\rm{Q} ', 'A^{-1}') 2158 2135 residuals.yaxis('\\rm{Residuals} ', 'normalized')
Note: See TracChangeset
for help on using the changeset viewer.