Changeset a534432 in sasview
- Timestamp:
- May 15, 2017 10:19:32 AM (8 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:
- 87ac6eb
- Parents:
- 82373f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitting.py
r82373f5 ra534432 11 11 #copyright 2009, University of Tennessee 12 12 ################################################################################ 13 from __future__ import print_function 14 13 15 import re 14 16 import sys … … 302 304 Make new model 303 305 """ 304 if self.new_model_frame !=None:306 if self.new_model_frame is not None: 305 307 self.new_model_frame.Show(False) 306 308 self.new_model_frame.Show(True) … … 386 388 help for setting list of the edit model menu labels 387 389 """ 388 if menu ==None:390 if menu is None: 389 391 menu = self.edit_custom_model 390 392 list_fnames = os.listdir(models.find_plugins_dir()) … … 441 443 wx.PostEvent(self.parent, StatusEvent(status=msg)) 442 444 443 if page !=None:445 if page is not None: 444 446 return set_focus_page(page) 445 447 if caption == "Const & Simul Fit": … … 634 636 state = self.temp_state[self.state_index] 635 637 #panel state should have model selection to set_state 636 if state.formfactorcombobox !=None:638 if state.formfactorcombobox is not None: 637 639 #set state 638 640 data = self.parent.create_gui_data(state.data) … … 1016 1018 return False 1017 1019 ## If a thread is already started, stop it 1018 #if self.calc_fit !=None and self.calc_fit.isrunning():1020 #if self.calc_fitis not None and self.calc_fit.isrunning(): 1019 1021 # self.calc_fit.stop() 1020 1022 msg = "Fitting is in progress..." … … 1106 1108 page = self.fit_panel.add_empty_page() 1107 1109 # add data associated to the page created 1108 if page !=None:1110 if page is not None: 1109 1111 evt = StatusEvent(status="Page Created", info="info") 1110 1112 wx.PostEvent(self.parent, evt) … … 1125 1127 page = self.fit_panel.set_data(data) 1126 1128 # page could be None when loading state files 1127 if page ==None:1129 if page is None: 1128 1130 return page 1129 1131 #append Data1D to the panel containing its theory … … 1193 1195 """ 1194 1196 # case that uid is not specified 1195 if uid ==None:1197 if uid is None: 1196 1198 for page_id in self.page_finder.keys(): 1197 1199 self.page_finder[page_id].schedule_tofit(value) … … 1216 1218 for item in param: 1217 1219 ## check if constraint 1218 if item[0] != None and item[1] !=None:1220 if item[0] is not None and item[1] is not None: 1219 1221 listOfConstraint.append((item[0], item[1])) 1220 1222 new_model = model … … 1231 1233 """ 1232 1234 panel = self.plot_panel 1233 if panel ==None:1235 if panel is None: 1234 1236 raise ValueError, "Fitting:_onSelect: NonType panel" 1235 1237 Plugin.on_perspective(self, event=event) … … 1253 1255 """ 1254 1256 """ 1255 print "update_fit result", result1257 print("update_fit result", result) 1256 1258 1257 1259 def _batch_fit_complete(self, result, pars, page_id, … … 1335 1337 if not correct_result or res.fitness is None or \ 1336 1338 not np.isfinite(res.fitness) or \ 1337 np.any(res.pvec ==None) or not \1339 np.any(res.pvec is None) or not \ 1338 1340 np.all(np.isfinite(res.pvec)): 1339 1341 data_name = str(None) … … 1457 1459 cell.value = index 1458 1460 1459 if theory_data !=None:1461 if theory_data is not None: 1460 1462 #Suucessful fit 1461 1463 theory_data.id = wx.NewId() … … 1526 1528 if res.fitness is None or \ 1527 1529 not np.isfinite(res.fitness) or \ 1528 np.any(res.pvec ==None) or \1530 np.any(res.pvec is None) or \ 1529 1531 not np.all(np.isfinite(res.pvec)): 1530 1532 fit_msg += "\nFitting did not converge!!!" … … 1544 1546 #(CallAfter is important to MAC) 1545 1547 try: 1546 #if res !=None:1548 #if res is not None: 1547 1549 wx.CallAfter(cpage.onsetValues, res.fitness, 1548 1550 res.param_list, … … 1587 1589 """ 1588 1590 event.Skip() 1589 if self.menu1 ==None:1591 if self.menu1 is None: 1590 1592 return 1591 1593 menu_item = self.menu1.FindItemById(self.id_reset_flag) … … 1646 1648 caption = evt.caption 1647 1649 enable_smearer = evt.enable_smearer 1648 if model ==None:1650 if model is None: 1649 1651 return 1650 1652 if uid not in self.page_finder.keys(): … … 1698 1700 new_plot.title = data.name 1699 1701 new_plot.group_id = data.group_id 1700 if new_plot.group_id ==None:1702 if new_plot.group_id is None: 1701 1703 new_plot.group_id = data.group_id 1702 1704 new_plot.id = data_id … … 1732 1734 @param unsmeared_error: data error, rescaled to unsmeared model 1733 1735 """ 1734 try: 1735 number_finite = np.count_nonzero(np.isfinite(y)) 1736 if not number_finite: 1737 logger.error("Using the present parameters the model does not return any finite value. ") 1738 wx.PostEvent(self.parent, StatusEvent(status = "Computing Error: %s" % 1739 str("Model did not return any finite value."), info="error")) 1740 return 1741 np.nan_to_num(y) 1742 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1743 data_description=model.name, 1744 data_id=str(page_id) + " " + data.name) 1745 if unsmeared_model is not None: 1746 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 1747 data_description=model.name + " unsmeared", 1748 data_id=str(page_id) + " " + data.name + " unsmeared") 1749 1750 if unsmeared_data is not None and unsmeared_error is not None: 1751 self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 1752 data_description="Data unsmeared", 1753 data_id="Data " + data.name + " unsmeared", 1754 dy=unsmeared_error) 1755 # Comment this out until we can get P*S models with correctly populated parameters 1756 #if sq_model is not None and pq_model is not None: 1757 # self.create_theory_1D(x, sq_model, page_id, model, data, state, 1758 # data_description=model.name + " S(q)", 1759 # data_id=str(page_id) + " " + data.name + " S(q)") 1760 # self.create_theory_1D(x, pq_model, page_id, model, data, state, 1761 # data_description=model.name + " P(q)", 1762 # data_id=str(page_id) + " " + data.name + " P(q)") 1763 1764 current_pg = self.fit_panel.get_page_by_id(page_id) 1765 title = new_plot.title 1766 batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 1767 if not batch_on: 1768 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 1769 title=str(title))) 1770 elif plot_result: 1771 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 1772 if data.id == top_data_id: 1773 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 1774 title=str(title))) 1775 caption = current_pg.window_caption 1776 self.page_finder[page_id].set_fit_tab_caption(caption=caption) 1777 1778 self.page_finder[page_id].set_theory_data(data=new_plot, 1736 1737 number_finite = np.count_nonzero(np.isfinite(y)) 1738 np.nan_to_num(y) 1739 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1740 data_description=model.name, 1741 data_id=str(page_id) + " " + data.name) 1742 if unsmeared_model is not None: 1743 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 1744 data_description=model.name + " unsmeared", 1745 data_id=str(page_id) + " " + data.name + " unsmeared") 1746 1747 if unsmeared_data is not None and unsmeared_error is not None: 1748 self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 1749 data_description="Data unsmeared", 1750 data_id="Data " + data.name + " unsmeared", 1751 dy=unsmeared_error) 1752 # Comment this out until we can get P*S models with correctly populated parameters 1753 #if sq_model is not None and pq_model is not None: 1754 # self.create_theory_1D(x, sq_model, page_id, model, data, state, 1755 # data_description=model.name + " S(q)", 1756 # data_id=str(page_id) + " " + data.name + " S(q)") 1757 # self.create_theory_1D(x, pq_model, page_id, model, data, state, 1758 # data_description=model.name + " P(q)", 1759 # data_id=str(page_id) + " " + data.name + " P(q)") 1760 1761 current_pg = self.fit_panel.get_page_by_id(page_id) 1762 title = new_plot.title 1763 batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 1764 if not batch_on: 1765 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 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, 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, 1779 1774 fid=data.id) 1780 1781 1782 1775 if toggle_mode_on: 1776 wx.PostEvent(self.parent, 1777 NewPlotEvent(group_id=str(page_id) + " Model2D", 1783 1778 action="Hide")) 1784 1785 1786 1787 1779 else: 1780 if update_chisqr: 1781 wx.PostEvent(current_pg, 1782 Chi2UpdateEvent(output=self._cal_chisqr( 1788 1783 data=data, 1789 1784 fid=fid, 1790 1785 weight=weight, 1791 page_id=page_id, 1792 index=index))) 1793 else: 1794 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1795 index=index, weight=weight) 1796 1797 msg = "Computation completed!" 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 1792 if not number_finite: 1793 logger.error("Using the present parameters the model does not return any finite value. ") 1794 msg = "Computing Error: Model did not return any finite value." 1795 wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 1796 else: 1797 msg = "Computation completed!" 1798 1798 if number_finite != y.size: 1799 1799 msg += ' PROBLEM: For some Q values the model returns non finite intensities!' 1800 1800 logger.error("For some Q values the model returns non finite intensities.") 1801 1802 1801 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1803 1804 except:1805 raise1806 1802 1807 1803 def _calc_exception(self, etype, value, tb): … … 1828 1824 that can be plot. 1829 1825 """ 1830 number_finite = np.count_nonzero(np.isfinite(image)) 1831 if not number_finite: 1832 logger.error("Using the present parameters the model does not return any finite value. ") 1833 wx.PostEvent(self.parent, StatusEvent(status = "Computing Error: %s" % 1834 str("Model did not return any finite value."), info="error")) 1835 return 1826 number_finite = np.count_nonzero(np.isfinite(image)) 1836 1827 np.nan_to_num(image) 1837 1828 new_plot = Data2D(image=image, err_image=data.err_data) … … 1892 1883 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1893 1884 index=index, weight=weight) 1894 msg = "Computation completed!" 1895 if number_finite != image.size: 1896 msg += ' PROBLEM: For some Qx,Qy values the model returns non finite intensities!' 1897 logger.error("For some Qx,Qy values the model returns non finite intensities.") 1898 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1885 1886 if not number_finite: 1887 logger.error("Using the present parameters the model does not return any finite value. ") 1888 msg = "Computing Error: Model did not return any finite value." 1889 wx.PostEvent(self.parent, StatusEvent(status = msg, info="error")) 1890 else: 1891 msg = "Computation completed!" 1892 if number_finite != image.size: 1893 msg += ' PROBLEM: For some Qx,Qy values the model returns non finite intensities!' 1894 logger.error("For some Qx,Qy values the model returns non finite intensities.") 1895 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1899 1896 1900 1897 def _draw_model2D(self, model, page_id, qmin, … … 2022 2019 chisqr = None 2023 2020 #to compute chisq make sure data has valid data 2024 # return None if data ==None2025 if not check_data_validity(data_copy) or data_copy ==None:2021 # return None if data is None 2022 if not check_data_validity(data_copy) or data_copy is None: 2026 2023 return chisqr 2027 2024 2028 2025 # Get data: data I, theory I, and data dI in order 2029 2026 if data_copy.__class__.__name__ == "Data2D": 2030 if index ==None:2027 if index is None: 2031 2028 index = np.ones(len(data_copy.data), dtype=bool) 2032 if weight !=None:2029 if weight is not None: 2033 2030 data_copy.err_data = weight 2034 2031 # get rid of zero error points … … 2037 2034 fn = data_copy.data[index] 2038 2035 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2039 if theory_data ==None:2036 if theory_data is None: 2040 2037 return chisqr 2041 2038 gn = theory_data.data[index] … … 2043 2040 else: 2044 2041 # 1 d theory from model_thread is only in the range of index 2045 if index ==None:2042 if index is None: 2046 2043 index = np.ones(len(data_copy.y), dtype=bool) 2047 if weight !=None:2044 if weight is not None: 2048 2045 data_copy.dy = weight 2049 if data_copy.dy ==None or data_copy.dy == []:2046 if data_copy.dy is None or data_copy.dy == []: 2050 2047 dy = np.ones(len(data_copy.y)) 2051 2048 else: … … 2057 2054 2058 2055 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2059 if theory_data ==None:2056 if theory_data is None: 2060 2057 return chisqr 2061 2058 gn = theory_data.y … … 2066 2063 res = (fn - gn) / en 2067 2064 except ValueError: 2068 print "Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en))2065 print("Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en))) 2069 2066 return 2070 2067 … … 2100 2097 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2101 2098 gn = theory_data.data 2102 if weight ==None:2099 if weight is None: 2103 2100 en = data_copy.err_data 2104 2101 else: … … 2121 2118 else: 2122 2119 # 1 d theory from model_thread is only in the range of index 2123 if data_copy.dy ==None or data_copy.dy == []:2120 if data_copy.dy is None or data_copy.dy == []: 2124 2121 dy = np.ones(len(data_copy.y)) 2125 2122 else: 2126 if weight ==None:2123 if weight is None: 2127 2124 dy = np.ones(len(data_copy.y)) 2128 2125 ## Set consitently w/AbstractFitengine: … … 2162 2159 ##group_id specify on which panel to plot this data 2163 2160 group_id = self.page_finder[page_id].get_graph_id() 2164 if group_id ==None:2161 if group_id is None: 2165 2162 group_id = data.group_id 2166 2163 new_plot.group_id = "res" + str(group_id)
Note: See TracChangeset
for help on using the changeset viewer.