Skip to content

Commit

Permalink
API: Added cx.DataPath constructor to take a "/Path/Like/This" string (
Browse files Browse the repository at this point in the history
…#751)

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Oct 24, 2023
1 parent f185948 commit 867a59f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/Plugins/ComplexCore/wrapping/python/complexpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ Result<> ExecutePipeline(Pipeline& pipeline, DataStructure& dataStructure)
return result;
}

complex::DataPath CreateDataPath(std::string_view path)
{
auto result = DataPath::FromString(path);
return result.value();
}

PYBIND11_MODULE(complex, mod)
{
auto* internals = new Internals();
Expand Down Expand Up @@ -364,6 +370,7 @@ PYBIND11_MODULE(complex, mod)
py::class_<DataPath> dataPath(mod, "DataPath");
dataPath.def(py::init<>());
dataPath.def(py::init<std::vector<std::string>>());
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("/")); });
Expand Down
4 changes: 2 additions & 2 deletions wrapping/python/docs/source/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions wrapping/python/docs/source/DataObjects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down Expand Up @@ -60,8 +61,6 @@ any needed DataGroups.
result = cx.CreateDataGroup.execute(data_structure=data_structure,
Data_Object_Path=cx.DataPath(['Group']))
.. _DataPath:

.. _DataArray:

Expand Down
30 changes: 26 additions & 4 deletions wrapping/python/examples/basic_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,7 +61,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
Expand Down Expand Up @@ -77,7 +89,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
Expand Down Expand Up @@ -110,4 +121,15 @@
print('Warnings: {}', result.warnings)
else:
print("No errors running CreateAttributeMatrixFilter filter")




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")

0 comments on commit 867a59f

Please sign in to comment.