Changeset a6fccd7 in sasview for src/sas/sasgui/perspectives/fitting
- Timestamp:
- Dec 21, 2016 8:48:31 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.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- fa487d93
- Parents:
- 9e0aa69a (diff), bb3eb744 (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:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r9e0aa69a ra6fccd7 52 52 FONT_VARIANT = 1 53 53 ON_MAC = True 54 55 54 56 55 class BasicPage(ScrolledPanel, PanelBase): … … 1042 1041 disp_model = POLYDISPERSITY_MODELS['array']() 1043 1042 if hasattr(state, "values") and \ 1044 self.disp_cb_dict[item].GetValue() is True:1043 self.disp_cb_dict[item].GetValue(): 1045 1044 if len(state.values) > 0: 1046 1045 self.values = state.values … … 1451 1450 self.state_change = True 1452 1451 self._draw_model() 1452 # Time delay has been introduced to prevent _handle error 1453 # on Windows 1454 # This part of code is executed when model is selected and 1455 # it's parameters are changed (with respect to previously 1456 # selected model). There are two Iq evaluations occuring one 1457 # after another and therefore there may be compilation error 1458 # if model is calculated for the first time. 1459 # This seems to be Windows only issue - haven't tested on Linux 1460 # though.The proper solution (other than time delay) requires 1461 # more fundemental code refatoring 1462 # Wojtek P. Nov 7, 2016 1463 if not ON_MAC: 1464 time.sleep(0.1) 1453 1465 self.Refresh() 1454 1466 … … 2129 2141 flag = False 2130 2142 else: 2131 self.Npts_fit.SetValue(str(len(index_data[index_data is True])))2143 self.Npts_fit.SetValue(str(len(index_data[index_data]))) 2132 2144 self.fitrange = True 2133 2145 … … 2164 2176 flag = False 2165 2177 else: 2166 val = index_data[index_data is True] 2167 val = len(val) if isinstance(val, list) else 1 2168 self.Npts_fit.SetValue(str(val)) 2178 self.Npts_fit.SetValue(str(len(index_data[index_data]))) 2169 2179 self.fitrange = True 2170 2180 … … 2390 2400 2391 2401 # Redraw the model 2392 self._draw_model() 2402 # Wojtek P. Nov 7, 2016: Redrawing seems to be unnecessary here 2403 # self._draw_model() 2393 2404 # self._undo.Enable(True) 2394 2405 event = PageInfoEvent(page=self) … … 2609 2620 Layout after self._draw_model 2610 2621 """ 2611 if ON_MAC is True:2622 if ON_MAC: 2612 2623 time.sleep(1) 2613 2624 -
src/sas/sasgui/perspectives/fitting/fitpage.py
r77910cf ra6fccd7 81 81 flag = check_data_validity(self.data) & (self.model is not None) 82 82 self.btFit.Enable(flag) 83 83 84 84 def on_set_focus(self, event): 85 85 """ 86 Override the basepage focus method to ensure the save flag is set 86 Override the basepage focus method to ensure the save flag is set 87 87 properly when focusing on the fit page. 88 88 """ … … 238 238 239 239 weighting_set_box = wx.StaticBox(self, wx.ID_ANY, 240 'Set Weighting by Selecting dI Source')240 'Set Weighting by Selecting dI Source') 241 241 weighting_box = wx.StaticBoxSizer(weighting_set_box, wx.HORIZONTAL) 242 242 sizer_weighting = wx.BoxSizer(wx.HORIZONTAL) … … 1164 1164 if event is not None: 1165 1165 if (event.GetEventObject() == self.formfactorbox 1166 1167 1168 1166 and self.structurebox.GetLabel() != 'None')\ 1167 or event.GetEventObject() == self.structurebox\ 1168 or event.GetEventObject() == self.multifactorbox: 1169 1169 copy_flag = self.get_copy_params() 1170 1170 is_poly_enabled = self.enable_disp.GetValue() … … 1206 1206 self._keep.Enable(not self.batch_on) 1207 1207 self._set_save_flag(True) 1208 self._set_smear(self.data) 1208 #Setting smearing for cases with and without data. 1209 self._set_smear(self.data) 1209 1210 1210 1211 # more disables for 2D … … 1213 1214 try: 1214 1215 # update smearer sizer 1215 self.onSmear(None) 1216 #This call for smearing set up caused double evaluation of 1217 #I(q) and double compilation as results 1218 #self.onSmear(None) 1216 1219 temp_smear = None 1217 1220 if not self.disable_smearer.GetValue(): … … 1227 1230 # set smearing value whether or not data contain the smearing info 1228 1231 evt = ModelEventbox(model=self.model, 1229 smearer=temp_smear,1230 enable_smearer=not self.disable_smearer.GetValue(),1231 qmin=float(self.qmin_x),1232 uid=self.uid,1233 caption=self.window_caption,1234 qmax=float(self.qmax_x))1232 smearer=temp_smear, 1233 enable_smearer=not self.disable_smearer.GetValue(), 1234 qmin=float(self.qmin_x), 1235 uid=self.uid, 1236 caption=self.window_caption, 1237 qmax=float(self.qmax_x)) 1235 1238 1236 1239 self._manager._on_model_panel(evt=evt) … … 1616 1619 return 1617 1620 # check if it is pinhole smear and get min max if it is. 1618 if data.dx is not None and n ot numpy.any(data.dx):1621 if data.dx is not None and numpy.any(data.dx): 1619 1622 self.smear_type = "Pinhole" 1620 1623 self.dq_l = data.dx[0] -
src/sas/sasgui/perspectives/fitting/fitting.py
r1a5d5f2 r06a4306 864 864 enable1D=enable1D, enable2D=enable2D, 865 865 qmin=qmin, qmax=qmax, weight=weight) 866 self._mac_sleep(0.2)867 866 868 867 def _mac_sleep(self, sec=0.2): … … 1964 1963 ## May need rethinking 1965 1964 ## 1966 ## -PDB August 12, 2014 1965 ## -PDB August 12, 2014 1967 1966 while self.calc_1D.isrunning(): 1968 1967 time.sleep(0.1) -
src/sas/sasgui/perspectives/fitting/model_thread.py
r286c757 rd3911e3 82 82 fn.set_model(self.model) 83 83 fn.set_index(index_model) 84 # Get necessary data from self.data and set the data for smearing85 fn.get_data()86 84 # Calculate smeared Intensity 87 85 #(by Gaussian averaging): DataLoader/smearing2d/Smearer2D() … … 89 87 else: 90 88 # calculation w/o smearing 91 value = self.model.evalDistribution(\ 92 [self.data.qx_data[index_model], 93 self.data.qy_data[index_model]]) 89 value = self.model.evalDistribution([ 90 self.data.qx_data[index_model], 91 self.data.qy_data[index_model] 92 ]) 94 93 output = numpy.zeros(len(self.data.qx_data)) 95 94 # output default is None -
src/sas/sasgui/perspectives/fitting/models.py
r313c5c9 r0de74af 23 23 PLUGIN_LOG = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR, 24 24 "plugins.log") 25 PLUGIN_NAME_BASE = '[plug-in] ' 25 26 26 27 def get_model_python_path(): … … 181 182 try: 182 183 model = load_custom_model(path) 183 model.name = "[plug-in] "+model.name184 model.name = PLUGIN_NAME_BASE + model.name 184 185 plugins[model.name] = model 185 186 except Exception: -
src/sas/sasgui/perspectives/fitting/pagestate.py
rc8e1996 r9e0aa69a 25 25 from lxml import etree 26 26 27 from sasmodels import convert 27 28 import sasmodels.weights 28 29 … … 271 272 # store value of chisqr 272 273 self.tcChi = None 274 self.version = (1,0,0) 273 275 274 276 def clone(self): … … 355 357 obj.saved_states[copy_name] = copy_state 356 358 return obj 359 360 def _old_first_model(self): 361 """ 362 Handle save states from 4.0.1 and before where the first item in the 363 selection boxes of category, formfactor and structurefactor were not 364 saved. 365 :return: None 366 """ 367 if self.formfactorcombobox == '': 368 if self.categorycombobox == '' and len(self.parameters) == 3: 369 self.categorycombobox = "Shape-Independent" 370 self.formfactorcombobox = 'PowerLawAbsModel' 371 elif self.categorycombobox == '' and len(self.parameters) == 9: 372 self.categorycombobox = 'Cylinder' 373 self.formfactorcombobox = 'barbell' 374 elif self.categorycombobox == 'Shapes': 375 self.formfactorcombobox = 'BCCrystalModel' 376 elif self.categorycombobox == 'Uncategorized': 377 self.formfactorcombobox = 'LineModel' 378 elif self.categorycombobox == 'StructureFactor': 379 self.structurecombobox = 'HardsphereStructure' 380 elif self.categorycombobox == 'Customized Models': 381 self.formfactorcombobox = 'MySumFunction' 382 elif self.categorycombobox == 'Ellipsoid': 383 self.formfactorcombobox = 'core_shell_ellipsoid' 384 elif self.categorycombobox == 'Lamellae': 385 self.formfactorcombobox = 'lamellar' 386 elif self.categorycombobox == 'Paracrystal': 387 self.formfactorcombobox = 'bcc_paracrystal' 388 elif self.categorycombobox == 'Parallelepiped': 389 self.formfactorcombobox = 'core_shell_parallelepiped' 390 elif self.categorycombobox == 'Shape Independent': 391 self.formfactorcombobox = 'be_polyelectrolyte' 392 elif self.categorycombobox == 'Sphere': 393 self.formfactorcombobox = 'adsorbed_layer' 394 elif self.categorycombobox == 'Structure Factor': 395 self.formfactorcombobox = 'hardsphere' 396 397 @staticmethod 398 def param_remap_to_sasmodels_convert(params, is_string=False): 399 """ 400 Remaps the parameters for sasmodels conversion 401 402 :param params: list of parameters (likely self.parameters) 403 :return: remapped dictionary of parameters 404 """ 405 p = dict() 406 for fittable, name, value, _, uncert, lower, upper, units in params: 407 if not value: 408 value = numpy.nan 409 if not uncert or uncert[1] == '' or uncert[1] == 'None': 410 uncert[0] = False 411 uncert[1] = numpy.nan 412 if not upper or upper[1] == '' or upper[1] == 'None': 413 upper[0] = False 414 upper[1] = numpy.nan 415 if not lower or lower[1] == '' or lower[1] == 'None': 416 lower[0] = False 417 lower[1] = numpy.nan 418 if is_string: 419 p[name] = str(value) 420 else: 421 p[name] = float(value) 422 p[name + ".fittable"] = bool(fittable) 423 p[name + ".std"] = float(uncert[1]) 424 p[name + ".upper"] = float(upper[1]) 425 p[name + ".lower"] = float(lower[1]) 426 p[name + ".units"] = units 427 return p 428 429 @staticmethod 430 def param_remap_from_sasmodels_convert(params): 431 """ 432 Converts {name : value} map back to [] param list 433 :param params: parameter map returned from sasmodels 434 :return: None 435 """ 436 p_map = [] 437 for name, info in params.iteritems(): 438 if ".fittable" in name or ".std" in name or ".upper" in name or \ 439 ".lower" in name or ".units" in name: 440 pass 441 else: 442 fittable = params.get(name + ".fittable", True) 443 std = params.get(name + ".std", '0.0') 444 upper = params.get(name + ".upper", 'inf') 445 lower = params.get(name + ".lower", '-inf') 446 units = params.get(name + ".units") 447 if std is not None and std is not numpy.nan: 448 std = [True, str(std)] 449 else: 450 std = [False, ''] 451 if lower is not None and lower is not numpy.nan: 452 lower = [True, str(lower)] 453 else: 454 lower = [True, '-inf'] 455 if upper is not None and upper is not numpy.nan: 456 upper = [True, str(upper)] 457 else: 458 upper = [True, 'inf'] 459 param_list = [bool(fittable), str(name), str(info), 460 "+/-", std, lower, upper, str(units)] 461 p_map.append(param_list) 462 return p_map 463 464 def _convert_to_sasmodels(self): 465 """ 466 Convert parameters to a form usable by sasmodels converter 467 468 :return: None 469 """ 470 # Create conversion dictionary to send to sasmodels 471 self._old_first_model() 472 p = self.param_remap_to_sasmodels_convert(self.parameters) 473 structurefactor, params = convert.convert_model(self.structurecombobox, 474 p, False, self.version) 475 formfactor, params = convert.convert_model(self.formfactorcombobox, 476 params, False, self.version) 477 if len(self.str_parameters) > 0: 478 str_pars = self.param_remap_to_sasmodels_convert( 479 self.str_parameters, True) 480 formfactor, str_params = convert.convert_model( 481 self.formfactorcombobox, str_pars) 482 for key, value in str_params.iteritems(): 483 params[key] = value 484 485 # Only convert if old != new, otherwise all the same 486 if formfactor != self.formfactorcombobox or \ 487 structurefactor != self.structurecombobox: 488 # Spherical SLD number of layers changed between 3.1.2 and 4.0 489 if self.formfactorcombobox == 'SphericalSLDModel': 490 self.multi_factor += 1 491 self.formfactorcombobox = formfactor 492 self.structurecombobox = structurefactor 493 self.parameters = [] 494 self.parameters = self.param_remap_from_sasmodels_convert(params) 357 495 358 496 def _repr_helper(self, list, rep): … … 682 820 683 821 attr = newdoc.createAttribute("version") 684 attr.nodeValue = '1.0' 822 import sasview 823 attr.nodeValue = sasview.__version__ 824 # attr.nodeValue = '1.0' 685 825 top_element.setAttributeNode(attr) 686 826 … … 875 1015 raise RuntimeError, msg 876 1016 877 if node.get('version') and node.get('version') == '1.0': 878 1017 if node.get('version'): 1018 1019 self.version = tuple(int(e) for e in 1020 str.split(node.get('version'), ".")) 879 1021 # Get file name 880 1022 entry = get_content('ns:filename', node)
Note: See TracChangeset
for help on using the changeset viewer.