Commit 3f1d6a42 authored by Hahn, Steven's avatar Hahn, Steven
Browse files

add function isCommonLogBins

parent 7a680704
......@@ -418,6 +418,9 @@ public:
/// always safe to assume it is just 2
size_t numberOfAxis() const;
/// Returns true if the workspace contains common X bins with log spacing
virtual bool isCommonLogBins() const;
/// Returns true if the workspace contains data in histogram form (as
/// opposed to point-like)
virtual bool isHistogramData() const;
......
......@@ -876,6 +876,39 @@ void MatrixWorkspace::replaceAxis(const std::size_t &axisIndex,
m_axes[axisIndex] = newAxis;
}
/**
* Whether the workspace contains common X bins with logarithmic spacing
* @return whether the workspace contains common X bins with log spacing
*/
bool MatrixWorkspace::isCommonLogBins() const {
if (!this->isCommonBins()) {
return false;
}
if (this->getNumberHistograms() == 0) {
return false;
}
const auto &x0 = this->x(0);
if (x0.size() < 2) {
return false;
}
// guard against all axis elements being equal
if (x0[1] == x0[0]) {
return false;
}
double diff = x0[1] / x0[0];
for (size_t i = 1; i < x0.size() - 1; ++i) {
if (x0[i + 1] / x0[i] != diff) {
return false;
}
}
return true;
}
/**
* Return the number of Axis stored by this workspace
* @return int
......
......@@ -23,6 +23,9 @@
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/ReferenceFrame.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidHistogramData/LinearGenerator.h"
#include "MantidHistogramData/LogarithmicGenerator.h"
#include "MantidIndexing/IndexInfo.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/VMD.h"
......@@ -467,6 +470,7 @@ public:
void testEmptyWorkspace() {
WorkspaceTester ws;
TS_ASSERT(ws.isCommonBins());
TS_ASSERT_EQUALS(ws.isCommonLogBins(), false);
TS_ASSERT_EQUALS(ws.blocksize(), 0);
TS_ASSERT_EQUALS(ws.size(), 0);
}
......@@ -476,6 +480,7 @@ public:
ws.initialize(10, 10, 10);
// After initialization, ws should contain a shared HistogramX.
TS_ASSERT(ws.isCommonBins());
TS_ASSERT_EQUALS(ws.isCommonLogBins(), false);
// Modifying the value of one Spectrum will cause this Histogram to detach.
// Since the value is identical, isCommonBins is still true.
ws.mutableX(0)[0] = 1.;
......@@ -485,6 +490,26 @@ public:
TS_ASSERT_EQUALS(ws.isCommonBins(), false);
}
void testIsCommonLogAxis() {
WorkspaceTester ws;
ws.initialize(10, 10, 10);
TS_ASSERT_EQUALS(ws.isCommonLogBins(), false);
auto logAxis = Kernel::make_cow<Mantid::HistogramData::HistogramX>(
10, Mantid::HistogramData::LogarithmicGenerator(1., 0.1));
for (size_t i = 0; i < ws.getNumberHistograms(); ++i) {
ws.setSharedX(i, logAxis);
}
TS_ASSERT_EQUALS(ws.isCommonLogBins(), true);
auto linearAxis = Kernel::make_cow<Mantid::HistogramData::HistogramX>(
10, Mantid::HistogramData::LinearGenerator(1., 0.1));
for (size_t i = 0; i < ws.getNumberHistograms(); ++i) {
ws.setSharedX(i, linearAxis);
}
TS_ASSERT_EQUALS(ws.isCommonLogBins(), false);
}
void test_updateSpectraUsing() {
WorkspaceTester testWS;
testWS.initialize(3, 1, 1);
......
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