Changes in / [8ac3551:8289ae3] in sasview
- Files:
-
- 5 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
r948484f r846a063 29 29 default_categories.json 30 30 /setup.cfg 31 **/UI/*.py 32 !**/UI/__init__.py 31 33 32 34 # doc build -
run.py
r4992ff2 r4992ff2 141 141 sys.path.append(build_path) 142 142 143 # Run the UI conversion tool 144 import sas.qtgui.convertUI 145 146 143 147 if __name__ == "__main__": 144 148 # Need to add absolute path before actual prepare call, -
src/sas/qtgui/Perspectives/Inversion/InversionLogic.py
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
re90988c r304e42f 29 29 BACKGROUND_INPUT = 0.0 30 30 MAX_DIST = 140.0 31 32 # TODO: Modify plot references, don't just send new 31 DICT_KEYS = ["Calculator", "PrPlot", "DataPlot", "DMaxWindow", 32 "Logic", "NFuncEst"] 33 34 35 # TODO: Remove not working 36 # TODO: Explore window not working 33 37 # TODO: Update help with batch capabilities 34 38 # TODO: Method to export results in some meaningful way … … 50 54 51 55 self._manager = parent 52 self._model_item = QtGui.QStandardItem()53 56 self.communicate = GuiUtils.Communicate() 54 57 55 58 self.logic = InversionLogic() 56 57 # Reference to Dmax window58 self.dmaxWindow = None59 59 60 60 # The window should not close 61 61 self._allow_close = False 62 62 63 # Visible data set items 63 64 # current QStandardItem showing on the panel 64 65 self._data = None 65 66 # current Data1D as referenced by self._data 66 67 self._data_set = None 67 68 # p(r) calculator 68 # Reference to Dmax window for self._data 69 self.dmaxWindow = None 70 # p(r) calculator for self._data 69 71 self._calculator = Invertor() 70 self._last_calculator = None 72 # Default to background estimate 73 self._calculator.set_est_bck(True) 74 # plots of self._data 75 self.pr_plot = None 76 self.data_plot = None 77 # suggested nTerms 78 self.nTermsSuggested = NUMBER_OF_TERMS 79 80 # Calculation threads used by all data items 71 81 self.calc_thread = None 72 82 self.estimation_thread = None 73 83 74 # Current data object in view 75 self._data_index = 0 76 # list mapping data to p(r) calculation 84 # Mapping for all data items 85 # list mapping data to all parameters 77 86 self._data_list = {} 78 87 if not isinstance(data, list): … … 80 89 if data is not None: 81 90 for datum in data_list: 82 self._data_list[datum] = self._calculator.clone() 83 84 # dict of models for quick update after calculation 85 # {item:model} 86 self._models = {} 87 88 self.calculateAllButton.setEnabled(False) 89 self.calculateThisButton.setEnabled(False) 90 91 # plots for current data 92 self.pr_plot = None 93 self.data_plot = None 94 # plot references for all data in perspective 95 self.pr_plot_list = {} 96 self.data_plot_list = {} 91 self.updateDataList(datum) 92 93 self.enableButtons() 97 94 98 95 self.model = QtGui.QStandardItemModel(self) … … 158 155 159 156 self.backgroundInput.editingFinished.connect( 160 lambda: self._calculator.set_ est_bck(int(is_float(self.backgroundInput.text()))))157 lambda: self._calculator.set_background(is_float(self.backgroundInput.text()))) 161 158 self.minQInput.editingFinished.connect( 162 159 lambda: self._calculator.set_qmin(is_float(self.minQInput.text()))) … … 308 305 309 306 def displayChange(self): 307 """Switch to another item in the data list""" 310 308 ref_item = self.dataList.itemData(self.dataList.currentIndex()) 311 self. _model_item = ref_item309 self.updateDataList(ref_item) 312 310 self.setCurrentData(ref_item) 313 self.setCurrentModel(ref_item) 314 315 def removeData(self): 316 """Remove the existing data reference from the P(r) Persepective""" 317 self._data_list.pop(self._data) 318 self.pr_plot_list.pop(self._data) 319 self.data_plot_list.pop(self._data) 320 if self.dmaxWindow is not None: 321 self.dmaxWindow = None 322 self.dataList.removeItem(self.dataList.currentIndex()) 323 self.dataList.setCurrentIndex(0) 324 # Last file removed 325 if not self._data_list: 326 self._data = None 327 self.pr_plot = None 328 self._data_set = None 329 self.calculateThisButton.setEnabled(False) 330 self.calculateAllButton.setEnabled(False) 331 self.explorerButton.setEnabled(False) 311 self.updateGuiValues() 332 312 333 313 ###################################################################### 334 314 # GUI Interaction Events 335 336 def setCurrentModel(self, ref_item):337 '''update the current model with stored values'''338 if ref_item in self._models:339 self.model = self._models[ref_item]340 315 341 316 def update_calculator(self): … … 355 330 InversionWindow.__init__(self.parent(), list(self._data_list.keys())) 356 331 exit(0) 357 # TODO: Only send plot first time - otherwise, update in complete358 332 if self.pr_plot is not None: 359 333 title = self.pr_plot.name … … 363 337 GuiUtils.updateModelItemWithPlot(self._data, self.data_plot, title) 364 338 if self.dmaxWindow is not None: 365 366 367 339 self.dmaxWindow.pr_state = self._calculator 340 self.dmaxWindow.nfunc = self.getNFunc() 341 self.dmaxWindow.modelChanged() 368 342 self.mapper.toFirst() 369 343 … … 386 360 if sender is self.estimateBgd: 387 361 self.backgroundInput.setEnabled(False) 362 self._calculator.set_est_bck = True 388 363 else: 389 364 self.backgroundInput.setEnabled(True) 365 self._calculator.set_est_bck = False 390 366 391 367 def openExplorerWindow(self): … … 410 386 if not isinstance(data_item, list): 411 387 msg = "Incorrect type passed to the P(r) Perspective" 412 raise AttributeError 388 raise AttributeError(msg) 413 389 414 390 for data in data_item: … … 417 393 return 418 394 # Create initial internal mappings 419 self._data_list[data] = self._calculator.clone()420 395 self._data_set = GuiUtils.dataFromItem(data) 421 self.data_plot_list[data] = self.data_plot 422 self.pr_plot_list[data] = self.pr_plot 396 self.logic = InversionLogic(self._data_set) 423 397 self.populateDataComboBox(self._data_set.filename, data) 398 # Estimate q range 399 qmin, qmax = self.logic.computeDataRange() 400 self._calculator.set_qmin(qmin) 401 self._calculator.set_qmax(qmax) 402 self.updateDataList(data) 424 403 self.setCurrentData(data) 425 426 404 # Estimate initial values from data 427 405 self.performEstimate() 428 self.logic = InversionLogic(self._data_set)429 430 # Estimate q range431 qmin, qmax = self.logic.computeDataRange()432 self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("{:.4g}".format(qmin)))433 self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("{:.4g}".format(qmax)))434 self._models[data] = self.model435 self.model_item = data436 437 406 self.enableButtons() 407 self.updateGuiValues() 408 409 def updateDataList(self, dataRef): 410 """Save the current data state of the window into self._data_list""" 411 if dataRef is None: 412 return 413 self._data_list[dataRef] = { 414 DICT_KEYS[0]: self._calculator, 415 DICT_KEYS[1]: self.pr_plot, 416 DICT_KEYS[2]: self.data_plot, 417 DICT_KEYS[3]: self.dmaxWindow, 418 DICT_KEYS[4]: self.logic, 419 DICT_KEYS[5]: self.nTermsSuggested 420 } 438 421 439 422 def getNFunc(self): … … 448 431 449 432 def setCurrentData(self, data_ref): 450 """Get the current data and display as necessary""" 451 433 """Get the data by reference and display as necessary""" 452 434 if data_ref is None: 453 435 return 454 455 436 if not isinstance(data_ref, QtGui.QStandardItem): 456 437 msg = "Incorrect type passed to the P(r) Perspective" 457 raise AttributeError 458 438 raise AttributeError(msg) 459 439 # Data references 460 440 self._data = data_ref 461 441 self._data_set = GuiUtils.dataFromItem(data_ref) 462 self._calculator = self._data_list[data_ref] 463 self.pr_plot = self.pr_plot_list[data_ref] 464 self.data_plot = self.data_plot_list[data_ref] 442 self._calculator = self._data_list[data_ref].get(DICT_KEYS[0]) 443 self.pr_plot = self._data_list[data_ref].get(DICT_KEYS[1]) 444 self.data_plot = self._data_list[data_ref].get(DICT_KEYS[2]) 445 self.dmaxWindow = self._data_list[data_ref].get(DICT_KEYS[3]) 446 self.logic = self._data_list[data_ref].get(DICT_KEYS[4]) 447 self.nTermsSuggested = self._data_list[data_ref].get(DICT_KEYS[5]) 448 self.updateGuiValues() 449 450 def updateGuiValues(self): 451 pr = self._calculator 452 out = self._calculator.out 453 cov = self._calculator.cov 454 elapsed = self._calculator.elapsed 455 alpha = self._calculator.suggested_alpha 456 nterms = self._calculator.nfunc 457 self.model.setItem(WIDGETS.W_QMIN, 458 QtGui.QStandardItem("{:.4g}".format(pr.get_qmin()))) 459 self.model.setItem(WIDGETS.W_QMAX, 460 QtGui.QStandardItem("{:.4g}".format(pr.get_qmax()))) 461 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, 462 QtGui.QStandardItem("{:.3f}".format(pr.background))) 463 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, 464 QtGui.QStandardItem("{:.3g}".format(pr.background))) 465 self.model.setItem(WIDGETS.W_COMP_TIME, 466 QtGui.QStandardItem("{:.4g}".format(elapsed))) 467 if alpha != 0: 468 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 469 self.regConstantSuggestionButton.setEnabled(alpha != self._calculator.alpha) 470 if nterms != self.nTermsSuggested: 471 self.noOfTermsSuggestionButton.setText( 472 "{:n}".format(self.nTermsSuggested)) 473 self.noOfTermsSuggestionButton.setEnabled(nterms != self.nTermsSuggested) 474 self.model.setItem(WIDGETS.W_COMP_TIME, 475 QtGui.QStandardItem("{:.2g}".format(elapsed))) 476 477 if isinstance(pr.chi2, np.ndarray): 478 self.model.setItem(WIDGETS.W_CHI_SQUARED, 479 QtGui.QStandardItem("{:.3g}".format(pr.chi2[0]))) 480 if out is not None: 481 self.model.setItem(WIDGETS.W_RG, 482 QtGui.QStandardItem("{:.3g}".format(pr.rg(out)))) 483 self.model.setItem(WIDGETS.W_I_ZERO, 484 QtGui.QStandardItem( 485 "{:.3g}".format(pr.iq0(out)))) 486 self.model.setItem(WIDGETS.W_OSCILLATION, QtGui.QStandardItem( 487 "{:.3g}".format(pr.oscillations(out)))) 488 self.model.setItem(WIDGETS.W_POS_FRACTION, QtGui.QStandardItem( 489 "{:.3g}".format(pr.get_positive(out)))) 490 if cov is not None: 491 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, 492 QtGui.QStandardItem( 493 "{:.3g}".format( 494 pr.get_pos_err(out, cov)))) 495 496 def removeData(self): 497 """Remove the existing data reference from the P(r) Persepective""" 498 if self.dmaxWindow is not None: 499 self.dmaxWindow = None 500 self.dataList.removeItem(self.dataList.currentIndex()) 501 self._data_list.pop(self._data) 502 # Last file removed 503 if len(self._data_list) == 0: 504 self._data = None 505 self.pr_plot = None 506 self._data_set = None 507 self._calculator = Invertor() 508 self.logic = InversionLogic() 509 self.enableButtons() 510 self.dataList.setCurrentIndex(0) 511 self.updateGuiValues() 465 512 466 513 ###################################################################### 467 514 # Thread Creators 468 515 def startThreadAll(self): 469 for data_ref, pr in list(self._data_list.items()): 470 self._data_set = GuiUtils.dataFromItem(data_ref) 471 self._calculator = pr 516 for data_ref in self._data_list.keys(): 517 self.setCurrentData(data_ref) 472 518 self.startThread() 473 519 … … 554 600 """ 555 601 alpha, message, elapsed = output_tuple 556 # Save useful info 557 self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem("{:.4g}".format(elapsed))) 558 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 559 self.regConstantSuggestionButton.setEnabled(True) 602 self.updateGuiValues() 560 603 if message: 561 604 logging.info(message) … … 576 619 """ 577 620 nterms, alpha, message, elapsed = output_tuple 621 self._calculator.elapsed = elapsed 622 self._calculator.suggested_alpha = alpha 623 self.nTermsSuggested = nterms 578 624 # Save useful info 579 self.noOfTermsSuggestionButton.setText("{:n}".format(nterms)) 580 self.noOfTermsSuggestionButton.setEnabled(True) 581 self.regConstantSuggestionButton.setText("{:.3g}".format(alpha)) 582 self.regConstantSuggestionButton.setEnabled(True) 583 self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem("{:.2g}".format(elapsed))) 625 self.updateGuiValues() 584 626 if message: 585 627 logging.info(message) … … 605 647 pr.elapsed = elapsed 606 648 607 # Show result on control panel608 self.model.setItem(WIDGETS.W_RG, QtGui.QStandardItem("{:.3g}".format(pr.rg(out))))609 self.model.setItem(WIDGETS.W_I_ZERO, QtGui.QStandardItem("{:.3g}".format(pr.iq0(out))))610 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT,611 QtGui.QStandardItem("{:.3f}".format(pr.est_bck)))612 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, QtGui.QStandardItem("{:.3g}".format(pr.background)))613 self.model.setItem(WIDGETS.W_CHI_SQUARED, QtGui.QStandardItem("{:.3g}".format(pr.chi2[0])))614 self.model.setItem(WIDGETS.W_COMP_TIME, QtGui.QStandardItem("{:.2g}".format(elapsed)))615 self.model.setItem(WIDGETS.W_OSCILLATION, QtGui.QStandardItem("{:.3g}".format(pr.oscillations(out))))616 self.model.setItem(WIDGETS.W_POS_FRACTION, QtGui.QStandardItem("{:.3g}".format(pr.get_positive(out))))617 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION,618 QtGui.QStandardItem("{:.3g}".format(pr.get_pos_err(out, cov))))619 620 649 # Save Pr invertor 621 650 self._calculator = pr 622 # Append data to data list623 self._data_list[self._data] = self._calculator.clone()624 625 # Update model dict626 self._models[self.model_item] = self.model627 651 628 652 # Create new P(r) and fit plots 629 653 if self.pr_plot is None: 630 654 self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 631 self.pr_plot_list[self._data] = self.pr_plot632 else:633 # FIXME: this should update the existing plot, not create a new one634 self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov)635 self.pr_plot_list[self._data] = self.pr_plot636 655 if self.data_plot is None: 637 656 self.data_plot = self.logic.new1DPlot(out, self._calculator) 638 self.data_plot_list[self._data] = self.data_plot 639 else: 640 # FIXME: this should update the existing plot, not create a new one 641 self.data_plot = self.logic.new1DPlot(out, self._calculator) 642 self.data_plot_list[self._data] = self.data_plot 657 self.updateDataList(self._data) 658 self.updateGuiValues() 643 659 644 660 def _threadError(self, error): -
src/sas/qtgui/Perspectives/Inversion/InversionUtils.py
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Perspectives/Inversion/Thread.py
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Perspectives/Inversion/UI/TabbedInversionUI.ui
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Perspectives/Inversion/UI/__init__.py
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Perspectives/Inversion/__init__.py
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Perspectives/__init__.py
- Property mode changed from 100755 to 100644
-
src/sas/qtgui/Plotting/ConvertUnits.py
- Property mode changed from 100644 to 100755
-
src/sas/qtgui/Plotting/DataTransform.py
- Property mode changed from 100644 to 100755
-
src/sas/qtgui/Plotting/Slicers/Arc.py
- Property mode changed from 100644 to 100755
Note: See TracChangeset
for help on using the changeset viewer.