Commit 67626e93 authored by Dimitar Tasev's avatar Dimitar Tasev
Browse files

Adds `hasAnyMaskedBins` on MatrixWorkspace

- Adds Python unit test for export
- Adds a `hasAnyMaskedBins` call in the MatrixWorkspace unit tests
parent 4cc098db
......@@ -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>;
......
......@@ -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
......
......@@ -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));
......
......@@ -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")
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment