Skip to content

Commit

Permalink
Set the proper MD frame for each dimension.
Browse files Browse the repository at this point in the history
Refs #11056
  • Loading branch information
martyngigg committed Jan 7, 2016
1 parent 451b947 commit 75e5938
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
44 changes: 30 additions & 14 deletions Framework/MDAlgorithms/src/LoadSQW2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,19 @@ LoadSQW2::createQDimension(size_t index, float dimMin, float dimMax,
"index between 0 & 2. Found: " +
std::to_string(index));
}
const std::string id = "Q" + std::to_string(index + 1);
std::string name, unit;
static std::array<const char *, 3> indexToDim{"x", "y", "z"};
MDHistoDimensionBuilder builder;
builder.setId(std::string("q") + indexToDim[index]);
MDHistoDimensionBuilder::resizeToFitMDBox(dimMin, dimMax);
builder.setMin(dimMin);
builder.setMax(dimMax);
builder.setNumBins(nbins);

std::string name, unit, frameName;
if (m_outputFrame == "Q_sample" || m_outputFrame == "Q_lab") {
static std::array<const char *, 3> indexToDim{"x", "y", "z"};
name = m_outputFrame + "_" + indexToDim[index];
unit = "A^-1";
frameName = (m_outputFrame == "Q_sample") ? "QSample" : "QLab";
} else if (m_outputFrame == "HKL") {
static std::array<const char *, 3> indexToHKL{"[H,0,0]", "[0,K,0]",
"[0,0,L]"};
Expand All @@ -506,28 +513,37 @@ LoadSQW2::createQDimension(size_t index, float dimMin, float dimMax,
const V3D x = bmat * dimDir;
double length = 2. * M_PI * x.norm();
unit = "in " + MDAlgorithms::sprintfd(length, 1.e-3) + " A^-1";
frameName = "HKL";
} else {
throw std::logic_error(
"LoadSQW2::createQDimension - Unknown output frame: " + m_outputFrame);
}
Mantid::Geometry::GeneralFrame frame(name, unit);
MDHistoDimensionBuilder::resizeToFitMDBox(dimMin, dimMax);
return make_shared<MDHistoDimension>(name, id, frame, dimMin, dimMax, nbins);
builder.setUnits(unit);
builder.setName(name);
builder.setFrameName(frameName);

return builder.create();
}

/**
* Create an energy dimension
* @param umin Dimension minimum from file
* @param umax Dimension maximum from file
* @param dimMin Dimension minimum in output frame
* @param dimMax Dimension maximum in output frame
* @param nbins Number of bins for this dimension
* @return A new MDHistoDimension object
*/
Geometry::IMDDimension_sptr LoadSQW2::createEnDimension(float umin, float umax,
size_t nbins) {
const std::string id("DeltaE"), name(id), unit(id);
Mantid::Geometry::GeneralFrame frame(name, unit);
MDHistoDimensionBuilder::resizeToFitMDBox(umin, umax);
return make_shared<MDHistoDimension>(name, id, frame, umin, umax, nbins);
Geometry::IMDDimension_sptr
LoadSQW2::createEnDimension(float dimMin, float dimMax, size_t nbins) {
MDHistoDimensionBuilder builder;
builder.setId("en");
builder.setUnits("meV");
builder.setName("en");
builder.setFrameName("meV");
MDHistoDimensionBuilder::resizeToFitMDBox(dimMin, dimMax);
builder.setMin(dimMin);
builder.setMax(dimMax);
builder.setNumBins(nbins);
return builder.create();
}

/**
Expand Down
19 changes: 11 additions & 8 deletions Framework/MDAlgorithms/test/LoadSQW2Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class LoadSQW2Test : public CxxTest::TestSuite {
typedef std::array<std::string, 4> StringList;
typedef std::array<double, 8> DoubleList;
typedef std::array<size_t, 4> SizeTList;
StringList ids, names, units;
StringList ids, names, units, frameNames;
DoubleList ulimits;
SizeTList nbins;
};
Expand Down Expand Up @@ -180,7 +180,7 @@ class LoadSQW2Test : public CxxTest::TestSuite {
TS_ASSERT_DELTA(expectedDim.ulimits[2 * i + 1], dim->getMaximum(), 1e-04);
TS_ASSERT_EQUALS(expectedDim.nbins[i], dim->getNBins());
TS_ASSERT_EQUALS(expectedDim.units[i], dim->getUnits().ascii());
TS_ASSERT_EQUALS(expectedDim.names[i], dim->getMDFrame().name());
TS_ASSERT_EQUALS(expectedDim.frameNames[i], dim->getMDFrame().name());
}
}
#ifdef __clang__
Expand All @@ -189,24 +189,27 @@ class LoadSQW2Test : public CxxTest::TestSuite {

DimensionProperties getExpectedDimProperties(std::string outputFrame) {
DimensionProperties expected;
expected.ids = {"Q1", "Q2", "Q3", "DeltaE"};
expected.ids = {"qx", "qy", "qz", "en"};
expected.nbins = {3, 3, 2, 2};
if (outputFrame == "HKL") {
expected.units = {"in 2.189 A^-1", "in 2.189 A^-1", "in 2.189 A^-1",
"DeltaE"};
expected.names = {"[H,0,0]", "[0,K,0]", "[0,0,L]", "DeltaE"};
"meV"};
expected.names = {"[H,0,0]", "[0,K,0]", "[0,0,L]", "en"};
expected.ulimits = {0.0439, 0.9271, -0.4644, -0.4024,
-0.7818, -0.5052, 2.5, 147.5};
expected.frameNames = {"HKL", "HKL", "HKL", "meV"};
} else {
expected.units = {"A^-1", "A^-1", "A^-1", "DeltaE"};
expected.units = {"Angstrom^-1", "Angstrom^-1", "Angstrom^-1", "meV"};
if (outputFrame == "Q_sample") {
expected.names = {"Q_sample_x", "Q_sample_y", "Q_sample_z", "DeltaE"};
expected.names = {"Q_sample_x", "Q_sample_y", "Q_sample_z", "en"};
expected.ulimits = {0.0962, 2.0297, -1.0169, -0.8811,
-1.7117, -1.1060, 2.5, 147.5};
expected.frameNames = {"QSample", "QSample", "QSample", "meV"};
} else if (outputFrame == "Q_lab") {
expected.names = {"Q_lab_x", "Q_lab_y", "Q_lab_z", "DeltaE"};
expected.names = {"Q_lab_x", "Q_lab_y", "Q_lab_z", "en"};
expected.ulimits = {-1.0174, -0.8810, -1.7116, -1.1057,
0.0962, 2.0296, 2.5, 147.5};
expected.frameNames = {"QLab", "QLab", "QLab", "meV"};
} else {
TS_FAIL("Unknown output frame: " + outputFrame);
}
Expand Down
8 changes: 4 additions & 4 deletions Vates/VatesAPI/test/SQWLoadingPresenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void testTimeLabel()
presenter.executeLoadMetadata();
vtkDataSet* product = presenter.execute(&factory, mockLoadingProgressAction, mockDrawingProgressAction);
TSM_ASSERT_EQUALS("Time label should be exact.",
presenter.getTimeStepLabel(), "E (mev)");
presenter.getTimeStepLabel(), "en (meV)");

TS_ASSERT(Mock::VerifyAndClearExpectations(view));
TS_ASSERT(Mock::VerifyAndClearExpectations(&factory));
Expand Down Expand Up @@ -231,13 +231,13 @@ void testAxisLabels()
TSM_ASSERT_THROWS_NOTHING("Should pass", presenter.setAxisLabels(product));
TSM_ASSERT_EQUALS("X Label should match exactly",
getStringFieldDataValue(product, "AxisTitleForX"),
"Q_\\zeta ($A\\^-1$)");
"Q_sample_x ($\\AA^{-1}$)");
TSM_ASSERT_EQUALS("Y Label should match exactly",
getStringFieldDataValue(product, "AxisTitleForY"),
"Q_\\xi ($A\\^-1$)");
"Q_sample_y ($\\AA^{-1}$)");
TSM_ASSERT_EQUALS("Z Label should match exactly",
getStringFieldDataValue(product, "AxisTitleForZ"),
"Q_\\eta ($A\\^-1$)");
"Q_sample_z ($\\AA^{-1}$)");

TS_ASSERT(Mock::VerifyAndClearExpectations(view));
TS_ASSERT(Mock::VerifyAndClearExpectations(&factory));
Expand Down

0 comments on commit 75e5938

Please sign in to comment.