Skip to content

Commit

Permalink
Re #6077 Add unit tests, add monitor to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Nov 13, 2012
1 parent 794cfe4 commit 6551824
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 52 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/PythonAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set ( TEST_FILES

# Python unit tests
set ( TEST_PY_FILES
EQSANSNormaliseTest.py
GoniometerTest.py
ImportTest.py
IPeaksWorkspaceTest.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ def _normalise_to_monitor(self, workspace):
ConvertUnits(InputWorkspace=monitor_ws+'_tof',
OutputWorkspace=monitor_ws+'_wl', Target="Wavelength")

SANSBeamFluxCorrection(InputWorkspace=workspace,
InputMonitorWorkspace=monitor_ws+'_wl',
ReferenceFluxFilename=reference_flux,
ReductionProperties=prop_mng,
OutputWorkspace=workspace)
self.setProperty("OutputMessage", "Data [%s] normalized to monitor" % (workspace))
proxy = SANSBeamFluxCorrection(InputWorkspace=workspace,
InputMonitorWorkspace=monitor_ws+'_wl',
ReferenceFluxFilename=reference_flux,
ReductionProperties=prop_mng,
OutputWorkspace=workspace)
output_msg = proxy.getPropertyValue("OutputMessage")
self.setProperty("OutputMessage",
"Data [%s] normalized to monitor\n %s" % (workspace, output_msg))
else:
self.setProperty("OutputMessage", "Monitor not available. Data [%s] NOT normalized to monitor" % (workspace))

Expand Down
45 changes: 45 additions & 0 deletions Code/Mantid/Framework/PythonAPI/test/EQSANSNormaliseTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
from MantidFramework import *
from mantidsimple import *

class EQSANSNormaliseTest(unittest.TestCase):

def setUp(self):
self.prop_mng = "eqsans_normalise_options"
self.data_ws = "eqsans_normalise_data_ws"

EQSANSLoad(Filename="EQSANS_3293_event.nxs",
NoBeamCenter=True,
ReductionProperties=self.prop_mng,
OutputWorkspace=self.data_ws)

def tearDown(self):
if mtd.workspaceExists(self.data_ws):
mtd.deleteWorkspace(self.data_ws)

def test_simple(self):
EQSANSNormalise(InputWorkspace=self.data_ws,
BeamSpectrumFile='SANSBeamFluxCorrectionMonitor.nxs',
NormaliseToMonitor=True,
ReductionProperties=self.prop_mng)

ref_values = [9.66631788e-08, 1.99540011e-08, 0.00000000e+00, 2.84897084e-08,
2.58802935e-08, 0.00000000e+00, 3.43023370e-08, 1.11017160e-08,
3.22199520e-08, 8.31598470e-08, 3.05866692e-08, 3.00540473e-08,
2.97218143e-08, 5.92981344e-08, 2.92735276e-08, 1.91616696e-08,
4.63637972e-08, 8.94602703e-09, 4.34305480e-08, 1.71487695e-08,
2.51816301e-08, 3.24283000e-08, 2.40811371e-08, 3.20081242e-08,
8.03994116e-09, 3.23002602e-08, 2.43204630e-08, 7.99166600e-09,
2.40009985e-08, 8.04082934e-09, 1.61818559e-08, 2.44975746e-08,
0.00000000e+00, 2.49096583e-08, 0.00000000e+00, 8.48764614e-09,
8.59073435e-09, 0.00000000e+00, 8.77853612e-09, 0.00000000e+00,
3.69158961e-08, 2.16789982e-08, 1.41834793e-08]

output_y = mtd[self.data_ws].readY(0)
self.assertAlmostEqual(output_y[0], ref_values[0], 6)
self.assertAlmostEqual(output_y[5], ref_values[5], 6)
self.assertAlmostEqual(output_y[10], ref_values[10], 6)
self.assertAlmostEqual(output_y[25], ref_values[25], 6)

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ReductionOptions(BaseOptions):

# Normalize to beam monitor
use_beam_monitor = False
beam_monitor_reference = ''

def __init__(self):
super(ReductionOptions, self).__init__()
Expand Down Expand Up @@ -61,6 +62,7 @@ def reset(self):

self.perform_TOF_correction = True
self.use_beam_monitor = False
self.beam_monitor_reference = ''

def options(self):
"""
Expand Down Expand Up @@ -95,6 +97,7 @@ def options(self):
if self.dark_current_corr:
script += " DarkCurrentFile='%s',\n" % self.dark_current_data

#TODO: add monitor options
return script

def _normalization_options(self):
Expand All @@ -105,7 +108,7 @@ def _normalization_options(self):
return "NoNormalization()\n"
elif self.normalization==ReductionOptions.NORMALIZATION_MONITOR:
if self.use_beam_monitor:
return "BeamMonitorNormalization()\n"
return "BeamMonitorNormalization(\"%s\")\n" % self.beam_monitor_reference
else:
return "TotalChargeNormalization()\n"
return ""
Expand Down Expand Up @@ -165,6 +168,7 @@ def to_xml(self):
xml += "<PerformTOFCorrection>%s</PerformTOFCorrection>\n" % self.perform_TOF_correction
# Normalization option
xml += "<UseBeamMonitor>%s</UseBeamMonitor>\n" % self.use_beam_monitor
xml += "<BeamMonitorRef>%s</BeamMonitorRef>\n" % self.beam_monitor_reference

return xml

Expand Down Expand Up @@ -208,3 +212,5 @@ def from_xml(self, xml_str):
# Normalization option
self.use_beam_monitor = BaseScriptElement.getBoolElement(dom, "UseBeamMonitor",
default = ReductionOptions.use_beam_monitor)
self.beam_monitor_reference = BaseScriptElement.getStringElement(dom, "BeamMonitorRef",
default = ReductionOptions.beam_monitor_reference)
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def initialize_content(self):
# TOF connections
self.connect(self._summary.tof_cut_chk, QtCore.SIGNAL("clicked(bool)"), self._tof_clicked)

# Monitor normalization
self.connect(self._summary.beam_monitor_chk, QtCore.SIGNAL("clicked(bool)"), self._beam_monitor_clicked)
self.connect(self._summary.beam_monitor_browse_button, QtCore.SIGNAL("clicked()"), self._beam_monitor_reference_browse)

# Resolution validator
self._summary.sample_apert_edit.setValidator(QtGui.QDoubleValidator(self._summary.sample_apert_edit))
self.connect(self._summary.resolution_chk, QtCore.SIGNAL("clicked(bool)"), self._resolution_clicked)
Expand All @@ -156,6 +160,7 @@ def initialize_content(self):
self._summary.config_options_layout.deleteLater()
self._summary.abs_scale_options_layout.deleteLater()
self._summary.abs_scale_direct_beam_layout.deleteLater()
self._summary.monitor_layout.deleteLater()
self._summary.direct_beam_label.hide()
self._summary.att_trans_label.hide()
self._summary.beamstop_chk.hide()
Expand All @@ -167,6 +172,8 @@ def initialize_content(self):
self._summary.scale_chk.hide()
self._summary.beam_monitor_chk.hide()
self._summary.tof_correction_chk.hide()
self._summary.beam_monitor_edit.hide()
self._summary.beam_monitor_browse_button.hide()

# Same thing for sample-detector distance and offset: not yet hooked in
self._summary.geometry_options_groupbox.hide()
Expand Down Expand Up @@ -244,6 +251,15 @@ def _tof_clicked(self, is_checked):
self._summary.low_tof_label.setEnabled(not is_checked)
self._summary.high_tof_label.setEnabled(not is_checked)

def _beam_monitor_clicked(self, is_checked):
self._summary.beam_monitor_edit.setEnabled(is_checked)
self._summary.beam_monitor_browse_button.setEnabled(is_checked)

def _beam_monitor_reference_browse(self):
fname = self.data_browse_dialog()
if fname:
self._summary.beam_monitor_edit.setText(fname)

def _beamstop_clicked(self, is_checked):
self._summary.scale_beam_radius_edit.setEnabled(is_checked and self._summary.scale_chk.isChecked())

Expand Down Expand Up @@ -387,7 +403,9 @@ def set_state(self, state):

self._summary.tof_correction_chk.setChecked(state.perform_TOF_correction)
self._summary.beam_monitor_chk.setChecked(state.use_beam_monitor)

self._summary.beam_monitor_edit.setText(QtCore.QString(str(state.beam_monitor_reference)))
self._beam_monitor_clicked(self._summary.beam_monitor_chk.isChecked())

# Output directory
self._summary.select_output_dir_radio.setChecked(not state.use_data_directory)
self._summary.use_data_dir_radio.setChecked(state.use_data_directory)
Expand Down Expand Up @@ -465,6 +483,7 @@ def get_state(self):

m.perform_TOF_correction = self._summary.tof_correction_chk.isChecked()
m.use_beam_monitor = self._summary.beam_monitor_chk.isChecked()
m.beam_monitor_reference = unicode(self._summary.beam_monitor_edit.text())

# Output directory
m.use_data_directory = self._summary.use_data_dir_radio.isChecked()
Expand Down
55 changes: 53 additions & 2 deletions Code/Mantid/scripts/Interface/ui/sans/eqsans_instrument.ui
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,71 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="monitor_layout">
<item>
<widget class="QCheckBox" name="beam_monitor_chk">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Select to normalize to the beam monitor data</string>
</property>
<property name="statusTip">
<string>Select to normalize to the beam monitor data</string>
</property>
<property name="text">
<string>Normalize to beam monitor</string>
<string>Monitor reference</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="beam_monitor_edit">
<property name="toolTip">
<string>Enter a valid path for the beam monitor reference file.</string>
</property>
<property name="statusTip">
<string>Enter a valid path for the beam monitor reference file.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="beam_monitor_browse_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 6551824

Please sign in to comment.