Skip to content

Commit

Permalink
Copy coordinate system to new workspaces
Browse files Browse the repository at this point in the history
This used to be done by copying the experiment info but is handled
separately now that the coordinate is an extra field.
Refs #11359
  • Loading branch information
martyngigg committed Mar 17, 2015
1 parent cee29dc commit d78fd4d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 7 deletions.
8 changes: 6 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/BinMD.cpp
Expand Up @@ -410,11 +410,15 @@ void BinMD::exec() {

CALL_MDEVENT_FUNCTION(this->binByIterating, m_inWS);

// Copy the experiment infos to the output
// Copy the

// Copy the coordinate system & experiment infos to the output
IMDEventWorkspace_sptr inEWS =
boost::dynamic_pointer_cast<IMDEventWorkspace>(m_inWS);
if (inEWS)
if (inEWS) {
outWS->setCoordinateSystem(inEWS->getSpecialCoordinateSystem());
outWS->copyExperimentInfos(*inEWS);
}

outWS->updateSum();
// Save the output
Expand Down
Expand Up @@ -176,6 +176,8 @@ void SimulateResolutionConvolvedModel::createOutputWorkspace() {
}
// Run information
m_outputWS->copyExperimentInfos(*m_inputWS);
// Coordinates
m_outputWS->setCoordinateSystem(m_inputWS->getSpecialCoordinateSystem());

m_outputWS->initialize();
m_outputWS->splitBox(); // Make grid box
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/SliceMD.cpp
Expand Up @@ -122,8 +122,10 @@ void SliceMD::slice(typename MDEventWorkspace<MDE, nd>::sptr ws) {
// Create the ouput workspace
typename MDEventWorkspace<OMDE, ond>::sptr outWS(
new MDEventWorkspace<OMDE, ond>());
for (size_t od = 0; od < m_binDimensions.size(); od++)
for (size_t od = 0; od < m_binDimensions.size(); od++) {
outWS->addDimension(m_binDimensions[od]);
}
outWS->setCoordinateSystem(ws->getSpecialCoordinateSystem());
outWS->initialize();
// Copy settings from the original box controller
BoxController_sptr bc = ws->getBoxController();
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/test/BinMDTest.h
Expand Up @@ -137,8 +137,10 @@ class BinMDTest : public CxxTest::TestSuite
TS_ASSERT( alg.isInitialized() )

IMDEventWorkspace_sptr in_ws = MDEventsTestHelper::makeMDEW<3>(10, 0.0, 10.0, numEventsPerBox);
in_ws->addExperimentInfo(ExperimentInfo_sptr(new ExperimentInfo));
Mantid::Kernel::SpecialCoordinateSystem appliedCoord = Mantid::Kernel::QSample;
in_ws->setCoordinateSystem(appliedCoord);
AnalysisDataService::Instance().addOrReplace("BinMDTest_ws", in_ws);

// 1000 boxes with 1 event each
TS_ASSERT_EQUALS( in_ws->getNPoints(), 1000*numEventsPerBox);

Expand All @@ -161,6 +163,7 @@ class BinMDTest : public CxxTest::TestSuite
TS_ASSERT(out);
if(!out) return;

TS_ASSERT_EQUALS(appliedCoord, out->getSpecialCoordinateSystem());
// Took 6x6x6 bins in the middle of the box
TS_ASSERT_EQUALS(out->getNPoints(), expected_numBins);
// Every box has a single event summed into it, so 1.0 weight
Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/test/MergeMDFilesTest.h
Expand Up @@ -48,14 +48,17 @@ class MergeMDFilesTest : public CxxTest::TestSuite

// Create a bunch of input files
std::vector<std::vector<std::string> > filenames;
Mantid::Kernel::SpecialCoordinateSystem appliedCoord = Mantid::Kernel::QSample;
std::vector<MDEventWorkspace3Lean::sptr> inWorkspaces;
// how many events put into each file.
long nFileEvents(1000);
for (size_t i=0; i<3; i++)
{
std::ostringstream mess;
mess << "MergeMDFilesTestInput" << i;
MDEventWorkspace3Lean::sptr ws = MDEventsTestHelper::makeFileBackedMDEW(mess.str(), true,-nFileEvents);
MDEventWorkspace3Lean::sptr ws =
MDEventsTestHelper::makeFileBackedMDEW(mess.str(), true,-nFileEvents, appliedCoord);

inWorkspaces.push_back(ws);
filenames.push_back(std::vector<std::string>(1,ws->getBoxController()->getFilename()));
}
Expand Down Expand Up @@ -87,6 +90,7 @@ class MergeMDFilesTest : public CxxTest::TestSuite
TS_ASSERT(ws);
if (!ws) return;

TS_ASSERT_EQUALS(appliedCoord, ws->getSpecialCoordinateSystem());
TS_ASSERT_EQUALS( ws->getNPoints(), 3*nFileEvents);
MDBoxBase3Lean * box = ws->getBox();
TS_ASSERT_EQUALS( box->getNumChildren(), 1000);
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/test/SliceMDTest.h
Expand Up @@ -137,6 +137,8 @@ class SliceMDTest : public CxxTest::TestSuite
TS_ASSERT( alg.isInitialized() )

IMDEventWorkspace_sptr in_ws = MDEventsTestHelper::makeAnyMDEW<MDE,nd>(10, 0.0, 10.0, 1);
Mantid::Kernel::SpecialCoordinateSystem appliedCoord = Mantid::Kernel::QSample;
in_ws->setCoordinateSystem(appliedCoord);
AnalysisDataService::Instance().addOrReplace("SliceMDTest_ws", in_ws);

TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace", "SliceMDTest_ws") );
Expand Down Expand Up @@ -166,6 +168,8 @@ class SliceMDTest : public CxxTest::TestSuite

TSM_ASSERT_EQUALS("Should default to TakeMaxRecursionDepthFromInput == true", in_ws->getBoxController()->getMaxDepth(), out->getBoxController()->getMaxDepth());

TS_ASSERT_EQUALS(appliedCoord, out->getSpecialCoordinateSystem());

// Took this many events out with the slice
TS_ASSERT_EQUALS(out->getNPoints(), expectedNumPoints);
// Output has this number of dimensions
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/FitMD.cpp
Expand Up @@ -211,6 +211,8 @@ boost::shared_ptr<API::Workspace> FitMD::createEventOutputWorkspace(

// Run information
outputWS->copyExperimentInfos(inputWorkspace);
// Coordinates
outputWS->setCoordinateSystem(inputWorkspace.getSpecialCoordinateSystem());
// Set sensible defaults for splitting behaviour
BoxController_sptr bc = outputWS->getBoxController();
bc->setSplitInto(3);
Expand Down
Expand Up @@ -47,7 +47,8 @@ createDiffractionEventWorkspace(int numEvents, int numPixels = 400,
* @return MDEW sptr
*/
Mantid::MDEvents::MDEventWorkspace3Lean::sptr
makeFileBackedMDEW(std::string wsName, bool fileBacked, long numEvents = 10000);
makeFileBackedMDEW(std::string wsName, bool fileBacked, long numEvents = 10000,
Kernel::SpecialCoordinateSystem coord = Kernel::None);

/// Make a fake n-dimensional MDHistoWorkspace
Mantid::MDEvents::MDHistoWorkspace_sptr
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp
Expand Up @@ -128,11 +128,13 @@ createDiffractionEventWorkspace(int numEvents, int numPixels, int numBins) {
* @return MDEW sptr
*/
MDEventWorkspace3Lean::sptr
makeFileBackedMDEW(std::string wsName, bool fileBacked, long numEvents) {
makeFileBackedMDEW(std::string wsName, bool fileBacked, long numEvents,
Kernel::SpecialCoordinateSystem coord) {
// ---------- Make a file-backed MDEventWorkspace -----------------------
std::string snEvents = boost::lexical_cast<std::string>(numEvents);
MDEventWorkspace3Lean::sptr ws1 =
MDEventsTestHelper::makeMDEW<3>(10, 0.0, 10.0, 0);
ws1->setCoordinateSystem(coord);
ws1->getBoxController()->setSplitThreshold(100);
Mantid::API::AnalysisDataService::Instance().addOrReplace(
wsName, boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(ws1));
Expand Down

0 comments on commit d78fd4d

Please sign in to comment.