From 62602d947fa764f71a6b2d661fcc12520764b937 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Fri, 22 Aug 2014 09:33:16 +0100 Subject: [PATCH 1/3] Move jump fit from Python script to algoriithm Refs #9345 --- .../algorithms/WorkflowAlgorithms/JumpFit.py | 153 ++++++++++++++++++ .../scripts/Inelastic/IndirectJumpFit.py | 102 ------------ 2 files changed, 153 insertions(+), 102 deletions(-) create mode 100644 Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py delete mode 100644 Code/Mantid/scripts/Inelastic/IndirectJumpFit.py diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py new file mode 100644 index 000000000000..e148097fdd52 --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py @@ -0,0 +1,153 @@ +from mantid.kernel import * +from mantid.api import * +from mantid.simpleapi import * +from mantid import logger, mtd +from IndirectCommon import * +from IndirectImport import import_mantidplot + +import os.path + + +class JumpFit(PythonAlgorithm): + + + def category(self): + return 'Workflow\\Inelastic;PythonAlgorithms;Inelastic' + + + def summary(self): + return '' ##TODO + + + def PyInit(self): + self.declareProperty(WorkspaceProperty('InputWorkspace', '', direction=Direction.Input), + doc='Input workspace') + + valid_functions = ['ChudleyElliot', 'HallRoss', 'FickDiffusion', 'TeixeiraWater'] + self.declareProperty(name='JumpFunction', defaultValue=valid_functions[0], + validator=StringListValidator(valid_functions), + doc='') ##TODO + + self.declareProperty(name='Width', defaultValue=0, validator=IntMandatoryValidator(), doc='') ##TODO + self.declareProperty(name='QMin', defaultValue=0.0, validator=FloatMandatoryValidator(), doc='') ##TODO + self.declareProperty(name='QMax', defaultValue=0.0, validator=FloatMandatoryValidator(), doc='') ##TODO + + self.declareProperty(name='Output', defaultValue='', direction=Direction.InOut, + doc='Output name') + + self.declareProperty(name='Verbose', defaultValue=False, doc='Output more verbose message to log') + self.declareProperty(name='Plot', defaultValue=False, doc='Plot result workspace') + self.declareProperty(name='Save', defaultValue=False, doc='Save result workspace to nexus file in the default save directory') + + + def PyExec(self): + in_ws = self.getPropertyValue('InputWorkspace') + out_name = self.getPropertyValue('Output') + + jump_function = self.getProperty('JumpFunction').value + width = self.getProperty('Width').value + q_min = self.getProperty('QMin').value + q_max = self.getProperty('QMax').value + + verbose = self.getProperty('Verbose').value + plot = self.getProperty('Plot').value + save = self.getProperty('Save').value + + workdir = getDefaultWorkingDirectory() + + StartTime('Jump fit : ' + jump_function + ' ; ') + + # Select the width we wish to fit + spectrum_ws = "__" + in_ws + ExtractSingleSpectrum(InputWorkspace=in_ws, OutputWorkspace=spectrum_ws, WorkspaceIndex=width) + + # Convert to HWHM + Scale(InputWorkspace=spectrum_ws, Factor=0.5, OutputWorkspace=spectrum_ws) + + # Crop the workspace between the given ranges + if verbose: + logger.notice('Cropping from Q= ' + str(q_min) + ' to ' + str(q_max)) + + # Give the user some extra infromation if required + if verbose: + in_run = mtd[in_ws].getRun() + try: + log = in_run.getLogData('fit_program') + if log: + val = log.value + logger.notice('Fit program was : ' + val) + except RuntimeError: + # If we couldn't find the fit program, just pass + pass + + logger.notice('Parameters in ' + in_ws) + + x_data = mtd[in_ws].readX(0) + xmax = x_data[-1] + + # Select fit function to use + if jump_function == 'ChudleyElliot': + # Chudley-Elliott: HWHM=(1-sin*(Q*L)/(Q*L))/Tau + # for Q->0 W=Q^2*L^2/(6*Tau) + + tval = 1.0 / xmax + lval = 1.5 + func = 'name=ChudleyElliot, Tau=' + str(tval) + ', L=' + str(lval) + + elif jump_function == 'HallRoss': + # Hall-Ross: HWHM=(1-exp(-L*Q^2))/Tau + # for Q->0 W=A*Q^2*r + + tval = 1.0 / xmax + lval = 1.5 + func = 'name=HallRoss, Tau=' + str(tval) + ', L=' + str(lval) + + elif jump_function == 'FickDiffusion': + # Fick: HWHM=D*Q^2 + + y_data = mtd[in_ws].readY(0) + diff = (y_data[2] - y_data[0]) / ((x_data[2] - x_data[0]) * (x_data[2] - x_data[0])) + func = 'name=FickDiffusion, D=' + str(diff) + + elif jump_function == 'TeixeiraWater': + # Teixeira: HWHM=Q^2*L/((1+Q^2*L)*tau) + # for Q->0 W= + + tval = 1.0 / xmax + lval = 1.5 + func = 'name=TeixeiraWater, Tau=' + str(tval) + ', L=' + str(lval) + + # Run fit function + if out_name is "": + out_name = in_ws[:-10] + '_' + jump_function + 'fit' + + Fit(Function=func, InputWorkspace=spectrum_ws, CreateOutput=True, Output=out_name, StartX=q_min, EndX=q_max) + fit_workspace = out_name + '_Workspace' + + # Populate sample logs + CopyLogs(InputWorkspace=in_ws, OutputWorkspace=fit_workspace) + AddSampleLog(Workspace=fit_workspace, LogName="jump_function", LogType="String", LogText=jump_function) + AddSampleLog(Workspace=fit_workspace, LogName="q_min", LogType="Number", LogText=str(q_min)) + AddSampleLog(Workspace=fit_workspace, LogName="q_max", LogType="Number", LogText=str(q_max)) + + # Process output options + if save: + fit_path = os.path.join(workdir, fit_workspace + '.nxs') + SaveNexusProcessed(InputWorkspace=fit_workspace, Filename=fit_path) + + if verbose: + logger.notice('Fit file is ' + fit_path) + + if plot: + mtd_plot = import_mantidplot() + mtd_plot.plotSpectrum(fit_workspace, [0, 1, 2], True) + + self.setProperty('Output', out_name) + + DeleteWorkspace(Workspace=spectrum_ws) + + EndTime('Jump fit : ' + jump_function + ' ; ') + + +# Register algorithm with Mantid +AlgorithmFactory.subscribe(JumpFit) diff --git a/Code/Mantid/scripts/Inelastic/IndirectJumpFit.py b/Code/Mantid/scripts/Inelastic/IndirectJumpFit.py deleted file mode 100644 index b4d43481583e..000000000000 --- a/Code/Mantid/scripts/Inelastic/IndirectJumpFit.py +++ /dev/null @@ -1,102 +0,0 @@ -from mantid.simpleapi import * -from mantid import config, logger, mtd -from IndirectCommon import * -from IndirectImport import import_mantidplot -import sys, os.path -mp = import_mantidplot() - -# Jump programs -def JumpRun(samWS,jumpFunc,width,qmin,qmax,Verbose=False,Plot=False,Save=False): - StartTime('Jump fit : '+jumpFunc+' ; ') - - workdir = getDefaultWorkingDirectory() - - #select the width we wish to fit - spectrumWs = "__" + samWS - ExtractSingleSpectrum(InputWorkspace=samWS, OutputWorkspace=spectrumWs, WorkspaceIndex=width) - - #convert to HWHM - Scale(InputWorkspace=spectrumWs, Factor=0.5, OutputWorkspace=spectrumWs) - - #crop the workspace between the given ranges - if Verbose: - logger.notice('Cropping from Q= ' + str(qmin) +' to '+ str(qmax)) - - #give the user some extra infromation if required - if Verbose: - inGR = mtd[samWS].getRun() - try: - log = inGR.getLogData('fit_program') - if log: - val = log.value - logger.notice('Fit program was : '+val) - except RuntimeError: - #if we couldn't find the fit program, just pass - pass - - logger.notice('Parameters in ' + samWS) - - x = mtd[samWS].readX(0) - xmax = x[-1] - - #select fit function to use - if jumpFunc == 'CE': - # Chudley-Elliott: HWHM=(1-sin*(Q*L)/(Q*L))/Tau - # for Q->0 W=Q^2*L^2/(6*Tau) - - tval = 1.0/xmax - lval = 1.5 - func = 'name=ChudleyElliot, Tau='+str(tval)+', L='+str(lval) - - elif jumpFunc == 'HallRoss': - # Hall-Ross: HWHM=(1-exp(-L*Q^2))/Tau - # for Q->0 W=A*Q^2*r - - tval = 1.0/xmax - lval = 1.5 - func = 'name=HallRoss, Tau='+str(tval)+', L='+str(lval) - - elif jumpFunc == 'Fick': - # Fick: HWHM=D*Q^2 - - y = mtd[samWS].readY(0) - diff = (y[2]-y[0])/((x[2]-x[0])*(x[2]-x[0])) - func = 'name=FickDiffusion, D='+str(diff) - - elif jumpFunc == 'Teixeira': - # Teixeira: HWHM=Q^2*L/((1+Q^2*L)*tau) - # for Q->0 W= - - tval = 1.0/xmax - lval = 1.5 - func = 'name=TeixeiraWater, Tau='+str(tval)+', L='+str(lval) - - else: - sys.exit("Error in Jump Fit: Invalid fit function supplied.") - return - - #run fit function - fit_workspace_base = samWS[:-10] +'_'+ jumpFunc +'fit' - Fit(Function=func, InputWorkspace=spectrumWs, CreateOutput=True, Output=fit_workspace_base, StartX=qmin, EndX=qmax) - fit_workspace = fit_workspace_base + '_Workspace' - - CopyLogs(InputWorkspace=samWS, OutputWorkspace=fit_workspace) - AddSampleLog(Workspace=fit_workspace, LogName="jump_function", LogType="String", LogText=jumpFunc) - AddSampleLog(Workspace=fit_workspace, LogName="q_min", LogType="Number", LogText=str(qmin)) - AddSampleLog(Workspace=fit_workspace, LogName="q_max", LogType="Number", LogText=str(qmax)) - - #process output options - if Save: - fit_path = os.path.join(workdir,fit_workspace+'.nxs') - SaveNexusProcessed(InputWorkspace=fit_workspace, Filename=fit_path) - - if Verbose: - logger.notice('Fit file is ' + fit_path) - - if Plot: - JumpPlot(fit_workspace) - - EndTime('Jump fit : '+jumpFunc+' ; ') - -def JumpPlot(inputWS): - mp.plotSpectrum(inputWS,[0,1,2],True) \ No newline at end of file From 097bb3d6a941c1ab6dd4d27dab9abeb26335249d Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Fri, 22 Aug 2014 10:19:50 +0100 Subject: [PATCH 2/3] Added use of algorithm to UI Refs #9345 --- .../algorithms/WorkflowAlgorithms/JumpFit.py | 4 +- .../IndirectBayesTab.h | 15 +++-- .../inc/MantidQtCustomInterfaces/JumpFit.h | 6 +- .../CustomInterfaces/src/IndirectBayesTab.cpp | 14 +++- .../MantidQt/CustomInterfaces/src/JumpFit.cpp | 65 ++++++++++--------- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py index e148097fdd52..95eb635c8e74 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py @@ -24,7 +24,7 @@ def PyInit(self): doc='Input workspace') valid_functions = ['ChudleyElliot', 'HallRoss', 'FickDiffusion', 'TeixeiraWater'] - self.declareProperty(name='JumpFunction', defaultValue=valid_functions[0], + self.declareProperty(name='Function', defaultValue=valid_functions[0], validator=StringListValidator(valid_functions), doc='') ##TODO @@ -44,7 +44,7 @@ def PyExec(self): in_ws = self.getPropertyValue('InputWorkspace') out_name = self.getPropertyValue('Output') - jump_function = self.getProperty('JumpFunction').value + jump_function = self.getProperty('Function').value width = self.getProperty('Width').value q_min = self.getProperty('QMin').value q_max = self.getProperty('QMax').value diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h index 56a19bc98052..7edd490264de 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h @@ -3,6 +3,7 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidQtMantidWidgets/RangeSelector.h" +#include "MantidQtAPI/AlgorithmRunner.h" #include "MantidQtAPI/QwtWorkspaceSpectrumData.h" #include @@ -42,7 +43,7 @@ namespace MantidQt This class defines a abstract base class for the different tabs of the Indirect Bayes interface. Any joint functionality shared between each of the tabs should be implemented here as well as defining shared member functions. - + @author Samuel Jackson, STFC Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory @@ -112,17 +113,19 @@ namespace MantidQt /// Function to run a string as python code void runPythonScript(const QString& pyInput); /// Function to read an instrument's resolution from the IPF using a string - bool getInstrumentResolution(const QString& filename, std::pair& res); + bool getInstrumentResolution(const QString& filename, std::pair& res); /// Function to read an instrument's resolution from the IPF using a workspace pointer bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair& res); /// Function to set the range limits of the plot void setPlotRange(QtProperty* min, QtProperty* max, const std::pair& bounds); /// Function to set the position of the lower guide on the plot - void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value); + void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value); /// Function to set the position of the upper guide on the plot - void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value); + void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value); /// Function to get the range of the curve displayed on the mini plot std::pair getCurveRange(); + /// Run an algorithm async + void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm); /// Plot of the input QwtPlot* m_plot; @@ -138,9 +141,11 @@ namespace MantidQt QtDoublePropertyManager* m_dblManager; /// Double editor facotry for the properties browser DoubleEditorFactory* m_dblEdFac; + /// Algorithm runner object to execute algorithms on a seperate thread from the gui + MantidQt::API::AlgorithmRunner* m_algRunner; }; } // namespace CustomInterfaces } // namespace Mantid -#endif \ No newline at end of file +#endif diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h index 582079841a94..a42bbe8bd48d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h @@ -37,10 +37,10 @@ namespace MantidQt void findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws); private: - //The ui form + // The UI form Ui::JumpFit m_uiForm; - // map of axis labels to spectrum number - std::map spectraList; + // Map of axis labels to spectrum number + std::map m_spectraList; }; } // namespace CustomInterfaces diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp index 7139ae889bf1..5ce3ff31c499 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp @@ -15,7 +15,8 @@ namespace MantidQt IndirectBayesTab::IndirectBayesTab(QWidget * parent) : QWidget(parent), m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_rangeSelector(new MantidWidgets::RangeSelector(m_plot)), m_propTree(new QtTreePropertyBrowser()), m_properties(), m_dblManager(new QtDoublePropertyManager()), - m_dblEdFac(new DoubleEditorFactory()) + m_dblEdFac(new DoubleEditorFactory()), + m_algRunner(new MantidQt::API::AlgorithmRunner(parent)) { m_propTree->setFactoryForManager(m_dblManager, m_dblEdFac); m_rangeSelector->setInfoOnly(false); @@ -58,6 +59,17 @@ namespace MantidQt emit executePythonScript(pyInput, true); } + /** + * Runs an algorithm async + * + * @param algorithm :: The algorithm to be run + */ + void IndirectBayesTab::runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm) + { + algorithm->setRethrows(true); + m_algRunner->startAlgorithm(algorithm); + } + /** * Plot a workspace to the miniplot given a workspace name and * a specturm index. diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp index d6492b4c0293..72a58b75b3a2 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp @@ -1,3 +1,4 @@ +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Run.h" #include "MantidAPI/TextAxis.h" #include "MantidQtCustomInterfaces/JumpFit.h" @@ -48,7 +49,7 @@ namespace MantidQt uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample); //this workspace doesn't have any valid widths - if(spectraList.size() == 0) + if(m_spectraList.size() == 0) { uiv.addErrorMessage("Input workspace doesn't appear to contain any width data."); } @@ -69,50 +70,51 @@ namespace MantidQt */ void JumpFit::run() { - QString verbose("False"); - QString plot("False"); - QString save("False"); - - QString sample = m_uiForm.dsSample->getCurrentDataName(); + using namespace Mantid::API; - //fit function to use - QString fitFunction("CE"); + // Fit function to use + QString fitFunction("ChudleyElliot"); switch(m_uiForm.cbFunction->currentIndex()) { case 0: - fitFunction = "CE"; // Use Chudley-Elliott + fitFunction = "ChudleyElliot"; break; case 1: fitFunction = "HallRoss"; break; case 2: - fitFunction = "Fick"; + fitFunction = "FickDiffusion"; break; case 3: - fitFunction = "Teixeira"; + fitFunction = "TeixeiraWater"; break; } + // Loaded workspace name + QString sample = m_uiForm.dsSample->getCurrentDataName(); + auto ws = Mantid::API::AnalysisDataService::Instance().retrieve(sample.toStdString()); + std::string widthText = m_uiForm.cbWidth->currentText().toStdString(); - int width = spectraList[widthText]; - QString widthTxt = boost::lexical_cast(width).c_str(); + long width = m_spectraList[widthText]; - // Cropping values - QString QMin = m_properties["QMin"]->valueText(); - QString QMax = m_properties["QMax"]->valueText(); + IAlgorithm_sptr fitAlg = AlgorithmManager::Instance().create("JumpFit"); + fitAlg->initialize(); - //output options - if(m_uiForm.chkVerbose->isChecked()) { verbose = "True"; } - if(m_uiForm.chkSave->isChecked()) { save = "True"; } - if(m_uiForm.chkPlot->isChecked()) { plot = "True"; } + fitAlg->setProperty("InputWorkspace", ws); + fitAlg->setProperty("Function", fitFunction.toStdString()); - QString pyInput = - "from IndirectJumpFit import JumpRun\n"; + fitAlg->setProperty("Width", width); + fitAlg->setProperty("QMin", m_dblManager->value(m_properties["QMin"])); + fitAlg->setProperty("QMax", m_dblManager->value(m_properties["QMax"])); - pyInput += "JumpRun('"+sample+"','"+fitFunction+"',"+widthTxt+","+QMin+","+QMax+"," - "Save="+save+", Plot="+plot+", Verbose="+verbose+")\n"; + bool verbose = m_uiForm.chkVerbose->isChecked(); + bool save = m_uiForm.chkSave->isChecked(); + bool plot = m_uiForm.chkPlot->isChecked(); + fitAlg->setProperty("Plot", plot); + fitAlg->setProperty("Verbose", verbose); + fitAlg->setProperty("Save", save); - runPythonScript(pyInput); + runAlgorithm(fitAlg); } /** @@ -134,18 +136,17 @@ namespace MantidQt */ void JumpFit::handleSampleInputReady(const QString& filename) { - auto ws = Mantid::API::AnalysisDataService::Instance().retrieve(filename.toStdString()); auto mws = boost::dynamic_pointer_cast(ws); findAllWidths(mws); - if(spectraList.size() > 0) + if(m_spectraList.size() > 0) { m_uiForm.cbWidth->setEnabled(true); std::string currentWidth = m_uiForm.cbWidth->currentText().toStdString(); - plotMiniPlot(filename, spectraList[currentWidth]); + plotMiniPlot(filename, m_spectraList[currentWidth]); std::pair res; std::pair range = getCurveRange(); @@ -176,7 +177,7 @@ namespace MantidQt void JumpFit::findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws) { m_uiForm.cbWidth->clear(); - spectraList.clear(); + m_spectraList.clear(); for (size_t i = 0; i < ws->getNumberHistograms(); ++i) { @@ -206,7 +207,7 @@ namespace MantidQt } cbItemName = title.substr(0, substrIndex); - spectraList[cbItemName] = static_cast(i); + m_spectraList[cbItemName] = static_cast(i); m_uiForm.cbWidth->addItem(QString(cbItemName.c_str())); //display widths f1.f1, f2.f1 and f2.f2 @@ -228,11 +229,11 @@ namespace MantidQt QString sampleName = m_uiForm.dsSample->getCurrentDataName(); QString samplePath = m_uiForm.dsSample->getFullFilePath(); - if(!sampleName.isEmpty() && spectraList.size() > 0) + if(!sampleName.isEmpty() && m_spectraList.size() > 0) { if(validate()) { - plotMiniPlot(sampleName, spectraList[text.toStdString()]); + plotMiniPlot(sampleName, m_spectraList[text.toStdString()]); } } } From b0c427a313dc44e1a1439cfeb219509c4611a510 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Fri, 22 Aug 2014 11:17:46 +0100 Subject: [PATCH 3/3] Minor refactoring, added docs Refs #9345 --- .../algorithms/WorkflowAlgorithms/JumpFit.py | 40 +++++++++---------- .../docs/source/algorithms/JumpFit-v1.rst | 18 +++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 Code/Mantid/docs/source/algorithms/JumpFit-v1.rst diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py index 95eb635c8e74..e17c431decbe 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py @@ -15,10 +15,6 @@ def category(self): return 'Workflow\\Inelastic;PythonAlgorithms;Inelastic' - def summary(self): - return '' ##TODO - - def PyInit(self): self.declareProperty(WorkspaceProperty('InputWorkspace', '', direction=Direction.Input), doc='Input workspace') @@ -26,11 +22,15 @@ def PyInit(self): valid_functions = ['ChudleyElliot', 'HallRoss', 'FickDiffusion', 'TeixeiraWater'] self.declareProperty(name='Function', defaultValue=valid_functions[0], validator=StringListValidator(valid_functions), - doc='') ##TODO + doc='The fit function to use') + + self.declareProperty(name='Width', defaultValue=0, validator=IntMandatoryValidator(), + doc='Spectrum in the workspace to use for fiting') - self.declareProperty(name='Width', defaultValue=0, validator=IntMandatoryValidator(), doc='') ##TODO - self.declareProperty(name='QMin', defaultValue=0.0, validator=FloatMandatoryValidator(), doc='') ##TODO - self.declareProperty(name='QMax', defaultValue=0.0, validator=FloatMandatoryValidator(), doc='') ##TODO + self.declareProperty(name='QMin', defaultValue=0.0, validator=FloatMandatoryValidator(), + doc='Lower bound of Q range to use for fitting') + self.declareProperty(name='QMax', defaultValue=0.0, validator=FloatMandatoryValidator(), + doc='Upper bound of Q range to use for fitting') self.declareProperty(name='Output', defaultValue='', direction=Direction.InOut, doc='Output name') @@ -83,45 +83,45 @@ def PyExec(self): logger.notice('Parameters in ' + in_ws) x_data = mtd[in_ws].readX(0) - xmax = x_data[-1] + m_max = x_data[-1] # Select fit function to use if jump_function == 'ChudleyElliot': # Chudley-Elliott: HWHM=(1-sin*(Q*L)/(Q*L))/Tau # for Q->0 W=Q^2*L^2/(6*Tau) - tval = 1.0 / xmax - lval = 1.5 - func = 'name=ChudleyElliot, Tau=' + str(tval) + ', L=' + str(lval) + t_val = 1.0 / m_max + l_val = 1.5 + function = 'name=ChudleyElliot, Tau=' + str(t_val) + ', L=' + str(l_val) elif jump_function == 'HallRoss': # Hall-Ross: HWHM=(1-exp(-L*Q^2))/Tau # for Q->0 W=A*Q^2*r - tval = 1.0 / xmax - lval = 1.5 - func = 'name=HallRoss, Tau=' + str(tval) + ', L=' + str(lval) + t_val = 1.0 / m_max + l_val = 1.5 + function = 'name=HallRoss, Tau=' + str(t_val) + ', L=' + str(l_val) elif jump_function == 'FickDiffusion': # Fick: HWHM=D*Q^2 y_data = mtd[in_ws].readY(0) diff = (y_data[2] - y_data[0]) / ((x_data[2] - x_data[0]) * (x_data[2] - x_data[0])) - func = 'name=FickDiffusion, D=' + str(diff) + function = 'name=FickDiffusion, D=' + str(diff) elif jump_function == 'TeixeiraWater': # Teixeira: HWHM=Q^2*L/((1+Q^2*L)*tau) # for Q->0 W= - tval = 1.0 / xmax - lval = 1.5 - func = 'name=TeixeiraWater, Tau=' + str(tval) + ', L=' + str(lval) + t_val = 1.0 / m_max + l_val = 1.5 + function = 'name=TeixeiraWater, Tau=' + str(t_val) + ', L=' + str(l_val) # Run fit function if out_name is "": out_name = in_ws[:-10] + '_' + jump_function + 'fit' - Fit(Function=func, InputWorkspace=spectrum_ws, CreateOutput=True, Output=out_name, StartX=q_min, EndX=q_max) + Fit(Function=function, InputWorkspace=spectrum_ws, CreateOutput=True, Output=out_name, StartX=q_min, EndX=q_max) fit_workspace = out_name + '_Workspace' # Populate sample logs diff --git a/Code/Mantid/docs/source/algorithms/JumpFit-v1.rst b/Code/Mantid/docs/source/algorithms/JumpFit-v1.rst new file mode 100644 index 000000000000..f89c39923941 --- /dev/null +++ b/Code/Mantid/docs/source/algorithms/JumpFit-v1.rst @@ -0,0 +1,18 @@ +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +Performs jump fitting on a workspace created by either ConvFit (Indirct Data Analysis) +or Quasi (Indirect Bayes). + +For more details, see the `Indirect Bayes docs +`_. + +.. categories::