Skip to content

Commit

Permalink
Re #4303 add angle offset to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Feb 3, 2012
1 parent 4047eed commit 81897a0
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
class DataSets(BaseScriptElement):

DataPeakSelectionType = 'narrow'
DataPeakPixels = [126, 134]
DataPeakPixels = [120, 130]
DataPeakDiscreteSelection = 'N/A'
DataBackgroundFlag = False
DataBackgroundRoi = [123, 137,123, 137]
DataBackgroundRoi = [115, 137,123, 137]
DataTofRange = [9600., 21600.]

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

NormPeakPixels = [127, 133]
NormPeakPixels = [120, 130]
NormBackgroundFlag = False
NormBackgroundRoi = [123, 137]
NormBackgroundRoi = [115, 137]

# Data files
#data_files = [66421]
Expand All @@ -35,6 +35,10 @@ class DataSets(BaseScriptElement):
q_min = 0.001
q_step = 0.001
auto_q_binning = False

# Angle offset
angle_offset = 0.0
angle_offset_error = 0.0

def __init__(self):
super(DataSets, self).__init__()
Expand All @@ -58,6 +62,14 @@ def to_script(self, for_automated_reduction=False):
script += " TOFRange=%s,\n" % str(self.DataTofRange)
script += " QMin=%s,\n" % str(self.q_min)
script += " QStep=%s,\n" % str(self.q_step)

# Angle offset
if self.angle_offset != 0.0:
script += " AngleOffset=%s,\n" % str(self.angle_offset)
script += " AngleOffsetError=%s,\n" % str(self.angle_offset_error)

# The output should be slightly different if we are generating
# a script for the automated reduction
if for_automated_reduction:
script += " OutputWorkspace='reflectivity_'+%s)" % str(self.data_files[0])
else:
Expand All @@ -72,8 +84,6 @@ def update(self):
"""
pass



def to_xml(self):
"""
Create XML from the current data.
Expand Down Expand Up @@ -108,6 +118,10 @@ def to_xml(self):
xml += "<q_step>%s</q_step>\n" % str(self.q_step)
xml += "<auto_q_binning>%s</auto_q_binning>" % str(self.auto_q_binning)

# Angle offset
xml += "<angle_offset>%s</angle_offset>\n" % str(self.angle_offset)
xml += "<angle_offset_error>%s</angle_offset_error>\n" % str(self.angle_offset_error)

xml += "</Data>\n"

return xml
Expand Down Expand Up @@ -180,6 +194,10 @@ def from_xml_element(self, instrument_dom):
self.q_step = BaseScriptElement.getFloatElement(instrument_dom, "q_step", default=DataSets.q_step)
self.auto_q_binning = BaseScriptElement.getBoolElement(instrument_dom, "auto_q_binning", default=False)

# Angle offset
self.angle_offset = BaseScriptElement.getFloatElement(instrument_dom, "angle_offset", default=DataSets.angle_offset)
self.angle_offset_error = BaseScriptElement.getFloatElement(instrument_dom, "angle_offset_error", default=DataSets.angle_offset_error)

def reset(self):
"""
Reset state
Expand All @@ -204,3 +222,7 @@ def reset(self):
self.q_min = DataSets.q_min
self.q_step = DataSets.q_step
self.auto_q_binning = DataSets.auto_q_binning

# Angle offset
self.angle_offset = DataSets.angle_offset
self.angle_offset_error = DataSets.angle_offset_error
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math
import os
import time
import sys
from reduction_gui.reduction.reflectometer.refl_data_script import DataSets
from reduction_gui.reduction.reflectometer.refl_data_series import DataSeries
from reduction_gui.settings.application_settings import GeneralSettings
Expand Down Expand Up @@ -67,6 +68,9 @@ def initialize_content(self):
self._summary.log_scale_chk.setChecked(True)
self._summary.q_min_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_min_edit))
self._summary.q_step_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_step_edit))

self._summary.angle_offset_edit.setValidator(QtGui.QDoubleValidator(self._summary.angle_offset_edit))
self._summary.angle_offset_error_edit.setValidator(QtGui.QDoubleValidator(self._summary.angle_offset_error_edit))

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 @@ -89,8 +93,8 @@ def initialize_content(self):
self.connect(self._summary.auto_reduce_btn, QtCore.SIGNAL("clicked()"), self._create_auto_reduce_template)

# If we do not have access to /SNS, don't display the automated reduction options
if not os.path.isdir("/SNS/REF_L"):
self._summary.auto_reduce_check.hide()
#if not os.path.isdir("/SNS/REF_L"):
# self._summary.auto_reduce_check.hide()

def _create_auto_reduce_template(self):
m = self.get_editing_state()
Expand Down Expand Up @@ -120,6 +124,28 @@ def _create_auto_reduce_template(self):
content += " Separator='Tab',\n"
content += " CommentIndicator='# ')"

# Place holder for reduction script
content += "\n"
content += "file_path = os.path.join(outputDir, 'REF_L_'+runNumber+'.py')\n"
content += "f=open(file_path,'w')\n"
content += "f.write('# Empty file')\n"
content += "f.close()\n"

# Reduction option to load into Mantid
xml_str = "<Reduction>\n"
xml_str += " <instrument_name>REF_L</instrument_name>\n"
xml_str += " <timestamp>%s</timestamp>\n" % time.ctime()
xml_str += " <python_version>%s</python_version>\n" % sys.version
if IS_IN_MANTIDPLOT:
xml_str += " <mantid_version>%s</mantid_version>\n" % mantid_build_version()
xml_str += m.to_xml()
xml_str += "</Reduction>\n"

content += "file_path = os.path.join(outputDir, 'REF_L_'+runNumber+'.xml')\n"
content += "f=open(file_path,'w')\n"
content += "f.write(%s)\n" % xml_str
content += "f.close()\n"

home_dir = os.path.expanduser('~')
f=open(os.path.join(home_dir,"reduce_REF_L.py"),'w')
f.write(content)
Expand Down Expand Up @@ -209,7 +235,11 @@ def _plot_count_vs_y(self):

f = FileFinder.findRuns("REF_L%s" % str(self._summary.data_run_number_edit.text()))
if len(f)>0 and os.path.isfile(f[0]):
data_manipulation.counts_vs_y_distribution(f[0], 9000, 23600)
def call_back(xmin, xmax):
self._summary.data_peak_from_pixel.setText("%-d" % int(xmin))
self._summary.data_peak_to_pixel.setText("%-d" % int(xmax))
data_manipulation.counts_vs_y_distribution(f[0], 9000, 23600, call_back)


def _plot_tof(self):
if not IS_IN_MANTIDPLOT:
Expand Down Expand Up @@ -266,6 +296,10 @@ def set_state(self, state):
self._summary.q_min_edit.setText(str(state.data_sets[0].q_min))
self._summary.log_scale_chk.setChecked(state.data_sets[0].q_step<0)
self._summary.q_step_edit.setText(str(math.fabs(state.data_sets[0].q_step)))

# Common angle offset
self._summary.angle_offset_edit.setText(str(state.data_sets[0].angle_offset))
self._summary.angle_offset_error_edit.setText(str(state.data_sets[0].angle_offset_error))

def set_editing_state(self, state):

Expand Down Expand Up @@ -323,11 +357,19 @@ def get_state(self):
if self._summary.log_scale_chk.isChecked():
q_step = -q_step

# Angle offset
angle_offset = float(self._summary.angle_offset_edit.text())
angle_offset_error = float(self._summary.angle_offset_error_edit.text())

for i in range(self._summary.angle_list.count()):
data = self._summary.angle_list.item(i).data(QtCore.Qt.UserRole).toPyObject()
# Over-write Q binning with common binning
data.q_min = q_min
data.q_step = q_step

# Over-write angle offset
data.angle_offset = angle_offset
data.angle_offset_error = angle_offset_error

state_list.append(data)
state.data_sets = state_list
Expand Down
93 changes: 89 additions & 4 deletions Code/Mantid/scripts/Interface/ui/reflectometer/data_refl_simple.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1171</width>
<width>1298</width>
<height>1160</height>
</rect>
</property>
Expand Down Expand Up @@ -36,7 +36,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1153</width>
<width>1280</width>
<height>1142</height>
</rect>
</property>
Expand Down Expand Up @@ -2463,13 +2463,13 @@ Drag items to change the reduction order.</string>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<width>90</width>
<height>16777215</height>
</size>
</property>
Expand Down Expand Up @@ -2593,6 +2593,91 @@ Drag items to change the reduction order.</string>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_23">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>90</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Angle offset</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="angle_offset_edit">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_24">
<property name="text">
<string> ± </string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="angle_offset_error_edit">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_25">
<property name="text">
<string>degrees</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_20">
<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>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 81897a0

Please sign in to comment.