Skip to content

Commit

Permalink
Fixed some issues during testing. Refs #11289.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Mar 17, 2015
1 parent 989d786 commit 421291f
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 38 deletions.
77 changes: 73 additions & 4 deletions Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py
Expand Up @@ -28,6 +28,7 @@ def _fromUtf8(s):
IMPORT_MANTID = True
except ImportError as e:
sys.path.append('/home/wzz/Mantid_Project/Mantid2/Code/release/bin')
sys.path.append('/Users/wzz/Mantid/Code/debug/bin')
try:
import mantid
except ImportError as e2:
Expand All @@ -36,6 +37,7 @@ def _fromUtf8(s):
raise e
else:
print "NO MANTID IS USED FOR DEBUGGING PURPOSE."
print sys.path
IMPORT_MANTID = False
else:
IMPORT_MANTID = True
Expand Down Expand Up @@ -81,6 +83,12 @@ def __init__(self, parent=None):
self.connect(self.ui.pushButton_loadData, QtCore.SIGNAL('clicked()'),
self.doLoadData)

self.connect(self.ui.pushButton_prevScan, QtCore.SIGNAL('clicked()'),
self.doLoadPrevScan)

self.connect(self.ui.pushButton_nextScan, QtCore.SIGNAL('clicked()'),
self.doLoadNextScan)

self.connect(self.ui.pushButton_unit2theta, QtCore.SIGNAL('clicked()'),
self.doPlot2Theta)

Expand Down Expand Up @@ -198,6 +206,10 @@ def _initSetup(self):

self._ptNo = None
self._detNo = None

# set up for plotting
self._myLineMarkerColorList = self.ui.graphicsView_reducedData.getDefaultColorMarkerComboList()
self._myLineMarkerColorIndex = 0

# State machine
# self._inPlotState = False
Expand Down Expand Up @@ -267,7 +279,6 @@ def doChangeSrcLocation(self):
return



def doCheckSrcServer(self):
"""" Check source data server's availability
"""
Expand Down Expand Up @@ -308,7 +319,54 @@ def doLoadData(self):
if execstatus is True:
self._plotReducedData(self._currUnit, 0)

return
return execstatus


def doLoadPrevScan(self):
"""
"""
# Advance scan number by 1
try:
scanno = int(self.ui.lineEdit_scanNo.text())
except ValueError:
self._logError("Either Exp No or Scan No is not set up right as integer.")
return
else:
scanno = scanno - 1
if scanno < 1:
self._logWarning("Scan number is 1 already. Cannot have previous scan")
return
self.ui.lineEdit_scanNo.setText(str(scanno))

# call load data
execstatus = self.doLoadData()

return execstatus


def doLoadNextScan(self):
"""
"""
# Advance scan number by 1
try:
scanno = int(self.ui.lineEdit_scanNo.text())
except ValueError:
self._logError("Either Exp No or Scan No is not set up right as integer.")
return
else:
scanno = scanno + 1
if scanno < 1:
self._logWarning("Scan number is 1 already. Cannot have previous scan")
return
self.ui.lineEdit_scanNo.setText(str(scanno))

# call load data
execstatus = self.doLoadData()
if execstatus is False:
scanno = scanno - 1
self.ui.lineEdit_scanNo.setText(str(scanno))

return execstatus


def doPlot2Theta(self):
Expand All @@ -327,7 +385,9 @@ def doPlot2Theta(self):

# Rebin
self._rebin('2theta', xmin, binsize, xmax)
self._plotReducedData()

xlabel = r"$2\theta$"
self._plotReducedData(xlabel)

return

Expand Down Expand Up @@ -677,8 +737,17 @@ def _plotReducedData(self, targetunit, spectrum):
wsname = str(self._myReducedPDWs)
api.ConvertToPointData(InputWorkspace=self._myReducedPDWs, OutputWorkspace=wsname)
self._myReducedPDWs = AnalysisDataService.retrieve(wsname)

# get the marker color for the line
marker, color = self._myLineMarkerColorList[self._myLineMarkerColorIndex]
if marker.count(' (') > 0:
marker = marker.split(' (')[0]
print "[DB] Print line %d: marker = %s, color = %s" % (self._myLineMarkerColorIndex, marker, color)
self._myLineMarkerColorIndex += 1

self.ui.graphicsView_reducedData.addPlot(self._myReducedPDWs.readX(spectrum),
self._myReducedPDWs.readY(spectrum))
self._myReducedPDWs.readY(spectrum), marker=marker, color=color,ylabel='intensity',
xlabel=r'2\theta',label=str(self._myReducedPDWs))

return

Expand Down
54 changes: 42 additions & 12 deletions Code/Mantid/scripts/HFIRPowderReduction/MplFigureCanvas.py
Expand Up @@ -7,9 +7,12 @@
from matplotlib.figure import Figure

MplLineStyles = ['-' , '--' , '-.' , ':' , 'None' , ' ' , '']
MplLineMarkers = [ ". (point)",
", (pixel )",
MplLineMarkers = [
"o (circle )",
"s (square )",
"D (diamond )",
", (pixel )",
". (point )",
"v (triangle_down )",
"^ (triangle_up )",
"< (triangle_left )",
Expand All @@ -19,27 +22,25 @@
"3 (tri_left )",
"4 (tri_right )",
"8 (octagon )",
"s (square )",
"p (pentagon )",
"* (star )",
"h (hexagon1 )",
"H (hexagon2 )",
"+ (plus )",
"x (x )",
"D (diamond )",
"d (thin_diamond )",
"| (vline )",
"_ (hline )",
"None (nothing )"]

MplBasicColors = [
"black",
"red",
"blue",
"green",
"red",
"cyan",
"magenta",
"yellow",
"black",
"white"]

class Qt4MplCanvas(FigureCanvas):
Expand Down Expand Up @@ -69,21 +70,32 @@ def __init__(self, parent):

return

def addPlot(self, x, y):
def addPlot(self, x, y, color=None, label="", xlabel=None, ylabel=None, marker=None, linestyle=None, linewidth=1):
""" Plot a set of data
Argument:
- x: numpy array X
- y: numpy array Y
"""
# process inputs and defaults
self.x = x
self.y = y


if color is None:
color = (0,1,0,1)
if marker is None:
marker = 'o'
if linestyle is None:
linestyle = '-'

# color must be RGBA (4-tuple)
r = self.axes.plot(x, y, color=(0,1,0,1), marker='o', linestyle='--',
label='X???X', linewidth=2) # return: list of matplotlib.lines.Line2D object
r = self.axes.plot(x, y, color=color, marker=marker, linestyle=linestyle,
label=label, linewidth=1) # return: list of matplotlib.lines.Line2D object

# set label
self.axes.set_xlabel(r"$2\theta$", fontsize=20)
# set x-axis and y-axis label
if xlabel is not None:
self.axes.set_xlabel(xlabel, fontsize=20)
if ylabel is not None:
self.axes.set_ylabel(ylabel, fontsize=20)

# set/update legend
self.axes.legend()
Expand Down Expand Up @@ -166,3 +178,21 @@ def getLineBasicColorList(self):
"""
"""
return MplBasicColors

def getDefaultColorMarkerComboList(self):
""" Get a list of line/marker color and marker style combination
as default to add more and more line to plot
"""
combolist = []
nummarkers = len(MplLineMarkers)
numcolors = len(MplBasicColors)

for i in xrange(nummarkers):
marker = MplLineMarkers[i]
for j in xrange(numcolors):
color = MplBasicColors[j]
combolist.append( (marker, color) )
# ENDFOR (j)
# ENDFOR(i)

return combolist
64 changes: 61 additions & 3 deletions Code/Mantid/scripts/HFIRPowderReduction/Ui_MainWindow.ui
Expand Up @@ -46,10 +46,68 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_prevScan">
<property name="text">
<string>Prev Scan</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_nextScan">
<property name="text">
<string>Next Scan</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_12">
<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="QComboBox" name="comboBox_wavelength">
<item>
<property name="text">
<string>Unknown</string>
</property>
</item>
<item>
<property name="text">
<string>Ge 113 IN Config 2.41 Å,</string>
</property>
</item>
<item>
<property name="text">
<string>(115) 1.54 Å</string>
</property>
</item>
<item>
<property name="text">
<string>(117) 1.12 Å.</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_calibration">
<property name="text">
<string>Ge 113 IN Config</string>
<string/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_clearPrevious">
<property name="text">
<string>Clear Previous Plot</string>
</property>
</widget>
</item>
Expand All @@ -73,7 +131,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
Expand Down Expand Up @@ -917,7 +975,7 @@
<x>0</x>
<y>0</y>
<width>1124</width>
<height>25</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down

0 comments on commit 421291f

Please sign in to comment.