Skip to content
Snippets Groups Projects
Commit 3505be87 authored by Zhou, Wenduo's avatar Zhou, Wenduo
Browse files

Refs #13136. Fixed problem to plot non-normalized detector counts.

And deleted unused customize.py and removed some pylint warning.

On branch 13136_fix_hb2a_gui_issues
Changes to be committed:
 - modified:   HfirPDReductionControl.py
 - modified:   HfirPDReductionGUI.py
 - modified:   HfirUtility.py
 - modified:   MplFigureCanvas.py
 - deleted:    customize.py
parent 8bff3076
No related branches found
No related tags found
No related merge requests found
......@@ -249,14 +249,14 @@ class HFIRPDRedControl(object):
return
def getIndividualDetCounts(self, exp, scan, detid, xlabel, raw=False):
def getIndividualDetCounts(self, exp, scan, detid, xlabel, normalized=True):
""" Get individual detector counts
Arguments:
- exp :: experiment number
- scan :: scan number
- detid :: detector ID
- xlabel :: x-axis for detector's counts. (1) None for Pt. Or (2) any valid sample log name
Return: 2-tuple (vecX, vecY) for plotting
:param exp:
:param scan:
:param detid:
:param xlabel:
:param normalized:
:return:
"""
# Check and get data
exp = int(exp)
......@@ -283,7 +283,8 @@ class HFIRPDRedControl(object):
api.GetSpiceDataRawCountsFromMD(InputWorkspace=datamdws,
MonitorWorkspace=monitormdws,
Mode='Detector',
DetectorID = detid)
DetectorID = detid,
NormalizeByMonitorCounts=normalized)
else:
print "Plot detector %d's counts vs. sample log %s."%(detid, xlabel)
tempoutws = \
......@@ -291,9 +292,8 @@ class HFIRPDRedControl(object):
MonitorWorkspace=monitormdws,
Mode='Detector',
DetectorID = detid,
XLabel=xlabel)
if raw is True:
raise RuntimeError('Implement ASAP if it is required to plot raw counts (not normalized)')
XLabel=xlabel,
NormalizeByMonitorCounts=normalized)
vecx = tempoutws.readX(0)[:]
vecy = tempoutws.readY(0)[:]
......
#pylint: disable=invalid-name, relative-import, too-many-lines,too-many-instance-attributes
#pylint: disable=invalid-name, relative-import, too-many-lines,too-many-instance-attributes too-many-statements
################################################################################
# Main class for HFIR powder reduction GUI
# Key word for future developing: FUTURE, NEXT, REFACTOR, RELEASE 2.0
......@@ -87,7 +87,7 @@ class MultiScanTabState(object):
"""
return self._scanList[:]
# disable=too-many-arguments
#pyline: disable=too-many-arguments
def setup(self, exp_no, scan_list, min_x, max_x, bin_size, unit, raw, correct_det_eff, exclude_dets):
"""
Set up the object
......@@ -796,7 +796,6 @@ class MainWindow(QtGui.QMainWindow):
# Set up some widgets for raw detector data. Won't be applied to tab 3
if itab != 3:
QtGui.QMessageBox.information(self, 'Debug Return', 'Time to set up logs')
floatsamplelognamelist = self._myControl.getSampleLogNames(expno, scanno)
self.ui.comboBox_indvDetXLabel.clear()
self.ui.comboBox_indvDetXLabel.addItem("2theta/Scattering Angle")
......@@ -1729,8 +1728,7 @@ class MainWindow(QtGui.QMainWindow):
# FUTURE: In future, need to find out how to use self._graphIndDevMode
# self._graphIndDevMode = (samplename, 'Counts')
return
return
def _plot_individual_detector_counts(self, expno, scanno, detid, xaxis, resetboundary=False):
""" Plot a specific detector's counts along all experiment points (pt)
......@@ -1763,7 +1761,6 @@ class MainWindow(QtGui.QMainWindow):
self._logNotice("Input x-axis is '%s' for plotting individual detector's counts."%(xaxis))
if len(xaxis) == 0:
xaxis = None
# FIXME - plot_normal should be propagated to _myControl
vecx, vecy = self._myControl.getIndividualDetCounts(expno, scanno, detid, xaxis, plot_normal)
if isinstance(vecx, numpy.ndarray) is False:
raise NotImplementedError('vecx, vecy must be numpy arrays.')
......@@ -1779,7 +1776,7 @@ class MainWindow(QtGui.QMainWindow):
else:
#xlabel = "Pt."
xlabel = xaxis
# TODO - If it works with any way of plotting, then refactor Pt. with any other sample names
# FUTURE - If it works with any way of plotting, then refactor Pt. with any other sample names
label = "Detector ID: %d" % (detid)
......
......@@ -115,10 +115,9 @@ def parseDetEffCorrFile(vancorrfname):
def parseDetExclusionFile(detexludefilename):
""" Parse excluded detectors file
Detector ID from standard HB2A detector exclusion file start from 0,
while in the other circumstance, it starts from 1.
Therefore Det ID output from here must be plus by 1.
Return :: 2-tuple
while in the other circumstance, it starts from 1.
Therefore Det ID output from here must be plus by 1.
Return :: 2-tuple
Success: Excluded detector IDs list, empty string
Fail: None, error message
"""
......
#pylint: disable=invalid-name,too-many-public-methods,too-many-arguments,non-parent-init-called
#pylint: disable=invalid-name,too-many-public-methods,too-many-arguments,non-parent-init-called, too-many-branches
import os
import numpy as np
......@@ -7,6 +7,7 @@ from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.image
MplLineStyles = ['-' , '--' , '-.' , ':' , 'None' , ' ' , '']
MplLineMarkers = [
......@@ -203,9 +204,9 @@ class MplFigureCanvas(QtGui.QWidget):
self._myLineMarkerColorIndex = 0
return marker, color
def resetLineColorStyle(self):
""" Reset the auto index for line's color and style
""" Reset the auto index for line's color and style
"""
self._myLineMarkerColorIndex = 0
return
......@@ -330,11 +331,10 @@ class Qt4MplCanvas(FigureCanvas):
# Register
if plot_error is True and len(r) == 3:
self._lineDict[self._lineIndex] = r[2]
for ir in xrange(3):
print '[DBNOW] %d'%(ir), r[ir], type(r[ir])
raise NotImplementedError('Stop here!')
# plot line with error bar. r[1] contains all lines
self._lineDict[self._lineIndex] = r
elif plot_error is False and len(r) == 1:
# regular line
self._lineDict[self._lineIndex] = r[0]
else:
print "Impoooooooooooooooosible! Number of returned tuple is %d"%(len(r))
......@@ -401,7 +401,7 @@ class Qt4MplCanvas(FigureCanvas):
# set aspect to auto mode
self.axes.set_aspect('auto')
img = mpimg.imread(str(imagefilename))
img = matplotlib.image.imread(str(imagefilename))
# lum_img = img[:,:,0]
# FUTURE : refactor for image size, interpolation and origin
imgplot = self.axes.imshow(img, extent=[0, 1000, 800, 0], interpolation='none', origin='lower')
......@@ -424,11 +424,22 @@ class Qt4MplCanvas(FigureCanvas):
"""
for ikey in self._lineDict.keys():
plot = self._lineDict[ikey]
if plot is not None:
if plot is None:
continue
if isinstance(plot, tuple) is False:
try:
self.axes.lines.remove(plot)
except ValueError as e:
print "[Error] Plot %s is not in axes.lines which has %d lines." % (str(plot), len(self.axes.lines))
print "[Error] Plot %s is not in axes.lines which has %d lines. Error mesage: %s" % (
str(plot), len(self.axes.lines), str(e))
self._lineDict[ikey] = None
else:
# error bar
plot[0].remove()
for line in plot[1]:
line.remove()
for line in plot[2]:
line.remove()
self._lineDict[ikey] = None
# ENDIF(plot)
# ENDFOR
......
#!/usr/bin/python
################################################################################
# Customize the widigets in a gui python file generated from pyuic4
################################################################################
import sys
import shutil
def main(argv):
""" Main
"""
if len(argv) < 2:
print "Input: %s [pyqt python file name]" % (argv[0])
return
# import
pfilename = argv[1]
if pfilename.endswith('.') is True:
pfilename += "py"
try:
pfile = open(pfilename, 'r')
lines = pfile.readlines()
pfile.close()
except IOError as ioe:
raise ioe
# move the source file
shutil.move(pfilename, pfilename+".bak")
# replace and add import
wbuf = ""
wbuf += "#pylint: disable=invalid-name,relative-import,too-many-lines,too-many-instance-attributes,"
wbuf += "too-many-statements,line-too-long,"
wbuf += "too-many-locals,attribute-defined-outside-init\n"
importclass = True
for line in lines:
if line.count('class') == 1 and line.count('):') == 1 and importclass is True:
# add import
wbuf += 'from MplFigureCanvas import *\n'
importclass = False
if line.count('QtGui.QGraphicsView(') == 1:
# replace QGraphicsView by Qt4MplCanvas
line = line.replace('QtGui.QGraphicsView(', 'Qt4MplPlotView(')
wbuf += line
# write to file
ofile = open(pfilename, 'w')
ofile.write(wbuf)
ofile.close()
return
if __name__ == "__main__":
main(sys.argv)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment