Changes in / [855e7ad:4b7d322] in sasview
- Location:
- src/sas
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/DMaxExplorerWidget.py
rb0ba43e re908916 42 42 self.parent = parent 43 43 44 self.setWindowTitle("D ââExplorer")44 self.setWindowTitle("Dmax Explorer") 45 45 46 46 self.pr_state = pr_state … … 116 116 bck = [] 117 117 chi2 = [] 118 118 plotable_xs = [] #Introducing this to make sure size of x and y for plotting is the same.8 119 119 try: 120 120 dmin = float(self.model.item(W.DMIN).text()) … … 128 128 129 129 original = self.pr_state.d_max 130 130 131 for x in xs: 131 132 self.pr_state.d_max = x … … 140 141 bck.append(self.pr_state.background) 141 142 chi2.append(self.pr_state.chi2) 143 plotable_xs.append(x) 142 144 except Exception as ex: 143 145 # This inversion failed, skip this D_max value … … 188 190 y_unit = "a.u." 189 191 190 data = Data1D( xs, ys)192 data = Data1D(plotable_xs, ys) 191 193 if self.hasPlot: 192 194 self.plot.removePlot(None) -
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r855e7ad r855e7ad 44 44 estimateSignal = QtCore.pyqtSignal(tuple) 45 45 estimateNTSignal = QtCore.pyqtSignal(tuple) 46 estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 47 estimateDynamicSignal = QtCore.pyqtSignal(tuple) 46 48 calculateSignal = QtCore.pyqtSignal(tuple) 47 49 … … 195 197 self.model.itemChanged.connect(self.model_changed) 196 198 self.estimateNTSignal.connect(self._estimateNTUpdate) 199 self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 200 self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 197 201 self.estimateSignal.connect(self._estimateUpdate) 198 202 self.calculateSignal.connect(self._calculateUpdate) 203 204 self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 199 205 200 206 def setupMapper(self): … … 310 316 and not self.isCalculating) 311 317 self.removeButton.setEnabled(self.logic.data_is_loaded) 312 self.explorerButton.setEnabled(self.logic.data_is_loaded 313 and np.all(self.logic.data.dy != 0)) 318 self.explorerButton.setEnabled(self.logic.data_is_loaded) 314 319 self.stopButton.setVisible(self.isCalculating) 315 320 self.regConstantSuggestionButton.setEnabled( … … 458 463 self._calculator.set_qmin(qmin) 459 464 self._calculator.set_qmax(qmax) 465 if np.size(self.logic.data.dy) == 0 or np.all(self.logic.data.dy) == 0: 466 self.logic.data.dy = self._calculator.add_errors(self.logic.data.y) 460 467 self.updateDataList(data) 461 468 self.populateDataComboBox(self.logic.data.filename, data) … … 502 509 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 503 510 self.performEstimate() 511 512 def updateDynamicGuiValues(self): 513 pr = self._calculator 514 alpha = self._calculator.suggested_alpha 515 self.model.setItem(WIDGETS.W_MAX_DIST, 516 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 517 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 518 self.noOfTermsSuggestionButton.setText( 519 "{:n}".format(self.nTermsSuggested)) 520 521 self.enableButtons() 504 522 505 523 def updateGuiValues(self): … … 521 539 self.model.setItem(WIDGETS.W_MAX_DIST, 522 540 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 523 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha))524 self.noOfTermsSuggestionButton.setText(525 "{:n}".format(self.nTermsSuggested))526 541 527 542 if isinstance(pr.chi2, np.ndarray): … … 674 689 self.estimationThreadNT.ready(2.5) 675 690 691 def performEstimateDynamicNT(self): 692 """ 693 Perform parameter estimation 694 """ 695 from .Thread import EstimateNT 696 697 self.updateCalculator() 698 699 # If a thread is already started, stop it 700 self.stopEstimateNTThread() 701 702 pr = self._calculator.clone() 703 # Skip the slit settings for the estimation 704 # It slows down the application and it doesn't change the estimates 705 pr.slit_height = 0.0 706 pr.slit_width = 0.0 707 nfunc = self.getNFunc() 708 709 self.estimationThreadNT = EstimateNT(pr, nfunc, 710 error_func=self._threadError, 711 completefn=self._estimateDynamicNTCompleted, 712 updatefn=None) 713 self.estimationThreadNT.queue() 714 self.estimationThreadNT.ready(2.5) 715 676 716 def stopEstimateNTThread(self): 677 717 if (self.estimationThreadNT is not None and … … 696 736 self.estimationThread.ready(2.5) 697 737 738 def performEstimateDynamic(self): 739 """ 740 Perform parameter estimation 741 """ 742 from .Thread import EstimatePr 743 744 # If a thread is already started, stop it 745 self.stopEstimationThread() 746 747 self.estimationThread = EstimatePr(self._calculator.clone(), 748 self.getNFunc(), 749 error_func=self._threadError, 750 completefn=self._estimateDynamicCompleted, 751 updatefn=None) 752 self.estimationThread.queue() 753 self.estimationThread.ready(2.5) 754 698 755 def stopEstimationThread(self): 699 756 """ Stop the estimation thread if it exists and is running """ … … 708 765 ''' Send a signal to the main thread for model update''' 709 766 self.estimateSignal.emit((alpha, message, elapsed)) 767 768 def _estimateDynamicCompleted(self, alpha, message, elapsed): 769 ''' Send a signal to the main thread for model update''' 770 self.estimateDynamicSignal.emit((alpha, message, elapsed)) 710 771 711 772 def _estimateUpdate(self, output_tuple): … … 723 784 logger.info(message) 724 785 self.performEstimateNT() 786 self.performEstimateDynamicNT() 787 788 def _estimateDynamicUpdate(self, output_tuple): 789 """ 790 Parameter estimation completed, 791 display the results to the user 792 793 :param alpha: estimated best alpha 794 :param elapsed: computation time 795 """ 796 alpha, message, elapsed = output_tuple 797 self._calculator.alpha = alpha 798 self._calculator.elapsed += self._calculator.elapsed 799 if message: 800 logger.info(message) 801 self.performEstimateDynamicNT() 725 802 726 803 def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 727 804 ''' Send a signal to the main thread for model update''' 728 805 self.estimateNTSignal.emit((nterms, alpha, message, elapsed)) 806 807 def _estimateDynamicNTCompleted(self, nterms, alpha, message, elapsed): 808 ''' Send a signal to the main thread for model update''' 809 self.estimateDynamicNTSignal.emit((nterms, alpha, message, elapsed)) 729 810 730 811 def _estimateNTUpdate(self, output_tuple): … … 750 831 self.startThread() 751 832 833 def _estimateDynamicNTUpdate(self, output_tuple): 834 """ 835 Parameter estimation completed, 836 display the results to the user 837 838 :param alpha: estimated best alpha 839 :param nterms: estimated number of terms 840 :param elapsed: computation time 841 """ 842 nterms, alpha, message, elapsed = output_tuple 843 self._calculator.elapsed += elapsed 844 self._calculator.suggested_alpha = alpha 845 self.nTermsSuggested = nterms 846 # Save useful info 847 self.updateDynamicGuiValues() 848 if message: 849 logger.info(message) 850 if self.isBatch: 851 self.acceptAlpha() 852 self.acceptNoTerms() 853 self.startThread() 854 752 855 def _calculateCompleted(self, out, cov, pr, elapsed): 753 856 ''' Send a signal to the main thread for model update''' -
src/sas/sascalc/pr/invertor.py
rb8080e1 reeea6a3 71 71 A[j][i] = (Fourier transformed base function for point j) 72 72 73 We the mchoose a number of r-points, n_r, to evaluate the second73 We then choose a number of r-points, n_r, to evaluate the second 74 74 derivative of P(r) at. This is used as our regularization term. 75 75 For a vector r of length n_r, the following n_r rows are set to :: … … 144 144 x, y, err, d_max, q_min, q_max and alpha 145 145 """ 146 if 146 if name == 'x': 147 147 if 0.0 in value: 148 148 msg = "Invertor: one of your q-values is zero. " … … 227 227 return None 228 228 229 def add_errors(self, yvalues): 230 """ 231 Adds errors to data set is they are not avaialble 232 :return: 233 """ 234 stats_errors = np.zeros(len(yvalues)) 235 for i in range(len(yvalues)): 236 # Scale the error so that we can fit over several decades of Q 237 scale = 0.05 * np.sqrt(yvalues[i]) 238 min_err = 0.01 * yvalues[i] 239 stats_errors[i] = scale * np.sqrt(np.fabs(yvalues[i])) + min_err 240 logger.warning("Simulated errors have been added to the data set\n") 241 return stats_errors 242 229 243 def clone(self): 230 244 """ … … 268 282 A[i][j] = (Fourier transformed base function for point j) 269 283 270 We the mchoose a number of r-points, n_r, to evaluate the second284 We then choose a number of r-points, n_r, to evaluate the second 271 285 derivative of P(r) at. This is used as our regularization term. 272 286 For a vector r of length n_r, the following n_r rows are set to ::
Note: See TracChangeset
for help on using the changeset viewer.