Commit 61d01a66 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Add int/sigint column to peaks workspace table

The value can already be calculated from a Peak object so
these changes simple ensure it is displayed in the table
representation.
parent 4e611ac1
......@@ -169,7 +169,7 @@ public:
double getL1() const override;
double getL2() const override;
double getValueByColName(const std::string &name_in) const;
double getValueByColName(std::string colName) const;
/// Get the peak shape.
const Mantid::Geometry::PeakShape &getPeakShape() const override;
......
......@@ -13,7 +13,6 @@
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/System.h"
#include "boost/make_shared.hpp"
......@@ -969,15 +968,15 @@ double Peak::getL1() const { return (samplePos - sourcePos).norm(); }
double Peak::getL2() const { return (detPos - samplePos).norm(); }
// -------------------------------------------------------------------------------------
/** Helper function for displaying/sorting peaks in MantidPlot
/** Helper function for displaying/sorting peaks
*
* @param name_in :: name of the column in the table workspace
* @param name :: name of the column in the table workspace. The matching is
* case-insensitive.
* @return a double representing that value (if that's possible)
* @throw std::runtime_error if you asked for a column that can't convert to
*double.
*/
double Peak::getValueByColName(const std::string &name_in) const {
std::string name = name_in;
double Peak::getValueByColName(std::string name) const {
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name == "runnumber")
return double(this->getRunNumber());
......@@ -1001,6 +1000,8 @@ double Peak::getValueByColName(const std::string &name_in) const {
return this->getIntensity();
else if (name == "sigint")
return this->getSigmaIntensity();
else if (name == "intens/sigint")
return this->getIntensityOverSigma();
else if (name == "bincount")
return this->getBinCount();
else if (name == "row")
......
......@@ -53,6 +53,7 @@ const std::string typeFromName(const std::string &name) {
TYPE_INDEX.emplace("DSpacing", "double");
TYPE_INDEX.emplace("Intens", "double");
TYPE_INDEX.emplace("SigInt", "double");
TYPE_INDEX.emplace("Intens/SigInt", "double");
TYPE_INDEX.emplace("BinCount", "double");
TYPE_INDEX.emplace("BankName", "str");
TYPE_INDEX.emplace("Row", "double");
......
......@@ -631,6 +631,7 @@ void PeaksWorkspace::initColumns() {
addPeakColumn("DSpacing");
addPeakColumn("Intens");
addPeakColumn("SigInt");
addPeakColumn("Intens/SigInt");
addPeakColumn("BinCount");
addPeakColumn("BankName");
addPeakColumn("Row");
......
......@@ -32,33 +32,42 @@ using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::Kernel;
/** Build a test PeaksWorkspace with one peak (others peaks can be added)
*
* @return PeaksWorkspace
*/
PeaksWorkspace_sptr buildPW() {
Instrument_sptr inst =
ComponentCreationHelper::createTestInstrumentRectangular2(1, 10);
inst->setName("SillyInstrument");
auto pw = std::make_shared<PeaksWorkspace>();
pw->setInstrument(inst);
std::string val = "value";
pw->mutableRun().addProperty("TestProp", val);
Peak p(inst, 1, 3.0);
pw->addPeak(p);
return pw;
}
class PeaksWorkspaceTest : public CxxTest::TestSuite {
private:
class TestablePeaksWorkspace : public PeaksWorkspace {
public:
TestablePeaksWorkspace(const PeaksWorkspace &other)
: PeaksWorkspace(other) {}
using ExperimentInfo::numberOfDetectorGroups;
};
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static PeaksWorkspaceTest *createSuite() { return new PeaksWorkspaceTest(); }
static void destroySuite(PeaksWorkspaceTest *suite) { delete suite; }
/** Build a test PeaksWorkspace with one peak (others peaks can be added)
*
* @return PeaksWorkspace
*/
PeaksWorkspace_sptr buildPW() {
Instrument_sptr inst =
ComponentCreationHelper::createTestInstrumentRectangular2(1, 10);
inst->setName("SillyInstrument");
auto pw = std::make_shared<PeaksWorkspace>();
pw->setInstrument(inst);
std::string val = "value";
pw->mutableRun().addProperty("TestProp", val);
Peak p(inst, 1, 3.0);
pw->addPeak(p);
return pw;
}
/** Check that the PeaksWorkspace build by buildPW() is correct */
void checkPW(const PeaksWorkspace &pw) {
TS_ASSERT_EQUALS(pw.columnCount(), 19);
TS_ASSERT_EQUALS(pw.columnCount(), 20);
TS_ASSERT_EQUALS(pw.rowCount(), 1);
TS_ASSERT_EQUALS(pw.getNumberPeaks(), 1);
if (pw.getNumberPeaks() != 1)
......@@ -74,14 +83,6 @@ public:
checkPW(*pw);
}
class TestablePeaksWorkspace : public PeaksWorkspace {
public:
TestablePeaksWorkspace(const PeaksWorkspace &other)
: PeaksWorkspace(other) {}
using ExperimentInfo::numberOfDetectorGroups;
};
void test_copyConstructor() {
auto pw = buildPW();
auto pw2 = std::make_shared<TestablePeaksWorkspace>(*pw);
......@@ -95,6 +96,64 @@ public:
checkPW(*pw2);
}
void test_column_access() {
auto pw = buildPW();
auto &peak0 = pw->getPeak(0);
const int runNo(1000), detID(10), row(0), col(1), peakNumber(1);
const double h(1.), k(-1.), l(2.), lambda(3.5), energy(6.67789),
tof(9733.13), dspacing(2.51539), intensity(2.3), sigInt(0.1),
binCount(100), tbar(0.4);
const V3D q(-1.79284, 0.0717138, 1.73782);
const std::string bankName("bank1");
peak0.setRunNumber(runNo);
peak0.setDetectorID(detID);
peak0.setH(h);
peak0.setK(k);
peak0.setL(l);
peak0.setWavelength(lambda);
peak0.setFinalEnergy(energy);
peak0.setIntensity(intensity);
peak0.setSigmaIntensity(sigInt);
peak0.setBinCount(binCount);
peak0.setPeakNumber(peakNumber);
peak0.setAbsorptionWeightedPathLength(tbar);
auto floatToStr = [](const double d, const int precision = -1) {
std::stringstream ss;
if (precision >= 0)
ss << std::fixed << std::setprecision(precision);
ss << d;
return ss.str();
};
auto v3dToStr = [](const V3D &pt) {
std::stringstream ss;
pt.printSelf(ss);
return ss.str();
};
using std::to_string;
// clang-format off
const std::array<std::string, 20> expected = {\
to_string(runNo), to_string(detID), floatToStr(h, 2), floatToStr(k, 2),
floatToStr(l, 2), floatToStr(lambda), floatToStr(energy), floatToStr(tof, 2), floatToStr(dspacing),
floatToStr(intensity), floatToStr(sigInt), floatToStr(intensity/sigInt), floatToStr(binCount), bankName,
to_string(row), to_string(col),
v3dToStr(q), v3dToStr(q),
to_string(peakNumber),
floatToStr(tbar)
};
// clang-format on
for (int i = 0; i < 20; ++i) {
const auto column = pw->getColumn(i);
TS_ASSERT_EQUALS(1, column->size());
std::stringstream os;
column->print(0, os);
TSM_ASSERT_EQUALS("Mismatch in column " + column->name(), expected[i],
os.str());
}
}
void test_sort() {
auto pw = buildPW();
const auto inst = pw->getInstrument();
......
......@@ -301,12 +301,12 @@ class LinkedUBs(DataProcessorAlgorithm):
num_peaks_var = self._num_peaks + self._peak_increment * m
# add q_lab and dpsacing values of found peaks to a list
qlabs_observed = np.array(self._observed_peaks.column(15))
dspacings_observed = np.array(self._observed_peaks.column(8))
qlabs_observed = np.array(self._observed_peaks.column("QLab"))
dspacings_observed = np.array(self._observed_peaks.column("DSpacing"))
# sort the predicted peaks from largest to smallest dspacing
qlabs_predicted = np.array(predictor.column(15))
dspacings_predicted = np.array(predictor.column(8))
qlabs_predicted = np.array(predictor.column("QLab"))
dspacings_predicted = np.array(predictor.column("DSpacing"))
# get the indexing list that sorts dspacing from largest to
# smallest
......
......@@ -60,5 +60,6 @@ Improvements
- New instrument geometry for MaNDi instrument at SNS
- New algorithm :ref:`AddAbsorptionWeightedPathLengths <algm-AddAbsorptionWeightedPathLengths-v1>` for calculating the absorption weighted path length for each peak in a peaks workspace. The absorption weighted path length is used downstream from Mantid in extinction correction calculations
- Can now edit H,K,L in the table of a peaks workspace in workbench (now consistent with Mantid Plot)
- The peaks workspace table display now contains a column showing the value of the intensity/sigma for each peak.
:ref:`Release 5.1.0 <v5.1.0>`
Markdown is supported
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