From 2adc86b56c93149e81dd650b7e4b893d3abd09cf Mon Sep 17 00:00:00 2001 From: Verena Reimund <reimund@ill.eu> Date: Tue, 24 Apr 2018 11:46:27 +0200 Subject: [PATCH] Workaround Multiply (for scaling) which does not propage Dx - new method scaleWorkspace which reinserts Dx values for point data - deleted MantidDataObjects/WorkspaceSingleValue.h from Multiply and Divide - introduced new class variables m_scaleFactor and m_errorScaleFactor; those values will now be initialised by 1.0 (the default value) and not 0.0 as before. - deleted unused tool-tip texts (Optional.) - ConjoinXRuns output workspace property is a Workspace and not a MatrixWorkspace -> dynamic pointer cast - unit tests for histograms pass - MantidPlot executes for point data example from unit test - unit test for point data fails (SortXAxis, Python algorithm, not registered!) Refs #22197 --- .../inc/MantidAlgorithms/Stitch1D.h | 17 +- Framework/Algorithms/src/Divide.cpp | 1 - Framework/Algorithms/src/Multiply.cpp | 1 - Framework/Algorithms/src/Stitch1D.cpp | 269 ++++++++++-------- Framework/Algorithms/test/Stitch1DTest.h | 53 ++-- docs/source/release/v3.13.0/framework.rst | 8 +- 6 files changed, 198 insertions(+), 151 deletions(-) diff --git a/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h b/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h index 30b3c669624..16623ba3089 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h @@ -2,6 +2,7 @@ #define MANTID_ALGORITHMS_STITCH1D_H_ #include "MantidAPI/Algorithm.h" +#include "MantidAPI/MatrixWorkspace_fwd.h" #include <boost/tuple/tuple.hpp> @@ -103,14 +104,22 @@ private: void reinsertSpecialValues(Mantid::API::MatrixWorkspace_sptr ws); /// Range tolerance static const double range_tolerance; - /// Index per workspace spectra of Nans - SpecialTypeIndexes m_nanYIndexes; - /// Index per workspace spectra of Infs - SpecialTypeIndexes m_infYIndexes; + /// Scaling factors + double m_scaleFactor; + double m_errorScaleFactor; + /// Scale workspace (left hand side or right hand side) + void scaleWorkspace(Mantid::API::MatrixWorkspace_sptr ws, + API::MatrixWorkspace_sptr divident, + API::MatrixWorkspace_sptr divisor, + Mantid::API::MatrixWorkspace_sptr dxWS); /// Index per workspace spectra of Nans SpecialTypeIndexes m_nanEIndexes; + SpecialTypeIndexes m_nanYIndexes; + SpecialTypeIndexes m_nanDxIndexes; /// Index per workspace spectra of Infs SpecialTypeIndexes m_infEIndexes; + SpecialTypeIndexes m_infYIndexes; + SpecialTypeIndexes m_infDxIndexes; }; } // namespace Algorithms diff --git a/Framework/Algorithms/src/Divide.cpp b/Framework/Algorithms/src/Divide.cpp index bb2c5fd000a..607a4fdfdfe 100644 --- a/Framework/Algorithms/src/Divide.cpp +++ b/Framework/Algorithms/src/Divide.cpp @@ -2,7 +2,6 @@ // Includes //---------------------------------------------------------------------- #include "MantidAlgorithms/Divide.h" -#include "MantidDataObjects/WorkspaceSingleValue.h" using namespace Mantid::API; using namespace Mantid::Kernel; diff --git a/Framework/Algorithms/src/Multiply.cpp b/Framework/Algorithms/src/Multiply.cpp index c3761ed2ea0..86f1d58bcfa 100644 --- a/Framework/Algorithms/src/Multiply.cpp +++ b/Framework/Algorithms/src/Multiply.cpp @@ -2,7 +2,6 @@ //---------------------------------------------------------------------- //---------------------------------------------------------------------- #include "MantidAlgorithms/Multiply.h" -#include "MantidDataObjects/WorkspaceSingleValue.h" using namespace Mantid::API; using namespace Mantid::Kernel; diff --git a/Framework/Algorithms/src/Stitch1D.cpp b/Framework/Algorithms/src/Stitch1D.cpp index 45a42a7540f..69fdbf660fb 100644 --- a/Framework/Algorithms/src/Stitch1D.cpp +++ b/Framework/Algorithms/src/Stitch1D.cpp @@ -1,8 +1,8 @@ #include "MantidAlgorithms/Stitch1D.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/WorkspaceProperty.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" +#include "MantidAPI/WorkspaceProperty.h" #include "MantidHistogramData/HistogramE.h" #include "MantidHistogramData/HistogramX.h" #include "MantidHistogramData/HistogramY.h" @@ -84,8 +84,7 @@ MatrixWorkspace_sptr Stitch1D::maskAllBut(int a1, int a2, } /** Mask out data in the region between a1 and a2 with zeros. Operation - * performed - * on the original workspace + * performed on the original workspace * @param a1 : start position in X * @param a2 : end position in X * @param source : Workspace to mask. @@ -126,10 +125,10 @@ void Stitch1D::init() { "Output stitched workspace."); declareProperty(make_unique<PropertyWithValue<double>>( "StartOverlap", Mantid::EMPTY_DBL(), Direction::Input), - "Start overlap x-value in units of x-axis. Optional."); + "Start overlap x-value in units of x-axis."); declareProperty(make_unique<PropertyWithValue<double>>( "EndOverlap", Mantid::EMPTY_DBL(), Direction::Input), - "End overlap x-value in units of x-axis. Optional."); + "End overlap x-value in units of x-axis."); declareProperty(make_unique<ArrayProperty<double>>( "Params", boost::make_shared<RebinParamsValidator>(true)), "Rebinning Parameters. See Rebin for format. If only a " @@ -149,7 +148,7 @@ void Stitch1D::init() { declareProperty(make_unique<PropertyWithValue<double>>( "ManualScaleFactor", 1.0, manualScaleFactorValidator, Direction::Input), - "Provided value for the scale factor. Optional."); + "Provided value for the scale factor."); declareProperty(make_unique<PropertyWithValue<double>>( "OutScaleFactor", Mantid::EMPTY_DBL(), Direction::Output), "The actual used value for the scaling factor."); @@ -310,17 +309,16 @@ MatrixWorkspace_sptr Stitch1D::rebin(MatrixWorkspace_sptr &input, PARALLEL_FOR_IF(Kernel::threadSafe(*outWS)) for (int i = 0; i < histogramCount; ++i) { PARALLEL_START_INTERUPT_REGION - std::vector<size_t> &nanYIndexes = m_nanYIndexes[i]; std::vector<size_t> &nanEIndexes = m_nanEIndexes[i]; - std::vector<size_t> &infYIndexes = m_infYIndexes[i]; + std::vector<size_t> &nanYIndexes = m_nanYIndexes[i]; std::vector<size_t> &infEIndexes = m_infEIndexes[i]; + std::vector<size_t> &infYIndexes = m_infYIndexes[i]; // Copy over the data auto &sourceY = outWS->mutableY(i); auto &sourceE = outWS->mutableE(i); for (size_t j = 0; j < sourceY.size(); ++j) { const double &value = sourceY[j]; - const double &eValue = sourceE[j]; if (std::isnan(value)) { nanYIndexes.push_back(j); sourceY[j] = 0; @@ -329,6 +327,7 @@ MatrixWorkspace_sptr Stitch1D::rebin(MatrixWorkspace_sptr &input, sourceY[j] = 0; } + const double &eValue = sourceE[j]; if (std::isnan(eValue)) { nanEIndexes.push_back(j); sourceE[j] = 0; @@ -355,6 +354,7 @@ MatrixWorkspace_sptr Stitch1D::integration(MatrixWorkspace_sptr &input, const double &start, const double &stop) { auto integration = this->createChildAlgorithm("Integration"); + integration->initialize(); integration->setProperty("InputWorkspace", input); integration->setProperty("RangeLower", start); integration->setProperty("RangeUpper", stop); @@ -363,8 +363,7 @@ MatrixWorkspace_sptr Stitch1D::integration(MatrixWorkspace_sptr &input, g_log.information("Integration RangeUpper: " + boost::lexical_cast<std::string>(stop)); integration->execute(); - MatrixWorkspace_sptr outWS = integration->getProperty("OutputWorkspace"); - return outWS; + return integration->getProperty("OutputWorkspace"); } /** Runs the WeightedMean Algorithm as a child @@ -375,11 +374,11 @@ MatrixWorkspace_sptr Stitch1D::integration(MatrixWorkspace_sptr &input, MatrixWorkspace_sptr Stitch1D::weightedMean(MatrixWorkspace_sptr &inOne, MatrixWorkspace_sptr &inTwo) { auto weightedMean = this->createChildAlgorithm("WeightedMean"); + weightedMean->initialize(); weightedMean->setProperty("InputWorkspace1", inOne); weightedMean->setProperty("InputWorkspace2", inTwo); weightedMean->execute(); - MatrixWorkspace_sptr outWS = weightedMean->getProperty("OutputWorkspace"); - return outWS; + return weightedMean->getProperty("OutputWorkspace"); } /** Runs the ConjoinXRuns Algorithm as a child @@ -393,12 +392,13 @@ MatrixWorkspace_sptr Stitch1D::conjoinXAxis(MatrixWorkspace_sptr &inOne, Mantid::API::AnalysisDataService::Instance().addOrReplace(in1, inOne); Mantid::API::AnalysisDataService::Instance().addOrReplace(in2, inTwo); auto conjoinX = this->createChildAlgorithm("ConjoinXRuns"); - conjoinX->setProperty("InputWorkspace", std::vector<std::string>{in1, in2}); + conjoinX->initialize(); + conjoinX->setProperty("InputWorkspaces", std::vector<std::string>{in1, in2}); conjoinX->execute(); - MatrixWorkspace_sptr outWS = conjoinX->getProperty("OutputWorkspace"); Mantid::API::AnalysisDataService::Instance().remove(in1); Mantid::API::AnalysisDataService::Instance().remove(in2); - return outWS; + API::Workspace_sptr ws = conjoinX->getProperty("OutputWorkspace"); + return boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(ws); } /** Runs the SortXAxis Algorithm as a child @@ -407,10 +407,11 @@ MatrixWorkspace_sptr Stitch1D::conjoinXAxis(MatrixWorkspace_sptr &inOne, */ MatrixWorkspace_sptr Stitch1D::sortXAxis(MatrixWorkspace_sptr &inWS) { auto sortX = this->createChildAlgorithm("SortXAxis"); + sortX->setChild(true); + sortX->initialize(); sortX->setProperty("InputWorkspace", inWS); sortX->execute(); - MatrixWorkspace_sptr outWS = sortX->getProperty("OutputWorkspace"); - return outWS; + return sortX->getProperty("OutputWorkspace"); } /** Runs the CreateSingleValuedWorkspace Algorithm as a child @@ -420,10 +421,10 @@ MatrixWorkspace_sptr Stitch1D::sortXAxis(MatrixWorkspace_sptr &inWS) { MatrixWorkspace_sptr Stitch1D::singleValueWS(double val) { auto singleValueWS = this->createChildAlgorithm("CreateSingleValuedWorkspace"); + singleValueWS->initialize(); singleValueWS->setProperty("DataValue", val); singleValueWS->execute(); - MatrixWorkspace_sptr outWS = singleValueWS->getProperty("OutputWorkspace"); - return outWS; + return singleValueWS->getProperty("OutputWorkspace"); } /** Finds the bins containing the ends of the overlapping region @@ -474,123 +475,151 @@ bool Stitch1D::hasNonzeroErrors(MatrixWorkspace_sptr ws) { return hasNonZeroErrors; } +/** + * @brief scaleWorkspace will set m_scaleFactor and m_errorScaleFactor + * @param ws :: Input workspace + * @param divident + * @param divisor + * @param dxWS :: A MatrixWorkspace (size of ws) containing Dx values + */ +void Stitch1D::scaleWorkspace(MatrixWorkspace_sptr ws, + MatrixWorkspace_sptr divident, + MatrixWorkspace_sptr divisor, + MatrixWorkspace_sptr dxWS) { + const auto ratio = divident / divisor; + ws *= ratio; + // We lost Dx values (Multiply) and need to get them back for point data + if (ws->size() == dxWS->size()) { + for (size_t i = 0; i < ws->getNumberHistograms(); ++i) { + if (dxWS->hasDx(i) && !ws->hasDx(i)) { + ws->setSharedDx(i, dxWS->sharedDx(i)); + } + } + } + m_scaleFactor = ratio->y(0).front(); + m_errorScaleFactor = ratio->e(0).front(); + if (m_scaleFactor < 1e-2 || m_scaleFactor > 1e2 || + std::isnan(m_scaleFactor)) { + std::stringstream messageBuffer; + messageBuffer << "Stitch1D calculated scale factor is: " << m_scaleFactor + << ". Check that in both input workspaces the integrated " + "overlap region is non-zero."; + g_log.warning(messageBuffer.str()); + } +} + //---------------------------------------------------------------------------------------------- /** Execute the algorithm. */ void Stitch1D::exec() { - MatrixWorkspace_sptr rhsWS = this->getProperty("RHSWorkspace"); MatrixWorkspace_sptr lhsWS = this->getProperty("LHSWorkspace"); + MatrixWorkspace_sptr rhsWS = this->getProperty("RHSWorkspace"); const MinMaxTuple intesectionXRegion = calculateXIntersection(lhsWS, rhsWS); - const double intersectionMin = intesectionXRegion.get<0>(); - const double intersectionMax = intesectionXRegion.get<1>(); - - double startOverlap = getStartOverlap(intersectionMin, intersectionMax); - double endOverlap = getEndOverlap(intersectionMin, intersectionMax); - - if (startOverlap > endOverlap) { - std::string message = boost::str( - boost::format("Stitch1D cannot have a StartOverlap > EndOverlap. " - "StartOverlap: %0.9f, EndOverlap: %0.9f") % - startOverlap % endOverlap); - throw std::runtime_error(message); - } - - const bool scaleRHS = this->getProperty("ScaleRHSWorkspace"); - MantidVec params = getRebinParams(lhsWS, rhsWS, scaleRHS); - - const double &xMin = params.front(); - const double &xMax = params.back(); - - if (std::abs(xMin - startOverlap) < 1E-6) - startOverlap = xMin; - - if (std::abs(xMax - endOverlap) < 1E-6) - endOverlap = xMax; - - if (startOverlap < xMin) { - std::string message = boost::str( - boost::format("Stitch1D StartOverlap is outside the available X range. " - "after rebinning. StartOverlap: %10.9f, X min: %10.9f") % - startOverlap % xMin); - throw std::runtime_error(message); - } - if (endOverlap > xMax) { - std::string message = boost::str( - boost::format("Stitch1D EndOverlap is outside the available X range " - "after rebinning. EndOverlap: %10.9f, X max: %10.9f") % - endOverlap % xMax); - throw std::runtime_error(message); - } - const size_t histogramCount = rhsWS->getNumberHistograms(); m_nanYIndexes.resize(histogramCount); m_infYIndexes.resize(histogramCount); m_nanEIndexes.resize(histogramCount); m_infEIndexes.resize(histogramCount); - const bool useManualScaleFactor = this->getProperty("UseManualScaleFactor"); - double scaleFactor = 0; - double errorScaleFactor = 0; + const double intersectionMin = intesectionXRegion.get<0>(); + const double intersectionMax = intesectionXRegion.get<1>(); - MatrixWorkspace_sptr lhs, rhs; + double startOverlap; + double endOverlap; + if (lhsWS->isHistogramData()) { + startOverlap = getStartOverlap(intersectionMin, intersectionMax); + endOverlap = getEndOverlap(intersectionMin, intersectionMax); + if (startOverlap > endOverlap) { + std::string message = boost::str( + boost::format("Stitch1D cannot have a StartOverlap > EndOverlap. " + "StartOverlap: %0.9f, EndOverlap: %0.9f") % + startOverlap % endOverlap); + throw std::runtime_error(message); + } + } else { + startOverlap = intersectionMin; + endOverlap = intersectionMax; + } + + const bool scaleRHS = this->getProperty("ScaleRHSWorkspace"); - // If the input workspaces are histograms ... + MatrixWorkspace_sptr lhs; + MatrixWorkspace_sptr rhs; if (lhsWS->isHistogramData()) { + MantidVec params = getRebinParams(lhsWS, rhsWS, scaleRHS); + const double &xMin = params.front(); + const double &xMax = params.back(); + + if (std::abs(xMin - startOverlap) < 1E-6) + startOverlap = xMin; + + if (std::abs(xMax - endOverlap) < 1E-6) + endOverlap = xMax; + + if (startOverlap < xMin) { + std::string message = boost::str( + boost::format( + "Stitch1D StartOverlap is outside the available X range. " + "StartOverlap: %10.9f, X min: %10.9f") % + startOverlap % xMin); + throw std::runtime_error(message); + } + if (endOverlap > xMax) { + std::string message = boost::str( + boost::format("Stitch1D EndOverlap is outside the available X range. " + "EndOverlap: %10.9f, X max: %10.9f") % + endOverlap % xMax); + throw std::runtime_error(message); + } lhs = rebin(lhsWS, params); rhs = rebin(rhsWS, params); + } else { + lhs = lhsWS; + rhs = rhsWS; } - if (useManualScaleFactor) { - double manualScaleFactor = this->getProperty("ManualScaleFactor"); - MatrixWorkspace_sptr manualScaleFactorWS = singleValueWS(manualScaleFactor); + m_scaleFactor = this->getProperty("ManualScaleFactor"); + m_errorScaleFactor = m_scaleFactor; + const bool useManualScaleFactor = this->getProperty("UseManualScaleFactor"); + if (useManualScaleFactor) { + MatrixWorkspace_sptr manualScaleFactorWS = singleValueWS(m_scaleFactor); if (scaleRHS) rhs *= manualScaleFactorWS; else lhs *= manualScaleFactorWS; - scaleFactor = manualScaleFactor; - errorScaleFactor = manualScaleFactor; } else { - auto rhsOverlapIntegrated = integration(rhs, startOverlap, endOverlap); - auto lhsOverlapIntegrated = integration(lhs, startOverlap, endOverlap); - - MatrixWorkspace_sptr ratio; - if (scaleRHS) { - ratio = lhsOverlapIntegrated / rhsOverlapIntegrated; - rhs = rhs * ratio; - } else { - ratio = rhsOverlapIntegrated / lhsOverlapIntegrated; - lhs *= ratio; - } - scaleFactor = ratio->y(0).front(); - errorScaleFactor = ratio->e(0).front(); - if (scaleFactor < 1e-2 || scaleFactor > 1e2 || std::isnan(scaleFactor)) { - std::stringstream messageBuffer; - messageBuffer << "Stitch1D calculated scale factor is: " << scaleFactor - << ". Check that in both input workspaces the integrated " - "overlap region is non-zero."; - g_log.warning(messageBuffer.str()); - } + const auto rhsOverlapIntegrated = + integration(rhs, startOverlap, endOverlap); + const auto lhsOverlapIntegrated = + integration(lhs, startOverlap, endOverlap); + if (scaleRHS) + scaleWorkspace(rhs, lhsOverlapIntegrated, rhsOverlapIntegrated, rhsWS); + else + scaleWorkspace(lhs, rhsOverlapIntegrated, lhsOverlapIntegrated, lhsWS); } + // Provide log information about the scale factors used in the calculations. + std::stringstream messageBuffer; + messageBuffer << "Scale Factor Y is: " << m_scaleFactor + << " Scale Factor E is: " << m_errorScaleFactor; + g_log.notice(messageBuffer.str()); - boost::tuple<int, int> startEnd = - findStartEndIndexes(startOverlap, endOverlap, lhs); - int a1 = boost::tuples::get<0>(startEnd); - int a2 = boost::tuples::get<1>(startEnd); - - // Mask out everything BUT the overlap region as a new workspace. - MatrixWorkspace_sptr overlap1 = maskAllBut(a1, a2, lhs); - // Mask out everything BUT the overlap region as a new workspace. - MatrixWorkspace_sptr overlap2 = maskAllBut(a1, a2, rhs); - // Mask out everything AFTER the overlap region as a new workspace. - maskInPlace(a1 + 1, static_cast<int>(lhs->blocksize()), lhs); - // Mask out everything BEFORE the overlap region as a new workspace. - maskInPlace(0, a2, rhs); - - MatrixWorkspace_sptr overlapave; - - // If the input workspaces are histograms ... - if (lhsWS->isHistogramData()) { + MatrixWorkspace_sptr result; + if (lhsWS->isHistogramData()) { // If the input workspaces are histograms ... + boost::tuple<int, int> startEnd = + findStartEndIndexes(startOverlap, endOverlap, lhs); + int a1 = boost::tuples::get<0>(startEnd); + int a2 = boost::tuples::get<1>(startEnd); + + // Mask out everything BUT the overlap region as a new workspace. + MatrixWorkspace_sptr overlap1 = maskAllBut(a1, a2, lhs); + // Mask out everything BUT the overlap region as a new workspace. + MatrixWorkspace_sptr overlap2 = maskAllBut(a1, a2, rhs); + // Mask out everything AFTER the overlap region as a new workspace. + maskInPlace(a1 + 1, static_cast<int>(lhs->blocksize()), lhs); + // Mask out everything BEFORE the overlap region as a new workspace. + maskInPlace(0, a2, rhs); + MatrixWorkspace_sptr overlapave; if (hasNonzeroErrors(overlap1) && hasNonzeroErrors(overlap2)) { overlapave = weightedMean(overlap1, overlap2); } else { @@ -599,22 +628,16 @@ void Stitch1D::exec() { MatrixWorkspace_sptr denominator = singleValueWS(2.0); overlapave = sum / denominator; } + result = lhs + overlapave + rhs; + reinsertSpecialValues(result); } else { // The input workspaces are point data ... join & sort - auto ws = conjoinXAxis(overlap1, overlap2); - overlapave = sortXAxis(ws); + MatrixWorkspace_sptr ws = conjoinXAxis(lhs, rhs); + if (!ws) + g_log.error("Could not retrieve joined workspace."); + result = sortXAxis(ws); } - - MatrixWorkspace_sptr result = lhs + overlapave + rhs; - reinsertSpecialValues(result); - - // Provide log information about the scale factors used in the calculations. - std::stringstream messageBuffer; - messageBuffer << "Scale Factor Y is: " << scaleFactor - << " Scale Factor E is: " << errorScaleFactor; - g_log.notice(messageBuffer.str()); - setProperty("OutputWorkspace", result); - setProperty("OutScaleFactor", scaleFactor); + setProperty("OutScaleFactor", m_scaleFactor); } /** Put special values back. diff --git a/Framework/Algorithms/test/Stitch1DTest.h b/Framework/Algorithms/test/Stitch1DTest.h index 560b20d52c2..c0007ff2f57 100644 --- a/Framework/Algorithms/test/Stitch1DTest.h +++ b/Framework/Algorithms/test/Stitch1DTest.h @@ -240,14 +240,35 @@ public: } void test_point_workspaces_pass() { - auto point_ws = make_arbitrary_point_ws(); - const auto &x = HistogramX(3, LinearGenerator(-.5, 0.2)); - const auto &y = HistogramY(3, LinearGenerator(1., 1.0)); + const auto &x1 = HistogramX(3, LinearGenerator(1., 1.)); + const auto &y1 = HistogramY(3, LinearGenerator(1., 1.)); const auto &e = HistogramE(3, 1.); - const auto &dx = HistogramDx(3, LinearGenerator(-3., 0.1)); - auto point_ws_2 = createWorkspace(x, y, e, dx); - TSM_ASSERT_THROWS_NOTHING("Point workspaces should pass", - do_stitch1D(point_ws, point_ws_2)); + const auto &dx1 = HistogramDx(3, LinearGenerator(-3., 0.)); + auto point_ws_1 = createWorkspace(x1, y1, e, dx1); + + const auto &x2 = HistogramX(3, LinearGenerator(1.5, 1.)); + const auto &y2 = HistogramY(3, LinearGenerator(5., 1.)); + const auto &dx2 = HistogramDx(3, LinearGenerator(-9., 0.));//1. + auto point_ws_2 = createWorkspace(x2, y2, e, dx2); + + Stitch1D alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("LHSWorkspace", point_ws_1); + alg.setProperty("RHSWorkspace", point_ws_2); + alg.setPropertyValue("OutputWorkspace", "dummy_value"); + alg.execute(); + //TS_ASSERT(alg.isExecuted()); + //MatrixWorkspace_const_sptr stitched = alg.getProperty("OutputWorkspace"); + //const std::vector<double> x_values{1., 2., 2.1, 3., 3.1, 4.1}; + //TS_ASSERT(stitched->x(0).rawData(), x_values); + //const std::vector<double> y_values{1., 2., 5., 3., 6., 7.}; + //TS_ASSERT(stitched->y(0).rawData(), y_values); + //const std::vector<double> dx_values{-3., -3., -9., -3., -9., -9.}; + //TS_ASSERT(stitched->dx(0).rawData(), dx_values); + //double scaleFactor = alg.getProperty("OutScaleFactor"); + //TS_ASSERT(scaleFactor, 0.); } void test_histogram_workspaces_pass() { @@ -268,20 +289,18 @@ public: alg.initialize(); alg.setProperty("LHSWorkspace", make_arbitrary_point_ws()); alg.setProperty("RHSWorkspace", make_arbitrary_histogram_ws()); - alg.setProperty("StartOverlap", -1); - alg.setProperty("EndOverlap", 1); + alg.setProperty("StartOverlap", -1.); + alg.setProperty("EndOverlap", 1.); alg.setProperty("Params", std::vector<double>(1., 0.2)); alg.setProperty("ScaleRHSWorkspace", true); alg.setPropertyValue("OutputWorkspace", "dummy_value"); - alg.execute(); - TSM_ASSERT("RHSWorkspace must be point data.", - !alg.isExecuted()); + TS_ASSERT_THROWS(alg.execute(), std::runtime_error); + TS_ASSERT(!alg.isExecuted()); alg.setProperty("LHSWorkspace", make_arbitrary_histogram_ws()); alg.setProperty("RHSWorkspace", make_arbitrary_point_ws()); - alg.execute(); - TSM_ASSERT("RHSWorkspace must be a histogram.", - !alg.isExecuted()); + TS_ASSERT_THROWS(alg.execute(), std::runtime_error); + TS_ASSERT(!alg.isExecuted()); } void test_stitching_uses_supplied_params() { @@ -549,7 +568,7 @@ public: TSM_ASSERT("All error values are non-zero", alg.hasNonzeroErrors(ws)); // Run it again with all zeros - e = HistogramE(9, 0); + e = HistogramE(9, 0.); ws = createWorkspace(x, y, e, dx, 1); TSM_ASSERT("All error values are non-zero", !alg.hasNonzeroErrors(ws)); @@ -564,7 +583,7 @@ public: // Note: The size for y and e previously contained a factor nspectrum, but // it is unclear why, so I removed it. - HistogramX x(10, LinearGenerator(-1, 0.2)); + HistogramX x(10, LinearGenerator(-1., 0.2)); HistogramY y(9, 1.); HistogramE e(9, 1.); HistogramDx dx(9, 0.); diff --git a/docs/source/release/v3.13.0/framework.rst b/docs/source/release/v3.13.0/framework.rst index 576ea915962..fa3581d5ea3 100644 --- a/docs/source/release/v3.13.0/framework.rst +++ b/docs/source/release/v3.13.0/framework.rst @@ -27,11 +27,9 @@ Improved - :ref:`Maxent <algm-Maxent>` when outputting the results of the iterations, it no longer pads with zeroes but returns as many items as iterations done for each spectrum, making the iterations easy to count. -- :ref:`ConvertToPointData <algm-ConvertToPointData>` and :ref:`ConvertToHistogram <algm-ConvertToHistogram>` now propagate the Dx errors to the output. -- The algorithm :ref:`algm-Stitch1D` can now receive point data as input workspaces and does apply a full overlap while keeping corresponding Dx values. -- The algorithm :ref:`CreateWorkspace <algm-CreateWorkspace>` can now optionally receive the Dx errors. -- :ref:`ConjoinXRuns <algm-ConjoinXRuns>` joins Dx errors if present -- The algorithm :ref:`SortXAxis <algm-SortXAxis>` has a new input option that allows ascending (default) and descending sorting. Furthermore, Dx values will be considered if present. The documentation needed to be corrected. +- XError values (Dx) can now be treated by the following algorithms: :ref:`ConjoinXRuns <algm-ConjoinXRuns>`, :ref:`ConvertToHistogram <algm-ConvertToHistogram>`, :ref:`ConvertToPointData <algm-ConvertToPointData>`, :ref:`CreateWorkspace <algm-CreateWorkspace>`, :ref:`SortXAxis <algm-SortXAxis>`, :ref:`algm-Stitch1D`. +- :ref:`Stitch1D <algm-Stitch1D>` can treat point data. +- The algorithm :ref:`SortXAxis <algm-SortXAxis>` has a new input option that allows ascending (default) and descending sorting. The documentation needed to be corrected in general. Bug fixes ######### -- GitLab