diff --git a/Framework/MDAlgorithms/CMakeLists.txt b/Framework/MDAlgorithms/CMakeLists.txt index f3e9e4d04a2db2271f828af463f363f2364f2462..8725b21a5ce0ae0f8beeca48f7506a054beffeb4 100644 --- a/Framework/MDAlgorithms/CMakeLists.txt +++ b/Framework/MDAlgorithms/CMakeLists.txt @@ -12,6 +12,7 @@ set ( SRC_FILES src/CentroidPeaksMD.cpp src/CentroidPeaksMD2.cpp src/CloneMDWorkspace.cpp + src/CompactMD.cpp src/CompareMDWorkspaces.cpp src/ConvToMDBase.cpp src/ConvToMDEventsWS.cpp @@ -136,6 +137,7 @@ set ( INC_FILES inc/MantidMDAlgorithms/CentroidPeaksMD2.h inc/MantidMDAlgorithms/CloneMDWorkspace.h inc/MantidMDAlgorithms/CompareMDWorkspaces.h + inc/MantidMDAlgorithms/CompactMD.h inc/MantidMDAlgorithms/ConvToMDBase.h inc/MantidMDAlgorithms/ConvertCWPDMDToSpectra.h inc/MantidMDAlgorithms/ConvertCWSDExpToMomentum.h @@ -257,6 +259,7 @@ set ( TEST_FILES CentroidPeaksMDTest.h CloneMDWorkspaceTest.h CompareMDWorkspacesTest.h + CompactMDTest.h ConvertCWPDMDToSpectraTest.h ConvertCWSDExpToMomentumTest.h ConvertCWSDMDtoHKLTest.h diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CompactMD.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CompactMD.h new file mode 100644 index 0000000000000000000000000000000000000000..c206f73b5409e0178a836f0d32a3a30d67014c16 --- /dev/null +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/CompactMD.h @@ -0,0 +1,65 @@ +#ifndef MANTID_MDALGORITHMS_COMPACTMD_H_ +#define MANTID_MDALGORITHMS_COMPACTMD_H_ + +/** An algorithm used to crop an MDHistoWorkspace based on the first + non-zero signals found in each dimension. + + @author Matt King + @date 02-10-2015 + + Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + 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> +*/ + +#include "MantidAPI/IMDHistoWorkspace.h" +#include "MantidDataObjects/MDHistoWorkspace.h" +#include "MantidMDAlgorithms/CutMD.h" +#include "MantidAPI/Algorithm.h" +#include "boost/shared_ptr.hpp" +namespace Mantid { +namespace MDAlgorithms { +class DLLExport CompactMD : public API::Algorithm { +public: + CompactMD(){}; + ~CompactMD(){}; + + virtual void init(); + virtual void exec(); + /// Algorithm's name for identification + const std::string name() const { return "CompactMD"; } + /// Summary of algorithms purpose + const std::string summary() const { + return "Crops an MDHistoWorkspace based on the first non-zero signals " + "giving a more focussed area of interest."; + } + const std::string category() const { return "MDAlgorithms"; } + /// Algorithm's version for identification + int version() const { return 1; } + /// Finding the extents of the first non-zero signals. + void + findFirstNonZeroMinMaxExtents(Mantid::API::IMDHistoWorkspace_sptr inputWs, + std::vector<Mantid::coord_t> &minVec, + std::vector<Mantid::coord_t> &maxVec); +}; +} +} + +#endif // MANTID_MDALGORITHMS_COMPACTMD_H_ \ No newline at end of file diff --git a/Framework/MDAlgorithms/src/CompactMD.cpp b/Framework/MDAlgorithms/src/CompactMD.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c815d5277ff64361e8487fe54f330c038b1f0bd --- /dev/null +++ b/Framework/MDAlgorithms/src/CompactMD.cpp @@ -0,0 +1,140 @@ +#include "MantidMDAlgorithms/CompactMD.h" +#include "MantidAPI/IMDIterator.h" +using namespace Mantid::API; +using namespace Mantid::Geometry; +using namespace Mantid::Kernel; + +namespace { +/** + * helper method to create a string from min and max extents (with non-zero + * signals) ready to be used as the PBins for IntegrateMDHistoWorkspace + * algorithm in + * exec + * @param minVector : Vector containing the minimum extents that we will crop + * to. + * @param maxVector : Vector containing the maximum extents that we will crop + * to. + * @param inputWs : Used in the calculation from centre to bin edges + * @return : a string vector of binning parameters for IntegrateMDHistoWorkspace + * to take as input. +*/ +std::vector<std::string> +createPBinStringVector(std::vector<Mantid::coord_t> minVector, + std::vector<Mantid::coord_t> maxVector, + IMDHistoWorkspace_sptr inputWs) { + size_t numDims = inputWs->getNumDims(); + std::vector<std::string> pBinStrVector; + for (size_t iter = 0; iter < numDims; iter++) { + if (minVector[iter] >= maxVector[iter]) { + std::cerr << "Minimum extent of non-zero signal must be LESS than the " + "maximum extent with non-zero signal" << std::endl; + } + // creating pbin string using Min and Max Centre positions + auto pBinStr = boost::lexical_cast<std::string>( + minVector[iter] - + (inputWs->getDimension(iter)->getBinWidth() * 0.5)) + + ",0," + + boost::lexical_cast<std::string>( + maxVector[iter] + + (inputWs->getDimension(iter)->getBinWidth() * 0.5)); + pBinStrVector.push_back(pBinStr); + } + return pBinStrVector; +} +} + +namespace Mantid { +namespace MDAlgorithms { + +DECLARE_ALGORITHM(CompactMD) + +/** +* Finding the centre points of Bins with non-zero signal values +* we then compare this centre to minimum and maximum centres we have +* to get the minimum and maximum extents of the workspace that has non-zero +* signal values in the Bins. +* @param inputWs : The workspace that will be iterated over to find the extents. +* @param minVec : Vector used to stored the minimum extent in each dimension +* @param maxVec : Vector used to stored the maximum extents in each dimension +*/ + +void CompactMD::findFirstNonZeroMinMaxExtents( + IMDHistoWorkspace_sptr inputWs, std::vector<Mantid::coord_t> &minVec, + std::vector<Mantid::coord_t> &maxVec) { + auto ws_iter = inputWs->createIterator(); + do { + if (ws_iter->getSignal() == 0) { + // if signal is 0 then go to next index + continue; + } else { + // we have found a non-zero signal we need to compare + // the position of the bin with our Min and Max values + auto current_index = ws_iter->getLinearIndex(); + auto current_center = inputWs->getCenter(current_index); + for (size_t index = 0; index < inputWs->getNumDims(); index++) { + if (current_center[index] > maxVec[index]) { + // set new maximum + maxVec[index] = current_center[index]; + } + if (current_center[index] < minVec[index]) { + // set new minimum + minVec[index] = current_center[index]; + } + } + } + } while (ws_iter->next()); +} + +/** +* Initiliase the algorithm's properties. +*/ +void CompactMD::init() { + // input workspace to compact + declareProperty(new WorkspaceProperty<IMDHistoWorkspace>("InputWorkspace", "", + Direction::Input), + "MDHistoWorkspace to compact"); + // output workspace that will have been compacted + declareProperty(new WorkspaceProperty<IMDHistoWorkspace>( + "OutputWorkspace", "", Direction::Output), + "Output compacted workspace"); +} +/** +* Execute the algorithm. +*/ +void CompactMD::exec() { + const IMDHistoWorkspace_sptr input_ws = this->getProperty("InputWorkspace"); + IMDWorkspace_sptr out_ws; + + const size_t nDimensions = input_ws->getNumDims(); + std::vector<Mantid::coord_t> minVector; + std::vector<Mantid::coord_t> maxVector; + + // fill the min/max vectors with values per dimension. + for (size_t index = 0; index < nDimensions; index++) { + minVector.push_back(input_ws->getDimension(index)->getMaximum()); + maxVector.push_back(input_ws->getDimension(index)->getMinimum()); + } + // start our search for the first non-zero signal index. + findFirstNonZeroMinMaxExtents(input_ws, minVector, maxVector); + auto pBinStrings = createPBinStringVector(minVector, maxVector, input_ws); + // creating IntegrateMDHistoWorkspace algorithm to crop our workspace. + auto cut_alg = this->createChildAlgorithm("IntegrateMDHistoWorkspace"); + cut_alg->setProperty("InputWorkspace", input_ws); + cut_alg->setProperty("OutputWorkspace", "temp"); + // setting property PxBin depending on the number of dimensions the + // input workspace has. + for (size_t iter = 0; iter < input_ws->getNumDims(); iter++) { + std::string propertyString = + "P" + boost::lexical_cast<std::string>(iter + 1) + "Bin"; + cut_alg->setProperty(propertyString, pBinStrings[iter]); + } + cut_alg->execute(); + + // retrieve the output workspace from IntegrateMDHistoWorkspace + IMDHistoWorkspace_sptr temp = cut_alg->getProperty("OutputWorkspace"); + out_ws = temp; + // set output workspace of CompactMD to output of IntegrateMDHistoWorkspace + this->setProperty("OutputWorkspace", out_ws); +} +} +} \ No newline at end of file diff --git a/Framework/MDAlgorithms/src/IntegrateMDHistoWorkspace.cpp b/Framework/MDAlgorithms/src/IntegrateMDHistoWorkspace.cpp index 1468a6001c3194cd40433439827f19207efa27ae..ee80f5f9e527c13dde9b8612a768c4c3cde20b58 100644 --- a/Framework/MDAlgorithms/src/IntegrateMDHistoWorkspace.cpp +++ b/Framework/MDAlgorithms/src/IntegrateMDHistoWorkspace.cpp @@ -104,7 +104,7 @@ Mantid::coord_t getPrecisionCorrectedCoordinate(Mantid::coord_t position, // Check if the relative deviation is larger than 1e-6 const auto deviation = fabs((nearest - position) / binWidth); - const auto tolerance = 1e-6; + const auto tolerance = 1e-5; Mantid::coord_t coordinate(position); if (deviation < tolerance) { coordinate = nearest; @@ -195,6 +195,7 @@ MDHistoWorkspace_sptr createShapedOutput(IMDHistoWorkspace const *const inWS, binning.back()) /*max*/); // Set custom min, max and nbins. } else if (i < pbins.size() && similarBinning(pbins[i])) { auto binning = pbins[i]; + Mantid::coord_t pMin = static_cast<Mantid::coord_t>(binning.front()); Mantid::coord_t pMax = static_cast<Mantid::coord_t>(binning.back()); size_t numberOfBins; diff --git a/Framework/MDAlgorithms/test/CompactMDTest.h b/Framework/MDAlgorithms/test/CompactMDTest.h new file mode 100644 index 0000000000000000000000000000000000000000..2629ac5f2f70ecac62b99e666ce107a88a3692b9 --- /dev/null +++ b/Framework/MDAlgorithms/test/CompactMDTest.h @@ -0,0 +1,274 @@ +#ifndef MANTID_MDALGORITHMS_COMPACTMDTEST_H_ +#define MANTID_MDALGORITHMS_COMPACTMDTEST_H_ +#include <cxxtest/TestSuite.h> + +#include "MantidMDAlgorithms/CompactMD.h" +#include "MantidDataObjects/MDHistoWorkspace.h" +#include "MantidTestHelpers/MDEventsTestHelper.h" + +using Mantid::MDAlgorithms::CompactMD; +using namespace Mantid::API; + +//================== +// Functional Tests +//================== +class CompactMDTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static CompactMDTest *createSuite() { return new CompactMDTest(); } + static void destroySuite(CompactMDTest *suite) { delete suite; } + + void test_Init() { + CompactMD alg; + TSM_ASSERT_THROWS_NOTHING("Instance of CompactMD threw: ", + alg.initialize()); + TSM_ASSERT("Instance of CompactMD was not initialised: ", + alg.isInitialized()); + } + void + test_all_non_zero_signals_are_kept_with_data_concentrated_in_the_centre() { + /* + *testing the effectiveness of CompactMD when the data looks like this: + *------------------ + * Input structure: + *------------------ + * ------------- + * | |///| | + * ------------- + * -3-2-1 0 1 2 3 + *--------------------------- + * Expected output structure: + *---------------------------- + * should trim until the first non-zero value. + * ----- + * |///| + * ----- + * -1 0 1 + */ + + using namespace Mantid::DataObjects; + const size_t numDims = 1; + const double signal = 0.0; + const double errorSquared = 1.3; + size_t numBins[static_cast<int>(numDims)] = {3}; + Mantid::coord_t min[static_cast<int>(numDims)] = {-3}; + Mantid::coord_t max[static_cast<int>(numDims)] = {3}; + const std::string name("test"); + auto inWS = MDEventsTestHelper::makeFakeMDHistoWorkspaceGeneral( + numDims, signal, errorSquared, numBins, min, max, name); + inWS->setSignalAt(1, 1.0); // set middle bin signal to one + CompactMD alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("InputWorkspace", inWS); + alg.setProperty("OutputWorkspace", "out"); + alg.execute(); + // output workspace should be cropped so extents ~ [-1,1] + IMDHistoWorkspace_sptr outputWorkspace = alg.getProperty("OutputWorkspace"); + TSM_ASSERT_EQUALS("Should have a signal of 1.0: ", + outputWorkspace->getSignalAt(0), 1); + TSM_ASSERT_EQUALS("Minimum should be cropped to -1: ", + outputWorkspace->getDimension(0)->getMinimum(), -1.0); + TSM_ASSERT_EQUALS("Maximum should be cropped to 1: ", + outputWorkspace->getDimension(0)->getMaximum(), 1.0); + TSM_ASSERT_EQUALS("Number of Bins should be 1 : ", + outputWorkspace->getDimension(0)->getNBins(), 1.0); + TSM_ASSERT_EQUALS("Bin width should be consistent: ", + outputWorkspace->getDimension(0)->getBinWidth(), + inWS->getDimension(0)->getBinWidth()); + } + void test_all_non_zero_signals_are_kept_with_data_in_each_corner() { + /* + *testing the effectiveness of CompactMD when the data looks like this: + *----------------------------------- + * Input structure: 2D HistoWorkspace + *----------------------------------- + * ------------- -3 + * |/a/| |/b/| -2 + * ------------- -1 + * | | | | 0 + * ------------- 1 + * |/c/| |/d/| 2 + * ------------- 3 + * -3-2-1 0 1 2 3 + *---------------------------- + * Expected output structure: + *---------------------------- + * should not trim the workspace at all. + * ------------- -3 + * |/a/| |/b/| -2 + * ------------- -1 + * | | | | 0 + * ------------- 1 + * |/c/| |/d/| 2 + * ------------- 3 + * -3-2-1 0 1 2 3 + */ + using namespace Mantid::DataObjects; + const size_t numDims = 2; + const double signal = 0.0; + const double errorSquared = 1.2; + size_t numBins[static_cast<int>(numDims)] = {3, 3}; + Mantid::coord_t min[static_cast<int>(numDims)] = {-3, -3}; + Mantid::coord_t max[static_cast<int>(numDims)] = {3, 3}; + const std::string name("test"); + auto inWS = MDEventsTestHelper::makeFakeMDHistoWorkspaceGeneral( + numDims, signal, errorSquared, numBins, min, max, name); + inWS->setSignalAt(0, 1.0); // cell a + inWS->setSignalAt(2, 1.0); // cell b + inWS->setSignalAt(6, 1.0); // cell c + inWS->setSignalAt(8, 1.0); // cell d + + CompactMD alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("InputWorkspace", inWS); + alg.setProperty("OutputWorkspace", "out"); + alg.execute(); + IMDHistoWorkspace_sptr outputWorkspace = alg.getProperty("OutputWorkspace"); + /*TSM_ASSERT_EQUALS("Should have a signal of 1.0: ", + outputWorkspace->getSignalAt(0), 1); + TSM_ASSERT_EQUALS("Should have a signal of 1.0: ", + outputWorkspace->getSignalAt(2), 1); + TSM_ASSERT_EQUALS("Should have a signal of 1.0: ", + outputWorkspace->getSignalAt(6), 1); + TSM_ASSERT_EQUALS("Should have a signal of 1.0: ", + outputWorkspace->getSignalAt(8), 1); + TSM_ASSERT_EQUALS("Minimum for dim 0 should be consistent: ", + outputWorkspace->getDimension(0)->getMinimum(), + inWS->getDimension(0)->getMinimum()); + TSM_ASSERT_EQUALS("Maximum for dim 0 should be consistent: ", + outputWorkspace->getDimension(0)->getMaximum(), + inWS->getDimension(0)->getMaximum()); + TSM_ASSERT_EQUALS("Minimum for dim 1 should be consistent:", + outputWorkspace->getDimension(1)->getMinimum(), + inWS->getDimension(1)->getMinimum()); + TSM_ASSERT_EQUALS("Maximum for dim 1 should be consistent: ", + outputWorkspace->getDimension(1)->getMaximum(), + inWS->getDimension(1)->getMaximum()); + TSM_ASSERT_EQUALS("Number of Bins for dim 0 should be consistent : ", + outputWorkspace->getDimension(0)->getNBins(), + inWS->getDimension(0)->getNBins()); + TSM_ASSERT_EQUALS("Number of Bins for dim 1 should be consistent : ", + outputWorkspace->getDimension(1)->getNBins(), + inWS->getDimension(1)->getNBins()); + TSM_ASSERT_EQUALS("Bin width for dim 0 should be consistent: ", + outputWorkspace->getDimension(0)->getBinWidth(), + inWS->getDimension(0)->getBinWidth()); + TSM_ASSERT_EQUALS("Bin width for dim 1 should be consistent: ", + outputWorkspace->getDimension(1)->getBinWidth(), + inWS->getDimension(1)->getBinWidth());*/ + } + + void + test_all_non_zero_signals_are_kept_when_data_is_concentrated_in_one_half_of_the_workspace() { + /* + *testing the effectiveness of CompactMD when the data looks like this: + *------------------ + * Input structure: + *------------------ + * ------------- + * |///| | | + * ------------- + * -3-2-1 0 1 2 3 + *--------------------------- + * Expected output structure: + *---------------------------- + * should trim until the first non-zero value. + * ----- + * |///| + * ----- + * 1 2 3 + */ + + using namespace Mantid::DataObjects; + const size_t numDims = 1; + const double signal = 0.0; + const double errorSquared = 1.3; + size_t numBins[static_cast<int>(numDims)] = {3}; + Mantid::coord_t min[static_cast<int>(numDims)] = {-3}; + Mantid::coord_t max[static_cast<int>(numDims)] = {3}; + const std::string name("test"); + auto inWS = MDEventsTestHelper::makeFakeMDHistoWorkspaceGeneral( + numDims, signal, errorSquared, numBins, min, max, name); + inWS->setSignalAt(0, 1.0); // set right-most bin signal to one + CompactMD alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("InputWorkspace", inWS); + alg.setProperty("OutputWorkspace", "out"); + TS_ASSERT_THROWS_NOTHING(alg.execute()); + IMDHistoWorkspace_sptr outputWorkspace = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWorkspace); + TSM_ASSERT_EQUALS("Should have a signal of 1.0: ", + outputWorkspace->getSignalAt(0), 1); + TSM_ASSERT_EQUALS("Minimum should be cut to 1: ", + outputWorkspace->getDimension(0)->getMinimum(), -3.0); + TSM_ASSERT_EQUALS("Maximum should still be 3: ", + outputWorkspace->getDimension(0)->getMaximum(), -1.0); + TSM_ASSERT_EQUALS("Number of Bins should be 1 : ", + outputWorkspace->getDimension(0)->getNBins(), 1); + TSM_ASSERT_EQUALS("Bin width should be consistent: ", + outputWorkspace->getDimension(0)->getBinWidth(), + inWS->getDimension(0)->getBinWidth()); + } + void test_compact_md_throws_when_loading_empty_workspace() { + using namespace Mantid::DataObjects; + const size_t numDims = 1; + const double signal = 0.0; + const double errorSquared = 1.3; + size_t numBins[static_cast<int>(numDims)] = {3}; + Mantid::coord_t min[static_cast<int>(numDims)] = {-3}; + Mantid::coord_t max[static_cast<int>(numDims)] = {3}; + const std::string name("test"); + auto inWS = MDEventsTestHelper::makeFakeMDHistoWorkspaceGeneral( + numDims, signal, errorSquared, numBins, min, max, name); + CompactMD alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("InputWorkspace", inWS); + alg.setProperty("OutputWorkspace", "out"); + TS_ASSERT_THROWS(alg.execute(), std::runtime_error &); + } +}; +//=================== +// Performance Tests +//=================== +using namespace Mantid::DataObjects; +class CompactMDTestPerformance : public CxxTest::TestSuite { + +private: + MDHistoWorkspace_sptr m_ws; + +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static CompactMDTestPerformance *createSuite() { + return new CompactMDTestPerformance(); + } + static void destroySuite(CompactMDTestPerformance *suite) { delete suite; } + + CompactMDTestPerformance() { + // Create a 4D workspace. + m_ws = MDEventsTestHelper::makeFakeMDHistoWorkspace( + 1.0 /*signal*/, 4 /*nd*/, 100 /*nbins*/, 10 /*max*/, 1.0 /*error sq*/); + } + void test_execute_4d() { + CompactMD alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("InputWorkspace", m_ws); + alg.setProperty("OutputWorkspace", "out"); + alg.execute(); + IMDHistoWorkspace_sptr outWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outWS); + } +}; + +#endif // !MANTID_MDALGORITHMS_COMPACTMDTEST_H_ diff --git a/docs/source/algorithms/CompactMD-v1.rst b/docs/source/algorithms/CompactMD-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..388f9ca7a084c437305608994667507b9665158f --- /dev/null +++ b/docs/source/algorithms/CompactMD-v1.rst @@ -0,0 +1,62 @@ +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- +Used to crop an n-dimensional :ref:`MDHistoWorkspace <MDHistoWorkspace>` to the first non-zero signal values found in all dimensions. + +Cropping +-------- +The cropping is done by supplying `IntegrateMDHistoWorkspace <http://docs.mantidproject.org/nightly/algorithms/IntegrateMDHistoWorkspace-v1.html>`__ with the minimum and maximum extents associated with the first non-zero +signal values in the workspace. + + +Usage +----- + + +**Example - CompactMD on MDHistoWorkspace** + +.. testcode:: CompactMDOnMDHistoWorkspace + + import math + #create an MDEventWorkspace for Rebinning + mdws = CreateMDWorkspace(Dimensions=3, Extents='-10,10,-10,10,-10,10', Names='A,B,C', Units='U,U,U') + FakeMDEventData(InputWorkspace=mdws, PeakParams='100000,-5,-5,0,1') + FakeMDEventData(InputWorkspace=mdws, PeakParams='100000,0,0,0,1') + FakeMDEventData(InputWorkspace=mdws, PeakParams='100000,5,5,0,1') + #Rebin mdws to create an MDHistoWorkspace + binned_ws = BinMD(InputWorkspace=mdws, AxisAligned=False, BasisVector0='a,unit,1,1,0',BasisVector1='b,unit,-1,1,0',BasisVector2='c,unit,0,0,1',NormalizeBasisVectors=True,Translation=[-10,-10,0], OutputExtents=[0,math.sqrt(2*20*20),-2,2,-10,10], OutputBins=[100, 100, 1] ) + + #A visualisation of the rebinned_ws can be found in the 'Input' section below. + + #run CompactMD on the rebinned workspace + compact_output = CompactMD(binned_ws) + + #A visualisation of the compacted workspace can be found in the 'Output' section below. + +Input: + +.. figure:: /images/RebbinedWorkspaceNoCompactMDApplied.jpg + :alt: RebbinedWorkspaceNoCompactMDApplied.jpg + :width: 400px + :align: center + + +Output: + +.. figure:: /images/RebbinedWorkspaceWithCompactMDApplied.jpg + :alt: RebbinedWorkspaceWithCompactMDApplied.jpg + :width: 400px + :align: center + + + +.. categories:: + +.. sourcelink:: \ No newline at end of file diff --git a/docs/source/images/RebbinedWorkspaceNoCompactMDApplied.JPG b/docs/source/images/RebbinedWorkspaceNoCompactMDApplied.JPG new file mode 100644 index 0000000000000000000000000000000000000000..977b23d832c1c10900d09d518dd9e1745776aa92 Binary files /dev/null and b/docs/source/images/RebbinedWorkspaceNoCompactMDApplied.JPG differ diff --git a/docs/source/images/RebbinedWorkspaceWithCompactMDApplied.JPG b/docs/source/images/RebbinedWorkspaceWithCompactMDApplied.JPG new file mode 100644 index 0000000000000000000000000000000000000000..36a4fbc0a412fce0fbb71bd17b3e0c75414ebce4 Binary files /dev/null and b/docs/source/images/RebbinedWorkspaceWithCompactMDApplied.JPG differ