Changes in src/sas/sasgui/perspectives/fitting/fitting.py [463e7ffc:7432acb] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitting.py
r463e7ffc r7432acb 16 16 import wx 17 17 import logging 18 import numpy 18 import numpy as np 19 19 import time 20 20 from copy import deepcopy … … 302 302 Make new model 303 303 """ 304 if self.new_model_frame !=None:304 if self.new_model_frame is not None: 305 305 self.new_model_frame.Show(False) 306 306 self.new_model_frame.Show(True) … … 386 386 help for setting list of the edit model menu labels 387 387 """ 388 if menu ==None:388 if menu is None: 389 389 menu = self.edit_custom_model 390 390 list_fnames = os.listdir(models.find_plugins_dir()) … … 441 441 wx.PostEvent(self.parent, StatusEvent(status=msg)) 442 442 443 if page !=None:443 if page is not None: 444 444 return set_focus_page(page) 445 445 if caption == "Const & Simul Fit": … … 634 634 state = self.temp_state[self.state_index] 635 635 #panel state should have model selection to set_state 636 if state.formfactorcombobox !=None:636 if state.formfactorcombobox is not None: 637 637 #set state 638 638 data = self.parent.create_gui_data(state.data) … … 877 877 enable1D=enable1D, enable2D=enable2D, 878 878 qmin=qmin, qmax=qmax, weight=weight) 879 880 def _mac_sleep(self, sec=0.2):881 """882 Give sleep to MAC883 """884 if ON_MAC:885 time.sleep(sec)886 879 887 880 def draw_model(self, model, page_id, data=None, smearer=None, … … 1023 1016 return False 1024 1017 ## If a thread is already started, stop it 1025 #if self.calc_fit !=None and self.calc_fit.isrunning():1018 #if self.calc_fitis not None and self.calc_fit.isrunning(): 1026 1019 # self.calc_fit.stop() 1027 1020 msg = "Fitting is in progress..." … … 1032 1025 manager=self, 1033 1026 improvement_delta=0.1) 1034 self._mac_sleep(0.2)1035 1027 1036 1028 # batch fit … … 1114 1106 page = self.fit_panel.add_empty_page() 1115 1107 # add data associated to the page created 1116 if page !=None:1108 if page is not None: 1117 1109 evt = StatusEvent(status="Page Created", info="info") 1118 1110 wx.PostEvent(self.parent, evt) … … 1133 1125 page = self.fit_panel.set_data(data) 1134 1126 # page could be None when loading state files 1135 if page ==None:1127 if page is None: 1136 1128 return page 1137 1129 #append Data1D to the panel containing its theory … … 1201 1193 """ 1202 1194 # case that uid is not specified 1203 if uid ==None:1195 if uid is None: 1204 1196 for page_id in self.page_finder.keys(): 1205 1197 self.page_finder[page_id].schedule_tofit(value) … … 1224 1216 for item in param: 1225 1217 ## check if constraint 1226 if item[0] != None and item[1] !=None:1218 if item[0] is not None and item[1] is not None: 1227 1219 listOfConstraint.append((item[0], item[1])) 1228 1220 new_model = model … … 1239 1231 """ 1240 1232 panel = self.plot_panel 1241 if panel ==None:1233 if panel is None: 1242 1234 raise ValueError, "Fitting:_onSelect: NonType panel" 1243 1235 Plugin.on_perspective(self, event=event) … … 1272 1264 :param elapsed: time spent at the fitting level 1273 1265 """ 1274 self._mac_sleep(0.2)1275 1266 uid = page_id[0] 1276 1267 if uid in self.fit_thread_list.keys(): … … 1334 1325 new_theory = copy_data.data 1335 1326 new_theory[res.index] = res.theory 1336 new_theory[res.index == False] = n umpy.nan1327 new_theory[res.index == False] = np.nan 1337 1328 correct_result = True 1338 1329 #get all fittable parameters of the current model … … 1343 1334 param_list.remove(param) 1344 1335 if not correct_result or res.fitness is None or \ 1345 not n umpy.isfinite(res.fitness) or \1346 numpy.any(res.pvec ==None) or not \1347 numpy.all(numpy.isfinite(res.pvec)):1336 not np.isfinite(res.fitness) or \ 1337 np.any(res.pvec is None) or not \ 1338 np.all(np.isfinite(res.pvec)): 1348 1339 data_name = str(None) 1349 1340 if data is not None: … … 1354 1345 msg += "Data %s and Model %s did not fit.\n" % (data_name, 1355 1346 model_name) 1356 ERROR = n umpy.NAN1347 ERROR = np.NAN 1357 1348 cell = BatchCell() 1358 1349 cell.label = res.fitness … … 1368 1359 batch_inputs["error on %s" % str(param)].append(ERROR) 1369 1360 else: 1370 # TODO: Why sometimes res.pvec comes with n umpy.float64?1361 # TODO: Why sometimes res.pvec comes with np.float64? 1371 1362 # probably from scipy lmfit 1372 if res.pvec.__class__ == n umpy.float64:1363 if res.pvec.__class__ == np.float64: 1373 1364 res.pvec = [res.pvec] 1374 1365 … … 1466 1457 cell.value = index 1467 1458 1468 if theory_data !=None:1459 if theory_data is not None: 1469 1460 #Suucessful fit 1470 1461 theory_data.id = wx.NewId() … … 1522 1513 page_id = [] 1523 1514 ## fit more than 1 model at the same time 1524 self._mac_sleep(0.2)1525 1515 try: 1526 1516 index = 0 … … 1535 1525 fit_msg = res.mesg 1536 1526 if res.fitness is None or \ 1537 not n umpy.isfinite(res.fitness) or \1538 numpy.any(res.pvec ==None) or \1539 not n umpy.all(numpy.isfinite(res.pvec)):1527 not np.isfinite(res.fitness) or \ 1528 np.any(res.pvec is None) or \ 1529 not np.all(np.isfinite(res.pvec)): 1540 1530 fit_msg += "\nFitting did not converge!!!" 1541 1531 wx.CallAfter(self._update_fit_button, page_id) 1542 1532 else: 1543 1533 #set the panel when fit result are float not list 1544 if res.pvec.__class__ == n umpy.float64:1534 if res.pvec.__class__ == np.float64: 1545 1535 pvec = [res.pvec] 1546 1536 else: 1547 1537 pvec = res.pvec 1548 if res.stderr.__class__ == n umpy.float64:1538 if res.stderr.__class__ == np.float64: 1549 1539 stderr = [res.stderr] 1550 1540 else: … … 1554 1544 #(CallAfter is important to MAC) 1555 1545 try: 1556 #if res !=None:1546 #if res is not None: 1557 1547 wx.CallAfter(cpage.onsetValues, res.fitness, 1558 1548 res.param_list, … … 1597 1587 """ 1598 1588 event.Skip() 1599 if self.menu1 ==None:1589 if self.menu1 is None: 1600 1590 return 1601 1591 menu_item = self.menu1.FindItemById(self.id_reset_flag) … … 1656 1646 caption = evt.caption 1657 1647 enable_smearer = evt.enable_smearer 1658 if model ==None:1648 if model is None: 1659 1649 return 1660 1650 if uid not in self.page_finder.keys(): … … 1694 1684 if dy is None: 1695 1685 new_plot.is_data = False 1696 new_plot.dy = n umpy.zeros(len(y))1686 new_plot.dy = np.zeros(len(y)) 1697 1687 # If this is a theory curve, pick the proper symbol to make it a curve 1698 1688 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM … … 1708 1698 new_plot.title = data.name 1709 1699 new_plot.group_id = data.group_id 1710 if new_plot.group_id ==None:1700 if new_plot.group_id is None: 1711 1701 new_plot.group_id = data.group_id 1712 1702 new_plot.id = data_id … … 1743 1733 """ 1744 1734 try: 1745 n umpy.nan_to_num(y)1735 np.nan_to_num(y) 1746 1736 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1747 1737 data_description=model.name, … … 1827 1817 that can be plot. 1828 1818 """ 1829 n umpy.nan_to_num(image)1819 np.nan_to_num(image) 1830 1820 new_plot = Data2D(image=image, err_image=data.err_data) 1831 1821 new_plot.name = model.name + '2d' … … 2012 2002 chisqr = None 2013 2003 #to compute chisq make sure data has valid data 2014 # return None if data ==None2015 if not check_data_validity(data_copy) or data_copy ==None:2004 # return None if data is None 2005 if not check_data_validity(data_copy) or data_copy is None: 2016 2006 return chisqr 2017 2007 2018 2008 # Get data: data I, theory I, and data dI in order 2019 2009 if data_copy.__class__.__name__ == "Data2D": 2020 if index ==None:2021 index = n umpy.ones(len(data_copy.data), dtype=bool)2022 if weight !=None:2010 if index is None: 2011 index = np.ones(len(data_copy.data), dtype=bool) 2012 if weight is not None: 2023 2013 data_copy.err_data = weight 2024 2014 # get rid of zero error points 2025 2015 index = index & (data_copy.err_data != 0) 2026 index = index & (n umpy.isfinite(data_copy.data))2016 index = index & (np.isfinite(data_copy.data)) 2027 2017 fn = data_copy.data[index] 2028 2018 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2029 if theory_data ==None:2019 if theory_data is None: 2030 2020 return chisqr 2031 2021 gn = theory_data.data[index] … … 2033 2023 else: 2034 2024 # 1 d theory from model_thread is only in the range of index 2035 if index ==None:2036 index = n umpy.ones(len(data_copy.y), dtype=bool)2037 if weight !=None:2025 if index is None: 2026 index = np.ones(len(data_copy.y), dtype=bool) 2027 if weight is not None: 2038 2028 data_copy.dy = weight 2039 if data_copy.dy ==None or data_copy.dy == []:2040 dy = n umpy.ones(len(data_copy.y))2029 if data_copy.dy is None or data_copy.dy == []: 2030 dy = np.ones(len(data_copy.y)) 2041 2031 else: 2042 2032 ## Set consistently w/AbstractFitengine: … … 2047 2037 2048 2038 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2049 if theory_data ==None:2039 if theory_data is None: 2050 2040 return chisqr 2051 2041 gn = theory_data.y … … 2059 2049 return 2060 2050 2061 residuals = res[n umpy.isfinite(res)]2051 residuals = res[np.isfinite(res)] 2062 2052 # get chisqr only w/finite 2063 chisqr = n umpy.average(residuals * residuals)2053 chisqr = np.average(residuals * residuals) 2064 2054 2065 2055 self._plot_residuals(page_id=page_id, data=data_copy, … … 2090 2080 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2091 2081 gn = theory_data.data 2092 if weight ==None:2082 if weight is None: 2093 2083 en = data_copy.err_data 2094 2084 else: … … 2098 2088 residuals.qy_data = data_copy.qy_data 2099 2089 residuals.q_data = data_copy.q_data 2100 residuals.err_data = n umpy.ones(len(residuals.data))2090 residuals.err_data = np.ones(len(residuals.data)) 2101 2091 residuals.xmin = min(residuals.qx_data) 2102 2092 residuals.xmax = max(residuals.qx_data) … … 2111 2101 else: 2112 2102 # 1 d theory from model_thread is only in the range of index 2113 if data_copy.dy ==None or data_copy.dy == []:2114 dy = n umpy.ones(len(data_copy.y))2103 if data_copy.dy is None or data_copy.dy == []: 2104 dy = np.ones(len(data_copy.y)) 2115 2105 else: 2116 if weight ==None:2117 dy = n umpy.ones(len(data_copy.y))2106 if weight is None: 2107 dy = np.ones(len(data_copy.y)) 2118 2108 ## Set consitently w/AbstractFitengine: 2119 2109 ## But this should be corrected later. … … 2134 2124 residuals.y = (fn - gn[index]) / en 2135 2125 residuals.x = data_copy.x[index] 2136 residuals.dy = n umpy.ones(len(residuals.y))2126 residuals.dy = np.ones(len(residuals.y)) 2137 2127 residuals.dx = None 2138 2128 residuals.dxl = None … … 2152 2142 ##group_id specify on which panel to plot this data 2153 2143 group_id = self.page_finder[page_id].get_graph_id() 2154 if group_id ==None:2144 if group_id is None: 2155 2145 group_id = data.group_id 2156 2146 new_plot.group_id = "res" + str(group_id)
Note: See TracChangeset
for help on using the changeset viewer.