diff --git a/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py b/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py index 9d8ef70458e0..fe407e60cb0a 100644 --- a/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py +++ b/Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py @@ -29,7 +29,7 @@ def _fromUtf8(s): #----- default configuration --------------- DEFAULT_SERVER = 'http://neutron.ornl.gov/' DEFAULT_INSTRUMENT = 'HB2A' - +DEFAULT_WAVELENGTH = 2.4100 #------------------------------------------- @@ -60,11 +60,43 @@ def __init__(self, parent=None): self.connect(self.ui.pushButton_loadData, QtCore.SIGNAL('clicked()'), self.doLoadData) + self.connect(self.ui.pushButton_unit2theta, QtCore.SIGNAL('clicked()'), + self.doPlot2Theta) + + self.connect(self.ui.pushButton_unitD, QtCore.SIGNAL('clicked()'), + self.doPlotDspacing) + + self.connect(self.ui.pushButton_unitQ, QtCore.SIGNAL('clicked()'), + self.doPlotQ) + + # Define signal-event handling # Widget type definition + validator0 = QtGui.QIntValidator(self.ui.lineEdit_expNo) + validator0.setBottom(1) + self.ui.lineEdit_expNo.setValidator(validator0) + + validator1 = QtGui.QIntValidator(self.ui.lineEdit_expNo) + validator1.setBottom(1) + self.ui.lineEdit_scanNo.setValidator(validator1) + validator2 = QtGui.QDoubleValidator(self.ui.lineEdit_wavelength) + validator2.setBottom(0.) + self.ui.lineEdit_wavelength.setValidator(validator2) + + validator3 = QtGui.QDoubleValidator(self.ui.lineEdit_xmin) + validator3.setBottom(0.) + self.ui.lineEdit_xmin.setValidator(validator3) + + validator4 = QtGui.QDoubleValidator(self.ui.lineEdit_xmax) + validator4.setBottom(0.) + self.ui.lineEdit_xmax.setValidator(validator4) + + validator5 = QtGui.QDoubleValidator(self.ui.lineEdit_binsize) + validator5.setBottom(0.) + self.ui.lineEdit_binsize.setValidator(validator5) # Get initial setup self._initSetup() @@ -77,6 +109,9 @@ def _initSetup(self): """ # FIXME - This part will be implemented soon as default configuration is made + # UI widgets setup + self.ui.comboBox_outputFormat.addItems(['Fullprof', 'GSAS', 'Fullprof+GSAS']) + # Mantid configuration if IMPORT_MANTID is True: config = ConfigService.Instance() @@ -90,6 +125,8 @@ def _initSetup(self): self._localSrcDataDir = None self._srcAtLocal = False + self._currUnit = '2theta' + #-- Event Handling ---------------------------------------------------- @@ -107,12 +144,68 @@ def doLoadData(self): datafilename = self._loadDataFile(exp=expno, scan=scanno) # Get other information + xmin, xmax, binsize = self._getBinningParams() + if binsize is None: + self._logError("Bin size must be specified.") + + unit = self._currUnit + execstatus = self._reduceSpicePDData(datafilename, unit, xmin, xmax, binsize) return + def doPlot2Theta(self): + """ Rebin the data and plot in 2theta + """ + self._plotReducedData('2theta') + + return + + def doPlotDspacing(self): + """ Rebin the data and plot in d-spacing + """ + self._plotReducedData('dSpacing') + + return + + def doPlotQ(self): + """ Rebin the data and plot in momentum transfer Q + """ + self._plotReducedData('Momentum Transfer (Q)') + + return + + + #-------------------------------------------------------- + # + #-------------------------------------------------------- + + def _getBinningParams(self): + """ Get binning parameters + """ + xminstr = str(self.ui.lineEdit_xmin.text()).strip() + if len(xminstr) == 0: + xmin = None + else: + xmin = float(xminstr) + + xmaxstr = str(self.ui.lineEdit_xmax.text()).strip() + if len(xmaxstr) == 0: + xmax = None + else: + xmax = float(xmaxstr) + + binsizestr = str(self.ui.lineEdit_binsize.text()).strip() + if len(binsizestr) == 0: + binsize = None + else: + binsize = float(xminstr) + + return xmin, xmax, binsize + + def _loadDataFile(self, exp, scan): """ Load data file according to its exp and scan """ @@ -143,16 +236,19 @@ def _reduceSpicePDData(self, datafilename, unit, xmin, xmax, binsize): tablewsname = basewsname + "_RawTable" infowsname = basewsname + "ExpInfo" api.LoadSpiceAscii(Filename=datafilename, - OutputWorkspace=tablewsname, InfoWorkspace=infowsname) + OutputWorkspace=tablewsname, RunInfoWorkspace=infowsname) # Build MDWorkspace datamdwsname = basewsname + "_DataMD" monitorwsname = basewsname + "_MonitorMD" api.ConvertSpiceDataToRealSpace(InputWorkspace=tablewsname, - InfoWorkspace=infowsname, + RunInfoWorkspace=infowsname, OutputWorkspace=datamdwsname, OutputMontiorWorkspace=monitorwsname) + self._datamdws = AnalysisDataService.retrieve(datamdwsname) + self._monitormdws = AnalysisDataService.retrieve(monitorwsname) + # Rebin if xmin is None or xmax is None: binpar = "%.7f" % (binsize) @@ -163,14 +259,39 @@ def _reduceSpicePDData(self, datafilename, unit, xmin, xmax, binsize): api.ConvertCWPDMDToSpectra(InputWorkspace=datamdwsname, InputMonitorWorkspace=monitorwsname, OutputWorkspace=outwsname, - BinningParam=binpar, - UnitOutput = unit) + BinningParams=binpar, + UnitOutput = unit, + NeutronWaveLength=wavelength) self._outws = AnalysisDataService.retrieve(outwsname) return + def _plotReducedData(self, targetunit): + """ Plot reduced data + """ + # whether the data is load? + if self._inPlotState is False: + self._logWarning("No data to plot!") + + targetunit = '2theta' + if self._currUnit != targetunit: + self._currUnit = targetunit + self._rebin(targetunit) + self._plotBinnedData() + + + + # read the xmin, xmax and bin size + xmin = float(self.ui.lineEdit_xmin.text()) + xmax = float(self.ui.lineEdit_xmax.text()) + binsize = float(self.ui.lineEdit_xmin.text()) + + + + + def _rebin(self, unit, xmin, binsize, xmax): """ """