Changeset e51e078 in sasview
- Timestamp:
- Mar 22, 2018 5:02:08 PM (7 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:
- 304e42f
- Parents:
- 47bf906
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r47bf906 re51e078 30 30 MAX_DIST = 140.0 31 31 DICT_KEYS = ["Calculator", "PrPlot", "DataPlot", "DMaxWindow", 32 "Logic", "NFunc", "Estimates"] 33 ESTIMATE_KEYS = ["nFunc", "??????", "Background"] 34 35 36 # TODO: Modify plot references, don't just send new 32 "Logic", "NFunc", "NFuncEst", "BackgroundEst"] 33 34 37 35 # TODO: Update help with batch capabilities 38 36 # TODO: Method to export results in some meaningful way … … 70 68 # p(r) calculator for self._data 71 69 self._calculator = Invertor() 72 # Combo box index for self._data73 self._data_index = 074 70 # plots of self._data 75 71 self.pr_plot = None 76 72 self.data_plot = None 73 # suggested nTerms 74 self.nTermsSuggested = NUMBER_OF_TERMS 77 75 78 76 # Calculation threads used by all data items … … 81 79 82 80 # Mapping for all data items 83 # TODO: {QStandardItem -> {params: [], plot: Plot, dmax: dMax,84 # TODO: calculator: Invertor(), estimates: {}, data: Data1D, ...}85 81 # list mapping data to all parameters 86 82 self._data_list = {} … … 89 85 if data is not None: 90 86 for datum in data_list: 91 self._data_list[datum] = {DICT_KEYS[0]: self._calculator.clone(), 92 DICT_KEYS[4]: self.logic, 93 DICT_KEYS[5]: NUMBER_OF_TERMS, 94 DICT_KEYS[6]: {}} 95 96 self.calculateAllButton.setEnabled(False) 97 self.calculateThisButton.setEnabled(False) 87 self.updateDataList(datum) 88 89 self.enableButtons() 98 90 99 91 self.model = QtGui.QStandardItemModel(self) … … 311 303 """Switch to another item in the data list""" 312 304 ref_item = self.dataList.itemData(self.dataList.currentIndex()) 313 self.updateDataList( self._data)305 self.updateDataList(ref_item) 314 306 self.setCurrentData(ref_item) 315 307 … … 397 389 self.logic = InversionLogic(self._data_set) 398 390 self.populateDataComboBox(self._data_set.filename, data) 391 # Estimate q range 392 qmin, qmax = self.logic.computeDataRange() 393 self._calculator.set_qmin(qmin) 394 self._calculator.set_qmax(qmax) 395 self.updateDataList(data) 399 396 self.setCurrentData(data) 400 401 397 # Estimate initial values from data 402 398 self.performEstimate() 403 404 # Estimate q range405 qmin, qmax = self.logic.computeDataRange()406 self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("{:.4g}".format(qmin)))407 self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("{:.4g}".format(qmax)))408 self._data_list[data] = {DICT_KEYS[0]: self._calculator.clone(),409 DICT_KEYS[1]: self.data_plot,410 DICT_KEYS[2]: self.pr_plot,411 DICT_KEYS[4]: self.logic}412 399 self.enableButtons() 413 400 414 401 def updateDataList(self, dataRef): 415 402 """Save the current data state of the window into self._data_list""" 403 if dataRef is None: 404 return 416 405 self._data_list[dataRef] = { 417 DICT_KEYS[0]: self._calculator, 418 DICT_KEYS[1]: self.pr_plot, 419 DICT_KEYS[2]: self.data_plot, 420 DICT_KEYS[3]: self.dmaxWindow 406 DICT_KEYS[0]: self._calculator, 407 DICT_KEYS[1]: self.pr_plot, 408 DICT_KEYS[2]: self.data_plot, 409 DICT_KEYS[3]: self.dmaxWindow, 410 DICT_KEYS[4]: self.logic, 411 DICT_KEYS[5]: self.getNFunc(), 412 DICT_KEYS[6]: self.nTermsSuggested, 413 DICT_KEYS[7]: self.backgroundInput.text() 421 414 } 422 415 … … 433 426 def setCurrentData(self, data_ref): 434 427 """Get the data by reference and display as necessary""" 435 if data_ref is None:436 return437 428 if not isinstance(data_ref, QtGui.QStandardItem): 438 429 msg = "Incorrect type passed to the P(r) Perspective" 439 raise AttributeError 430 raise AttributeError(msg) 440 431 # Data references 441 432 self._data = data_ref … … 446 437 self.dmaxWindow = self._data_list[data_ref].get(DICT_KEYS[3]) 447 438 self.logic = self._data_list[data_ref].get(DICT_KEYS[4]) 448 # TODO: Do the values need to be updated when _calculator is changed? 439 self.updateGuiValues() 440 441 def updateGuiValues(self): 442 pr = self._calculator 443 out = self._calculator.out 444 cov = self._calculator.cov 445 elapsed = self._calculator.elapsed 446 alpha = self._calculator.suggested_alpha 447 nterms = self._calculator.nfunc 448 self.model.setItem(WIDGETS.W_QMIN, 449 QtGui.QStandardItem("{:.4g}".format(pr.get_qmin()))) 450 self.model.setItem(WIDGETS.W_QMAX, 451 QtGui.QStandardItem("{:.4g}".format(pr.get_qmax()))) 452 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, 453 QtGui.QStandardItem("{:.3f}".format(pr.est_bck))) 454 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, 455 QtGui.QStandardItem("{:.3g}".format(pr.background))) 456 self.model.setItem(WIDGETS.W_COMP_TIME, 457 QtGui.QStandardItem("{:.4g}".format(elapsed))) 458 if alpha != 0: 459 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 460 self.regConstantSuggestionButton.setEnabled(alpha != 0) 461 if nterms != self.nTermsSuggested: 462 self.noOfTermsSuggestionButton.setText( 463 "{:n}".format(self.nTermsSuggested)) 464 self.noOfTermsSuggestionButton.setEnabled(nterms != self.nTermsSuggested) 465 self.model.setItem(WIDGETS.W_COMP_TIME, 466 QtGui.QStandardItem("{:.2g}".format(elapsed))) 467 468 if isinstance(pr.chi2, list): 469 self.model.setItem(WIDGETS.W_CHI_SQUARED, 470 QtGui.QStandardItem("{:.3g}".format(pr.chi2[0]))) 471 if out is not None: 472 self.model.setItem(WIDGETS.W_RG, 473 QtGui.QStandardItem("{:.3g}".format(pr.rg(out)))) 474 self.model.setItem(WIDGETS.W_I_ZERO, 475 QtGui.QStandardItem( 476 "{:.3g}".format(pr.iq0(out)))) 477 self.model.setItem(WIDGETS.W_OSCILLATION, QtGui.QStandardItem( 478 "{:.3g}".format(pr.oscillations(out)))) 479 self.model.setItem(WIDGETS.W_POS_FRACTION, QtGui.QStandardItem( 480 "{:.3g}".format(pr.get_positive(out)))) 481 if cov is not None: 482 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, 483 QtGui.QStandardItem( 484 "{:.3g}".format( 485 pr.get_pos_err(out, cov)))) 449 486 450 487 def removeData(self): … … 453 490 self.dmaxWindow = None 454 491 self.dataList.removeItem(self.dataList.currentIndex()) 455 # TODO: Remove plot references from higher level too? 456 self.dataList.setCurrentIndex(0) 492 self._data_list.pop(self._data) 457 493 # Last file removed 458 self._data_list.pop(self._data) 459 if not self._data_list: 494 if len(self._data_list) == 0: 460 495 self._data = None 461 496 self.pr_plot = None 462 497 self._data_set = None 498 self._calculator = Invertor() 463 499 self.logic = InversionLogic() 464 500 self.enableButtons() 465 self.d isplayChange()501 self.dataList.setCurrentIndex(0) 466 502 467 503 ###################################################################### 468 504 # Thread Creators 469 505 def startThreadAll(self): 470 for data_ref, pr in list(self._data_list.items()): 471 self._data_set = GuiUtils.dataFromItem(data_ref) 472 self._calculator = pr 506 for data_ref in self._data_list.keys(): 507 self.setCurrentData(data_ref) 473 508 self.startThread() 474 509 … … 556 591 alpha, message, elapsed = output_tuple 557 592 # Save useful info 558 self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem("{:.4g}".format(elapsed))) 559 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 560 self.regConstantSuggestionButton.setEnabled(True) 593 self.updateGuiValues() 561 594 if message: 562 595 logging.info(message) … … 576 609 :param elapsed: computation time 577 610 """ 578 # TODO: Add estimates to DICT_KEYS579 611 nterms, alpha, message, elapsed = output_tuple 612 self._calculator.elapsed = elapsed 613 self._calculator.suggested_alpha = alpha 614 self.nTermsSuggested = nterms 580 615 # Save useful info 581 self.noOfTermsSuggestionButton.setText("{:n}".format(nterms)) 582 self.noOfTermsSuggestionButton.setEnabled(True) 583 self.regConstantSuggestionButton.setText("{:.3g}".format(alpha)) 584 self.regConstantSuggestionButton.setEnabled(True) 585 self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem("{:.2g}".format(elapsed))) 616 self.updateGuiValues() 586 617 if message: 587 618 logging.info(message) … … 607 638 pr.elapsed = elapsed 608 639 609 # Show result on control panel610 self.model.setItem(WIDGETS.W_RG, QtGui.QStandardItem("{:.3g}".format(pr.rg(out))))611 self.model.setItem(WIDGETS.W_I_ZERO, QtGui.QStandardItem("{:.3g}".format(pr.iq0(out))))612 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT,613 QtGui.QStandardItem("{:.3f}".format(pr.est_bck)))614 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, QtGui.QStandardItem("{:.3g}".format(pr.background)))615 self.model.setItem(WIDGETS.W_CHI_SQUARED, QtGui.QStandardItem("{:.3g}".format(pr.chi2[0])))616 self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem("{:.2g}".format(elapsed)))617 self.model.setItem(WIDGETS.W_OSCILLATION, QtGui.QStandardItem("{:.3g}".format(pr.oscillations(out))))618 self.model.setItem(WIDGETS.W_POS_FRACTION, QtGui.QStandardItem("{:.3g}".format(pr.get_positive(out))))619 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION,620 QtGui.QStandardItem("{:.3g}".format(pr.get_pos_err(out, cov))))621 622 640 # Save Pr invertor 623 641 self._calculator = pr 624 # Append data to data list625 self._data_list[self._data][DICT_KEYS[0]] = self._calculator.clone()626 642 627 643 # Create new P(r) and fit plots 628 644 if self.pr_plot is None: 629 645 self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 630 self._data_list[self._data][DICT_KEYS[1]] = self.pr_plot631 646 else: 632 # FIXME: this should update the existing plot, not create a new one 633 self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 634 self._data_list[self._data][DICT_KEYS[1]] = self.pr_plot 647 title = self.pr_plot.name 648 GuiUtils.updateModelItemWithPlot(self._data, self.pr_plot, title) 635 649 if self.data_plot is None: 636 650 self.data_plot = self.logic.new1DPlot(out, self._calculator) 637 self._data_list[self._data][DICT_KEYS[2]] = self.data_plot638 651 else: 639 # FIXME: this should update the existing plot, not create a new one 640 self.data_plot = self.logic.new1DPlot(out, self._calculator) 641 self._data_list[self._data][DICT_KEYS[2]] = self.data_plot 652 title = self.data_plot.name 653 GuiUtils.updateModelItemWithPlot(self._data, self.data_plot, title) 654 self.updateDataList(self._data) 655 self.updateGuiValues() 642 656 643 657 def _threadError(self, error):
Note: See TracChangeset
for help on using the changeset viewer.