diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt index cc0ebaa5c9e1..dfd187eaef05 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt @@ -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 diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDEventWorkspaceProperty.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDEventWorkspaceProperty.cpp new file mode 100644 index 000000000000..c0169c29fc04 --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDEventWorkspaceProperty.cpp @@ -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::define("IMDEventWorkspaceProperty"); +} diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspace.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspace.cpp index 40298057e32c..602eb47f6a7b 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspace.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspace.cpp @@ -16,11 +16,17 @@ void export_IMDWorkspace() .value("VolumeNormalization", Mantid::API::VolumeNormalization) .value("NumEventsNormalization", Mantid::API::NumEventsNormalization); + boost::python::enum_("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, 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(); } diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspaceProperty.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspaceProperty.cpp new file mode 100644 index 000000000000..23299662ed1e --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/IMDWorkspaceProperty.cpp @@ -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::define("IMDWorkspaceProperty"); +} diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/ITableWorkspace.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/ITableWorkspace.cpp index 2d84276064ef..7fba90b07401 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/ITableWorkspace.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/ITableWorkspace.cpp @@ -6,6 +6,7 @@ #include "MantidPythonInterface/kernel/Converters/PySequenceToVector.h" #include "MantidPythonInterface/kernel/Converters/CloneToNumpy.h" #include "MantidPythonInterface/kernel/Registry/DataItemInterface.h" +#include "MantidPythonInterface/kernel/Policies/VectorToNumpy.h" #include #include @@ -339,6 +340,8 @@ namespace void export_ITableWorkspace() { + using Mantid::PythonInterface::Policies::VectorToNumpy; + std::string iTableWorkspace_docstring = "Most of the information from a table workspace is returned "; iTableWorkspace_docstring += "as native copies. All of the column accessors return lists while the "; iTableWorkspace_docstring += "rows return dicts. This object does support the idom 'for row in "; @@ -364,9 +367,9 @@ void export_ITableWorkspace() .def("__len__", &ITableWorkspace::rowCount, "Returns the number of rows within the workspace") - .def("getColumnNames",&ITableWorkspace::getColumnNames, "Return a list of the column names") + .def("getColumnNames",&ITableWorkspace::getColumnNames, boost::python::return_value_policy(),"Return a list of the column names") - .def("keys", &ITableWorkspace::getColumnNames, "Return a list of the column names") + .def("keys", &ITableWorkspace::getColumnNames, boost::python::return_value_policy(), "Return a list of the column names") .def("column", &column, "Return all values of a specific column as a list") diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp index cc323a038306..e83d7784d163 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/src/Exports/Run.cpp @@ -6,6 +6,7 @@ #include "MantidGeometry/Instrument/Goniometer.h" #include +#include "MantidPythonInterface/kernel/Registry/PropertyWithValueFactory.h" using Mantid::API::Run; using Mantid::Kernel::Property; @@ -23,32 +24,20 @@ namespace * @param units A string representing a unit * @param replace If true, replace an existing property with this one else raise an error */ - void addPropertyWithUnit(Run & self, const std::string & name, PyObject *value, const std::string & units, bool replace) + void addPropertyWithUnit(Run & self, const std::string & name, const bpl::object & value, const std::string & units, bool replace) { extract extractor(value); if(extractor.check()) { Property *prop = extractor(); self.addProperty(prop->clone(), replace); // Clone the property as Python owns the one that is passed in + return; } - else if( PyFloat_Check(value) ) - { - self.addProperty(name, extract(value)(), units, replace); - } - else if( PyInt_Check(value) ) - { - self.addProperty(name, extract(value)(), units, replace); - } - else if( PyString_Check(value) ) - { - self.addProperty(name, extract(value)(), units, replace); - } - else - { - std::ostringstream msg; - msg << "Run::addProperty - Unknown value type given: " << value->ob_type->tp_name; - throw std::invalid_argument(msg.str()); - } + + // Use the factory + auto property = Mantid::PythonInterface::Registry::PropertyWithValueFactory::create(name, value, Mantid::Kernel::Direction::Input); + property->setUnits(units); + self.addProperty(property, replace); } /** @@ -58,7 +47,7 @@ namespace * @param value The value of the property * @param replace If true, replace an existing property with this one else raise an error */ - void addProperty(Run & self, const std::string & name, PyObject *value, bool replace) + void addProperty(Run & self, const std::string & name, const bpl::object & value, bool replace) { addPropertyWithUnit(self, name, value, "", replace); } @@ -69,7 +58,7 @@ namespace * @param name The name of the new property * @param value The value of the property */ - void addOrReplaceProperty(Run & self, const std::string & name, PyObject *value) + void addOrReplaceProperty(Run & self, const std::string & name, const bpl::object & value) { addProperty(self, name, value, true); } diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/ITableWorkspaceTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/ITableWorkspaceTest.py index c7ac606f0af5..7ca000a719c5 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/ITableWorkspaceTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/ITableWorkspaceTest.py @@ -19,7 +19,7 @@ def test_meta_information_is_correct(self): column_names = self._test_ws.getColumnNames() self.assertEquals(len(column_names), 19) - self.assertEquals(type(column_names), std_vector_str) + self.assertEquals(type(column_names), list) def test_cell_access_returns_variables_as_native_python_types(self): self.assertAlmostEquals(self._test_ws.cell('r_gd_prtn_chrg',0), 10.040912628173828, 15) diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/WorkspacePropertiesTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/WorkspacePropertiesTest.py index fc302d2482ec..f12bb112c364 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/WorkspacePropertiesTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/WorkspacePropertiesTest.py @@ -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 @@ -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() \ No newline at end of file diff --git a/Code/Mantid/docs/source/algorithms/CreateLogPropertyTable-v1.rst b/Code/Mantid/docs/source/algorithms/CreateLogPropertyTable-v1.rst index a8c6a0df0cc1..a313dd0f1cec 100644 --- a/Code/Mantid/docs/source/algorithms/CreateLogPropertyTable-v1.rst +++ b/Code/Mantid/docs/source/algorithms/CreateLogPropertyTable-v1.rst @@ -87,7 +87,7 @@ Output: .. testoutput:: CreateLogPropertyTable - Column names are: ['run_title','ImportantParameter'] + Column names are: ['run_title', 'ImportantParameter'] The values of the ImportantParameter are: ['1', '2', '3'] .. categories:: diff --git a/Code/Mantid/docs/source/algorithms/PreprocessDetectorsToMD-v1.rst b/Code/Mantid/docs/source/algorithms/PreprocessDetectorsToMD-v1.rst index fc725acb8156..f2ef5646edfe 100644 --- a/Code/Mantid/docs/source/algorithms/PreprocessDetectorsToMD-v1.rst +++ b/Code/Mantid/docs/source/algorithms/PreprocessDetectorsToMD-v1.rst @@ -82,7 +82,7 @@ Usage .. testoutput:: ExPreprocessDetectoresToMD The resulting table has the following columns: - ['DetDirections','L2','TwoTheta','Azimuthal','DetectorID','detIDMap','spec2detMap','detMask','eFixed'] + ['DetDirections', 'L2', 'TwoTheta', 'Azimuthal', 'DetectorID', 'detIDMap', 'spec2detMap', 'detMask', 'eFixed'] The number of rows in the workspace is : 918 The polar angle for detector N 10 is 0.314159 rad The table workspace logs (properties) are currently not availible from python