[f721030] | 1 | # global |
---|
| 2 | import sys |
---|
| 3 | import os |
---|
[f1f3e6a] | 4 | import logging |
---|
| 5 | import copy |
---|
| 6 | import webbrowser |
---|
| 7 | |
---|
[4992ff2] | 8 | from PyQt5 import QtCore |
---|
[f1f3e6a] | 9 | from PyQt5 import QtGui, QtWidgets |
---|
| 10 | from PyQt5 import QtWebKit |
---|
[f721030] | 11 | |
---|
| 12 | from twisted.internet import threads |
---|
[1042dba] | 13 | from twisted.internet import reactor |
---|
[f721030] | 14 | |
---|
| 15 | # sas-global |
---|
| 16 | from sas.sascalc.invariant import invariant |
---|
[dc5ef15] | 17 | from sas.qtgui.Plotting.PlotterData import Data1D |
---|
[83eb5208] | 18 | import sas.qtgui.Utilities.GuiUtils as GuiUtils |
---|
[f721030] | 19 | |
---|
[f1f3e6a] | 20 | # import sas.qtgui.Plotting.PlotHelper as PlotHelper |
---|
| 21 | |
---|
[f721030] | 22 | # local |
---|
[b3e8629] | 23 | from .UI.TabbedInvariantUI import Ui_tabbedInvariantUI |
---|
| 24 | from .InvariantDetails import DetailsDialog |
---|
| 25 | from .InvariantUtils import WIDGETS |
---|
[f721030] | 26 | |
---|
| 27 | # The minimum q-value to be used when extrapolating |
---|
| 28 | Q_MINIMUM = 1e-5 |
---|
| 29 | # The maximum q-value to be used when extrapolating |
---|
| 30 | Q_MAXIMUM = 10 |
---|
| 31 | # the ratio of maximum q value/(qmax of data) to plot the theory data |
---|
| 32 | Q_MAXIMUM_PLOT = 3 |
---|
[f1f3e6a] | 33 | # Default number of points of interpolation: high and low range |
---|
| 34 | NPOINTS_Q_INTERP = 10 |
---|
| 35 | # Default power law for interpolation |
---|
| 36 | DEFAULT_POWER_LOW = 4 |
---|
[f721030] | 37 | |
---|
[f1f3e6a] | 38 | # Background of line edits if settings OK or wrong |
---|
| 39 | BG_WHITE = "background-color: rgb(255, 255, 255);" |
---|
| 40 | BG_RED = "background-color: rgb(244, 170, 164);" |
---|
[f721030] | 41 | |
---|
[4992ff2] | 42 | class InvariantWindow(QtWidgets.QDialog, Ui_tabbedInvariantUI): |
---|
[f721030] | 43 | # The controller which is responsible for managing signal slots connections |
---|
| 44 | # for the gui and providing an interface to the data model. |
---|
[f1f3e6a] | 45 | name = "Invariant" # For displaying in the combo box in DataExplorer |
---|
| 46 | |
---|
[0979dfb] | 47 | def __init__(self, parent=None): |
---|
| 48 | super(InvariantWindow, self).__init__() |
---|
[469b4622] | 49 | self.setupUi(self) |
---|
| 50 | |
---|
[f721030] | 51 | self.setWindowTitle("Invariant Perspective") |
---|
[e540cd2] | 52 | |
---|
[f721030] | 53 | # initial input params |
---|
| 54 | self._background = 0.0 |
---|
| 55 | self._scale = 1.0 |
---|
| 56 | self._contrast = 1.0 |
---|
[f1f3e6a] | 57 | self._porod = None |
---|
| 58 | |
---|
| 59 | self.parent = parent |
---|
[f721030] | 60 | |
---|
[0979dfb] | 61 | self._manager = parent |
---|
[6fd4e36] | 62 | self._reactor = reactor |
---|
[a281ab8] | 63 | self._model_item = QtGui.QStandardItem() |
---|
[f721030] | 64 | |
---|
[6cb305a] | 65 | self._helpView = QtWebKit.QWebView() |
---|
[f721030] | 66 | self.detailsDialog = DetailsDialog(self) |
---|
[f1f3e6a] | 67 | self.detailsDialog.cmdOK.clicked.connect(self.enabling) |
---|
[f721030] | 68 | |
---|
| 69 | self._low_extrapolate = False |
---|
[f1f3e6a] | 70 | self._low_guinier = True |
---|
| 71 | self._low_fit = False |
---|
| 72 | self._low_power_value = False |
---|
| 73 | self._low_points = NPOINTS_Q_INTERP |
---|
| 74 | self._low_power_value = DEFAULT_POWER_LOW |
---|
| 75 | |
---|
[f721030] | 76 | self._high_extrapolate = False |
---|
[f1f3e6a] | 77 | self._high_power_value = False |
---|
| 78 | self._high_fit = False |
---|
| 79 | self._high_points = NPOINTS_Q_INTERP |
---|
| 80 | self._high_power_value = DEFAULT_POWER_LOW |
---|
[f721030] | 81 | |
---|
[d813cad8] | 82 | # no reason to have this widget resizable |
---|
[d1955d67] | 83 | self.resize(self.minimumSizeHint()) |
---|
[28a84e9] | 84 | |
---|
[f1f3e6a] | 85 | self.communicate = self._manager.communicator() |
---|
[f721030] | 86 | |
---|
[469b4622] | 87 | self._data = None |
---|
| 88 | self._path = "" |
---|
| 89 | |
---|
[b1e36a3] | 90 | self._allow_close = False |
---|
| 91 | |
---|
[f1f3e6a] | 92 | # Modify font in order to display Angstrom symbol correctly |
---|
| 93 | new_font = 'font-family: -apple-system, "Helvetica Neue", "Ubuntu";' |
---|
| 94 | self.lblTotalQUnits.setStyleSheet(new_font) |
---|
| 95 | self.lblSpecificSurfaceUnits.setStyleSheet(new_font) |
---|
| 96 | self.lblInvariantTotalQUnits.setStyleSheet(new_font) |
---|
| 97 | self.lblContrastUnits.setStyleSheet(new_font) |
---|
| 98 | self.lblPorodCstUnits.setStyleSheet(new_font) |
---|
| 99 | self.lblExtrapolQUnits.setStyleSheet(new_font) |
---|
| 100 | |
---|
| 101 | # To remove blue square around line edits |
---|
| 102 | self.txtBackgd.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 103 | self.txtContrast.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 104 | self.txtScale.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 105 | self.txtPorodCst.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 106 | self.txtNptsHighQ.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 107 | self.txtNptsLowQ.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 108 | self.txtPowerLowQ.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 109 | self.txtPowerHighQ.setAttribute(QtCore.Qt.WA_MacShowFocusRect, False) |
---|
| 110 | |
---|
| 111 | self.txtExtrapolQMin.setText(str(Q_MINIMUM)) |
---|
| 112 | self.txtExtrapolQMax.setText(str(Q_MAXIMUM)) |
---|
[f721030] | 113 | |
---|
| 114 | # Let's choose the Standard Item Model. |
---|
| 115 | self.model = QtGui.QStandardItemModel(self) |
---|
| 116 | |
---|
| 117 | # Connect buttons to slots. |
---|
| 118 | # Needs to be done early so default values propagate properly. |
---|
| 119 | self.setupSlots() |
---|
| 120 | |
---|
| 121 | # Set up the model. |
---|
| 122 | self.setupModel() |
---|
| 123 | |
---|
| 124 | # Set up the mapper |
---|
| 125 | self.setupMapper() |
---|
| 126 | |
---|
[7c487846] | 127 | # Default enablement |
---|
| 128 | self.cmdCalculate.setEnabled(False) |
---|
| 129 | |
---|
[f1f3e6a] | 130 | # validator: double |
---|
[7c487846] | 131 | self.txtBackgd.setValidator(GuiUtils.DoubleValidator()) |
---|
| 132 | self.txtContrast.setValidator(GuiUtils.DoubleValidator()) |
---|
| 133 | self.txtScale.setValidator(GuiUtils.DoubleValidator()) |
---|
| 134 | self.txtPorodCst.setValidator(GuiUtils.DoubleValidator()) |
---|
[f1f3e6a] | 135 | |
---|
| 136 | # validator: integer number |
---|
[7c487846] | 137 | self.txtNptsLowQ.setValidator(QtGui.QIntValidator()) |
---|
| 138 | self.txtNptsHighQ.setValidator(QtGui.QIntValidator()) |
---|
| 139 | self.txtPowerLowQ.setValidator(GuiUtils.DoubleValidator()) |
---|
| 140 | self.txtPowerHighQ.setValidator(GuiUtils.DoubleValidator()) |
---|
[f1f3e6a] | 141 | |
---|
| 142 | def enabling(self): |
---|
| 143 | """ """ |
---|
| 144 | self.cmdStatus.setEnabled(True) |
---|
[457d961] | 145 | |
---|
[b1e36a3] | 146 | def setClosable(self, value=True): |
---|
[f1f3e6a] | 147 | """ Allow outsiders close this widget """ |
---|
[b1e36a3] | 148 | assert isinstance(value, bool) |
---|
| 149 | |
---|
| 150 | self._allow_close = value |
---|
| 151 | |
---|
| 152 | def closeEvent(self, event): |
---|
| 153 | """ |
---|
| 154 | Overwrite QDialog close method to allow for custom widget close |
---|
| 155 | """ |
---|
| 156 | if self._allow_close: |
---|
| 157 | # reset the closability flag |
---|
| 158 | self.setClosable(value=False) |
---|
[7c487846] | 159 | # Tell the MdiArea to close the container |
---|
| 160 | self.parentWidget().close() |
---|
[b1e36a3] | 161 | event.accept() |
---|
| 162 | else: |
---|
| 163 | event.ignore() |
---|
| 164 | # Maybe we should just minimize |
---|
| 165 | self.setWindowState(QtCore.Qt.WindowMinimized) |
---|
[e540cd2] | 166 | |
---|
[f721030] | 167 | def updateFromModel(self): |
---|
[f1f3e6a] | 168 | """ Update the globals based on the data in the model """ |
---|
[f721030] | 169 | self._background = float(self.model.item(WIDGETS.W_BACKGROUND).text()) |
---|
[f1f3e6a] | 170 | self._contrast = float(self.model.item(WIDGETS.W_CONTRAST).text()) |
---|
| 171 | self._scale = float(self.model.item(WIDGETS.W_SCALE).text()) |
---|
| 172 | if self.model.item(WIDGETS.W_POROD_CST).text() != 'None' \ |
---|
| 173 | and self.model.item(WIDGETS.W_POROD_CST).text() != '': |
---|
| 174 | self._porod = float(self.model.item(WIDGETS.W_POROD_CST).text()) |
---|
| 175 | |
---|
| 176 | # Low extrapolating |
---|
| 177 | self._low_extrapolate = str(self.model.item(WIDGETS.W_ENABLE_LOWQ).text()) == 'true' |
---|
[f721030] | 178 | self._low_points = float(self.model.item(WIDGETS.W_NPTS_LOWQ).text()) |
---|
[f1f3e6a] | 179 | self._low_guinier = str(self.model.item(WIDGETS.W_LOWQ_GUINIER).text()) == 'true' |
---|
| 180 | self._low_fit = str(self.model.item(WIDGETS.W_LOWQ_FIT).text()) == 'true' |
---|
| 181 | self._low_power_value = float(self.model.item(WIDGETS.W_LOWQ_POWER_VALUE).text()) |
---|
[f721030] | 182 | |
---|
| 183 | # High extrapolating |
---|
[f1f3e6a] | 184 | self._high_extrapolate = str(self.model.item(WIDGETS.W_ENABLE_HIGHQ).text()) == 'true' |
---|
| 185 | self._high_points = float(self.model.item(WIDGETS.W_NPTS_HIGHQ).text()) |
---|
| 186 | self._high_fit = str(self.model.item(WIDGETS.W_HIGHQ_FIT).text()) == 'true' |
---|
| 187 | self._high_power_value = float(self.model.item(WIDGETS.W_HIGHQ_POWER_VALUE).text()) |
---|
[f721030] | 188 | |
---|
[a281ab8] | 189 | def calculateInvariant(self): |
---|
[f1f3e6a] | 190 | """ Use twisted to thread the calculations away """ |
---|
[f721030] | 191 | # Find out if extrapolation needs to be used. |
---|
| 192 | extrapolation = None |
---|
[f1f3e6a] | 193 | if self._low_extrapolate and not self._high_extrapolate: |
---|
[f721030] | 194 | extrapolation = "low" |
---|
[f1f3e6a] | 195 | elif not self._low_extrapolate and self._high_extrapolate: |
---|
[f721030] | 196 | extrapolation = "high" |
---|
| 197 | elif self._low_extrapolate and self._high_extrapolate: |
---|
| 198 | extrapolation = "both" |
---|
| 199 | |
---|
[f1f3e6a] | 200 | # modify the Calculate button to indicate background process |
---|
| 201 | self.cmdCalculate.setText("Calculating...") |
---|
| 202 | self.cmdCalculate.setEnabled(False) |
---|
| 203 | |
---|
| 204 | # Send the calculations to separate thread. |
---|
| 205 | d = threads.deferToThread(self.calculateThread, extrapolation) |
---|
| 206 | |
---|
| 207 | # Add deferred callback for call return |
---|
| 208 | d.addCallback(self.deferredPlot) |
---|
| 209 | d.addErrback(self.calculationFailed) |
---|
| 210 | |
---|
| 211 | def calculationFailed(self, reason): |
---|
| 212 | print("calculation failed: ", reason) |
---|
[7fb471d] | 213 | pass |
---|
[5032ea68] | 214 | |
---|
[f1f3e6a] | 215 | def deferredPlot(self, model): |
---|
[f721030] | 216 | """ |
---|
[f1f3e6a] | 217 | Run the GUI/model update in the main thread |
---|
[f721030] | 218 | """ |
---|
[f1f3e6a] | 219 | reactor.callFromThread(lambda: self.plotResult(model)) |
---|
[f721030] | 220 | |
---|
[f1f3e6a] | 221 | def plotResult(self, model): |
---|
| 222 | """ Plot result of calculation """ |
---|
[f721030] | 223 | # Set the button back to available |
---|
[f1f3e6a] | 224 | self.cmdCalculate.setEnabled(True) |
---|
| 225 | self.cmdCalculate.setText("Calculate") |
---|
| 226 | self.cmdStatus.setEnabled(True) |
---|
| 227 | |
---|
| 228 | self.model = model |
---|
| 229 | self._data = GuiUtils.dataFromItem(self._model_item) |
---|
[f721030] | 230 | |
---|
[a281ab8] | 231 | # Send the modified model item to DE for keeping in the model |
---|
[f1f3e6a] | 232 | # Currently -unused |
---|
[6cb305a] | 233 | # self.communicate.updateModelFromPerspectiveSignal.emit(self._model_item) |
---|
[f1f3e6a] | 234 | |
---|
| 235 | plot_data = GuiUtils.plotsFromCheckedItems(self._manager.filesWidget.model) |
---|
| 236 | |
---|
| 237 | self._manager.filesWidget.plotData(plot_data) |
---|
[5032ea68] | 238 | |
---|
[f1f3e6a] | 239 | # Update the details dialog in case it is open |
---|
| 240 | self.updateDetailsWidget(model) |
---|
| 241 | |
---|
| 242 | def updateDetailsWidget(self, model): |
---|
| 243 | """ |
---|
| 244 | On demand update of the details widget |
---|
| 245 | """ |
---|
| 246 | if self.detailsDialog.isVisible(): |
---|
| 247 | self.onStatus() |
---|
[f721030] | 248 | |
---|
| 249 | def calculateThread(self, extrapolation): |
---|
| 250 | """ |
---|
[5032ea68] | 251 | Perform Invariant calculations. |
---|
| 252 | TODO: Create a dictionary of results to be sent to DE on completion. |
---|
[f721030] | 253 | """ |
---|
| 254 | self.updateFromModel() |
---|
[f1f3e6a] | 255 | msg = '' |
---|
[f721030] | 256 | |
---|
| 257 | qstar_low = 0.0 |
---|
| 258 | qstar_low_err = 0.0 |
---|
| 259 | qstar_high = 0.0 |
---|
| 260 | qstar_high_err = 0.0 |
---|
| 261 | qstar_total = 0.0 |
---|
[f1f3e6a] | 262 | qstar_total_error = 0.0 |
---|
[f721030] | 263 | |
---|
[f1f3e6a] | 264 | temp_data = copy.deepcopy(self._data) |
---|
[f721030] | 265 | |
---|
[f1f3e6a] | 266 | # Prepare the invariant object |
---|
| 267 | inv = invariant.InvariantCalculator(data=temp_data, |
---|
| 268 | background=self._background, |
---|
| 269 | scale=self._scale) |
---|
[f721030] | 270 | if self._low_extrapolate: |
---|
[f1f3e6a] | 271 | |
---|
[f721030] | 272 | function_low = "power_law" |
---|
| 273 | if self._low_guinier: |
---|
| 274 | function_low = "guinier" |
---|
| 275 | if self._low_fit: |
---|
| 276 | self._low_power_value = None |
---|
[f1f3e6a] | 277 | |
---|
[f721030] | 278 | inv.set_extrapolation(range="low", |
---|
[f1f3e6a] | 279 | npts=int(self._low_points), |
---|
[f721030] | 280 | function=function_low, |
---|
| 281 | power=self._low_power_value) |
---|
| 282 | |
---|
| 283 | if self._high_extrapolate: |
---|
| 284 | function_low = "power_law" |
---|
| 285 | inv.set_extrapolation(range="high", |
---|
[f1f3e6a] | 286 | npts=int(self._high_points), |
---|
[f721030] | 287 | function=function_low, |
---|
[f1f3e6a] | 288 | power=self._high_power_value) |
---|
| 289 | # Compute invariant |
---|
[f721030] | 290 | calculation_failed = False |
---|
[f1f3e6a] | 291 | |
---|
[f721030] | 292 | try: |
---|
[f1f3e6a] | 293 | qstar_total, qstar_total_error = inv.get_qstar_with_error() |
---|
[f721030] | 294 | except Exception as ex: |
---|
[f1f3e6a] | 295 | msg += str(ex) |
---|
[f721030] | 296 | calculation_failed = True |
---|
| 297 | # Display relevant information |
---|
| 298 | item = QtGui.QStandardItem("ERROR") |
---|
| 299 | self.model.setItem(WIDGETS.W_INVARIANT, item) |
---|
| 300 | item = QtGui.QStandardItem("ERROR") |
---|
| 301 | self.model.setItem(WIDGETS.W_INVARIANT_ERR, item) |
---|
[f1f3e6a] | 302 | |
---|
[f721030] | 303 | try: |
---|
| 304 | volume_fraction, volume_fraction_error = \ |
---|
| 305 | inv.get_volume_fraction_with_error(self._contrast) |
---|
[f1f3e6a] | 306 | |
---|
[f721030] | 307 | except Exception as ex: |
---|
| 308 | calculation_failed = True |
---|
[f1f3e6a] | 309 | msg += str(ex) |
---|
[f721030] | 310 | # Display relevant information |
---|
| 311 | item = QtGui.QStandardItem("ERROR") |
---|
| 312 | self.model.setItem(WIDGETS.W_VOLUME_FRACTION, item) |
---|
| 313 | item = QtGui.QStandardItem("ERROR") |
---|
| 314 | self.model.setItem(WIDGETS.W_VOLUME_FRACTION_ERR, item) |
---|
| 315 | |
---|
[f1f3e6a] | 316 | if self._porod: |
---|
| 317 | try: |
---|
| 318 | surface, surface_error = \ |
---|
| 319 | inv.get_surface_with_error(self._contrast, self._porod) |
---|
| 320 | except Exception as ex: |
---|
| 321 | calculation_failed = True |
---|
| 322 | msg += str(ex) |
---|
| 323 | # Display relevant information |
---|
| 324 | item = QtGui.QStandardItem("ERROR") |
---|
| 325 | self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE, item) |
---|
| 326 | item = QtGui.QStandardItem("ERROR") |
---|
| 327 | self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE_ERR, item) |
---|
| 328 | else: |
---|
| 329 | surface = None |
---|
| 330 | |
---|
| 331 | if (calculation_failed): |
---|
| 332 | logging.warning('Calculation failed: {}'.format(msg)) |
---|
[f721030] | 333 | return self.model |
---|
[f1f3e6a] | 334 | else: |
---|
[f721030] | 335 | |
---|
[f1f3e6a] | 336 | if self._low_extrapolate: |
---|
| 337 | # for presentation in InvariantDetails |
---|
| 338 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
| 339 | extrapolated_data = inv.get_extra_data_low(self._low_points) |
---|
| 340 | power_low = inv.get_extrapolation_power(range='low') |
---|
| 341 | |
---|
| 342 | # Plot the chart |
---|
| 343 | title = "Low-Q extrapolation" |
---|
| 344 | |
---|
| 345 | # Convert the data into plottable |
---|
| 346 | extrapolated_data = self._manager.createGuiData(extrapolated_data) |
---|
| 347 | |
---|
| 348 | extrapolated_data.name = title |
---|
| 349 | extrapolated_data.title = title |
---|
| 350 | |
---|
| 351 | # copy labels and units of axes for plotting |
---|
| 352 | extrapolated_data._xaxis = temp_data._xaxis |
---|
| 353 | extrapolated_data._xunit = temp_data._xunit |
---|
| 354 | extrapolated_data._yaxis = temp_data._yaxis |
---|
| 355 | extrapolated_data._yunit = temp_data._yunit |
---|
| 356 | |
---|
| 357 | # Add the plot to the model item |
---|
| 358 | # This needs to run in the main thread |
---|
| 359 | reactor.callFromThread(GuiUtils.updateModelItemWithPlot, |
---|
| 360 | self._model_item, |
---|
| 361 | extrapolated_data, |
---|
| 362 | title) |
---|
| 363 | |
---|
| 364 | if self._high_extrapolate: |
---|
| 365 | # for presentation in InvariantDetails |
---|
[6cb305a] | 366 | qmax_plot = Q_MAXIMUM_PLOT * max(temp_data.x) |
---|
[f1f3e6a] | 367 | |
---|
| 368 | if qmax_plot > Q_MAXIMUM: |
---|
| 369 | qmax_plot = Q_MAXIMUM |
---|
| 370 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
| 371 | power_high = inv.get_extrapolation_power(range='high') |
---|
| 372 | high_out_data = inv.get_extra_data_high(q_end=qmax_plot, npts=500) |
---|
| 373 | |
---|
| 374 | # Plot the chart |
---|
| 375 | title = "High-Q extrapolation" |
---|
| 376 | |
---|
| 377 | # Convert the data into plottable |
---|
| 378 | high_out_data = self._manager.createGuiData(high_out_data) |
---|
| 379 | high_out_data.name = title |
---|
| 380 | high_out_data.title = title |
---|
| 381 | |
---|
| 382 | # copy labels and units of axes for plotting |
---|
| 383 | high_out_data._xaxis = temp_data._xaxis |
---|
| 384 | high_out_data._xunit = temp_data._xunit |
---|
| 385 | high_out_data._yaxis = temp_data._yaxis |
---|
| 386 | high_out_data._yunit = temp_data._yunit |
---|
| 387 | |
---|
| 388 | # Add the plot to the model item |
---|
| 389 | # This needs to run in the main thread |
---|
| 390 | reactor.callFromThread(GuiUtils.updateModelItemWithPlot, |
---|
| 391 | self._model_item, high_out_data, title) |
---|
| 392 | |
---|
| 393 | item = QtGui.QStandardItem(str(float('%.3g'% volume_fraction))) |
---|
| 394 | self.model.setItem(WIDGETS.W_VOLUME_FRACTION, item) |
---|
| 395 | item = QtGui.QStandardItem(str(float('%.3g'% volume_fraction_error))) |
---|
| 396 | self.model.setItem(WIDGETS.W_VOLUME_FRACTION_ERR, item) |
---|
| 397 | if surface: |
---|
| 398 | item = QtGui.QStandardItem(str(float('%.3g'% surface))) |
---|
| 399 | self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE, item) |
---|
| 400 | item = QtGui.QStandardItem(str(float('%.3g'% surface_error))) |
---|
| 401 | self.model.setItem(WIDGETS.W_SPECIFIC_SURFACE_ERR, item) |
---|
| 402 | item = QtGui.QStandardItem(str(float('%.3g'% qstar_total))) |
---|
| 403 | self.model.setItem(WIDGETS.W_INVARIANT, item) |
---|
| 404 | item = QtGui.QStandardItem(str(float('%.3g'% qstar_total_error))) |
---|
| 405 | self.model.setItem(WIDGETS.W_INVARIANT_ERR, item) |
---|
[1042dba] | 406 | |
---|
[f1f3e6a] | 407 | item = QtGui.QStandardItem(str(float('%.3g'% qstar_low))) |
---|
| 408 | self.model.setItem(WIDGETS.D_LOW_QSTAR, item) |
---|
| 409 | item = QtGui.QStandardItem(str(float('%.3g'% qstar_low_err))) |
---|
| 410 | self.model.setItem(WIDGETS.D_LOW_QSTAR_ERR, item) |
---|
| 411 | item = QtGui.QStandardItem(str(float('%.3g'% qstar_high))) |
---|
| 412 | self.model.setItem(WIDGETS.D_HIGH_QSTAR, item) |
---|
| 413 | item = QtGui.QStandardItem(str(float('%.3g'% qstar_high_err))) |
---|
| 414 | self.model.setItem(WIDGETS.D_HIGH_QSTAR_ERR, item) |
---|
[f721030] | 415 | |
---|
[f1f3e6a] | 416 | return self.model |
---|
[f721030] | 417 | |
---|
[5032ea68] | 418 | def title(self): |
---|
[f1f3e6a] | 419 | """ Perspective name """ |
---|
[5032ea68] | 420 | return "Invariant panel" |
---|
[f721030] | 421 | |
---|
[f1f3e6a] | 422 | def onStatus(self): |
---|
[f721030] | 423 | """ |
---|
[f1f3e6a] | 424 | Display Invariant Details panel when clicking on Status button |
---|
[f721030] | 425 | """ |
---|
| 426 | self.detailsDialog.setModel(self.model) |
---|
| 427 | self.detailsDialog.showDialog() |
---|
[f1f3e6a] | 428 | self.cmdStatus.setEnabled(False) |
---|
[f721030] | 429 | |
---|
[f1f3e6a] | 430 | def onHelp(self): |
---|
| 431 | """ Display help when clicking on Help button """ |
---|
| 432 | treeLocation = GuiUtils.HELP_DIRECTORY_LOCATION + \ |
---|
[31c5b58] | 433 | "/user/sasgui/perspectives/invariant/invariant_help.html" |
---|
[f1f3e6a] | 434 | webbrowser.open('file://' + treeLocation) |
---|
[f721030] | 435 | |
---|
| 436 | def setupSlots(self): |
---|
[f1f3e6a] | 437 | """ """ |
---|
| 438 | self.cmdCalculate.clicked.connect(self.calculateInvariant) |
---|
| 439 | self.cmdStatus.clicked.connect(self.onStatus) |
---|
| 440 | self.cmdHelp.clicked.connect(self.onHelp) |
---|
[f721030] | 441 | |
---|
[f1f3e6a] | 442 | self.chkLowQ.stateChanged.connect(self.stateChanged) |
---|
| 443 | self.chkLowQ.stateChanged.connect(self.checkQExtrapolatedData) |
---|
[f721030] | 444 | |
---|
[f1f3e6a] | 445 | self.chkHighQ.stateChanged.connect(self.stateChanged) |
---|
| 446 | self.chkHighQ.stateChanged.connect(self.checkQExtrapolatedData) |
---|
[f721030] | 447 | |
---|
[f1f3e6a] | 448 | # slots for the Guinier and PowerLaw radio buttons at low Q |
---|
| 449 | # since they are not auto-exclusive |
---|
| 450 | self.rbGuinier.toggled.connect(self.lowGuinierAndPowerToggle) |
---|
| 451 | |
---|
| 452 | self.rbPowerLawLowQ.toggled.connect(self.lowGuinierAndPowerToggle) |
---|
| 453 | |
---|
| 454 | self.rbFitHighQ.toggled.connect(self.hiFitAndFixToggle) |
---|
| 455 | |
---|
| 456 | self.rbFitLowQ.toggled.connect(self.lowFitAndFixToggle) |
---|
[f721030] | 457 | |
---|
| 458 | self.model.itemChanged.connect(self.modelChanged) |
---|
| 459 | |
---|
[f1f3e6a] | 460 | # update model from gui editing by users |
---|
| 461 | self.txtBackgd.textChanged.connect(self.updateFromGui) |
---|
| 462 | |
---|
| 463 | self.txtScale.textChanged.connect(self.updateFromGui) |
---|
| 464 | |
---|
| 465 | self.txtContrast.textChanged.connect(self.updateFromGui) |
---|
| 466 | |
---|
| 467 | self.txtPorodCst.textChanged.connect(self.updateFromGui) |
---|
| 468 | |
---|
| 469 | self.txtPowerLowQ.textChanged.connect(self.updateFromGui) |
---|
| 470 | |
---|
| 471 | self.txtPowerHighQ.textChanged.connect(self.updateFromGui) |
---|
| 472 | |
---|
| 473 | self.txtNptsLowQ.textChanged.connect(self.updateFromGui) |
---|
| 474 | |
---|
| 475 | self.txtNptsHighQ.textChanged.connect(self.updateFromGui) |
---|
| 476 | |
---|
| 477 | # check values of n_points compared to distribution length |
---|
| 478 | if self.txtNptsLowQ.isEnabled(): |
---|
| 479 | self.txtNptsLowQ.textChanged.connect(self.checkLength) |
---|
| 480 | |
---|
| 481 | if self.txtNptsHighQ.isEnabled(): |
---|
| 482 | self.txtNptsHighQ.textChanged.connect(self.checkLength) |
---|
| 483 | |
---|
| 484 | def stateChanged(self): |
---|
[f721030] | 485 | """ |
---|
[f1f3e6a] | 486 | Catch modifications from low- and high-Q extrapolation check boxes |
---|
[f721030] | 487 | """ |
---|
[f1f3e6a] | 488 | sender = self.sender() |
---|
| 489 | |
---|
| 490 | itemf = QtGui.QStandardItem(str(sender.isChecked()).lower()) |
---|
| 491 | if sender.text() == 'Enable Low-Q extrapolation': |
---|
| 492 | self.model.setItem(WIDGETS.W_ENABLE_LOWQ, itemf) |
---|
| 493 | |
---|
| 494 | if sender.text() == 'Enable High-Q extrapolation': |
---|
| 495 | self.model.setItem(WIDGETS.W_ENABLE_HIGHQ, itemf) |
---|
| 496 | |
---|
| 497 | def checkLength(self): |
---|
| 498 | """ |
---|
| 499 | Validators of number of points for extrapolation. |
---|
| 500 | Error if it is larger than the distribution length |
---|
| 501 | """ |
---|
[7c487846] | 502 | try: |
---|
| 503 | int_value = int(self.sender().text()) |
---|
| 504 | except ValueError: |
---|
| 505 | self.sender().setStyleSheet(BG_RED) |
---|
| 506 | self.cmdCalculate.setEnabled(False) |
---|
| 507 | return |
---|
| 508 | |
---|
[f1f3e6a] | 509 | if self._data: |
---|
[7c487846] | 510 | if len(self._data.x) < int_value: |
---|
| 511 | self.sender().setStyleSheet(BG_RED) |
---|
[f1f3e6a] | 512 | logging.warning('The number of points must be smaller than {}'.format(len(self._data.x))) |
---|
| 513 | self.cmdCalculate.setEnabled(False) |
---|
| 514 | else: |
---|
[7c487846] | 515 | self.sender().setStyleSheet(BG_WHITE) |
---|
[f1f3e6a] | 516 | self.cmdCalculate.setEnabled(True) |
---|
| 517 | else: |
---|
| 518 | # logging.info('no data is loaded') |
---|
| 519 | self.cmdCalculate.setEnabled(False) |
---|
| 520 | |
---|
| 521 | def modelChanged(self, item): |
---|
| 522 | """ Update when model changed """ |
---|
[f721030] | 523 | if item.row() == WIDGETS.W_ENABLE_LOWQ: |
---|
| 524 | toggle = (str(item.text()) == 'true') |
---|
| 525 | self._low_extrapolate = toggle |
---|
| 526 | self.lowQToggle(toggle) |
---|
| 527 | elif item.row() == WIDGETS.W_ENABLE_HIGHQ: |
---|
| 528 | toggle = (str(item.text()) == 'true') |
---|
| 529 | self._high_extrapolate = toggle |
---|
| 530 | self.highQToggle(toggle) |
---|
[f1f3e6a] | 531 | |
---|
| 532 | def checkQExtrapolatedData(self): |
---|
[f721030] | 533 | """ |
---|
[f1f3e6a] | 534 | Match status of low or high-Q extrapolated data checkbox in |
---|
| 535 | DataExplorer with low or high-Q extrapolation checkbox in invariant |
---|
| 536 | panel |
---|
[f721030] | 537 | """ |
---|
[f1f3e6a] | 538 | # name to search in DataExplorer |
---|
| 539 | if 'Low' in str(self.sender().text()): |
---|
| 540 | name = "Low-Q extrapolation" |
---|
| 541 | if 'High' in str(self.sender().text()): |
---|
| 542 | name = "High-Q extrapolation" |
---|
[f721030] | 543 | |
---|
[f1f3e6a] | 544 | GuiUtils.updateModelItemStatus(self._manager.filesWidget.model, |
---|
| 545 | self._path, name, |
---|
| 546 | self.sender().checkState()) |
---|
| 547 | |
---|
| 548 | def updateFromGui(self): |
---|
| 549 | """ Update model when new user inputs """ |
---|
| 550 | possible_senders = ['txtBackgd', 'txtContrast', 'txtPorodCst', |
---|
| 551 | 'txtScale', 'txtPowerLowQ', 'txtPowerHighQ', |
---|
| 552 | 'txtNptsLowQ', 'txtNptsHighQ'] |
---|
| 553 | |
---|
| 554 | related_widgets = [WIDGETS.W_BACKGROUND, WIDGETS.W_CONTRAST, |
---|
| 555 | WIDGETS.W_POROD_CST, WIDGETS.W_SCALE, |
---|
| 556 | WIDGETS.W_LOWQ_POWER_VALUE, WIDGETS.W_HIGHQ_POWER_VALUE, |
---|
| 557 | WIDGETS.W_NPTS_LOWQ, WIDGETS.W_NPTS_HIGHQ] |
---|
| 558 | |
---|
| 559 | related_internal_values = [self._background, self._contrast, |
---|
| 560 | self._porod, self._scale, |
---|
| 561 | self._low_power_value, |
---|
| 562 | self._high_power_value, |
---|
| 563 | self._low_points, self._high_points] |
---|
| 564 | |
---|
| 565 | item = QtGui.QStandardItem(self.sender().text()) |
---|
| 566 | |
---|
| 567 | index_elt = possible_senders.index(self.sender().objectName()) |
---|
| 568 | |
---|
| 569 | self.model.setItem(related_widgets[index_elt], item) |
---|
[7c487846] | 570 | try: |
---|
| 571 | related_internal_values[index_elt] = float(self.sender().text()) |
---|
| 572 | self.sender().setStyleSheet(BG_WHITE) |
---|
| 573 | self.cmdCalculate.setEnabled(True) |
---|
| 574 | except ValueError: |
---|
| 575 | # empty field, just skip |
---|
| 576 | self.sender().setStyleSheet(BG_RED) |
---|
| 577 | self.cmdCalculate.setEnabled(False) |
---|
[f1f3e6a] | 578 | |
---|
| 579 | def lowGuinierAndPowerToggle(self, toggle): |
---|
[f721030] | 580 | """ |
---|
[f1f3e6a] | 581 | Guinier and Power radio buttons cannot be selected at the same time |
---|
| 582 | If Power is selected, Fit and Fix radio buttons are visible and |
---|
| 583 | Power line edit can be edited if Fix is selected |
---|
[f721030] | 584 | """ |
---|
[f1f3e6a] | 585 | if self.sender().text() == 'Guinier': |
---|
| 586 | self._low_guinier = toggle |
---|
| 587 | |
---|
| 588 | toggle = not toggle |
---|
| 589 | self.rbPowerLawLowQ.setChecked(toggle) |
---|
| 590 | |
---|
| 591 | self.rbFitLowQ.toggled.connect(self.lowFitAndFixToggle) |
---|
| 592 | self.rbFitLowQ.setVisible(toggle) |
---|
| 593 | self.rbFixLowQ.setVisible(toggle) |
---|
| 594 | |
---|
| 595 | self.txtPowerLowQ.setEnabled(toggle and (not self._low_fit)) |
---|
| 596 | |
---|
| 597 | else: |
---|
| 598 | self._low_guinier = not toggle |
---|
| 599 | |
---|
| 600 | self.rbGuinier.setChecked(not toggle) |
---|
| 601 | |
---|
| 602 | self.rbFitLowQ.toggled.connect(self.lowFitAndFixToggle) |
---|
| 603 | self.rbFitLowQ.setVisible(toggle) |
---|
| 604 | self.rbFixLowQ.setVisible(toggle) |
---|
| 605 | |
---|
| 606 | self.txtPowerLowQ.setEnabled(toggle and (not self._low_fit)) |
---|
| 607 | |
---|
| 608 | def lowFitAndFixToggle(self, toggle): |
---|
| 609 | """ Fit and Fix radiobuttons cannot be selected at the same time """ |
---|
[f721030] | 610 | self._low_fit = toggle |
---|
[f1f3e6a] | 611 | |
---|
[f721030] | 612 | toggle = not toggle |
---|
[f1f3e6a] | 613 | self.txtPowerLowQ.setEnabled(toggle) |
---|
[f721030] | 614 | |
---|
| 615 | def hiFitAndFixToggle(self, toggle): |
---|
| 616 | """ |
---|
[f1f3e6a] | 617 | Enable editing of power exponent if Fix for high Q is checked |
---|
| 618 | Disable otherwise |
---|
[f721030] | 619 | """ |
---|
[f1f3e6a] | 620 | self.txtPowerHighQ.setEnabled(not toggle) |
---|
[f721030] | 621 | |
---|
| 622 | def highQToggle(self, clicked): |
---|
[f1f3e6a] | 623 | """ Disable/enable High Q extrapolation """ |
---|
| 624 | self.rbFitHighQ.setEnabled(clicked) |
---|
| 625 | self.rbFixHighQ.setEnabled(clicked) |
---|
| 626 | self.txtNptsHighQ.setEnabled(clicked) |
---|
| 627 | self.txtPowerHighQ.setEnabled(clicked) |
---|
[f721030] | 628 | |
---|
| 629 | def lowQToggle(self, clicked): |
---|
[f1f3e6a] | 630 | """ Disable / enable Low Q extrapolation """ |
---|
| 631 | self.rbGuinier.setEnabled(clicked) |
---|
| 632 | self.rbPowerLawLowQ.setEnabled(clicked) |
---|
| 633 | self.txtNptsLowQ.setEnabled(clicked) |
---|
[f721030] | 634 | # Enable subelements |
---|
[f1f3e6a] | 635 | self.rbFitLowQ.setVisible(self.rbPowerLawLowQ.isChecked()) |
---|
| 636 | self.rbFixLowQ.setVisible(self.rbPowerLawLowQ.isChecked()) |
---|
| 637 | self.rbFitLowQ.setEnabled(clicked) # and not self._low_guinier) |
---|
| 638 | self.rbFixLowQ.setEnabled(clicked) # and not self._low_guinier) |
---|
[f721030] | 639 | |
---|
[f1f3e6a] | 640 | self.txtPowerLowQ.setEnabled(clicked |
---|
| 641 | and not self._low_guinier |
---|
| 642 | and not self._low_fit) |
---|
[f721030] | 643 | |
---|
[f1f3e6a] | 644 | def setupModel(self): |
---|
| 645 | """ """ |
---|
[f721030] | 646 | # filename |
---|
| 647 | item = QtGui.QStandardItem(self._path) |
---|
| 648 | self.model.setItem(WIDGETS.W_FILENAME, item) |
---|
| 649 | |
---|
| 650 | # add Q parameters to the model |
---|
[469b4622] | 651 | qmin = 0.0 |
---|
[f721030] | 652 | item = QtGui.QStandardItem(str(qmin)) |
---|
| 653 | self.model.setItem(WIDGETS.W_QMIN, item) |
---|
[469b4622] | 654 | qmax = 0.0 |
---|
| 655 | item = QtGui.QStandardItem(str(qmax)) |
---|
[f721030] | 656 | self.model.setItem(WIDGETS.W_QMAX, item) |
---|
| 657 | |
---|
| 658 | # add custom input params |
---|
| 659 | item = QtGui.QStandardItem(str(self._background)) |
---|
| 660 | self.model.setItem(WIDGETS.W_BACKGROUND, item) |
---|
| 661 | item = QtGui.QStandardItem(str(self._contrast)) |
---|
| 662 | self.model.setItem(WIDGETS.W_CONTRAST, item) |
---|
| 663 | item = QtGui.QStandardItem(str(self._scale)) |
---|
| 664 | self.model.setItem(WIDGETS.W_SCALE, item) |
---|
[f1f3e6a] | 665 | # leave line edit empty if Porod constant not defined |
---|
| 666 | if self._porod != None: |
---|
| 667 | item = QtGui.QStandardItem(str(self._porod)) |
---|
| 668 | else: |
---|
| 669 | item = QtGui.QStandardItem(str('')) |
---|
| 670 | self.model.setItem(WIDGETS.W_POROD_CST, item) |
---|
| 671 | |
---|
[f721030] | 672 | # Dialog elements |
---|
| 673 | itemf = QtGui.QStandardItem("false") |
---|
| 674 | self.model.setItem(WIDGETS.W_ENABLE_HIGHQ, itemf) |
---|
| 675 | itemf = QtGui.QStandardItem("false") |
---|
| 676 | self.model.setItem(WIDGETS.W_ENABLE_LOWQ, itemf) |
---|
| 677 | |
---|
[f1f3e6a] | 678 | item = QtGui.QStandardItem(str(NPOINTS_Q_INTERP)) |
---|
[f721030] | 679 | self.model.setItem(WIDGETS.W_NPTS_LOWQ, item) |
---|
[f1f3e6a] | 680 | item = QtGui.QStandardItem(str(NPOINTS_Q_INTERP)) |
---|
[f721030] | 681 | self.model.setItem(WIDGETS.W_NPTS_HIGHQ, item) |
---|
| 682 | |
---|
| 683 | itemt = QtGui.QStandardItem("true") |
---|
| 684 | self.model.setItem(WIDGETS.W_LOWQ_GUINIER, itemt) |
---|
| 685 | |
---|
| 686 | itemt = QtGui.QStandardItem("true") |
---|
| 687 | self.model.setItem(WIDGETS.W_LOWQ_FIT, itemt) |
---|
[f1f3e6a] | 688 | item = QtGui.QStandardItem(str(DEFAULT_POWER_LOW)) |
---|
[f721030] | 689 | self.model.setItem(WIDGETS.W_LOWQ_POWER_VALUE, item) |
---|
| 690 | |
---|
| 691 | itemt = QtGui.QStandardItem("true") |
---|
| 692 | self.model.setItem(WIDGETS.W_HIGHQ_FIT, itemt) |
---|
[f1f3e6a] | 693 | item = QtGui.QStandardItem(str(DEFAULT_POWER_LOW)) |
---|
[f721030] | 694 | self.model.setItem(WIDGETS.W_HIGHQ_POWER_VALUE, item) |
---|
| 695 | |
---|
| 696 | def setupMapper(self): |
---|
| 697 | # Set up the mapper. |
---|
[4992ff2] | 698 | self.mapper = QtWidgets.QDataWidgetMapper(self) |
---|
[f721030] | 699 | self.mapper.setOrientation(QtCore.Qt.Vertical) |
---|
| 700 | self.mapper.setModel(self.model) |
---|
| 701 | |
---|
| 702 | # Filename |
---|
[f1f3e6a] | 703 | self.mapper.addMapping(self.txtName, WIDGETS.W_FILENAME) |
---|
| 704 | |
---|
[f721030] | 705 | # Qmin/Qmax |
---|
[f1f3e6a] | 706 | self.mapper.addMapping(self.txtTotalQMin, WIDGETS.W_QMIN) |
---|
| 707 | self.mapper.addMapping(self.txtTotalQMax, WIDGETS.W_QMAX) |
---|
[f721030] | 708 | |
---|
| 709 | # Background |
---|
[f1f3e6a] | 710 | self.mapper.addMapping(self.txtBackgd, WIDGETS.W_BACKGROUND) |
---|
| 711 | |
---|
[f721030] | 712 | # Scale |
---|
[f1f3e6a] | 713 | self.mapper.addMapping(self.txtScale, WIDGETS.W_SCALE) |
---|
| 714 | |
---|
[f721030] | 715 | # Contrast |
---|
[f1f3e6a] | 716 | self.mapper.addMapping(self.txtContrast, WIDGETS.W_CONTRAST) |
---|
[f721030] | 717 | |
---|
[f1f3e6a] | 718 | # Porod constant |
---|
| 719 | self.mapper.addMapping(self.txtPorodCst, WIDGETS.W_POROD_CST) |
---|
[f721030] | 720 | |
---|
[f1f3e6a] | 721 | # Lowq/Highq items |
---|
| 722 | self.mapper.addMapping(self.chkLowQ, WIDGETS.W_ENABLE_LOWQ) |
---|
| 723 | self.mapper.addMapping(self.chkHighQ, WIDGETS.W_ENABLE_HIGHQ) |
---|
[f721030] | 724 | |
---|
[f1f3e6a] | 725 | self.mapper.addMapping(self.txtNptsLowQ, WIDGETS.W_NPTS_LOWQ) |
---|
| 726 | self.mapper.addMapping(self.rbGuinier, WIDGETS.W_LOWQ_GUINIER) |
---|
| 727 | self.mapper.addMapping(self.rbFitLowQ, WIDGETS.W_LOWQ_FIT) |
---|
| 728 | self.mapper.addMapping(self.txtPowerLowQ, WIDGETS.W_LOWQ_POWER_VALUE) |
---|
[f721030] | 729 | |
---|
[f1f3e6a] | 730 | self.mapper.addMapping(self.txtNptsHighQ, WIDGETS.W_NPTS_HIGHQ) |
---|
| 731 | self.mapper.addMapping(self.rbFitHighQ, WIDGETS.W_HIGHQ_FIT) |
---|
| 732 | self.mapper.addMapping(self.txtPowerHighQ, WIDGETS.W_HIGHQ_POWER_VALUE) |
---|
[f721030] | 733 | |
---|
| 734 | # Output |
---|
[f1f3e6a] | 735 | self.mapper.addMapping(self.txtVolFract, WIDGETS.W_VOLUME_FRACTION) |
---|
| 736 | self.mapper.addMapping(self.txtVolFractErr, WIDGETS.W_VOLUME_FRACTION_ERR) |
---|
| 737 | self.mapper.addMapping(self.txtSpecSurf, WIDGETS.W_SPECIFIC_SURFACE) |
---|
| 738 | self.mapper.addMapping(self.txtSpecSurfErr, WIDGETS.W_SPECIFIC_SURFACE_ERR) |
---|
| 739 | self.mapper.addMapping(self.txtInvariantTot, WIDGETS.W_INVARIANT) |
---|
| 740 | self.mapper.addMapping(self.txtInvariantTotErr, WIDGETS.W_INVARIANT_ERR) |
---|
[f721030] | 741 | |
---|
[f1f3e6a] | 742 | self.mapper.toFirst() |
---|
[f721030] | 743 | |
---|
[f1f3e6a] | 744 | def setData(self, data_item=None, is_batch=False): |
---|
[a281ab8] | 745 | """ |
---|
| 746 | Obtain a QStandardItem object and dissect it to get Data1D/2D |
---|
| 747 | Pass it over to the calculator |
---|
| 748 | """ |
---|
[f1f3e6a] | 749 | assert data_item is not None |
---|
| 750 | |
---|
| 751 | if self.txtName.text() == data_item[0].text(): |
---|
| 752 | logging.info('This file is already loaded in Invariant panel.') |
---|
| 753 | return |
---|
| 754 | |
---|
[a281ab8] | 755 | if not isinstance(data_item, list): |
---|
| 756 | msg = "Incorrect type passed to the Invariant Perspective" |
---|
[b3e8629] | 757 | raise AttributeError(msg) |
---|
[a281ab8] | 758 | |
---|
| 759 | if not isinstance(data_item[0], QtGui.QStandardItem): |
---|
| 760 | msg = "Incorrect type passed to the Invariant Perspective" |
---|
[b3e8629] | 761 | raise AttributeError(msg) |
---|
[a281ab8] | 762 | |
---|
[f1f3e6a] | 763 | # only 1 file can be loaded |
---|
[a281ab8] | 764 | self._model_item = data_item[0] |
---|
| 765 | |
---|
| 766 | # Extract data on 1st child - this is the Data1D/2D component |
---|
[8548d739] | 767 | data = GuiUtils.dataFromItem(self._model_item) |
---|
[7c487846] | 768 | self.model.item(WIDGETS.W_FILENAME).setData(self._model_item.text()) |
---|
[f1f3e6a] | 769 | # update GUI and model with info from loaded data |
---|
| 770 | self.updateGuiFromFile(data=data) |
---|
[a281ab8] | 771 | |
---|
[f1f3e6a] | 772 | def updateGuiFromFile(self, data=None): |
---|
[f721030] | 773 | """ |
---|
[f1f3e6a] | 774 | update display in GUI and plot |
---|
[f721030] | 775 | """ |
---|
[f1f3e6a] | 776 | self._data = data |
---|
| 777 | |
---|
| 778 | # plot loaded file |
---|
| 779 | if not isinstance(self._data, Data1D): |
---|
| 780 | msg = "Error(s) occurred: Invariant cannot be computed with 2D data." |
---|
| 781 | raise AttributeError(msg) |
---|
| 782 | |
---|
| 783 | try: |
---|
| 784 | filename = data.filename |
---|
| 785 | except: |
---|
| 786 | msg = 'No filename' |
---|
| 787 | raise ValueError(msg) |
---|
| 788 | try: |
---|
| 789 | qmin = min(self._data.x) |
---|
| 790 | qmax = max(self._data.x) |
---|
| 791 | except: |
---|
| 792 | msg = "Unable to find q min/max of \n data named %s" % \ |
---|
| 793 | data.filename |
---|
| 794 | raise ValueError(msg) |
---|
| 795 | |
---|
| 796 | # update model with input form files: filename, qmin, qmax |
---|
| 797 | self.model.item(WIDGETS.W_FILENAME).setText(filename) |
---|
| 798 | self.model.item(WIDGETS.W_QMIN).setText(str(qmin)) |
---|
| 799 | self.model.item(WIDGETS.W_QMAX).setText(str(qmax)) |
---|
| 800 | self._path = filename |
---|
| 801 | |
---|
| 802 | # Calculate and add to GUI: volume fraction, invariant total, |
---|
| 803 | # and specific surface if porod checked |
---|
| 804 | self.calculateInvariant() |
---|
[f721030] | 805 | |
---|
[5032ea68] | 806 | def allowBatch(self): |
---|
| 807 | """ |
---|
| 808 | Tell the caller that we don't accept multiple data instances |
---|
| 809 | """ |
---|
| 810 | return False |
---|