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