Changes in / [2385397:1a15ada] in sasview
- Location:
- src/sas
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/DMaxExplorerWidget.py
re908916 rb0ba43e 42 42 self.parent = parent 43 43 44 self.setWindowTitle("D maxExplorer")44 self.setWindowTitle("Dââ Explorer") 45 45 46 46 self.pr_state = pr_state … … 116 116 bck = [] 117 117 chi2 = [] 118 plotable_xs = [] #Introducing this to make sure size of x and y for plotting is the same.8 118 119 119 try: 120 120 dmin = float(self.model.item(W.DMIN).text()) … … 128 128 129 129 original = self.pr_state.d_max 130 131 130 for x in xs: 132 131 self.pr_state.d_max = x … … 141 140 bck.append(self.pr_state.background) 142 141 chi2.append(self.pr_state.chi2) 143 plotable_xs.append(x)144 142 except Exception as ex: 145 143 # This inversion failed, skip this D_max value … … 190 188 y_unit = "a.u." 191 189 192 data = Data1D( plotable_xs, ys)190 data = Data1D(xs, ys) 193 191 if self.hasPlot: 194 192 self.plot.removePlot(None) -
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
r28965e9 r2b8286c 43 43 estimateSignal = QtCore.pyqtSignal(tuple) 44 44 estimateNTSignal = QtCore.pyqtSignal(tuple) 45 estimateDynamicNTSignal = QtCore.pyqtSignal(tuple)46 estimateDynamicSignal = QtCore.pyqtSignal(tuple)47 45 calculateSignal = QtCore.pyqtSignal(tuple) 48 46 … … 196 194 self.model.itemChanged.connect(self.model_changed) 197 195 self.estimateNTSignal.connect(self._estimateNTUpdate) 198 self.estimateDynamicNTSignal.connect(self._estimateDynamicNTUpdate)199 self.estimateDynamicSignal.connect(self._estimateDynamicUpdate)200 196 self.estimateSignal.connect(self._estimateUpdate) 201 197 self.calculateSignal.connect(self._calculateUpdate) 202 203 self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic)204 198 205 199 def setupMapper(self): … … 315 309 and not self.isCalculating) 316 310 self.removeButton.setEnabled(self.logic.data_is_loaded) 317 self.explorerButton.setEnabled(self.logic.data_is_loaded) 311 self.explorerButton.setEnabled(self.logic.data_is_loaded 312 and np.all(self.logic.data.dy != 0)) 318 313 self.stopButton.setVisible(self.isCalculating) 319 314 self.regConstantSuggestionButton.setEnabled( … … 506 501 self.dataPlot = self._dataList[data_ref].get(DICT_KEYS[2]) 507 502 self.performEstimate() 508 509 def updateDynamicGuiValues(self):510 pr = self._calculator511 alpha = self._calculator.suggested_alpha512 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()519 503 520 504 def updateGuiValues(self): … … 536 520 self.model.setItem(WIDGETS.W_MAX_DIST, 537 521 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 525 539 526 if isinstance(pr.chi2, np.ndarray): … … 684 671 self.estimationThreadNT.ready(2.5) 685 672 686 def performEstimateDynamicNT(self):687 """688 Perform parameter estimation689 """690 from .Thread import EstimateNT691 692 self.updateCalculator()693 694 # If a thread is already started, stop it695 self.stopEstimateNTThread()696 697 pr = self._calculator.clone()698 # Skip the slit settings for the estimation699 # It slows down the application and it doesn't change the estimates700 pr.slit_height = 0.0701 pr.slit_width = 0.0702 nfunc = self.getNFunc()703 704 self.estimationThreadNT = EstimateNT(pr, nfunc,705 error_func=self._threadError,706 completefn=self._estimateDynamicNTCompleted,707 updatefn=None)708 self.estimationThreadNT.queue()709 self.estimationThreadNT.ready(2.5)710 711 673 def stopEstimateNTThread(self): 712 674 if (self.estimationThreadNT is not None and … … 731 693 self.estimationThread.ready(2.5) 732 694 733 def performEstimateDynamic(self):734 """735 Perform parameter estimation736 """737 from .Thread import EstimatePr738 739 # If a thread is already started, stop it740 self.stopEstimationThread()741 742 self.estimationThread = EstimatePr(self._calculator.clone(),743 self.getNFunc(),744 error_func=self._threadError,745 completefn=self._estimateDynamicCompleted,746 updatefn=None)747 self.estimationThread.queue()748 self.estimationThread.ready(2.5)749 750 695 def stopEstimationThread(self): 751 696 """ Stop the estimation thread if it exists and is running """ … … 760 705 ''' Send a signal to the main thread for model update''' 761 706 self.estimateSignal.emit((alpha, message, elapsed)) 762 763 def _estimateDynamicCompleted(self, alpha, message, elapsed):764 ''' Send a signal to the main thread for model update'''765 self.estimateDynamicSignal.emit((alpha, message, elapsed))766 707 767 708 def _estimateUpdate(self, output_tuple): … … 779 720 logger.info(message) 780 721 self.performEstimateNT() 781 self.performEstimateDynamicNT()782 783 def _estimateDynamicUpdate(self, output_tuple):784 """785 Parameter estimation completed,786 display the results to the user787 788 :param alpha: estimated best alpha789 :param elapsed: computation time790 """791 alpha, message, elapsed = output_tuple792 self._calculator.alpha = alpha793 self._calculator.elapsed += self._calculator.elapsed794 if message:795 logger.info(message)796 self.performEstimateDynamicNT()797 722 798 723 def _estimateNTCompleted(self, nterms, alpha, message, elapsed): 799 724 ''' Send a signal to the main thread for model update''' 800 725 self.estimateNTSignal.emit((nterms, alpha, message, elapsed)) 801 802 def _estimateDynamicNTCompleted(self, nterms, alpha, message, elapsed):803 ''' Send a signal to the main thread for model update'''804 self.estimateDynamicNTSignal.emit((nterms, alpha, message, elapsed))805 726 806 727 def _estimateNTUpdate(self, output_tuple): … … 826 747 self.startThread() 827 748 828 def _estimateDynamicNTUpdate(self, output_tuple):829 """830 Parameter estimation completed,831 display the results to the user832 833 :param alpha: estimated best alpha834 :param nterms: estimated number of terms835 :param elapsed: computation time836 """837 nterms, alpha, message, elapsed = output_tuple838 self._calculator.elapsed += elapsed839 self._calculator.suggested_alpha = alpha840 self.nTermsSuggested = nterms841 # Save useful info842 self.updateDynamicGuiValues()843 if message:844 logger.info(message)845 if self.isBatch:846 self.acceptAlpha()847 self.acceptNoTerms()848 self.startThread()849 850 749 def _calculateCompleted(self, out, cov, pr, elapsed): 851 750 ''' Send a signal to the main thread for model update''' -
src/sas/sascalc/pr/invertor.py
r13da5f5 rb8080e1 71 71 A[j][i] = (Fourier transformed base function for point j) 72 72 73 We the nchoose a number of r-points, n_r, to evaluate the second73 We them 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 name == 'x':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 avaialble232 :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 Q237 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_err240 logger.warning("Simulated errors have been added to the data set\n")241 return stats_errors242 243 229 def clone(self): 244 230 """ … … 258 244 invertor.x = self.x 259 245 invertor.y = self.y 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 246 invertor.err = self.err 264 247 invertor.est_bck = self.est_bck 265 248 invertor.background = self.background … … 285 268 A[i][j] = (Fourier transformed base function for point j) 286 269 287 We the nchoose a number of r-points, n_r, to evaluate the second270 We them choose a number of r-points, n_r, to evaluate the second 288 271 derivative of P(r) at. This is used as our regularization term. 289 272 For a vector r of length n_r, the following n_r rows are set to :: … … 306 289 # Reset the background value before proceeding 307 290 # self.background = 0.0 308 if np.size(self.err) == 0 or np.all(self.err) == 0:309 self.err = self.add_errors(self.y)310 291 if not self.est_bck: 311 292 self.y -= self.background
Note: See TracChangeset
for help on using the changeset viewer.