Skip to content

Commit

Permalink
Re #10342 Add option to mask detector side
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Oct 10, 2014
1 parent 9030372 commit 8aae8cf
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 5 deletions.
Expand Up @@ -38,6 +38,9 @@ class ReductionOptions(BaseScriptElement):
n_q_bins = 100
n_sub_pix = 1
log_binning = False

# Mask side
masked_side = None

# Masking
class RectangleMask(object):
Expand Down Expand Up @@ -116,6 +119,9 @@ def to_script(self):
script += "IQxQy(nbins=%g)\n" % self.n_q_bins

# Mask
# Detector plane
if self.masked_side is not None:
script += "MaskDetectorSide('%s')\n" % str(self.masked_side)
# Edges
if (self.top != 0 or self.bottom != 0 or self.left != 0 or self.right != 0):
script += "Mask(nx_low=%d, nx_high=%d, ny_low=%d, ny_high=%d)\n" % (self.left, self.right, self.bottom, self.top)
Expand Down Expand Up @@ -182,6 +188,8 @@ def to_xml(self):
xml += " <mask_bottom>%g</mask_bottom>\n" % self.bottom
xml += " <mask_left>%g</mask_left>\n" % self.left
xml += " <mask_right>%g</mask_right>\n" % self.right

xml += " <mask_side>%s</mask_side>\n" % str(self.masked_side)

xml += " <Shapes>\n"
for item in self.shapes:
Expand Down Expand Up @@ -265,6 +273,8 @@ def from_xml(self, xml_str):
self.right = BaseScriptElement.getIntElement(mask_dom, "mask_right", default=ReductionOptions.right)
self.left = BaseScriptElement.getIntElement(mask_dom, "mask_left", default=ReductionOptions.left)

self.masked_side = BaseScriptElement.getStringElement(mask_dom, "mask_side", default=ReductionOptions.masked_side)

self.shapes = []
shapes_dom_list = mask_dom.getElementsByTagName("Shapes")
if len(shapes_dom_list)>0:
Expand Down Expand Up @@ -409,6 +419,7 @@ def reset(self):
self.detector_ids = []
self.mask_file = ''
self.use_mask_file = ReductionOptions.use_mask_file
self.masked_side = None

self.use_data_directory = ReductionOptions.use_data_directory
self.output_directory = ReductionOptions.output_directory
Expand Down
Expand Up @@ -138,6 +138,14 @@ def initialize_content(self):
self.connect(self._summary.scale_chk, QtCore.SIGNAL("clicked(bool)"), self._scale_clicked)
self._scale_clicked(self._summary.scale_chk.isChecked())

# If we are not in debug/expert mode, hide some advanced options
if not self._settings.debug:
self._summary.mask_side_layout.deleteLater()
self._summary.mask_side_label.hide()
self._summary.mask_side_none_radio.hide()
self._summary.mask_side_front_radio.hide()
self._summary.mask_side_back_radio.hide()

if not self._in_mantidplot:
self._summary.dark_plot_button.hide()
self._summary.scale_data_plot_button.hide()
Expand Down Expand Up @@ -340,6 +348,13 @@ def set_state(self, state):
self._mask_checked(state.use_mask_file)
self._masked_detectors = state.detector_ids
self.mask_reload = True

if state.masked_side == 'Front':
self._summary.mask_side_front_radio.setChecked(True)
elif state.masked_side == 'Back':
self._summary.mask_side_back_radio.setChecked(True)
else:
self._summary.mask_side_none_radio.setChecked(True)

def _prepare_field(self, is_enabled, stored_value, chk_widget, edit_widget, suppl_value=None, suppl_edit=None):
#to_display = str(stored_value) if is_enabled else ''
Expand Down Expand Up @@ -400,6 +415,14 @@ def get_state(self):
m.n_sub_pix = util._check_and_get_int_line_edit(self._summary.n_sub_pix_edit)
m.log_binning = self._summary.log_binning_radio.isChecked()

# Detector side masking
if self._summary.mask_side_front_radio.isChecked():
m.masked_side = 'Front'
elif self._summary.mask_side_back_radio.isChecked():
m.masked_side = 'Back'
else:
m.masked_side = None

# Mask detector IDs
m.use_mask_file = self._summary.mask_check.isChecked()
m.mask_file = unicode(self._summary.mask_edit.text())
Expand Down
66 changes: 66 additions & 0 deletions Code/Mantid/scripts/Interface/ui/sans/hfir_instrument.ui
Expand Up @@ -1052,6 +1052,72 @@ Values can be selected by hand by checking the boxes below.</string>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="mask_side_layout">
<item>
<widget class="QLabel" name="mask_side_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Mask detector side</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mask_side_none_radio">
<property name="toolTip">
<string>Select to keep both sides of the detector active [default].</string>
</property>
<property name="text">
<string>None</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mask_side_front_radio">
<property name="toolTip">
<string>Select to mask the front panel of the detector.</string>
</property>
<property name="text">
<string>Front</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mask_side_back_radio">
<property name="toolTip">
<string>Select to mask the back panel of the detector.</string>
</property>
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="font">
Expand Down
40 changes: 35 additions & 5 deletions Code/Mantid/scripts/Interface/ui/sans/ui_hfir_instrument.py
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/sans/hfir_instrument.ui'
#
# Created: Thu Jun 27 16:46:08 2013
# Created: Fri Oct 10 11:46:57 2014
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -398,6 +398,29 @@ def setupUi(self, Frame):
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout_3 = QtGui.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.mask_side_layout = QtGui.QHBoxLayout()
self.mask_side_layout.setObjectName("mask_side_layout")
self.mask_side_label = QtGui.QLabel(self.groupBox)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.mask_side_label.sizePolicy().hasHeightForWidth())
self.mask_side_label.setSizePolicy(sizePolicy)
self.mask_side_label.setMinimumSize(QtCore.QSize(150, 0))
self.mask_side_label.setObjectName("mask_side_label")
self.mask_side_layout.addWidget(self.mask_side_label)
self.mask_side_none_radio = QtGui.QRadioButton(self.groupBox)
self.mask_side_none_radio.setObjectName("mask_side_none_radio")
self.mask_side_layout.addWidget(self.mask_side_none_radio)
self.mask_side_front_radio = QtGui.QRadioButton(self.groupBox)
self.mask_side_front_radio.setObjectName("mask_side_front_radio")
self.mask_side_layout.addWidget(self.mask_side_front_radio)
self.mask_side_back_radio = QtGui.QRadioButton(self.groupBox)
self.mask_side_back_radio.setObjectName("mask_side_back_radio")
self.mask_side_layout.addWidget(self.mask_side_back_radio)
spacerItem9 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.mask_side_layout.addItem(spacerItem9)
self.verticalLayout_3.addLayout(self.mask_side_layout)
self.label_5 = QtGui.QLabel(self.groupBox)
font = QtGui.QFont()
font.setFamily("Bitstream Charter")
Expand Down Expand Up @@ -428,13 +451,13 @@ def setupUi(self, Frame):
self.mask_plot_button = QtGui.QPushButton(self.groupBox)
self.mask_plot_button.setObjectName("mask_plot_button")
self.horizontalLayout.addWidget(self.mask_plot_button)
spacerItem9 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem9)
spacerItem10 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem10)
self.verticalLayout_3.addLayout(self.horizontalLayout)
self.verticalLayout_2.addLayout(self.verticalLayout_3)
self.verticalLayout_4.addWidget(self.groupBox)
spacerItem10 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_4.addItem(spacerItem10)
spacerItem11 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_4.addItem(spacerItem11)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout.addWidget(self.scrollArea)

Expand Down Expand Up @@ -501,6 +524,13 @@ def retranslateUi(self, Frame):
self.label_10.setText(QtGui.QApplication.translate("Frame", "Wavelength spread [ratio]", None, QtGui.QApplication.UnicodeUTF8))
self.wavelength_spread_edit.setToolTip(QtGui.QApplication.translate("Frame", "Enter the value of the neutron wavelength spread.", None, QtGui.QApplication.UnicodeUTF8))
self.groupBox.setTitle(QtGui.QApplication.translate("Frame", "Mask", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_label.setText(QtGui.QApplication.translate("Frame", "Mask detector side", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_none_radio.setToolTip(QtGui.QApplication.translate("Frame", "Select to keep both sides of the detector active [default].", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_none_radio.setText(QtGui.QApplication.translate("Frame", "None", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_front_radio.setToolTip(QtGui.QApplication.translate("Frame", "Select to mask the front panel of the detector.", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_front_radio.setText(QtGui.QApplication.translate("Frame", "Front", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_back_radio.setToolTip(QtGui.QApplication.translate("Frame", "Select to mask the back panel of the detector.", None, QtGui.QApplication.UnicodeUTF8))
self.mask_side_back_radio.setText(QtGui.QApplication.translate("Frame", "Back", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("Frame", "Choose a file to set your mask. Note that only the mask information, not the data, will be used in the reduction.\n"
"The data is only used to help you setting the mask.\n"
"The mask information is saved separately so that your data file will NOT be modified.", None, QtGui.QApplication.UnicodeUTF8))
Expand Down

0 comments on commit 8aae8cf

Please sign in to comment.