Changeset 919d47c in sasview
- Timestamp:
- Jun 8, 2017 9:11:37 AM (8 years ago)
- Branches:
- 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
- Children:
- 8eaa101
- Parents:
- 70080a0
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r70080a0 r919d47c 44 44 45 45 DEFAULT_POLYDISP_FUNCTION = 'gaussian' 46 47 # Mapping between column index and relevant parameter name extension48 POLY_COL_NAME = 049 POLY_COL_WIDTH = 150 POLY_COL_MIN = 251 POLY_COL_MAX = 352 POLY_COL_NPTS = 453 POLY_COL_NSIGMAS = 554 POLY_COL_FUNCTION = 655 POLY_COLUMN_DICT = {56 POLY_COL_WIDTH: 'width',57 POLY_COL_MIN: 'min',58 POLY_COL_MAX: 'max',59 POLY_COL_NPTS: 'npts',60 POLY_COL_NSIGMAS: 'nsigmas'}61 46 62 47 class FittingWidget(QtGui.QWidget, Ui_FittingWidgetUI): … … 499 484 500 485 # Extract changed value. 501 if model_column == POLY_COL_NAME:486 if model_column == self.lstPoly.itemDelegate().POLY_PARAMETER: 502 487 # Is the parameter checked for fitting? 503 488 value = item.checkState() … … 509 494 self.parameters_to_fit.remove(parameter_name) 510 495 return 511 elif model_column in [ POLY_COL_MIN, POLY_COL_MAX]:496 elif model_column in [self.lstPoly.itemDelegate().POLY_MIN, self.lstPoly.itemDelegate().POLY_MAX]: 512 497 try: 513 498 value = float(item.text()) … … 520 505 current_details = self.kernel_module.details[parameter_name] 521 506 current_details[model_column-1] = value 507 elif model_column == self.lstPoly.itemDelegate().POLY_FUNCTION: 508 # name of the function - just pass 509 return 522 510 else: 523 511 try: … … 526 514 # Can't be converted properly, bring back the old value and exit 527 515 return 528 529 516 property_name = str(self._poly_model.headerData(model_column, 1).toPyObject()).lower() # Value, min, max, etc. 530 # print "%s(%s) => %d" % (parameter_name, property_name, value)531 517 532 518 # Update the sasmodel 533 519 # PD[ratio] -> width, npts -> npts, nsigs -> nsigmas 534 self.kernel_module.setParam(parameter_name + '.' + POLY_COLUMN_DICT[model_column], value) 535 536 # Reload the main model - may not be required if no variable is shown in main view 537 #model = str(self.cbModel.currentText()) 538 #self.SASModelToQModel(model) 539 540 pass # debug anchor 520 self.kernel_module.setParam(parameter_name + '.' + \ 521 self.lstPoly.itemDelegate().POLY_COLUMN_DICT[model_column], value) 541 522 542 523 def onHelp(self): … … 697 678 return 698 679 699 def updateFittedValues(row _i):680 def updateFittedValues(row): 700 681 # Utility function for main model update 701 682 # internal so can use closure for param_dict 702 param_name = str(self._model_model.item(row _i, 0).text())683 param_name = str(self._model_model.item(row, 0).text()) 703 684 if param_name not in param_dict.keys(): 704 685 return 705 686 # modify the param value 706 687 param_repr = GuiUtils.formatNumber(param_dict[param_name][0], high=True) 707 self._model_model.item(row _i, 1).setText(param_repr)688 self._model_model.item(row, 1).setText(param_repr) 708 689 if self.has_error_column: 709 690 error_repr = GuiUtils.formatNumber(param_dict[param_name][1], high=True) 710 self._model_model.item(row_i, 2).setText(error_repr) 711 712 def createErrorColumn(row_i): 691 self._model_model.item(row, 2).setText(error_repr) 692 693 def updatePolyValues(row): 694 # Utility function for updateof polydispersity part of the main model 695 param_name = str(self._model_model.item(row, 0).text())+'.width' 696 if param_name not in param_dict.keys(): 697 return 698 # modify the param value 699 param_repr = GuiUtils.formatNumber(param_dict[param_name][0], high=True) 700 self._model_model.item(row, 0).child(0).child(0,1).setText(param_repr) 701 702 def createErrorColumn(row): 713 703 # Utility function for error column update 714 704 item = QtGui.QStandardItem() 715 for param_name in param_dict.keys(): 716 if str(self._model_model.item(row_i, 0).text()) != param_name: 717 continue 705 def createItem(param_name): 718 706 error_repr = GuiUtils.formatNumber(param_dict[param_name][1], high=True) 719 707 item.setText(error_repr) 708 def curr_param(): 709 return str(self._model_model.item(row, 0).text()) 710 711 [createItem(param_name) for param_name in param_dict.keys() if curr_param() == param_name] 712 720 713 error_column.append(item) 721 714 … … 724 717 self._model_model.blockSignals(True) 725 718 self.iterateOverModel(updateFittedValues) 719 self.iterateOverModel(updatePolyValues) 726 720 self._model_model.blockSignals(False) 727 721 … … 769 763 self._poly_model.item(row_i, 2).setText(error_repr) 770 764 765 771 766 def createErrorColumn(row_i): 772 767 # Utility function for error column update … … 774 769 return 775 770 item = QtGui.QStandardItem() 776 for param_name in param_dict.keys(): 777 if str(self._poly_model.item(row_i, 0).text()).rsplit()[-1] + '.width' != param_name: 778 continue 771 772 def createItem(param_name): 779 773 error_repr = GuiUtils.formatNumber(param_dict[param_name][1], high=True) 780 774 item.setText(error_repr) 775 776 def poly_param(): 777 return str(self._poly_model.item(row_i, 0).text()).rsplit()[-1] + '.width' 778 779 [createItem(param_name) for param_name in param_dict.keys() if poly_param() == param_name] 780 781 781 error_column.append(item) 782 782 … … 786 786 self.iterateOverModel(updateFittedValues) 787 787 self._poly_model.blockSignals(False) 788 789 #return790 788 791 789 if self.has_poly_error_column: … … 798 796 self.lstPoly.itemDelegate().POLY_NSIGS = 6 799 797 self.lstPoly.itemDelegate().POLY_FUNCTION = 7 798 self.lstPoly.itemDelegate().POLY_COLUMN_DICT = { 799 2: 'width', 800 3: 'min', 801 4: 'max', 802 5: 'npts', 803 6: 'nsigmas'} 800 804 801 805 error_column = [] … … 1332 1336 param = self.model_parameters.form_volume_parameters[row_index] 1333 1337 1338 def updateFunctionCaption(row): 1339 # Utility function for update of polydispersity function name in the main model 1340 param_name = str(self._model_model.item(row, 0).text())# +'.width' 1341 if param_name != param.name: 1342 return 1343 # modify the param value 1344 self._model_model.item(row, 0).child(0).child(0,4).setText(combo_string) 1345 1334 1346 if combo_string == 'array': 1335 1347 try: 1336 1348 self.loadPolydispArray() 1349 # Update main model for display 1350 self.iterateOverModel(updateFunctionCaption) 1337 1351 except (ValueError, IOError): 1338 1352 # Don't do anything if file lookup failed … … 1343 1357 1344 1358 # Enable the row in case it was disabled by Array 1345 #[self._poly_model.item(row_index, i).setEnabled(True) for i in xrange(6)] 1346 1347 npts_index = self._poly_model.index(row_index, POLY_COL_NPTS) 1348 nsigs_index = self._poly_model.index(row_index, POLY_COL_NSIGMAS) 1359 self._poly_model.blockSignals(True) 1360 [self._poly_model.item(row_index, i).setEnabled(True) for i in xrange(6)] 1361 self._poly_model.blockSignals(False) 1362 1363 npts_index = self._poly_model.index(row_index, self.lstPoly.itemDelegate().POLY_NPTS) 1364 nsigs_index = self._poly_model.index(row_index, self.lstPoly.itemDelegate().POLY_NSIGS) 1349 1365 1350 1366 npts = POLYDISPERSITY_MODELS[str(combo_string)].default['npts'] … … 1353 1369 self._poly_model.setData(npts_index, QtCore.QVariant(npts)) 1354 1370 self._poly_model.setData(nsigs_index, QtCore.QVariant(nsigs)) 1371 1372 self.iterateOverModel(updateFunctionCaption) 1355 1373 1356 1374 def loadPolydispArray(self): … … 1365 1383 values = [] 1366 1384 weights = [] 1385 def appendData(data_tuple): 1386 """ 1387 Fish out floats from a tuple of strings 1388 """ 1389 try: 1390 values.append(float(data_tuple[0])) 1391 weights.append(float(data_tuple[1])) 1392 except (ValueError, IndexError): 1393 # just pass through if line with bad data 1394 return 1395 1367 1396 with open(datafile, 'r') as column_file: 1368 1397 column_data = [line.rstrip().split() for line in column_file.readlines()] 1369 for line in column_data: 1370 try: 1371 values.append(float(line[0])) 1372 weights.append(float(line[1])) 1373 except (ValueError, IndexError): 1374 # just pass through if line with bad data 1375 pass 1398 [appendData(line) for line in column_data] 1376 1399 1377 1400 self.disp_model = POLYDISPERSITY_MODELS['array']() -
src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py
r06b0138 r919d47c 93 93 POLY_FUNCTION=6 94 94 POLY_EDITABLE_PARAMS = [POLY_MIN, POLY_MAX, POLY_NPTS, POLY_NSIGS] 95 POLY_COLUMN_DICT = { 96 POLY_PD: 'width', 97 POLY_MIN: 'min', 98 POLY_MAX: 'max', 99 POLY_NPTS: 'npts', 100 POLY_NSIGS: 'nsigmas'} 95 101 96 102 combo_updated = QtCore.pyqtSignal(str, int)
Note: See TracChangeset
for help on using the changeset viewer.