Skip to content

Commit

Permalink
Re #4303 tweak Q binning inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jan 31, 2012
1 parent a994d0d commit 6ed073c
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 156 deletions.
38 changes: 18 additions & 20 deletions Code/Mantid/Framework/PythonAPI/PythonAlgorithms/RefLReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def PyInit(self):
self.declareListProperty("TOFRange", [9000., 23600.], Validator=ArrayBoundedValidator(Lower=0))
self.declareListProperty("TOFBinning", [0.,200.,200000.],
Description="Positive is linear bins, negative is logarithmic")
self.declareProperty("QCutEnabled", False)
self.declareListProperty("QBinning", [0.001,0.001,0.2],
Description="Positive is linear bins, negative is logarithmic")
self.declareProperty("QMin", 0.001, Description="Minimum Q-value")
self.declareProperty("QStep", 0.001, Description="Step-size in Q. Enter a negative value to get a log scale.")
# Output workspace to put the transmission histo into
self.declareWorkspaceProperty("OutputWorkspace", "", Direction.Output)

def PyExec(self):
import os
import numpy
import math
from reduction.instruments.reflectometer import wks_utility
tof_binning = self.getProperty("TOFBinning")
if len(tof_binning) != 1 and len(tof_binning) != 3:
Expand All @@ -54,18 +54,9 @@ def PyExec(self):

TOFrange = self.getProperty("TOFRange") #microS

q_cut_enabled = self.getProperty("QCutEnabled")
q_binning = None
if q_cut_enabled:
q_binning = self.getProperty("QBinning")
if len(q_binning) != 1 and len(q_binning) != 3:
raise RuntimeError("Can only specify (width) or (start,width,stop) for binning. Found %d values." % len(q_binning))
if len(q_binning) == 3:
if q_binning[0] == 0. and q_binning[1] == 0. and q_binning[2] == 0.:
raise RuntimeError("Failed to specify the q-binning")

print q_binning

q_min = self.getProperty("QMin")
q_step = self.getProperty("QStep")

#Due to the frame effect, it's sometimes necessary to narrow the range
#over which we add all the pixels along the low resolution
#Parameter
Expand Down Expand Up @@ -170,10 +161,17 @@ def PyExec(self):
BackfromYpixel = data_back[0]
BacktoYpixel = data_back[1]

#Create a new event workspace of only the range of pixel of interest
#background range (along the y-axis) and of only the pixel
#of interest along the x-axis (to avoid the frame effect)
# Create a new event workspace of only the range of pixel of interest
# background range (along the y-axis) and of only the pixel
# of interest along the x-axis (to avoid the frame effect)
theta = tthd_rad - ths_rad

if dMD is not None and theta is not None:
_tof_axis = mtd[ws_histo_data].readX(0)
_const = float(4) * math.pi * m * dMD / h
_q_axis = 1e-10 * _const * math.sin(theta) / (_tof_axis*1e-6)
q_max = max(_q_axis)

wks_utility.createIntegratedWorkspace(mtd[ws_histo_data],
"IntegratedDataWks1",
fromXpixel=Xrange[0],
Expand All @@ -186,8 +184,8 @@ def PyExec(self):
source_to_detector=dMD,
sample_to_detector=dSD,
theta=theta,
geo_correction=True,
q_binning=q_binning)
geo_correction=False,
q_binning=[q_min,q_step,q_max])

ConvertToHistogram(InputWorkspace='IntegratedDataWks1',
OutputWorkspace='IntegratedDataWks')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class DataSets(BaseScriptElement):
DataTofRange = [9600., 21600.]

x_range = [115,210]
norm_x_min = 115
norm_x_max = 210

NormPeakPixels = [127, 133]
NormBackgroundFlag = False
Expand All @@ -32,8 +34,7 @@ class DataSets(BaseScriptElement):
# Q range
q_min = 0.001
q_step = 0.001
q_max = 0.2
q_cut_enabled = False
auto_q_binning = False

def __init__(self):
super(DataSets, self).__init__()
Expand All @@ -55,9 +56,8 @@ def to_script(self):
script += " SubtractNormBackground=%s,\n" % str(self.NormBackgroundFlag)
script += " LowResAxisPixelRange=%s,\n" % str(self.x_range)
script += " TOFRange=%s,\n" % str(self.DataTofRange)
if self.q_cut_enabled:
script += " QCutEnabled=True"
script += " QBinning=[%s,%s,%s],\n" % (self.q_min, self.q_step, self.q_max)
script += " QMin=%s,\n" % str(self.q_min)
script += " QStep=%s,\n" % str(self.q_step)
script += " OutputWorkspace='reflectivity_%s')" % str(self.data_files[0])
script += "\n"

Expand Down Expand Up @@ -90,7 +90,8 @@ def to_xml(self):
xml += "<data_sets>%s</data_sets>\n" % ','.join([str(i) for i in self.data_files])
xml += "<x_min_pixel>%s</x_min_pixel>\n" % str(self.x_range[0])
xml += "<x_max_pixel>%s</x_max_pixel>\n" % str(self.x_range[1])

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

xml += "<norm_from_peak_pixels>%s</norm_from_peak_pixels>\n" % str(self.NormPeakPixels[0])
xml += "<norm_to_peak_pixels>%s</norm_to_peak_pixels>\n" % str(self.NormPeakPixels[1])
Expand All @@ -102,8 +103,7 @@ def to_xml(self):
# Q cut
xml += "<q_min>%s</q_min>\n" % str(self.q_min)
xml += "<q_step>%s</q_step>\n" % str(self.q_step)
xml += "<q_max>%s</q_max>\n" % str(self.q_max)
xml += "<q_cut_enabled>%s</q_cut_enabled>" % str(self.q_cut_enabled)
xml += "<auto_q_binning>%s</auto_q_binning>" % str(self.auto_q_binning)

xml += "</Data>\n"

Expand Down Expand Up @@ -132,6 +132,11 @@ def from_xml_element(self, instrument_dom):
self.x_range = [BaseScriptElement.getIntElement(instrument_dom, "x_min_pixel"),
BaseScriptElement.getIntElement(instrument_dom, "x_max_pixel")]

self.norm_x_min = BaseScriptElement.getIntElement(instrument_dom, "norm_x_min",
default=DataSets.norm_x_min)
self.norm_x_max = BaseScriptElement.getIntElement(instrument_dom, "norm_x_max",
default=DataSets.norm_x_max)

#discrete selection string
self.DataPeakDiscreteSelection = BaseScriptElement.getStringElement(instrument_dom, "peak_discrete_selection")

Expand Down Expand Up @@ -167,11 +172,10 @@ def from_xml_element(self, instrument_dom):

self.norm_file = BaseScriptElement.getIntElement(instrument_dom, "norm_dataset")

# Q cut
# Q cut
self.q_min = BaseScriptElement.getFloatElement(instrument_dom, "q_min", default=DataSets.q_min)
self.q_max = BaseScriptElement.getFloatElement(instrument_dom, "q_max", default=DataSets.q_max)
self.q_step = BaseScriptElement.getFloatElement(instrument_dom, "q_step", default=DataSets.q_step)
self.q_cut_enabled = BaseScriptElement.getBoolElement(instrument_dom, "q_cut_enabled", default=False)
self.auto_q_binning = BaseScriptElement.getBoolElement(instrument_dom, "auto_q_binning", default=False)

def reset(self):
"""
Expand All @@ -190,8 +194,10 @@ def reset(self):
self.NormPeakPixels = DataSets.NormPeakPixels
self.norm_file = DataSets.norm_file
self.x_range = DataSets.x_range
self.norm_x_max = DataSets.norm_x_max
self.norm_x_min = DataSets.norm_x_min

# Q range
self.q_min = DataSets.q_min
self.q_step = DataSets.q_step
self.q_max = DataSets.q_max
self.q_cut_enabled = DataSets.q_cut_enabled
self.auto_q_binning = DataSets.auto_q_binning
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ def initialize_content(self):

self._summary.x_min_edit.setValidator(QtGui.QDoubleValidator(self._summary.x_min_edit))
self._summary.x_max_edit.setValidator(QtGui.QDoubleValidator(self._summary.x_max_edit))
self._summary.norm_x_min_edit.setValidator(QtGui.QDoubleValidator(self._summary.norm_x_min_edit))
self._summary.norm_x_max_edit.setValidator(QtGui.QDoubleValidator(self._summary.norm_x_max_edit))

self._summary.q_cut_chk.setChecked(False)
self.connect(self._summary.q_cut_chk, QtCore.SIGNAL("clicked(bool)"), self._enable_q_cut)
self._summary.log_scale_chk.setChecked(True)
self._summary.q_min_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_min_edit))
self._summary.q_max_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_max_edit))
self._summary.q_step_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_step_edit))
self._enable_q_cut(self._summary.q_cut_chk.isChecked())

self._summary.norm_peak_from_pixel.setValidator(QtGui.QIntValidator(self._summary.norm_peak_from_pixel))
self._summary.norm_peak_to_pixel.setValidator(QtGui.QIntValidator(self._summary.norm_peak_to_pixel))
Expand All @@ -93,11 +92,6 @@ def initialize_content(self):
if not os.path.isdir("/SNS/REF_L"):
self._summary.auto_reduce_check.hide()

def _enable_q_cut(self, is_enabled):
self._summary.q_min_edit.setEnabled(is_enabled)
self._summary.q_max_edit.setEnabled(is_enabled)
self._summary.q_step_edit.setEnabled(is_enabled)

def _create_auto_reduce_template(self):
m = self.get_editing_state()
m.data_files = ["runNumber"]
Expand Down Expand Up @@ -240,40 +234,6 @@ def _angle_changed(self):
state = current_item.data(QtCore.Qt.UserRole).toPyObject()
self.set_editing_state(state)

def _check_for_missing_fields(self):

self._summary.data_peak_discrete_selection_missing.setText(" ")
from_pixel = self._summary.data_peak_from_pixel.text()
if from_pixel == '':
self._summary.data_peak_from_pixel_missing.setText("*")
else:
self._summary.data_peak_from_pixel_missing.setText(" ")

to_pixel = self._summary.data_peak_to_pixel.text()
if to_pixel == '':
self._summary.data_peak_to_pixel_missing.setText("*")
else:
self._summary.data_peak_to_pixel_missing.setText(" ")

#background
is_checked = self._summary.data_background_switch.isChecked()
if is_checked:
from_pixel1 = self._summary.data_background_from_pixel1.text()
if from_pixel1 == '':
self._summary.data_background_from_pixel_missing.setText("*")
else:
self._summary.data_background_from_pixel_missing.setText(" ")

to_pixel1 = self._summary.data_background_to_pixel1.text()
if to_pixel1 == '':
self._summary.data_background_to_pixel_missing.setText("*")
else:
self._summary.data_background_to_pixel_missing.setText(" ")

else:
self._summary.data_background_from_pixel_missing.setText(" ")
self._summary.data_background_to_pixel_missing.setText(" ")

def set_state(self, state):
"""
Populate the UI elements with the data from the given state.
Expand Down Expand Up @@ -309,6 +269,9 @@ def set_editing_state(self, state):
self._summary.x_min_edit.setText(str(state.x_range[0]))
self._summary.x_max_edit.setText(str(state.x_range[1]))

self._summary.norm_x_min_edit.setText(str(state.norm_x_min))
self._summary.norm_x_max_edit.setText(str(state.norm_x_max))

#Background flag
self._summary.data_background_switch.setChecked(state.DataBackgroundFlag)
self._data_background_clicked(state.DataBackgroundFlag)
Expand All @@ -333,6 +296,11 @@ def set_editing_state(self, state):

self._summary.norm_background_from_pixel1.setText(str(state.NormBackgroundRoi[0]))
self._summary.norm_background_to_pixel1.setText(str(state.NormBackgroundRoi[1]))

# Q binning
self._summary.q_min_edit.setText(str(state.q_min))
self._summary.log_scale_chk.setChecked(state.q_step<0)
self._summary.q_step_edit.setText(str(math.fabs(state.q_step)))

def get_state(self):
"""
Expand All @@ -357,6 +325,9 @@ def get_editing_state(self):
m.x_range = [int(self._summary.x_min_edit.text()),
int(self._summary.x_max_edit.text())]

m.norm_x_min = int(self._summary.norm_x_min_edit.text())
m.norm_x_max = int(self._summary.norm_x_max_edit.text())

#Background flag
m.DataBackgroundFlag = self._summary.data_background_switch.isChecked()

Expand Down Expand Up @@ -385,4 +356,10 @@ def get_editing_state(self):
roi1_from = int(self._summary.norm_background_from_pixel1.text())
roi1_to = int(self._summary.norm_background_to_pixel1.text())
m.NormBackgroundRoi = [roi1_from, roi1_to]

m.q_min = float(self._summary.q_min_edit.text())
m.q_step = float(self._summary.q_step_edit.text())
if self._summary.log_scale_chk.isChecked():
m.q_step = -m.q_step

return m
14 changes: 7 additions & 7 deletions Code/Mantid/scripts/Interface/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
os.system("pyuic4 -o ui/ui_instrument_dialog.py ui/instrument_dialog.ui")

# REF - new
os.system("pyuic4 -o ui/reflectometer/ui_advanced.py ui/reflectometer/advanced.ui")
os.system("pyuic4 -o ui/reflectometer/ui_data_refl.py ui/reflectometer/data_refl.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_advanced.py ui/reflectometer/advanced.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_data_refl.py ui/reflectometer/data_refl.ui")
os.system("pyuic4 -o ui/reflectometer/ui_data_refl_simple.py ui/reflectometer/data_refl_simple.ui")
os.system("pyuic4 -o ui/reflectometer/ui_merging_reflm.py ui/reflectometer/merging_refl.ui")
os.system("pyuic4 -o ui/reflectometer/ui_merging_reflm.py ui/reflectometer/merging_refm.ui")
os.system("pyuic4 -o ui/reflectometer/ui_norm_refl.py ui/reflectometer/norm_refl.ui")
os.system("pyuic4 -o ui/reflectometer/ui_parameters_refl.py ui/reflectometer/parameters_refl.ui")
os.system("pyuic4 -o ui/reflectometer/ui_parameters_refm.py ui/reflectometer/parameters_refm.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_merging_reflm.py ui/reflectometer/merging_refl.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_merging_reflm.py ui/reflectometer/merging_refm.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_norm_refl.py ui/reflectometer/norm_refl.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_parameters_refl.py ui/reflectometer/parameters_refl.ui")
#os.system("pyuic4 -o ui/reflectometer/ui_parameters_refm.py ui/reflectometer/parameters_refm.ui")

# Example
#os.system("pyuic4 -o ui/ui_example.py ui/example.ui")
Expand Down

0 comments on commit 6ed073c

Please sign in to comment.