Skip to content

Commit

Permalink
Few housekeeping changes. tried to fix 2D plotting issue, but I can't…
Browse files Browse the repository at this point in the history
… seem get to run with the following code

```
        GuiUtils.updateModelItemWithPlot(item, new_plot, new_plot.id)

        self.base.manager.communicator.plotUpdateSignal.emit([new_plot])
        self.base.manager.communicator.forcePlotDisplaySignal.emit([item, new_plot])
```

changes made using feedback from:

1) #2181 (comment)
removed as it was something that I was testing out but didn't end up using.

2) #2181 (comment)
Moved closeEvent() from InversionWidget.py to InversionPerspective.py.

3) #2181 (comment)
changed `from sas.sascalc.dataloader.manipulations import SectorQ` to `from sasdata.data_util.manipulations import SectorQ`
  • Loading branch information
ru4en authored and krzywon committed Oct 25, 2024
1 parent 4cdf997 commit 6070541
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 67 deletions.
25 changes: 19 additions & 6 deletions src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def __init__(self, parent=None):
self.supports_reports = True
self.supports_fitting_menu= False



# The window should not close
self._allowClose = False

Expand Down Expand Up @@ -123,10 +121,6 @@ def __init__(self, parent=None):
######################################################################
# Batch Mode and Tab Functions

def calculate(self):
# Default to background estimate
self._calculator.est_bck = True

def resetTab(self, index):
"""
Adds a new tab and removes the last tab
Expand Down Expand Up @@ -222,6 +216,25 @@ def isSerializable(self):
"""
return True

def closeEvent(self, event):
"""
Overwrite QDialog close method to allow for custom widget close
"""
# Close report widgets before closing/minimizing main widget
self.closeDMax()
self.closeBatchResults()
if self._allowClose:
# reset the closability flag
self.setClosable(value=False)
# Tell the MdiArea to close the container if it is visible
if self.parentWidget():
self.parentWidget().close()
event.accept()
else:
event.ignore()
# Maybe we should just minimize
self.setWindowState(QtCore.Qt.WindowMinimized)

def closeDMax(self):
if self.dmaxWindow is not None:
self.dmaxWindow.close()
Expand Down
97 changes: 38 additions & 59 deletions src/sas/qtgui/Perspectives/Inversion/InversionWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Batch calculation display
from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel
from ...Plotting.Plotter import Plotter
from ...Plotting.Plotter2D import Plotter2D
from ...Plotting.Plotter2D import Plotter2D, Plotter2DWidget
from ...Plotting.Slicers.SectorSlicer import SectorInteractor


Expand All @@ -29,6 +29,7 @@ def is_float(value):
except ValueError:
return 0.0


# Default Values for inputs
NUMBER_OF_TERMS = 10
REGULARIZATION = 0.0001
Expand Down Expand Up @@ -58,23 +59,26 @@ class InversionWidget(QtWidgets.QWidget, Ui_PrInversion):
estimateDynamicSignal = QtCore.pyqtSignal(tuple)
calculateSignal = QtCore.pyqtSignal(tuple)

plotUpdateSignal = QtCore.pyqtSignal(list)
forcePlotDisplaySignal = QtCore.pyqtSignal(list)

def __init__(self, parent=None, data=None, tab_id=1):
super(InversionWidget, self).__init__()

# 2D Data globals #####################

self.is2D = False # used to determine weather its a 2D tab
self.isSlicing = False # used to determine weather 2D data is being sliced
self.startPoint = None # start point for where to start slicing
self.noOfSlices = None # number of slices
self.slices = {} # List to store the slices from 2D data
self.is2D = False # used to determine weather its a 2D tab
self.isSlicing = False # used to determine weather 2D data is being sliced
self.startPoint = None # start point for where to start slicing
self.noOfSlices = None # number of slices
self.slices = {} # List to store the slices from 2D data
self.isSliced = False

# Slice values

self.phi = None # Phi Value of slice
self.deltaPhi = None # Number of slicer
self.qbins = None # Number of points on plot
self.phi = None # Phi Value of slice
self.deltaPhi = None # Number of slicer
self.qbins = None # Number of points on plot

# 2D Data Plot

Expand Down Expand Up @@ -104,13 +108,8 @@ def __init__(self, parent=None, data=None, tab_id=1):
self.communicate.dataDeletedSignal.connect(self.removeData)
self.batchResults = {}

self.plot2D = Plotter2D(quickplot=True)
self.plot1D = Plotter(quickplot=True)
self.logic = InversionLogic()

# Allow Tabs to close
self._allowClose = True

# current QStandardItem showing on the panel
self._data = None

Expand All @@ -131,6 +130,8 @@ def __init__(self, parent=None, data=None, tab_id=1):
# plots of self._data
self.prPlot = None
self.dataPlot = None
self.plot2D = None
self.plot1D = Plotter(quickplot=True)

# suggested nTerms
self.nTermsSuggested = NUMBER_OF_TERMS
Expand Down Expand Up @@ -189,51 +190,19 @@ def allowSwap(self):
"""
return False

def setClosable(self, value=True):
"""
Allow outsiders close this widget
"""
assert isinstance(value, bool)
self._allowClose = value

def setPlotable(self, value=True):
"""
Let Plots to be displayable - needed so batch mode is not clutter with plots
"""
assert isinstance(value, bool)
self._allowPlots = value

def isClosable(self):
"""
Allow outsiders close this widget
"""
return self._allowClose

def isSerializable(self):
"""
Tell the caller that this perspective writes its state
"""
return True

def closeEvent(self, event):
"""
Overwrite QDialog close method to allow for custom widget close
"""
# Close report widgets before closing/minimizing main widget
self.closeDMax()
self.closeBatchResults()
if self._allowClose:
# reset the closability flag
self.setClosable(value=False)
# Tell the MdiArea to close the container if it is visible
if self.parentWidget():
self.parentWidget().close()
event.accept()
else:
event.ignore()
# Maybe we should just minimize
self.setWindowState(QtCore.Qt.WindowMinimized)

def closeDMax(self):
if self.dmaxWindow is not None:
self.dmaxWindow.close()
Expand Down Expand Up @@ -281,6 +250,7 @@ def setupLinks(self):
self.estimateSignal.connect(self._estimateUpdate)
self.calculateSignal.connect(self._calculateUpdate)
self.maxDistanceInput.textEdited.connect(self.performEstimateDynamic)
self.plotUpdateSignal.connect(lambda: print('Plot'))

def setupMapper(self):
# Set up the mapper.
Expand Down Expand Up @@ -528,7 +498,6 @@ def stopCalculation(self):
self.stopCalcThread()
self.stopEstimationThread()
self.stopEstimateNTThread()

# Show any batch calculations that successfully completed
if self.isBatch and self.batchResultsWindow is not None:
self.showBatchOutput()
Expand Down Expand Up @@ -618,7 +587,7 @@ def resetCalcPrams(self):
self._calculator.set_alpha(self._calculator.regConst)
self._calculator.set_dmax(self._calculator.d_max)

self.updateCalculator() # sets Background
self.updateCalculator() # sets Background

def getState(self):
"""
Expand Down Expand Up @@ -917,7 +886,7 @@ def startThread(self):
self.stopCalcThread()

pr = self._calculator.clone()
#Making sure that nfunc and alpha parameters are correctly initialized
# Making sure that nfunc and alpha parameters are correctly initialized
pr.suggested_alpha = self._calculator.alpha
self.calcThread = CalcPr(pr, self.getNFunc(),
error_func=self._threadError,
Expand Down Expand Up @@ -1068,6 +1037,9 @@ def _estimateDynamicUpdate(self, output_tuple):
logger.info(message)
self.performEstimateDynamicNT()

def _plotUpdate(self):
print("Plotting update")

def _estimateNTCompleted(self, nterms, alpha, message, elapsed):
''' Send a signal to the main thread for model update'''
self.estimateNTSignal.emit((nterms, alpha, message, elapsed))
Expand Down Expand Up @@ -1206,12 +1178,13 @@ def slice(self):
from functools import partial
self.plot1D.plot(slice)
self.plot1D.show()
self.sliceList.setItem(row, 0, QtWidgets.QTableWidgetItem(slice.title)) # sets the title
self.sliceList.setItem(row, 1, QtWidgets.QTableWidgetItem(str(slice.phi))) # sets the phi
self.sliceList.setItem(row, 2, QtWidgets.QTableWidgetItem(str(slice.startPoint))) # sets the start Point
self.sliceList.setItem(row, 3, QtWidgets.QTableWidgetItem(str(slice.noOfSlices))) # sets the number of slices
self.sliceList.setItem(row, 4, QtWidgets.QTableWidgetItem(str(slice.Qbin))) # set Number of points on plot
self.sliceList.setItem(row, 5, QtWidgets.QTableWidgetItem(str(slice.deltaPhi))) # set Delta phi
self.sliceList.setItem(row, 0, QtWidgets.QTableWidgetItem(slice.title)) # sets the title
self.sliceList.setItem(row, 1, QtWidgets.QTableWidgetItem(str(slice.phi))) # sets the phi
self.sliceList.setItem(row, 2, QtWidgets.QTableWidgetItem(str(slice.startPoint))) # sets the start Point
self.sliceList.setItem(row, 3,
QtWidgets.QTableWidgetItem(str(slice.noOfSlices))) # sets the number of slices
self.sliceList.setItem(row, 4, QtWidgets.QTableWidgetItem(str(slice.Qbin))) # set Number of points on plot
self.sliceList.setItem(row, 5, QtWidgets.QTableWidgetItem(str(slice.deltaPhi))) # set Delta phi
plotButton = QtWidgets.QPushButton(str(slice.phi))
self.sliceList.setCellWidget(row, 6, plotButton)
plotButton.clicked.connect(partial(self.show1DPlot, slice))
Expand Down Expand Up @@ -1247,11 +1220,15 @@ def show2DPlot(self):
"""
Show 2D plot representing the raw 2D data
"""
self.plot2D.plot(data=self.logic.data, marker='-')
self.plot2D._item = self.plot2D
self.plot2D.setSlicer(SectorInteractor)
# data = GuiUtils.dataFromItem(s)

self.plot2D = Plotter2D(self, quickplot=True)
self.plot2D.data = self.logic.data
self.plot2D.plot()
self.plot2D.item = self.tabMain
self.plot2D.onSectorView()

self.plot2D.show()
self.updateSlicerParams()
self.enableButtons()

def show1DPlot(self, data):
Expand Down Expand Up @@ -1320,6 +1297,7 @@ def muiltiSlicer(self):
self.phi += self.deltaPhi
return listOfSlices


class InversionWidget2D(InversionWidget):
"""
TO DO In the future:
Expand All @@ -1329,5 +1307,6 @@ class InversionWidget2D(InversionWidget):
"""
pass


def debug(checkpoint):
print(" - - - - - - - - [ DEBUG :: Checkpoint {} ] - - - - - - - - ".format(checkpoint))
3 changes: 1 addition & 2 deletions src/sas/qtgui/Plotting/Slicers/SectorSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self, base, axes, item=None, color='black', zorder=3):
self.markers = []
self.axes = axes
self._item = item
self.data = self.base.data[0]

# Connect the plot to event
self.connect = self.base.connect
Expand Down Expand Up @@ -299,7 +298,7 @@ def getSlice(self, nbins=None):
if data is None:
return
# Averaging
from sas.sascalc.dataloader.manipulations import SectorQ
from sasdata.data_util.manipulations import SectorQ
radius = self.qmax
phimin = -self.left_line.phi + self.main_line.theta
phimax = self.left_line.phi + self.main_line.theta
Expand Down

0 comments on commit 6070541

Please sign in to comment.