diff --git a/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Framework/API/inc/MantidAPI/MatrixWorkspace.h index 645ce53fe15854d98d884adf49a083a57a885d33..e978fc9e06a52805acc1fec931224bf0ed14cd42 100644 --- a/Framework/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Framework/API/inc/MantidAPI/MatrixWorkspace.h @@ -445,6 +445,7 @@ public: void flagMasked(const size_t &index, const size_t &binIndex, const double &weight = 1.0); bool hasMaskedBins(const size_t &workspaceIndex) const; + bool hasAnyMaskedBins() const; /// Masked bins for each spectrum are stored as a set of pairs containing <bin /// index, weight> using MaskList = std::map<size_t, double>; diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index 569dca09f2286c7b87f074eda1cf9382f71eebc8..55d5ecf1d1c58baae56ffb22bc55fa22f0e38291 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -1200,6 +1200,11 @@ bool MatrixWorkspace::hasMaskedBins(const size_t &workspaceIndex) const { return m_masks.find(workspaceIndex) != m_masks.end(); } +/** Does this workspace contain any masked bins + * @return True if there are masked bins somewhere in this workspace + */ +bool MatrixWorkspace::hasAnyMaskedBins() const { return !m_masks.empty(); } + /** Returns the list of masked bins for a spectrum. * @param workspaceIndex * @return A const reference to the list of masked bins diff --git a/Framework/API/test/MatrixWorkspaceTest.h b/Framework/API/test/MatrixWorkspaceTest.h index 7997ea3f25a09f45a5f59dc16762199ff772ce3d..069b4742d730c1fc3d66e808edf4cc84ce76aa14 100644 --- a/Framework/API/test/MatrixWorkspaceTest.h +++ b/Framework/API/test/MatrixWorkspaceTest.h @@ -710,6 +710,7 @@ public: auto ws = makeWorkspaceWithDetectors(2, 2); // Now do a valid masking TS_ASSERT_THROWS_NOTHING(ws->flagMasked(0, 1, 0.75)); + TS_ASSERT(ws->hasAnyMaskedBins()); TS_ASSERT(ws->hasMaskedBins(0)); TS_ASSERT_EQUALS(ws->maskedBins(0).size(), 1); TS_ASSERT_EQUALS(ws->maskedBins(0).begin()->first, 1); @@ -731,6 +732,7 @@ public: void testMasking() { auto ws2 = makeWorkspaceWithDetectors(1, 2); + TS_ASSERT(!ws2->hasAnyMaskedBins()); TS_ASSERT(!ws2->hasMaskedBins(0)); // Doesn't throw on invalid spectrum number, just returns false TS_ASSERT(!ws2->hasMaskedBins(1)); diff --git a/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp b/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp index ed44518b237aef05efc9b4839a263f700e41224a..230b93e0cd3d249382b0f551c48fda5a282d8845 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/MatrixWorkspace.cpp @@ -332,6 +332,9 @@ void export_MatrixWorkspace() { MatrixWorkspace_YUnitLabelOverloads( (arg("self"), arg("useLatex"), arg("plotAsDistribution")), "Returns the caption for the Y axis")) + .def("hasAnyMaskedBins", &MatrixWorkspace::hasAnyMaskedBins, + (arg("self")), + "Returns true if any of the bins in this workspace are masked.") .def("hasMaskedBins", &MatrixWorkspace::hasMaskedBins, (arg("self"), arg("workspaceIndex")), "Returns true if this spectrum contains any masked bins") diff --git a/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py b/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py index aa2950a3421f46d65944ab12860719a852e4cc58..5bed2dd3f6475cb1bc735b5915c70af91c728edc 100644 --- a/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/MatrixWorkspaceTest.py @@ -443,6 +443,12 @@ class MatrixWorkspaceTest(unittest.TestCase): self.assertTrue(ws.hasMaskedBins(0)) self.assertFalse(ws.hasMaskedBins(1)) + def test_hasAnyMaskedBins(self): + numBins = 10 + numHist=11 + ws = WorkspaceCreationHelper.create2DWorkspace123WithMaskedBin(numHist, numBins, 0, 1) + self.assertTrue(ws.hasAnyMaskedBins()) + def test_maskedBinsIndices(self): numBins = 10 numHist=11