Skip to content

Commit

Permalink
Refs #10357. Improved loading.
Browse files Browse the repository at this point in the history
On branch feature/10357_eventfilter_gui_load
  modified:   Mantid/scripts/FilterEvents/MainWindow.ui
  modified:   Mantid/scripts/FilterEvents/Ui_MainWindow.py
  modified:   Mantid/scripts/FilterEvents/eventFilterGUI.py
Including
(1) Changed the label to load file;
(2) Enabled to load by run number, nexus file name or
instrument_runnumber;
(3) Name of output workspace is made consistent as
InstrumentShortName_RunNumber_event

  modified:   Mantid/scripts/FilterEvents.py
An unnecessary output is removed
  • Loading branch information
wdzhou committed Nov 5, 2014
1 parent 0b966e4 commit 84aca9c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 45 deletions.
2 changes: 0 additions & 2 deletions Code/Mantid/scripts/FilterEvents.py
Expand Up @@ -11,8 +11,6 @@ def qapp():

app = qapp()

print "[******************] It is touched."

reducer = eventFilterGUI.MainWindow() #the main ui class in this file is called MainWindow
reducer.show()
app.exec_()
64 changes: 43 additions & 21 deletions Code/Mantid/scripts/FilterEvents/MainWindow.ui
Expand Up @@ -24,30 +24,17 @@
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="pushButton_browse">
<property name="geometry">
<rect>
<x>560</x>
<x>530</x>
<y>30</y>
<width>98</width>
<width>61</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>66</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>File Name</string>
<string>Browse</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
Expand All @@ -59,6 +46,9 @@
<height>27</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The name of the NeXus file or the run number to load. &lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Run number should be InstrumentName_RunNumber (for example, NOM_11788)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QSlider" name="horizontalSlider">
<property name="geometry">
Expand Down Expand Up @@ -97,15 +87,15 @@
<rect>
<x>130</x>
<y>80</y>
<width>381</width>
<width>461</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>560</x>
<x>610</x>
<y>80</y>
<width>98</width>
<height>27</height>
Expand Down Expand Up @@ -892,7 +882,7 @@
</property>
</widget>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="widget">
<attribute name="title">
<string>Error Message</string>
</attribute>
Expand Down Expand Up @@ -970,7 +960,7 @@
<widget class="QLabel" name="label_error">
<property name="geometry">
<rect>
<x>700</x>
<x>730</x>
<y>20</y>
<width>81</width>
<height>41</height>
Expand All @@ -988,6 +978,38 @@
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; color:#ff0000;&quot;&gt;ERROR!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_logname_2">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>111</width>
<height>17</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The name of the NeXus file or the run number to load&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Label for file name or run number&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>File / Run </string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_load">
<property name="geometry">
<rect>
<x>610</x>
<y>30</y>
<width>98</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down
32 changes: 19 additions & 13 deletions Code/Mantid/scripts/FilterEvents/Ui_MainWindow.py
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'MainWindow.ui'
#
# Created: Wed Sep 24 11:22:31 2014
# Created: Tue Nov 4 15:50:54 2014
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!
Expand All @@ -28,12 +28,9 @@ def setupUi(self, MainWindow):
self.graphicsView = QtGui.QGraphicsView(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(20, 150, 741, 411))
self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(560, 30, 98, 27))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 30, 66, 17))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.pushButton_browse = QtGui.QPushButton(self.centralwidget)
self.pushButton_browse.setGeometry(QtCore.QRect(530, 30, 61, 27))
self.pushButton_browse.setObjectName(_fromUtf8("pushButton_browse"))
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(130, 30, 381, 27))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
Expand All @@ -48,10 +45,10 @@ def setupUi(self, MainWindow):
self.verticalSlider.setTickPosition(QtGui.QSlider.TicksAbove)
self.verticalSlider.setObjectName(_fromUtf8("verticalSlider"))
self.comboBox = QtGui.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(130, 80, 381, 27))
self.comboBox.setGeometry(QtCore.QRect(130, 80, 461, 27))
self.comboBox.setObjectName(_fromUtf8("comboBox"))
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(560, 80, 98, 27))
self.pushButton_3.setGeometry(QtCore.QRect(610, 80, 98, 27))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(120, 600, 151, 27))
Expand Down Expand Up @@ -282,14 +279,20 @@ def setupUi(self, MainWindow):
self.lineEdit_outwsname.setGeometry(QtCore.QRect(120, 650, 211, 27))
self.lineEdit_outwsname.setObjectName(_fromUtf8("lineEdit_outwsname"))
self.label_error = QtGui.QLabel(self.centralwidget)
self.label_error.setGeometry(QtCore.QRect(700, 20, 81, 41))
self.label_error.setGeometry(QtCore.QRect(730, 20, 81, 41))
font = QtGui.QFont()
font.setPointSize(14)
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.label_error.setFont(font)
self.label_error.setObjectName(_fromUtf8("label_error"))
self.label_logname_2 = QtGui.QLabel(self.centralwidget)
self.label_logname_2.setGeometry(QtCore.QRect(20, 30, 111, 17))
self.label_logname_2.setObjectName(_fromUtf8("label_logname_2"))
self.pushButton_load = QtGui.QPushButton(self.centralwidget)
self.pushButton_load.setGeometry(QtCore.QRect(610, 30, 98, 27))
self.pushButton_load.setObjectName(_fromUtf8("pushButton_load"))
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 823, 25))
Expand All @@ -299,7 +302,6 @@ def setupUi(self, MainWindow):
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)

# Add figure to graphics view
self.figure = Figure((4.0, 3.0), dpi=100)
self.theplot = self.figure.add_subplot(111)
self.graphicsView = FigureCanvas(self.figure)
Expand All @@ -313,8 +315,8 @@ def setupUi(self, MainWindow):

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("MainWindow", "Load", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "File Name", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_browse.setText(QtGui.QApplication.translate("MainWindow", "Browse", None, QtGui.QApplication.UnicodeUTF8))
self.lineEdit.setToolTip(QtGui.QApplication.translate("MainWindow", "<html><head/><body><p>The name of the NeXus file or the run number to load. </p><p><br/></p><p>Run number should be InstrumentName_RunNumber (for example, NOM_11788)</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "Use", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Starting Time", None, QtGui.QApplication.UnicodeUTF8))
self.label_4.setText(QtGui.QApplication.translate("MainWindow", "Stopping Time", None, QtGui.QApplication.UnicodeUTF8))
Expand Down Expand Up @@ -369,4 +371,8 @@ def retranslateUi(self, MainWindow):
self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Splitter Title", None, QtGui.QApplication.UnicodeUTF8))
self.label_outwsname.setText(QtGui.QApplication.translate("MainWindow", "Output Name", None, QtGui.QApplication.UnicodeUTF8))
self.label_error.setText(QtGui.QApplication.translate("MainWindow", "<html><head/><body><p><span style=\" color:#ff0000;\">ERROR!</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.label_logname_2.setToolTip(QtGui.QApplication.translate("MainWindow", "<html><head/><body><p>The name of the NeXus file or the run number to load</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.label_logname_2.setWhatsThis(QtGui.QApplication.translate("MainWindow", "<html><head/><body><p>Label for file name or run number</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
self.label_logname_2.setText(QtGui.QApplication.translate("MainWindow", "File / Run ", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_load.setText(QtGui.QApplication.translate("MainWindow", "Load", None, QtGui.QApplication.UnicodeUTF8))

82 changes: 73 additions & 9 deletions Code/Mantid/scripts/FilterEvents/eventFilterGUI.py
Expand Up @@ -17,6 +17,8 @@
import mantid.kernel
from mantid.simpleapi import AnalysisDataService

from mantid.kernel import ConfigService

import os

HUGE_FAST = 10000
Expand Down Expand Up @@ -45,11 +47,16 @@ class MainWindow(QtGui.QMainWindow):
# Version 2.0 + Import
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
self.figure = Figure((4.0, 3.0), dpi=100)
self.theplot = self.figure.add_subplot(111)
self.graphicsView = FigureCanvas(self.figure)
self.graphicsView.setParent(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(40, 230, 721, 411))
self.graphicsView.setGeometry(QtCore.QRect(20, 150, 741, 411))
self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
"""
Expand All @@ -60,6 +67,10 @@ def __init__(self, parent=None):
# Base class
QtGui.QMainWindow.__init__(self,parent)

# Mantid configuration
config = ConfigService.Instance()
self._instrument = config["default.instrument"]

# Central widget
self.centralwidget = QtGui.QWidget(self)

Expand Down Expand Up @@ -117,7 +128,8 @@ def __init__(self, parent=None):
# File loader
self.scanEventWorkspaces()
self.connect(self.ui.pushButton_refreshWS, SIGNAL('clicked()'), self.scanEventWorkspaces)
self.connect(self.ui.pushButton_2, SIGNAL('clicked()'), self.browse_openFile)
self.connect(self.ui.pushButton_browse, SIGNAL('clicked()'), self.browse_File)
self.connect(self.ui.pushButton_load, SIGNAL('clicked()'), self.load_File)
self.connect(self.ui.pushButton_3, SIGNAL('clicked()'), self.use_existWS)

# Set up time
Expand Down Expand Up @@ -594,20 +606,36 @@ def set_maxLogValue(self):

return

def browse_openFile(self):
def browse_File(self):
""" Open a file dialog to get file
"""
filename = QtGui.QFileDialog.getOpenFileName(self, 'Input File Dialog',
self._defaultdir, "Data (*.nxs *.dat);;All files (*.*)")

self.ui.lineEdit.setText(str(filename))

print "Selected file: ", filename
# print "Selected file: ", filename

dataws = self._loadFile(str(filename))
self._importDataWorkspace(dataws)
return

def load_File(self):
""" Load the file by file name or run number
"""
# Get file name from line editor
filename = str(self.ui.lineEdit.text())

self._defaultdir = os.path.dirname(str(filename))
# Find out it is relative path or absolute path
if os.path.abspath(filename) == filename:
isabspath = True
else:
isabspath = False

dataws = self._loadFile(str(filename))
if dataws is None:
print "Unable to locate run %s in default directory %s." % (filename, self._defaultdir)
else:
self._importDataWorkspace(dataws)
self._defaultdir = os.path.dirname(str(filename))

return

Expand Down Expand Up @@ -779,17 +807,53 @@ def scanEventWorkspaces(self):
# ENDFOR

if len(eventwsnames) > 0:
self.ui.comboBox.clear()
self.ui.comboBox.addItems(eventwsnames)

return


def _loadFile(self, filename):
""" Load file
""" Load file or run
File will be loaded to a workspace shown in MantidPlot
"""
wsname = os.path.splitext(os.path.split(filename)[1])[0]
config = ConfigService

# Check input file name and output workspace name
if filename.isdigit() is True:
# Construct a file name from run number
runnumber = int(filename)
if runnumber <= 0:
print "Run number cannot be less or equal to zero. User gives %s. " % (filename)
return None
else:
ishort = config.getInstrument(self._instrument).shortName()
filename = "%s_%s" %(ishort, filename)
wsname = filename + "_event"

elif filename.count(".") > 0:
# A proper file name
wsname = os.path.splitext(os.path.split(filename)[1])[0]

elif filename.count("_") == 1:
# A short one as instrument_runnumber
iname = filename.split("_")[0]
str_runnumber = filename.split("_")[1]
if str_runnumber.isdigit() is True and int(str_runnumber) > 0:
# Acccepted format
ishort = config.getInstrument(iname).shortName()
wsname = "%s_%s_event" % (ishort, str_runnumber)
else:
# Non-supported
print "File name / run number in such format %s is not supported. " % (filename)
return None

else:
# Unsupported format
print "File name / run number in such format %s is not supported. " % (filename)
return None

# Load
try:
ws = api.Load(Filename=filename, OutputWorkspace=wsname)
except:
Expand Down

0 comments on commit 84aca9c

Please sign in to comment.