Changeset 6da860a in sasview for src/sas/qtgui/Perspectives
- Timestamp:
- May 1, 2018 11:51:06 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:
- 72ecbdf2
- Parents:
- 6bd0d81
- Location:
- src/sas/qtgui/Perspectives/Inversion
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Inversion/DMaxExplorerWidget.py
rae34d30 r6da860a 8 8 9 9 # global 10 import sys11 import os12 10 import logging 13 11 import numpy as np … … 51 49 52 50 self.plot = PlotterWidget(self, self) 53 self.hasPlot = None51 self.hasPlot = False 54 52 self.verticalLayout.insertWidget(0, self.plot) 55 53 56 54 # Let's choose the Standard Item Model. 57 55 self.model = QtGui.QStandardItemModel(self) 58 self.mapper = None56 self.mapper = QtWidgets.QDataWidgetMapper(self) 59 57 60 58 # Add validators on line edits 61 59 self.setupValidators() 62 60 63 # #Connect buttons to slots.64 # #Needs to be done early so default values propagate properly.61 # Connect buttons to slots. 62 # Needs to be done early so default values propagate properly. 65 63 self.setupSlots() 66 64 … … 89 87 90 88 def setupMapper(self): 91 self.mapper = QtWidgets.QDataWidgetMapper(self)92 89 self.mapper.setOrientation(QtCore.Qt.Vertical) 93 90 self.mapper.setModel(self.model) … … 112 109 chi2 = [] 113 110 114 xs = np.linspace(float(self.model.item(W.DMIN).text()), 115 float(self.model.item(W.DMAX).text()), 116 float(self.model.item(W.NPTS).text())) 111 try: 112 dmin = float(self.model.item(W.DMIN).text()) 113 dmax = float(self.model.item(W.DMAX).text()) 114 npts = float(self.model.item(W.NPTS).text()) 115 xs = np.linspace(dmin, dmax, npts) 116 except ValueError as e: 117 msg = ("An input value is not correctly formatted. Please check {}" 118 .format(e.message)) 119 logger.error(msg) 117 120 118 121 original = self.pr_state.d_max … … 133 136 msg = "ExploreDialog: inversion failed " 134 137 msg += "for D_max=%s\n%s" % (str(x), ex) 135 print(msg)136 138 logger.error(msg) 137 139 … … 143 145 msg = "ExploreDialog: inversion failed " 144 146 msg += "for D_max=%s\n%s" % (str(x), ex) 145 print(msg)146 147 logger.error(msg) 147 148 -
src/sas/qtgui/Perspectives/Inversion/InversionLogic.py
r318b353e r6da860a 1 1 import math 2 import pylab2 import logging 3 3 import numpy as np 4 4 … … 12 12 GROUP_ID_IQ_DATA = r"$I_{obs}(q)$" 13 13 GROUP_ID_PR_FIT = r"$P_{fit}(r)$" 14 PR_PLOT_PTS = 51 15 16 logger = logging.getLogger(__name__) 14 17 15 18 … … 19 22 No QStandardModelIndex here. 20 23 """ 21 22 # TODO: Add way to change this value23 _pr_n_pts = 5124 24 25 25 def __init__(self, data=None): … … 63 63 maxq = pr.q_max 64 64 65 x = pylab.arange(minq, maxq, maxq / 301.0)65 x = np.arange(minq, maxq, maxq / 301.0) 66 66 y = np.zeros(len(x)) 67 67 err = np.zeros(len(x)) … … 73 73 except: 74 74 err[i] = 1.0 75 print(("Error getting error", value, x[i]))75 logger.log(("Error getting error", value, x[i])) 76 76 77 77 new_plot = Data1D(x, y) … … 89 89 # If we have used slit smearing, plot the smeared I(q) too 90 90 if pr.slit_width > 0 or pr.slit_height > 0: 91 x = pylab.arange(minq, maxq, maxq / 301.0)91 x = np.arange(minq, maxq, maxq / 301.0) 92 92 y = np.zeros(len(x)) 93 93 err = np.zeros(len(x)) … … 99 99 except: 100 100 err[i] = 1.0 101 print(("Error getting error", value, x[i]))101 logger.log(("Error getting error", value, x[i])) 102 102 103 103 new_plot = Data1D(x, y) … … 113 113 return new_plot 114 114 115 def update1DPlot(self, plot, out, pr, q=None):116 """117 Create a new 1D data instance based on fitting results118 """119 120 qtemp = pr.x121 if q is not None:122 qtemp = q123 124 # Make a plot125 maxq = max(qtemp)126 127 minq = min(qtemp)128 129 # Check for user min/max130 if pr.q_min is not None and maxq >= pr.q_min >= minq:131 minq = pr.q_min132 if pr.q_max is not None and maxq >= pr.q_max >= minq:133 maxq = pr.q_max134 135 x = pylab.arange(minq, maxq, maxq / 301.0)136 y = np.zeros(len(x))137 err = np.zeros(len(x))138 for i in range(len(x)):139 value = pr.iq(out, x[i])140 y[i] = value141 try:142 err[i] = math.sqrt(math.fabs(value))143 except:144 err[i] = 1.0145 print(("Error getting error", value, x[i]))146 147 plot.x = x148 plot.y = y149 150 # If we have used slit smearing, plot the smeared I(q) too151 if pr.slit_width > 0 or pr.slit_height > 0:152 x = pylab.arange(minq, maxq, maxq / 301.0)153 y = np.zeros(len(x))154 err = np.zeros(len(x))155 for i in range(len(x)):156 value = pr.iq_smeared(pr.out, x[i])157 y[i] = value158 try:159 err[i] = math.sqrt(math.fabs(value))160 except:161 err[i] = 1.0162 print(("Error getting error", value, x[i]))163 164 plot.x = x165 plot.y = y166 167 return plot168 169 115 def newPRPlot(self, out, pr, cov=None): 170 116 """ 171 117 """ 172 118 # Show P(r) 173 x = pylab.arange(0.0, pr.d_max, pr.d_max / self._pr_n_pts)119 x = np.arange(0.0, pr.d_max, pr.d_max / PR_PLOT_PTS) 174 120 175 121 y = np.zeros(len(x)) … … 193 139 y[i] = value 194 140 195 # if self._normalize_output == True:196 # y = y / total197 # dy = dy / total198 # elif self._scale_output_unity == True:199 # y = y / pmax200 # dy = dy / pmax201 202 141 if cov2 is None: 203 142 new_plot = Data1D(x, y) … … 213 152 214 153 return new_plot 215 216 def updatePRPlot(self, plot, out, pr, cov=None):217 x = pylab.arange(0.0, pr.d_max, pr.d_max / self._pr_n_pts)218 219 y = np.zeros(len(x))220 dy = np.zeros(len(x))221 222 total = 0.0223 pmax = 0.0224 cov2 = np.ascontiguousarray(cov)225 226 for i in range(len(x)):227 if cov2 is None:228 value = pr.pr(out, x[i])229 else:230 (value, dy[i]) = pr.pr_err(out, cov2, x[i])231 total += value * pr.d_max / len(x)232 233 # keep track of the maximum P(r) value234 if value > pmax:235 pmax = value236 237 y[i] = value238 239 # if self._normalize_output == True:240 # y = y / total241 # dy = dy / total242 # elif self._scale_output_unity == True:243 # y = y / pmax244 # dy = dy / pmax245 plot.x = x246 plot.y = y247 248 if cov2 is not None:249 plot.dy = dy250 251 return plot252 154 253 155 def computeDataRange(self): -
src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
rd79bb7e r6da860a 31 31 MAX_DIST = 140.0 32 32 DICT_KEYS = ["Calculator", "PrPlot", "DataPlot"] 33 34 logger = logging.getLogger(__name__) 33 35 34 36 … … 354 356 msg = "Unable to update P{r}. The connection between the main GUI " 355 357 msg += "and P(r) was severed. Attempting to restart P(r)." 356 logg ing.warning(msg)358 logger.warning(msg) 357 359 self.setClosable(True) 358 360 self.close() … … 395 397 """ 396 398 from .DMaxExplorerWidget import DmaxWindow 397 self.dmaxWindow = DmaxWindow(self._calculator, self.getNFunc(), self) 399 self.dmaxWindow = DmaxWindow(pr_state=self._calculator, 400 nfunc=self.getNFunc(), 401 parent=self) 398 402 self.dmaxWindow.show() 399 403 … … 459 463 nfunc = int(self.noOfTermsInput.text()) 460 464 except ValueError: 461 logg ing.error("Incorrect number of terms specified: %s"465 logger.error("Incorrect number of terms specified: %s" 462 466 %self.noOfTermsInput.text()) 463 467 self.noOfTermsInput.setText(str(NUMBER_OF_TERMS)) … … 581 585 self.dataList.setCurrentIndex(index) 582 586 self.isBatch = True 587 # Add the index before calculating in case calculation fails 588 self.batchComplete.append(index) 583 589 break 584 590 if self.isBatch: … … 599 605 # Set data before running the calculations 600 606 self.updateCalculator() 607 # Disable calculation buttons to prevent thread interference 608 self.calculateAllButton.setEnabled(False) 609 self.calculateThisButton.setEnabled(False) 601 610 602 611 # If a thread is already started, stop it … … 672 681 """ 673 682 alpha, message, elapsed = output_tuple 683 self._calculator.alpha = alpha 684 self._calculator.elapsed += self._calculator.elapsed 674 685 if message: 675 logg ing.info(message)686 logger.info(message) 676 687 self.performEstimateNT() 677 688 … … 690 701 """ 691 702 nterms, alpha, message, elapsed = output_tuple 692 self._calculator.elapsed = elapsed703 self._calculator.elapsed += elapsed 693 704 self._calculator.suggested_alpha = alpha 694 705 self.nTermsSuggested = nterms … … 696 707 self.updateGuiValues() 697 708 if message: 698 logg ing.info(message)709 logger.info(message) 699 710 if self.isBatch: 700 711 self.acceptAlpha() … … 742 753 Call-back method for calculation errors 743 754 """ 744 logg ing.warning(error)755 logger.error(error)
Note: See TracChangeset
for help on using the changeset viewer.