Skip to content

Commit

Permalink
Started to make code GUI compatible (add new parameters...). This refs
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed May 1, 2012
1 parent f447581 commit d0d2ba4
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ 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 @@ -23,6 +23,8 @@ class DataSets(BaseScriptElement):
s1w = 'N/A'
s2w = 'N/A'
scaling_factor_file = 'N/A'
tof_min = 0.
tof_max = 200000.

def __init__(self):
super(DataSets, self).__init__()
Expand All @@ -33,15 +35,25 @@ 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 += '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 += ' 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 += ' 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)
Expand All @@ -55,7 +67,6 @@ def update(self):
"""
Update transmission from reduction output
"""
print 'in update of refl_sf_calculator_data_script'
pass

def to_xml(self):
Expand All @@ -64,6 +75,8 @@ def to_xml(self):
"""
xml = "<RefLSFCalculator>\n"
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)
Expand Down Expand Up @@ -94,12 +107,13 @@ def from_xml_element(self, instrument_dom):
Read in data from XML
@param xml_str: text to read the data from
"""
print 'from_xml element'

#incident medium
self.incident_medium_list = BaseScriptElement.getStringList(instrument_dom, "incident_medium_list")
self.incident_medium_index_selected = BaseScriptElement.getIntElement(instrument_dom, "incident_medium_index_selected")

self.tof_min = BaseScriptElement.getFloatElement(instrument_dom, "tof_min")
self.tof_max = BaseScriptElement.getFloatElement(instrument_dom, "tof_max")

#run number
self.data_file = BaseScriptElement.getIntElement(instrument_dom, "data_file")

Expand Down Expand Up @@ -143,4 +157,6 @@ def reset(self):
self.s2h = DataSets.s2h
self.s1w = DataSets.s1w
self.s2w = DataSets.s2w
self.tof_min = DataSets.tof_min
self.tof_max = DataSets.tof_max

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def initialize_content(self):
self._summary.waiting_label.hide()
self._summary.data_run_number_processing.hide()

#tof
self._summary.tof_min.setValidator(QtGui.QDoubleValidator(self._summary.tof_min))
self._summary.tof_max.setValidator(QtGui.QDoubleValidator(self._summary.tof_max))
self.connect(self._summary.plot_counts_vs_tof_btn, QtCore.SIGNAL("clicked()"), self._plot_counts_vs_tof)

self._summary.data_run_number_edit.setValidator(QtGui.QIntValidator(self._summary.data_run_number_edit))
self._summary.number_of_attenuator.setValidator(QtGui.QIntValidator(self._summary.number_of_attenuator))
self._summary.data_peak_from_pixel.setValidator(QtGui.QIntValidator(self._summary.data_peak_from_pixel))
Expand All @@ -89,6 +94,11 @@ def initialize_content(self):
#Number of attenuator value changed
call_back = partial(self._edit_event, ctrl=self._summary.number_of_attenuator)
self.connect(self._summary.number_of_attenuator, QtCore.SIGNAL("textChanged(QString)"), call_back)
#tof selection (from and to) changed
call_back = partial(self._edit_event, ctrl=self._summary.tof_min)
self.connect(self._summary.tof_min, QtCore.SIGNAL("textChanged(QString)"), call_back)
call_back = partial(self._edit_event, ctrl=self._summary.tof_max)
self.connect(self._summary.tof_max, QtCore.SIGNAL("textChanged(QString)"), call_back)
#peak selection (from and to) changed
call_back = partial(self._edit_event, ctrl=self._summary.data_peak_from_pixel)
self.connect(self._summary.data_peak_from_pixel, QtCore.SIGNAL("textChanged(QString)"), call_back)
Expand Down Expand Up @@ -133,6 +143,23 @@ def _ref_instrument_selected(self):
#TODO: allow log binning
self._summary.log_scale_chk.hide()

def _plot_counts_vs_tof(self):
if not IS_IN_MANTIDPLOT:
return

f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(self._summary.data_run_number_edit.text())))

range_min = float(self._summary.tof_min.text())
range_max = float(self._summary.tof_max.text())

if len(f)>0 and os.path.isfile(f[0]):
def call_back(xmin, xmax):
self._summary.tof_min.setText("%-d" % float(xmin))
self._summary.tof_max.setText("%-d" % float(xmax))
data_manipulation.tof_distribution(f[0], call_back,
range_min=range_min,
range_max=range_max)

def _plot_count_vs_y(self, is_peak=True):
"""
Plot counts as a function of high-resolution pixels
Expand Down Expand Up @@ -270,6 +297,8 @@ def _data_background_clicked(self, is_checked):

def _reset_warnings(self):
self._summary.edited_warning_label.hide()
util.set_edited(self._summary.tof_min, False)
util.set_edited(self._summary.tof_max, False)
util.set_edited(self._summary.data_run_number_edit, False)
util.set_edited(self._summary.incident_medium_combobox, False)
util.set_edited(self._summary.number_of_attenuator, False)
Expand Down Expand Up @@ -322,7 +351,8 @@ def set_editing_state(self, state):
for i in range(len(_list)):
self._summary.incident_medium_combobox.addItem(str(_list[i]))
self._summary.incident_medium_combobox.setCurrentIndex(state.incident_medium_index_selected)

self._summary.tof_min.setText(str(state.tof_min))
self._summary.tof_max.setText(str(state.tof_max))
self._summary.data_run_number_edit.setText(str(state.data_file))
self._summary.number_of_attenuator.setText(str(state.number_attenuator))
self._summary.data_peak_from_pixel.setText(str(state.peak_selection[0]))
Expand Down Expand Up @@ -351,7 +381,7 @@ def get_state(self):
m.incident_medium_index_selected = self._summary.incident_medium_combobox.currentIndex()

incident_medium = m.incident_medium_list[m.incident_medium_index_selected]

for i in range(self._summary.angle_list.count()):
data = self._summary.angle_list.item(i).data(QtCore.Qt.UserRole).toPyObject()
# Over-write incident medium with global incident medium
Expand All @@ -368,11 +398,15 @@ def get_editing_state(self):
#run number
m.data_file = str(self._summary.data_run_number_edit.text())

#incident medium
m.incident_medium_list = [self._summary.incident_medium_combobox.itemText(i)
for i in range(self._summary.incident_medium_combobox.count())]
m.incident_medium_index_selected = self._summary.incident_medium_combobox.currentIndex()

# #incident medium
# m.incident_medium_list = [self._summary.incident_medium_combobox.itemText(i)
# for i in range(self._summary.incident_medium_combobox.count())]
# m.incident_medium_index_selected = self._summary.incident_medium_combobox.currentIndex()

#tof
m.tof_min = self._summary.tof_min.text()
m.tof_max = self._summary.tof_max.text()

#number of attenuator
m.number_attenuator = int(self._summary.number_of_attenuator.text())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="tof_min">
<property name="minimumSize">
<size>
<width>150</width>
Expand Down Expand Up @@ -342,7 +342,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2">
<widget class="QLineEdit" name="tof_max">
<property name="minimumSize">
<size>
<width>150</width>
Expand Down Expand Up @@ -380,7 +380,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QPushButton" name="plot_count_vs_y_btn_2">
<widget class="QPushButton" name="plot_counts_vs_tof_btn">
<property name="minimumSize">
<size>
<width>150</width>
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/data_refl_simple.ui'
#
# Created: Wed Apr 11 11:01:51 2012
# Created: Tue May 1 06:40:10 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 d0d2ba4

Please sign in to comment.