Skip to content

Commit

Permalink
Merge branch 'master' into feature/10431_refl_presenter_use_model
Browse files Browse the repository at this point in the history
Refs #10431

Conflicts:
	Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewPresenterTest.h
  • Loading branch information
Harry Jeffery committed Oct 27, 2014
2 parents 4e5752a + cfc7623 commit 1434c96
Show file tree
Hide file tree
Showing 21 changed files with 880 additions and 174 deletions.
4 changes: 1 addition & 3 deletions Code/Mantid/Build/CMake/DarwinSetup.cmake
Expand Up @@ -128,9 +128,7 @@ else()
set ( PYQT4_PYTHONPATH /usr/local/lib/python${PY_VER}/site-packages/PyQt4 )
set ( SITEPACKAGES /usr/local/lib/python${PY_VER}/site-packages )
# use homebrew OpenSSL package
EXEC_PROGRAM( brew ARGS info openssl | grep openssl: | cut -c 17-22 OUTPUT_VARIABLE _openssl_version )
MESSAGE(STATUS "OpenSSL version: ${_openssl_version}")
set ( OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/${_openssl_version}/ )
set ( OPENSSL_ROOT_DIR /usr/local/opt/openssl )
endif()

# Python packages
Expand Down
141 changes: 94 additions & 47 deletions Code/Mantid/Framework/Algorithms/src/ElasticWindow.cpp
Expand Up @@ -14,7 +14,6 @@ namespace Algorithms
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ElasticWindow)


using namespace Kernel;
using namespace API;

Expand Down Expand Up @@ -48,16 +47,31 @@ void ElasticWindow::exec()

MatrixWorkspace_sptr outputQ;
MatrixWorkspace_sptr outputQSquared;

const bool childAlgLogging(true);
double startProgress(0.0), stepProgress(0.0), endProgress(0.0);
double startProgress(0.0), endProgress(0.0);

// Determine if we are converting from spectra number (red) or Q (Sqw)
const bool axisIsSpectrumNumber = inputWorkspace->getAxis(1)->isSpectra();
g_log.information() << "Axis is spectrum number: " << axisIsSpectrumNumber << std::endl;

// Determine if we need to use the second time range...
if ( ! ( ( enR2S == enR2E ) && ( enR2S == EMPTY_DBL() ) ) )
const bool backgroundSubtraction = !((enR2S == enR2E) && (enR2S == EMPTY_DBL()));
g_log.information() << "Use background subtraction: " << backgroundSubtraction << std::endl;

// Calculate number of steps
size_t numSteps = 4;
if(backgroundSubtraction)
numSteps += 1;
if(axisIsSpectrumNumber)
numSteps += 1;

double stepProgress = 1.0 / static_cast<double>(numSteps);

if(backgroundSubtraction)
{
stepProgress = 1.0/6.0;

// ... CalculateFlatBackground, Minus, Integration...
IAlgorithm_sptr flatBG = createChildAlgorithm("CalculateFlatBackground",startProgress, endProgress,childAlgLogging);
IAlgorithm_sptr flatBG = createChildAlgorithm("CalculateFlatBackground", startProgress, endProgress, childAlgLogging);
flatBG->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWorkspace);
flatBG->setProperty<double>("StartX", enR2S);
flatBG->setProperty<double>("EndX", enR2E);
Expand All @@ -69,7 +83,7 @@ void ElasticWindow::exec()

MatrixWorkspace_sptr flatBGws = flatBG->getProperty("OutputWorkspace");

IAlgorithm_sptr integ = createChildAlgorithm("Integration",startProgress, endProgress,childAlgLogging);
IAlgorithm_sptr integ = createChildAlgorithm("Integration", startProgress, endProgress, childAlgLogging);
integ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", flatBGws);
integ->setProperty<double>("RangeLower", enR1S);
integ->setProperty<double>("RangeUpper", enR1E);
Expand All @@ -80,10 +94,8 @@ void ElasticWindow::exec()
}
else
{
stepProgress = 1.0/5.0;

// ... Just Integration ...
IAlgorithm_sptr integ = createChildAlgorithm("Integration",startProgress, endProgress,childAlgLogging);
IAlgorithm_sptr integ = createChildAlgorithm("Integration", startProgress, endProgress, childAlgLogging);
integ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", inputWorkspace);
integ->setProperty<double>("RangeLower", enR1S);
integ->setProperty<double>("RangeUpper", enR1E);
Expand All @@ -95,45 +107,80 @@ void ElasticWindow::exec()
startProgress += stepProgress;
endProgress += stepProgress;

// ... ConvertSpectrumAxis (ElasticQ). Version 2 to give the correct number
const int version = 2;
IAlgorithm_sptr csaQ = createChildAlgorithm("ConvertSpectrumAxis",startProgress,endProgress,childAlgLogging,version);
csaQ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", integWS);
csaQ->setPropertyValue("Target", "ElasticQ");
csaQ->setPropertyValue("EMode", "Indirect");
csaQ->setPropertyValue("OutputWorkspace", "csaQ");
csaQ->execute();
MatrixWorkspace_sptr csaQws = csaQ->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;

// ... ConvertSpectrumAxis (Q2) ...
IAlgorithm_sptr csaQ2 = createChildAlgorithm("ConvertSpectrumAxis",startProgress,endProgress,childAlgLogging,version);
csaQ2->setProperty<MatrixWorkspace_sptr>("InputWorkspace", integWS);
csaQ2->setPropertyValue("Target", "ElasticQSquared");
csaQ2->setPropertyValue("EMode", "Indirect");
csaQ2->setPropertyValue("OutputWorkspace", "csaQ2");
csaQ2->execute();
MatrixWorkspace_sptr csaQ2ws = csaQ2->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;
if(axisIsSpectrumNumber)
{
// Use ConvertSpectrumAxis v2 for correct result
const int version = 2;

// ... ConvertSpectrumAxis (Q) ...
IAlgorithm_sptr csaQ = createChildAlgorithm("ConvertSpectrumAxis", startProgress, endProgress, childAlgLogging, version);
csaQ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", integWS);
csaQ->setPropertyValue("Target", "ElasticQ");
csaQ->setPropertyValue("EMode", "Indirect");
csaQ->setPropertyValue("OutputWorkspace", "csaQ");
csaQ->execute();
MatrixWorkspace_sptr csaQws = csaQ->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;

// ... ConvertSpectrumAxis (Q2) ...
IAlgorithm_sptr csaQ2 = createChildAlgorithm("ConvertSpectrumAxis", startProgress, endProgress, childAlgLogging, version);
csaQ2->setProperty<MatrixWorkspace_sptr>("InputWorkspace", integWS);
csaQ2->setPropertyValue("Target", "ElasticQSquared");
csaQ2->setPropertyValue("EMode", "Indirect");
csaQ2->setPropertyValue("OutputWorkspace", "csaQ2");
csaQ2->execute();
MatrixWorkspace_sptr csaQ2ws = csaQ2->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;

// ... Transpose A ...
IAlgorithm_sptr tranQ = createChildAlgorithm("Transpose",startProgress,endProgress,childAlgLogging);
tranQ->setProperty<MatrixWorkspace_sptr>("InputWorkspace",csaQws);
tranQ->setPropertyValue("OutputWorkspace", "outQ");
tranQ->execute();
outputQ = tranQ->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;
// ... Transpose (Q) ...
IAlgorithm_sptr tranQ = createChildAlgorithm("Transpose", startProgress, endProgress, childAlgLogging);
tranQ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", csaQws);
tranQ->setPropertyValue("OutputWorkspace", "outQ");
tranQ->execute();
outputQ = tranQ->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;

// ... Transpose (Q2) ...
IAlgorithm_sptr tranQ2 = createChildAlgorithm("Transpose", startProgress, endProgress, childAlgLogging);
tranQ2->setProperty<MatrixWorkspace_sptr>("InputWorkspace", csaQ2ws);
tranQ2->setPropertyValue("OutputWorkspace", "outQSquared");
tranQ2->execute();
outputQSquared = tranQ2->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;
}
else
{
// ... Transpose (Q) ...
IAlgorithm_sptr tranQ = createChildAlgorithm("Transpose", startProgress, endProgress, childAlgLogging);
tranQ->setProperty<MatrixWorkspace_sptr>("InputWorkspace", integWS);
tranQ->setPropertyValue("OutputWorkspace", "outQ");
tranQ->execute();
outputQ = tranQ->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;

// ... Transpose B ...
IAlgorithm_sptr tranQ2 = createChildAlgorithm("Transpose", startProgress,endProgress,childAlgLogging);
tranQ2->setProperty<MatrixWorkspace_sptr>("InputWorkspace",csaQ2ws);
tranQ2->setPropertyValue("OutputWorkspace", "outQSquared");
tranQ2->execute();
outputQSquared = tranQ2->getProperty("OutputWorkspace");
// ... Convert to Histogram (Q2) ...
IAlgorithm_sptr histQ2 = createChildAlgorithm("ConvertToHistogram", startProgress, endProgress, childAlgLogging);
histQ2->setProperty<MatrixWorkspace_sptr>("InputWorkspace", outputQ);
histQ2->setPropertyValue("OutputWorkspace", "outQ");
histQ2->execute();
MatrixWorkspace_sptr qHistWS = histQ2->getProperty("OutputWorkspace");
startProgress += stepProgress;
endProgress += stepProgress;

// ... Convert Units (Q2) ...
IAlgorithm_sptr convUnitQ2 = createChildAlgorithm("ConvertUnits", startProgress, endProgress, childAlgLogging);
convUnitQ2->setProperty<MatrixWorkspace_sptr>("InputWorkspace", qHistWS);
convUnitQ2->setPropertyValue("Target", "QSquared");
convUnitQ2->setPropertyValue("EMode", "Indirect");
convUnitQ2->setPropertyValue("OutputWorkspace", "outQSquared");
convUnitQ2->execute();
outputQSquared = convUnitQ2->getProperty("OutputWorkspace");
}

setProperty("OutputInQ", outputQ);
setProperty("OutputInQSquared", outputQSquared);
Expand Down
50 changes: 46 additions & 4 deletions Code/Mantid/Framework/Algorithms/test/ElasticWindowTest.h
Expand Up @@ -9,6 +9,7 @@
#include "MantidKernel/System.h"

#include "MantidAlgorithms/ConvertUnits.h"
#include "MantidAlgorithms/ConvertSpectrumAxis.h"
#include "MantidAlgorithms/CreateSampleWorkspace.h"
#include "MantidAlgorithms/ElasticWindow.h"
#include "MantidAlgorithms/Rebin.h"
Expand Down Expand Up @@ -64,6 +65,23 @@ class ElasticWindowTest : public CxxTest::TestSuite
setParamAlg.execute();
}

/**
* Converts the generated sample workspace spectra axis to Q.
*/
void convertSampleWsToQ()
{
ConvertSpectrumAxis convQAlg;
convQAlg.initialize();

TS_ASSERT_THROWS_NOTHING( convQAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( convQAlg.setProperty("Target", "MomentumTransfer") );
TS_ASSERT_THROWS_NOTHING( convQAlg.setProperty("EMode", "Indirect") );
TS_ASSERT_THROWS_NOTHING( convQAlg.setProperty("OutputWorkspace", "__ElasticWindowTest_sample") );

TS_ASSERT_THROWS_NOTHING( convQAlg.execute() );
TS_ASSERT( convQAlg.isExecuted() );
}

/**
* Test initialization of the algorithm is successful.
*/
Expand All @@ -75,9 +93,9 @@ class ElasticWindowTest : public CxxTest::TestSuite
}

/**
* Test running ElasticWindow with just the peak range defined.
* Test running ElasticWindow with just the peak range defined using reduced data.
*/
void test_peakOnly()
void test_redPeakOnly()
{
ElasticWindow elwinAlg;
elwinAlg.initialize();
Expand All @@ -96,9 +114,33 @@ class ElasticWindowTest : public CxxTest::TestSuite
}

/**
* Test running ElasticWindow with both the peak and background ranges defined.
* Test running ElasticWindow with just the peak range defined using S(Q,w) data.
*/
void test_sqwPeakOnly()
{
// First convert the sample workspace from spectra number to elastic Q
convertSampleWsToQ();

ElasticWindow elwinAlg;
elwinAlg.initialize();

TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("InputWorkspace", "__ElasticWindowTest_sample") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1Start", -0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("Range1End", 0.1) );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQ", "__ElasticWindowTest_outputQ") );
TS_ASSERT_THROWS_NOTHING( elwinAlg.setProperty("OutputInQSquared", "__ElasticWindowTest_outputQsq") );

TS_ASSERT_THROWS_NOTHING( elwinAlg.execute() );
TS_ASSERT( elwinAlg.isExecuted() );

MatrixWorkspace_sptr qWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("__ElasticWindowTest_outputQ");
verifyQworkspace(qWs);
}

/**
* Test running ElasticWindow with both the peak and background ranges defined using reduced data.
*/
void test_peakAndBackground()
void test_redPeakAndBackground()
{
ElasticWindow elwinAlg;
elwinAlg.initialize();
Expand Down
34 changes: 34 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
Expand Up @@ -1798,6 +1798,40 @@ namespace Mantid
}
file.closeData();

// get the experiment identifier
try {
file.openData("experiment_identifier");
string expId("");
if (file.getInfo().type == ::NeXus::CHAR)
{
expId = file.getStrData();
}
if (!expId.empty()) {
WS->mutableRun().addProperty("experiment_identifier", expId);
}
file.closeData();
} catch (::NeXus::Exception &) {
// let it drop on floor
}

// get the sample name
try {
file.openGroup("sample", "NXsample");
file.openData("name");
string name("");
if (file.getInfo().type == ::NeXus::CHAR)
{
name = file.getStrData();
}
if (!name.empty()) {
WS->mutableSample().setName(name);
}
file.closeData();
file.closeGroup();
} catch (::NeXus::Exception &) {
// let it drop on floor
}

// get the duration
file.openData("duration");
std::vector<double> duration;
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ set ( SRC_FILES
src/CreateMDWorkspace.cpp
src/DivideMD.cpp
src/EqualToMD.cpp
src/EvaluateMDFunction.cpp
src/ExponentialMD.cpp
src/FakeMDEventData.cpp
src/FindPeaksMD.cpp
Expand Down Expand Up @@ -103,6 +104,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/DllConfig.h
inc/MantidMDAlgorithms/EqualToMD.h
inc/MantidMDAlgorithms/ExponentialMD.h
inc/MantidMDAlgorithms/EvaluateMDFunction.h
inc/MantidMDAlgorithms/FakeMDEventData.h
inc/MantidMDAlgorithms/FindPeaksMD.h
inc/MantidMDAlgorithms/GSLFunctions.h
Expand Down Expand Up @@ -185,6 +187,7 @@ set ( TEST_FILES
DivideMDTest.h
EqualToMDTest.h
ExponentialMDTest.h
EvaluateMDFunctionTest.h
FakeMDEventDataTest.h
FindPeaksMDTest.h
FitResolutionConvolvedModelTest.h
Expand Down
@@ -0,0 +1,56 @@
#ifndef MANTID_MDALGORITHMS_EVALUATEMDFUNCTION_H_
#define MANTID_MDALGORITHMS_EVALUATEMDFUNCTION_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"

namespace Mantid
{
namespace MDAlgorithms
{

/** EvaluateMDFunction : TODO: DESCRIPTION
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport EvaluateMDFunction : public API::Algorithm
{
public:
EvaluateMDFunction();
virtual ~EvaluateMDFunction();

virtual const std::string name() const {return "EvaluateMDFunction";}
virtual int version() const;
virtual const std::string category() const;
virtual const std::string summary() const;

private:
void init();
void exec();


};


} // namespace MDAlgorithms
} // namespace Mantid

#endif /* MANTID_MDALGORITHMS_EVALUATEMDFUNCTION_H_ */

0 comments on commit 1434c96

Please sign in to comment.