Changeset 6a455cd3 in sasview for src/sas/sasgui/perspectives/fitting
- Timestamp:
- Jul 24, 2017 10:27: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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 146c669
- Parents:
- b61bd57 (diff), bc04647 (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:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
rb301db9 r914c49d5 2 2 Base Page for fitting 3 3 """ 4 from __future__ import print_function 5 4 6 import sys 5 7 import os 6 8 import wx 7 import numpy 9 import numpy as np 8 10 import time 9 11 import copy … … 34 36 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 35 37 38 logger = logging.getLogger(__name__) 36 39 37 40 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() … … 100 103 self.graph_id = None 101 104 # Q range for data set 102 self.qmin_data_set = n umpy.inf105 self.qmin_data_set = np.inf 103 106 self.qmax_data_set = None 104 107 self.npts_data_set = 0 … … 251 254 if not hasattr(self, "model_view"): 252 255 return 253 toggle_mode_on = self.model_view.IsEnabled() 256 toggle_mode_on = self.model_view.IsEnabled() or self.data is None 254 257 if toggle_mode_on: 255 258 if self.enable2D and not check_data_validity(self.data): … … 278 281 279 282 """ 280 x = n umpy.linspace(start=self.qmin_x, stop=self.qmax_x,283 x = np.linspace(start=self.qmin_x, stop=self.qmax_x, 281 284 num=self.npts_x, endpoint=True) 282 285 self.data = Data1D(x=x) … … 295 298 """ 296 299 if self.qmin_x >= 1.e-10: 297 qmin = n umpy.log10(self.qmin_x)300 qmin = np.log10(self.qmin_x) 298 301 else: 299 302 qmin = -10. 300 303 301 304 if self.qmax_x <= 1.e10: 302 qmax = n umpy.log10(self.qmax_x)305 qmax = np.log10(self.qmax_x) 303 306 else: 304 307 qmax = 10. 305 308 306 x = n umpy.logspace(start=qmin, stop=qmax,309 x = np.logspace(start=qmin, stop=qmax, 307 310 num=self.npts_x, endpoint=True, base=10.0) 308 311 self.data = Data1D(x=x) … … 341 344 qstep = self.npts_x 342 345 343 x = n umpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True)344 y = n umpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True)346 x = np.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) 347 y = np.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) 345 348 # use data info instead 346 new_x = n umpy.tile(x, (len(y), 1))347 new_y = n umpy.tile(y, (len(x), 1))349 new_x = np.tile(x, (len(y), 1)) 350 new_y = np.tile(y, (len(x), 1)) 348 351 new_y = new_y.swapaxes(0, 1) 349 352 # all data reuire now in 1d array 350 353 qx_data = new_x.flatten() 351 354 qy_data = new_y.flatten() 352 q_data = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)355 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 353 356 # set all True (standing for unmasked) as default 354 mask = n umpy.ones(len(qx_data), dtype=bool)357 mask = np.ones(len(qx_data), dtype=bool) 355 358 # store x and y bin centers in q space 356 359 x_bins = x … … 358 361 359 362 self.data.source = Source() 360 self.data.data = n umpy.ones(len(mask))361 self.data.err_data = n umpy.ones(len(mask))363 self.data.data = np.ones(len(mask)) 364 self.data.err_data = np.ones(len(mask)) 362 365 self.data.qx_data = qx_data 363 366 self.data.qy_data = qy_data … … 656 659 # It seems MAC needs wxCallAfter 657 660 if event.GetId() == GUIFRAME_ID.COPYEX_ID: 658 print "copy excel"661 print("copy excel") 659 662 wx.CallAfter(self.get_copy_excel) 660 663 elif event.GetId() == GUIFRAME_ID.COPYLAT_ID: 661 print "copy latex"664 print("copy latex") 662 665 wx.CallAfter(self.get_copy_latex) 663 666 else: … … 782 785 except Exception: 783 786 # Skip non-data lines 784 logg ing.error(traceback.format_exc())785 return n umpy.array(angles), numpy.array(weights)787 logger.error(traceback.format_exc()) 788 return np.array(angles), np.array(weights) 786 789 except: 787 790 raise … … 1304 1307 [state.values, state.weights] 1305 1308 except Exception: 1306 logg ing.error(traceback.format_exc())1309 logger.error(traceback.format_exc()) 1307 1310 selection = self._find_polyfunc_selection(disp_model) 1308 1311 for list in self.fittable_param: … … 1321 1324 list[6].Disable() 1322 1325 except Exception: 1323 logg ing.error(traceback.format_exc())1326 logger.error(traceback.format_exc()) 1324 1327 # For array, disable all fixed params 1325 1328 if selection == 1: … … 1330 1333 item[2].Disable() 1331 1334 except Exception: 1332 logg ing.error(traceback.format_exc())1335 logger.error(traceback.format_exc()) 1333 1336 1334 1337 def _selectDlg(self): … … 1449 1452 self.state_change = True 1450 1453 self._draw_model() 1451 # Time delay has been introduced to prevent _handle error1452 # on Windows1453 # This part of code is executed when model is selected and1454 # it's parameters are changed (with respect to previously1455 # selected model). There are two Iq evaluations occuring one1456 # after another and therefore there may be compilation error1457 # if model is calculated for the first time.1458 # This seems to be Windows only issue - haven't tested on Linux1459 # though.The proper solution (other than time delay) requires1460 # more fundemental code refatoring1461 # Wojtek P. Nov 7, 20161462 if not ON_MAC:1463 time.sleep(0.1)1464 1454 self.Refresh() 1465 1455 1466 # logg ing.info("is_modified flag set to %g",is_modified)1456 # logger.info("is_modified flag set to %g",is_modified) 1467 1457 return is_modified 1468 1458 … … 1569 1559 self.save_current_state() 1570 1560 except Exception: 1571 logg ing.error(traceback.format_exc())1561 logger.error(traceback.format_exc()) 1572 1562 1573 1563 return flag, is_modified … … 2120 2110 for data in self.data_list: 2121 2111 # q value from qx and qy 2122 radius = n umpy.sqrt(data.qx_data * data.qx_data +2112 radius = np.sqrt(data.qx_data * data.qx_data + 2123 2113 data.qy_data * data.qy_data) 2124 2114 # get unmasked index … … 2126 2116 (radius <= float(self.qmax.GetValue())) 2127 2117 index_data = (index_data) & (data.mask) 2128 index_data = (index_data) & (n umpy.isfinite(data.data))2118 index_data = (index_data) & (np.isfinite(data.data)) 2129 2119 2130 2120 if len(index_data[index_data]) < 10: … … 2161 2151 index_data = (float(self.qmin.GetValue()) <= radius) & \ 2162 2152 (radius <= float(self.qmax.GetValue())) 2163 index_data = (index_data) & (n umpy.isfinite(data.y))2153 index_data = (index_data) & (np.isfinite(data.y)) 2164 2154 2165 2155 if len(index_data[index_data]) < 5: … … 2233 2223 2234 2224 # Check that min is less than max 2235 low = -n umpy.inf if min_str == "" else float(min_str)2236 high = n umpy.inf if max_str == "" else float(max_str)2225 low = -np.inf if min_str == "" else float(min_str) 2226 high = np.inf if max_str == "" else float(max_str) 2237 2227 if high < low: 2238 2228 min_ctrl.SetBackgroundColour("pink") … … 2384 2374 self.model.set_dispersion(p, disp_model) 2385 2375 except Exception: 2386 logg ing.error(traceback.format_exc())2376 logger.error(traceback.format_exc()) 2387 2377 2388 2378 # save state into … … 2499 2489 self.Refresh() 2500 2490 except Exception: 2501 logg ing.error(traceback.format_exc())2491 logger.error(traceback.format_exc()) 2502 2492 # Error msg 2503 2493 msg = "Error occurred:" … … 2600 2590 del self.state.model._persistency_dict[name.split('.')[0]] 2601 2591 except Exception: 2602 logg ing.error(traceback.format_exc())2592 logger.error(traceback.format_exc()) 2603 2593 2604 2594 def _lay_out(self): … … 2609 2599 Layout is called after fitting. 2610 2600 """ 2611 self._sleep4sec()2612 2601 self.Layout() 2613 2602 return 2614 2615 def _sleep4sec(self):2616 """2617 sleep for 1 sec only applied on Mac2618 Note: This 1sec helps for Mac not to crash on self.2619 Layout after self._draw_model2620 """2621 if ON_MAC:2622 time.sleep(1)2623 2603 2624 2604 def _find_polyfunc_selection(self, disp_func=None): … … 2654 2634 self.qmin_x = data_min 2655 2635 self.qmax_x = math.sqrt(x * x + y * y) 2656 # self.data.mask = n umpy.ones(len(self.data.data),dtype=bool)2636 # self.data.mask = np.ones(len(self.data.data),dtype=bool) 2657 2637 # check smearing 2658 2638 if not self.disable_smearer.GetValue(): … … 2742 2722 except Exception: 2743 2723 # Not for control panels 2744 logg ing.error(traceback.format_exc())2724 logger.error(traceback.format_exc()) 2745 2725 # Make sure the resduals plot goes to the last 2746 2726 if res_item is not None: … … 3075 3055 disfunc = str(item[7].GetValue()) 3076 3056 except Exception: 3077 logg ing.error(traceback.format_exc())3057 logger.error(traceback.format_exc()) 3078 3058 3079 3059 # 2D … … 3118 3098 disfunc += ' ' + str(weight) 3119 3099 except Exception: 3120 logg ing.error(traceback.format_exc())3100 logger.error(traceback.format_exc()) 3121 3101 content += name + ',' + str(check) + ',' + value + disfunc + ',' + \ 3122 3102 bound_lo + ',' + bound_hi + ':' … … 3366 3346 3367 3347 if value[1] == 'array': 3368 pd_vals = n umpy.array(value[2])3369 pd_weights = n umpy.array(value[3])3348 pd_vals = np.array(value[2]) 3349 pd_weights = np.array(value[3]) 3370 3350 if len(pd_vals) == 0 or len(pd_vals) != len(pd_weights): 3371 3351 msg = ("bad array distribution parameters for %s" … … 3389 3369 3390 3370 except Exception: 3391 logg ing.error(traceback.format_exc())3392 print 3393 sys.exc_info()[1] 3371 logger.error(traceback.format_exc()) 3372 print("Error in BasePage._paste_poly_help: %s" % \ 3373 sys.exc_info()[1]) 3394 3374 3395 3375 def _set_disp_cb(self, isarray, item): … … 3420 3400 Moveit; This method doesn't belong here 3421 3401 """ 3422 print "BasicPage.update_pinhole_smear was called: skipping"3402 print("BasicPage.update_pinhole_smear was called: skipping") 3423 3403 return 3424 3404 … … 3596 3576 # check model type to show sizer 3597 3577 if self.model is not None: 3598 print "_set_model_sizer_selection: disabled."3578 print("_set_model_sizer_selection: disabled.") 3599 3579 # self._set_model_sizer_selection(self.model) 3600 3580 -
src/sas/sasgui/perspectives/fitting/batchfitpage.py
ree4b3cb r7432acb 200 200 # self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() 201 201 # 202 # if self.model !=None:202 # if self.model is not None: 203 203 # self._set_copy_flag(True) 204 204 # self._set_paste_flag(True) 205 # if self.data !=None:205 # if self.data is not None: 206 206 # self._set_bookmark_flag(False) 207 207 # self._keep.Enable(False) … … 225 225 # 226 226 # 227 # if event !=None:227 # if event is not None: 228 228 # ## post state to fit panel 229 229 # new_event = PageInfoEvent(page = self) … … 254 254 # is_modified = False 255 255 # 256 # if self.model != None:256 # if self.model is not None: 257 257 # ##Check the values 258 258 # self._check_value_enter( self.fittable_param) … … 291 291 # else: 292 292 # #self.btFit.Enable(True) 293 # if self._is_2D() and self.data !=None:293 # if self._is_2D() and self.data is not None: 294 294 # self.btEditMask.Enable(True) 295 295 # … … 335 335 # self._set_save_flag(False) 336 336 # else: 337 # if self.model !=None:337 # if self.model is not None: 338 338 # self._set_bookmark_flag(False) 339 339 # self._keep.Enable(False) -
src/sas/sasgui/perspectives/fitting/fitpage.py
r7143065 r6a455cd3 6 6 import wx 7 7 import wx.lib.newevent 8 import numpy 8 import numpy as np 9 9 import copy 10 10 import math … … 1115 1115 if item.GetValue(): 1116 1116 if button_list.index(item) == 0: 1117 flag = 0 # dy = n umpy.ones_like(dy_data)1117 flag = 0 # dy = np.ones_like(dy_data) 1118 1118 elif button_list.index(item) == 1: 1119 1119 flag = 1 # dy = dy_data 1120 1120 elif button_list.index(item) == 2: 1121 flag = 2 # dy = n umpy.sqrt(numpy.abs(data))1121 flag = 2 # dy = np.sqrt(np.abs(data)) 1122 1122 elif button_list.index(item) == 3: 1123 flag = 3 # dy = n umpy.abs(data)1123 flag = 3 # dy = np.abs(data) 1124 1124 break 1125 1125 return flag … … 1426 1426 key = event.GetKeyCode() 1427 1427 length = len(self.data.x) 1428 indx = (n umpy.abs(self.data.x - x_data)).argmin()1428 indx = (np.abs(self.data.x - x_data)).argmin() 1429 1429 # return array.flat[idx] 1430 1430 if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: … … 1481 1481 self.enable2D: 1482 1482 # set mask 1483 radius = n umpy.sqrt(self.data.qx_data * self.data.qx_data +1483 radius = np.sqrt(self.data.qx_data * self.data.qx_data + 1484 1484 self.data.qy_data * self.data.qy_data) 1485 1485 index_data = ((self.qmin_x <= radius) & (radius <= self.qmax_x)) 1486 1486 index_data = (index_data) & (self.data.mask) 1487 index_data = (index_data) & (n umpy.isfinite(self.data.data))1487 index_data = (index_data) & (np.isfinite(self.data.data)) 1488 1488 if len(index_data[index_data]) < 10: 1489 1489 msg = "Cannot Plot :No or too little npts in" … … 1602 1602 and data.dqx_data.any() != 0: 1603 1603 self.smear_type = "Pinhole2d" 1604 self.dq_l = format_number(n umpy.average(data.dqx_data))1605 self.dq_r = format_number(n umpy.average(data.dqy_data))1604 self.dq_l = format_number(np.average(data.dqx_data)) 1605 self.dq_r = format_number(np.average(data.dqy_data)) 1606 1606 return 1607 1607 else: 1608 1608 return 1609 1609 # check if it is pinhole smear and get min max if it is. 1610 if data.dx is not None and n umpy.any(data.dx):1610 if data.dx is not None and np.any(data.dx): 1611 1611 self.smear_type = "Pinhole" 1612 1612 self.dq_l = data.dx[0] … … 1616 1616 elif data.dxl is not None or data.dxw is not None: 1617 1617 self.smear_type = "Slit" 1618 if data.dxl is not None and n umpy.all(data.dxl, 0):1618 if data.dxl is not None and np.all(data.dxl, 0): 1619 1619 self.dq_l = data.dxl[0] 1620 if data.dxw is not None and n umpy.all(data.dxw, 0):1620 if data.dxw is not None and np.all(data.dxw, 0): 1621 1621 self.dq_r = data.dxw[0] 1622 1622 # return self.smear_type,self.dq_l,self.dq_r … … 1812 1812 if not flag: 1813 1813 self.onSmear(None) 1814 1815 def _mac_sleep(self, sec=0.2):1816 """1817 Give sleep to MAC1818 """1819 if self.is_mac:1820 time.sleep(sec)1821 1814 1822 1815 def get_view_mode(self): … … 1925 1918 self.default_mask = copy.deepcopy(self.data.mask) 1926 1919 if self.data.err_data is not None \ 1927 and n umpy.any(self.data.err_data):1920 and np.any(self.data.err_data): 1928 1921 di_flag = True 1929 1922 if self.data.dqx_data is not None \ 1930 and n umpy.any(self.data.dqx_data):1923 and np.any(self.data.dqx_data): 1931 1924 dq_flag = True 1932 1925 else: 1933 1926 self.slit_smearer.Enable(True) 1934 1927 self.pinhole_smearer.Enable(True) 1935 if self.data.dy is not None and n umpy.any(self.data.dy):1928 if self.data.dy is not None and np.any(self.data.dy): 1936 1929 di_flag = True 1937 if self.data.dx is not None and n umpy.any(self.data.dx):1930 if self.data.dx is not None and np.any(self.data.dx): 1938 1931 dq_flag = True 1939 elif self.data.dxl is not None and n umpy.any(self.data.dxl):1932 elif self.data.dxl is not None and np.any(self.data.dxl): 1940 1933 dq_flag = True 1941 1934 … … 2071 2064 if self.data.__class__.__name__ == "Data2D" or \ 2072 2065 self.enable2D: 2073 radius = n umpy.sqrt(self.data.qx_data * self.data.qx_data +2066 radius = np.sqrt(self.data.qx_data * self.data.qx_data + 2074 2067 self.data.qy_data * self.data.qy_data) 2075 2068 index_data = (self.qmin_x <= radius) & (radius <= self.qmax_x) 2076 2069 index_data = (index_data) & (self.data.mask) 2077 index_data = (index_data) & (n umpy.isfinite(self.data.data))2070 index_data = (index_data) & (np.isfinite(self.data.data)) 2078 2071 npts2fit = len(self.data.data[index_data]) 2079 2072 else: … … 2108 2101 # make sure stop button to fit button all the time 2109 2102 self._on_fit_complete() 2110 if out is None or not n umpy.isfinite(chisqr):2103 if out is None or not np.isfinite(chisqr): 2111 2104 raise ValueError, "Fit error occured..." 2112 2105 … … 2119 2112 2120 2113 # Check if chi2 is finite 2121 if chisqr is not None and n umpy.isfinite(chisqr):2114 if chisqr is not None and np.isfinite(chisqr): 2122 2115 # format chi2 2123 2116 chi2 = format_number(chisqr, True) … … 2171 2164 2172 2165 if cov[ind] is not None: 2173 if n umpy.isfinite(float(cov[ind])):2166 if np.isfinite(float(cov[ind])): 2174 2167 val_err = format_number(cov[ind], True) 2175 2168 item[4].SetForegroundColour(wx.BLACK) … … 2192 2185 self.save_current_state() 2193 2186 2194 if not self.is_mac:2195 self.Layout()2196 self.Refresh()2197 self._mac_sleep(0.1)2198 2187 # plot model ( when drawing, do not update chisqr value again) 2199 2188 self._draw_model(update_chisqr=False, source='fit') … … 2295 2284 self.smear_type = 'Pinhole2d' 2296 2285 len_data = len(data.data) 2297 data.dqx_data = n umpy.zeros(len_data)2298 data.dqy_data = n umpy.zeros(len_data)2286 data.dqx_data = np.zeros(len_data) 2287 data.dqy_data = np.zeros(len_data) 2299 2288 else: 2300 2289 self.smear_type = 'Pinhole' 2301 2290 len_data = len(data.x) 2302 data.dx = n umpy.zeros(len_data)2291 data.dx = np.zeros(len_data) 2303 2292 data.dxl = None 2304 2293 data.dxw = None … … 2473 2462 try: 2474 2463 self.dxl = float(self.smear_slit_height.GetValue()) 2475 data.dxl = self.dxl * n umpy.ones(data_len)2464 data.dxl = self.dxl * np.ones(data_len) 2476 2465 self.smear_slit_height.SetBackgroundColour(wx.WHITE) 2477 2466 except: 2478 2467 self.dxl = None 2479 data.dxl = n umpy.zeros(data_len)2468 data.dxl = np.zeros(data_len) 2480 2469 if self.smear_slit_height.GetValue().lstrip().rstrip() != "": 2481 2470 self.smear_slit_height.SetBackgroundColour("pink") … … 2486 2475 self.dxw = float(self.smear_slit_width.GetValue()) 2487 2476 self.smear_slit_width.SetBackgroundColour(wx.WHITE) 2488 data.dxw = self.dxw * n umpy.ones(data_len)2477 data.dxw = self.dxw * np.ones(data_len) 2489 2478 except: 2490 2479 self.dxw = None 2491 data.dxw = n umpy.zeros(data_len)2480 data.dxw = np.zeros(data_len) 2492 2481 if self.smear_slit_width.GetValue().lstrip().rstrip() != "": 2493 2482 self.smear_slit_width.SetBackgroundColour("pink") … … 2616 2605 if event is None: 2617 2606 output = "-" 2618 elif not n umpy.isfinite(event.output):2607 elif not np.isfinite(event.output): 2619 2608 output = "-" 2620 2609 else: -
src/sas/sasgui/perspectives/fitting/fitting.py
r4c5098c 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 … … 16 18 import wx 17 19 import logging 18 import numpy 20 import numpy as np 19 21 import time 20 22 from copy import deepcopy … … 48 50 49 51 from . import models 52 53 logger = logging.getLogger(__name__) 50 54 51 55 MAX_NBR_DATA = 4 … … 119 123 self.page_finder = {} 120 124 # Log startup 121 logg ing.info("Fitting plug-in started")125 logger.info("Fitting plug-in started") 122 126 self.batch_capable = self.get_batch_capable() 123 127 … … 300 304 Make new model 301 305 """ 302 if self.new_model_frame !=None:306 if self.new_model_frame is not None: 303 307 self.new_model_frame.Show(False) 304 308 self.new_model_frame.Show(True) … … 346 350 page.formfactorbox.SetLabel(current_val) 347 351 except: 348 logg ing.error("update_custom_combo: %s", sys.exc_value)352 logger.error("update_custom_combo: %s", sys.exc_value) 349 353 350 354 def set_edit_menu(self, owner): … … 384 388 help for setting list of the edit model menu labels 385 389 """ 386 if menu ==None:390 if menu is None: 387 391 menu = self.edit_custom_model 388 392 list_fnames = os.listdir(models.find_plugins_dir()) … … 439 443 wx.PostEvent(self.parent, StatusEvent(status=msg)) 440 444 441 if page !=None:445 if page is not None: 442 446 return set_focus_page(page) 443 447 if caption == "Const & Simul Fit": … … 586 590 msg = "Fitting: cannot deal with the theory received" 587 591 evt = StatusEvent(status=msg, info="error") 588 logg ing.error("set_theory " + msg + "\n" + str(sys.exc_value))592 logger.error("set_theory " + msg + "\n" + str(sys.exc_value)) 589 593 wx.PostEvent(self.parent, evt) 590 594 … … 632 636 state = self.temp_state[self.state_index] 633 637 #panel state should have model selection to set_state 634 if state.formfactorcombobox !=None:638 if state.formfactorcombobox is not None: 635 639 #set state 636 640 data = self.parent.create_gui_data(state.data) … … 875 879 enable1D=enable1D, enable2D=enable2D, 876 880 qmin=qmin, qmax=qmax, weight=weight) 877 878 def _mac_sleep(self, sec=0.2):879 """880 Give sleep to MAC881 """882 if ON_MAC:883 time.sleep(sec)884 881 885 882 def draw_model(self, model, page_id, data=None, smearer=None, … … 1021 1018 return False 1022 1019 ## If a thread is already started, stop it 1023 #if self.calc_fit !=None and self.calc_fit.isrunning():1020 #if self.calc_fitis not None and self.calc_fit.isrunning(): 1024 1021 # self.calc_fit.stop() 1025 1022 msg = "Fitting is in progress..." … … 1030 1027 manager=self, 1031 1028 improvement_delta=0.1) 1032 self._mac_sleep(0.2)1033 1029 1034 1030 # batch fit … … 1112 1108 page = self.fit_panel.add_empty_page() 1113 1109 # add data associated to the page created 1114 if page !=None:1110 if page is not None: 1115 1111 evt = StatusEvent(status="Page Created", info="info") 1116 1112 wx.PostEvent(self.parent, evt) … … 1131 1127 page = self.fit_panel.set_data(data) 1132 1128 # page could be None when loading state files 1133 if page ==None:1129 if page is None: 1134 1130 return page 1135 1131 #append Data1D to the panel containing its theory … … 1199 1195 """ 1200 1196 # case that uid is not specified 1201 if uid ==None:1197 if uid is None: 1202 1198 for page_id in self.page_finder.keys(): 1203 1199 self.page_finder[page_id].schedule_tofit(value) … … 1222 1218 for item in param: 1223 1219 ## check if constraint 1224 if item[0] != None and item[1] !=None:1220 if item[0] is not None and item[1] is not None: 1225 1221 listOfConstraint.append((item[0], item[1])) 1226 1222 new_model = model … … 1237 1233 """ 1238 1234 panel = self.plot_panel 1239 if panel ==None:1235 if panel is None: 1240 1236 raise ValueError, "Fitting:_onSelect: NonType panel" 1241 1237 Plugin.on_perspective(self, event=event) … … 1259 1255 """ 1260 1256 """ 1261 print "update_fit result", result1257 print("update_fit result", result) 1262 1258 1263 1259 def _batch_fit_complete(self, result, pars, page_id, … … 1270 1266 :param elapsed: time spent at the fitting level 1271 1267 """ 1272 self._mac_sleep(0.2)1273 1268 uid = page_id[0] 1274 1269 if uid in self.fit_thread_list.keys(): … … 1332 1327 new_theory = copy_data.data 1333 1328 new_theory[res.index] = res.theory 1334 new_theory[res.index == False] = n umpy.nan1329 new_theory[res.index == False] = np.nan 1335 1330 correct_result = True 1336 1331 #get all fittable parameters of the current model … … 1341 1336 param_list.remove(param) 1342 1337 if not correct_result or res.fitness is None or \ 1343 not n umpy.isfinite(res.fitness) or \1344 numpy.any(res.pvec ==None) or not \1345 numpy.all(numpy.isfinite(res.pvec)):1338 not np.isfinite(res.fitness) or \ 1339 np.any(res.pvec is None) or not \ 1340 np.all(np.isfinite(res.pvec)): 1346 1341 data_name = str(None) 1347 1342 if data is not None: … … 1352 1347 msg += "Data %s and Model %s did not fit.\n" % (data_name, 1353 1348 model_name) 1354 ERROR = n umpy.NAN1349 ERROR = np.NAN 1355 1350 cell = BatchCell() 1356 1351 cell.label = res.fitness … … 1366 1361 batch_inputs["error on %s" % str(param)].append(ERROR) 1367 1362 else: 1368 # TODO: Why sometimes res.pvec comes with n umpy.float64?1363 # TODO: Why sometimes res.pvec comes with np.float64? 1369 1364 # probably from scipy lmfit 1370 if res.pvec.__class__ == n umpy.float64:1365 if res.pvec.__class__ == np.float64: 1371 1366 res.pvec = [res.pvec] 1372 1367 … … 1464 1459 cell.value = index 1465 1460 1466 if theory_data !=None:1461 if theory_data is not None: 1467 1462 #Suucessful fit 1468 1463 theory_data.id = wx.NewId() … … 1520 1515 page_id = [] 1521 1516 ## fit more than 1 model at the same time 1522 self._mac_sleep(0.2)1523 1517 try: 1524 1518 index = 0 … … 1533 1527 fit_msg = res.mesg 1534 1528 if res.fitness is None or \ 1535 not n umpy.isfinite(res.fitness) or \1536 numpy.any(res.pvec ==None) or \1537 not n umpy.all(numpy.isfinite(res.pvec)):1529 not np.isfinite(res.fitness) or \ 1530 np.any(res.pvec is None) or \ 1531 not np.all(np.isfinite(res.pvec)): 1538 1532 fit_msg += "\nFitting did not converge!!!" 1539 1533 wx.CallAfter(self._update_fit_button, page_id) 1540 1534 else: 1541 1535 #set the panel when fit result are float not list 1542 if res.pvec.__class__ == n umpy.float64:1536 if res.pvec.__class__ == np.float64: 1543 1537 pvec = [res.pvec] 1544 1538 else: 1545 1539 pvec = res.pvec 1546 if res.stderr.__class__ == n umpy.float64:1540 if res.stderr.__class__ == np.float64: 1547 1541 stderr = [res.stderr] 1548 1542 else: … … 1552 1546 #(CallAfter is important to MAC) 1553 1547 try: 1554 #if res !=None:1548 #if res is not None: 1555 1549 wx.CallAfter(cpage.onsetValues, res.fitness, 1556 1550 res.param_list, … … 1595 1589 """ 1596 1590 event.Skip() 1597 if self.menu1 ==None:1591 if self.menu1 is None: 1598 1592 return 1599 1593 menu_item = self.menu1.FindItemById(self.id_reset_flag) … … 1654 1648 caption = evt.caption 1655 1649 enable_smearer = evt.enable_smearer 1656 if model ==None:1650 if model is None: 1657 1651 return 1658 1652 if uid not in self.page_finder.keys(): … … 1692 1686 if dy is None: 1693 1687 new_plot.is_data = False 1694 new_plot.dy = n umpy.zeros(len(y))1688 new_plot.dy = np.zeros(len(y)) 1695 1689 # If this is a theory curve, pick the proper symbol to make it a curve 1696 1690 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM … … 1706 1700 new_plot.title = data.name 1707 1701 new_plot.group_id = data.group_id 1708 if new_plot.group_id ==None:1702 if new_plot.group_id is None: 1709 1703 new_plot.group_id = data.group_id 1710 1704 new_plot.id = data_id … … 1740 1734 @param unsmeared_error: data error, rescaled to unsmeared model 1741 1735 """ 1742 try: 1743 numpy.nan_to_num(y) 1744 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1745 data_description=model.name, 1746 data_id=str(page_id) + " " + data.name) 1747 if unsmeared_model is not None: 1748 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 1749 data_description=model.name + " unsmeared", 1750 data_id=str(page_id) + " " + data.name + " unsmeared") 1751 1752 if unsmeared_data is not None and unsmeared_error is not None: 1753 self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 1754 data_description="Data unsmeared", 1755 data_id="Data " + data.name + " unsmeared", 1756 dy=unsmeared_error) 1757 # Comment this out until we can get P*S models with correctly populated parameters 1758 #if sq_model is not None and pq_model is not None: 1759 # self.create_theory_1D(x, sq_model, page_id, model, data, state, 1760 # data_description=model.name + " S(q)", 1761 # data_id=str(page_id) + " " + data.name + " S(q)") 1762 # self.create_theory_1D(x, pq_model, page_id, model, data, state, 1763 # data_description=model.name + " P(q)", 1764 # data_id=str(page_id) + " " + data.name + " P(q)") 1765 1766 current_pg = self.fit_panel.get_page_by_id(page_id) 1767 title = new_plot.title 1768 batch_on = self.fit_panel.get_page_by_id(page_id).batch_on 1769 if not batch_on: 1770 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 1771 title=str(title))) 1772 elif plot_result: 1773 top_data_id = self.fit_panel.get_page_by_id(page_id).data.id 1774 if data.id == top_data_id: 1775 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, 1776 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, 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, 1781 1774 fid=data.id) 1782 1783 1784 1775 if toggle_mode_on: 1776 wx.PostEvent(self.parent, 1777 NewPlotEvent(group_id=str(page_id) + " Model2D", 1785 1778 action="Hide")) 1786 1787 1788 1789 1779 else: 1780 if update_chisqr: 1781 wx.PostEvent(current_pg, 1782 Chi2UpdateEvent(output=self._cal_chisqr( 1790 1783 data=data, 1791 1784 fid=fid, 1792 1785 weight=weight, 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 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: 1799 1797 msg = "Computation completed!" 1798 if number_finite != y.size: 1799 msg += ' PROBLEM: For some Q values the model returns non finite intensities!' 1800 logger.error("For some Q values the model returns non finite intensities.") 1800 1801 wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 1801 except:1802 raise1803 1802 1804 1803 def _calc_exception(self, etype, value, tb): … … 1806 1805 Handle exception from calculator by posting it as an error. 1807 1806 """ 1808 logg ing.error("".join(traceback.format_exception(etype, value, tb)))1807 logger.error("".join(traceback.format_exception(etype, value, tb))) 1809 1808 msg = traceback.format_exception(etype, value, tb, limit=1) 1810 1809 evt = StatusEvent(status="".join(msg), type="stop", info="error") … … 1825 1824 that can be plot. 1826 1825 """ 1827 numpy.nan_to_num(image) 1826 number_finite = np.count_nonzero(np.isfinite(image)) 1827 np.nan_to_num(image) 1828 1828 new_plot = Data2D(image=image, err_image=data.err_data) 1829 1829 new_plot.name = model.name + '2d' … … 1883 1883 self._plot_residuals(page_id=page_id, data=data, fid=fid, 1884 1884 index=index, weight=weight) 1885 msg = "Computation completed!" 1886 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")) 1887 1896 1888 1897 def _draw_model2D(self, model, page_id, qmin, … … 2010 2019 chisqr = None 2011 2020 #to compute chisq make sure data has valid data 2012 # return None if data ==None2013 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: 2014 2023 return chisqr 2015 2024 2016 2025 # Get data: data I, theory I, and data dI in order 2017 2026 if data_copy.__class__.__name__ == "Data2D": 2018 if index ==None:2019 index = n umpy.ones(len(data_copy.data), dtype=bool)2020 if weight !=None:2027 if index is None: 2028 index = np.ones(len(data_copy.data), dtype=bool) 2029 if weight is not None: 2021 2030 data_copy.err_data = weight 2022 2031 # get rid of zero error points 2023 2032 index = index & (data_copy.err_data != 0) 2024 index = index & (n umpy.isfinite(data_copy.data))2033 index = index & (np.isfinite(data_copy.data)) 2025 2034 fn = data_copy.data[index] 2026 2035 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2027 if theory_data ==None:2036 if theory_data is None: 2028 2037 return chisqr 2029 2038 gn = theory_data.data[index] … … 2031 2040 else: 2032 2041 # 1 d theory from model_thread is only in the range of index 2033 if index ==None:2034 index = n umpy.ones(len(data_copy.y), dtype=bool)2035 if weight !=None:2042 if index is None: 2043 index = np.ones(len(data_copy.y), dtype=bool) 2044 if weight is not None: 2036 2045 data_copy.dy = weight 2037 if data_copy.dy ==None or data_copy.dy == []:2038 dy = n umpy.ones(len(data_copy.y))2046 if data_copy.dy is None or data_copy.dy == []: 2047 dy = np.ones(len(data_copy.y)) 2039 2048 else: 2040 2049 ## Set consistently w/AbstractFitengine: … … 2045 2054 2046 2055 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2047 if theory_data ==None:2056 if theory_data is None: 2048 2057 return chisqr 2049 2058 gn = theory_data.y … … 2054 2063 res = (fn - gn) / en 2055 2064 except ValueError: 2056 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))) 2057 2066 return 2058 2067 2059 residuals = res[n umpy.isfinite(res)]2068 residuals = res[np.isfinite(res)] 2060 2069 # get chisqr only w/finite 2061 chisqr = n umpy.average(residuals * residuals)2070 chisqr = np.average(residuals * residuals) 2062 2071 2063 2072 self._plot_residuals(page_id=page_id, data=data_copy, … … 2088 2097 theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) 2089 2098 gn = theory_data.data 2090 if weight ==None:2099 if weight is None: 2091 2100 en = data_copy.err_data 2092 2101 else: … … 2096 2105 residuals.qy_data = data_copy.qy_data 2097 2106 residuals.q_data = data_copy.q_data 2098 residuals.err_data = n umpy.ones(len(residuals.data))2107 residuals.err_data = np.ones(len(residuals.data)) 2099 2108 residuals.xmin = min(residuals.qx_data) 2100 2109 residuals.xmax = max(residuals.qx_data) … … 2109 2118 else: 2110 2119 # 1 d theory from model_thread is only in the range of index 2111 if data_copy.dy ==None or data_copy.dy == []:2112 dy = n umpy.ones(len(data_copy.y))2120 if data_copy.dy is None or data_copy.dy == []: 2121 dy = np.ones(len(data_copy.y)) 2113 2122 else: 2114 if weight ==None:2115 dy = n umpy.ones(len(data_copy.y))2123 if weight is None: 2124 dy = np.ones(len(data_copy.y)) 2116 2125 ## Set consitently w/AbstractFitengine: 2117 2126 ## But this should be corrected later. … … 2132 2141 residuals.y = (fn - gn[index]) / en 2133 2142 residuals.x = data_copy.x[index] 2134 residuals.dy = n umpy.ones(len(residuals.y))2143 residuals.dy = np.ones(len(residuals.y)) 2135 2144 residuals.dx = None 2136 2145 residuals.dxl = None … … 2150 2159 ##group_id specify on which panel to plot this data 2151 2160 group_id = self.page_finder[page_id].get_graph_id() 2152 if group_id ==None:2161 if group_id is None: 2153 2162 group_id = data.group_id 2154 2163 new_plot.group_id = "res" + str(group_id) -
src/sas/sasgui/perspectives/fitting/media/plugin.rst
r984f3fc r72100ee 538 538 sin, cos, tan, asin, acos, atan: 539 539 Trigonometry functions and inverses, operating on radians. 540 sinh, cos , tanh, asinh, acosh, atanh:540 sinh, cosh, tanh, asinh, acosh, atanh: 541 541 Hyperbolic trigonometry functions. 542 542 atan2(y,x): -
src/sas/sasgui/perspectives/fitting/model_thread.py
rc1c9929 r7432acb 4 4 5 5 import time 6 import numpy 6 import numpy as np 7 7 import math 8 8 from sas.sascalc.data_util.calcthread import CalcThread … … 53 53 self.starttime = time.time() 54 54 # Determine appropriate q range 55 if self.qmin ==None:55 if self.qmin is None: 56 56 self.qmin = 0 57 if self.qmax ==None:58 if self.data !=None:57 if self.qmax is None: 58 if self.data is not None: 59 59 newx = math.pow(max(math.fabs(self.data.xmax), 60 60 math.fabs(self.data.xmin)), 2) … … 68 68 69 69 # Define matrix where data will be plotted 70 radius = n umpy.sqrt((self.data.qx_data * self.data.qx_data) + \70 radius = np.sqrt((self.data.qx_data * self.data.qx_data) + \ 71 71 (self.data.qy_data * self.data.qy_data)) 72 72 … … 75 75 index_model = (self.qmin <= radius) & (radius <= self.qmax) 76 76 index_model = index_model & self.data.mask 77 index_model = index_model & n umpy.isfinite(self.data.data)77 index_model = index_model & np.isfinite(self.data.data) 78 78 79 79 if self.smearer is not None: … … 91 91 self.data.qy_data[index_model] 92 92 ]) 93 output = n umpy.zeros(len(self.data.qx_data))93 output = np.zeros(len(self.data.qx_data)) 94 94 # output default is None 95 95 # This method is to distinguish between masked … … 163 163 """ 164 164 self.starttime = time.time() 165 output = n umpy.zeros((len(self.data.x)))165 output = np.zeros((len(self.data.x))) 166 166 index = (self.qmin <= self.data.x) & (self.data.x <= self.qmax) 167 167 … … 175 175 self.qmax) 176 176 mask = self.data.x[first_bin:last_bin+1] 177 unsmeared_output = n umpy.zeros((len(self.data.x)))177 unsmeared_output = np.zeros((len(self.data.x))) 178 178 unsmeared_output[first_bin:last_bin+1] = self.model.evalDistribution(mask) 179 179 self.smearer.model = self.model … … 183 183 # Check that the arrays are compatible. If we only have a model but no data, 184 184 # the length of data.y will be zero. 185 if isinstance(self.data.y, n umpy.ndarray) and output.shape == self.data.y.shape:186 unsmeared_data = n umpy.zeros((len(self.data.x)))187 unsmeared_error = n umpy.zeros((len(self.data.x)))185 if isinstance(self.data.y, np.ndarray) and output.shape == self.data.y.shape: 186 unsmeared_data = np.zeros((len(self.data.x))) 187 unsmeared_error = np.zeros((len(self.data.x))) 188 188 unsmeared_data[first_bin:last_bin+1] = self.data.y[first_bin:last_bin+1]\ 189 189 * unsmeared_output[first_bin:last_bin+1]\ … … 209 209 210 210 if p_model is not None and s_model is not None: 211 sq_values = n umpy.zeros((len(self.data.x)))212 pq_values = n umpy.zeros((len(self.data.x)))211 sq_values = np.zeros((len(self.data.x))) 212 pq_values = np.zeros((len(self.data.x))) 213 213 sq_values[index] = s_model.evalDistribution(self.data.x[index]) 214 214 pq_values[index] = p_model.evalDistribution(self.data.x[index]) -
src/sas/sasgui/perspectives/fitting/models.py
r05b8e01 r6a455cd3 2 2 Utilities to manage models 3 3 """ 4 from __future__ import print_function 5 4 6 import traceback 5 7 import os … … 19 21 from sasmodels.sasview_model import load_custom_model, load_standard_models 20 22 from sas.sasgui.perspectives.fitting.fitpage import CUSTOM_MODEL 23 24 logger = logging.getLogger(__name__) 21 25 22 26 … … 140 144 type, value, tb = sys.exc_info() 141 145 if type is not None and issubclass(type, py_compile.PyCompileError): 142 print "Problem with", repr(value)146 print("Problem with", repr(value)) 143 147 raise type, value, tb 144 148 return 1 … … 153 157 try: 154 158 import compileall 155 compileall.compile_dir(dir=dir, ddir=dir, force= 1,159 compileall.compile_dir(dir=dir, ddir=dir, force=0, 156 160 quiet=report_problem) 157 161 except: … … 160 164 161 165 162 def _find Models(dir):166 def _find_models(): 163 167 """ 164 168 Find custom models 165 169 """ 166 170 # List of plugin objects 167 dir = find_plugins_dir()171 directory = find_plugins_dir() 168 172 # Go through files in plug-in directory 169 if not os.path.isdir(dir ):170 msg = "SasView couldn't locate Model plugin folder %r." % dir 171 logg ing.warning(msg)173 if not os.path.isdir(directory): 174 msg = "SasView couldn't locate Model plugin folder %r." % directory 175 logger.warning(msg) 172 176 return {} 173 177 174 plugin_log("looking for models in: %s" % str(dir ))175 # compile_file(dir) #always recompile the folder plugin176 logg ing.info("plugin model dir: %s" % str(dir))178 plugin_log("looking for models in: %s" % str(directory)) 179 # compile_file(directory) #always recompile the folder plugin 180 logger.info("plugin model dir: %s" % str(directory)) 177 181 178 182 plugins = {} 179 for filename in os.listdir(dir ):183 for filename in os.listdir(directory): 180 184 name, ext = os.path.splitext(filename) 181 185 if ext == '.py' and not name == '__init__': 182 path = os.path.abspath(os.path.join(dir , filename))186 path = os.path.abspath(os.path.join(directory, filename)) 183 187 try: 184 188 model = load_custom_model(path) … … 189 193 msg += "\nwhile accessing model in %r" % path 190 194 plugin_log(msg) 191 logg ing.warning("Failed to load plugin %r. See %s for details"192 193 195 logger.warning("Failed to load plugin %r. See %s for details" 196 % (path, PLUGIN_LOG)) 197 194 198 return plugins 195 199 … … 261 265 temp = {} 262 266 if self.is_changed(): 263 temp = _findModels( dir)267 temp = _findModels() 264 268 self.last_time_dir_modified = time.time() 265 269 return temp 266 logg ing.info("plugin model : %s" % str(temp))270 logger.info("plugin model : %s" % str(temp)) 267 271 return temp 268 272 … … 338 342 """ 339 343 self.plugins = [] 340 new_plugins = _find Models(dir)344 new_plugins = _find_models() 341 345 for name, plug in new_plugins.iteritems(): 342 346 for stored_name, stored_plug in self.stored_plugins.iteritems(): -
src/sas/sasgui/perspectives/fitting/pagestate.py
r27109e5 r959eb01 18 18 import copy 19 19 import logging 20 import numpy 20 import numpy as np 21 21 import traceback 22 22 … … 33 33 from sas.sascalc.dataloader.data_info import Data2D, Collimation, Detector 34 34 from sas.sascalc.dataloader.data_info import Process, Aperture 35 36 logger = logging.getLogger(__name__) 35 37 36 38 # Information to read/write state as xml … … 395 397 msg = "Save state does not have enough information to load" 396 398 msg += " the all of the data." 397 logg ing.warning(msg=msg)399 logger.warning(msg=msg) 398 400 else: 399 401 self.formfactorcombobox = FIRST_FORM[self.categorycombobox] … … 410 412 for fittable, name, value, _, uncert, lower, upper, units in params: 411 413 if not value: 412 value = n umpy.nan414 value = np.nan 413 415 if not uncert or uncert[1] == '' or uncert[1] == 'None': 414 416 uncert[0] = False 415 uncert[1] = n umpy.nan417 uncert[1] = np.nan 416 418 if not upper or upper[1] == '' or upper[1] == 'None': 417 419 upper[0] = False 418 upper[1] = n umpy.nan420 upper[1] = np.nan 419 421 if not lower or lower[1] == '' or lower[1] == 'None': 420 422 lower[0] = False 421 lower[1] = n umpy.nan423 lower[1] = np.nan 422 424 if is_string: 423 425 p[name] = str(value) … … 449 451 lower = params.get(name + ".lower", '-inf') 450 452 units = params.get(name + ".units") 451 if std is not None and std is not n umpy.nan:453 if std is not None and std is not np.nan: 452 454 std = [True, str(std)] 453 455 else: 454 456 std = [False, ''] 455 if lower is not None and lower is not n umpy.nan:457 if lower is not None and lower is not np.nan: 456 458 lower = [True, str(lower)] 457 459 else: 458 460 lower = [True, '-inf'] 459 if upper is not None and upper is not n umpy.nan:461 if upper is not None and upper is not np.nan: 460 462 upper = [True, str(upper)] 461 463 else: … … 620 622 except Exception: 621 623 msg = "Report string expected 'name: value' but got %r" % line 622 logg ing.error(msg)624 logger.error(msg) 623 625 if name.count("State created"): 624 626 repo_time = "" + value … … 662 664 except Exception: 663 665 msg = "While parsing 'data: ...'\n" 664 logg ing.error(msg + traceback.format_exc())666 logger.error(msg + traceback.format_exc()) 665 667 if name == "model name ": 666 668 try: … … 678 680 except Exception: 679 681 msg = "While parsing 'Plotting Range: ...'\n" 680 logg ing.error(msg + traceback.format_exc())682 logger.error(msg + traceback.format_exc()) 681 683 paramval = "" 682 684 for lines in param_string.split(":"): … … 1037 1039 msg = "PageState.fromXML: Could not" 1038 1040 msg += " read timestamp\n %s" % sys.exc_value 1039 logg ing.error(msg)1041 logger.error(msg) 1040 1042 1041 1043 if entry is not None: … … 1077 1079 except Exception: 1078 1080 base = "unable to load distribution %r for %s" 1079 logg ing.error(base % (value, parameter))1081 logger.error(base % (value, parameter)) 1080 1082 continue 1081 1083 _disp_obj_dict = getattr(self, varname) … … 1099 1101 msg = ("Error reading %r from %s %s\n" 1100 1102 % (line, tagname, name)) 1101 logg ing.error(msg + traceback.format_exc())1102 dic[name] = n umpy.array(value_list)1103 logger.error(msg + traceback.format_exc()) 1104 dic[name] = np.array(value_list) 1103 1105 setattr(self, varname, dic) 1104 1106 … … 1207 1209 1208 1210 except: 1209 logg ing.info("XML document does not contain fitting information.\n"1211 logger.info("XML document does not contain fitting information.\n" 1210 1212 + traceback.format_exc()) 1211 1213 -
src/sas/sasgui/perspectives/fitting/report_dialog.py
rd85c194 r7432acb 39 39 self.nimages = len(self.report_list[2]) 40 40 41 if self.report_list[2] !=None:41 if self.report_list[2] is not None: 42 42 # put image path in the report string 43 43 if len(self.report_list[2]) == 1: -
src/sas/sasgui/perspectives/fitting/utils.py
rd85c194 r959eb01 2 2 Module contains functions frequently used in this package 3 3 """ 4 import numpy 4 import numpy as np 5 5 6 6 … … 19 19 data = data.y 20 20 if flag == 0: 21 weight = n umpy.ones_like(data)21 weight = np.ones_like(data) 22 22 elif flag == 1: 23 23 weight = dy_data 24 24 elif flag == 2: 25 weight = n umpy.sqrt(numpy.abs(data))25 weight = np.sqrt(np.abs(data)) 26 26 elif flag == 3: 27 weight = n umpy.abs(data)27 weight = np.abs(data) 28 28 return weight -
src/sas/sasgui/perspectives/fitting/fitpanel.py
r67b0a99 rd79feea 92 92 # state must be cloned 93 93 state = page.get_state().clone() 94 if data is not None or page.model is not None: 94 # data_list only populated with real data 95 # Fake object in data from page.get_data() if model is selected 96 if len(page.data_list) is not 0 and page.model is not None: 95 97 new_doc = self._manager.state_reader.write_toXML(data, 96 98 state, 97 99 batch_state) 100 # Fit #2 through #n are append to first fit 98 101 if doc is not None and hasattr(doc, "firstChild"): 99 child = new_doc.firstChild.firstChild 100 doc.firstChild.appendChild(child) 102 # Only append if properly formed new_doc 103 if new_doc is not None and hasattr(new_doc, "firstChild"): 104 child = new_doc.firstChild.firstChild 105 doc.firstChild.appendChild(child) 106 # First fit defines the main document 101 107 else: 102 108 doc = new_doc … … 395 401 temp_data = page.get_data() 396 402 if temp_data is not None and temp_data.id in data: 397 self.SetSelection(pos) 398 self.on_close_page(event=None) 399 temp = self.GetSelection() 400 self.DeletePage(temp) 403 self.close_page_with_data(temp_data) 401 404 if self.sim_page is not None: 402 405 if len(self.sim_page.model_list) == 0: … … 405 408 self.on_close_page(event=None) 406 409 temp = self.GetSelection() 407 self.DeletePage( temp)410 self.DeletePage(pos) 408 411 self.sim_page = None 409 412 self.batch_on = False
Note: See TracChangeset
for help on using the changeset viewer.