diff --git a/CMakePresets.json b/CMakePresets.json index 3f82c32354..d3540632ee 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -129,6 +129,10 @@ "Python3_EXECUTABLE": { "type": "PATH", "value": "/Users/runner/hostedtoolcache/Python/3.10.13/x64/bin/python3.10" + }, + "COMPLEX_PY_DISABLE_HIDDEN_VISIBILITY": { + "type": "BOOL", + "value": "ON" } } }, @@ -146,6 +150,14 @@ "VCPKG_HOST_TRIPLET": { "type": "STRING", "value": "arm64-osx-dynamic" + }, + "Python3_EXECUTABLE": { + "type": "PATH", + "value": "/Users/runner/hostedtoolcache/Python/3.10.13/x64/bin/python3.10" + }, + "COMPLEX_PY_DISABLE_HIDDEN_VISIBILITY": { + "type": "BOOL", + "value": "ON" } } }, diff --git a/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp b/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp index 288f07a335..6b746e5ee9 100644 --- a/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp +++ b/src/Plugins/ComplexCore/wrapping/python/complexpy.cpp @@ -544,8 +544,11 @@ PYBIND11_MODULE(complex, mod) std::vector outputPaths; for(const auto* object : self.getTopLevelData()) { - auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value(); - outputPaths.push_back(topLevelPath); + if(object != nullptr) + { + auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value(); + outputPaths.push_back(topLevelPath); + } } return outputPaths; } diff --git a/src/complex/Utilities/DataGroupUtilities.cpp b/src/complex/Utilities/DataGroupUtilities.cpp index a1a4bef254..15a58f3671 100644 --- a/src/complex/Utilities/DataGroupUtilities.cpp +++ b/src/complex/Utilities/DataGroupUtilities.cpp @@ -186,7 +186,6 @@ std::optional> GetAllChildDataPaths(const DataStructure& d { bool ignore = false; DataPath childPath = parentGroup.createChildPath(childName); - const DataObject* dataObject = dataStructure.getData(childPath); for(const auto& ignoredPath : ignoredDataPaths) { if(childPath == ignoredPath) @@ -195,7 +194,8 @@ std::optional> GetAllChildDataPaths(const DataStructure& d break; } } - if(!ignore && (dataObjectType == DataObject::Type::DataObject || dataObject->getDataObjectType() == dataObjectType)) + const DataObject* dataObject = dataStructure.getData(childPath); + if(dataObject != nullptr && !ignore && (dataObjectType == DataObject::Type::DataObject || dataObject->getDataObjectType() == dataObjectType)) { childDataObjects.push_back(childPath); } @@ -211,7 +211,7 @@ std::optional> GetAllChildDataPaths(const DataStructure& d { std::vector childDataObjects; const DataObject* dataObject1 = dataStructure.getData(parent); - if(dataObject1->getDataObjectType() == DataObject::Type::DataArray || dataObject1->getDataObjectType() == DataObject::Type::DynamicListArray || + if(dataObject1 == nullptr || dataObject1->getDataObjectType() == DataObject::Type::DataArray || dataObject1->getDataObjectType() == DataObject::Type::DynamicListArray || dataObject1->getDataObjectType() == DataObject::Type::NeighborList || dataObject1->getDataObjectType() == DataObject::Type::ScalarData || dataObject1->getDataObjectType() == DataObject::Type::StringArray) { diff --git a/wrapping/python/CMakeLists.txt b/wrapping/python/CMakeLists.txt index 19bb3d13c8..947baba19e 100644 --- a/wrapping/python/CMakeLists.txt +++ b/wrapping/python/CMakeLists.txt @@ -300,18 +300,19 @@ if(COMPLEX_ENABLE_PYTHON_TESTS) set(PYTHON_TEST_INPUT_DIR "${complex_SOURCE_DIR}/wrapping/python/examples") set(COMPLEX_PYTHON_TESTS + "angle_conversion" + "basic_arrays" "basic_ebsd_ipf" - "import_d3d" - # "angle_conversion" - # "basic_arrays" - # "basic_numpy" - # "create_ensemble_info" - # "generated_file_list" - # "geometry_examples" - # "import_hdf5" - # "output_file" - # "pipeline" - # "read_csv_file" + "basic_numpy" + "create_ensemble_info" + "generated_file_list" + "geometry_examples" + "import_d3d" # Dependent on 'basic_ebsd_ipf' running first + "import_hdf5" # Dependent on 'basic_ebsd_ipf' running first + "output_file" + "pipeline" + "read_csv_file" + # "read_esprit_data" ) CreatePythonTests(PREFIX "PY_COMPLEX" diff --git a/wrapping/python/CxPybind/CxPybind/CxPybind.hpp b/wrapping/python/CxPybind/CxPybind/CxPybind.hpp index da4e033fbd..5847084a60 100644 --- a/wrapping/python/CxPybind/CxPybind/CxPybind.hpp +++ b/wrapping/python/CxPybind/CxPybind/CxPybind.hpp @@ -397,7 +397,18 @@ auto BindFilter(py::handle scope, const Internals& internals) std::string executeSig = MakePythonSignature("execute", internals); std::string executeDocString = fmt::format("{}\n\nExecutes the filter\n", executeSig); - + filter.def_static("human_name", [&internals]() { + FilterT filter; + return filter.humanName(); + }); + filter.def_static("name", [&internals]() { + FilterT filter; + return filter.name(); + }); + filter.def_static("uuid", [&internals]() { + FilterT filter; + return filter.uuid(); + }); filter.def_static( "execute", [&internals](DataStructure& dataStructure, const py::kwargs& kwargs) { diff --git a/wrapping/python/complex_test_dirs.in.py b/wrapping/python/complex_test_dirs.in.py index 3b489cd664..e1a6881026 100644 --- a/wrapping/python/complex_test_dirs.in.py +++ b/wrapping/python/complex_test_dirs.in.py @@ -6,6 +6,21 @@ ''' + +import complex as cx + +def check_filter_result(filter: cx.IFilter, result: cx.IFilter.ExecuteResult): + if len(result.warnings) != 0: + print(f'{filter.name()} :: Warnings: {result.warnings}') + + has_errors = len(result.errors) != 0 + if has_errors: + print(f'{filter.name()} :: Errors: {result.errors}') + raise RuntimeError(result) + + print(f"{filter.name()} :: No errors running the filter") + + def GetBuildDirectory(): return '${CMAKE_LIBRARY_OUTPUT_DIRECTORY}' @@ -23,3 +38,13 @@ def GetComplexPythonSourceDir(): def GetComplexSourceDir(): return '${complex_SOURCE_DIR}' + +def print_all_paths(): + print(f'#### Important Filesystem Paths ####') + print(f' GetBuildDirectory: {GetBuildDirectory()}') + print(f' GetTestDirectory: {GetTestDirectory()}') + print(f' GetTestTempDirectory: {GetTestTempDirectory()}') + print(f' GetDataDirectory: {GetDataDirectory()}') + print(f' GetComplexPythonSourceDir: {GetComplexPythonSourceDir()}') + print(f' GetComplexSourceDir: {GetComplexSourceDir()}') + print('#######################################') \ No newline at end of file diff --git a/wrapping/python/docs/source/Overview.rst b/wrapping/python/docs/source/Overview.rst index 4215779c51..e4ec52a525 100644 --- a/wrapping/python/docs/source/Overview.rst +++ b/wrapping/python/docs/source/Overview.rst @@ -181,7 +181,49 @@ form a **Pipeline**, in which the data structure flows through the set of **Filt being modified along the way. If a **Filter** reads in data from outside of DREAM3D-NX, then the new data will be incorporated into the existing data structure. Or, if no data structure yet exists (e.g, starting from a “blank slate”), a new one will be -created. +created. + +.. py:class:: complex.IFilter + + This class holds an instantiation of a DREAM3D-NX filter. The filter can be + preflighted, executed or just held for later execution. + + .. py:method:: name() + + :return: The C++ classname of the filter + :rtype: str + + .. py:method:: human_name() + + :return: What the user would see in the DREAM3D-NX application + :rtype: str + + .. py:method:: uuid() + + :return: The unique identifier of the filter + :rtype: str + + .. py:method:: execute() + + :return: A complex.IFilter.Result object that contains any warnings or errors + that were encountered during the execution of the filter. + :rtype: complex.IFilter.Result + + .. py:method:: preflight() + + :return: A complex.IFilter.Result object that contains any warnings or errors + that were encountered during the preflight of the filter. + :rtype: complex.IFilter.Result + +.. code:: python + + create_array_filter = cx.CreateDataArray() + print(f'{create_array_filter.name()}') + print(f'{create_array_filter.human_name()}') + print(f'{create_array_filter.uuid()}') + +For examles of executing a filter, please see any of the example python files included +with the source package. .. _Pipeline: .. _Plugin: diff --git a/wrapping/python/examples/angle_conversion.py b/wrapping/python/examples/angle_conversion.py index 697c0fd962..c8acad9b37 100644 --- a/wrapping/python/examples/angle_conversion.py +++ b/wrapping/python/examples/angle_conversion.py @@ -1,4 +1,40 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk @@ -7,6 +43,10 @@ import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() # ------------------------------------------------------------------------------ @@ -22,11 +62,8 @@ tuple_dimensions=[[99]], output_data_array=array_path, initialization_value='0') -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray") +cxtest.check_filter_result(cx.CreateDataArray, result) + # Get a numpy.view into the newly created DataArray data_array = data_structure[array_path] @@ -48,11 +85,8 @@ input_type=0, output_orientation_array_name='Quaternions', output_type=2) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ConvertOrientations") +cxtest.check_filter_result(cxor.ConvertOrientations, result) + # Get the Quaternions and print them out. data_array = data_structure[quat_path] diff --git a/wrapping/python/examples/basic_arrays.py b/wrapping/python/examples/basic_arrays.py index 070fd9a1f4..20f0178e3c 100644 --- a/wrapping/python/examples/basic_arrays.py +++ b/wrapping/python/examples/basic_arrays.py @@ -1,11 +1,53 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk import orientationanalysis as cxor +import complex_test_dirs as cxtest import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + # Create a Data Structure data_structure = cx.DataStructure() @@ -14,19 +56,13 @@ #------------------------------------------------------------------------------ result = cx.CreateDataGroup.execute(data_structure=data_structure, 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") +cxtest.check_filter_result(cx.CreateDataGroup, result) + 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") +cxtest.check_filter_result(cx.CreateDataGroup, result) + #------------------------------------------------------------------------------ # Create 1D Array @@ -43,11 +79,8 @@ numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + # We can check the output of the filter by simply printing the array npdata = data_structure[output_array_path].npview() @@ -69,11 +102,8 @@ numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + data_array = data_structure[output_array_path] print(f'name: {data_array.name}') @@ -101,11 +131,8 @@ numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + npdata = data_structure[output_array_path].npview() print(npdata) @@ -113,23 +140,16 @@ result = cx.CreateAttributeMatrixFilter.execute(data_structure=data_structure, data_object_path=cx.DataPath(["New Attribute Matrix"]), tuple_dimensions = [[100., 200., 300.]]) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running CreateAttributeMatrixFilter filter") +cxtest.check_filter_result(cx.CreateAttributeMatrixFilter, result) -output_file_path = "/tmp/output_file_example.dream3d" +output_file_path = cxtest.GetTestTempDirectory() + "/output_file_example.dream3d" result = cx.WriteDREAM3DFilter.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") +cxtest.check_filter_result(cx.WriteDREAM3DFilter, result) + #------------------------------------------------------------------------------ diff --git a/wrapping/python/examples/basic_ebsd_ipf.py b/wrapping/python/examples/basic_ebsd_ipf.py index e17ba116e7..73ed691999 100644 --- a/wrapping/python/examples/basic_ebsd_ipf.py +++ b/wrapping/python/examples/basic_ebsd_ipf.py @@ -1,4 +1,40 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk @@ -7,6 +43,10 @@ import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() #------------------------------------------------------------------------------ # Create a Data Structure @@ -18,12 +58,9 @@ cell_attribute_matrix_name="Scan Data", cell_ensemble_attribute_matrix_name="Phase Data", data_container_name=cx.DataPath(["Small IN100"]), - input_file=cxtest.GetDataDirectory() + "/Data/SmallIN100/Slice_1.ang") -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ReadAngDataFilter") + input_file=cxtest.GetBuildDirectory() + "/Data/Small_IN100/Slice_1.ang") + +cxtest.check_filter_result(cxor.ReadAngDataFilter, result) #------------------------------------------------------------------------------ # Rotate the Euler Reference Frame @@ -31,12 +68,7 @@ result = cxor.RotateEulerRefFrameFilter.execute(data_structure=data_structure, euler_angles_array_path=cx.DataPath(["Small IN100", "Scan Data", "EulerAngles"]), rotation_axis=[0,0,1,90]) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the RotateEulerRefFrameFilter") - +cxtest.check_filter_result(cxor.RotateEulerRefFrameFilter, result) #------------------------------------------------------------------------------ # Rotate the Sample Reference Frame 180@010 @@ -50,11 +82,8 @@ selected_image_geometry=cx.DataPath(["Small IN100"]), #rotation_matrix=[[1,0,0],[0,1,0],[0,0,1]] ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the RotateEulerRefFrameFilter") +cxtest.check_filter_result(cx.RotateSampleRefFrameFilter, result) + #------------------------------------------------------------------------------ # Create a ThresholdSet to use in the MultiThreshold Objects filter @@ -77,11 +106,8 @@ array_thresholds=threshold_set, created_data_path="Mask", created_mask_type=cx.DataType.boolean) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the MultiThresholdObjects") +cxtest.check_filter_result(cx.MultiThresholdObjects, result) + #------------------------------------------------------------------------------ # Generate the IPF Colors for the <001> direction @@ -95,28 +121,20 @@ reference_dir=[0,0,1], use_mask=True ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the GenerateIPFColorsFilter") +cxtest.check_filter_result(cxor.GenerateIPFColorsFilter, result) + #------------------------------------------------------------------------------ # Write the IPF colors to a PNG file #------------------------------------------------------------------------------ -result = cxitk.ITKImageWriter.execute(data_structure=data_structure, file_name=cxtest.GetTestTempDirectory() + "/Small_IN100_IPF_Z.png", +result = cxitk.ITKImageWriter.execute(data_structure=data_structure, + file_name=cxtest.GetTestTempDirectory() + "/Small_IN100_IPF_Z.png", image_array_path=cx.DataPath(["Small IN100", "Scan Data", "IPFColors"]), image_geom_path=cx.DataPath(["Small IN100"]), index_offset=0, plane=0) - -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ITKImageWriter") - +cxtest.check_filter_result(cxitk.ITKImageWriter, result) # #------------------------------------------------------------------------------ # # Show the IPFColors using MatPlotLib @@ -143,11 +161,8 @@ output_rgb_array_name="CI Color", selected_data_array_path=cx.DataPath(["Small IN100", "Scan Data", "Confidence Index"]), selected_preset=color_control_points) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the GenerateColorTableFilter") +cxtest.check_filter_result(cx.GenerateColorTableFilter, result) + #------------------------------------------------------------------------------ # Create a Pole Figure @@ -166,16 +181,13 @@ lambert_size=64, material_name_array_path=cx.DataPath(["Small IN100", "Phase Data", "MaterialName"]), num_colors=32, - output_path="small_in100_pole_figure", + output_path=cxtest.GetTestTempDirectory() + "/small_in100_pole_figure", save_as_image_geometry=True, title="Small IN100 Slice 1", use_mask=True, write_image_to_disk=True) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the WritePoleFigureFilter") +cxtest.check_filter_result(cxor.WritePoleFigureFilter, result) + #------------------------------------------------------------------------------ @@ -183,13 +195,7 @@ #------------------------------------------------------------------------------ output_file_path = cxtest.GetTestTempDirectory() + "/basic_ebsd_example.dream3d" -print(f'{output_file_path}') result = cx.WriteDREAM3DFilter.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 WriteDREAM3DFilter") - +cxtest.check_filter_result(cx.WriteDREAM3DFilter, result) diff --git a/wrapping/python/examples/basic_numpy.py b/wrapping/python/examples/basic_numpy.py index 406c435d52..32a6a6a8f7 100644 --- a/wrapping/python/examples/basic_numpy.py +++ b/wrapping/python/examples/basic_numpy.py @@ -1,4 +1,44 @@ +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx +import complex_test_dirs as cxtest + + import numpy as np @@ -34,7 +74,8 @@ radians_data = np.radians(degrees_data) # Run a D3D filter to convert back to degrees -assert cx.ChangeAngleRepresentation.execute(data_structure, conversion_type=0, angles_array_path=array_path) +result = cx.ChangeAngleRepresentation.execute(data_structure, conversion_type=0, angles_array_path=array_path) +cxtest.check_filter_result(cx.ChangeAngleRepresentation, result) # compare the 2 arrays assert np.array_equal(npdata, radians_data) diff --git a/wrapping/python/examples/create_ensemble_info.py b/wrapping/python/examples/create_ensemble_info.py index 32420de23d..6456be19e9 100644 --- a/wrapping/python/examples/create_ensemble_info.py +++ b/wrapping/python/examples/create_ensemble_info.py @@ -1,11 +1,53 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk import orientationanalysis as cxor +import complex_test_dirs as cxtest import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + # Create a Data Structure data_structure = cx.DataStructure() @@ -21,9 +63,4 @@ phase_types_array_name="Primary", ensemble=ensemble_info_parameter ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the filter") - +cxtest.check_filter_result(cxor.CreateEnsembleInfoFilter, result) diff --git a/wrapping/python/examples/generated_file_list.py b/wrapping/python/examples/generated_file_list.py index 27518b700b..df6db82d18 100644 --- a/wrapping/python/examples/generated_file_list.py +++ b/wrapping/python/examples/generated_file_list.py @@ -1,17 +1,60 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk import orientationanalysis as cxor +import complex_test_dirs as cxtest import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pre-generated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + + # Create a Data Structure data_structure = cx.DataStructure() generated_file_list_value = cx.GeneratedFileListParameter.ValueType() -generated_file_list_value.input_path = "Data/Porosity_Image" +generated_file_list_value.input_path = cxtest.GetBuildDirectory() + "/Data/Porosity_Image" generated_file_list_value.ordering = cx.GeneratedFileListParameter.Ordering.LowToHigh generated_file_list_value.file_prefix = "slice_" @@ -30,8 +73,4 @@ input_file_list_info=generated_file_list_value, origin=[0., 0., 0.], spacing=[1., 1.,1.]) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the filter") +cxtest.check_filter_result(cxitk.ITKImportImageStack, result) diff --git a/wrapping/python/examples/geometry_examples.py b/wrapping/python/examples/geometry_examples.py index 95d38434ff..2154c2ec70 100644 --- a/wrapping/python/examples/geometry_examples.py +++ b/wrapping/python/examples/geometry_examples.py @@ -1,3 +1,40 @@ +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk @@ -6,6 +43,11 @@ import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + """ In the code below we are using some data files that are found in the complex source code repository. It will up to the programmer to correctly set the paths @@ -23,11 +65,8 @@ geometry_type=0, # 0 = Image Geometry origin=[0.0, 0.0, 0.0], spacing=[1.0, 1.0, 1.0]) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateGeometryFilter filter") +cxtest.check_filter_result(cx.CreateGeometryFilter, result) + data_object = data_structure["Image Geometry"] print(f'data_object: {type(data_object)}') @@ -47,11 +86,8 @@ result = create_array_filter.execute(data_structure=data_structure, component_count=1, data_format="", initialization_value="10", numeric_type=array_type, output_data_array=output_array_path) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + # ------------------------------------------------------------------------------ # Lets try a Rectilinear Grid Geometry @@ -76,11 +112,8 @@ numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + x_coords = data_structure[output_array_path].npview() x_coords = np.squeeze(x_coords, axis=1) @@ -97,11 +130,8 @@ numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + y_coords = data_structure[output_array_path].npview() y_coords = np.squeeze(y_coords, axis=1) @@ -118,11 +148,8 @@ numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + z_coords = data_structure[output_array_path].npview() z_coords = np.squeeze(z_coords, axis=1) @@ -137,11 +164,8 @@ y_bounds=cx.DataPath("RectGridCoords/Y Coords"), z_bounds=cx.DataPath("RectGridCoords/Z Coords") ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateGeometryFilter filter") +cxtest.check_filter_result(cx.CreateGeometryFilter, result) + rect_grid_geom = data_structure["RectGrid Geometry"] x_cell_count = rect_grid_geom.num_x_cells @@ -162,11 +186,8 @@ tuple_dimensions=[[144]], output_data_array=array_path, initialization_value='0') -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + # Read the CSV file into the DataArray using the numpy view vertex_coords = data_structure[array_path].npview() @@ -180,11 +201,8 @@ tuple_dimensions=[[242]], output_data_array=array_path, initialization_value='0') -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + # Read the CSV file into the DataArray using the numpy view triangles = data_structure[array_path].npview() file_path = cxtest.GetComplexSourceDir() + '/test/Data/TriangleConnectivity.csv' @@ -200,11 +218,8 @@ vertex_list_name=cx.DataPath('Vertices'), triangle_list_name=cx.DataPath('Triangles') ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateGeometryFilter (Triangle) filter") +cxtest.check_filter_result(cx.CreateGeometryFilter, result) + # ------------------------------------------------------------------------------ # Lets try a Edge Geometry @@ -217,11 +232,8 @@ tuple_dimensions=[[144]], output_data_array=array_path, initialization_value='0') -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + # Read the CSV file into the DataArray using the numpy view vertex_coords = data_structure[array_path].npview() @@ -235,11 +247,8 @@ tuple_dimensions=[[264]], output_data_array=array_path, initialization_value='0') -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateDataArray filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + # Read the CSV file into the DataArray using the numpy view file_path = cxtest.GetComplexSourceDir() + '/test/Data/EdgeConnectivity.csv' @@ -255,17 +264,11 @@ vertex_list_name=cx.DataPath('Vertices'), edge_list_name=cx.DataPath('Edges') ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the CreateGeometryFilter (Edge) filter") +cxtest.check_filter_result(cx.CreateGeometryFilter, result) + output_file_path = cxtest.GetTestTempDirectory() + "/geometry_examples.dream3d" result = cx.WriteDREAM3DFilter.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 WriteDREAM3DFilter filter") +cxtest.check_filter_result(cx.WriteDREAM3DFilter, result) + diff --git a/wrapping/python/examples/import_d3d.py b/wrapping/python/examples/import_d3d.py index 23cf04240f..e516f24f44 100644 --- a/wrapping/python/examples/import_d3d.py +++ b/wrapping/python/examples/import_d3d.py @@ -1,3 +1,40 @@ +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk @@ -6,6 +43,10 @@ import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() # Create the DataStructure object data_structure = cx.DataStructure() @@ -17,12 +58,7 @@ print(f'{import_data.file_path}') result = cx.ReadDREAM3DFilter.execute(data_structure=data_structure, import_file_data=import_data) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ReadDREAM3DFilter filter") - +cxtest.check_filter_result(cx.ReadDREAM3DFilter, result) #------------------------------------------------------------------------------ # Print out the children of some of the Attribute Matrix groups @@ -51,8 +87,5 @@ result = cx.WriteDREAM3DFilter.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 WriteDREAM3DFilter") +cxtest.check_filter_result(cx.WriteDREAM3DFilter, result) + diff --git a/wrapping/python/examples/import_hdf5.py b/wrapping/python/examples/import_hdf5.py index 40e78c7530..3a9aab74de 100644 --- a/wrapping/python/examples/import_hdf5.py +++ b/wrapping/python/examples/import_hdf5.py @@ -1,9 +1,53 @@ +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk import orientationanalysis as cxor +import complex_test_dirs as cxtest import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + + # Create the DataStructure object data_structure = cx.DataStructure() @@ -26,26 +70,21 @@ ) dataset1 = cx.ReadHDF5DatasetParameter.DatasetImportInfo() -dataset1.dataset_path = "/DataStructure/DataContainer/CellData/Confidence Index" -dataset1.tuple_dims = "117,201,189" +dataset1.dataset_path = "/DataStructure/Small IN100/Scan Data/Confidence Index" +dataset1.tuple_dims = "1,201,189" dataset1.component_dims = "1" dataset2 = cx.ReadHDF5DatasetParameter.DatasetImportInfo() -dataset2.dataset_path = "/DataStructure/DataContainer/CellData/EulerAngles" -dataset2.tuple_dims = "117,201,189" +dataset2.dataset_path = "/DataStructure/Small IN100/Scan Data/EulerAngles" +dataset2.tuple_dims = "1,201,189" dataset2.component_dims = "3" import_hdf5_param = cx.ReadHDF5DatasetParameter.ValueType() -import_hdf5_param.input_file = "Data/Output/Reconstruction/SmallIN100_Final.dream3d" +import_hdf5_param.input_file = cxtest.GetTestTempDirectory() + "/basic_ebsd_example.dream3d" import_hdf5_param.datasets = [dataset1, dataset2] # import_hdf5_param.parent = cx.DataPath(["Imported Data"]) result = cx.ReadHDF5Dataset.execute(data_structure=data_structure, import_hd_f5_file=import_hdf5_param ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ReadHDF5DatasetParameter filter") - +cxtest.check_filter_result(cx.ReadHDF5Dataset, result) diff --git a/wrapping/python/examples/output_file.py b/wrapping/python/examples/output_file.py index e63cdc6316..89c1d99fb1 100644 --- a/wrapping/python/examples/output_file.py +++ b/wrapping/python/examples/output_file.py @@ -1,11 +1,53 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk import orientationanalysis as cxor +import complex_test_dirs as cxtest import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + # Let's get a data array created to have something to write. # Create a Data Structure @@ -19,22 +61,14 @@ create_array_filter = cx.CreateDataArray() result = create_array_filter.execute(data_structure=data_structure, component_count=1, data_format="", initialization_value="10", numeric_type=array_type, output_data_array=output_array_path, tuple_dimensions=tuple_dims) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the filter") +cxtest.check_filter_result(cx.CreateDataArray, result) + npdata = data_structure[output_array_path].npview() print(npdata) -output_file_path = "output_file_example.dream3d" +output_file_path = cxtest.GetTestTempDirectory() + "/output_file_example.dream3d" result = cx.WriteDREAM3DFilter.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") - +cxtest.check_filter_result(cx.WriteDREAM3DFilter, result) diff --git a/wrapping/python/examples/pipeline.py b/wrapping/python/examples/pipeline.py index 653a9ecf62..f3d1af3f0b 100644 --- a/wrapping/python/examples/pipeline.py +++ b/wrapping/python/examples/pipeline.py @@ -1,4 +1,40 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk @@ -7,6 +43,11 @@ import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + data_structure = cx.DataStructure() pipeline = cx.Pipeline().from_file(cxtest.GetComplexSourceDir() + '/src/Plugins/OrientationAnalysis/pipelines/EBSD Reconstruction/(01) Small IN100 Archive.d3dpipeline') diff --git a/wrapping/python/examples/read_csv_file.py b/wrapping/python/examples/read_csv_file.py index b34fd65eb3..04586cbe9c 100644 --- a/wrapping/python/examples/read_csv_file.py +++ b/wrapping/python/examples/read_csv_file.py @@ -1,14 +1,57 @@ +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk import orientationanalysis as cxor +import complex_test_dirs as cxtest import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() + # Create the DataStructure object data_structure = cx.DataStructure() # This file has 7 columns to import read_csv_data = cx.ReadCSVDataParameter() -read_csv_data.input_file_path = "wrapping/python/examples/test_csv_data.csv" +read_csv_data.input_file_path = cxtest.GetComplexPythonSourceDir() + "/examples/test_csv_data.csv" read_csv_data.start_import_row = 2 read_csv_data.delimiters = [','] read_csv_data.custom_headers = [] @@ -29,8 +72,4 @@ # The ReadCSVData object with all member variables set. read_csv_data=read_csv_data # The ReadCSVData object with all member variables set. ) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ReadCSVFileFilter filter") +cxtest.check_filter_result(cx.ReadCSVFileFilter, result) diff --git a/wrapping/python/examples/read_esprit_data.py b/wrapping/python/examples/read_esprit_data.py index 17c19dbf0a..02066c93b7 100644 --- a/wrapping/python/examples/read_esprit_data.py +++ b/wrapping/python/examples/read_esprit_data.py @@ -1,4 +1,40 @@ -# Import the DREAM3D Base library and Plugins +""" +Important Note +============== + +This python file can be used as an example of how to execute a number of DREAM3D-NX +filters one after another, if you plan to use the codes below (and you are welcome to), +there are a few things that you, the developer, should take note of: + +Import Statements +----------------- + +You will most likely *NOT* need to include the following code: + + .. code:: python + + import complex_test_dirs as cxtest + +Filter Error Detection +---------------------- + +In each section of code a filter is created and executed immediately. This may or +may *not* be what you want to do. You can also preflight the filter to verify the +correctness of the filters before executing the filter **although** this is done +for you when the filter is executed. As such, you will want to check the 'result' +variable to see if there are any errors or warnings. If there **are** any then +you, as the developer, should act appropriately on the errors or warnings. +More specifically, this bit of code: + + .. code:: python + + cxtest.check_filter_result(cxor.ReadAngDataFilter, result) + +is used by the simplnx unit testing framework and should be replaced by your own +error checking code. You are welcome to look up the function definition and use +that. + +""" import complex as cx import itkimageprocessing as cxitk @@ -7,6 +43,10 @@ import numpy as np +#------------------------------------------------------------------------------ +# Print the various filesystem paths that are pregenerated for this machine. +#------------------------------------------------------------------------------ +cxtest.print_all_paths() # ------------------------------------------------------------------------------ @@ -30,14 +70,7 @@ selected_scan_names = param1, z_spacing = 1.0) -if len(result.errors) != 0: - print('Errors: {}', result.errors) - print('Warnings: {}', result.warnings) -else: - print("No errors running the ReadH5EspritDataFilter") - - - +cxtest.check_filter_result(cxor.ReadH5EspritDataFilter, result) #------------------------------------------------------------------------------ # Write the DataStructure to a .dream3d file @@ -46,10 +79,4 @@ result = cx.WriteDREAM3DFilter.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 WriteDREAM3DFilter") - -print(f'{output_file_path}') +cxtest.check_filter_result(cx.WriteDREAM3DFilter, result)