From 578465b50f956b1938afd47fc92a510182b55c6b Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 10 Oct 2023 17:01:31 -0400 Subject: [PATCH] API: Added cx.DataPath constructor to take a "/Path/Like/This" string Signed-off-by: Michael Jackson --- .../ComplexCore/wrapping/python/complexpy.cpp | 7 +++++ wrapping/python/docs/source/API.rst | 4 +-- wrapping/python/docs/source/DataObjects.rst | 3 +- wrapping/python/examples/basic_arrays.py | 30 ++++++++++++++++--- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp b/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp index 6254d876f1..6b3244e6f6 100644 --- a/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp +++ b/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp @@ -269,6 +269,12 @@ Result<> ExecutePipeline(Pipeline& pipeline, DataStructure& dataStructure) return result; } +complex::DataPath CreateDataPath(const std::string& path) +{ + auto result = DataPath::FromString(path); + return result.value(); +} + PYBIND11_MODULE(complex, mod) { auto* internals = new Internals(); @@ -377,6 +383,7 @@ PYBIND11_MODULE(complex, mod) py::class_ dataPath(mod, "DataPath"); dataPath.def(py::init<>()); dataPath.def(py::init>()); + dataPath.def(py::init<>(&CreateDataPath)); dataPath.def("__getitem__", [](const DataPath& self, usize index) { return self[index]; }); dataPath.def("__repr__", [](const DataPath& self) { return fmt::format("DataPath('{}')", self.toString("/")); }); dataPath.def("__str__", [](const DataPath& self) { return fmt::format("DataPath('{}')", self.toString("/")); }); diff --git a/wrapping/python/docs/source/API.rst b/wrapping/python/docs/source/API.rst index aa008175e1..8cd49b0d91 100644 --- a/wrapping/python/docs/source/API.rst +++ b/wrapping/python/docs/source/API.rst @@ -31,7 +31,7 @@ General Parameters .. code:: python - data_path = cx.DataPath(["Small IN100", "Scan Data", "Data"]) + data_path = cx.DataPath("Small IN100/Scan Data/Data") .. _ArraySelectionParameter: .. py:class:: ArraySelectionParameter @@ -41,7 +41,7 @@ General Parameters .. code:: python - data_path = cx.DataPath(["Small IN100", "Scan Data", "Data"]) + data_path = cx.DataPath("Small IN100/Scan Data/Data") .. _ArrayThresholdsParameter: .. py:class:: ArrayThresholdsParameter diff --git a/wrapping/python/docs/source/DataObjects.rst b/wrapping/python/docs/source/DataObjects.rst index 8527f1b16e..435f0f39ed 100644 --- a/wrapping/python/docs/source/DataObjects.rst +++ b/wrapping/python/docs/source/DataObjects.rst @@ -30,6 +30,7 @@ This is the abstract base class for all other objects that can be inserted into DataStructure_ . It should never be used as the appropriate class from the list below should be used instead. +.. _DataPath: DataPath --------- @@ -60,8 +61,6 @@ any needed DataGroups. result = cx.CreateDataGroup.execute(data_structure=data_structure, Data_Object_Path=cx.DataPath(['Group'])) -.. _DataPath: - .. _DataArray: diff --git a/wrapping/python/examples/basic_arrays.py b/wrapping/python/examples/basic_arrays.py index dbc73bb0ac..c202cd8e5b 100644 --- a/wrapping/python/examples/basic_arrays.py +++ b/wrapping/python/examples/basic_arrays.py @@ -13,7 +13,20 @@ # Create a top level group: (Not needed) #------------------------------------------------------------------------------ result = cx.CreateDataGroup.execute(data_structure=data_structure, - Data_Object_Path=cx.DataPath(['Group'])) + data_object_path=cx.DataPath(['Group'])) +if len(result.errors) != 0: + print('Errors: {}', result.errors) + print('Warnings: {}', result.warnings) +else: + print("No errors running CreateDataGroup filter") + +result = cx.CreateDataGroup.execute(data_structure=data_structure, + data_object_path=cx.DataPath("/Some/Path/To/Group")); +if len(result.errors) != 0: + print('Errors: {}', result.errors) + print('Warnings: {}', result.warnings) +else: + print("No errors running CreateDataGroup filter") #------------------------------------------------------------------------------ # Create 1D Array @@ -43,7 +56,6 @@ #------------------------------------------------------------------------------ # Create 2D Array #------------------------------------------------------------------------------ -data_structure = cx.DataStructure() # Create a 2D Array with dimensions 2, 5 where the 5 is the fastest moving dimension. # Example, and Image where 5 wide x 2 High @@ -70,7 +82,6 @@ #------------------------------------------------------------------------------ # Create 3D Array #------------------------------------------------------------------------------ -data_structure = cx.DataStructure() # Create a 3D Array with dimensions 3, 2, 5 where the 5 is the fastest moving dimension. # Example, and Image where 5 wide x 2 High @@ -101,4 +112,15 @@ print('Warnings: {}', result.warnings) else: print("No errors running CreateAttributeMatrixFilter filter") - \ No newline at end of file + + + +output_file_path = "/tmp/output_file_example.dream3d" +result = cx.ExportDREAM3DFilter.execute(data_structure=data_structure, + export_file_path=output_file_path, + write_xdmf_file=True) +if len(result.errors) != 0: + print('Errors: {}', result.errors) + print('Warnings: {}', result.warnings) +else: + print("No errors running the filter") \ No newline at end of file