Skip to content

Commit

Permalink
Refs #11289. Started to implement auto correction file.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Apr 21, 2015
1 parent ba106d4 commit 3e2d360
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 74 deletions.
Expand Up @@ -9,6 +9,8 @@

import numpy

import HfirUtility as hutil

# Import mantid
IMPORT_MANTID = False
try:
Expand Down Expand Up @@ -520,7 +522,52 @@ def reduceSpicePDData(self, exp, scan, datafilename, unit, xmin, xmax, binsize,
self._myWorkspaceDict[(exp, scan)] = wsmanager

return True



def retrieveCorrectionData(self, instrument, exp, scan):
""" Retrieve including dowloading and/or local locating
powder diffraction's correction files
Arguments:
- instrument :: name of powder diffractometer in upper case
- exp :: integer as epxeriment number
- scan :: integer as scan number
"""
if instrument.upper() == 'HB2A':
# get detector efficiency correction file
try:
wsmanager = self._myWorkspaceDict[(int(exp), int(scan))]
except KeyError:
return (False, "Exp %s Scan %s has not been loaded. \
This method must be called after data is loaded." % (str(exp),
str(scan)))

m1 = wsmanager.datamdws.getExperimentInfo(0).run.getProperty('m1').value()
colltrans = wsmanager.datamdws.getExperimentInfo(0).run.getProperty('colltrans').value()

detefffname, deteffurl, wavelength = hutil.makeHB2ADetEfficiencyFileName(exp, m1, colltrans)

downloadFile(deteffurl, localfilepath)

# get excluded detector file
excldetfilenane, exclurl = hutil.makeExcludedDetectorFileName(exp)

downloadFile(exclurl, localfilepath)

# Set to ws manager
wsmanager.setWavelength(wavelength)
wsmanager.setDetEfficencyFile(...)
wsmanager.setExcludedDetFile(...)


else:
raise NotImplementedError("Instrument %s is not supported to retrieve correction file." % (instrument))


return



def savePDFile(self, exp, scan, filetype, sfilename):
""" Save a reduced workspace to gsas/fullprof/topaz data file
"""
Expand Down
154 changes: 81 additions & 73 deletions Code/Mantid/scripts/HFIRPowderReduction/HfirPDReductionGUI.py
Expand Up @@ -70,11 +70,11 @@ def __init__(self, parent=None):

# tab 'Raw Detectors'
self.connect(self.ui.pushButton_plotRaw, QtCore.SIGNAL('clicked()'),
self.doPlotRawDet)
self.doPlotRawPtMain)
self.connect(self.ui.pushButton_ptUp, QtCore.SIGNAL('clicked()'),
self.doPlotPrevPtRaw)
self.doPlotRawPtPrev)
self.connect(self.ui.pushButton_ptDown, QtCore.SIGNAL('clicked()'),
self.doPlotNextPtRaw)
self.doPlotRawPtNext)
self.connect(self.ui.pushButton_clearRawDets, QtCore.SIGNAL('clicked()'),
self.doClearRawDetCanvas)

Expand Down Expand Up @@ -315,21 +315,36 @@ def doCheckSrcServer(self):
def doClearIndDetCanvas(self):
""" Clear the canvas in tab 'Individual Detector'
"""
# TODO ASAP
raise NotImplementedError("ASAP - doClearIndDetCanvas")
self.ui.graphicsView_indvDet.clearAllLines()


def doClearMultiRunCanvas(self):
""" Clear the canvas in tab 'Multiple Run'
This canvas is applied to both 1D and 2D image.
Clear-all-lines might be not enough to clear 2D image
"""
# TODO ASAP
raise NotImplementedError("ASAP - doClearMultiRunCanvas")
self.ui.graphicsView_mergeRun.clearCanvas()

return


def doClearRawDetCanvas(self):
""" Clear the canvas in tab 'Raw Detector'
""" Clear the canvas in tab 'Raw Detector':
only need to clear lines
"""
# TODO ASAP
raise NotImplementedError("ASAP - doClearRawDetCanvas")
self.ui.graphicsView_Raw.clearAllLines()

return


def doClearVanadiumCanvas(self):
""" Clear the canvas in tab 'Vanadium'
"""
self.ui.graphicsView_vanPeaks.clearAllLines()

return


def doLoadData(self):
""" Load and reduce data
Expand Down Expand Up @@ -368,7 +383,11 @@ def doLoadData(self):
Scan %d." % (expno, scanno))
# ENDIF(status)

# TODO - ASAP : Need a method to download the correction file and find out the wavelength!
# Download the correction file and find out the wavelength!
status, errmsg = self._myControl.retrieveCorrectionData(instrument='HB2A', expno, scanno)
if status is False:
self._logError("Unable to download correction files for Exp %d Scan %d. \
\nReason: %s." % (expno, scanno, errmsg))

# Now do different tasks for different tab
if itab == 0 or itab == 1:
Expand Down Expand Up @@ -672,8 +691,50 @@ def doPlotQ(self):
return


def doPlotRawDet(self):
""" Plot current raw detector signals
# TODO - Remove this commented method after code is tested
# def doPlotRawDetPrev(self):
# """ Plot previous raw detector signals for tab 'Individual Detector'
# """
# # Validate the operation
# if self._rawDetPtNo is None and self._rawDetExpNo is None \
# and self._rawDetScanNo is None:
# self._logError('doPlotRawDetPrev cannot work because no Exp/Scan/Pt has been set.')

# # Plot
# execstatus = self._plotRawDetSignal(self._rawDetExpNo, self._rawDetScanNo,
# self._rawDetPlotMode, self._rawDetPtNo-1, doOverPlot)

# # Write back
# if execstatus is True:
# self._rawDetPtNo += 1
# self.ui.lineEdit_ptNo.setText(str(self._rawDetPtNo))

# return


# TODO - Remove this commented method after code is tested
# def doPlotRawDetNext(self):
# """ Plot next raw detector signals for tab 'Individual Detector'
# """
# # FIXME - Is this correct? Should be for all Pt. or all Detector???
# # Validate the operation
# if self._rawDetPtNo is None and self._rawDetExpNo is None \
# and self._rawDetScanNo is None:
# self._logError('doPlotRawDetPrev cannot work because no Exp/Scan/Pt has been set.')

# # Plot
# execstatus = self._plotRawDetSignal(self._rawDetExpNo, self._rawDetScanNo,
# self._rawDetPlotMode, self._rawDetPtNo+1, doOverPlot)

# # Write back
# if execstatus is True:
# self._rawDetPtNo += 1
# self.ui.lineEdit_ptNo.setText(str(self._rawDetPtNo))

# return

def doPlotRawPtMain(self):
""" Plot current raw detector signal for a specific Pt.
"""
# get experiment number and scan number for data file
try:
Expand All @@ -697,73 +758,20 @@ def doPlotRawDet(self):

# set global values if good
if execstatus is True:
self._ptNo = ptNo
self._expNo = expno
self._scanNo = scanno
self._rawDetPtNo = ptNo
self._rawDetExpNo = expno
self._rawDetScanNo = scanno
self._rawDetPlotMode = plotMode
else:
print "[Error] Execution fails with signal %s. " % (str(execstatus))

return


def doPlotPrevDetRaw(self):
""" Plot previous raw detector signals for tab 'Individual Detector'
"""
# TODO - ASAP
raise NotImplementedError("ASAP doPlotPrevDetRaw")

# check
if self._ptNo is not None and self._detNo is not None:
detno = self._detNo + 1
else:
self._logError("Unable to plot previous raw detector \
because Pt. or Detector ID has not been set up yet.")
return

# det number minus 1
status, errmsg = self._checkValidPtDet(self._ptNo, detno)
if status is False:
self._logError(errmsg)
else:
self._detNo = detno
self.ui.lineEdit_detNo.setText(str(self._detNo))

# plot
self._plotRawDetSignal(self._ptNo, self._detNo)

return


def doPlotNextDetRaw(self):
""" Plot next raw detector signals for tab 'Individual Detector'
"""
# TODO - ASAP
raise NotImplementedError("ASAP doPlotNextDetRaw")

# check
if self._ptNo is not None:
detno = self._detNo + 1
else:
self._logError("Unable to plot previous raw detector \
because Pt. or Detector ID has not been set up yet.")
return

# det number plus 1
status, errmsg = self._checkValidPtDet(self._ptNo, detno)
if status is False:
self._logError(errmsg)
else:
self._detNo = detno
self.ui.lineEdit_detNo.setText(str(self._detNo))

# plot
self._plotRawDetSignal(self._ptNo, self._detNo)

return

def doPlotNextPtRaw(self):
def doPlotRawPtNext(self):
""" Plot next raw detector signals
"""
# FIXME - Is this correct? Should be for all Pt. or all Detector???
# check
if self._ptNo is not None:
ptno = self._ptNo + 1
Expand All @@ -786,7 +794,7 @@ def doPlotNextPtRaw(self):
return


def doPlotPrevPtRaw(self):
def doPlotRawPtPrev(self):
""" Plot previous raw detector
"""
# check
Expand Down
76 changes: 76 additions & 0 deletions Code/Mantid/scripts/HFIRPowderReduction/HfirUtility.py
@@ -0,0 +1,76 @@
################################################################################
#
# Utility methods for HFIR powder reduction
#
################################################################################


def makeHB2ADetEfficiencyFileName(self, expno, m1, colltrans):
""" Fabricate the detector's efficiency file name for HB2A
Example: HB2A_exp0400__Ge_113_IN_vcorr.txt
* Ge 113: :math:`\lambda = 2.41 \AA`, m1 = 9.45
* Ge 115: :math:`\lambda = 1.54 \AA`, m1 = 0
* Ge 117 :math:`\lambda = 1.12 \AA`, No used
Arguments:
- expno :: experiment number
- m1 :: Ge setup for neutron wavelength (m1)
- colltrans :: for In/Out
Return :: 3-tuple (filename, filename with URL, wavelength)
"""
# Determine wavelength setup
wavelengthsetup = None
m1 = float(m1)
if abs(m1 - 9.45) < 0.01:
# m1 = 9.45
wavelength = 2.41
wavelengthsetup = 'Ge_113'
elif abs(m1) < 0.01:
# m1 = 0.
wavelength = 1.54
wavelengthsetup = 'Ge_115'
else:
# not defined
raise NotImplementedError("'m1' value %f is not defined for wavelength setup." % (m1))

# Determine In/Out, i.e., collimator trans
colltrans = int(colltrans)
if abs(colltrans) == 80:
collimator = 'OUT'
elif colltrans == 0:
collimator = 'IN'
else:
raise NotImplementedError("'colltrans' equal to %d is not defined for IN/OUT." % (colltrans))

# Make the detector efficiency file name
expno = int(expno)
defefffilename = 'HB2A_exp%04d__%s_%s_vcorr.txt' % (expno, wavelengthsetup, collimator)
url = 'http://neutron.ornl.gov/user_data/hb2a/exp%d/Datafiles/%s' % (expno, defefffilename)

return (defefffilename, url, wavelength)


def makeExcludedDetectorFileName(self, expno):
""" Make the excluded detectors' file name
Return :: 2-tuple (file name, URL)
"""
expno = int(expno)
excludeddetfilename = 'HB2A_exp%04d__exclude_detectors.txt' % (expno)
url = 'http://neutron.ornl.gov/user_data/hb2a/exp%d/Datafiles/%s' % (expno, excludeddetfilename)

return (excludeddetfilename, url)


def makeDetGapFileName(self, expno):
""" Make the detectors' gap file name
Return :: 2-tuple (file name, URL)
"""
expno = int(expno)
detgapfilename = 'HB2A_exp04d__gaps.txt' % (expno)
url = 'http://neutron.ornl.gov/user_data/hb2a/exp%d/Datafiles/%s' % (expno, detgapfilename)

return (detgapfilename, url)

0 comments on commit 3e2d360

Please sign in to comment.