Skip to content

Commit

Permalink
Re #4303 add autoreduce options
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jan 27, 2012
1 parent fdd114f commit 5095818
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Interface/reduction_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, instrument=None, instrument_list=None):
# Name handle for the instrument
if instrument is None:
instrument = unicode(settings.value("instrument_name", QtCore.QVariant('')).toString())
if instrument not in instrument_list:
if instrument_list is not None and instrument not in instrument_list:
instrument = None

self._instrument = instrument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"""
from interface import InstrumentInterface
from reduction_gui.widgets.reflectometer.refl_data_simple import DataReflWidget
from reduction_gui.widgets.reflectometer.stitcher import StitcherWidget
#from reduction_gui.widgets.reflectometer.refl_parameters import ParametersReflWidget
#from reduction_gui.widgets.reflectometer.refl_norm import NormReflWidget
#from reduction_gui.widgets.reflectometer.advanced import AdvancedWidget
#from reduction_gui.widgets.output import OutputWidget
try:
from reduction_gui.widgets.reflectometer.stitcher import StitcherWidget
HAS_STITCHER = True
except:
HAS_STITCHER = False


from reduction_gui.reduction.reflectometer.refl_reduction import REFLReductionScripter

Expand All @@ -32,16 +33,6 @@ def __init__(self, name, settings):

# data REF_L tab
self.attach(DataReflWidget(settings = self._settings, name=name))
self.attach(StitcherWidget(settings = self._settings))

# normalization REF_L tab
#self.attach(NormReflWidget(settings = self._settings, data_proxy=DataProxy))

# Parameters REF_L tab
#self.attach(ParametersReflWidget(settings = self._settings, data_proxy=DataProxy))

# Parameters advanced tab
#self.attach(AdvancedWidget(settings = self._settings, data_proxy=DataProxy))

# Reduction output
#self.attach(OutputWidget(settings = self._settings))
if HAS_STITCHER:
self.attach(StitcherWidget(settings = self._settings))

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def to_xml(self):
def from_xml(self, xml_str):
self.reset()
dom = xml.dom.minidom.parseString(xml_str)
self.from_xml_dom(dom)
self.from_xml_element(dom)
element_list = dom.getElementsByTagName("Data")
if len(element_list)>0:
instrument_dom = element_list[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
import reduction_gui.widgets.util as util
import math
import os
import _qti
import time
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
from reduction_gui.widgets.base_widget import BaseWidget
import ui.reflectometer.ui_data_refl_simple

from reduction.instruments.reflectometer import data_manipulation

IS_IN_MANTIDPLOT = False
try:
import mantidplot
from MantidFramework import *
mtd.initialise(False)
from mantidsimple import *
import _qti
from reduction.instruments.reflectometer import data_manipulation

IS_IN_MANTIDPLOT = True
except:
pass
Expand Down Expand Up @@ -57,6 +58,14 @@ def initialize_content(self):
self._summary.data_background_to_pixel1.setValidator(QtGui.QIntValidator(self._summary.data_background_to_pixel1))
self._summary.data_from_tof.setValidator(QtGui.QDoubleValidator(self._summary.data_from_tof))
self._summary.data_to_tof.setValidator(QtGui.QDoubleValidator(self._summary.data_to_tof))

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

self._summary.norm_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))
self._summary.norm_background_from_pixel1.setValidator(QtGui.QIntValidator(self._summary.norm_background_from_pixel1))
self._summary.norm_background_to_pixel1.setValidator(QtGui.QIntValidator(self._summary.norm_background_to_pixel1))

# Event connections
self.connect(self._summary.norm_background_switch, QtCore.SIGNAL("clicked(bool)"), self._norm_background_clicked)
Expand All @@ -67,6 +76,91 @@ def initialize_content(self):
self.connect(self._summary.angle_list, QtCore.SIGNAL("itemSelectionChanged()"), self._angle_changed)
self.connect(self._summary.remove_btn, QtCore.SIGNAL("clicked()"), self._remove_item)

# Set up the automated reduction options
self._summary.auto_reduce_check.setChecked(False)
self._auto_reduce(False)
self.connect(self._summary.auto_reduce_check, QtCore.SIGNAL("clicked(bool)"), self._auto_reduce)
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()

def _create_auto_reduce_template(self):
m = self.get_editing_state()
m.data_files = ["runNumber"]
reduce_script = m.to_script()

content = "# Script automatically generated by Mantid on %s\n" % time.ctime()
content += "import sys\n"
content += "import os\n"
content += "sys.path.append('/opt/Mantid/bin')\n"
content += "from MantidFramework import *\n"
content += "mtd.initialize()\n"
content += "from mantidsimple import *\n\n"

content += "runNumber=sys.argv[1]\n"
content += "outputDir=sys.argv[2]\n\n"

content += reduce_script

content += "\n"
content += "file_name = 'reflectivity_'+runNumber+'.txt'\n"
content += "file_path = os.path.join(outputDir,file_name)\n"
content += "SaveAscii(Filename=file_path,\n"
content += " InputWorkspace='reflectivity_runNumber',\n"
content += " Separator='Tab',\n"
content += " CommentIndicator='# ')"

home_dir = os.path.expanduser('~')
f=open(os.path.join(home_dir,"reduce_REF_L.py"),'w')
f.write(content)
f.close()

# Check whether we can write to the system folder
def _report_error(error=None):
message = ""
if error is not None:
message += error+'\n\n'
else:
message += "The automated reduction script could not be saved.\n\n"
message += "Your script has been saved in your home directory:\n"
message += os.path.join(home_dir,"reduce_REF_L.py")
message += "\n\nTry copying it by hand in %s\n" % sns_path
QtGui.QMessageBox.warning(self, "Error saving automated reduction script", message)

sns_path = "/SNS/REF_L/shared/autoreduce"
if os.path.isdir(sns_path):
if os.access(sns_path, os.W_OK):
file_path = os.path.join(sns_path,"reduce_REF_L.py")
if os.path.isfile(file_path) and not os.access(file_path, os.W_OK):
_report_error("You do not have permissions to overwrite %s." % file_path)
return
try:
f = open(file_path,'w')
f.write(content)
f.close()
QtGui.QMessageBox.information(self, "Automated reduction script saved",
"The automated reduction script has been updated")
except:
_report_error()
else:
_report_error("You do not have permissions to write to %s." % sns_path)
else:
_report_error("The autoreduce directory doesn't exist.\n"
"Your instrument may not be set up for automated reduction.")

def _auto_reduce(self, is_checked=False):
if is_checked:

self._summary.auto_reduce_help_label.show()
self._summary.auto_reduce_tip_label.show()
self._summary.auto_reduce_btn.show()
else:
self._summary.auto_reduce_help_label.hide()
self._summary.auto_reduce_tip_label.hide()
self._summary.auto_reduce_btn.hide()

def _remove_item(self):
row = self._summary.angle_list.currentRow()
if row>=0:
Expand Down Expand Up @@ -102,11 +196,17 @@ def _norm_background_clicked(self, is_checked):
self._summary.norm_background_to_pixel1_label.setEnabled(is_checked)

def _plot_count_vs_y(self):
if not IS_IN_MANTIDPLOT:
return

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 _plot_tof(self):
if not IS_IN_MANTIDPLOT:
return

f = FileFinder.findRuns("REF_L%s" % str(self._summary.norm_run_number_edit.text()))
if len(f)>0 and os.path.isfile(f[0]):
data_manipulation.tof_distribution(f[0])
Expand Down
114 changes: 114 additions & 0 deletions Code/Mantid/scripts/Interface/ui/reflectometer/data_refl_simple.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2200,13 +2200,120 @@ Drag items to change the reduction order.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Click to add the data set above to the reduction list</string>
</property>
<property name="text">
<string>Save to list</string>
</property>
</widget>
</item>
</layout>
</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>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="auto_reduce_help_label">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;Automated Reduction&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-style:italic;&quot;&gt;The parameters above can be used to specify how new data files &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-style:italic;&quot;&gt;are automatically reduced.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-style:italic;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-style:italic;&quot;&gt;Once you click the &amp;quot;Apply Changes&amp;quot; button, the parameters above&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:12pt; font-style:italic;&quot;&gt;will be used to reduce all your data files until you change them again.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt; font-style:italic;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<spacer name="horizontalSpacer_12">
<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>
<item>
<widget class="QLabel" name="auto_reduce_tip_label">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Click to apply changes to the automated reduction process:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</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="QPushButton" name="auto_reduce_btn">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Click to apply changes to the automated reduction process</string>
</property>
<property name="text">
<string>Apply Changes</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand All @@ -2223,6 +2330,13 @@ Drag items to change the reduction order.</string>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="auto_reduce_check">
<property name="text">
<string>Show automated reduction information</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 5095818

Please sign in to comment.