Changeset dceff6e in sasview for src/sas/sasgui/perspectives
- Timestamp:
- Aug 31, 2016 11:21:55 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:
- ce94504
- Parents:
- ec30905 (diff), 4036cb0 (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
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/calculator/data_operator.py
re871a2d r0e760e9 15 15 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 16 16 17 #Control panel width 17 #Control panel width 18 18 if sys.platform.count("win32") > 0: 19 19 PANEL_TOP = 0 … … 156 156 157 157 wx.EVT_TEXT_ENTER(self.data_namectr, -1, self.on_name) 158 wx.EVT_TEXT _ENTER(self.numberctr, -1, self.on_number)158 wx.EVT_TEXT(self.numberctr, -1, self.on_number) 159 159 wx.EVT_COMBOBOX(self.data1_cbox, -1, self.on_select_data1) 160 160 wx.EVT_COMBOBOX(self.operator_cbox, -1, self.on_select_operator) … … 235 235 self.name_sizer.Layout() 236 236 237 def on_number(self, event=None ):237 def on_number(self, event=None, control=None): 238 238 """ 239 239 On selecting Number for Data2 240 240 """ 241 241 self.send_warnings('') 242 item = event.GetEventObject() 242 item = control 243 if item is None and event is not None: 244 item = event.GetEventObject() 245 elif item is None: 246 raise ValueError("Event or control must be supplied") 243 247 text = item.GetValue().strip() 244 248 if self.numberctr.IsShown(): … … 251 255 except: 252 256 self._set_textctrl_color(self.numberctr, 'pink') 253 msg = "DataOperation: Number requires a float number." 254 self.send_warnings(msg, 'error') 255 return 257 if event is None: 258 msg = "DataOperation: Number requires a float number." 259 self.send_warnings(msg, 'error') 260 return False 256 261 else: 257 262 self._set_textctrl_color(self.numberctr, self.color) … … 263 268 self.draw_output(self.output) 264 269 self.Refresh() 270 return True 265 271 266 272 def on_select_data1(self, event=None): … … 607 613 wx.MessageBox(msg, 'Error') 608 614 return 615 if self.numberctr.IsEnabled() and self.numberctr.IsShown(): 616 valid_num = self.on_number(control=self.numberctr) 617 if not valid_num: 618 return 609 619 # send data to data manager 610 620 self.output.name = name … … 731 741 #add plot 732 742 self.graph.add(plot) 733 #draw 743 #draw 734 744 self.graph.render(self) 735 745 … … 985 995 window = DataOperatorWindow(parent=None, data=[], title="Data Editor") 986 996 app.MainLoop() 987 -
src/sas/sasgui/perspectives/calculator/image_viewer.py
rd0248bd r25b9707a 73 73 parent.put_icon(plot_frame) 74 74 except: 75 print "parent", parent76 75 err_msg += "Failed to load '%s'.\n" % basename 77 76 if err_msg: … … 109 108 """ 110 109 # Initialize the Frame object 111 PlotFrame.__init__(self, parent, id, title, scale, size) 110 PlotFrame.__init__(self, parent, id, title, scale, size, 111 show_menu_icons=False) 112 112 self.parent = parent 113 113 self.data = image … … 437 437 ImageView(None).load() 438 438 app.MainLoop() 439 -
src/sas/sasgui/perspectives/calculator/model_editor.py
rbb841ef r9501661 578 578 else: 579 579 out_f.write(line + "\n") 580 elif line.count("P1 = make_class"):580 elif line.count("P1 = find_model"): 581 581 out_f.write(line % (name1) + "\n") 582 elif line.count("P2 = make_class"):582 elif line.count("P2 = find_model"): 583 583 out_f.write(line % (name2) + "\n") 584 584 … … 719 719 Do the layout for parameter related widgets 720 720 """ 721 param_txt = wx.StaticText(self, -1, 'Fit Parameters (if any): ') 722 723 param_tip = "#Set the parameters and initial values.\n" 721 param_txt = wx.StaticText(self, -1, 'Fit Parameters NOT requiring' + \ 722 ' polydispersity (if any): ') 723 724 param_tip = "#Set the parameters NOT requiring polydispersity " + \ 725 "and their initial values.\n" 724 726 param_tip += "#Example:\n" 725 727 param_tip += "A = 1\nB = 1" … … 736 738 737 739 # Parameters with polydispersity 738 pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring polydispersity (if any): ') 739 740 pd_param_tip = "#Set the parameters and initial values.\n" 740 pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring ' + \ 741 'polydispersity (if any): ') 742 743 pd_param_tip = "#Set the parameters requiring polydispersity and " + \ 744 "their initial values.\n" 741 745 pd_param_tip += "#Example:\n" 742 746 pd_param_tip += "C = 2\nD = 2" … … 803 807 self.bt_close.SetToolTipString("Close this panel.") 804 808 805 self.button_sizer.AddMany([(self.bt_apply, 0, 806 wx.LEFT, EDITOR_WIDTH * 0.8), 807 (self.bt_help, 0, 808 wx.LEFT,15), 809 (self.bt_close, 0, 810 wx.LEFT | wx.BOTTOM, 15)]) 809 self.button_sizer.AddMany([(self.bt_apply, 0,0), 810 (self.bt_help, 0, wx.LEFT | wx.BOTTOM,15), 811 (self.bt_close, 0, wx.LEFT | wx.RIGHT, 15)]) 811 812 812 813 def _do_layout(self): … … 835 836 wx.ALL | wx.EXPAND, 5), 836 837 (self.msg_sizer, 0, wx.EXPAND | wx.ALL, 5), 837 (self.button_sizer, 0, wx. EXPAND | wx.ALL, 5)])838 (self.button_sizer, 0, wx.ALIGN_RIGHT)]) 838 839 self.SetSizer(self.main_sizer) 839 840 self.SetAutoLayout(True) … … 1237 1238 ##import scipy? 1238 1239 #class Model(Model1DPlugin): 1239 # name = ""1240 # name = basename without extension of __file__ 1240 1241 # def __init__(self): 1241 1242 # Model1DPlugin.__init__(self, name=self.name) 1242 1243 # #set name same as file name 1243 # self.name = self.get_fname()1244 1244 # #self.params here 1245 1245 # self.description = "%s" … … 1303 1303 """ 1304 1304 TEST_TEMPLATE = """ 1305 def get_fname(self):1306 path = sys._getframe().f_code.co_filename1307 basename = os.path.basename(path)1308 name, _ = os.path.splitext(basename)1309 return name1310 1305 ###################################################################### 1311 1306 ## THIS IS FOR TEST. DO NOT MODIFY THE FOLLOWING LINES!!!!!!!!!!!!!!!! … … 1330 1325 import sys 1331 1326 import copy 1327 import collections 1332 1328 1333 1329 import numpy 1334 1330 1335 1331 from sas.sascalc.fit.pluginmodel import Model1DPlugin 1336 from sasmodels.sasview_model import make_class 1337 from sasmodels.core import load_model_info 1338 # User can change the name of the model (only with single functional model) 1339 #P1_model: 1340 #from %s import Model as P1 1341 1342 #P2_model: 1343 #from %s import Model as P2 1332 from sasmodels.sasview_model import find_model 1344 1333 1345 1334 class Model(Model1DPlugin): 1346 name = "" 1347 def __init__(self): 1335 name = os.path.splitext(os.path.basename(__file__))[0] 1336 is_multiplicity_model = False 1337 def __init__(self, multiplicity=1): 1348 1338 Model1DPlugin.__init__(self, name='') 1349 P1 = make_class('%s')1350 P2 = make_class('%s')1339 P1 = find_model('%s') 1340 P2 = find_model('%s') 1351 1341 p_model1 = P1() 1352 1342 p_model2 = P2() 1353 1343 ## Setting model name model description 1354 1344 self.description = '%s' 1355 self.name = self.get_fname()1356 1345 if self.name.rstrip().lstrip() == '': 1357 1346 self.name = self._get_name(p_model1.name, p_model2.name) … … 1362 1351 1363 1352 ## Define parameters 1364 self.params = {}1353 self.params = collections.OrderedDict() 1365 1354 1366 1355 ## Parameter details [units, min, max] … … 1391 1380 #list of parameter that can be fitted 1392 1381 self._set_fixed_params() 1382 1393 1383 ## parameters with orientation 1384 self.orientation_params = [] 1394 1385 for item in self.p_model1.orientation_params: 1395 1386 new_item = "p1_" + item … … 1402 1393 self.orientation_params.append(new_item) 1403 1394 ## magnetic params 1395 self.magnetic_params = [] 1404 1396 for item in self.p_model1.magnetic_params: 1405 1397 new_item = "p1_" + item … … 1459 1451 1460 1452 def _set_dispersion(self): 1453 self.dispersion = collections.OrderedDict() 1461 1454 ##set dispersion only from p_model 1462 1455 for name , value in self.p_model1.dispersion.iteritems(): … … 1574 1567 1575 1568 def _set_fixed_params(self): 1569 self.fixed = [] 1576 1570 for item in self.p_model1.fixed: 1577 1571 new_item = "p1" + item … … 1624 1618 self.description += description 1625 1619 1626 def get_fname(self):1627 path = sys._getframe().f_code.co_filename1628 basename = os.path.basename(path)1629 name, _ = os.path.splitext(basename)1630 return name1631 1632 1620 if __name__ == "__main__": 1633 1621 m1= Model() -
src/sas/sasgui/perspectives/calculator/pyconsole.py
r26d6e045 r7673ecd 27 27 """ 28 28 # try running the model 29 from sasmodels. core import load_model, call_kernel30 model = load_model(path)31 29 from sasmodels.sasview_model import load_custom_model 30 Model = load_custom_model(path) 31 model = Model() 32 32 q = np.array([0.01, 0.1]) 33 kernel = model.make_kernel([q]) 34 Iq = call_kernel(kernel, {}) 35 33 Iq = model.evalDistribution(q) 36 34 qx, qy = np.array([0.01, 0.01]), np.array([0.1, 0.1]) 37 kernel = model.make_kernel([qx, qy]) 38 Iqxy = call_kernel(kernel, {}) 35 Iqxy = model.evalDistribution([qx, qy]) 39 36 40 37 result = """ … … 56 53 except Exception: 57 54 import traceback 58 result, errmsg = None, traceback.format_exc( limit=2)55 result, errmsg = None, traceback.format_exc() 59 56 60 57 parts = ["Running model '%s'..." % os.path.basename(fname)] -
src/sas/sasgui/perspectives/fitting/basepage.py
rcb4ef58 ree4b3cb 12 12 import json 13 13 import logging 14 import traceback 15 14 16 from collections import defaultdict 15 17 from wx.lib.scrolledpanel import ScrolledPanel 18 19 import sasmodels.sasview_model 16 20 from sas.sasgui.guiframe.panel_base import PanelBase 17 21 from sas.sasgui.guiframe.utils import format_number, check_float, IdList … … 198 202 self.state_change = False 199 203 ## save customized array 200 self.values = []201 self.weights = []204 self.values = {} # type: Dict[str, List[float, ...]] 205 self.weights = {} # type: Dict[str, List[float, ...]] 202 206 ## retrieve saved state 203 207 self.number_saved_state = 0 … … 852 856 angles.append(angle) 853 857 weights.append(weight) 854 except :858 except Exception: 855 859 # Skip non-data lines 856 logging.error( sys.exc_info()[1])860 logging.error(traceback.format_exc()) 857 861 return numpy.array(angles), numpy.array(weights) 858 862 except: … … 1393 1397 self.model._persistency_dict[key] = \ 1394 1398 [state.values, state.weights] 1395 except :1396 logging.error( sys.exc_info()[1])1399 except Exception: 1400 logging.error(traceback.format_exc()) 1397 1401 selection = self._find_polyfunc_selection(disp_model) 1398 1402 for list in self.fittable_param: … … 1410 1414 list[5].Disable() 1411 1415 list[6].Disable() 1412 except :1413 logging.error( sys.exc_info()[1])1416 except Exception: 1417 logging.error(traceback.format_exc()) 1414 1418 # For array, disable all fixed params 1415 1419 if selection == 1: … … 1419 1423 try: 1420 1424 item[2].Disable() 1421 except :1422 logging.error( sys.exc_info()[1])1425 except Exception: 1426 logging.error(traceback.format_exc()) 1423 1427 1424 1428 # Make sure the check box updated when all checked … … 1500 1504 is_2Ddata = True 1501 1505 if self.model != None: 1502 try: 1503 is_modified = self._check_value_enter(self.fittable_param, 1504 is_modified) 1505 is_modified = self._check_value_enter(self.fixed_param, 1506 is_modified) 1507 is_modified = self._check_value_enter(self.parameters, 1508 is_modified) 1509 except: 1510 logging.error(sys.exc_info()[1]) 1506 is_modified = (self._check_value_enter(self.fittable_param) 1507 or self._check_value_enter(self.fixed_param) 1508 or self._check_value_enter(self.parameters)) 1511 1509 1512 1510 # Here we should check whether the boundaries have been modified. … … 1557 1555 flag = True 1558 1556 self.fitrange = True 1559 is_modified = False1560 1557 1561 1558 #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ … … 1570 1567 [self.data]) 1571 1568 ##Check the values 1572 self._check_value_enter(self.fittable_param , is_modified)1573 self._check_value_enter(self.fixed_param , is_modified)1574 self._check_value_enter(self.parameters , is_modified)1569 self._check_value_enter(self.fittable_param) 1570 self._check_value_enter(self.fixed_param) 1571 self._check_value_enter(self.parameters) 1575 1572 1576 1573 # If qmin and qmax have been modified, update qmin and qmax and … … 1651 1648 try: 1652 1649 self.save_current_state() 1653 except :1654 logging.error( sys.exc_info()[1])1650 except Exception: 1651 logging.error(traceback.format_exc()) 1655 1652 1656 1653 return flag 1657 1658 def _is_modified(self, is_modified):1659 """1660 return to self._is_modified1661 """1662 return is_modified1663 1654 1664 1655 def _reset_parameters_state(self, listtorestore, statelist): … … 1895 1886 if mod_cat == custom_model: 1896 1887 for model in self.model_list_box[mod_cat]: 1897 if 'sasmodels.sasview_model.' in str(model): 1898 str_m = model.id 1899 else: 1900 str_m = str(model).split(".")[0] 1901 #self.model_box.Append(str_m) 1888 str_m = model.id if hasattr(model, 'id') else model.name 1902 1889 m_list.append(self.model_dict[str_m]) 1903 1890 else: … … 1910 1897 # wx.PostEvent(self.parent.parent, 1911 1898 # StatusEvent(status=msg, info="error")) 1912 except :1913 msg = "%s\n" % (sys.exc_info()[1])1899 except Exception: 1900 msg = traceback.format_exc() 1914 1901 wx.PostEvent(self._manager.parent, 1915 1902 StatusEvent(status=msg, info="error")) … … 1964 1951 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1965 1952 # Flag to register when a parameter has changed. 1966 #is_modified = False1967 1953 if tcrtl.GetValue().lstrip().rstrip() != "": 1968 1954 try: … … 1994 1980 if temp_npts != self.num_points: 1995 1981 self.num_points = temp_npts 1996 #is_modified = True1997 1982 else: 1998 1983 msg = "Cannot plot: No points in Q range!!! " … … 2146 2131 self.temp_multi_functional = True 2147 2132 elif form_factor != None: 2148 self.model = form_factor(self.multi_factor) 2133 if self.multi_factor is not None: 2134 self.model = form_factor(self.multi_factor) 2135 else: 2136 # old style plugin models do not accept a multiplicity argument 2137 self.model = form_factor() 2149 2138 else: 2150 2139 self.model = None … … 2165 2154 self.on_set_focus(None) 2166 2155 self.Layout() 2156 2167 2157 2168 2158 def _validate_qrange(self, qmin_ctrl, qmax_ctrl): … … 2272 2262 return flag 2273 2263 2274 def _check_value_enter(self, list , modified):2264 def _check_value_enter(self, list): 2275 2265 """ 2276 2266 :param list: model parameter and panel info … … 2282 2272 parameter's maximum value , 2283 2273 parameter's units] 2284 """ 2285 is_modified = modified2286 if len(list) == 0:2287 return is_modified2274 2275 Returns True if the model parameters have changed. 2276 """ 2277 is_modified = False 2288 2278 for item in list: 2289 2279 #skip angle parameters for 1D 2290 if not self.enable2D: 2291 if item in self.orientation_params: 2292 continue 2293 #try: 2280 if not self.enable2D and item in self.orientation_params: 2281 continue 2282 2294 2283 name = str(item[1]) 2295 2296 if string.find(name, ".npts") == -1 and \ 2297 string.find(name, ".nsigmas") == -1: 2298 ## check model parameters range 2299 param_min = None 2300 param_max = None 2301 2302 ## check minimun value 2303 if item[5] != None and item[5] != "": 2304 if item[5].GetValue().lstrip().rstrip() != "": 2305 try: 2306 param_min = float(item[5].GetValue()) 2307 if not self._validate_qrange(item[5], item[2]): 2308 if numpy.isfinite(param_min): 2309 item[2].SetValue(format_number(param_min)) 2310 2311 item[5].SetBackgroundColour(wx.WHITE) 2312 item[2].SetBackgroundColour(wx.WHITE) 2313 2314 except: 2315 msg = "Wrong fit parameter range entered" 2316 wx.PostEvent(self._manager.parent, 2317 StatusEvent(status=msg)) 2318 raise ValueError, msg 2319 is_modified = True 2320 ## check maximum value 2321 if item[6] != None and item[6] != "": 2322 if item[6].GetValue().lstrip().rstrip() != "": 2323 try: 2324 param_max = float(item[6].GetValue()) 2325 if not self._validate_qrange(item[2], item[6]): 2326 if numpy.isfinite(param_max): 2327 item[2].SetValue(format_number(param_max)) 2328 2329 item[6].SetBackgroundColour(wx.WHITE) 2330 item[2].SetBackgroundColour(wx.WHITE) 2331 except: 2332 msg = "Wrong Fit parameter range entered " 2333 wx.PostEvent(self._manager.parent, 2334 StatusEvent(status=msg)) 2335 raise ValueError, msg 2336 is_modified = True 2337 2338 if param_min != None and param_max != None: 2339 if not self._validate_qrange(item[5], item[6]): 2340 msg = "Wrong Fit range entered for parameter " 2341 msg += "name %s of model %s " % (name, self.model.name) 2342 wx.PostEvent(self._manager.parent, 2343 StatusEvent(status=msg)) 2344 2345 if name in self.model.details.keys(): 2346 self.model.details[name][1:3] = param_min, param_max 2347 is_modified = True 2348 else: 2349 self.model.details[name] = ["", param_min, param_max] 2350 is_modified = True 2351 try: 2352 # Check if the textctr is enabled 2353 if item[2].IsEnabled(): 2354 value = float(item[2].GetValue()) 2355 item[2].SetBackgroundColour("white") 2356 # If the value of the parameter has changed, 2357 # +update the model and set the is_modified flag 2358 if value != self.model.getParam(name) and \ 2359 numpy.isfinite(value): 2360 self.model.setParam(name, value) 2361 except: 2362 item[2].SetBackgroundColour("pink") 2363 msg = "Wrong Fit parameter value entered " 2364 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2284 if name.endswith(".npts") or name.endswith(".nsigmas"): 2285 continue 2286 2287 # Check that min, max and value are floats 2288 value_ctrl, min_ctrl, max_ctrl = item[2], item[5], item[6] 2289 min_str = min_ctrl.GetValue().strip() 2290 max_str = max_ctrl.GetValue().strip() 2291 value_str = value_ctrl.GetValue().strip() 2292 validity = check_float(value_ctrl) 2293 if min_str != "": 2294 validity = validity and check_float(min_ctrl) 2295 if max_str != "": 2296 validity = validity and check_float(max_ctrl) 2297 if not validity: 2298 continue 2299 2300 # Check that min is less than max 2301 low = -numpy.inf if min_str == "" else float(min_str) 2302 high = numpy.inf if max_str == "" else float(max_str) 2303 if high < low: 2304 min_ctrl.SetBackgroundColour("pink") 2305 min_ctrl.Refresh() 2306 max_ctrl.SetBackgroundColour("pink") 2307 max_ctrl.Refresh() 2308 #msg = "Invalid fit range for %s: min must be smaller than max"%name 2309 #wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 2310 continue 2311 2312 # Force value between min and max 2313 value = float(value_str) 2314 if value < low: 2315 value = low 2316 value_ctrl.SetValue(format_number(value)) 2317 elif value > high: 2318 value = high 2319 value_ctrl.SetValue(format_number(value)) 2320 2321 # Update value in model if it has changed 2322 if value != self.model.getParam(name): 2323 self.model.setParam(name, value) 2324 is_modified = True 2325 2326 if name not in self.model.details.keys(): 2327 self.model.details[name] = ["", None, None] 2328 old_low, old_high = self.model.details[name][1:3] 2329 if old_low != low or old_high != high: 2330 # The configuration has changed but it won't change the 2331 # computed curve so no need to set is_modified to True 2332 #is_modified = True 2333 self.model.details[name][1:3] = low, high 2365 2334 2366 2335 return is_modified … … 2474 2443 try: 2475 2444 self.model.set_dispersion(p, disp_model) 2476 except :2477 logging.error( sys.exc_info()[1])2445 except Exception: 2446 logging.error(traceback.format_exc()) 2478 2447 2479 2448 ## save state into … … 2588 2557 self._draw_model() 2589 2558 self.Refresh() 2590 except: 2559 except Exception: 2560 logging.error(traceback.format_exc()) 2591 2561 # Error msg 2592 2562 msg = "Error occurred:" … … 2680 2650 # Try to delete values and weight of the names array dic if exists 2681 2651 try: 2682 del self.values[name] 2683 del self.weights[name] 2684 # delete all other dic 2685 del self.state.values[name] 2686 del self.state.weights[name] 2687 del self.model._persistency_dict[name.split('.')[0]] 2688 del self.state.model._persistency_dict[name.split('.')[0]] 2689 except: 2690 logging.error(sys.exc_info()[1]) 2652 if name in self.values: 2653 del self.values[name] 2654 del self.weights[name] 2655 # delete all other dic 2656 del self.state.values[name] 2657 del self.state.weights[name] 2658 del self.model._persistency_dict[name.split('.')[0]] 2659 del self.state.model._persistency_dict[name.split('.')[0]] 2660 except Exception: 2661 logging.error(traceback.format_exc()) 2691 2662 2692 2663 def _lay_out(self): … … 2832 2803 graphs.append(item2.figure) 2833 2804 canvases.append(item2.canvas) 2834 except :2805 except Exception: 2835 2806 # Not for control panels 2836 logging.error( sys.exc_info()[1])2807 logging.error(traceback.format_exc()) 2837 2808 # Make sure the resduals plot goes to the last 2838 2809 if res_item != None: … … 2936 2907 """ 2937 2908 2938 _TreeLocation = "user/ sasgui/perspectives/fitting/mag_help.html"2909 _TreeLocation = "user/magnetism.html" 2939 2910 _doc_viewer = DocumentationWindow(self, wx.ID_ANY, _TreeLocation, "", 2940 2911 "Polarized Beam/Magnetc Help") … … 3167 3138 if item[7].__class__.__name__ == 'ComboBox': 3168 3139 disfunc = str(item[7].GetValue()) 3169 except :3170 logging.error( sys.exc_info()[1])3140 except Exception: 3141 logging.error(traceback.format_exc()) 3171 3142 3172 3143 # 2D … … 3174 3145 try: 3175 3146 check = item[0].GetValue() 3176 except :3147 except Exception: 3177 3148 check = None 3178 3149 name = item[1] … … 3202 3173 for weight in self.weights[name]: 3203 3174 disfunc += ' ' + str(weight) 3204 except :3205 logging.error( sys.exc_info()[1])3175 except Exception: 3176 logging.error(traceback.format_exc()) 3206 3177 content += name + ',' + str(check) + ',' + value + disfunc + ':' 3207 3178 … … 3403 3374 weights=pd_weights) 3404 3375 is_array = True 3405 except :3406 logging.error( sys.exc_info()[1])3376 except Exception: 3377 logging.error(traceback.format_exc()) 3407 3378 if not is_array: 3408 3379 self._disp_obj_dict[name] = disp_model … … 3418 3389 self.state.weights] 3419 3390 3420 except :3421 logging.error( sys.exc_info()[1])3391 except Exception: 3392 logging.error(traceback.format_exc()) 3422 3393 print "Error in BasePage._paste_poly_help: %s" % \ 3423 3394 sys.exc_info()[1] -
src/sas/sasgui/perspectives/fitting/batchfitpage.py
rfc18690 ree4b3cb 256 256 # if self.model != None: 257 257 # ##Check the values 258 # self._check_value_enter( self.fittable_param , is_modified)259 # self._check_value_enter( self.fixed_param , is_modified)260 # self._check_value_enter( self.parameters , is_modified)258 # self._check_value_enter( self.fittable_param) 259 # self._check_value_enter( self.fixed_param) 260 # self._check_value_enter( self.parameters) 261 261 # 262 262 # # If qmin and qmax have been modified, update qmin and qmax and -
src/sas/sasgui/perspectives/fitting/fitpage.py
r934ce649 ree4b3cb 1365 1365 try: 1366 1366 tcrtl.SetBackgroundColour(wx.WHITE) 1367 self._check_value_enter(self.fittable_param , is_modified)1368 self._check_value_enter(self.parameters , is_modified)1367 self._check_value_enter(self.fittable_param) 1368 self._check_value_enter(self.parameters) 1369 1369 except: 1370 1370 tcrtl.SetBackgroundColour("pink") -
src/sas/sasgui/perspectives/fitting/fitting.py
r934ce649 r7673ecd 273 273 wx.PostEvent(self.parent, evt) 274 274 break 275 except: 275 except Exception: 276 import traceback; traceback.print_exc() 276 277 msg = 'Delete Error: \nCould not delete the file; Check if in use.' 277 278 wx.MessageBox(msg, 'Error') … … 579 580 _, theory_state = item 580 581 self.fit_panel.set_model_state(theory_state) 581 except :582 except Exception: 582 583 msg = "Fitting: cannot deal with the theory received" 583 584 evt = StatusEvent(status=msg, info="error") -
src/sas/sasgui/perspectives/fitting/media/fitting_help.rst
r20846be rb64b87c 15 15 16 16 17 Fitting Perspective18 ======= ============17 Fitting 18 ======= 19 19 20 20 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ … … 24 24 25 25 To fit some data you must first load some data, activate one or more data sets, 26 send those data sets to the fitting perspective, and select a model to fit to 27 each data set. 26 send those data sets to fitting, and select a model to fit to each data set. 28 27 29 28 Instructions on how to load and activate data are in the section :ref:`Loading_data`. … … 331 330 This mode fits one data set. 332 331 333 When data is sent to the fitting perspective it is plotted in a graph window as 334 markers. 332 When data is sent to the fitting it is plotted in a graph window as markers. 335 333 336 334 If a graph does not appear, or a graph window appears but is empty, then the data -
src/sas/sasgui/perspectives/fitting/media/pd_help.rst
r7805458 rb64b87c 105 105 106 106 The median value for the distribution will be the value given for the respective 107 size parameter in the *Fit ting Perspective*, for example, radius = 60.107 size parameter in the *FitPage*, for example, radius = 60. 108 108 109 109 The polydispersity is given by |sigma| … … 172 172 173 173 SasView only uses these array values during the computation, therefore any mean 174 value of the parameter represented by *x* present in the *Fit ting Perspective*174 value of the parameter represented by *x* present in the *FitPage* 175 175 will be ignored. 176 176 -
src/sas/sasgui/perspectives/fitting/models.py
r6afc14b rdceff6e 2 2 Utilities to manage models 3 3 """ 4 import imp4 import traceback 5 5 import os 6 6 import sys … … 8 8 # Time is needed by the log method 9 9 import time 10 import datetime 10 11 import logging 11 12 import py_compile … … 20 21 21 22 PLUGIN_DIR = 'plugin_models' 23 PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR, 24 "plugins.log") 22 25 23 26 def get_model_python_path(): … … 28 31 29 32 30 def log(message):33 def plugin_log(message): 31 34 """ 32 35 Log a message in a file located in the user's home directory 33 36 """ 34 dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) 35 out = open(os.path.join(dir, "plugins.log"), 'a') 36 out.write("%10g: %s\n" % (time.clock(), message)) 37 out = open(PLUGIN_LOG, 'a') 38 now = time.time() 39 stamp = datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S') 40 out.write("%s: %s\n" % (stamp, message)) 37 41 out.close() 38 42 … … 51 55 if not issubclass(model, Model1DPlugin): 52 56 msg = "Plugin %s must be of type Model1DPlugin \n" % str(name) 53 log(msg)57 plugin_log(msg) 54 58 return None 55 59 if model.__name__ != "Model": 56 60 msg = "Plugin %s class name must be Model \n" % str(name) 57 log(msg)61 plugin_log(msg) 58 62 return None 59 63 try: … … 63 67 str(sys.exc_type), 64 68 sys.exc_info()[1]) 65 log(msg)69 plugin_log(msg) 66 70 return None 67 71 … … 72 76 msg = "Plugin %s: error writing function \n\t :%s %s\n " % \ 73 77 (str(name), str(sys.exc_type), sys.exc_info()[1]) 74 log(msg)78 plugin_log(msg) 75 79 return None 76 80 else: 77 81 msg = "Plugin %s needs a method called function \n" % str(name) 78 log(msg)82 plugin_log(msg) 79 83 return None 80 84 return model … … 132 136 """ 133 137 def __nonzero__(self): 134 type, value, t raceback= sys.exc_info()138 type, value, tb = sys.exc_info() 135 139 if type is not None and issubclass(type, py_compile.PyCompileError): 136 140 print "Problem with", repr(value) 137 raise type, value, t raceback141 raise type, value, tb 138 142 return 1 139 143 … … 155 159 156 160 def _findModels(dir): 161 """ 162 Find custom models 163 """ 157 164 # List of plugin objects 158 plugins = {}159 165 dir = find_plugins_dir() 160 166 # Go through files in plug-in directory 161 #always recompile the folder plugin162 167 if not os.path.isdir(dir): 163 msg = "SasView couldn't locate Model plugin folder." 164 msg += """ "%s" does not exist""" % dir 168 msg = "SasView couldn't locate Model plugin folder %r." % dir 165 169 logging.warning(msg) 166 return plugins 167 else: 168 log("looking for models in: %s" % str(dir)) 169 compile_file(dir) 170 logging.info("plugin model dir: %s" % str(dir)) 171 try: 172 list = os.listdir(dir) 173 for item in list: 174 toks = os.path.splitext(os.path.basename(item)) 175 if toks[1] == '.py' and not toks[0] == '__init__': 176 name = toks[0] 177 path = [os.path.abspath(dir)] 178 file = None 179 try: 180 (file, path, info) = imp.find_module(name, path) 181 module = imp.load_module(name, file, item, info) 182 if hasattr(module, "Model"): 183 try: 184 if _check_plugin(module.Model, name) != None: 185 plugins[name] = module.Model 186 except: 187 msg = "Error accessing Model" 188 msg += "in %s\n %s %s\n" % (name, 189 str(sys.exc_type), 190 sys.exc_info()[1]) 191 log(msg) 192 else: 193 filename = os.path.join(dir, item) 194 plugins[name] = load_custom_model(filename) 195 196 except: 197 msg = "Error accessing Model" 198 msg += " in %s\n %s %s \n" % (name, 199 str(sys.exc_type), 200 sys.exc_info()[1]) 201 log(msg) 202 finally: 203 204 if not file == None: 205 file.close() 206 except: 207 # Don't deal with bad plug-in imports. Just skip. 208 msg = "Could not import model plugin: %s" % sys.exc_info()[1] 209 log(msg) 210 170 return {} 171 172 plugin_log("looking for models in: %s" % str(dir)) 173 #compile_file(dir) #always recompile the folder plugin 174 logging.info("plugin model dir: %s" % str(dir)) 175 176 plugins = {} 177 for filename in os.listdir(dir): 178 name, ext = os.path.splitext(filename) 179 if ext == '.py' and not name == '__init__': 180 path = os.path.abspath(os.path.join(dir, filename)) 181 try: 182 model = load_custom_model(path) 183 plugins[model.name] = model 184 except Exception: 185 msg = traceback.format_exc() 186 msg += "\nwhile accessing model in %r" % path 187 plugin_log(msg) 188 logging.warning("Failed to load plugin %r. See %s for details" 189 % (path, PLUGIN_LOG)) 190 211 191 return plugins 212 192 -
src/sas/sasgui/perspectives/fitting/pagestate.py
rc10d9d6c r7673ecd 19 19 import logging 20 20 import numpy 21 import string21 import traceback 22 22 23 23 import xml.dom.minidom … … 473 473 try: 474 474 value = content[1] 475 except :476 logging.error( sys.exc_value)475 except Exception: 476 logging.error(traceback.format_exc()) 477 477 if name.count("State created"): 478 478 repo_time = "" + value … … 515 515 title = content[2] + " [" + repo_time + "]" 516 516 title_name = HEADER % title 517 except :518 logging.error( sys.exc_value)517 except Exception: 518 logging.error(traceback.format_exc()) 519 519 if name == "model name ": 520 520 try: … … 530 530 q_name = ("Q Range: " + q_range) 531 531 q_range = CENTRE % q_name 532 except :533 logging.error( sys.exc_value)532 except Exception: 533 logging.error(traceback.format_exc()) 534 534 paramval = "" 535 535 for lines in param_string.split(":"): … … 864 864 attribute = getattr(self, item[1]) 865 865 attribute[name] = com_name 866 except :867 logging.error( sys.exc_value)866 except Exception: 867 logging.error(traceback.format_exc()) 868 868 869 869 # get self.values and self.weights dic. if exists … … 880 880 val = float(line) 881 881 value_list.append(val) 882 except :882 except Exception: 883 883 # pass if line is empty (it happens) 884 logging.error( sys.exc_value)884 logging.error(traceback.format_exc()) 885 885 dic[name] = numpy.array(value_list) 886 886 setattr(self, item[1], dic) … … 1293 1293 if len(note_value) > 0: 1294 1294 data_info.notes.append(note_value) 1295 except :1295 except Exception: 1296 1296 err_mess = "cansas_reader.read: error processing entry notes\n %s" % sys.exc_value 1297 1297 self.errors.append(err_mess) … … 1315 1315 if len(detail_value) > 0: 1316 1316 data_info.sample.details.append(detail_value) 1317 except :1317 except Exception: 1318 1318 err_mess = "cansas_reader.read: error processing sample details\n %s" % sys.exc_value 1319 1319 self.errors.append(err_mess) -
src/sas/sasgui/perspectives/invariant/invariant_panel.py
rc12f9b4 rcb93b40 250 250 251 251 num = self.state.saved_state['state_num'] 252 if num> 0:252 if int(num) > 0: 253 253 self._set_undo_flag(True) 254 if num< len(state.state_list) - 1:254 if int(num) < len(state.state_list) - 1: 255 255 self._set_redo_flag(True) 256 256 … … 1860 1860 (self.button_calculate, 0, 1861 1861 wx.RIGHT | wx.TOP | wx.BOTTOM, 10), 1862 (self.button_help, 0, 1862 (self.button_help, 0, 1863 1863 wx.RIGHT | wx.TOP | wx.BOTTOM, 10),]) 1864 1864 def _do_layout(self): … … 1882 1882 self.SetSizer(self.main_sizer) 1883 1883 self.SetAutoLayout(True) 1884 1884 1885 1885 def on_help(self, event): 1886 1886 """ 1887 Bring up the Invariant Documentation whenever the HELP button is 1887 Bring up the Invariant Documentation whenever the HELP button is 1888 1888 clicked. 1889 1889 -
src/sas/sasgui/perspectives/invariant/invariant_state.py
rc10d9d6c rcb93b40 426 426 if input_field is not None: 427 427 temp_state[item] = val 428 self.state_list[ ind] = temp_state428 self.state_list[str(ind)] = temp_state 429 429 430 430 # Parse current state (ie, saved_state) … … 790 790 doc = state.toXML(datainfo.name, doc=doc, entry_node=sasentry) 791 791 return doc 792 -
src/sas/sasgui/perspectives/invariant/media/invariant_help.rst
r70305bd2 rb64b87c 4 4 .. by S King, ISIS, during SasView CodeCamp-III in Feb 2015. 5 5 6 Invariant Calculation Perspective7 ===================== ============6 Invariant Calculation 7 ===================== 8 8 9 9 Description … … 45 45 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 46 46 47 Using the perspective48 --------------------- 47 Using invariant analysis 48 ------------------------ 49 49 50 50 1) Select *Invariant* from the *Analysis* menu on the SasView toolbar. … … 53 53 54 54 3) Select a dataset and use the *Send To* button on the *Data Explorer* to load 55 the dataset into the *Invariant* p erspective.55 the dataset into the *Invariant* panel. 56 56 57 4) Use the *Customised Input* boxes on the *Invariant* p erspectiveto subtract57 4) Use the *Customised Input* boxes on the *Invariant* panel to subtract 58 58 any background, specify the contrast (i.e. difference in SLDs - this must be 59 59 specified for the eventual value of Q*\ to be on an absolute scale), or to … … 73 73 74 74 8) If the value of Q*\ calculated with the extrapolated regions is invalid, a 75 red warning will appear at the top of the *Invariant* p erspective panel.75 red warning will appear at the top of the *Invariant* panel. 76 76 77 77 The details of the calculation are available by clicking the *Details* -
src/sas/sasgui/perspectives/pr/media/pr_help.rst
r7805458 rb64b87c 4 4 .. by S King, ISIS, during SasView CodeCamp-III in Feb 2015. 5 5 6 P(r) Inversion Perspective7 ================ ==========6 P(r) Calculation 7 ================ 8 8 9 9 Description … … 32 32 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 33 33 34 Using the perspective35 -------------------- -34 Using P(r) inversion 35 -------------------- 36 36 37 37 The user must enter
Note: See TracChangeset
for help on using the changeset viewer.