From 331855f29e84949ef42229cd440f59ed65d29d85 Mon Sep 17 00:00:00 2001
From: Wenduo Zhou
Date: Wed, 22 Apr 2015 14:51:03 -0400
Subject: [PATCH] Checkpointing progress on fixing coding errors. Refs #11289.
---
.../HfirPDReductionControl.py | 209 ++++++++++++------
.../HFIRPowderReduction/HfirPDReductionGUI.py | 183 ++++++++-------
.../HFIRPowderReduction/MplFigureCanvas.py | 8 +-
.../HFIRPowderReduction/Ui_MainWindow.py | 57 +++--
.../HFIRPowderReduction/Ui_MainWindow.ui | 28 ++-
.../HFIRPowderReduction/testGUI_Normalized.py | 20 +-
.../HFIRPowderReduction/testGUI_RawDetect.py | 3 +-
7 files changed, 326 insertions(+), 182 deletions(-)
diff --git a/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionControl.py b/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionControl.py
index ec89826311f7..3ecdd449f723 100644
--- a/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionControl.py
+++ b/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionControl.py
@@ -66,10 +66,24 @@ def __init__(self, exp, scan):
self.reducedws = None
self.binsize = 1E10
+ self._rawSpiceTableWS = None
+ self._rawLogInfoWS = None
+
self._wavelength = None
return
+ def getRawSpiceTable(self):
+ """
+ """
+ return self._rawSpiceTableWS
+
+
+ def getRawInfoMatrixWS(self):
+ """
+ """
+ return self._rawLogInfoWS
+
def getVanadiumPeaks(self):
"""
"""
@@ -98,6 +112,26 @@ def setup(self, datamdws, monitormdws, reducedws=None, unit=None, binsize=None):
return
+ def setRawWorkspaces(self, spicetablews, logmatrixws):
+ """ Set 2 raw SPICE workspaces
+ """
+ # Validate
+ if spicetablews.id() != 'TableWorkspace' or logmatrixws.id() != 'Workspace2D':
+ raise NotImplementedError("Input workspaces for setRawWorkspaces() are not of correct types.")
+
+ self._rawSpiceTableWS = spicetablews
+ self._rawLogInfoWS = logmatrixws
+
+ return
+
+ def setupMDWrokspaces(self, datamdws, monitormdws):
+ """
+ """
+ self.datamdws = datamdws
+ self.monitormdws = monitormdws
+
+ return
+
def setVanadiumPeaks(self, vanpeakposlist):
""" Set up vanadium peaks in 2theta
"""
@@ -145,29 +179,39 @@ def __init__(self):
def getIndividualDetCounts(self, exp, scan, detid, xlabel):
""" Get individual detector counts
"""
- # check and get data
+ # Check and get data
+ exp = int(exp)
+ scan = int(scan)
+ detid = int(detid)
+
if self._myWorkspaceDict.has_key((exp, scan)) is False:
raise NotImplementedError("Exp %d Scan %d does not have reduced \
workspace." % (exp, scan))
else:
rmanager = self._myWorkspaceDict[(exp, scan)]
+
+ datamdws = rmanager.datamdws
+ monitormdws = rmanager.monitormdws
+
+ if datamdws is None or monitormdws is None:
+ raise NotImplementedError('Reduction manager has no MDEventWorkspaces setup.')
# END-IF-ELSE
- # get raw counts
+ # Get raw counts
# FIXME : use **args
if xlabel is None:
- tempoutws = api.GetSpiceDataRawCountsFromMD(
- InputWorkspace=rmanager.datamdws,
- MonitorWorkspace=rmanager.monitormdws,
- Mode='Detector',
- DetectorID = detid)
+ tempoutws = \
+ api.GetSpiceDataRawCountsFromMD(InputWorkspace=datamdws,
+ MonitorWorkspace=monitormdws,
+ Mode='Detector',
+ DetectorID = detid)
else:
- tempoutws = api.GetSpiceDataRawCountsFromMD(
- InputWorkspace=rmanager.datamdws,
- MonitorWorkspace=rmanager.monitormdws,
- Mode='Detector',
- DetectorID = detid,
- XLabel=xlabel)
+ tempoutws = \
+ api.GetSpiceDataRawCountsFromMD(InputWorkspace=datamdws,
+ MonitorWorkspace=monitormdws,
+ Mode='Detector',
+ DetectorID = detid,
+ XLabel=xlabel)
vecx = tempoutws.readX(0)[:]
vecy = tempoutws.readY(0)[:]
@@ -178,12 +222,20 @@ def getIndividualDetCounts(self, exp, scan, detid, xlabel):
def getRawDetectorCounts(self, exp, scan, ptnolist=None):
""" Return raw detector counts as a list of 3-tuples
"""
- # check and get data
+ # Check and get data
+ exp = int(exp)
+ scan = int(scan)
+
if self._myWorkspaceDict.has_key((exp, scan)) is False:
raise NotImplementedError("Exp %d Scan %d does not have reduced \
workspace." % (exp, scan))
else:
rmanager = self._myWorkspaceDict[(exp, scan)]
+ datamdws = rmanager.datamdws
+ monitormdws = rmanager.monitormdws
+
+ if datamdws is None or monitormdws is None:
+ raise NotImplementedError('Reduction manager has no MDEventWorkspaces setup.')
# END-IF-ELSE
# get the complete list of Pt. number
@@ -195,11 +247,10 @@ def getRawDetectorCounts(self, exp, scan, ptnolist=None):
# Loop over all Pt. number
for pt in ptnolist:
# get data
- tempoutws = api.GetSpiceDataRawCountsFromMD(
- InputWorkspace=rmanager.datamdws,
- MonitorWorkspace=rmanager.monitormdws,
- Mode='Pt.',
- Pt = pt)
+ tempoutws = api.GetSpiceDataRawCountsFromMD(InputWorkspace=datamdws,
+ MonitorWorkspace=monitormdws,
+ Mode='Pt.',
+ Pt = pt)
vecx = tempoutws.readX(0)[:]
vecy = tempoutws.readY(0)[:]
@@ -378,7 +429,7 @@ def loadSpicePDData(self, expno, scanno, datafilename):
# Create a reduction manager and add workspaces to it
wsmanager = PDRManager(expno, scanno)
- wsmanager.setRawWorkspaces(tablews, infws)
+ wsmanager.setRawWorkspaces(tablews, infows)
self._myWorkspaceDict[ (int(expno), int(scanno) )] = wsmanager
return
@@ -395,9 +446,10 @@ def parseSpiceData(self, expno, scanno, detefftablews=None):
int(scanno)))
# Convert to MDWorkspace
- tablews = wsmanager.getRawDataTable()
+ tablews = wsmanager.getRawSpiceTable()
infows = wsmanager.getRawInfoMatrixWS()
+ basewsname = tablews.name().split('_RawTable')[0]
datamdwsname = basewsname + "_DataMD"
monitorwsname = basewsname + "_MonitorMD"
api.ConvertSpiceDataToRealSpace(InputWorkspace=tablews,
@@ -426,6 +478,7 @@ def mergeReduceSpiceData(self, expscanfilelist, unit, xmin, xmax, binsize,
Arguements:
- expscanfilelist: list of 3 tuples: expnumber, scannumber and file name
"""
+ # FIXME : Updated to new workflow! and catch more exceptions
# data structure initialization
datamdwslist = []
monitormdwslist = []
@@ -445,9 +498,21 @@ def mergeReduceSpiceData(self, expscanfilelist, unit, xmin, xmax, binsize,
raise NotImplementedError("Invalid exp-scan-file list tuple. \
Reason: %s." % (str(e)))
- # reduce data
+ # load spice data
+ execstatus = self.loadSpicePDData(exp, scan, fname)
+
+ # TODO - Need to deal with correction files
+ detefftablews = None
+
+ # parse raw spice data to MDEventsWorkspaces
+ execstatus = self.parseSpiceData(exp, scan, detefftablews)
+
+ # get exluded detectors' list
+ excludeddetlist = []
+
+ # reduce
rebingood = self.reduceSpicePDData(exp, scan, fname, unit, xmin, xmax,
- binsize, wavelength)
+ binsize, wavelength, excludeddetlist)
if rebingood is True:
wsmanager = self.getWorkspace(exp, scan, True)
@@ -526,7 +591,7 @@ def rebin(self, exp, scan, unit, wavelength, xmin, binsize, xmax):
return True
- def reduceSpicePDData(self, exp, scan, datafilename, unit, xmin, xmax, binsize, wavelength=None):
+ def reduceSpicePDData(self, exp, scan, datafilename, unit, xmin, xmax, binsize, wavelength=None, excludeddetlist=[]):
""" Reduce SPICE powder diffraction data.
Return - Boolean as reduction is successful or not
"""
@@ -564,39 +629,39 @@ def reduceSpicePDData(self, exp, scan, datafilename, unit, xmin, xmax, binsize,
datamdws = wsmanager.datamdws
monitormdws = wsmanager.monitormdws
- # Get correction files
- # TODO / FIXME : Develop file loading and parsing algorithms!!!
- localdir = os.path.dirname(datafilename)
- print "[Dev] Data file name: %s in local directory %s." % (datafilename, localdir)
- status, returnbody = self.retrieveCorrectionData(instrument='HB2A', datamdws=datamdws, exp=exp, localdatadir=localdir)
-
- if status is False:
- errmsg = returnbody
- self._logError("Unable to download correction files for Exp %d Scan %d. \
- \nReason: %s." % (expno, scanno, errmsg))
- vcorrfilename = None
- excludedfilename = None
- else:
- print "[Info] Detectors correction files: %s." % (str(returnbody))
- autowavelength = returnbody[0]
- vcorrfilename = returnbody[1]
- excludedfilename = returnbody[2]
- print "[Dev] Wavelength: %f vs %f (user vs. local)" % (wavelength, autowavelength)
-
- if autowavelength is not None:
- wavelength = autowavelength
+ # # Get correction files
+ # # TODO / FIXME : Develop file loading and parsing algorithms!!!
+ # localdir = os.path.dirname(datafilename)
+ # print "[Dev] Data file name: %s in local directory %s." % (datafilename, localdir)
+ # status, returnbody = self.retrieveCorrectionData(instrument='HB2A', datamdws=datamdws, exp=exp, localdatadir=localdir)
+
+ # if status is False:
+ # errmsg = returnbody
+ # self._logError("Unable to download correction files for Exp %d Scan %d. \
+ # \nReason: %s." % (expno, scanno, errmsg))
+ # vcorrfilename = None
+ # excludedfilename = None
+ # else:
+ # print "[Info] Detectors correction files: %s." % (str(returnbody))
+ # autowavelength = returnbody[0]
+ # vcorrfilename = returnbody[1]
+ # excludedfilename = returnbody[2]
+ # print "[Dev] Wavelength: %f vs %f (user vs. local)" % (wavelength, autowavelength)
+ #
+ # if autowavelength is not None:
+ # wavelength = autowavelength
# TODO - Parse and setup corrections...
- if vcorrfilename is not None:
- vcorrtablews = self._myControl.parseDetEfficiencyFile('HB2A', vcorrfilename)
- else:
- vcorrtablews = None
+ # if vcorrfilename is not None:
+ # vcorrtablews = self._myControl.parseDetEfficiencyFile('HB2A', vcorrfilename)
+ # else:
+ # vcorrtablews = None
- # TODO - Parse and set up excluded detectors
- if excludedfilename is not None:
- excludeddetlist = self._myControl.parseExcludedDetFile('HB2A', excludedfilename)
- else:
- excludeddetlist = []
+ # # TODO - Parse and set up excluded detectors
+ # if excludedfilename is not None:
+ # excludeddetlist = self._myControl.parseExcludedDetFile('HB2A', excludedfilename)
+ # else:
+ # excludeddetlist = []
# binning from MD to single spectrum ws
# set up binning parameters
@@ -605,16 +670,17 @@ def reduceSpicePDData(self, exp, scan, datafilename, unit, xmin, xmax, binsize,
else:
binpar = "%.7f, %.7f, %.7f" % (xmin, binsize, xmax)
+ basewsname = datamdws.name().split("_DataMD")[0]
outwsname = basewsname + "_Reduced"
# TODO - Applied excluded detectors and vanadium correction into account
- api.ConvertCWPDMDToSpectra(InputWorkspace=datamdwsname,
- InputMonitorWorkspace=monitorwsname,
+ api.ConvertCWPDMDToSpectra(InputWorkspace=datamdws,
+ InputMonitorWorkspace=monitormdws,
OutputWorkspace=outwsname,
BinningParams=binpar,
UnitOutput = unit,
NeutronWaveLength=wavelength)
- print "[DB] Reduction is finished. Data is in workspace %s. " % (datamdwsname)
+ print "[DB] Reduction is finished. Data is in workspace %s. " % (outwsname)
# Set up class variable for min/max and
outws = AnalysisDataService.retrieve(outwsname)
@@ -633,7 +699,7 @@ def reduceSpicePDData(self, exp, scan, datafilename, unit, xmin, xmax, binsize,
return True
- def retrieveCorrectionData(self, instrument, datamdws, exp, localdatadir):
+ def retrieveCorrectionData(self, instrument, exp, scan, localdatadir):
""" Retrieve including dowloading and/or local locating
powder diffraction's correction files
@@ -646,13 +712,19 @@ def retrieveCorrectionData(self, instrument, datamdws, exp, localdatadir):
"""
if instrument.upper() == 'HB2A':
# For HFIR HB2A only
+
+ try:
+ wsmanager = self._myWorkspaceDict[(exp, scan)]
+ except KeyError as e:
+ raise e
# Get parameter m1 and colltrans
- m1 = datamdws.getExperimentInfo(0).run().getProperty('m1').value
- try:
- colltrans = datamdws.getExperimentInfo(0).run().getProperty('colltrans').value
- except RuntimeError:
- colltrans = None
+ m1 = self._getValueFromTable(wsmanager.getRawSpiceTable(), 'm1')
+ colltrans = self._getValueFromTable(wsmanager.getRawSpiceTable(), 'colltrans')
+ #try:
+ # colltrans = datamdws.getExperimentInfo(0).run().getProperty('colltrans').value
+ #except RuntimeError:
+ # colltrans = None
# detector efficiency file
detefffname, deteffurl, wavelength = hutil.makeHB2ADetEfficiencyFileName(exp, m1, colltrans)
@@ -759,6 +831,17 @@ def stripVanadiumPeaks(self, exp, scan, binparams, vanpeakposlist=None):
return
+ def _getValueFromTable(self, tablews, colname, rowindex=0):
+ """ Get value from a table workspace
+ """
+ colnames = tablews.getColumnNames()
+ try:
+ colindex = colnames.index(colname)
+ rvalue = tablews.cell(rowindex, colindex)
+ except ValueError:
+ rvalue = None
+
+ return rvalue
""" External Methods """
def downloadFile(url, localfilepath):
diff --git a/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py b/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py
index 098f238ec2b2..29cbf58df59a 100644
--- a/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py
+++ b/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py
@@ -1,6 +1,8 @@
################################################################################
#
# Main class for HFIR powder reduction GUI
+#
+# Key word for future developing: FUTURE, NEXT, REFACTOR
#
################################################################################
@@ -240,7 +242,7 @@ def _initSetup(self):
self._viewMerge_Y = None
# Control of plots: key = canvas, value = list of 2-integer-tuple (expno, scanno)
- self._tabPlotDict = {}
+ self._tabLineDict = {}
return
@@ -316,9 +318,14 @@ def doCheckSrcServer(self):
def doClearIndDetCanvas(self):
- """ Clear the canvas in tab 'Individual Detector'
+ """ Clear the canvas in tab 'Individual Detector' and current plotted lines
+ in managing dictionary
"""
self.ui.graphicsView_indvDet.clearAllLines()
+ if self._tabLineDict.has_key(self.ui.graphicsView_indvDet):
+ self._tabLineDict[self.ui.graphicsView_indvDet] = []
+
+ return
def doClearMultiRunCanvas(self):
@@ -337,6 +344,7 @@ def doClearRawDetCanvas(self):
only need to clear lines
"""
self.ui.graphicsView_Raw.clearAllLines()
+ self._tabLineDict[self.ui.graphicsView_Raw] = []
return
@@ -410,6 +418,7 @@ def doLoadData(self):
status, returnbody = self._myControl.retrieveCorrectionData(instrument='HB2A',
exp=expno, scan=scanno,
localdatadir=localdir)
+
if status is True:
autowavelength = returnbody[0]
vancorrfname = returnbody[1]
@@ -418,7 +427,6 @@ def doLoadData(self):
autowavelength = None
vancorrfname = None
excldetfname = None
- else:
# Optionally parse det effecient file
if self.ui.checkBox_useDetEffCorr.isChecked():
@@ -431,15 +439,16 @@ def doLoadData(self):
else:
detefftablews = None
# ENDIF
-
+
# Parse SPICE data to MDEventWorkspaces
try:
- execstatus = self._myControl.arseSpiceData(self, expno, scanno, detefftablews=detefftablews)
+ print "Det EFF Table WS: ", str(detefftablews)
+ execstatus = self._myControl.parseSpiceData(expno, scanno, detefftablews)
if execstatus is False:
cause = "Parse data failed."
else:
cause = None
- except Exception as e:
+ except NotImplementedError as e:
execstatus = False
cause = str(e)
finally:
@@ -449,11 +458,13 @@ def doLoadData(self):
# END-TRY-EXCEPT-FINALLY
else:
# Unsupported case
- raise NotImplementedError("%d-th tab should not get this far."%(itab))
+ errmsg = "%d-th tab should not get this far.\n"%(itab)
+ errmsg += 'GUI has been changed, but the change has not been considered! iTab = %d' % (itab)
+ raise NotImplementedError(errmsg)
# ENDIFELSE
# Process wavelength
- wavelength = self.getFloat(self.self.ui.lineEdit_wavelength)
+ wavelength = self.getFloat(self.ui.lineEdit_wavelength)
if autowavelength is not None:
if wavelength is None:
wavelength = autowavelength
@@ -533,10 +544,6 @@ def doLoadData(self):
print "Vanadium peaks: ", vanpeakpos
self._plotPeakIndicators(self.ui.graphicsView_vanPeaks, vanpeakpos)
# ENDIF(execstatus)
-
- else:
- # Non-supported case
- raise NotImplementedError('GUI has been changed, but the change has not been considered!')
# END-IF-ELSE (itab)
return execstatus
@@ -607,6 +614,7 @@ def doMergeScans(self):
""" Merge several scans
for tab 'merge'
"""
+ # FIXME - Updated to new workflow!
# get inputs for scans
try:
expno = int(self.ui.lineEdit_expNo.text())
@@ -730,7 +738,7 @@ def doPlotDspacing(self):
def doPlotIndvDetMain(self):
""" Plot individual detector
"""
- # get exp and scan numbers and check whether the data has been loaded
+ # Get exp and scan numbers and check whether the data has been loaded
try:
expno = self.getInteger(self.ui.lineEdit_expNo)
scanno = self.getInteger(self.ui.lineEdit_scanNo)
@@ -738,13 +746,18 @@ def doPlotIndvDetMain(self):
self._logError(str(e))
return
- # get detector ID and x-label option
+ # Get detector ID and x-label option
try:
detid = self.getInteger(self.ui.lineEdit_detID)
except EmptyError:
self._logError("Detector ID must be specified for plotting individual detector.")
return
+ # Over plot previous or clear
+ overplot = self.ui.checkBox_overPlotIndvDet.isChecked()
+ if overplot is False:
+ self.doClearIndDetCanvas()
+
xlabel = str(self.ui.comboBox_indvDetXLabel.currentText())
if xlabel.strip() == "":
xlabel = None
@@ -767,6 +780,12 @@ def doPlotIndvDetNext(self):
# Plot
try:
currdetid = self._detID + 1
+
+ # Over plot previous or clear
+ overplot = self.ui.checkBox_overPlotIndvDet.isChecked()
+ if overplot is False:
+ self.doClearIndDetCanvas()
+
self._plotIndividualDetCounts(self._expNo, self._scanNo, currdetid,
self._indvXLabel)
except Exception as e:
@@ -785,6 +804,12 @@ def doPlotIndvDetPrev(self):
# Plot
try:
currdetid = self._detID - 1
+
+ # Over plot previous or clear
+ overplot = self.ui.checkBox_overPlotIndvDet.isChecked()
+ if overplot is False:
+ self.doClearIndDetCanvas()
+
self._plotIndividualDetCounts(self._expNo, self._scanNo, currdetid,
self._indvXLabel)
except Exception as e:
@@ -810,9 +835,7 @@ def doPlotQ(self):
def doPlotRawPtMain(self):
""" Plot current raw detector signal for a specific Pt.
"""
- # FIXME / TODO - shall check whether the plot is on canvas
-
- # get experiment number and scan number for data file
+ # Get experiment number and scan number for data file
try:
expno = self.getInteger(self.ui.lineEdit_expNo)
scanno = self.getInteger(self.ui.lineEdit_scanNo)
@@ -847,17 +870,16 @@ def doPlotRawPtMain(self):
def doPlotRawPtNext(self):
""" Plot next raw detector signals
"""
- # FIXME / TODO - shall check whether the plot is on canvas
-
- # check
+ # Check
if self._rawDetPtNo is not None:
ptno = self._rawDetPtNo + 1
else:
self._logError("Unable to plot previous raw detector \
because Pt. or Detector ID has not been set up yet.")
return
+ # ENDIFELSE
- # get plot mode and plot
+ # Get plot mode and plot
plotmode = str(self.ui.comboBox_rawDetMode.currentText())
overplot = bool(self.ui.checkBox_overpltRawDet.isChecked())
execstatus = self._plotRawDetSignal(self._rawDetExpNo, self._rawDetScanNo, plotmode,
@@ -1096,6 +1118,20 @@ def getInteger(self, lineedit):
return value
+ def getFloat(self, lineedit):
+ """ Get integer from line edit
+ """
+ valuestr = str(lineedit.text()).strip()
+ if len(valuestr) == 0:
+ raise EmptyError("Input is empty. It cannot be converted to integer.")
+
+ try:
+ value = float(valuestr)
+ except ValueError as e:
+ raise e
+
+ return value
+
def on_mouseMotion(self, event):
"""
@@ -1201,17 +1237,18 @@ def _plotIndividualDetCounts(self, expno, scanno, detid, xlabel):
scanno = int(scanno)
detid = int(detid)
- # load data if necessary
+ # Reject if data is not loaded
if self._myControl.hasDataLoaded(expno, scanno) is False:
- rvalue, filename = self._uiLoadDataFile(expno, scanno)
- if rvalue is False:
- self._logError("Unable to download or locate local data file for Exp %d \
- Scan %d." % (expno, scanno))
- return
- self._myControl.loadSpicePDData(expno, scanno, filename)
+ self._logError("Data file for Exp %d Scan %d has not been loaded." % (expno, scanno))
+ return False
+
+ # Canvas and line information
+ canvas = self.ui.graphicsView_indvDet
+ if self._tabLineDict.has_key(canvas) is False:
+ self._tabLineDict[canvas] = []
# pop out the xlabel list
- # FIXME - Only need to set up once!
+ # REFACTOR - Only need to set up once if previous plot has the same setup
floatsamplelognamelist = self._myControl.getSampleLogNames(expno, scanno)
self.ui.comboBox_indvDetXLabel.clear()
self.ui.comboBox_indvDetXLabel.addItems(floatsamplelognamelist)
@@ -1219,33 +1256,27 @@ def _plotIndividualDetCounts(self, expno, scanno, detid, xlabel):
# get data
vecx, vecy = self._myControl.getIndividualDetCounts(expno, scanno, detid, xlabel)
- # plot to canvas
- canvas = self.ui.graphicsView_indvDet
+ # Plot to canvas
marker, color = canvas.getNextLineMarkerColorCombo()
if xlabel is None:
- xlabel = r'2\theta'
+ xlabel = r'$2\theta$'
label = "Detector ID: %d" % (detid)
- # Check line managing dictionary
- if self._tabLineDict.has_key(canvas) is None:
- self._tabLineDict[canvas] = []
-
- if self._tabLineDict[canvas].count( (expno, scanno, detid) ) is False:
+ if self._tabLineDict[canvas].count( (expno, scanno, detid) ) == 0:
canvas.addPlot(vecx, vecy, marker=marker, color=color, xlabel=xlabel, \
ylabel='Counts',label=label)
self._tabLineDict[canvas].append( (expno, scanno, detid) )
# auto setup for image boundary
- xmin = min(min(vecx), canvas.getXLimit[0])
- xmax = max(max(vecx), canvas.getXLimit[1])
-
- ymin = min(min(vecy), canvas.getYLimit[0])
- ymax = max(max(vecy), canvas.getYLimit[1])
+ xmin = min(min(vecx), canvas.getXLimit()[0])
+ xmax = max(max(vecx), canvas.getXLimit()[1])
+ ymin = min(min(vecy), canvas.getYLimit()[0])
+ ymax = max(max(vecy), canvas.getYLimit()[1])
dx = xmax-xmin
dy = ymax-ymin
- canvas.setXYLimit(xmin-dx*0.1, xmax+dx*0.1, ymin-dy*0.1, ymax+dy*0.1)
+ canvas.setXYLimit(xmin-dx*0.0001, xmax+dx*0.0001, ymin-dy*0.0001, ymax+dy*0.0001)
return True
@@ -1276,14 +1307,15 @@ def _plotRawDetSignal(self, expno, scanno, plotmode, ptno, dooverplot):
scanno = int(scanno)
ptno = int(ptno)
- # Load data if necessary
- if self._myControl.hasDataLoaded(expno, scanno) is False:
- rvalue, filename = self._uiLoadDataFile(expno, scanno)
- if rvalue is False:
- self._logError("Unable to download or locate local data file for Exp %d \
- Scan %d." % (expno, scanno))
- return
- self._myControl.loadSpicePDData(expno, scanno, filename)
+ # Set up canvas and dictionary
+ canvas = self.ui.graphicsView_Raw
+ if self._tabLineDict.has_key(canvas) is False:
+ self._tabLineDict[canvas] = []
+
+ # Check whether data exists
+ if self._myControl.hasDataLoaded(expno, scanno) is False:
+ self._logError("File has not been loaded for Exp %d Scan %d. Load data first!" % (expno, scanno))
+ return
# Get vecx and vecy
if plotmode == "All Pts.":
@@ -1293,7 +1325,6 @@ def _plotRawDetSignal(self, expno, scanno, plotmode, ptno, dooverplot):
# Clear previous
self.ui.graphicsView_Raw.clearAllLines()
self.ui.graphicsView_Raw.setLineMarkerColorIndex(0)
-
self._tabLineDict[canvas] = []
elif plotmode == "Single Pts.":
@@ -1301,6 +1332,7 @@ def _plotRawDetSignal(self, expno, scanno, plotmode, ptno, dooverplot):
if dooverplot is False:
self.ui.graphicsView_Raw.clearAllLines()
self.ui.graphicsView_Raw.setLineMarkerColorIndex(0)
+ self._tabLineDict[canvas] = []
# Plot one pts.
vecxylist = self._myControl.getRawDetectorCounts(expno, scanno, [ptno])
@@ -1309,22 +1341,17 @@ def _plotRawDetSignal(self, expno, scanno, plotmode, ptno, dooverplot):
# Raise exception
raise NotImplementedError("Plot mode %s is not supported." % (plotmode))
- # plot
- canvas = self.ui.graphicsView_Raw
- if self._tabLineDict.has_key(canvas) is False:
- self._tabLineDict[canvas] = []
-
- # FIXME
+ # Set up unit/x-label
unit = r"$2\theta$"
# plot
- xmin = 1.E10
- xmax = -1.0E10
- ymin = 1.E10
- ymax = -1.0E10
+ xmin = None
+ xmax = None
+ ymin = None
+ ymax = None
for ptno, vecx, vecy in vecxylist:
- # FIXME - Label is left blank as there can be too many labels
- label = str(ptno)
+ # FUTURE: Label is left blank as there can be too many labels
+ label = 'Pt %d' % (ptno)
# skip if this plot has existed
if self._tabLineDict[canvas].count( (expno, scanno, ptno) ) == 1:
@@ -1338,25 +1365,17 @@ def _plotRawDetSignal(self, expno, scanno, plotmode, ptno, dooverplot):
self._tabLineDict[canvas].append( (expno, scanno, ptno) )
# auto setup for image boundary
- tmpxmin = min(vecx)
- tmpxmax = max(vecx)
- if tmpxmin < xmin:
- xmin = tmpxmin
- if tmpxmax > xmax:
- xmax = tmpxmax
-
- tmpymax = max(vecy)
- tmpymin = min(vecy)
- if tmpymin < ymin:
- ymin = tmpymin
- if tmpymax > ymax:
- ymax = tmpymax
+ xmin = min(min(vecx), canvas.getXLimit()[0])
+ xmax = max(max(vecx), canvas.getXLimit()[1])
+ ymin = min(min(vecy), canvas.getYLimit()[0])
+ ymax = max(max(vecy), canvas.getYLimit()[1])
# ENDFOR
- # set X-Y range
- dx = xmax-xmin
- dy = ymax-ymin
- canvas.setXYLimit(xmin-dx*0.1, xmax+dx*0.1, ymin-dy*0.1, ymax+dy*0.1)
+ # Reset canvas x-y limit
+ if xmin is not None:
+ dx = xmax-xmin
+ dy = ymax-ymin
+ canvas.setXYLimit(xmin-dx*0.0001, xmax+dx*0.0001, ymin-dy*0.0001, ymax+dy*0.0001)
return True
@@ -1692,3 +1711,5 @@ def _getIntArray(self, intliststring):
# ENDFOR
return intlist
+
+
diff --git a/Code/Mantid/scripts/HFIRPowderReduction/MplFigureCanvas.py b/Code/Mantid/scripts/HFIRPowderReduction/MplFigureCanvas.py
index d9d8739fc7cc..f4caa6f1cf2d 100644
--- a/Code/Mantid/scripts/HFIRPowderReduction/MplFigureCanvas.py
+++ b/Code/Mantid/scripts/HFIRPowderReduction/MplFigureCanvas.py
@@ -231,6 +231,7 @@ def __init__(self, parent):
"""
# Instantialize matplotlib Figure
self.fig = Figure()
+ self.fig.patch.set_facecolor('white')
self.axes = self.fig.add_subplot(111) # return: matplotlib.axes.AxesSubplot
# Initialize parent class and set parent
@@ -316,9 +317,10 @@ def addPlot2D(self, array2d, xmin, xmax, ymin, ymax, holdprev, yticklabels=None)
# show image
imgplot = self.axes.imshow(array2d, extent=[xmin,xmax,ymin,ymax], interpolation='none')
# set y ticks as an option:
- if yticklabels is not None:
- # it will always label the first N ticks even image is zoomed in
- self.axes.set_yticklabels(yticklabels)
+ # FIXME - Set up the Y-axis ticks is erroreous
+ # if yticklabels is not None:
+ # # it will always label the first N ticks even image is zoomed in
+ # self.axes.set_yticklabels(yticklabels)
# explicitly set aspect ratio of the image
self.axes.set_aspect('auto')
diff --git a/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.py b/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.py
index be3f96121b4a..0082ce106dab 100644
--- a/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.py
+++ b/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.py
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'Ui_MainWindow.ui'
#
-# Created: Tue Apr 21 16:26:31 2015
+# Created: Wed Apr 22 14:50:13 2015
# by: PyQt4 UI code generator 4.11.2
#
# WARNING! All changes made in this file will be lost!
@@ -73,17 +73,29 @@ def setupUi(self, MainWindow):
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_25 = QtGui.QHBoxLayout()
self.horizontalLayout_25.setObjectName(_fromUtf8("horizontalLayout_25"))
- self.checkBox = QtGui.QCheckBox(self.centralwidget)
- self.checkBox.setObjectName(_fromUtf8("checkBox"))
- self.horizontalLayout_25.addWidget(self.checkBox)
+ self.checkBox_useDetEffCorr = QtGui.QCheckBox(self.centralwidget)
+ sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ sizePolicy.setHeightForWidth(self.checkBox_useDetEffCorr.sizePolicy().hasHeightForWidth())
+ self.checkBox_useDetEffCorr.setSizePolicy(sizePolicy)
+ self.checkBox_useDetEffCorr.setMinimumSize(QtCore.QSize(250, 0))
+ self.checkBox_useDetEffCorr.setObjectName(_fromUtf8("checkBox_useDetEffCorr"))
+ self.horizontalLayout_25.addWidget(self.checkBox_useDetEffCorr)
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_25.addItem(spacerItem1)
self.label_detEffFileName = QtGui.QLabel(self.centralwidget)
self.label_detEffFileName.setObjectName(_fromUtf8("label_detEffFileName"))
self.horizontalLayout_25.addWidget(self.label_detEffFileName)
- self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
- self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
- self.horizontalLayout_25.addWidget(self.pushButton_2)
+ self.lineEdit_vcorrFileName = QtGui.QLineEdit(self.centralwidget)
+ self.lineEdit_vcorrFileName.setObjectName(_fromUtf8("lineEdit_vcorrFileName"))
+ self.horizontalLayout_25.addWidget(self.lineEdit_vcorrFileName)
+ self.pushButton_browseVCorrFile = QtGui.QPushButton(self.centralwidget)
+ self.pushButton_browseVCorrFile.setObjectName(_fromUtf8("pushButton_browseVCorrFile"))
+ self.horizontalLayout_25.addWidget(self.pushButton_browseVCorrFile)
+ self.pushButton_viewVCorrection = QtGui.QPushButton(self.centralwidget)
+ self.pushButton_viewVCorrection.setObjectName(_fromUtf8("pushButton_viewVCorrection"))
+ self.horizontalLayout_25.addWidget(self.pushButton_viewVCorrection)
self.comboBox_effCorrect = QtGui.QComboBox(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
@@ -97,14 +109,26 @@ def setupUi(self, MainWindow):
self.verticalLayout.addLayout(self.horizontalLayout_25)
self.horizontalLayout_24 = QtGui.QHBoxLayout()
self.horizontalLayout_24.setObjectName(_fromUtf8("horizontalLayout_24"))
- self.checkBox_2 = QtGui.QCheckBox(self.centralwidget)
- self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
- self.horizontalLayout_24.addWidget(self.checkBox_2)
+ self.checkBox_useDetExcludeFile = QtGui.QCheckBox(self.centralwidget)
+ sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ sizePolicy.setHeightForWidth(self.checkBox_useDetExcludeFile.sizePolicy().hasHeightForWidth())
+ self.checkBox_useDetExcludeFile.setSizePolicy(sizePolicy)
+ self.checkBox_useDetExcludeFile.setMinimumSize(QtCore.QSize(250, 0))
+ self.checkBox_useDetExcludeFile.setObjectName(_fromUtf8("checkBox_useDetExcludeFile"))
+ self.horizontalLayout_24.addWidget(self.checkBox_useDetExcludeFile)
spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_24.addItem(spacerItem3)
self.label_excFileName = QtGui.QLabel(self.centralwidget)
self.label_excFileName.setObjectName(_fromUtf8("label_excFileName"))
self.horizontalLayout_24.addWidget(self.label_excFileName)
+ self.lineEdit_excludedDetFileName = QtGui.QLineEdit(self.centralwidget)
+ self.lineEdit_excludedDetFileName.setObjectName(_fromUtf8("lineEdit_excludedDetFileName"))
+ self.horizontalLayout_24.addWidget(self.lineEdit_excludedDetFileName)
+ self.pushButton_browseExcludedDetFile = QtGui.QPushButton(self.centralwidget)
+ self.pushButton_browseExcludedDetFile.setObjectName(_fromUtf8("pushButton_browseExcludedDetFile"))
+ self.horizontalLayout_24.addWidget(self.pushButton_browseExcludedDetFile)
spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_24.addItem(spacerItem4)
self.label_detExcluded = QtGui.QLabel(self.centralwidget)
@@ -857,12 +881,15 @@ def retranslateUi(self, MainWindow):
self.comboBox_wavelength.setItemText(1, _translate("MainWindow", "(115) 1.54 Å", None))
self.comboBox_wavelength.setItemText(2, _translate("MainWindow", "(117) 1.12 Å.", None))
self.comboBox_wavelength.setItemText(3, _translate("MainWindow", "User Specified", None))
- self.checkBox.setText(_translate("MainWindow", "Detectors Efficiency Correction", None))
- self.label_detEffFileName.setText(_translate("MainWindow", "(Detectors Efficiency File)", None))
- self.pushButton_2.setText(_translate("MainWindow", "View Correction", None))
+ self.checkBox_useDetEffCorr.setText(_translate("MainWindow", "Detectors Efficiency Correction", None))
+ self.label_detEffFileName.setToolTip(_translate("MainWindow", "
Vanadium correction file
", None))
+ self.label_detEffFileName.setText(_translate("MainWindow", "Detectors Efficiency File", None))
+ self.pushButton_browseVCorrFile.setText(_translate("MainWindow", "Browse", None))
+ self.pushButton_viewVCorrection.setText(_translate("MainWindow", "View Correction", None))
self.comboBox_effCorrect.setToolTip(_translate("MainWindow", "File name for efficiency correction
", None))
- self.checkBox_2.setText(_translate("MainWindow", "Using Exclusion File", None))
- self.label_excFileName.setText(_translate("MainWindow", "(Excluded Detector File)", None))
+ self.checkBox_useDetExcludeFile.setText(_translate("MainWindow", "Using Exclusion File", None))
+ self.label_excFileName.setText(_translate("MainWindow", "Excluded Detectors File", None))
+ self.pushButton_browseExcludedDetFile.setText(_translate("MainWindow", "Browse", None))
self.label_detExcluded.setText(_translate("MainWindow", "Detectors to Exclude ", None))
self.tabWidget.setToolTip(_translate("MainWindow", "Question about use case of tab\'Raw Detectors\': What do you want to see?
1. single detector\'s counts in all Pt.?
> what is the X-axis? Pt. or 2theta?
2. all detectors\' counts in one Pt.?
> what is the X-axis? Det no or 2theta?
", None))
self.comboBox_rawDetMode.setItemText(0, _translate("MainWindow", "All Pts.", None))
diff --git a/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.ui b/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.ui
index d5bd6b76657d..f6c81753f0a3 100644
--- a/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.ui
+++ b/Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.ui
@@ -106,6 +106,18 @@
-
+
+
+ 0
+ 0
+
+
+
+
+ 250
+ 0
+
+
Detectors Efficiency Correction
@@ -189,6 +201,18 @@
-
+
+
+ 0
+ 0
+
+
+
+
+ 250
+ 0
+
+
Using Exclusion File
@@ -213,7 +237,7 @@
-
- Excluded Detectors File
+ Excluded Detectors File
@@ -1786,7 +1810,7 @@
0
0
1412
- 22
+ 25