Changeset ae34d30 in sasview
- Timestamp:
- Apr 17, 2018 1:41:24 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:
- 5a5e371
- Parents:
- 98485fe
- Location:
- src/sas/qtgui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/DMaxExplorerWidget.py
rf4480f0 rae34d30 42 42 super(DmaxWindow, self).__init__() 43 43 self.setupUi(self) 44 self.parent = parent 44 45 45 46 self.setWindowTitle("Dââ Explorer") … … 188 189 data._yunit = y_unit 189 190 self.plot.plot(data=data, marker="-") 191 192 def closeEvent(self, event): 193 """Override close event""" 194 self.parent.dmaxWindow = None 195 event.accept() -
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r98485fe rae34d30 1 import sys2 1 import logging 3 import pylab4 2 import numpy as np 5 3 … … 16 14 # pr inversion calculation elements 17 15 from sas.sascalc.pr.invertor import Invertor 18 19 16 # Batch calculation display 20 17 from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel … … 60 57 61 58 # The window should not close 62 self._allow _close = False63 64 # Visible data setitems59 self._allowClose = False 60 61 # Visible data items 65 62 # current QStandardItem showing on the panel 66 63 self._data = None … … 72 69 self._calculator.est_bck = True 73 70 # plots of self._data 74 self.pr _plot = None75 self.data _plot = None71 self.prPlot = None 72 self.dataPlot = None 76 73 # suggested nTerms 77 74 self.nTermsSuggested = NUMBER_OF_TERMS 78 75 79 76 # Calculation threads used by all data items 80 self.isBatch = False 81 self.calc_thread = None 82 self.estimation_thread = None 83 self.estimation_thread_nt = None 77 self.calcThread = None 78 self.estimationThread = None 79 self.estimationThreadNT = None 84 80 85 81 # Mapping for all data items 86 # listmapping data to all parameters87 self._data _list = {}82 # Dictionary mapping data to all parameters 83 self._dataList = {} 88 84 if not isinstance(data, list): 89 85 data_list = [data] … … 97 93 self.mapper = QtWidgets.QDataWidgetMapper(self) 98 94 99 # Batch fitting results 100 self.grid_window = None 95 # Batch fitting parameters 96 self.isBatch = False 97 self.batchResultsWindow = None 101 98 self.batchResults = {} 102 99 self.batchComplete = [] … … 127 124 """ 128 125 assert isinstance(value, bool) 129 self._allow _close = value126 self._allowClose = value 130 127 131 128 def closeEvent(self, event): … … 133 130 Overwrite QDialog close method to allow for custom widget close 134 131 """ 135 if self._allow_close: 132 # Close report widgets before closing/minimizing main widget 133 self.closeDMax() 134 self.closeBatchResults() 135 if self._allowClose: 136 136 # reset the closability flag 137 137 self.setClosable(value=False) … … 143 143 # Maybe we should just minimize 144 144 self.setWindowState(QtCore.Qt.WindowMinimized) 145 146 def closeDMax(self): 147 if self.dmaxWindow is not None: 148 self.dmaxWindow.close() 149 150 def closeBatchResults(self): 151 if self.batchResultsWindow is not None: 152 self.batchResultsWindow.close() 145 153 146 154 ###################################################################### … … 230 238 Update boxes with initial values 231 239 """ 232 item = QtGui.QStandardItem(str(BACKGROUND_INPUT)) 233 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, item) 234 item = QtGui.QStandardItem("") 235 self.model.setItem(WIDGETS.W_QMIN, item) 236 item = QtGui.QStandardItem("") 237 self.model.setItem(WIDGETS.W_QMAX, item) 238 item = QtGui.QStandardItem("") 239 self.model.setItem(WIDGETS.W_SLIT_WIDTH, item) 240 item = QtGui.QStandardItem("") 241 self.model.setItem(WIDGETS.W_SLIT_HEIGHT, item) 242 item = QtGui.QStandardItem(str(NUMBER_OF_TERMS)) 243 self.model.setItem(WIDGETS.W_NO_TERMS, item) 244 item = QtGui.QStandardItem(str(REGULARIZATION)) 245 self.model.setItem(WIDGETS.W_REGULARIZATION, item) 246 item = QtGui.QStandardItem(str(MAX_DIST)) 247 self.model.setItem(WIDGETS.W_MAX_DIST, item) 248 item = QtGui.QStandardItem("") 249 self.model.setItem(WIDGETS.W_RG, item) 250 item = QtGui.QStandardItem("") 251 self.model.setItem(WIDGETS.W_I_ZERO, item) 252 item = QtGui.QStandardItem("") 253 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, item) 254 item = QtGui.QStandardItem("") 255 self.model.setItem(WIDGETS.W_COMP_TIME, item) 256 item = QtGui.QStandardItem("") 257 self.model.setItem(WIDGETS.W_CHI_SQUARED, item) 258 item = QtGui.QStandardItem("") 259 self.model.setItem(WIDGETS.W_OSCILLATION, item) 260 item = QtGui.QStandardItem("") 261 self.model.setItem(WIDGETS.W_POS_FRACTION, item) 262 item = QtGui.QStandardItem("") 263 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, item) 240 blank_item = QtGui.QStandardItem("") 241 no_terms_item = QtGui.QStandardItem(str(NUMBER_OF_TERMS)) 242 bgd_item = QtGui.QStandardItem(str(BACKGROUND_INPUT)) 243 reg_item = QtGui.QStandardItem(str(REGULARIZATION)) 244 max_dist_item = QtGui.QStandardItem(str(MAX_DIST)) 245 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, bgd_item) 246 self.model.setItem(WIDGETS.W_QMIN, blank_item) 247 self.model.setItem(WIDGETS.W_QMAX, blank_item) 248 self.model.setItem(WIDGETS.W_SLIT_WIDTH, blank_item) 249 self.model.setItem(WIDGETS.W_SLIT_HEIGHT, blank_item) 250 self.model.setItem(WIDGETS.W_NO_TERMS, no_terms_item) 251 self.model.setItem(WIDGETS.W_REGULARIZATION, reg_item) 252 self.model.setItem(WIDGETS.W_MAX_DIST, max_dist_item) 253 self.model.setItem(WIDGETS.W_RG, blank_item) 254 self.model.setItem(WIDGETS.W_I_ZERO, blank_item) 255 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, bgd_item) 256 self.model.setItem(WIDGETS.W_COMP_TIME, blank_item) 257 self.model.setItem(WIDGETS.W_CHI_SQUARED, blank_item) 258 self.model.setItem(WIDGETS.W_OSCILLATION, blank_item) 259 self.model.setItem(WIDGETS.W_POS_FRACTION, blank_item) 260 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, blank_item) 264 261 265 262 def setupWindow(self): … … 285 282 Enable buttons when data is present, else disable them 286 283 """ 287 self.calculateAllButton.setEnabled(len(self._data_list) > 1) 288 self.calculateThisButton.setEnabled(self.logic.data_is_loaded) 284 self.calculateAllButton.setEnabled(len(self._dataList) > 1 285 and not self.isBatch) 286 self.calculateThisButton.setEnabled(self.logic.data_is_loaded 287 and not self.isBatch) 289 288 self.removeButton.setEnabled(self.logic.data_is_loaded) 290 289 self.explorerButton.setEnabled(self.logic.data_is_loaded) … … 320 319 # GUI Interaction Events 321 320 322 def update _calculator(self):321 def updateCalculator(self): 323 322 """Update all p(r) params""" 324 323 self._calculator.set_x(self.logic.data.x) … … 338 337 self.setClosable(True) 339 338 self.close() 340 InversionWindow.__init__(self.parent(), list(self._data _list.keys()))339 InversionWindow.__init__(self.parent(), list(self._dataList.keys())) 341 340 exit(0) 342 341 if self.dmaxWindow is not None: … … 384 383 :param output_data: Dictionary mapping filename -> P(r) instance 385 384 """ 386 if self. grid_window is None:387 self. grid_window = BatchInversionOutputPanel(385 if self.batchResultsWindow is None: 386 self.batchResultsWindow = BatchInversionOutputPanel( 388 387 parent=self, output_data=self.batchResults) 389 388 else: 390 self. grid_window.setupTable(self.batchResults)391 self. grid_window.show()389 self.batchResultsWindow.setupTable(self.batchResults) 390 self.batchResultsWindow.show() 392 391 393 392 ###################################################################### … … 407 406 408 407 for data in data_item: 409 if data in self._data _list.keys():408 if data in self._dataList.keys(): 410 409 # Don't add data if it's already in 411 410 continue … … 425 424 if dataRef is None: 426 425 return 427 self._data _list[dataRef] = {426 self._dataList[dataRef] = { 428 427 DICT_KEYS[0]: self._calculator, 429 DICT_KEYS[1]: self.pr _plot,430 DICT_KEYS[2]: self.data _plot428 DICT_KEYS[1]: self.prPlot, 429 DICT_KEYS[2]: self.dataPlot 431 430 } 432 431 # Update batch results window when finished 433 432 self.batchResults[self.logic.data.filename] = self._calculator 434 if self. grid_window is not None:433 if self.batchResultsWindow is not None: 435 434 self.showBatchOutput() 436 435 … … 456 455 self._data = data_ref 457 456 self.logic.data = GuiUtils.dataFromItem(data_ref) 458 self._calculator = self._data _list[data_ref].get(DICT_KEYS[0])459 self.pr _plot = self._data_list[data_ref].get(DICT_KEYS[1])460 self.data _plot = self._data_list[data_ref].get(DICT_KEYS[2])457 self._calculator = self._dataList[data_ref].get(DICT_KEYS[0]) 458 self.prPlot = self._dataList[data_ref].get(DICT_KEYS[1]) 459 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 461 460 self.performEstimate() 462 461 … … 477 476 self.model.setItem(WIDGETS.W_COMP_TIME, 478 477 QtGui.QStandardItem("{:.4g}".format(elapsed))) 478 self.model.setItem(WIDGETS.W_MAX_DIST, 479 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 479 480 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 480 481 self.noOfTermsSuggestionButton.setText( 481 482 "{:n}".format(self.nTermsSuggested)) 482 self.model.setItem(WIDGETS.W_COMP_TIME,483 QtGui.QStandardItem("{:.2g}".format(elapsed)))484 483 485 484 if isinstance(pr.chi2, np.ndarray): … … 501 500 "{:.3g}".format( 502 501 pr.get_pos_err(out, cov)))) 503 if self.pr _plot is not None:504 title = self.pr _plot.name505 GuiUtils.updateModelItemWithPlot(self._data, self.pr _plot, title)506 self.communicate.plotRequestedSignal.emit([self.pr _plot])507 if self.data _plot is not None:508 title = self.data _plot.name509 GuiUtils.updateModelItemWithPlot(self._data, self.data _plot, title)502 if self.prPlot is not None: 503 title = self.prPlot.name 504 GuiUtils.updateModelItemWithPlot(self._data, self.prPlot, title) 505 self.communicate.plotRequestedSignal.emit([self.prPlot]) 506 if self.dataPlot is not None: 507 title = self.dataPlot.name 508 GuiUtils.updateModelItemWithPlot(self._data, self.dataPlot, title) 510 509 self.communicate.plotRequestedSignal.emit( 511 [self.data _plot, self.logic.data])510 [self.dataPlot, self.logic.data]) 512 511 self.enableButtons() 513 512 514 513 def removeData(self, data_list=None): 515 514 """Remove the existing data reference from the P(r) Persepective""" 516 if self.dmaxWindow is not None:517 self.dmaxWindow.close()518 self.dmaxWindow = None519 if self.grid_window is not None:520 self.grid_window.close()521 515 if not data_list: 522 516 data_list = [self._data] 517 self.closeDMax() 523 518 for data in data_list: 524 self._data_list.pop(data) 519 self._dataList.pop(data) 520 data_file = GuiUtils.dataFromItem(data) 521 self.batchResults.pop(data_file.filename) 525 522 self._data = None 526 523 for index in range(0, len(self.dataList)): … … 528 525 self.dataList.removeItem(index) 529 526 # Last file removed 530 if len(self._data _list) == 0:531 self. _data= None532 self. pr_plot = None533 self. data_plot= None527 if len(self._dataList) == 0: 528 self.prPlot = None 529 self.dataPlot = None 530 self.logic.data = None 534 531 self._calculator = Invertor() 535 self. logic.data = None532 self.closeBatchResults() 536 533 self.nTermsSuggested = NUMBER_OF_TERMS 537 534 self.noOfTermsSuggestionButton.setText("{:n}".format( … … 549 546 550 547 def startThreadAll(self): 548 self.calculateAllButton.setText("Calculating...") 551 549 self.batchComplete = [] 552 550 self.isBatch = True … … 556 554 def startNextBatchItem(self): 557 555 self.isBatch = False 558 for index in range(len(self._data _list)):556 for index in range(len(self._dataList)): 559 557 if index not in self.batchComplete: 560 558 self.dataList.setCurrentIndex(index) 561 559 self.isBatch = True 562 560 break 563 # If none left, end564 561 if self.isBatch: 565 562 self.performEstimate() 563 else: 564 # If no data sets left, end batch calculation 565 self.calculateAllButton.setText("Calculate All") 566 self.enableButtons() 566 567 567 568 def startThread(self): … … 572 573 573 574 # Set data before running the calculations 574 self.update _calculator()575 self.updateCalculator() 575 576 576 577 # If a thread is already started, stop it 577 if self.calc _thread is not None and self.calc_thread.isrunning():578 self.calc _thread.stop()578 if self.calcThread is not None and self.calcThread.isrunning(): 579 self.calcThread.stop() 579 580 pr = self._calculator.clone() 580 581 nfunc = self.getNFunc() 581 self.calc _thread = CalcPr(pr, nfunc,582 583 584 585 self.calc _thread.queue()586 self.calc _thread.ready(2.5)582 self.calcThread = CalcPr(pr, nfunc, 583 error_func=self._threadError, 584 completefn=self._calculateCompleted, 585 updatefn=None) 586 self.calcThread.queue() 587 self.calcThread.ready(2.5) 587 588 588 589 def performEstimateNT(self): … … 592 593 from .Thread import EstimateNT 593 594 594 self.update _calculator()595 self.updateCalculator() 595 596 596 597 # If a thread is already started, stop it 597 if (self.estimation _thread_ntis not None and598 self.estimation _thread_nt.isrunning()):599 self.estimation _thread_nt.stop()598 if (self.estimationThreadNT is not None and 599 self.estimationThreadNT.isrunning()): 600 self.estimationThreadNT.stop() 600 601 pr = self._calculator.clone() 601 602 # Skip the slit settings for the estimation … … 605 606 nfunc = self.getNFunc() 606 607 607 self.estimation _thread_nt= EstimateNT(pr, nfunc,608 error_func=self._threadError,609 completefn=self._estimateNTCompleted,610 updatefn=None)611 self.estimation _thread_nt.queue()612 self.estimation _thread_nt.ready(2.5)608 self.estimationThreadNT = EstimateNT(pr, nfunc, 609 error_func=self._threadError, 610 completefn=self._estimateNTCompleted, 611 updatefn=None) 612 self.estimationThreadNT.queue() 613 self.estimationThreadNT.ready(2.5) 613 614 614 615 def performEstimate(self): … … 619 620 620 621 # If a thread is already started, stop it 621 if (self.estimation _thread is not None and622 self.estimation _thread.isrunning()):623 self.estimation _thread.stop()624 self.estimation _thread = EstimatePr(self._calculator.clone(),625 626 627 628 629 self.estimation _thread.queue()630 self.estimation _thread.ready(2.5)622 if (self.estimationThread is not None and 623 self.estimationThread.isrunning()): 624 self.estimationThread.stop() 625 self.estimationThread = EstimatePr(self._calculator.clone(), 626 self.getNFunc(), 627 error_func=self._threadError, 628 completefn=self._estimateCompleted, 629 updatefn=None) 630 self.estimationThread.queue() 631 self.estimationThread.ready(2.5) 631 632 632 633 ###################################################################### … … 700 701 701 702 # Update P(r) and fit plots 702 self.pr _plot = self.logic.newPRPlot(out, self._calculator, cov)703 self.pr _plot.filename = self.logic.data.filename704 self.data _plot = self.logic.new1DPlot(out, self._calculator)705 self.data _plot.filename = self.logic.data.filename703 self.prPlot = self.logic.newPRPlot(out, self._calculator, cov) 704 self.prPlot.filename = self.logic.data.filename 705 self.dataPlot = self.logic.new1DPlot(out, self._calculator) 706 self.dataPlot.filename = self.logic.data.filename 706 707 707 708 # Udpate internals and GUI -
src/sas/qtgui/Utilities/GridPanel.py
r98485fe rae34d30 352 352 def closeEvent(self, event): 353 353 """Tell the parent window the window closed""" 354 self.parent. grid_window = None354 self.parent.batchResultsWindow = None 355 355 event.accept()
Note: See TracChangeset
for help on using the changeset viewer.