Changeset 47bf906 in sasview for src/sas/qtgui/Perspectives
- Timestamp:
- Mar 20, 2018 3:23:43 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:
- e51e078
- Parents:
- d744767
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
re90988c r47bf906 29 29 BACKGROUND_INPUT = 0.0 30 30 MAX_DIST = 140.0 31 DICT_KEYS = ["Calculator", "PrPlot", "DataPlot", "DMaxWindow", 32 "Logic", "NFunc", "Estimates"] 33 ESTIMATE_KEYS = ["nFunc", "??????", "Background"] 34 31 35 32 36 # TODO: Modify plot references, don't just send new … … 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 # Combo box index for self._data 73 self._data_index = 0 74 # plots of self._data 75 self.pr_plot = None 76 self.data_plot = None 77 78 # Calculation threads used by all data items 71 79 self.calc_thread = None 72 80 self.estimation_thread = None 73 81 74 # Current data object in view 75 self._data_index = 0 76 # list mapping data to p(r) calculation 82 # Mapping for all data items 83 # TODO: {QStandardItem -> {params: [], plot: Plot, dmax: dMax, 84 # TODO: calculator: Invertor(), estimates: {}, data: Data1D, ...} 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 = {} 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]: {}} 87 95 88 96 self.calculateAllButton.setEnabled(False) 89 97 self.calculateThisButton.setEnabled(False) 90 91 # plots for current data92 self.pr_plot = None93 self.data_plot = None94 # plot references for all data in perspective95 self.pr_plot_list = {}96 self.data_plot_list = {}97 98 98 99 self.model = QtGui.QStandardItemModel(self) … … 158 159 159 160 self.backgroundInput.editingFinished.connect( 160 lambda: self._calculator.set_est_bck(i nt(is_float(self.backgroundInput.text()))))161 lambda: self._calculator.set_est_bck(is_float(self.backgroundInput.text()))) 161 162 self.minQInput.editingFinished.connect( 162 163 lambda: self._calculator.set_qmin(is_float(self.minQInput.text()))) … … 308 309 309 310 def displayChange(self): 311 """Switch to another item in the data list""" 310 312 ref_item = self.dataList.itemData(self.dataList.currentIndex()) 311 self. _model_item = ref_item313 self.updateDataList(self._data) 312 314 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 = None322 self.dataList.removeItem(self.dataList.currentIndex())323 self.dataList.setCurrentIndex(0)324 # Last file removed325 if not self._data_list:326 self._data = None327 self.pr_plot = None328 self._data_set = None329 self.calculateThisButton.setEnabled(False)330 self.calculateAllButton.setEnabled(False)331 self.explorerButton.setEnabled(False)332 315 333 316 ###################################################################### 334 317 # 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 318 341 319 def update_calculator(self): … … 355 333 InversionWindow.__init__(self.parent(), list(self._data_list.keys())) 356 334 exit(0) 357 # TODO: Only send plot first time - otherwise, update in complete358 335 if self.pr_plot is not None: 359 336 title = self.pr_plot.name … … 363 340 GuiUtils.updateModelItemWithPlot(self._data, self.data_plot, title) 364 341 if self.dmaxWindow is not None: 365 366 367 342 self.dmaxWindow.pr_state = self._calculator 343 self.dmaxWindow.nfunc = self.getNFunc() 344 self.dmaxWindow.modelChanged() 368 345 self.mapper.toFirst() 369 346 … … 410 387 if not isinstance(data_item, list): 411 388 msg = "Incorrect type passed to the P(r) Perspective" 412 raise AttributeError 389 raise AttributeError(msg) 413 390 414 391 for data in data_item: … … 417 394 return 418 395 # Create initial internal mappings 419 self._data_list[data] = self._calculator.clone()420 396 self._data_set = GuiUtils.dataFromItem(data) 421 self.data_plot_list[data] = self.data_plot 422 self.pr_plot_list[data] = self.pr_plot 397 self.logic = InversionLogic(self._data_set) 423 398 self.populateDataComboBox(self._data_set.filename, data) 424 399 self.setCurrentData(data) … … 426 401 # Estimate initial values from data 427 402 self.performEstimate() 428 self.logic = InversionLogic(self._data_set)429 403 430 404 # Estimate q range … … 432 406 self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem("{:.4g}".format(qmin))) 433 407 self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem("{:.4g}".format(qmax))) 434 self._models[data] = self.model 435 self.model_item = data 436 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} 437 412 self.enableButtons() 413 414 def updateDataList(self, dataRef): 415 """Save the current data state of the window into self._data_list""" 416 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 421 } 438 422 439 423 def getNFunc(self): … … 448 432 449 433 def setCurrentData(self, data_ref): 450 """Get the current data and display as necessary""" 451 434 """Get the data by reference and display as necessary""" 452 435 if data_ref is None: 453 436 return 454 455 437 if not isinstance(data_ref, QtGui.QStandardItem): 456 438 msg = "Incorrect type passed to the P(r) Perspective" 457 439 raise AttributeError 458 459 440 # Data references 460 441 self._data = data_ref 461 442 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] 443 self._calculator = self._data_list[data_ref].get(DICT_KEYS[0]) 444 self.pr_plot = self._data_list[data_ref].get(DICT_KEYS[1]) 445 self.data_plot = self._data_list[data_ref].get(DICT_KEYS[2]) 446 self.dmaxWindow = self._data_list[data_ref].get(DICT_KEYS[3]) 447 self.logic = self._data_list[data_ref].get(DICT_KEYS[4]) 448 # TODO: Do the values need to be updated when _calculator is changed? 449 450 def removeData(self): 451 """Remove the existing data reference from the P(r) Persepective""" 452 if self.dmaxWindow is not None: 453 self.dmaxWindow = None 454 self.dataList.removeItem(self.dataList.currentIndex()) 455 # TODO: Remove plot references from higher level too? 456 self.dataList.setCurrentIndex(0) 457 # Last file removed 458 self._data_list.pop(self._data) 459 if not self._data_list: 460 self._data = None 461 self.pr_plot = None 462 self._data_set = None 463 self.logic = InversionLogic() 464 self.enableButtons() 465 self.displayChange() 465 466 466 467 ###################################################################### … … 575 576 :param elapsed: computation time 576 577 """ 578 # TODO: Add estimates to DICT_KEYS 577 579 nterms, alpha, message, elapsed = output_tuple 578 580 # Save useful info … … 621 623 self._calculator = pr 622 624 # Append data to data list 623 self._data_list[self._data] = self._calculator.clone() 624 625 # Update model dict 626 self._models[self.model_item] = self.model 625 self._data_list[self._data][DICT_KEYS[0]] = self._calculator.clone() 627 626 628 627 # Create new P(r) and fit plots 629 628 if self.pr_plot is None: 630 629 self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 631 self. pr_plot_list[self._data] = self.pr_plot630 self._data_list[self._data][DICT_KEYS[1]] = self.pr_plot 632 631 else: 633 632 # FIXME: this should update the existing plot, not create a new one 634 633 self.pr_plot = self.logic.newPRPlot(out, self._calculator, cov) 635 self. pr_plot_list[self._data] = self.pr_plot634 self._data_list[self._data][DICT_KEYS[1]] = self.pr_plot 636 635 if self.data_plot is None: 637 636 self.data_plot = self.logic.new1DPlot(out, self._calculator) 638 self. data_plot_list[self._data] = self.data_plot637 self._data_list[self._data][DICT_KEYS[2]] = self.data_plot 639 638 else: 640 639 # FIXME: this should update the existing plot, not create a new one 641 640 self.data_plot = self.logic.new1DPlot(out, self._calculator) 642 self. data_plot_list[self._data] = self.data_plot641 self._data_list[self._data][DICT_KEYS[2]] = self.data_plot 643 642 644 643 def _threadError(self, error):
Note: See TracChangeset
for help on using the changeset viewer.