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

Merge pull request #13940 from mantidproject/to_pdfgetn_workflow_algorithm

PDFgetN workflow algorithm is implemented.

I ran two scripts in parallel to compare the results from SNSPowderReduction and PDToPDFgetN.  There is slightly difference, but acceptable.  

Issue is thus closed.
parents 17fdaf7a 0c4e060e
No related branches found
No related tags found
No related merge requests found
#pylint: disable=no-init
from mantid.simpleapi import *
from mantid.api import *
from mantid.kernel import Direction, FloatArrayProperty
import mantid
COMPRESS_TOL_TOF = .01
class PDToPDFgetN(DataProcessorAlgorithm):
_focusPos = {}
_iparmFile = None
def category(self):
return "Workflow\\Diffraction;PythonAlgorithms"
def name(self):
return "PDToPDFgetN"
def summary(self):
return "The algorithm used converting raw data to pdfgetn input files"
def PyInit(self):
group = "Input"
self.declareProperty(FileProperty(name="Filename",
defaultValue="", action=FileAction.Load,
extensions=["_event.nxs", ".nxs.h5"]),
"Event file")
self.declareProperty("MaxChunkSize", 0.0,
"Specify maximum Gbytes of file to read in one chunk. Default is whole file.")
self.declareProperty("FilterBadPulses", 95.,
doc="Filter out events measured while proton " +
"charge is more than 5% below average")
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "",
direction=Direction.Input,
optional=PropertyMode.Optional),
doc="Handle to reduced workspace")
self.setPropertyGroup("Filename", group)
self.setPropertyGroup("MaxChunkSize", group)
self.setPropertyGroup("FilterBadPulses", group)
self.setPropertyGroup("InputWorkspace", group)
group = "Output"
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "",
direction=Direction.Output),
doc="Handle to reduced workspace")
self.declareProperty(FileProperty(name="PDFgetNFile", defaultValue="", action=FileAction.Save,
extensions=[".getn"]), "Output filename")
self.setPropertyGroup("OutputWorkspace", group)
self.setPropertyGroup("PDFgetNFile", group)
self.declareProperty(FileProperty(name="CalibrationFile",
defaultValue="", action=FileAction.OptionalLoad,
extensions=[".h5", ".hd5", ".hdf", ".cal"]))
self.declareProperty(FileProperty(name="CharacterizationRunsFile", defaultValue="",
action=FileAction.OptionalLoad,
extensions=["txt"]),
"File with characterization runs denoted")
self.declareProperty("RemovePromptPulseWidth", 0.0,
"Width of events (in microseconds) near the prompt pulse to remove. 0 disables")
self.declareProperty("CropWavelengthMin", 0.,
"Crop the data at this minimum wavelength.")
self.declareProperty("CropWavelengthMax", 0.,
"Crop the data at this maximum wavelength.")
self.declareProperty(FloatArrayProperty("Binning", values=[0., 0., 0.],
direction=Direction.Input), "Positive is linear bins, negative is logorithmic")
self.declareProperty("ResampleX", 0,
"Number of bins in x-axis. Non-zero value overrides \"Params\" property. " +
"Negative value means logorithmic binning.")
def _loadCharacterizations(self):
self._focusPos = {}
self._iparmFile = None
charFilename = self.getProperty("CharacterizationRunsFile").value
if charFilename is None or len(charFilename) <= 0:
return
results = PDLoadCharacterizations(Filename=charFilename,
OutputWorkspace="characterizations")
self._iparmFile = results[1]
self._focusPos['PrimaryFlightPath'] = results[2]
self._focusPos['SpectrumIDs'] = results[3]
self._focusPos['L2'] = results[4]
self._focusPos['Polar'] = results[5]
self._focusPos['Azimuthal'] = results[6]
def PyExec(self):
self._loadCharacterizations()
wksp = self.getProperty("InputWorkspace").value
if wksp is None:
wksp = LoadEventAndCompress(Filename=self.getProperty("Filename").value,
OutputWorkspace=self.getPropertyValue("OutputWorkspace"),
MaxChunkSize=self.getProperty("MaxChunkSize").value,
FilterBadPulses=self.getProperty("FilterBadPulses").value,
CompressTOFTolerance=COMPRESS_TOL_TOF)
else:
self.log().information("Using input workspace. Ignoring properties 'Filename', " +
"'OutputWorkspace', 'MaxChunkSize', and 'FilterBadPulses'")
charac = ""
if mtd.doesExist("characterizations"):
charac = "characterizations"
# get the correct row of the table
PDDetermineCharacterizations(InputWorkspace=wksp,
Characterizations=charac,
ReductionProperties="__snspowderreduction")
wksp = AlignAndFocusPowder(InputWorkspace=wksp, OutputWorkspace=wksp,
CalFileName=self.getProperty("CalibrationFile").value,
Params=self.getProperty("Binning").value,
ResampleX=self.getProperty("ResampleX").value, Dspacing=True,
PreserveEvents=False,
RemovePromptPulseWidth=self.getProperty("RemovePromptPulseWidth").value,
CompressTolerance=COMPRESS_TOL_TOF,
CropWavelengthMin=self.getProperty("CropWavelengthMin").value,
CropWavelengthMax=self.getProperty("CropWavelengthMax").value,
ReductionProperties="__snspowderreduction",
**(self._focusPos))
wksp = NormaliseByCurrent(InputWorkspace=wksp, OutputWorkspace=wksp)
wksp.getRun()['gsas_monitor'] = 1
if self._iparmFile is not None:
wksp.getRun()['iparm_file'] = self._iparmFile
wksp = SetUncertainties(InputWorkspace=wksp, OutputWorkspace=wksp,
SetError="sqrt")
SaveGSS(InputWorkspace=wksp,
Filename=self.getProperty("PDFgetNFile").value,
SplitFiles=False, Append=False,
MultiplyByBinWidth=False,
Bank=mantid.pmds["__snspowderreduction"]["bank"].value,
Format="SLOG", ExtendedHeader=True)
self.setProperty("OutputWorkspace", wksp)
# Register algorithm with Mantid.
AlgorithmFactory.subscribe(PDToPDFgetN)
...@@ -17,7 +17,8 @@ def getSaveDir(): ...@@ -17,7 +17,8 @@ def getSaveDir():
return os.path.abspath(os.path.curdir) return os.path.abspath(os.path.curdir)
def do_cleanup(): def do_cleanup():
Files = ["PG3_9829.gsa", Files = ["PG3_9829.getn",
"PG3_9829.gsa",
"PG3_9829.py", "PG3_9829.py",
"PG3_9830.gsa", "PG3_9830.gsa",
"PG3_9830.py", "PG3_9830.py",
...@@ -249,3 +250,38 @@ class SeriesAndConjoinFilesTest(stresstesting.MantidStressTest): ...@@ -249,3 +250,38 @@ class SeriesAndConjoinFilesTest(stresstesting.MantidStressTest):
self.tolerance = 1.0e-2 self.tolerance = 1.0e-2
return ('PG3_9829','PG3_9829_golden') return ('PG3_9829','PG3_9829_golden')
#return ('PG3_9830','PG3_9830_golden') # can only validate one workspace #return ('PG3_9830','PG3_9830_golden') # can only validate one workspace
class ToPDFgetNTest(stresstesting.MantidStressTest):
cal_file = "PG3_FERNS_d4832_2011_08_24.cal"
char_file = "PG3_characterization_2012_02_23-HR-ILL.txt"
data_file = "PG3_9829_event.nxs"
getn_file = "PG3_9829.getn"
def cleanup(self):
do_cleanup()
return True
def requiredMemoryMB(self):
"""Requires 3Gb"""
return 3000
def requiredFiles(self):
files = [self.cal_file, self.char_file, self.data_file]
return files
def runTest(self):
savedir = getSaveDir()
PDToPDFgetN(Filename=self.data_file,
FilterBadPulses=25,
OutputWorkspace=self.data_file,
PDFgetNFile=os.path.join(savedir, self.getn_file),
CalibrationFile=self.cal_file,
CharacterizationRunsFile=self.char_file,
RemovePromptPulseWidth=50,
Binning=-.0004)
def validateMethod(self):
return None # it running is all that we need
def validate(self):
pass
.. algorithm::
.. summary::
.. alias::
.. properties::
Description
-----------
This is a workflow algorithm that creates files suitable as input
into `PDFgetN <http://pdfgetn.sourceforge.net/>`_.
#. :ref:`algm-PDLoadCharacterizations`
#. :ref:`algm-LoadEventAndCompress` if ``InputWorkspace`` is not
provided
#. :ref:`algm-PDDetermineCharacterizations` to determine information
from the characterization file
#. :ref:`algm-AlignAndFocusPowder`
#. :ref:`algm-NormaliseByCurrent`
#. :ref:`algm-SetUncertainties` (``SetError="sqrt"``)
#. :ref:`algm-SaveGSS`
Workflow
########
.. diagram:: PDToPDFgetN-v1_wkflw.dot
.. categories::
.. sourcelink::
digraph AlignAndFocusPowder {
label="AlignAndFocusPowder Flowchart"
$global_style
subgraph params {
$param_style
InputWorkspace
}
subgraph algoritms {
$algorithm_style
loadChar [label="PDLoadCharacterizations v1"]
loadEvent [label="LoadEventAndCompress v1"]
determineChar [label="PDDetermineCharacterizations v1"]
alignAndFocus [label="AlignAndFocusPowder v1"]
norm [label="NormaliseByCurrent v1"]
setUncert [label="SetUncertainties v1"]
saveGSS [label="SaveGSS v1"]
}
subgraph decisions {
$decision_style
}
loadChar -> determineChar
loadEvent -> InputWorkspace
InputWorkspace -> determineChar
InputWorkspace -> alignAndFocus
determineChar -> alignAndFocus
alignAndFocus -> norm
norm -> setUncert
setUncert -> saveGSS
}
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