Changes in / [bb477f5:48e55c9] 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
r2b8286c r4d959c8 43 43 estimateSignal = QtCore.pyqtSignal(tuple) 44 44 estimateNTSignal = QtCore.pyqtSignal(tuple) 45 estimateDynamicNTSignal = QtCore.pyqtSignal(tuple) 46 estimateDynamicSignal = QtCore.pyqtSignal(tuple) 45 47 calculateSignal = QtCore.pyqtSignal(tuple) 46 48 … … 194 196 self.model.itemChanged.connect(self.model_changed) 195 197 self.estimateNTSignal.connect(self._estimateNTUpdate) 198 self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate) 199 self.estimateDynamicSignal.connect(self._estimateDynamicUpdate) 196 200 self.estimateSignal.connect(self._estimateUpdate) 197 201 self.calculateSignal.connect(self._calculateUpdate) 202 203 self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic) 198 204 199 205 def setupMapper(self): … … 309 315 and not self.isCalculating) 310 316 self.removeButton.setEnabled(self.logic.data_is_loaded) 311 self.explorerButton.setEnabled(self.logic.data_is_loaded 312 and np.all(self.logic.data.dy != 0)) 317 self.explorerButton.setEnabled(self.logic.data_is_loaded) 313 318 self.stopButton.setVisible(self.isCalculating) 314 319 self.regConstantSuggestionButton.setEnabled( … … 501 506 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 502 507 self.performEstimate() 508 509 def updateDynamicGuiValues(self): 510 pr = self._calculator 511 alpha = self._calculator.suggested_alpha 512 self.model.setItem(WIDGETS.W_MAX_DIST, 513 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 514 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 515 self.noOfTermsSuggestionButton.setText( 516 "{:n}".format(self.nTermsSuggested)) 517 518 self.enableButtons() 503 519 504 520 def updateGuiValues(self): … … 520 536 self.model.setItem(WIDGETS.W_MAX_DIST, 521 537 QtGui.QStandardItem("{:.4g}".format(pr.get_dmax()))) 522 self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 523 self.noOfTermsSuggestionButton.setText( 524 "{:n}".format(self.nTermsSuggested)) 538 #FIXME: At the initial initialization trigger Dynamic estimate instead of this one 539 #self.regConstantSuggestionButton.setText("{:-3.2g}".format(alpha)) 540 #self.noOfTermsSuggestionButton.setText( 541 # "{:n}".format(self.nTermsSuggested)) 525 542 526 543 if isinstance(pr.chi2, np.ndarray): … … 641 658 self.calcThread.ready(2.5) 642 659 660 #Perform estimate should be done on value enter this should solve delay problem 661 #self.performEstimate() 662 643 663 def stopCalcThread(self): 644 664 """ Stops a thread if it exists and is running """ … … 667 687 error_func=self._threadError, 668 688 completefn=self._estimateNTCompleted, 689 updatefn=None) 690 self.estimationThreadNT.queue() 691 self.estimationThreadNT.ready(2.5) 692 693 def performEstimateDynamicNT(self): 694 """ 695 Perform parameter estimation 696 """ 697 from .Thread import EstimateNT 698 699 self.updateCalculator() 700 701 # If a thread is already started, stop it 702 self.stopEstimateNTThread() 703 704 pr = self._calculator.clone() 705 # Skip the slit settings for the estimation 706 # It slows down the application and it doesn't change the estimates 707 pr.slit_height = 0.0 708 pr.slit_width = 0.0 709 nfunc = self.getNFunc() 710 711 self.estimationThreadNT = EstimateNT(pr, nfunc, 712 error_func=self._threadError, 713 completefn=self._estimateDynamicNTCompleted, 669 714 updatefn=None) 670 715 self.estimationThreadNT.queue() … … 693 738 self.estimationThread.ready(2.5) 694 739 740 def performEstimateDynamic(self): 741 """ 742 Perform parameter estimation 743 """ 744 from .Thread import EstimatePr 745 746 # If a thread is already started, stop it 747 self.stopEstimationThread() 748 749 self.estimationThread = EstimatePr(self._calculator.clone(), 750 self.getNFunc(), 751 error_func=self._threadError, 752 completefn=self._estimateDynamicCompleted, 753 updatefn=None) 754 self.estimationThread.queue() 755 self.estimationThread.ready(2.5) 756 695 757 def stopEstimationThread(self): 696 758 """ Stop the estimation thread if it exists and is running """ … … 705 767 ''' Send a signal to the main thread for model update''' 706 768 self.estimateSignal.emit((alpha, message, elapsed)) 769 770 def _estimateDynamicCompleted(self, alpha, message, elapsed): 771 ''' Send a signal to the main thread for model update''' 772 self.estimateDynamicSignal.emit((alpha, message, elapsed)) 707 773 708 774 def _estimateUpdate(self, output_tuple): … … 721 787 self.performEstimateNT() 722 788 789 def _estimateDynamicUpdate(self, output_tuple): 790 """ 791 Parameter estimation completed, 792 display the results to the user 793 794 :param alpha: estimated best alpha 795 :param elapsed: computation time 796 """ 797 alpha, message, elapsed = output_tuple 798 self._calculator.alpha = alpha 799 self._calculator.elapsed += self._calculator.elapsed 800 if message: 801 logger.info(message) 802 self.performEstimateDynamicNT() 803 723 804 def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 724 805 ''' Send a signal to the main thread for model update''' 725 806 self.estimateNTSignal.emit((nterms, alpha, message, elapsed)) 807 808 def _estimateDynamicNTCompleted(self, nterms, alpha, message, elapsed): 809 ''' Send a signal to the main thread for model update''' 810 self.estimateDynamicNTSignal.emit((nterms, alpha, message, elapsed)) 726 811 727 812 def _estimateNTUpdate(self, output_tuple): … … 747 832 self.startThread() 748 833 834 def _estimateDynamicNTUpdate(self, output_tuple): 835 """ 836 Parameter estimation completed, 837 display the results to the user 838 839 :param alpha: estimated best alpha 840 :param nterms: estimated number of terms 841 :param elapsed: computation time 842 """ 843 nterms, alpha, message, elapsed = output_tuple 844 self._calculator.elapsed += elapsed 845 self._calculator.suggested_alpha = alpha 846 self.nTermsSuggested = nterms 847 # Save useful info 848 self.updateDynamicGuiValues() 849 if message: 850 logger.info(message) 851 if self.isBatch: 852 self.acceptAlpha() 853 self.acceptNoTerms() 854 self.startThread() 855 749 856 def _calculateCompleted(self, out, cov, pr, elapsed): 750 857 ''' Send a signal to the main thread for model update''' -
src/sas/sascalc/pr/invertor.py
rb8080e1 r6701a0b 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 """ … … 244 258 invertor.x = self.x 245 259 invertor.y = self.y 246 invertor.err = self.err 260 if np.size(self.err) == 0 or np.all(self.err) == 0: 261 invertor.err = self.add_errors(self.y) 262 else: 263 invertor.err = self.err 247 264 invertor.est_bck = self.est_bck 248 265 invertor.background = self.background … … 268 285 A[i][j] = (Fourier transformed base function for point j) 269 286 270 We the mchoose a number of r-points, n_r, to evaluate the second287 We then choose a number of r-points, n_r, to evaluate the second 271 288 derivative of P(r) at. This is used as our regularization term. 272 289 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.