Skip to content

Commit

Permalink
Merge branch 'master' into feature/9843_integrate_sysmonitor_widget
Browse files Browse the repository at this point in the history
Conflicts:
	Code/Mantid/CMakeLists.txt
Refs #9843
  • Loading branch information
martyngigg committed Jan 8, 2015
2 parents c15e56f + 1324972 commit 7e39b5a
Show file tree
Hide file tree
Showing 20 changed files with 964 additions and 165 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/CMakeLists.txt
Expand Up @@ -199,7 +199,7 @@ if ( ENABLE_CPACK )
set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},python-ipython >= 1.1.0" )
# scipy, matplotlib, psutil
set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},scipy,python-matplotlib,python-psutil" )
set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},mxml,hdf,hdf5" )
set ( CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES},mxml,hdf,hdf5,jsoncpp" )

if( "${UNIX_CODENAME}" MATCHES "Santiago" )
# On RHEL6 we have to use an updated qscintilla to fix an auto complete bug
Expand All @@ -222,7 +222,7 @@ if ( ENABLE_CPACK )
"libboost-python${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION},"
"libnexus0 (>= 4.3),libgsl0ldbl,libqtcore4 (>= 4.2),libqtgui4 (>= 4.2),libqt4-opengl (>= 4.2),"
"libqt4-xml (>= 4.2),libqt4-svg (>= 4.2),libqt4-qt3support (>= 4.2),qt4-dev-tools,"
"libqwt5-qt4,libqwtplot3d-qt4-0,python-numpy,python-sip,python-qt4" )
"libqwt5-qt4,libqwtplot3d-qt4-0,python-numpy,python-sip,python-qt4,libjsoncpp0" )
set ( PERFTOOLS_DEB_PACKAGE "libgoogle-perftools0 (>= 1.7)" )
if( "${UNIX_CODENAME}" MATCHES "lucid" )
list ( APPEND DEPENDS_LIST ",libqscintilla2-5,"
Expand Down
41 changes: 34 additions & 7 deletions Code/Mantid/Framework/Algorithms/src/AsymmetryCalc.cpp
Expand Up @@ -50,26 +50,37 @@ void AsymmetryCalc::exec() {
// Get original workspace
API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");

// Make an intermediate workspace and prepare it for asymmetry calculation
API::MatrixWorkspace_sptr tmpWS;
if (forward_list.size() > 1 || backward_list.size() > 1) {
// If forward or backward lists have more than 1 entries spectra need to be grouped

// First group spectra from the backward list leaving the rest ungrouped
API::IAlgorithm_sptr group = createChildAlgorithm("GroupDetectors");
group->setProperty("InputWorkspace", inputWS);
group->setProperty("SpectraList", backward_list);
group->setProperty("KeepUngroupedSpectra", true);
group->execute();
tmpWS = group->getProperty("OutputWorkspace");

// Then group spectra from the forward list leaving the rest ungrouped
group = createChildAlgorithm("GroupDetectors");
group->setProperty("InputWorkspace", tmpWS);
group->setProperty("SpectraList", forward_list);
group->setProperty("KeepUngroupedSpectra", true);
group->execute();
tmpWS = group->getProperty("OutputWorkspace");

// The order of grouping leaves the forward spectra group in the first histogram
// and the barckward one is the second
forward = 0;
backward = 1;
} else {
// If the forward and backward lists are empty or have at most 1 index
// there is no need for grouping and the input workspace can be used
// directly
tmpWS = inputWS;

// get workspace indices from spectra ids for forward and backward
std::vector<specid_t> specIDs(2);
specIDs[0] = forward;
Expand All @@ -86,14 +97,21 @@ void AsymmetryCalc::exec() {
backward = static_cast<int>(indices[1]);
}

// Create a workspace with only one spectra for forward
const size_t blocksize = inputWS->blocksize();
assert( tmpWS->blocksize() == blocksize );
const bool isInputHistogram = inputWS->isHistogramData();

// Create a point data workspace with only one spectra for forward
API::MatrixWorkspace_sptr outputWS = API::WorkspaceFactory::Instance().create(
inputWS, 1, inputWS->readX(0).size(), inputWS->blocksize());
inputWS, 1, blocksize, blocksize);

// Get the reference to the input x values.
auto& tmpX = tmpWS->readX(forward);

// Calculate asymmetry for each time bin
// F-aB / F+aB
Progress prog(this, 0.0, 1.0, tmpWS->blocksize());
for (size_t j = 0; j < tmpWS->blocksize(); ++j) {
Progress prog(this, 0.0, 1.0, blocksize);
for (size_t j = 0; j < blocksize; ++j) {
// cal F-aB
double numerator =
tmpWS->dataY(forward)[j] - alpha * tmpWS->dataY(backward)[j];
Expand Down Expand Up @@ -121,16 +139,25 @@ void AsymmetryCalc::exec() {
}
outputWS->dataE(0)[j] = error;

// set the x values
if ( isInputHistogram )
{
outputWS->dataX(0)[j] = ( tmpX[j] + tmpX[j+1] ) / 2;
}
else
{
outputWS->dataX(0)[j] = tmpX[j];
}

prog.report();
}

// Copy the imput time bins on to the output
outputWS->dataX(0) = inputWS->readX(0);
assert( outputWS->dataX(0).size() == blocksize );

// Update Y axis units
outputWS->setYUnit("Asymmetry");

setProperty("OutputWorkspace", outputWS);
setProperty("OutputWorkspace", outputWS);
}

} // namespace Algorithm
Expand Down
17 changes: 15 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/Integration.cpp
Expand Up @@ -28,8 +28,7 @@ using namespace DataObjects;
*/
void Integration::init() {
declareProperty(
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input,
boost::make_shared<HistogramValidator>()),
new WorkspaceProperty<>("InputWorkspace", "", Direction::Input),
"The input workspace to integrate.");
declareProperty(
new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output),
Expand Down Expand Up @@ -254,6 +253,7 @@ void Integration::exec() {
*/
MatrixWorkspace_const_sptr Integration::getInputWorkspace() {
MatrixWorkspace_sptr temp = getProperty("InputWorkspace");

if (temp->id() == "RebinnedOutput") {
// Clean the input workspace in the RebinnedOutput case for nan's and
// inf's in order to treat the data correctly later.
Expand All @@ -268,6 +268,19 @@ MatrixWorkspace_const_sptr Integration::getInputWorkspace() {
alg->executeAsChildAlg();
temp = alg->getProperty("OutputWorkspace");
}

// To integrate point data it will be converted to histograms
if ( !temp->isHistogramData() )
{
auto alg = this->createChildAlgorithm("ConvertToHistogram");
alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", temp);
std::string outName = "_" + temp->getName() + "_histogram";
alg->setProperty("OutputWorkspace", outName);
alg->executeAsChildAlg();
temp = alg->getProperty("OutputWorkspace");
temp->isDistribution(true);
}

return temp;
}

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/AsymmetryCalcTest.h
Expand Up @@ -76,6 +76,7 @@ class AsymmetryCalcTest : public CxxTest::TestSuite

//Use a range as cxxtest seems to complain about the accuracy
TS_ASSERT_DELTA(outputWS->dataY(0)[100],0.2965,0.005);
TS_ASSERT( !outputWS->isHistogramData() );
}

void test_single_spectra()
Expand All @@ -99,6 +100,7 @@ class AsymmetryCalcTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS( outputWS->readY(0)[0], -0.5 ); // == (1 - 3)/(1 + 3)
TS_ASSERT_EQUALS( outputWS->readY(0)[6], -0.5 ); // == (1 - 3)/(1 + 3)
TS_ASSERT_EQUALS( outputWS->readY(0)[9], -0.5 ); // == (1 - 3)/(1 + 3)
TS_ASSERT( !outputWS->isHistogramData() );
}

void test_yUnitLabel()
Expand Down
94 changes: 93 additions & 1 deletion Code/Mantid/Framework/Algorithms/test/IntegrationTest.h
Expand Up @@ -50,7 +50,9 @@ class IntegrationTest : public CxxTest::TestSuite
}

~IntegrationTest()
{}
{
AnalysisDataService::Instance().clear();
}

void testInit()
{
Expand Down Expand Up @@ -450,6 +452,96 @@ class IntegrationTest : public CxxTest::TestSuite

}

void test_point_data_linear_x()
{
// Set up a small workspace for testing
const size_t nspec = 5;
Workspace_sptr space = WorkspaceFactory::Instance().create("Workspace2D",nspec,5,5);
Workspace2D_sptr space2D = boost::dynamic_pointer_cast<Workspace2D>(space);

for (int j = 0; j < 5; ++j) {
for (int k = 0; k < 5; ++k) {
space2D->dataX(j)[k] = 0.9*k;
space2D->dataY(j)[k] = 2*k + double(j);
space2D->dataE(j)[k] = 1.0;
}
}

const std::string outWsName = "IntegrationTest_PointData";
Integration alg;
alg.setRethrows(true);
alg.initialize();
alg.setProperty("InputWorkspace", space2D);
alg.setPropertyValue("OutputWorkspace", outWsName);
TS_ASSERT_THROWS_NOTHING( alg.execute() );
TS_ASSERT( alg.isExecuted() );

MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWsName) );
TS_ASSERT( output );
if ( !output ) return;

TS_ASSERT_EQUALS( output->getNumberHistograms(), 5 );
TS_ASSERT_EQUALS( output->blocksize(), 1 );
TS_ASSERT( output->isHistogramData() );

TS_ASSERT_DELTA( output->readX(0).front(), -0.5 * 0.9, 1e-14 );
TS_ASSERT_DELTA( output->readX(0).back(), 4.5 * 0.9, 1e-14 );

TS_ASSERT_DELTA( output->readY(0)[0], 20 * 0.9, 1e-14 );
TS_ASSERT_DELTA( output->readY(1)[0], 25 * 0.9, 1e-14 );
TS_ASSERT_DELTA( output->readY(2)[0], 30 * 0.9, 1e-14 );
TS_ASSERT_DELTA( output->readY(3)[0], 35 * 0.9, 1e-14 );
TS_ASSERT_DELTA( output->readY(4)[0], 40 * 0.9, 1e-14 );

AnalysisDataService::Instance().remove( outWsName );
}

void test_point_data_non_linear_x()
{
// Set up a small workspace for testing
const size_t nspec = 5;
Workspace_sptr space = WorkspaceFactory::Instance().create("Workspace2D",nspec,5,5);
Workspace2D_sptr space2D = boost::dynamic_pointer_cast<Workspace2D>(space);

for (int j = 0; j < 5; ++j) {
for (int k = 0; k < 5; ++k) {
space2D->dataX(j)[k] = k * (1.0 + 1.0 * k);
space2D->dataY(j)[k] = 2*k + double(j);
space2D->dataE(j)[k] = 1.0;
}
}

const std::string outWsName = "IntegrationTest_PointData";
Integration alg;
alg.setRethrows(true);
alg.initialize();
alg.setProperty("InputWorkspace", space2D);
alg.setPropertyValue("OutputWorkspace", outWsName);
TS_ASSERT_THROWS_NOTHING( alg.execute() );
TS_ASSERT( alg.isExecuted() );

MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWsName) );
TS_ASSERT( output );
if ( !output ) return;

TS_ASSERT_EQUALS( output->getNumberHistograms(), 5 );
TS_ASSERT_EQUALS( output->blocksize(), 1 );
TS_ASSERT( output->isHistogramData() );

TS_ASSERT_EQUALS( output->readX(0).front(), -1.0 );
TS_ASSERT_EQUALS( output->readX(0).back(), 24.0 );

TS_ASSERT_EQUALS( output->readY(0)[0], 132.0 );
TS_ASSERT_EQUALS( output->readY(1)[0], 157.0 );
TS_ASSERT_EQUALS( output->readY(2)[0], 182.0 );
TS_ASSERT_EQUALS( output->readY(3)[0], 207.0 );
TS_ASSERT_EQUALS( output->readY(4)[0], 232.0 );

AnalysisDataService::Instance().remove( outWsName );
}

private:
Integration alg; // Test with range limits
Integration alg2; // Test without limits
Expand Down

0 comments on commit 7e39b5a

Please sign in to comment.