Skip to content

Commit

Permalink
reimplement skipping artificial normalization (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
rboston628 authored Nov 14, 2024
1 parent 74da998 commit c92d475
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
65 changes: 29 additions & 36 deletions src/snapred/ui/view/reduction/ArtificialNormalizationView.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import matplotlib.pyplot as plt
from mantid.plots.datafunctions import get_spectrum
from mantid.simpleapi import mtd
from qtpy.QtCore import Qt, Signal, Slot
from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import (
QFrame,
QGridLayout,
QHBoxLayout,
QLabel,
QLineEdit,
QMessageBox,
QPushButton,
Expand All @@ -26,8 +27,9 @@ class ArtificialNormalizationView(BackendRequestView):
def __init__(self, parent=None):
super().__init__(parent=parent)

# create the run number fields
# create the run number field
self.fieldRunNumber = self._labeledField("Run Number", QLineEdit())
self.fieldRunNumber.setEnabled(False)

# create the graph elements
self.figure = plt.figure(constrained_layout=True)
Expand All @@ -38,10 +40,6 @@ def __init__(self, parent=None):
self.lssDropdown = self._trueFalseDropDown("LSS")
self.decreaseParameterDropdown = self._trueFalseDropDown("Decrease Parameter")

# disable run number
for x in [self.fieldRunNumber]:
x.setEnabled(False)

# create the adjustment controls
self.smoothingSlider = self._labeledField("Smoothing", QLineEdit())
self.smoothingSlider.field.setText(str(Config["ui.default.reduction.smoothing"]))
Expand All @@ -59,30 +57,31 @@ def __init__(self, parent=None):
self.recalculationButton = QPushButton("Recalculate")
self.recalculationButton.clicked.connect(self.emitValueChange)

# add all elements to the grid layout
self.layout.addWidget(self.fieldRunNumber, 0, 0)
self.layout.addWidget(self.navigationBar, 1, 0)
self.layout.addWidget(self.canvas, 2, 0, 1, -1)
self.layout.addLayout(peakControlLayout, 3, 0, 1, 2)
self.layout.addWidget(self.lssDropdown, 4, 0)
self.layout.addWidget(self.decreaseParameterDropdown, 4, 1)
self.layout.addWidget(self.recalculationButton, 5, 0, 1, 2)

self.layout.setRowStretch(2, 10)

# store the initial layout without graphs
# add all elements to an adjust layout
self.adjustLayout = QGridLayout()
self.adjustLayout.addWidget(self.fieldRunNumber, 0, 0)
self.adjustLayout.addWidget(self.navigationBar, 1, 0)
self.adjustLayout.addWidget(self.canvas, 2, 0, 1, -1)
self.adjustLayout.addLayout(peakControlLayout, 3, 0, 1, 2)
self.adjustLayout.addWidget(self.lssDropdown, 4, 0)
self.adjustLayout.addWidget(self.decreaseParameterDropdown, 4, 1)
self.adjustLayout.addWidget(self.recalculationButton, 5, 0, 1, 2)

self.adjustLayout.setRowStretch(2, 10)

# add the adjust layout to this layout so it may be turned on and off
self.adjustFrame = QFrame()
self.adjustFrame.setLayout(self.adjustLayout)
self.layout.addWidget(self.adjustFrame, 0, 0, -1, -1)
self.adjustFrame.show()

# store the initial layout height without graphs
self.initialLayoutHeight = self.size().height()

self.signalUpdateRecalculationButton.connect(self.setEnableRecalculateButton)
self.signalUpdateFields.connect(self._updateFields)
self.signalRunNumberUpdate.connect(self._updateRunNumber)

self.messageLabel = QLabel("")
self.messageLabel.setStyleSheet("font-size: 24px; font-weight: bold; color: black;")
self.messageLabel.setAlignment(Qt.AlignCenter)
self.layout.addWidget(self.messageLabel, 0, 0, 1, 2)
self.messageLabel.hide()

@Slot(str)
def _updateRunNumber(self, runNumber):
self.fieldRunNumber.setText(runNumber)
Expand Down Expand Up @@ -180,17 +179,11 @@ def verify(self):
# TODO what needs to be verified?
return True

def showMessage(self, message: str):
self.clearView()
self.messageLabel.setText(message)
self.messageLabel.show()

def clearView(self):
# Remove all existing widgets except the layout
for i in reversed(range(self.layout.count())):
widget = self.layout.itemAt(i).widget()
if widget is not None and widget != self.messageLabel:
widget.deleteLater() # Delete the widget
def showSkippedView(self):
self.adjustFrame.hide()

def showAdjustView(self):
self.adjustFrame.show()

def getPeakWindowClippingSize(self):
return int(self.peakWindowClippingSize.field.text())
Expand Down
6 changes: 3 additions & 3 deletions src/snapred/ui/workflow/ReductionWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def _triggerReduction(self, workflowPresenter):
# Use one timestamp for the entire set of runNumbers:
timestamp = self.request(path="reduction/getUniqueTimestamp").data
for runNumber in runNumbers:
self._artificialNormalizationView.updateRunNumber(runNumber)
request_ = ReductionRequest(
runNumber=str(runNumber),
useLiteMode=self._reductionRequestView.liteModeToggle.field.getState(),
Expand All @@ -175,17 +176,16 @@ def _triggerReduction(self, workflowPresenter):
# Validate reduction; if artificial normalization is needed, handle it
response = self.request(path="reduction/validateReduction", payload=request_)
if ContinueWarning.Type.MISSING_NORMALIZATION in self.continueAnywayFlags:
self._artificialNormalizationView.updateRunNumber(runNumber)
self._artificialNormalizationView.showAdjustView()
response = self.request(path="reduction/grabWorkspaceforArtificialNorm", payload=request_)
self._artificialNormalization(workflowPresenter, response.data, runNumber)
else:
# Proceed with reduction if artificial normalization is not needed
self._artificialNormalizationView.showSkippedView()
response = self.request(path="reduction/", payload=request_)
if response.code == ResponseCode.OK:
record, unfocusedData = response.data.record, response.data.unfocusedData
self._finalizeReduction(record, unfocusedData)
self._artificialNormalizationView.updateRunNumber(runNumber)
self._artificialNormalizationView.showMessage("Artificial Normalization not Needed")
workflowPresenter.advanceWorkflow()
return self.responses[-1]

Expand Down

0 comments on commit c92d475

Please sign in to comment.