diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h index 62fc457a07d9578dfc38c9ebb1e6a11e0f49d504..ac12465bf242ff08edc087e4f0bf2154b20d1cde 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h @@ -107,6 +107,8 @@ namespace Mantid Mantid::API::MatrixWorkspace_sptr & source); /// Mask out everything but the data in the ranges, but do it inplace. void maskInPlace(int a1, int a2, Mantid::API::MatrixWorkspace_sptr source); + /// Add back in any special values + void reinsertSpecialValues(Mantid::API::MatrixWorkspace_sptr ws); /// Range tolerance static const double range_tolerance; /// Index per workspace spectra of Nans diff --git a/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp b/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp index 28a2ca2ba30720c6fec86ea9a411e1df69cffc1a..42718c2a9937eb88e891f9a01e9c4d3aa3be57af 100644 --- a/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Stitch1D.cpp @@ -299,38 +299,39 @@ rebin->setProperty("Params", params); rebin->execute(); MatrixWorkspace_sptr outWS = rebin->getProperty("OutputWorkspace"); + const int histogramCount = static_cast<int>(outWS->getNumberHistograms()); +// Record special values and then mask them out as zeros. PARALLEL_FOR1(outWS) for (int i = 0; i < histogramCount; ++i) { PARALLEL_START_INTERUPT_REGION - std::vector<size_t> nanIndexes; - std::vector<size_t> infIndexes; + std::vector<size_t>& nanIndexes = m_nanIndexes[i]; + std::vector<size_t>& infIndexes = m_infIndexes[i] ; // Copy over the data MantidVec& sourceY = outWS->dataY(i); for (size_t j = 0; j < sourceY.size(); ++j) { - if (isNan(sourceY[j])) + const double& value = sourceY[j]; + if (isNan(value)) { nanIndexes.push_back(j); - //sourceY[j] = 0; + sourceY[j] = 0; } - else if (isInf(sourceY[j])) + else if (isInf(value)) { infIndexes.push_back(j); sourceY[j] = 0; } - } - m_nanIndexes[i] = nanIndexes; - m_infIndexes[i] = infIndexes; PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION + return outWS; } @@ -602,6 +603,7 @@ overlapave = sum / denominator; } MatrixWorkspace_sptr result = rebinnedLHS + overlapave + rebinnedRHS; +reinsertSpecialValues(result); // Provide log information about the scale factors used in the calculations. std::stringstream messageBuffer; @@ -613,5 +615,31 @@ setProperty("OutScaleFactor", scaleFactor); } +void Stitch1D::reinsertSpecialValues(MatrixWorkspace_sptr ws) +{ +int histogramCount = static_cast<int>(ws->getNumberHistograms()); +PARALLEL_FOR1(ws) +for (int i = 0; i < histogramCount; ++i) +{ +PARALLEL_START_INTERUPT_REGION + // Copy over the data +MantidVec& sourceY = ws->dataY(i); + +for (size_t j = 0; j < m_nanIndexes[i].size(); ++j) +{ + sourceY[m_nanIndexes[i][j]] = std::numeric_limits<double>::quiet_NaN(); +} + +size_t siz = m_infIndexes[i].size(); +for (size_t j = 0; j < m_infIndexes[i].size(); ++j) +{ + sourceY[m_infIndexes[i][j]] = std::numeric_limits<double>::infinity(); +} + +PARALLEL_END_INTERUPT_REGION +} +PARALLEL_CHECK_INTERUPT_REGION +} + } // namespace Algorithms } // namespace Mantid diff --git a/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h b/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h index 8f1bc18086c920ccc356ed87f5c7b2ac1d027ff5..71b1ae004ca8dad776c8c214f170f19a2065c3de 100644 --- a/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h +++ b/Code/Mantid/Framework/Algorithms/test/Stitch1DTest.h @@ -644,7 +644,7 @@ public: TSM_ASSERT("NOT all error values are non-zero", alg.hasNonzeroErrors(ws)); } - void test_patch_nan_y_value() + void test_patch_nan_y_value_for_scaling() { const size_t nspectrum = 1; @@ -672,7 +672,7 @@ public: TSM_ASSERT("ScaleFactor should not be NAN", !boost::math::isnan(scaleFactor)); } - void test_patch_inf_y_value() + void test_patch_inf_y_value_for_scaling() { const size_t nspectrum = 1; @@ -700,6 +700,40 @@ public: TSM_ASSERT("ScaleFactor should not be Infinity", !boost::math::isinf(scaleFactor)); } + + void test_reset_nans() + { + const size_t nspectrum = 1; + + auto x = MantidVec(10); + const double xstart = 0; + const double xstep = 1; + LinearSequence<MantidVec::value_type> sequenceX(xstart, xstep); + std::generate(x.begin(), x.end(), sequenceX); + + auto y = MantidVec(nspectrum * (x.size() - 1), 1); + auto e = MantidVec(nspectrum * (x.size() - 1), 1); + + double nan = std::numeric_limits<double>::quiet_NaN(); + y[0] = nan; // Add a Infinity + MatrixWorkspace_sptr lhsWS = createWorkspace(x, y, e, static_cast<int>(nspectrum)); + + y[0] = y[1]; + // Remove infinity + MatrixWorkspace_sptr rhsWS = createWorkspace(x, y, e, static_cast<int>(nspectrum)); + + auto ret = do_stitch1D(lhsWS, rhsWS); + + MatrixWorkspace_sptr outWs = ret.get<0>(); + double scaleFactor = ret.get<1>(); + + TSM_ASSERT("ScaleFactor should not be Infinity", !boost::math::isinf(scaleFactor)); + + auto outY = outWs->readY(0); + TSM_ASSERT("Nans should be put back", boost::math::isnan(outY[0])); + } + + }; #endif /* MANTID_ALGORITHMS_STITCH1DTEST_H_ */