Skip to content

Commit

Permalink
refs #10530. Start new algorithm.
Browse files Browse the repository at this point in the history
Needed to expose a few more property types to get this started. All tested.
  • Loading branch information
OwenArnold committed Nov 11, 2014
1 parent 2b7c702 commit 52acb58
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 3 deletions.
Expand Up @@ -34,9 +34,11 @@ set ( EXPORT_FILES
src/Exports/ITableWorkspaceProperty.cpp
src/Exports/MDGeometry.cpp
src/Exports/IMDWorkspace.cpp
src/Exports/IMDWorkspaceProperty.cpp
src/Exports/IMDHistoWorkspace.cpp
src/Exports/IMDHistoWorkspaceProperty.cpp
src/Exports/IMDEventWorkspace.cpp
src/Exports/IMDEventWorkspaceProperty.cpp
src/Exports/MatrixWorkspace.cpp
src/Exports/MatrixWorkspaceProperty.cpp
src/Exports/IEventWorkspace.cpp
Expand Down
@@ -0,0 +1,9 @@
#include "MantidPythonInterface/api/WorkspacePropertyExporter.h"
#include "MantidAPI/IMDEventWorkspace.h"

void export_IMDEventWorkspaceProperty()
{
using Mantid::API::IMDEventWorkspace;
using Mantid::PythonInterface::WorkspacePropertyExporter;
WorkspacePropertyExporter<IMDEventWorkspace>::define("IMDEventWorkspaceProperty");
}
Expand Up @@ -16,11 +16,17 @@ void export_IMDWorkspace()
.value("VolumeNormalization", Mantid::API::VolumeNormalization)
.value("NumEventsNormalization", Mantid::API::NumEventsNormalization);

boost::python::enum_<Mantid::API::SpecialCoordinateSystem>("SpecialCoordinateSystem")
.value("None", Mantid::API::None)
.value("QLab", Mantid::API::QLab)
.value("QSample", Mantid::API::QSample)
.value("HKL", Mantid::API::HKL);

// EventWorkspace class
class_< IMDWorkspace, bases<Workspace, MDGeometry>, boost::noncopyable >("IMDWorkspace", no_init)
.def("getNPoints", &IMDWorkspace::getNPoints, args("self"), "Returns the total number of points within the workspace")
.def("getNEvents", &IMDWorkspace::getNEvents, args("self"), "Returns the total number of events, contributed to the workspace")
;
.def("getSpecialCoordinateSystem", &IMDWorkspace::getSpecialCoordinateSystem, args("self"), "Returns the special coordinate system of the workspace");

DataItemInterface<IMDWorkspace>();
}
Expand Down
@@ -0,0 +1,9 @@
#include "MantidPythonInterface/api/WorkspacePropertyExporter.h"
#include "MantidAPI/IMDWorkspace.h"

void export_IMDWorkspaceProperty()
{
using Mantid::API::IMDWorkspace;
using Mantid::PythonInterface::WorkspacePropertyExporter;
WorkspacePropertyExporter<IMDWorkspace>::define("IMDWorkspaceProperty");
}
@@ -0,0 +1,32 @@
from mantid.kernel import *
from mantid.api import *
from mantid.simpleapi import *
import os.path


class CutMD(DataProcessorAlgorithm):

def category(self):
return 'MDAlgorithms'

def summary(self):
return 'Slices multidimensional workspaces using input projection information'

def PyInit(self):
self.declareProperty(IMDEventWorkspaceProperty('InputWorkspace', '', direction=Direction.Input),
doc='MDWorkspace to slice')

self.declareProperty(IMDWorkspaceProperty('OutputWorkspace', '',
direction=Direction.Output),
doc='Output cut workspace')

def PyExec(self):
to_cut = self.getProperty("InputWorkspace").value

coord_system = to_cut.getSpecialCoordinateSystem()
if not coord_system == SpecialCoordinateSystem.HKL:
raise ValueError("Input Workspace must be in reciprocal lattice dimensions (HKL)")

self.setProperty("OutputWorkspace", to_cut)

AlgorithmFactory.subscribe(CutMD)
Expand Up @@ -10,6 +10,7 @@ set ( TEST_PY_FILES
AnalysisDataServiceTest.py
AxisTest.py
CatalogManagerTest.py
CutMDTest.py
DataProcessorAlgorithmTest.py
DeprecatedAlgorithmCheckerTest.py
ExperimentInfoTest.py
Expand Down
@@ -0,0 +1,25 @@
import unittest
import testhelpers

from mantid.simpleapi import CutMD, CreateMDWorkspace, SetSpecialCoordinates, CompareMDWorkspaces


class CutMDTest(unittest.TestCase):

def test_exec_throws_if_not_a_hkl_workspace(self):
test_md = CreateMDWorkspace(Dimensions=3, Extents="-10,10,-10,10,-10,10", Names="A,B,C", Units="U,U,U")
SetSpecialCoordinates(InputWorkspace=test_md, SpecialCoordinates='Q (lab frame)')
self.assertRaises(RuntimeError, CutMD, InputWorkspace=test_md, OutputWorkspace="out_ws")

def test_slice_to_original(self):
in_md = CreateMDWorkspace(Dimensions=3, Extents="-10,10,-10,10,-10,10", Names="A,B,C", Units="U,U,U")
SetSpecialCoordinates(InputWorkspace=in_md, SpecialCoordinates='HKL')
out_md = CutMD(in_md)
comparison = CompareMDWorkspaces(Workspace1=in_md, Workspace2=out_md)
self.assertTrue(comparison, "Input and output workspaces should be identical" )

def test_run_it(self):
pass

if __name__ == '__main__':
unittest.main()
Expand Up @@ -4,7 +4,8 @@
import unittest
import testhelpers
from mantid.api import (WorkspaceProperty, WorkspaceGroupProperty, MatrixWorkspaceProperty,
IEventWorkspaceProperty, ITableWorkspaceProperty, IMDHistoWorkspaceProperty,
IEventWorkspaceProperty, ITableWorkspaceProperty,
IMDWorkspaceProperty, IMDHistoWorkspaceProperty, IMDEventWorkspaceProperty,
PropertyMode, LockMode)
from mantid.kernel import Direction, Property

Expand Down Expand Up @@ -54,8 +55,14 @@ def test_IEventWorkspaceProperty_can_be_instantiated(self):
def test_ITableWorkspaceProperty_can_be_instantiated(self):
self._do_test(ITableWorkspaceProperty)

def test_IHistoWorkspaceProperty_can_be_instantiated(self):
def test_IMDHistoWorkspaceProperty_can_be_instantiated(self):
self._do_test(IMDHistoWorkspaceProperty)

def test_IMDEventWorkspaceProperty_can_be_instantiated(self):
self._do_test(IMDEventWorkspaceProperty)

def test_IMDWorkspaceProperty_can_be_instantiated(self):
self._do_test(IMDWorkspaceProperty)

if __name__ == "__main__":
unittest.main()

0 comments on commit 52acb58

Please sign in to comment.