Skip to content

Commit

Permalink
Work in progress to create executable command to run sfCalculator. Th…
Browse files Browse the repository at this point in the history
…is refs #5071
  • Loading branch information
JeanBilheux committed May 4, 2012
1 parent d812dfe commit 383439a
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,94 @@ class REFLSFCalculatorScripter(BaseReductionScripter):
def __init__(self, name="REFL"):
super(REFLSFCalculatorScripter, self).__init__(name=name)

def create_script(self, script_part2):
"""
This creates the special script for the sfCalculator algorithm
"""
algo = 'sfCalculator.calculate'

script_split = script_part2.split('\n')
new_script = ''

run_number = []
attenuator = []

peak_from = []
peak_to = []
back_from = []
back_to = []

tof_range = ['','']
incident_medium = ''

for _line in script_split:
if _line != '':
_line_split = _line.split(':')
_arg = _line_split[0]
_val = _line_split[1]

if _arg == 'Run number':
run_number.append(_val)
continue

if _arg == 'TOF from':
if tof_range[0] != '':
tof_range[0] = _val
continue

if _arg == 'TOF to':
if tof_range[1] != '':
tof_range[1] = _val
continue

if _arg == 'Incident medium':
if incident_medium != '':
incident_medium = _val
continue

if _arg == 'Number of attenuator':
attenuator.append(_val)
continue

if _arg == 'Peak from pixel':
peak_from.append(_val)
continue

if _arg == 'Peak to pixel':
peak_from.append(_val)
continue

if _arg == 'Back from pixel':
peak_from.append(_val)
continue

if _arg == 'Back to pixel':
peak_from.append(_val)
continue

run_attenuator = []
for (run,att) in zip(run_number, attenuator):
run_attenuator.append(run + ':' + attenuator)

list_peak_back = []
for (_peak_from, _peak_to, _back_from, _back_to) in zip(peak_from, peak_to, back_from, back_to):
list_peak_back.append([_peak_from,_peak_to,_back_from,_back_to])














return new_script

def to_script(self, file_name=None):
"""
Spits out the text of a reduction script with the current state.
Expand All @@ -36,11 +124,14 @@ def to_script(self, file_name=None):
script += "from mantidsimple import *\n\n"

script += "REF_RED_OUTPUT_MESSAGE = ''\n\n"


script_part2 = ''
for item in self._observers:
if item.state() is not None:
script += str(item.state())

script_part2 += str(item.state())

script += self.create_script(script_part2)

if file_name is not None:
f = open(file_name, 'w')
f.write(script)
Expand All @@ -55,8 +146,6 @@ def apply(self):
if HAS_MANTID:
script = self.to_script(None)

print script

try:
t0 = time.time()
exec script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
class DataSets(BaseScriptElement):

data_file = 0
incident_medium_list = ['H20','Small Circular SA holder','Large Circular SA holder']
incident_medium_list = ['H20']
incident_medium_index_selected = 0
number_attenuator = 0
peak_selection = [0,0]
back_selection = [0,0]
back_flag = True
lambda_requested = 'N/A'
s1h = 'N/A'
s2h = 'N/A'
Expand All @@ -35,31 +34,15 @@ def to_script(self):
Generate reduction script
@param execute: if true, the script will be executed
"""







script = 'Run number: %s \n' % str(self.data_file)
script += 'TOF range: \n'
script += ' from tof: %s ' % str(self.tof_min)
script += ' to tof: %s \n' % str(self.tof_max)
script += 'Incident medium: %s \n' % str(self.incident_medium_list[self.incident_medium_index_selected])
script += 'TOF from: %s \n' % str(self.tof_min)
script += 'TOF to: %s \n' % str(self.tof_max)
script += 'Number of attenuator: %s \n' % str(self.number_attenuator)
script += 'Peak selection \n'
script += ' from pixel: %s ' % str(self.peak_selection[0])
script += ' to pixel: %s \n' % str(self.peak_selection[1])
script += 'Back flag: %s \n' % str(self.back_flag)
script += 'Back selection \n'
script += ' from pixel: %s ' % str(self.back_selection[0])
script += ' to pixel: %s \n' % str(self.back_selection[1])
# script += 'Lammbda requested: %s \n' % str(self.lambda_requested)
# script += 's1h: %s' %str(self.s1h)
# script += ' s2h: %s' %str(self.s2h)
# script += ' s1w: %s' %str(self.s1w)
# script += ' s2w:%s' %str(self.s2w)
script += "\n"
script += 'Peak from pixel: %s \n' % str(self.peak_selection[0])
script += 'Peak to pixel: %s \n' % str(self.peak_selection[1])
script += 'Back from pixel: %s \n' % str(self.back_selection[0])
script += 'Back to pixel: %s \n' % str(self.back_selection[1])

return script

Expand All @@ -77,20 +60,19 @@ def to_xml(self):
xml += "<incident_medium_list>%s</incident_medium_list>\n" % ','.join([str(i) for i in self.incident_medium_list])
xml += "<tof_min>%s</tof_min>\n" % str(self.tof_min)
xml += "<tof_max>%s</tof_max>\n" % str(self.tof_max)
xml += "<incident_medium_index_selected>%s</incident_medium_index_selected>" % str(self.incident_medium_index_selected)
xml += "<data_file>%s</data_file>" % str(self.data_file)
xml += "<number_attenuator>%s</number_attenuator>" % str(self.number_attenuator)
xml += "<peak_selection_from_pixel>%s</peak_selection_from_pixel>" % str(self.peak_selection[0])
xml += "<peak_selection_to_pixel>%s</peak_selection_to_pixel>" % str(self.peak_selection[1])
xml += "<background_flag>%s</background_flag>" % str(self.back_flag)
xml += "<back_selection_from_pixel>%s</back_selection_from_pixel>" % str(self.back_selection[0])
xml += "<back_selection_to_pixel>%s</back_selection_to_pixel>" % str(self.back_selection[1])
xml += "<lambda_requested>%s</lambda_requested>" % str(self.lambda_requested)
xml += "<s1h>%s</s1h>" % str(self.s1h)
xml += "<s2h>%s</s2h>" % str(self.s2h)
xml += "<s1w>%s</s1w>" % str(self.s1w)
xml += "<s2w>%s</s2w>" % str(self.s2w)
xml += "<scaling_factor_file>%s</scaling_factor_file>" % str(self.scaling_factor_file)
xml += "<incident_medium_index_selected>%s</incident_medium_index_selected>\n" % str(self.incident_medium_index_selected)
xml += "<data_file>%s</data_file>\n" % str(self.data_file)
xml += "<number_attenuator>%s</number_attenuator>\n" % str(self.number_attenuator)
xml += "<peak_selection_from_pixel>%s</peak_selection_from_pixel>\n" % str(self.peak_selection[0])
xml += "<peak_selection_to_pixel>%s</peak_selection_to_pixel>\n" % str(self.peak_selection[1])
xml += "<back_selection_from_pixel>%s</back_selection_from_pixel>\n" % str(self.back_selection[0])
xml += "<back_selection_to_pixel>%s</back_selection_to_pixel>\n" % str(self.back_selection[1])
xml += "<lambda_requested>%s</lambda_requested>\n" % str(self.lambda_requested)
xml += "<s1h>%s</s1h>\n" % str(self.s1h)
xml += "<s2h>%s</s2h>\n" % str(self.s2h)
xml += "<s1w>%s</s1w>\n" % str(self.s1w)
xml += "<s2w>%s</s2w>\n" % str(self.s2w)
xml += "<scaling_factor_file>%s</scaling_factor_file>\n" % str(self.scaling_factor_file)
xml += "</RefLSFCalculator>\n"
return xml

Expand Down Expand Up @@ -125,18 +107,17 @@ def from_xml_element(self, instrument_dom):
BaseScriptElement.getIntElement(instrument_dom, "peak_selection_to_pixel")]

#background flag and selection from and to
self.back_flag = BaseScriptElement.getStringElement(instrument_dom, "background_flag")
self.back_selection = [BaseScriptElement.getIntElement(instrument_dom, "back_selection_from_pixel"),
BaseScriptElement.getIntElement(instrument_dom, "back_selection_to_pixel")]

#lambda requested
self.lambda_requested = BaseScriptElement.getFloatElement(instrument_dom, "lambda_requested")
self.lambda_requested = BaseScriptElement.getStringElement(instrument_dom, "lambda_requested")

#s1h, s2h, s1w, s2w
self.s1h = BaseScriptElement.getFloatElement(instrument_dom, "s1h")
self.s2h = BaseScriptElement.getFloatElement(instrument_dom, "s1w")
self.s1w = BaseScriptElement.getFloatElement(instrument_dom, "s2h")
self.s2w = BaseScriptElement.getFloatElement(instrument_dom, "s2w")
self.s1h = BaseScriptElement.getStringElement(instrument_dom, "s1h")
self.s2h = BaseScriptElement.getStringElement(instrument_dom, "s1w")
self.s1w = BaseScriptElement.getStringElement(instrument_dom, "s2h")
self.s2w = BaseScriptElement.getStringElement(instrument_dom, "s2w")

#scaling factor file
self.scaling_factor_file = BaseScriptElement.getStringElement(instrument_dom, "scaling_factor_file")
Expand All @@ -151,7 +132,6 @@ def reset(self):
self.number_attenuator = DataSets.number_attenuator
self.peak_selection = DataSets.peak_selection
self.back_selection = DataSets.back_selection
self.back_flag = DataSets.back_flag
self.lambda_requested = DataSets.lambda_requested
self.s1h = DataSets.s1h
self.s2h = DataSets.s2h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def initialize_content(self):
#Event connections
self.connect(self._summary.data_run_number_edit, QtCore.SIGNAL("returnPressed()"), self.data_run_number_validated)
self.connect(self._summary.add_dataset_btn, QtCore.SIGNAL("clicked()"), self._add_data)
self.connect(self._summary.data_background_switch, QtCore.SIGNAL("clicked(bool)"), self._data_background_clicked)
self.connect(self._summary.remove_btn, QtCore.SIGNAL("clicked()"), self._remove_item)
self.connect(self._summary.plot_count_vs_y_btn, QtCore.SIGNAL("clicked()"), self._plot_count_vs_y)
self.connect(self._summary.plot_count_vs_y_bck_btn, QtCore.SIGNAL("clicked()"), self._plot_count_vs_y_bck)
Expand All @@ -104,9 +103,8 @@ def initialize_content(self):
self.connect(self._summary.data_peak_from_pixel, QtCore.SIGNAL("textChanged(QString)"), call_back)
call_back = partial(self._edit_event, ctrl=self._summary.data_peak_to_pixel)
self.connect(self._summary.data_peak_to_pixel, QtCore.SIGNAL("textChanged(QString)"), call_back)
#background flag and from/to textEdit changed
call_back = partial(self._edit_event, ctrl=self._summary.data_background_switch)
self.connect(self._summary.data_background_switch, QtCore.SIGNAL("clicked()"), call_back)

#data background
call_back = partial(self._edit_event, ctrl=self._summary.data_background_from_pixel)
self.connect(self._summary.data_background_from_pixel, QtCore.SIGNAL("textChanged(QString)"), call_back)
call_back = partial(self._edit_event, ctrl=self._summary.data_background_to_pixel)
Expand Down Expand Up @@ -283,17 +281,17 @@ def _add_data(self):

self._reset_warnings()

def _data_background_clicked(self, is_checked):
"""
This is reached when the user clicks the Background switch and will enabled or not
the widgets that follow that button
"""
self._summary.data_background_from_pixel.setEnabled(is_checked)
self._summary.data_background_from_pixel_label.setEnabled(is_checked)
self._summary.data_background_to_pixel.setEnabled(is_checked)
self._summary.data_background_to_pixel_label.setEnabled(is_checked)
self._summary.plot_count_vs_y_bck_btn.setEnabled(is_checked)
self._edit_event(None, self._summary.data_background_switch)
# def _data_background_clicked(self, is_checked):
# """
# This is reached when the user clicks the Background switch and will enabled or not
# the widgets that follow that button
# """
# self._summary.data_background_from_pixel.setEnabled(is_checked)
# self._summary.data_background_from_pixel_label.setEnabled(is_checked)
# self._summary.data_background_to_pixel.setEnabled(is_checked)
# self._summary.data_background_to_pixel_label.setEnabled(is_checked)
# self._summary.plot_count_vs_y_bck_btn.setEnabled(is_checked)
# self._edit_event(None, self._summary.data_background_switch)

def _reset_warnings(self):
self._summary.edited_warning_label.hide()
Expand All @@ -304,7 +302,6 @@ def _reset_warnings(self):
util.set_edited(self._summary.number_of_attenuator, False)
util.set_edited(self._summary.data_peak_from_pixel, False)
util.set_edited(self._summary.data_peak_to_pixel, False)
util.set_edited(self._summary.data_background_switch, False)
util.set_edited(self._summary.data_background_from_pixel, False)
util.set_edited(self._summary.data_background_to_pixel, False)

Expand Down Expand Up @@ -359,8 +356,8 @@ def set_editing_state(self, state):
self._summary.data_peak_to_pixel.setText(str(state.peak_selection[1]))
self._summary.data_background_from_pixel.setText(str(state.back_selection[0]))
self._summary.data_background_to_pixel.setText(str(state.back_selection[1]))
self._summary.data_background_switch.setChecked(bool(state.back_flag))
self._summary.lambda_request.setText(str(state.lambda_requested))

self._summary.s1h.setText(str(state.s1h))
self._summary.s2h.setText(str(state.s2h))
self._summary.s1w.setText(str(state.s1w))
Expand Down Expand Up @@ -414,10 +411,6 @@ def get_editing_state(self):
m.peak_selection = [int(self._summary.data_peak_from_pixel.text()),
int(self._summary.data_peak_to_pixel.text())]

#background flag
m.back_flag = self._summary.data_background_switch.isChecked()


#background
m.back_selection = [int(self._summary.data_background_from_pixel.text()),
int(self._summary.data_background_to_pixel.text())]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,24 +778,24 @@ p, li { white-space: pre-wrap; }
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="data_background_switch">
<widget class="QLabel" name="label_14">
<property name="minimumSize">
<size>
<width>160</width>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>160</width>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Background </string>
<string>Background selection</string>
</property>
<property name="checked">
<bool>true</bool>
<property name="indent">
<number>0</number>
</property>
</widget>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/reflectometer/refl_sf_calculator.ui'
#
# Created: Tue May 1 06:59:39 2012
# Created: Fri May 4 12:30:45 2012
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -269,12 +269,12 @@ def setupUi(self, Frame):
self.horizontalLayout_8 = QtGui.QHBoxLayout()
self.horizontalLayout_8.setSpacing(0)
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.data_background_switch = QtGui.QCheckBox(self.groupBox)
self.data_background_switch.setMinimumSize(QtCore.QSize(160, 0))
self.data_background_switch.setMaximumSize(QtCore.QSize(160, 16777215))
self.data_background_switch.setChecked(True)
self.data_background_switch.setObjectName("data_background_switch")
self.horizontalLayout_8.addWidget(self.data_background_switch)
self.label_14 = QtGui.QLabel(self.groupBox)
self.label_14.setMinimumSize(QtCore.QSize(150, 0))
self.label_14.setMaximumSize(QtCore.QSize(150, 16777215))
self.label_14.setIndent(0)
self.label_14.setObjectName("label_14")
self.horizontalLayout_8.addWidget(self.label_14)
self.data_background_from_pixel_label = QtGui.QLabel(self.groupBox)
self.data_background_from_pixel_label.setEnabled(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
Expand Down Expand Up @@ -546,7 +546,7 @@ def retranslateUi(self, Frame):
self.data_peak_to_pixel.setText(QtGui.QApplication.translate("Frame", "0", None, QtGui.QApplication.UnicodeUTF8))
self.plot_count_vs_y_btn.setToolTip(QtGui.QApplication.translate("Frame", "Plot detector counts versus Y pixel", None, QtGui.QApplication.UnicodeUTF8))
self.plot_count_vs_y_btn.setText(QtGui.QApplication.translate("Frame", "Counts vs Pixel...", None, QtGui.QApplication.UnicodeUTF8))
self.data_background_switch.setText(QtGui.QApplication.translate("Frame", "Background ", None, QtGui.QApplication.UnicodeUTF8))
self.label_14.setText(QtGui.QApplication.translate("Frame", "Background selection", None, QtGui.QApplication.UnicodeUTF8))
self.data_background_from_pixel_label.setText(QtGui.QApplication.translate("Frame", "from pixel", None, QtGui.QApplication.UnicodeUTF8))
self.data_background_from_pixel.setText(QtGui.QApplication.translate("Frame", "0", None, QtGui.QApplication.UnicodeUTF8))
self.data_background_to_pixel_label.setText(QtGui.QApplication.translate("Frame", " to pixel ", None, QtGui.QApplication.UnicodeUTF8))
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Interface/ui/ui_refl_sf_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/ui_refl_sf_calculator.ui'
#
# Created: Tue May 1 06:41:54 2012
# Created: Fri May 4 12:28:05 2012
# by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!
Expand Down

0 comments on commit 383439a

Please sign in to comment.