Changeset d1a4793 in sasview for src/sas/qtgui/Perspectives/PrInversion
- Timestamp:
- Oct 27, 2017 11:20:08 AM (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:
- e7651ff
- Parents:
- dab3351
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/PrInversion/PrInversionPerspective.py
rdab3351 rd1a4793 1 1 import sys 2 2 import logging 3 import pylab 3 4 import numpy as np 4 5 … … 14 15 15 16 # pr inversion calculation elements 17 from sas.sascalc.dataloader.data_info import Data1D 16 18 from sas.sascalc.pr.invertor import Invertor 17 19 20 def is_float(value): 21 try: 22 return float(value) 23 except ValueError: 24 return 0.0 18 25 19 26 class PrInversionWindow(QtGui.QTabWidget, Ui_PrInversion): … … 41 48 # is there data 42 49 self._has_data = False 50 self._data = Data1D() 51 52 # p(r) calculator 53 self._calculator = Invertor() 54 self._last_calculator = None 55 self.calc_thread = None 56 self.estimation_thread = None 43 57 44 58 # Current data object in view … … 49 63 data = [data] 50 64 for datum in data: 51 self._data_list.append({datum : None}) 52 53 # p(r) calculator 54 self._calculator = Invertor() 55 self._last_calculator = None 56 self.calc_thread = None 57 self.estimation_thread = None 65 self._data_list.append({datum: self._calculator.clone()}) 58 66 59 67 self.model = QtGui.QStandardItemModel(self) … … 234 242 # GUI Interaction Events 235 243 244 def update_calculator(self): 245 """Update all p(r) params. Take all GUI values as an override""" 246 self._calculator.set_x(self._data.x) 247 self._calculator.set_y(self._data.y) 248 self._calculator.set_err(self._data.dy) 249 self._calculator.set_qmin(is_float(UI.TabbedPrInversionUI._fromUtf8( 250 self.minQInput.text()))) 251 self._calculator.set_qmax(is_float(UI.TabbedPrInversionUI._fromUtf8( 252 self.maxQInput.text()))) 253 self._calculator.set_alpha(is_float(UI.TabbedPrInversionUI._fromUtf8( 254 self.regularizationConstantInput.text()))) 255 self._calculator.set_dmax(is_float(UI.TabbedPrInversionUI._fromUtf8( 256 self.maxDistanceInput.text()))) 257 self._calculator.set_est_bck(int(is_float( 258 UI.TabbedPrInversionUI._fromUtf8(self.backgroundInput.text())))) 259 self._calculator.set_slit_height(is_float( 260 UI.TabbedPrInversionUI._fromUtf8(self.slitHeightInput.text()))) 261 self._calculator.set_slit_width(is_float( 262 UI.TabbedPrInversionUI._fromUtf8(self.slitWidthInput.text()))) 263 236 264 def _calculation(self): 237 265 """ 238 266 Calculate the P(r) for every data set in the data list 239 267 """ 240 # TODO: Set all invertor values before calculation241 self. _calculator.__setattr__("qmin", UI.TabbedPrInversionUI._fromUtf8(242 self.minQInput.text()))268 # Pull in any GUI changes before running the calculations 269 self.update_calculator() 270 # Run 243 271 self.startThread() 244 272 … … 314 342 self._data_list.append({data_object: None}) 315 343 self._has_data = True 344 self._data = data_object 316 345 self.enableButtons() 317 346 self.populateDataComboBox(data_object.filename) 318 self.model.setItem(WIDGETS.W_QMIN, 319 QtGui.QStandardItem(str(data_object.x.min())))320 self.model.setItem(WIDGETS.W_QMAX, 321 QtGui.QStandardItem(str(data_object.x.max())))347 self.model.setItem(WIDGETS.W_QMIN, QtGui.QStandardItem( 348 "{:.4g}".format(data_object.x.min()))) 349 self.model.setItem(WIDGETS.W_QMAX, QtGui.QStandardItem( 350 "{:.4g}".format(data_object.x.max()))) 322 351 323 352 # Estimate initial values from data 353 self.update_calculator() 324 354 self.performEstimate() 325 355 326 356 # TODO: Plot data on load 327 357 328 # TODO: Only load inthe 1st data until batch mode is working329 # TODO: Thus, the break358 # TODO: Only load the 1st data until batch mode is working 359 # TODO: thus, the break 330 360 break 331 361 … … 411 441 self.regConstantSuggestionButton.setText(QtCore.QString(str(alpha))) 412 442 self.regConstantSuggestionButton.setEnabled(True) 413 if message is not None:443 if message: 414 444 logging.info(message) 415 445 self.performEstimateNT() … … 426 456 """ 427 457 # Save useful info 428 self.noOfTermsSuggestionButton.setText(QtCore.QString(str(nterms))) 458 self.noOfTermsSuggestionButton.setText(QtCore.QString( 459 "{:n}".format(nterms))) 429 460 self.noOfTermsSuggestionButton.setEnabled(True) 430 self.regConstantSuggestionButton.setText(QtCore.QString(str(alpha))) 461 self.regConstantSuggestionButton.setText(QtCore.QString( 462 "{:.3g}".format(alpha))) 431 463 self.regConstantSuggestionButton.setEnabled(True) 432 464 self.model.setItem(WIDGETS.W_COMP_TIME, 433 465 QtGui.QStandardItem(str(elapsed))) 434 if message is not None:466 if message: 435 467 logging.info(message) 436 468 pass … … 459 491 # Show result on control panel 460 492 493 # TODO: Connect self._calculator to GUI 461 494 self.model.setItem(WIDGETS.W_RG, QtGui.QStandardItem(str(pr.rg(out)))) 462 495 self.model.setItem(WIDGETS.W_I_ZERO, 463 496 QtGui.QStandardItem(str(pr.iq0(out)))) 464 497 self.model.setItem(WIDGETS.W_BACKGROUND_INPUT, 465 QtGui.QStandardItem("{:. 2g}".format(pr.background)))498 QtGui.QStandardItem("{:.3f}".format(pr.background))) 466 499 self.model.setItem(WIDGETS.W_BACKGROUND_OUTPUT, 467 500 QtGui.QStandardItem(str(pr.background))) 468 501 self.model.setItem(WIDGETS.W_CHI_SQUARED, 469 QtGui.QStandardItem(str(pr.chi2 )))502 QtGui.QStandardItem(str(pr.chi2[0]))) 470 503 self.model.setItem(WIDGETS.W_COMP_TIME, 471 504 QtGui.QStandardItem(str(elapsed))) … … 476 509 self.model.setItem(WIDGETS.W_SIGMA_POS_FRACTION, 477 510 QtGui.QStandardItem(str(pr.get_pos_err(out, cov)))) 511 512 # Display results tab 513 self.PrTabWidget.setCurrentIndex(1) 478 514 479 515 # TODO: Show plots
Note: See TracChangeset
for help on using the changeset viewer.