Skip to content
Snippets Groups Projects
Commit c47112a3 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #11393. Add tests for width.

parent d302f786
No related merge requests found
......@@ -7,6 +7,7 @@
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/MandatoryValidator.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidMDEvents/MDHistoWorkspaceIterator.h"
#include <boost/make_shared.hpp>
#include <vector>
#include <map>
......@@ -19,6 +20,7 @@
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::MDEvents;
typedef std::vector<int> WidthVector;
typedef boost::function<IMDHistoWorkspace_sptr(IMDHistoWorkspace_const_sptr, const WidthVector&)> SmoothFunction;
......@@ -40,11 +42,12 @@ std::vector<std::string> functions() {
IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth, const WidthVector& widthVector)
{
IMDHistoWorkspace_sptr outWS = toSmooth->clone();
boost::scoped_ptr<IMDIterator> iterator(toSmooth->createIterator(NULL)); // TODO should be multi-threaded
boost::scoped_ptr<MDHistoWorkspaceIterator> iterator(dynamic_cast<MDHistoWorkspaceIterator*>(toSmooth->createIterator(NULL))); // TODO should be multi-threaded
do
{
// Gets all vertex-touching neighbours
std::vector<size_t> neighbourIndexes = iterator->findNeighbourIndexes();
std::vector<size_t> neighbourIndexes = iterator->findNeighbourIndexesByWidth(widthVector.front()); // TODO we should use the whole width vector not just the first element.
const size_t nNeighbours = neighbourIndexes.size();
double sumSignal = iterator->getSignal();
double sumSqError = iterator->getError();
......
......@@ -82,7 +82,7 @@ public:
}
void test_smooth_hat_function()
void test_smooth_hat_function_3_pix_width()
{
auto toSmooth = MDEventsTestHelper::makeFakeMDHistoWorkspace(1 /*signal*/, 2 /*numDims*/, 3 /*numBins in each dimension*/);
toSmooth->setSignalAt(4, 2.0);
......@@ -116,8 +116,67 @@ public:
TS_ASSERT_EQUALS(5.0/4, out->getSignalAt(0));
TS_ASSERT_EQUALS(7.0/6, out->getSignalAt(1));
TS_ASSERT_EQUALS(10.0/9, out->getSignalAt(4));
}
void test_smooth_hat_function_5_pix_width()
{
auto toSmooth = MDEventsTestHelper::makeFakeMDHistoWorkspace(1 /*signal*/, 2 /*numDims*/, 5 /*numBins in each dimension*/);
toSmooth->setSignalAt(12, 4.0);
/*
2D MDHistoWorkspace Input
1 - 1 - 1 - 1 - 1
1 - 1 - 1 - 1 - 1
1 - 1 - 4 - 1 - 1
1 - 1 - 1 - 1 - 1
1 - 1 - 1 - 1 - 1
*/
SmoothMD alg;
alg.setChild(true);
alg.initialize();
std::vector<int> widthVector(1, 5); // Smooth with width == 5
alg.setProperty("WidthVector", widthVector);
alg.setProperty("InputWorkspace", toSmooth);
alg.setPropertyValue("OutputWorkspace", "dummy");
alg.execute();
IMDHistoWorkspace_sptr out = alg.getProperty("OutputWorkspace");
/*
2D MDHistoWorkspace Expected
key:
x = 12/9
y = 18/15
z = 28/25
` = ignore
x - ` - y - ` - x
` - ` - ` - ` - `
y - ` - z - ` - y
` - ` - ` - ` - `
x - ` - y - ` - x
*/
// Check vertexes
double x = 12.0/9;
TS_ASSERT_EQUALS(x, out->getSignalAt(0));
TS_ASSERT_EQUALS(x, out->getSignalAt(4));
TS_ASSERT_EQUALS(x, out->getSignalAt(20));
TS_ASSERT_EQUALS(x, out->getSignalAt(24));
// Check edges
double y = 18.0/15;
TS_ASSERT_EQUALS(y, out->getSignalAt(2));
TS_ASSERT_EQUALS(y, out->getSignalAt(10));
TS_ASSERT_EQUALS(y, out->getSignalAt(14));
TS_ASSERT_EQUALS(y, out->getSignalAt(22));
// Check centre
double z = 28.0/25;
TS_ASSERT_EQUALS(z, out->getSignalAt(12));
}
......
......@@ -10,7 +10,7 @@
Description
-----------
TODO: Enter a full rst-markup description of your algorithm here.
Provides smoothing of :ref:`MDHistoWorkspaces <MDHistoWorkspace>`__ in n-dimensions. The WidthVector relates to the number of pixels to include in the width for each dimension. *WidthVector* **must contain entries that are odd numbers**.
Usage
......
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