diff --git a/Code/Mantid/scripts/Interface/compile_sans_ui.py b/Code/Mantid/scripts/Interface/compile_sans_ui.py index 6ccf2e080a907cc78ce5c77ec9c196ba65d605bb..9e4e7b652cdd8168e4a4c66c047b79104f02f7db 100644 --- a/Code/Mantid/scripts/Interface/compile_sans_ui.py +++ b/Code/Mantid/scripts/Interface/compile_sans_ui.py @@ -26,6 +26,7 @@ try: os.system("pyuic4 -o ui/ui_trans_spreader.py ui/trans_spreader.ui") os.system("pyuic4 -o ui/ui_instrument_dialog.py ui/instrument_dialog.ui") os.system("pyuic4 -o ui/ui_data_catalog.py ui/data_catalog.ui") + os.system("pyuic4 -o ui/ui_stitcher.py ui/stitcher.ui") # Example #os.system("pyuic4 -o ui/ui_example.py ui/example.ui") diff --git a/Code/Mantid/scripts/Interface/reduction_gui/instruments/eqsans_interface_dev.py b/Code/Mantid/scripts/Interface/reduction_gui/instruments/eqsans_interface_dev.py index 54e2878e8e6dbefe633de919f083cf82b03bcff0..fe0f73e32a649ad2958f6b793e7d1b9293c08a79 100644 --- a/Code/Mantid/scripts/Interface/reduction_gui/instruments/eqsans_interface_dev.py +++ b/Code/Mantid/scripts/Interface/reduction_gui/instruments/eqsans_interface_dev.py @@ -16,6 +16,14 @@ from reduction_gui.reduction.sans.eqsans_catalog import DataCatalog from reduction_gui.reduction.sans.eqsans_data_proxy import DataProxy +IS_IN_MANTIDPLOT = False +try: + import qti + from reduction_gui.widgets.sans.stitcher import StitcherWidget + IS_IN_MANTIDPLOT = True +except: + pass + class EQSANSInterface(InstrumentInterface): """ Defines the widgets for EQSANS reduction @@ -42,3 +50,7 @@ class EQSANSInterface(InstrumentInterface): # Catalog self.attach(SANSCatalogWidget(settings = self._settings, catalog_cls=DataCatalog)) + + # Stitcher + if IS_IN_MANTIDPLOT: + self.attach(StitcherWidget(settings = self._settings)) diff --git a/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/eqsans_instrument.py b/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/eqsans_instrument.py index 6d26fc8a1ad495b3dfffd864c0a3f0b963c84969..37fcbc6f541a1cb678e4f44dd9d1dd7ba7ffac2c 100644 --- a/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/eqsans_instrument.py +++ b/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/eqsans_instrument.py @@ -223,6 +223,10 @@ class SANSInstrumentWidget(BaseWidget): use_data_dir = self._summary.use_data_dir_radio.isChecked() self._summary.output_dir_edit.setEnabled(not use_data_dir) self._summary.output_dir_browse_button.setEnabled(not use_data_dir) + if use_data_dir: + self._settings.emit_key_value("OUTPUT_DIR", self._settings.data_path) + else: + self._settings.emit_key_value("OUTPUT_DIR", str(self._summary.output_dir_edit.text())) def _output_dir_browse(self): output_dir = QtGui.QFileDialog.getExistingDirectory(self, "Output Directory - Choose a directory", diff --git a/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/stitcher.py b/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/stitcher.py new file mode 100644 index 0000000000000000000000000000000000000000..430b4edcef75c6e356abc3ed697831e53b4bfaa2 --- /dev/null +++ b/Code/Mantid/scripts/Interface/reduction_gui/widgets/sans/stitcher.py @@ -0,0 +1,384 @@ +from PyQt4 import QtGui, uic, QtCore +import os +from reduction_gui.settings.application_settings import GeneralSettings +from reduction_gui.widgets.base_widget import BaseWidget +import reduction_gui.widgets.util as util +import ui.ui_stitcher + +import qti +from MantidFramework import * +mtd.initialise(False) +from mantidsimple import * + +from LargeScaleStructures.data_stitching import DataSet, Stitcher, RangeSelector + +from reduction_gui.reduction.scripter import BaseScriptElement +class StitcherState(BaseScriptElement): + def __init__(self): + pass + +class StitcherWidget(BaseWidget): + """ + Widget that present a data catalog to the user + """ + ## Widget name + name = "Data Stitching" + + def __init__(self, parent=None, state=None, settings=None): + super(StitcherWidget, self).__init__(parent, state, settings) + + class DataFrame(QtGui.QFrame, ui.ui_stitcher.Ui_Frame): + def __init__(self, parent=None): + QtGui.QFrame.__init__(self, parent) + self.setupUi(self) + + self._content = DataFrame(self) + self.initialize_content() + self._layout.addWidget(self._content) + + # General GUI settings + if settings is None: + settings = GeneralSettings() + self._settings = settings + + # Connect do UI data update + self._settings.data_updated.connect(self._data_updated) + + self._low_q_data = None + self._medium_q_data = None + self._high_q_data = None + + self._referenceID = 0 + + self._graph = None + self._output_dir = None + self._stitcher = None + + def initialize_content(self): + """ + Initialize the content of the frame + """ + # Validators + self._content.low_scale_edit.setValidator(QtGui.QDoubleValidator(self._content.low_scale_edit)) + self._content.medium_scale_edit.setValidator(QtGui.QDoubleValidator(self._content.medium_scale_edit)) + self._content.high_scale_edit.setValidator(QtGui.QDoubleValidator(self._content.high_scale_edit)) + + # Browse buttons + self.connect(self._content.low_q_browse_button, QtCore.SIGNAL("clicked()"), self._low_q_browse) + self.connect(self._content.medium_q_browse_button, QtCore.SIGNAL("clicked()"), self._medium_q_browse) + self.connect(self._content.high_q_browse_button, QtCore.SIGNAL("clicked()"), self._high_q_browse) + + self.connect(self._content.low_q_edit, QtCore.SIGNAL("returnPressed()"), self._update_low_q) + self.connect(self._content.medium_q_edit, QtCore.SIGNAL("returnPressed()"), self._update_medium_q) + self.connect(self._content.high_q_edit, QtCore.SIGNAL("returnPressed()"), self._update_high_q) + + # Radio buttons + self.connect(self._content.low_radio, QtCore.SIGNAL("clicked()"), self._low_q_selected) + self.connect(self._content.medium_radio, QtCore.SIGNAL("clicked()"), self._medium_q_selected) + self.connect(self._content.high_radio, QtCore.SIGNAL("clicked()"), self._high_q_selected) + + # Selection buttons + self.connect(self._content.low_range_button, QtCore.SIGNAL("clicked()"), self._low_range) + self.connect(self._content.medium_range_button, QtCore.SIGNAL("clicked()"), self._medium_range) + + # Scale factors + self.connect(self._content.low_scale_edit, QtCore.SIGNAL("returnPressed()"), self._update_low_scale) + self.connect(self._content.medium_scale_edit, QtCore.SIGNAL("returnPressed()"), self._update_medium_scale) + self.connect(self._content.high_scale_edit, QtCore.SIGNAL("returnPressed()"), self._update_high_scale) + + # Apply and save buttons + self.connect(self._content.apply_button, QtCore.SIGNAL("clicked()"), self._apply) + self.connect(self._content.save_result_button, QtCore.SIGNAL("clicked()"), self._save_result) + + # Create button group for data set selection + g = QtGui.QButtonGroup(self) + g.addButton(self._content.low_radio) + g.addButton(self._content.medium_radio) + g.addButton(self._content.high_radio) + g.setExclusive(True) + self._content.low_radio.setChecked(True) + + def _update_low_scale(self): + """ + Callback for scale update from user + """ + self._low_q_data.set_scale(float(self._content.low_scale_edit.text())) + self.plot_result() + + def _update_medium_scale(self): + """ + Callback for scale update from user + """ + self._medium_q_data.set_scale(float(self._content.medium_scale_edit.text())) + self.plot_result() + + def _update_high_scale(self): + """ + Callback for scale update from user + """ + self._high_q_data.set_scale(float(self._content.high_scale_edit.text())) + self.plot_result() + + def _low_range(self): + """ + User requested to select range common to data sets 1 and 2 + """ + if self._low_q_data is not None: + def call_back(xmin, xmax): + self._content.low_min_edit.setText(str(xmin)) + self._content.low_max_edit.setText(str(xmax)) + ws_list = [] + if self._low_q_data is not None: + ws_list.append(str(self._low_q_data)) + if self._medium_q_data is not None: + ws_list.append(str(self._medium_q_data)) + RangeSelector.connect(ws_list, call_back=call_back) + + def _medium_range(self): + """ + User requested to select range common to data sets 2 and 3 + """ + if self._medium_q_data is not None: + def call_back(xmin, xmax): + self._content.medium_min_edit.setText(str(xmin)) + self._content.medium_max_edit.setText(str(xmax)) + ws_list = [] + if self._medium_q_data is not None: + ws_list.append(str(self._medium_q_data)) + if self._high_q_data is not None: + ws_list.append(str(self._high_q_data)) + RangeSelector.connect(ws_list, call_back=call_back) + + def _low_q_selected(self): + """ + Callback for radio button clicked [selected as reference data set] + """ + self._content.low_scale_edit.setText("1.0") + self._referenceID = 0 + + def _medium_q_selected(self): + """ + Callback for radio button clicked [selected as reference data set] + """ + self._content.medium_scale_edit.setText("1.0") + self._referenceID = 1 + + def _high_q_selected(self): + """ + Callback for radio button clicked [selected as reference data set] + """ + self._content.high_scale_edit.setText("1.0") + self._referenceID = 2 + + def _update_low_q(self): + """ + Update Low-Q data set + """ + file = str(self._content.low_q_edit.text()) + if os.path.isfile(file): + self._low_q_data = DataSet(file) + self._low_q_data.load(True) + minx, maxx = self._low_q_data.get_range() + self._content.low_min_edit.setText(str(minx)) + self._content.low_max_edit.setText(str(maxx)) + self._content.low_scale_edit.setText("1.0") + util.set_valid(self._content.low_q_edit, True) + else: + self._low_q_data = None + util.set_valid(self._content.low_q_edit, False) + + def _update_medium_q(self): + """ + Update Medium-Q data set + """ + file = str(self._content.medium_q_edit.text()) + if os.path.isfile(file): + self._medium_q_data = DataSet(file) + self._medium_q_data.load(True) + minx, maxx = self._medium_q_data.get_range() + self._content.medium_min_edit.setText(str(minx)) + self._content.medium_max_edit.setText(str(maxx)) + self._content.medium_scale_edit.setText("1.0") + util.set_valid(self._content.medium_q_edit, True) + else: + self._medium_q_data = None + util.set_valid(self._content.medium_q_edit, False) + + def _update_high_q(self): + """ + Update High-Q data set + """ + file = str(self._content.high_q_edit.text()) + if os.path.isfile(file): + self._high_q_data = DataSet(file) + self._high_q_data.load(True) + self._content.high_scale_edit.setText("1.0") + util.set_valid(self._content.high_q_edit, True) + else: + self._high_q_data = None + util.set_valid(self._content.high_q_edit, False) + + def data_browse_dialog(self): + """ + Pop up a file dialog box. + """ + title = "Data file - Choose a reduced I(Q) file" + if not os.path.isdir(self._output_dir): + self._output_dir = os.path.expanduser("~") + fname = QtCore.QFileInfo(QtGui.QFileDialog.getOpenFileName(self, title, + self._output_dir, + "Data files (*.xml)")).filePath() + if fname: + # Store the location of the loaded file + self._output_dir = str(QtCore.QFileInfo(fname).path()) + return str(fname) + + def _low_q_browse(self): + """ + Browse for Low-Q I(Q) data set + """ + fname = self.data_browse_dialog() + if fname: + self._content.low_q_edit.setText(fname) + self._update_low_q() + + def _medium_q_browse(self): + """ + Browse for Medium-Q I(Q) data set + """ + fname = self.data_browse_dialog() + if fname: + self._content.medium_q_edit.setText(fname) + self._update_medium_q() + + def _high_q_browse(self): + """ + Browse for High-Q I(Q) data set + """ + fname = self.data_browse_dialog() + if fname: + self._content.high_q_edit.setText(fname) + self._update_high_q() + + def is_running(self, is_running): + """ + Enable/disable controls depending on whether a reduction is running or not + @param is_running: True if a reduction is running + """ + super(StitcherWidget, self).is_running(is_running) + self._content.save_result_button.setEnabled(not is_running) + self._content.apply_button.setEnabled(not is_running) + + def _data_updated(self, key, value): + """ + Respond to application-level key/value pair updates. + @param key: key string + @param value: value string + """ + if key=="OUTPUT_DIR": + self._output_dir = value + + def _apply(self): + """ + Perform auto-scaling + """ + s = Stitcher() + if self._low_q_data is not None: + xmin = util._check_and_get_float_line_edit(self._content.low_min_edit) + xmax = util._check_and_get_float_line_edit(self._content.low_max_edit) + self._low_q_data.set_range(xmin,xmax) + s.append(self._low_q_data) + if self._referenceID==0: + scale = util._check_and_get_float_line_edit(self._content.low_scale_edit) + self._low_q_data.set_scale(scale) + + if self._medium_q_data is not None: + s.append(self._medium_q_data) + if self._referenceID==1: + scale = util._check_and_get_float_line_edit(self._content.medium_scale_edit) + self._medium_q_data.set_scale(scale) + + if self._high_q_data is not None: + xmin = util._check_and_get_float_line_edit(self._content.medium_min_edit) + xmax = util._check_and_get_float_line_edit(self._content.medium_max_edit) + s.append(self._high_q_data) + if self._referenceID==2: + scale = util._check_and_get_float_line_edit(self._content.high_scale_edit) + self._high_q_data.set_scale(scale) + + if s.size()==0: + return + + s.set_reference(self._referenceID) + s.compute() + + # Update scaling factor + if self._low_q_data is not None: + self._content.low_scale_edit.setText(str(self._low_q_data.get_scale())) + n_first = util._check_and_get_int_line_edit(self._content.low_first_spin) + n_last = util._check_and_get_int_line_edit(self._content.low_last_spin) + self._low_q_data.set_skipped_points(n_first, n_last) + if self._medium_q_data is not None: + self._content.medium_scale_edit.setText(str(self._medium_q_data.get_scale())) + n_first = util._check_and_get_int_line_edit(self._content.medium_first_spin) + n_last = util._check_and_get_int_line_edit(self._content.medium_last_spin) + self._medium_q_data.set_skipped_points(n_first, n_last) + if self._high_q_data is not None: + self._content.high_scale_edit.setText(str(self._high_q_data.get_scale())) + n_first = util._check_and_get_int_line_edit(self._content.high_first_spin) + n_last = util._check_and_get_int_line_edit(self._content.high_last_spin) + self._high_q_data.set_skipped_points(n_first, n_last) + + self._stitcher = s + + self.plot_result() + + def plot_result(self): + """ + Plot the scaled data sets + """ + ws_list = [] + if self._low_q_data is not None: + self._low_q_data.apply_scale() + ws_list.append(self._low_q_data.get_scaled_ws()) + + if self._medium_q_data is not None: + self._medium_q_data.apply_scale() + ws_list.append(self._medium_q_data.get_scaled_ws()) + + if self._high_q_data is not None: + self._high_q_data.apply_scale() + ws_list.append(self._high_q_data.get_scaled_ws()) + + if len(ws_list)>0: + self._graph = qti.app.mantidUI.pyPlotSpectraList(ws_list,[0],True) + + def _save_result(self): + """ + Save the scaled output in one combined I(Q) file + """ + if self._stitcher is not None: + if not os.path.isdir(self._output_dir): + self._output_dir = os.path.expanduser("~") + fname_qstr = QtGui.QFileDialog.getSaveFileName(self, "Save combined I(Q)", + self._output_dir, + "Data Files (*.xml)") + fname = str(QtCore.QFileInfo(fname_qstr).filePath()) + if len(fname)>0: + if not fname.endswith('.xml'): + fname += ".xml" + + self._stitcher.save_combined(fname) + + def set_state(self, state): + """ + Update the catalog according to the new data path + """ + pass + + + def get_state(self): + """ + Return dummy state + """ + return StitcherState() \ No newline at end of file diff --git a/Code/Mantid/scripts/Interface/reduction_gui/widgets/util.py b/Code/Mantid/scripts/Interface/reduction_gui/widgets/util.py index 33060516e9b1cdcd4a374749f430e2c9868832b0..69114bd88aa8e18990fde87b8248e71ea9daae39 100644 --- a/Code/Mantid/scripts/Interface/reduction_gui/widgets/util.py +++ b/Code/Mantid/scripts/Interface/reduction_gui/widgets/util.py @@ -6,7 +6,7 @@ CSS_VALID = """QLineEdit { }""" CSS_INVALID = """QLineEdit { - background-color: #F7E93A; + background-color: #FFFF3C; }""" CSS_DEFAULT = """QLineEdit{}""" @@ -37,4 +37,12 @@ def _check_and_get_int_line_edit(line_edit): line_edit.setStyleSheet(CSS_DEFAULT) else: line_edit.setStyleSheet(CSS_INVALID) - return value[0] \ No newline at end of file + return value[0] + +def set_valid(line_edit, is_valid): + if is_valid: + line_edit.setStyleSheet(CSS_DEFAULT) + else: + line_edit.setStyleSheet(CSS_INVALID) + + \ No newline at end of file diff --git a/Code/Mantid/scripts/Interface/ui/stitcher.ui b/Code/Mantid/scripts/Interface/ui/stitcher.ui new file mode 100644 index 0000000000000000000000000000000000000000..40e5331093e337ccb75c404fa24fb4ea35a383d7 --- /dev/null +++ b/Code/Mantid/scripts/Interface/ui/stitcher.ui @@ -0,0 +1,900 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Frame</class> + <widget class="QFrame" name="Frame"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>737</width> + <height>1163</height> + </rect> + </property> + <property name="windowTitle"> + <string>Frame</string> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label_13"> + <property name="font"> + <font> + <italic>true</italic> + </font> + </property> + <property name="text"> + <string>Select the I(Q) data sets you want to combine.</string> + </property> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Low Q</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_11"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>I(q) file:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="low_q_edit"/> + </item> + <item> + <widget class="QPushButton" name="low_q_browse_button"> + <property name="text"> + <string>Browse</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <spacer name="horizontalSpacer_10"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="low_radio"> + <property name="text"> + <string>Normalize to this data set</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_8"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_10"> + <property name="text"> + <string>Scaling factor</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="low_scale_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_6"> + <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> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_12"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>Skip first </string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="low_first_spin"/> + </item> + <item> + <widget class="QLabel" name="label_9"> + <property name="text"> + <string>and last</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="low_last_spin"/> + </item> + <item> + <widget class="QLabel" name="label_14"> + <property name="text"> + <string>points</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_5"> + <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> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</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> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_17"> + <item> + <widget class="Line" name="line_4"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Min Q</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="low_min_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QLabel" name="label_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Max Q</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="low_max_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="low_range_button"> + <property name="text"> + <string>Pick Overlap Region</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer_3"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Medium Q</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>I(q) file:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="medium_q_edit"/> + </item> + <item> + <widget class="QPushButton" name="medium_q_browse_button"> + <property name="text"> + <string>Browse</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <spacer name="horizontalSpacer_11"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="medium_radio"> + <property name="text"> + <string>Normalize to this data set</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_14"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Scaling factor</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="medium_scale_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Expanding</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_13"> + <item> + <spacer name="horizontalSpacer_7"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_15"> + <property name="text"> + <string>Skip first </string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="medium_first_spin"/> + </item> + <item> + <widget class="QLabel" name="label_16"> + <property name="text"> + <string>and last</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="medium_last_spin"/> + </item> + <item> + <widget class="QLabel" name="label_17"> + <property name="text"> + <string>points</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_9"> + <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> + <item> + <spacer name="verticalSpacer_4"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_11"> + <item> + <widget class="Line" name="line_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_7"> + <item> + <widget class="QLabel" name="label_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Min Q</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="medium_min_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <item> + <widget class="QLabel" name="label_6"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>50</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>Max Q</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="medium_max_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="medium_range_button"> + <property name="text"> + <string>Pick Overlap Region</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer_5"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QGroupBox" name="groupBox_3"> + <property name="title"> + <string>High Q</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <item> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>I(q) file:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="high_q_edit"/> + </item> + <item> + <widget class="QPushButton" name="high_q_browse_button"> + <property name="text"> + <string>Browse</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_10"> + <item> + <spacer name="horizontalSpacer_12"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="high_radio"> + <property name="text"> + <string>Normalize to this data set</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_12"> + <property name="text"> + <string>Scaling factor</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="high_scale_edit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <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> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_14"> + <item> + <spacer name="horizontalSpacer_15"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>80</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_18"> + <property name="text"> + <string>Skip first </string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="high_first_spin"/> + </item> + <item> + <widget class="QLabel" name="label_19"> + <property name="text"> + <string>and last</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="high_last_spin"/> + </item> + <item> + <widget class="QLabel" name="label_20"> + <property name="text"> + <string>points</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_16"> + <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> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_16"> + <item> + <spacer name="horizontalSpacer_13"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="apply_button"> + <property name="palette"> + <palette> + <active> + <colorrole role="Button"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>223</red> + <green>242</green> + <blue>208</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="Button"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>223</red> + <green>242</green> + <blue>208</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="Button"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>223</red> + <green>242</green> + <blue>208</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="text"> + <string>Auto Scale</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="save_result_button"> + <property name="text"> + <string>Save Result</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/Code/Mantid/scripts/Interface/ui/ui_stitcher.py b/Code/Mantid/scripts/Interface/ui/ui_stitcher.py new file mode 100644 index 0000000000000000000000000000000000000000..6798fadc11129e9edbfc3ba6853bb3187b40d663 --- /dev/null +++ b/Code/Mantid/scripts/Interface/ui/ui_stitcher.py @@ -0,0 +1,427 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'ui/stitcher.ui' +# +# Created: Fri Nov 11 18:11:14 2011 +# by: PyQt4 UI code generator 4.7.4 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +class Ui_Frame(object): + def setupUi(self, Frame): + Frame.setObjectName("Frame") + Frame.resize(737, 1163) + Frame.setFrameShape(QtGui.QFrame.StyledPanel) + Frame.setFrameShadow(QtGui.QFrame.Raised) + self.verticalLayout = QtGui.QVBoxLayout(Frame) + self.verticalLayout.setObjectName("verticalLayout") + self.label_13 = QtGui.QLabel(Frame) + font = QtGui.QFont() + font.setItalic(True) + self.label_13.setFont(font) + self.label_13.setObjectName("label_13") + self.verticalLayout.addWidget(self.label_13) + self.groupBox = QtGui.QGroupBox(Frame) + self.groupBox.setObjectName("groupBox") + self.verticalLayout_11 = QtGui.QVBoxLayout(self.groupBox) + self.verticalLayout_11.setObjectName("verticalLayout_11") + self.horizontalLayout_2 = QtGui.QHBoxLayout() + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.label_2 = QtGui.QLabel(self.groupBox) + self.label_2.setObjectName("label_2") + self.horizontalLayout_2.addWidget(self.label_2) + self.low_q_edit = QtGui.QLineEdit(self.groupBox) + self.low_q_edit.setObjectName("low_q_edit") + self.horizontalLayout_2.addWidget(self.low_q_edit) + self.low_q_browse_button = QtGui.QPushButton(self.groupBox) + self.low_q_browse_button.setObjectName("low_q_browse_button") + self.horizontalLayout_2.addWidget(self.low_q_browse_button) + self.verticalLayout_11.addLayout(self.horizontalLayout_2) + self.horizontalLayout = QtGui.QHBoxLayout() + self.horizontalLayout.setObjectName("horizontalLayout") + spacerItem = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout.addItem(spacerItem) + self.low_radio = QtGui.QRadioButton(self.groupBox) + self.low_radio.setObjectName("low_radio") + self.horizontalLayout.addWidget(self.low_radio) + spacerItem1 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout.addItem(spacerItem1) + self.label_10 = QtGui.QLabel(self.groupBox) + self.label_10.setObjectName("label_10") + self.horizontalLayout.addWidget(self.label_10) + self.low_scale_edit = QtGui.QLineEdit(self.groupBox) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.low_scale_edit.sizePolicy().hasHeightForWidth()) + self.low_scale_edit.setSizePolicy(sizePolicy) + self.low_scale_edit.setObjectName("low_scale_edit") + self.horizontalLayout.addWidget(self.low_scale_edit) + spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout.addItem(spacerItem2) + self.verticalLayout_11.addLayout(self.horizontalLayout) + self.horizontalLayout_12 = QtGui.QHBoxLayout() + self.horizontalLayout_12.setObjectName("horizontalLayout_12") + spacerItem3 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_12.addItem(spacerItem3) + self.label_8 = QtGui.QLabel(self.groupBox) + self.label_8.setObjectName("label_8") + self.horizontalLayout_12.addWidget(self.label_8) + self.low_first_spin = QtGui.QSpinBox(self.groupBox) + self.low_first_spin.setObjectName("low_first_spin") + self.horizontalLayout_12.addWidget(self.low_first_spin) + self.label_9 = QtGui.QLabel(self.groupBox) + self.label_9.setObjectName("label_9") + self.horizontalLayout_12.addWidget(self.label_9) + self.low_last_spin = QtGui.QSpinBox(self.groupBox) + self.low_last_spin.setObjectName("low_last_spin") + self.horizontalLayout_12.addWidget(self.low_last_spin) + self.label_14 = QtGui.QLabel(self.groupBox) + self.label_14.setObjectName("label_14") + self.horizontalLayout_12.addWidget(self.label_14) + spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_12.addItem(spacerItem4) + self.verticalLayout_11.addLayout(self.horizontalLayout_12) + self.verticalLayout.addWidget(self.groupBox) + spacerItem5 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed) + self.verticalLayout.addItem(spacerItem5) + self.horizontalLayout_17 = QtGui.QHBoxLayout() + self.horizontalLayout_17.setObjectName("horizontalLayout_17") + self.line_4 = QtGui.QFrame(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.line_4.sizePolicy().hasHeightForWidth()) + self.line_4.setSizePolicy(sizePolicy) + self.line_4.setFrameShape(QtGui.QFrame.HLine) + self.line_4.setFrameShadow(QtGui.QFrame.Sunken) + self.line_4.setObjectName("line_4") + self.horizontalLayout_17.addWidget(self.line_4) + self.verticalLayout_3 = QtGui.QVBoxLayout() + self.verticalLayout_3.setObjectName("verticalLayout_3") + self.horizontalLayout_3 = QtGui.QHBoxLayout() + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.label = QtGui.QLabel(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) + self.label.setSizePolicy(sizePolicy) + self.label.setMinimumSize(QtCore.QSize(50, 0)) + self.label.setObjectName("label") + self.horizontalLayout_3.addWidget(self.label) + self.low_min_edit = QtGui.QLineEdit(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.low_min_edit.sizePolicy().hasHeightForWidth()) + self.low_min_edit.setSizePolicy(sizePolicy) + self.low_min_edit.setObjectName("low_min_edit") + self.horizontalLayout_3.addWidget(self.low_min_edit) + self.verticalLayout_3.addLayout(self.horizontalLayout_3) + self.horizontalLayout_4 = QtGui.QHBoxLayout() + self.horizontalLayout_4.setObjectName("horizontalLayout_4") + self.label_3 = QtGui.QLabel(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth()) + self.label_3.setSizePolicy(sizePolicy) + self.label_3.setMinimumSize(QtCore.QSize(50, 0)) + self.label_3.setObjectName("label_3") + self.horizontalLayout_4.addWidget(self.label_3) + self.low_max_edit = QtGui.QLineEdit(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.low_max_edit.sizePolicy().hasHeightForWidth()) + self.low_max_edit.setSizePolicy(sizePolicy) + self.low_max_edit.setObjectName("low_max_edit") + self.horizontalLayout_4.addWidget(self.low_max_edit) + self.verticalLayout_3.addLayout(self.horizontalLayout_4) + self.horizontalLayout_17.addLayout(self.verticalLayout_3) + self.low_range_button = QtGui.QPushButton(Frame) + self.low_range_button.setObjectName("low_range_button") + self.horizontalLayout_17.addWidget(self.low_range_button) + self.line_5 = QtGui.QFrame(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.line_5.sizePolicy().hasHeightForWidth()) + self.line_5.setSizePolicy(sizePolicy) + self.line_5.setFrameShape(QtGui.QFrame.HLine) + self.line_5.setFrameShadow(QtGui.QFrame.Sunken) + self.line_5.setObjectName("line_5") + self.horizontalLayout_17.addWidget(self.line_5) + self.verticalLayout.addLayout(self.horizontalLayout_17) + spacerItem6 = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed) + self.verticalLayout.addItem(spacerItem6) + self.groupBox_2 = QtGui.QGroupBox(Frame) + self.groupBox_2.setObjectName("groupBox_2") + self.verticalLayout_5 = QtGui.QVBoxLayout(self.groupBox_2) + self.verticalLayout_5.setObjectName("verticalLayout_5") + self.horizontalLayout_5 = QtGui.QHBoxLayout() + self.horizontalLayout_5.setObjectName("horizontalLayout_5") + self.label_4 = QtGui.QLabel(self.groupBox_2) + self.label_4.setObjectName("label_4") + self.horizontalLayout_5.addWidget(self.label_4) + self.medium_q_edit = QtGui.QLineEdit(self.groupBox_2) + self.medium_q_edit.setObjectName("medium_q_edit") + self.horizontalLayout_5.addWidget(self.medium_q_edit) + self.medium_q_browse_button = QtGui.QPushButton(self.groupBox_2) + self.medium_q_browse_button.setObjectName("medium_q_browse_button") + self.horizontalLayout_5.addWidget(self.medium_q_browse_button) + self.verticalLayout_5.addLayout(self.horizontalLayout_5) + self.horizontalLayout_6 = QtGui.QHBoxLayout() + self.horizontalLayout_6.setObjectName("horizontalLayout_6") + spacerItem7 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_6.addItem(spacerItem7) + self.medium_radio = QtGui.QRadioButton(self.groupBox_2) + self.medium_radio.setObjectName("medium_radio") + self.horizontalLayout_6.addWidget(self.medium_radio) + spacerItem8 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_6.addItem(spacerItem8) + self.label_11 = QtGui.QLabel(self.groupBox_2) + self.label_11.setObjectName("label_11") + self.horizontalLayout_6.addWidget(self.label_11) + self.medium_scale_edit = QtGui.QLineEdit(self.groupBox_2) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.medium_scale_edit.sizePolicy().hasHeightForWidth()) + self.medium_scale_edit.setSizePolicy(sizePolicy) + self.medium_scale_edit.setObjectName("medium_scale_edit") + self.horizontalLayout_6.addWidget(self.medium_scale_edit) + spacerItem9 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_6.addItem(spacerItem9) + self.verticalLayout_5.addLayout(self.horizontalLayout_6) + self.horizontalLayout_13 = QtGui.QHBoxLayout() + self.horizontalLayout_13.setObjectName("horizontalLayout_13") + spacerItem10 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_13.addItem(spacerItem10) + self.label_15 = QtGui.QLabel(self.groupBox_2) + self.label_15.setObjectName("label_15") + self.horizontalLayout_13.addWidget(self.label_15) + self.medium_first_spin = QtGui.QSpinBox(self.groupBox_2) + self.medium_first_spin.setObjectName("medium_first_spin") + self.horizontalLayout_13.addWidget(self.medium_first_spin) + self.label_16 = QtGui.QLabel(self.groupBox_2) + self.label_16.setObjectName("label_16") + self.horizontalLayout_13.addWidget(self.label_16) + self.medium_last_spin = QtGui.QSpinBox(self.groupBox_2) + self.medium_last_spin.setObjectName("medium_last_spin") + self.horizontalLayout_13.addWidget(self.medium_last_spin) + self.label_17 = QtGui.QLabel(self.groupBox_2) + self.label_17.setObjectName("label_17") + self.horizontalLayout_13.addWidget(self.label_17) + spacerItem11 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_13.addItem(spacerItem11) + self.verticalLayout_5.addLayout(self.horizontalLayout_13) + self.verticalLayout.addWidget(self.groupBox_2) + spacerItem12 = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed) + self.verticalLayout.addItem(spacerItem12) + self.horizontalLayout_11 = QtGui.QHBoxLayout() + self.horizontalLayout_11.setObjectName("horizontalLayout_11") + self.line_2 = QtGui.QFrame(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.line_2.sizePolicy().hasHeightForWidth()) + self.line_2.setSizePolicy(sizePolicy) + self.line_2.setFrameShape(QtGui.QFrame.HLine) + self.line_2.setFrameShadow(QtGui.QFrame.Sunken) + self.line_2.setObjectName("line_2") + self.horizontalLayout_11.addWidget(self.line_2) + self.verticalLayout_4 = QtGui.QVBoxLayout() + self.verticalLayout_4.setObjectName("verticalLayout_4") + self.horizontalLayout_7 = QtGui.QHBoxLayout() + self.horizontalLayout_7.setObjectName("horizontalLayout_7") + self.label_5 = QtGui.QLabel(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_5.sizePolicy().hasHeightForWidth()) + self.label_5.setSizePolicy(sizePolicy) + self.label_5.setMinimumSize(QtCore.QSize(50, 0)) + self.label_5.setObjectName("label_5") + self.horizontalLayout_7.addWidget(self.label_5) + self.medium_min_edit = QtGui.QLineEdit(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.medium_min_edit.sizePolicy().hasHeightForWidth()) + self.medium_min_edit.setSizePolicy(sizePolicy) + self.medium_min_edit.setObjectName("medium_min_edit") + self.horizontalLayout_7.addWidget(self.medium_min_edit) + self.verticalLayout_4.addLayout(self.horizontalLayout_7) + self.horizontalLayout_8 = QtGui.QHBoxLayout() + self.horizontalLayout_8.setObjectName("horizontalLayout_8") + self.label_6 = QtGui.QLabel(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label_6.sizePolicy().hasHeightForWidth()) + self.label_6.setSizePolicy(sizePolicy) + self.label_6.setMinimumSize(QtCore.QSize(50, 0)) + self.label_6.setObjectName("label_6") + self.horizontalLayout_8.addWidget(self.label_6) + self.medium_max_edit = QtGui.QLineEdit(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.medium_max_edit.sizePolicy().hasHeightForWidth()) + self.medium_max_edit.setSizePolicy(sizePolicy) + self.medium_max_edit.setObjectName("medium_max_edit") + self.horizontalLayout_8.addWidget(self.medium_max_edit) + self.verticalLayout_4.addLayout(self.horizontalLayout_8) + self.horizontalLayout_11.addLayout(self.verticalLayout_4) + self.medium_range_button = QtGui.QPushButton(Frame) + self.medium_range_button.setObjectName("medium_range_button") + self.horizontalLayout_11.addWidget(self.medium_range_button) + self.line_3 = QtGui.QFrame(Frame) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.line_3.sizePolicy().hasHeightForWidth()) + self.line_3.setSizePolicy(sizePolicy) + self.line_3.setFrameShape(QtGui.QFrame.HLine) + self.line_3.setFrameShadow(QtGui.QFrame.Sunken) + self.line_3.setObjectName("line_3") + self.horizontalLayout_11.addWidget(self.line_3) + self.verticalLayout.addLayout(self.horizontalLayout_11) + spacerItem13 = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed) + self.verticalLayout.addItem(spacerItem13) + self.groupBox_3 = QtGui.QGroupBox(Frame) + self.groupBox_3.setObjectName("groupBox_3") + self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox_3) + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.horizontalLayout_9 = QtGui.QHBoxLayout() + self.horizontalLayout_9.setObjectName("horizontalLayout_9") + self.label_7 = QtGui.QLabel(self.groupBox_3) + self.label_7.setObjectName("label_7") + self.horizontalLayout_9.addWidget(self.label_7) + self.high_q_edit = QtGui.QLineEdit(self.groupBox_3) + self.high_q_edit.setObjectName("high_q_edit") + self.horizontalLayout_9.addWidget(self.high_q_edit) + self.high_q_browse_button = QtGui.QPushButton(self.groupBox_3) + self.high_q_browse_button.setObjectName("high_q_browse_button") + self.horizontalLayout_9.addWidget(self.high_q_browse_button) + self.verticalLayout_2.addLayout(self.horizontalLayout_9) + self.horizontalLayout_10 = QtGui.QHBoxLayout() + self.horizontalLayout_10.setObjectName("horizontalLayout_10") + spacerItem14 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_10.addItem(spacerItem14) + self.high_radio = QtGui.QRadioButton(self.groupBox_3) + self.high_radio.setObjectName("high_radio") + self.horizontalLayout_10.addWidget(self.high_radio) + spacerItem15 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_10.addItem(spacerItem15) + self.label_12 = QtGui.QLabel(self.groupBox_3) + self.label_12.setObjectName("label_12") + self.horizontalLayout_10.addWidget(self.label_12) + self.high_scale_edit = QtGui.QLineEdit(self.groupBox_3) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.high_scale_edit.sizePolicy().hasHeightForWidth()) + self.high_scale_edit.setSizePolicy(sizePolicy) + self.high_scale_edit.setObjectName("high_scale_edit") + self.horizontalLayout_10.addWidget(self.high_scale_edit) + spacerItem16 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_10.addItem(spacerItem16) + self.verticalLayout_2.addLayout(self.horizontalLayout_10) + self.horizontalLayout_14 = QtGui.QHBoxLayout() + self.horizontalLayout_14.setObjectName("horizontalLayout_14") + spacerItem17 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_14.addItem(spacerItem17) + self.label_18 = QtGui.QLabel(self.groupBox_3) + self.label_18.setObjectName("label_18") + self.horizontalLayout_14.addWidget(self.label_18) + self.high_first_spin = QtGui.QSpinBox(self.groupBox_3) + self.high_first_spin.setObjectName("high_first_spin") + self.horizontalLayout_14.addWidget(self.high_first_spin) + self.label_19 = QtGui.QLabel(self.groupBox_3) + self.label_19.setObjectName("label_19") + self.horizontalLayout_14.addWidget(self.label_19) + self.high_last_spin = QtGui.QSpinBox(self.groupBox_3) + self.high_last_spin.setObjectName("high_last_spin") + self.horizontalLayout_14.addWidget(self.high_last_spin) + self.label_20 = QtGui.QLabel(self.groupBox_3) + self.label_20.setObjectName("label_20") + self.horizontalLayout_14.addWidget(self.label_20) + spacerItem18 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_14.addItem(spacerItem18) + self.verticalLayout_2.addLayout(self.horizontalLayout_14) + self.verticalLayout.addWidget(self.groupBox_3) + self.line = QtGui.QFrame(Frame) + self.line.setFrameShape(QtGui.QFrame.HLine) + self.line.setFrameShadow(QtGui.QFrame.Sunken) + self.line.setObjectName("line") + self.verticalLayout.addWidget(self.line) + self.horizontalLayout_16 = QtGui.QHBoxLayout() + self.horizontalLayout_16.setObjectName("horizontalLayout_16") + spacerItem19 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.horizontalLayout_16.addItem(spacerItem19) + self.apply_button = QtGui.QPushButton(Frame) + palette = QtGui.QPalette() + brush = QtGui.QBrush(QtGui.QColor(223, 242, 208)) + brush.setStyle(QtCore.Qt.SolidPattern) + palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) + brush = QtGui.QBrush(QtGui.QColor(223, 242, 208)) + brush.setStyle(QtCore.Qt.SolidPattern) + palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) + brush = QtGui.QBrush(QtGui.QColor(223, 242, 208)) + brush.setStyle(QtCore.Qt.SolidPattern) + palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) + self.apply_button.setPalette(palette) + self.apply_button.setAutoFillBackground(False) + self.apply_button.setObjectName("apply_button") + self.horizontalLayout_16.addWidget(self.apply_button) + self.save_result_button = QtGui.QPushButton(Frame) + self.save_result_button.setObjectName("save_result_button") + self.horizontalLayout_16.addWidget(self.save_result_button) + self.verticalLayout.addLayout(self.horizontalLayout_16) + spacerItem20 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.verticalLayout.addItem(spacerItem20) + + self.retranslateUi(Frame) + QtCore.QMetaObject.connectSlotsByName(Frame) + + def retranslateUi(self, Frame): + Frame.setWindowTitle(QtGui.QApplication.translate("Frame", "Frame", None, QtGui.QApplication.UnicodeUTF8)) + self.label_13.setText(QtGui.QApplication.translate("Frame", "Select the I(Q) data sets you want to combine.", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox.setTitle(QtGui.QApplication.translate("Frame", "Low Q", None, QtGui.QApplication.UnicodeUTF8)) + self.label_2.setText(QtGui.QApplication.translate("Frame", "I(q) file:", None, QtGui.QApplication.UnicodeUTF8)) + self.low_q_browse_button.setText(QtGui.QApplication.translate("Frame", "Browse", None, QtGui.QApplication.UnicodeUTF8)) + self.low_radio.setText(QtGui.QApplication.translate("Frame", "Normalize to this data set", None, QtGui.QApplication.UnicodeUTF8)) + self.label_10.setText(QtGui.QApplication.translate("Frame", "Scaling factor", None, QtGui.QApplication.UnicodeUTF8)) + self.label_8.setText(QtGui.QApplication.translate("Frame", "Skip first ", None, QtGui.QApplication.UnicodeUTF8)) + self.label_9.setText(QtGui.QApplication.translate("Frame", "and last", None, QtGui.QApplication.UnicodeUTF8)) + self.label_14.setText(QtGui.QApplication.translate("Frame", "points", None, QtGui.QApplication.UnicodeUTF8)) + self.label.setText(QtGui.QApplication.translate("Frame", "Min Q", None, QtGui.QApplication.UnicodeUTF8)) + self.label_3.setText(QtGui.QApplication.translate("Frame", "Max Q", None, QtGui.QApplication.UnicodeUTF8)) + self.low_range_button.setText(QtGui.QApplication.translate("Frame", "Pick Overlap Region", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox_2.setTitle(QtGui.QApplication.translate("Frame", "Medium Q", None, QtGui.QApplication.UnicodeUTF8)) + self.label_4.setText(QtGui.QApplication.translate("Frame", "I(q) file:", None, QtGui.QApplication.UnicodeUTF8)) + self.medium_q_browse_button.setText(QtGui.QApplication.translate("Frame", "Browse", None, QtGui.QApplication.UnicodeUTF8)) + self.medium_radio.setText(QtGui.QApplication.translate("Frame", "Normalize to this data set", None, QtGui.QApplication.UnicodeUTF8)) + self.label_11.setText(QtGui.QApplication.translate("Frame", "Scaling factor", None, QtGui.QApplication.UnicodeUTF8)) + self.label_15.setText(QtGui.QApplication.translate("Frame", "Skip first ", None, QtGui.QApplication.UnicodeUTF8)) + self.label_16.setText(QtGui.QApplication.translate("Frame", "and last", None, QtGui.QApplication.UnicodeUTF8)) + self.label_17.setText(QtGui.QApplication.translate("Frame", "points", None, QtGui.QApplication.UnicodeUTF8)) + self.label_5.setText(QtGui.QApplication.translate("Frame", "Min Q", None, QtGui.QApplication.UnicodeUTF8)) + self.label_6.setText(QtGui.QApplication.translate("Frame", "Max Q", None, QtGui.QApplication.UnicodeUTF8)) + self.medium_range_button.setText(QtGui.QApplication.translate("Frame", "Pick Overlap Region", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox_3.setTitle(QtGui.QApplication.translate("Frame", "High Q", None, QtGui.QApplication.UnicodeUTF8)) + self.label_7.setText(QtGui.QApplication.translate("Frame", "I(q) file:", None, QtGui.QApplication.UnicodeUTF8)) + self.high_q_browse_button.setText(QtGui.QApplication.translate("Frame", "Browse", None, QtGui.QApplication.UnicodeUTF8)) + self.high_radio.setText(QtGui.QApplication.translate("Frame", "Normalize to this data set", None, QtGui.QApplication.UnicodeUTF8)) + self.label_12.setText(QtGui.QApplication.translate("Frame", "Scaling factor", None, QtGui.QApplication.UnicodeUTF8)) + self.label_18.setText(QtGui.QApplication.translate("Frame", "Skip first ", None, QtGui.QApplication.UnicodeUTF8)) + self.label_19.setText(QtGui.QApplication.translate("Frame", "and last", None, QtGui.QApplication.UnicodeUTF8)) + self.label_20.setText(QtGui.QApplication.translate("Frame", "points", None, QtGui.QApplication.UnicodeUTF8)) + self.apply_button.setText(QtGui.QApplication.translate("Frame", "Auto Scale", None, QtGui.QApplication.UnicodeUTF8)) + self.save_result_button.setText(QtGui.QApplication.translate("Frame", "Save Result", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/Code/Mantid/scripts/LargeScaleStructures/data_stitching.py b/Code/Mantid/scripts/LargeScaleStructures/data_stitching.py new file mode 100644 index 0000000000000000000000000000000000000000..486bbc08096fd106ac77059451304fe3a8399508 --- /dev/null +++ b/Code/Mantid/scripts/LargeScaleStructures/data_stitching.py @@ -0,0 +1,325 @@ +import os +import copy +from MantidFramework import * +mtd.initialise(False) +from mantidsimple import * + +from PyQt4 import QtGui, QtCore + +class RangeSelector(object): + """ + Brings up range selector window and connects the user selection to + a call-back function. + """ + __instance=None + + class _Selector(object): + def __init__(self): + self._call_back = None + self._graph = None + + def disconnect(self): + qti.app.disconnect(qti.app.mantidUI, QtCore.SIGNAL("x_range_update(double,double)"), self._call_back) + + def connect(self, ws, call_back): + self._call_back = call_back + qti.app.connect(qti.app.mantidUI, QtCore.SIGNAL("x_range_update(double,double)"), self._call_back) + self._graph = qti.app.mantidUI.pyPlotSpectraList(ws,[0],True) + qti.app.selectMultiPeak(False) + qti.app.selectMultiPeak(False) + + @classmethod + def connect(cls, ws, call_back): + if RangeSelector.__instance is not None: + RangeSelector.__instance.disconnect() + else: + RangeSelector.__instance = RangeSelector._Selector() + RangeSelector.__instance.connect(ws, call_back) + +class DataSet(object): + """ + Data set class for stitcher + """ + def __init__(self, file_path=""): + self._file_path = file_path + self._xmin = None + self._xmax = None + self._ws_name = None + self._ws_scaled = None + self._scale = 1.0 + self._last_applied_scale = 1.0 + self._graph = None + self._skip_last = 0 + self._skip_first = 0 + + def __str__(self): + return self._ws_name + + def get_scaled_ws(self): + """ + Get the name of the scaled workspace, if it exists + """ + if mtd.workspaceExists(self._ws_scaled): + return self._ws_scaled + return None + + def set_skipped_points(self, first, last): + """ + Set the number of points to skip at the beginning and + end of the distribution + @param first: number of points to skip at the beginning of distribution + @param last: number of points to skip at the end of distribution + """ + self._skip_last = last + self._skip_first = first + + def is_loaded(self): + """ + Return True is this data set has been loaded + """ + return mtd.workspaceExists(self._ws_name) + + def set_scale(self, scale=1.0): + """ + Set the scaling factor for this data set + @param scale: scaling factor + """ + self._scale = scale + + def get_scale(self): + """ + Get the current scaling factor for this data set + """ + return self._scale + + def set_range(self, xmin, xmax): + """ + Set the Q range for this data set + @param xmin: minimum Q value + @param xmax: maximum Q value + """ + self._xmin = xmin + self._xmax = xmax + + def get_range(self): + """ + Return the Q range for this data set + """ + return self._xmin, self._xmax + + def apply_scale(self): + """ + Apply the scaling factor to the unmodified data set + """ + self.load() + + Scale(InputWorkspace=self._ws_name, OutputWorkspace=self._ws_scaled, + Operation="Multiply", Factor=self._scale) + + y_scaled = mtd[self._ws_scaled].dataY(0) + e_scaled = mtd[self._ws_scaled].dataE(0) + for i in range(self._skip_first): + y_scaled[i] = 0 + e_scaled[i] = 0 + for i in range(len(y_scaled)-self._skip_last, len(y_scaled)): + y_scaled[i] = 0 + e_scaled[i] = 0 + + # Dummy operation to update the plot + Scale(InputWorkspace=self._ws_scaled, OutputWorkspace=self._ws_scaled, + Operation="Multiply", Factor=1.0) + + def load(self, update_range=False): + """ + Load a data set from file + @param upate_range: if True, the Q range of the data set will be udpated + """ + if os.path.isfile(self._file_path): + self._ws_name = os.path.basename(self._file_path) + self._ws_scaled = self._ws_name+"_scaled" + Load(Filename=self._file_path, OutputWorkspace=self._ws_name) + if update_range: + self._xmin = min(mtd[self._ws_name].readX(0)) + self._xmax = max(mtd[self._ws_name].readX(0)) + self._last_applied_scale = 1.0 + + def integrate(self, xmin=None, xmax=None): + """ + Integrate a distribution between the given boundaries + @param xmin: minimum Q value + @param xmax: maximum Q value + """ + self.load() + + if xmin is None: + xmin = self._xmin + if xmax is None: + xmax = self._xmax + + x = mtd[self._ws_name].readX(0) + y = mtd[self._ws_name].readY(0) + + is_histo = len(x)==len(y)+1 + if not is_histo and len(x)!=len(y): + raise RuntimeError, "Corrupted I(q) %s" % self._ws_name + + sum = 0.0 + if is_histo: + for i in range(len(y)): + if x[i]>xmin and x[i+1]<xmax: + sum += y[i]*(x[i+1]-x[i]) + else: + for i in range(len(y)-1): + if x[i]>=xmin and x[i+1]<=xmax: + sum += (y[i]+y[i+1])*(x[i+1]-x[i])/2.0 + elif x[i]<xmin and x[i+1]>xmin: + sum += (y[i+1]+(y[i]-y[i+1])/(x[i]-x[i+1])*(x[i]-xmin)/2.0) * (x[i+1]-xmin) + elif x[i]<xmax and x[i+1]>xmax: + sum += (y[i]+(y[i+1]-y[i])/(x[i+1]-x[i])*(xmax-x[i])/2.0) * (xmax-x[i]) + + return sum + + def select_range(self, call_back=None): + if mtd.workspaceExists(self._ws_name): + if call_back is None: + call_back = self.set_range + RangeSelector.connect([self._ws_name], call_back=call_back) + +class Stitcher(object): + """ + Data set stitcher + """ + def __init__(self): + ## Reference ID (int) + self._reference = None + ## List of data sets to process + self._data_sets = [] + + def size(self): + """ + Return the number of data sets + """ + return len(self._data_sets) + + def append(self, data_set): + """ + Append a data set to the list of data sets to process + @param data_set: DataSet object + """ + self._data_sets.append(data_set) + return len(self._data_sets)-1 + + @classmethod + def normalize(cls, data_ref, data_to_scale): + """ + Scale a data set relative to a reference + @param data_ref: reference data set + @param data_to_scale: data set to rescale + """ + if data_ref == data_to_scale: + return + + # Get ranges + ref_min, ref_max = data_ref.get_range() + d_min, d_max = data_to_scale.get_range() + + # Check that we have an overlap + if ref_max<d_min or ref_min>d_max: + mtd.sendLogMessage("No overlap between %s and %d" % (str(data_ref), str(data_to_scale))) + return + + # Get overlap + xmin = max(ref_min, d_min) + xmax = min(ref_max, d_max) + + # Compute integrals + sum_ref = data_ref.integrate(xmin, xmax) + sum_d = data_to_scale.integrate(xmin, xmax) + + if sum_ref!=0 and sum_d!=0: + ref_scale = data_ref.get_scale() + data_to_scale.set_scale(ref_scale*sum_ref/sum_d) + + def compute(self): + """ + Compute scaling factors relative to reference data set + """ + if len(self._data_sets)<2: + return + + for i in range(self._reference): + Stitcher.normalize(self._data_sets[i+1], self._data_sets[i]) + for i in range(self._reference,len(self._data_sets)-1): + Stitcher.normalize(self._data_sets[i], self._data_sets[i+1]) + + def set_reference(self, id): + """ + Select which data set is the reference to normalize to + @param id: index of the reference in the internal file list. + """ + if id>=len(self._data_sets): + raise RuntimeError, "Stitcher: invalid reference ID" + self._reference = id + + def save_combined(self, file_path=None): + """ + Save the resulting scaled I(Q) curves in one data file + @param file_path: file to save data in + """ + iq = self.get_scaled_data() + if file_path is not None: + SaveCanSAS1D(Filename=file_path, InputWorkspace=iq) + + def get_scaled_data(self): + """ + Return the data points for the scaled data set + """ + if len(self._data_sets)==0: + return + + ws_combined = "combined_Iq" + CloneWorkspace(InputWorkspace=self._data_sets[0].get_scaled_ws(), + OutputWorkspace=ws_combined) + + x = mtd[ws_combined].dataX(0) + y = mtd[ws_combined].dataY(0) + e = mtd[ws_combined].dataE(0) + if len(x)!=len(y) and len(x)!=len(e): + raise RuntimeError, "Stitcher expected distributions but got histo" + + for d in self._data_sets[1:]: + ws = d.get_scaled_ws() + if ws is not None: + _x = mtd[ws].dataX(0) + _y = mtd[ws].dataY(0) + _e = mtd[ws].dataE(0) + if len(_x)!=len(_y) and len(_x)!=len(_e): + raise RuntimeError, "Stitcher expected distributions but got histo" + x.extend(_x) + y.extend(_y) + e.extend(_e) + + zipped = zip(x,y,e) + def cmp(p1,p2): + if p2[0]==p1[0]: + return 0 + return -1 if p2[0]>p1[0] else 1 + combined = sorted(zipped, cmp) + x,y,e = zip(*combined) + + xtmp = mtd[ws_combined].dataX(0) + ytmp = mtd[ws_combined].dataY(0) + etmp = mtd[ws_combined].dataE(0) + for i in range(len(ytmp)): + xtmp[i] = x[i] + ytmp[i] = y[i] + etmp[i] = e[i] + + return ws_combined + + + + + + + \ No newline at end of file