Changeset ba8d326 in sasview for src/sas/sasgui
- Timestamp:
- Jun 23, 2017 4:16:29 PM (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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 98e3f24
- Parents:
- 81b35396
- git-author:
- Paul Kienzle <pkienzle@…> (06/21/17 12:38:48)
- git-committer:
- Paul Kienzle <pkienzle@…> (06/23/17 16:16:29)
- Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r81b35396 rba8d326 285 285 """ 286 286 x = np.linspace(start=self.qmin_x, stop=self.qmax_x, 287 287 num=self.npts_x, endpoint=True) 288 288 self.data = Data1D(x=x) 289 289 self.data.xaxis('\\rm{Q}', "A^{-1}") … … 311 311 312 312 x = np.logspace(start=qmin, stop=qmax, 313 313 num=self.npts_x, endpoint=True, base=10.0) 314 314 self.data = Data1D(x=x) 315 315 self.data.xaxis('\\rm{Q}', "A^{-1}") … … 904 904 if len(self._disp_obj_dict) > 0: 905 905 for k, v in self._disp_obj_dict.iteritems(): 906 self.state. _disp_obj_dict[k] = v.type906 self.state.disp_obj_dict[k] = v.type 907 907 908 908 self.state.values = copy.deepcopy(self.values) … … 922 922 self.state.str_parameters) 923 923 self._copy_parameters_state(self.orientation_params, 924 924 self.state.orientation_params) 925 925 self._copy_parameters_state(self.orientation_params_disp, 926 926 self.state.orientation_params_disp) … … 976 976 try: 977 977 self.state.disp_cb_dict[k] = v.GetValue() 978 except :978 except Exception: 979 979 self.state.disp_cb_dict[k] = None 980 980 if len(self._disp_obj_dict) > 0: 981 981 for k, v in self._disp_obj_dict.iteritems(): 982 self.state. _disp_obj_dict[k] = v.type982 self.state.disp_obj_dict[k] = v.type 983 983 984 984 self.state.values = copy.deepcopy(self.values) … … 1022 1022 # to support older version 1023 1023 category_pos = int(state.categorycombobox) 1024 except :1024 except Exception: 1025 1025 category_pos = 0 1026 1026 for ind_cat in range(self.categorybox.GetCount()): … … 1034 1034 # to support older version 1035 1035 formfactor_pos = int(state.formfactorcombobox) 1036 except :1036 except Exception: 1037 1037 formfactor_pos = 0 1038 1038 for ind_form in range(self.formfactorbox.GetCount()): … … 1047 1047 # to support older version 1048 1048 structfactor_pos = int(state.structurecombobox) 1049 except :1049 except Exception: 1050 1050 structfactor_pos = 0 1051 1051 for ind_struct in range(self.structurebox.GetCount()): … … 1284 1284 self.dI_sqrdata.SetValue(state.dI_sqrdata) 1285 1285 self.dI_idata.SetValue(state.dI_idata) 1286 except :1286 except Exception: 1287 1287 # to support older state file formats 1288 1288 self.dI_noweight.SetValue(False) … … 1340 1340 self.weights = copy.deepcopy(state.weights) 1341 1341 1342 for key, disp_type in state. _disp_obj_dict.iteritems():1342 for key, disp_type in state.disp_obj_dict.iteritems(): 1343 1343 # disp_model = disp 1344 1344 disp_model = POLYDISPERSITY_MODELS[disp_type]() … … 1574 1574 try: 1575 1575 self.npts_x = float(self.Npts_total.GetValue()) 1576 except :1576 except Exception: 1577 1577 flag = False 1578 1578 return flag … … 1615 1615 return 1616 1616 1617 for j in range(len(listtorestore)):1617 for item_page in listtorestore: 1618 1618 for param in statelist: 1619 if param[1] == listtorestore[j][1]: 1620 item_page = listtorestore[j] 1619 if param[1] == item_page[1]: 1621 1620 item_page_info = param 1622 1621 if (item_page_info[1] == "theta" or item_page_info[1] == … … 1664 1663 listtorestore = copy.deepcopy(statelist) 1665 1664 1666 for j in range(len(listtorestore)): 1667 item_page = listtorestore[j] 1668 item_page_info = statelist[j] 1665 for item_page, item_page_info in zip(listtorestore, statelist): 1669 1666 # change the state of the check box for simple parameters 1670 1671 1667 if item_page[0] is not None: 1672 1668 item_page[0].SetValue(format_number(item_page_info[0], True)) … … 1921 1917 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1922 1918 return 1923 except :1919 except Exception: 1924 1920 tcrtl.SetBackgroundColour("pink") 1925 1921 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1] … … 1978 1974 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 1979 1975 return 1980 except :1976 except Exception: 1981 1977 tcrtl.SetBackgroundColour("pink") 1982 1978 msg = "Model Error: wrong value entered: %s" % sys.exc_info()[1] … … 2156 2152 # q value from qx and qy 2157 2153 radius = np.sqrt(data.qx_data * data.qx_data + 2158 2154 data.qy_data * data.qy_data) 2159 2155 # get unmasked index 2160 2156 index_data = (float(self.qmin.GetValue()) <= radius) & \ … … 2385 2381 put gaussian dispersity into current model 2386 2382 """ 2387 if len(self.param_toFit) > 0:2383 if self.param_toFit: 2388 2384 for item in self.fittable_param: 2389 2385 if item in self.param_toFit: … … 2402 2398 # from sas.models.dispersion_models import GaussianDispersion 2403 2399 from sasmodels.weights import GaussianDispersion 2404 if len(self.disp_cb_dict) == 0: 2405 self.save_current_state() 2400 if not self.disp_cb_dict: 2406 2401 self.sizer4_4.Clear(True) 2407 self.Layout() 2408 return 2409 if (len(self.disp_cb_dict) > 0): 2402 else: 2410 2403 for p in self.disp_cb_dict: 2411 2404 # The parameter was un-selected. … … 2480 2473 self._disp_obj_dict[name1] = disp_model 2481 2474 self.model.set_dispersion(param_name, disp_model) 2482 self.state. _disp_obj_dict[name1] = disp_model.type2475 self.state.disp_obj_dict[name1] = disp_model.type 2483 2476 2484 2477 value1 = str(format_number(self.model.getParam(name1), True)) … … 2595 2588 self._disp_obj_dict[name] = disp 2596 2589 self.model.set_dispersion(name.split('.')[0], disp) 2597 self.state. _disp_obj_dict[name] = disp.type2590 self.state.disp_obj_dict[name] = disp.type 2598 2591 self.values[name] = values 2599 2592 self.weights[name] = weights … … 2953 2946 # go through the parameters 2954 2947 strings = self._get_copy_helper(self.parameters, 2955 self.orientation_params)2948 self.orientation_params) 2956 2949 content += strings 2957 2950 2958 2951 # go through the fittables 2959 2952 strings = self._get_copy_helper(self.fittable_param, 2960 self.orientation_params_disp)2953 self.orientation_params_disp) 2961 2954 content += strings 2962 2955 2963 2956 # go through the fixed params 2964 2957 strings = self._get_copy_helper(self.fixed_param, 2965 self.orientation_params_disp)2958 self.orientation_params_disp) 2966 2959 content += strings 2967 2960 2968 2961 # go through the str params 2969 2962 strings = self._get_copy_helper(self.str_parameters, 2970 self.orientation_params)2963 self.orientation_params) 2971 2964 content += strings 2972 2965 return content … … 3027 3020 Get the string copies of the param names and values in the tap 3028 3021 """ 3029 content = '\\begin{table}'3030 content += '\\begin{tabular}[h]'3022 content = r'\begin{table}' 3023 content += r'\begin{tabular}[h]' 3031 3024 3032 3025 crlf = chr(13) + chr(10) … … 3039 3032 for param in self.parameters: 3040 3033 content += 'l|l|' 3041 content += '}\hline'3034 content += r'}\hline' 3042 3035 content += crlf 3043 3036 3044 3037 for index, param in enumerate(self.parameters): 3045 content += param[1].replace('_', '\_') # parameter name3038 content += param[1].replace('_', r'\_') # parameter name 3046 3039 content += ' & ' 3047 content += param[1].replace('_', '\_') + "\_err"3040 content += param[1].replace('_', r'\_') + r'\_err' 3048 3041 if index < len(self.parameters) - 1: 3049 3042 content += ' & ' 3050 content += '\\\\ \\hline'3043 content += r'\\ \hline' 3051 3044 content += crlf 3052 3045 … … 3058 3051 if index < len(self.parameters) - 1: 3059 3052 content += ' & ' 3060 content += '\\\\ \\hline'3053 content += r'\\ \hline' 3061 3054 content += crlf 3062 3055 3063 content += '\\end{tabular}'3064 content += '\\end{table}'3056 content += r'\end{tabular}' 3057 content += r'\end{table}' 3065 3058 return content 3066 3059 else: … … 3320 3313 if name.endswith('.npts'): 3321 3314 pd = int(pd) 3322 except :3315 except Exception: 3323 3316 # continue 3324 3317 if not pd and pd != '': … … 3406 3399 self._disp_obj_dict[name] = disp_model 3407 3400 self.model.set_dispersion(param_name, disp_model) 3408 self.state. _disp_obj_dict[name] = disp_model.type3401 self.state.disp_obj_dict[name] = disp_model.type 3409 3402 # TODO: It's not an array, why update values and weights? 3410 3403 self.model._persistency_dict[param_name] = \ … … 3512 3505 3513 3506 else: 3514 for (model, enabled)in sorted(self.master_category_dict[category],3515 3516 if (enabled):3507 for model, enabled in sorted(self.master_category_dict[category], 3508 key=lambda name: name[0]): 3509 if enabled: 3517 3510 self.model_box.Append(model) 3518 3511 … … 3755 3748 self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) 3756 3749 self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus 3757 if kill_focus_callback is None else kill_focus_callback)3750 if kill_focus_callback is None else kill_focus_callback) 3758 3751 self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter 3759 if text_enter_callback is None else text_enter_callback)3752 if text_enter_callback is None else text_enter_callback) 3760 3753 if not ON_MAC: 3761 3754 self.Bind(wx.EVT_LEFT_UP, self._highlight_text 3762 if mouse_up_callback is None else mouse_up_callback)3755 if mouse_up_callback is None else mouse_up_callback) 3763 3756 3764 3757 def _on_set_focus(self, event): -
src/sas/sasgui/perspectives/fitting/fit_thread.py
r959eb01 rba8d326 29 29 worktime=0.03, 30 30 reset_flag=False): 31 CalcThread.__init__(self, 32 completefn, 33 updatefn, 34 yieldtime, 35 worktime) 31 CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime) 36 32 self.handler = handler 37 33 self.fitter = fn … … 93 89 # Real code should not print, but this is an example... 94 90 #print "keyboard exception" 95 #Stop on exception during fitting. Todo: need to put 91 #Stop on exception during fitting. Todo: need to put 96 92 #some mssg and reset progress bar. 97 93 … … 100 96 if self.handler is not None: 101 97 self.handler.stop(msg=msg) 102 except: 98 except: # catch-all: show every exception which stops the thread 103 99 import traceback 104 100 if self.handler is not None: -
src/sas/sasgui/perspectives/fitting/model_thread.py
r7432acb rba8d326 1 1 """ 2 2 Calculation thread for modeling 3 3 """ 4 4 … … 28 28 worktime=0.04, 29 29 exception_handler=None, 30 30 ): 31 31 CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime, 32 32 exception_handler=exception_handler) … … 57 57 if self.qmax is None: 58 58 if self.data is not None: 59 newx = math.pow(max(math.fabs(self.data.xmax), 60 math.fabs(self.data.xmin)), 2) 61 newy = math.pow(max(math.fabs(self.data.ymax), 62 math.fabs(self.data.ymin)), 2) 63 self.qmax = math.sqrt(newx + newy) 59 newx = max(math.fabs(self.data.xmax), math.fabs(self.data.xmin)) 60 newy = max(math.fabs(self.data.ymax), math.fabs(self.data.ymin)) 61 self.qmax = math.sqrt(newx**2 + newy**2) 64 62 65 63 if self.data is None: … … 68 66 69 67 # Define matrix where data will be plotted 70 radius = np.sqrt((self.data.qx_data * self.data.qx_data) + \ 71 (self.data.qy_data * self.data.qy_data)) 72 73 # For theory, qmax is based on 1d qmax 68 radius = np.sqrt(self.data.qx_data**2 + self.data.qy_data**2) 69 70 # For theory, qmax is based on 1d qmax 74 71 # so that must be mulitified by sqrt(2) to get actual max for 2d 75 72 index_model = (self.qmin <= radius) & (radius <= self.qmax) 76 index_model = index_model &self.data.mask77 index_model = index_model &np.isfinite(self.data.data)73 index_model &= self.data.mask 74 index_model &= np.isfinite(self.data.data) 78 75 79 76 if self.smearer is not None: … … 100 97 elapsed = time.time() - self.starttime 101 98 self.complete(image=output, 102 103 104 105 106 107 108 109 110 111 112 113 114 115 99 data=self.data, 100 page_id=self.page_id, 101 model=self.model, 102 state=self.state, 103 toggle_mode_on=self.toggle_mode_on, 104 elapsed=elapsed, 105 index=index_model, 106 fid=self.fid, 107 qmin=self.qmin, 108 qmax=self.qmax, 109 weight=self.weight, 110 #qstep=self.qstep, 111 update_chisqr=self.update_chisqr, 112 source=self.source) 116 113 117 114 … … 137 134 worktime=0.01, 138 135 exception_handler=None, 139 136 ): 140 137 """ 141 138 """ … … 192 189 * unsmeared_output[first_bin:last_bin+1]\ 193 190 / output[first_bin:last_bin+1] 194 unsmeared_output =unsmeared_output[index]195 unsmeared_data =unsmeared_data[index]196 unsmeared_error =unsmeared_error191 unsmeared_output = unsmeared_output[index] 192 unsmeared_data = unsmeared_data[index] 193 unsmeared_error = unsmeared_error 197 194 else: 198 195 output[index] = self.model.evalDistribution(self.data.x[index]) -
src/sas/sasgui/perspectives/fitting/models.py
r8cec26b rba8d326 68 68 try: 69 69 new_instance = model() 70 except :70 except Exception: 71 71 msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name), 72 72 str(sys.exc_type), … … 78 78 try: 79 79 value = new_instance.function() 80 except :80 except Exception: 81 81 msg = "Plugin %s: error writing function \n\t :%s %s\n " % \ 82 82 (str(name), str(sys.exc_type), sys.exc_info()[1]) … … 102 102 103 103 # Find paths needed 104 # TODO: remove unneeded try/except block 104 105 try: 105 106 # For source … … 108 109 else: 109 110 raise 110 except :111 except Exception: 111 112 # Check for data path next to exe/zip file. 112 113 #Look for maximum n_dir up of the current dir to find plugins dir … … 158 159 compileall.compile_dir(dir=dir, ddir=dir, force=0, 159 160 quiet=report_problem) 160 except :161 except Exception: 161 162 return sys.exc_info()[1] 162 163 return None … … 177 178 plugin_log("looking for models in: %s" % str(directory)) 178 179 # compile_file(directory) #always recompile the folder plugin 179 logger.info("plugin model dir: %s" %str(directory))180 logger.info("plugin model dir: %s", str(directory)) 180 181 181 182 plugins = {} … … 192 193 msg += "\nwhile accessing model in %r" % path 193 194 plugin_log(msg) 194 logger.warning("Failed to load plugin %r. See %s for details" 195 % (path, PLUGIN_LOG))195 logger.warning("Failed to load plugin %r. See %s for details", 196 path, PLUGIN_LOG) 196 197 197 198 return plugins … … 230 231 231 232 232 class ModelManagerBase :233 class ModelManagerBase(object): 233 234 """ 234 235 Base class for the model manager … … 265 266 if self.is_changed(): 266 267 return _find_models() 267 logger.info("plugin model : %s" %str(temp))268 logger.info("plugin model : %s", str(temp)) 268 269 return temp 269 270 … … 297 298 for name, plug in self.stored_plugins.iteritems(): 298 299 self.model_dictionary[name] = plug 299 300 300 301 self._get_multifunc_models() 301 302
Note: See TracChangeset
for help on using the changeset viewer.