Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needed to expose a few more property types to get this started. All tested.
- Loading branch information
1 parent
2b7c702
commit 52acb58
Showing
8 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDEventWorkspaceProperty.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspaceProperty.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
32 changes: 32 additions & 0 deletions
32
Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters