-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsimplnxpy.cpp
More file actions
1954 lines (1714 loc) · 107 KB
/
Copy pathsimplnxpy.cpp
File metadata and controls
1954 lines (1714 loc) · 107 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <NxPybind/NxPybind.hpp>
#include <pybind11/pybind11.h>
#include <pybind11/functional.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/stl/filesystem.h>
#include "SimplnxCore/Filters/CreateGeometryFilter.hpp"
#include "SimplnxCore/SimplnxCoreFilterBinding.hpp"
#include "SimplnxCore/SimplnxCorePlugin.hpp"
#include <simplnx/DataStructure/AttributeMatrix.hpp>
#include <simplnx/DataStructure/DataArray.hpp>
#include <simplnx/DataStructure/DataGroup.hpp>
#include <simplnx/DataStructure/DataStore.hpp>
#include <simplnx/DataStructure/DataStructure.hpp>
#include <simplnx/DataStructure/Geometry/EdgeGeom.hpp>
#include <simplnx/DataStructure/Geometry/HexahedralGeom.hpp>
#include <simplnx/DataStructure/Geometry/IGeometry.hpp>
#include <simplnx/DataStructure/Geometry/ImageGeom.hpp>
#include <simplnx/DataStructure/Geometry/QuadGeom.hpp>
#include <simplnx/DataStructure/Geometry/RectGridGeom.hpp>
#include <simplnx/DataStructure/Geometry/TetrahedralGeom.hpp>
#include <simplnx/DataStructure/Geometry/TriangleGeom.hpp>
#include <simplnx/DataStructure/Geometry/VertexGeom.hpp>
#include <simplnx/DataStructure/NeighborList.hpp>
#include <simplnx/DataStructure/StringArray.hpp>
#include <simplnx/Filter/Actions/CopyArrayInstanceAction.hpp>
#include <simplnx/Filter/Actions/CopyDataObjectAction.hpp>
#include <simplnx/Filter/Actions/CreateArrayAction.hpp>
#include <simplnx/Filter/Actions/CreateAttributeMatrixAction.hpp>
#include <simplnx/Filter/Actions/CreateDataGroupAction.hpp>
#include <simplnx/Filter/Actions/CreateGeometry1DAction.hpp>
#include <simplnx/Filter/Actions/CreateGeometry2DAction.hpp>
#include <simplnx/Filter/Actions/CreateGeometry3DAction.hpp>
#include <simplnx/Filter/Actions/CreateImageGeometryAction.hpp>
#include <simplnx/Filter/Actions/CreateNeighborListAction.hpp>
#include <simplnx/Filter/Actions/CreateRectGridGeometryAction.hpp>
#include <simplnx/Filter/Actions/CreateStringArrayAction.hpp>
#include <simplnx/Filter/Actions/CreateVertexGeometryAction.hpp>
#include <simplnx/Filter/Actions/DeleteDataAction.hpp>
#include <simplnx/Filter/Actions/EmptyAction.hpp>
#include <simplnx/Filter/Actions/ImportH5ObjectPathsAction.hpp>
#include <simplnx/Filter/Actions/ImportObjectAction.hpp>
#include <simplnx/Filter/Actions/MoveDataAction.hpp>
#include <simplnx/Filter/Actions/RenameDataAction.hpp>
#include <simplnx/Filter/Actions/UpdateImageGeomAction.hpp>
#include <simplnx/Filter/IFilter.hpp>
#include <simplnx/Filter/IParameter.hpp>
#include <simplnx/Filter/Parameters.hpp>
#include <simplnx/Parameters/ArrayCreationParameter.hpp>
#include <simplnx/Parameters/ArraySelectionParameter.hpp>
#include <simplnx/Parameters/ArrayThresholdsParameter.hpp>
#include <simplnx/Parameters/AttributeMatrixSelectionParameter.hpp>
#include <simplnx/Parameters/BoolParameter.hpp>
#include <simplnx/Parameters/CalculatorParameter.hpp>
#include <simplnx/Parameters/ChoicesParameter.hpp>
#include <simplnx/Parameters/CreateColorMapParameter.hpp>
#include <simplnx/Parameters/CropGeometryParameter.hpp>
#include <simplnx/Parameters/DataGroupCreationParameter.hpp>
#include <simplnx/Parameters/DataGroupSelectionParameter.hpp>
#include <simplnx/Parameters/DataObjectNameParameter.hpp>
#include <simplnx/Parameters/DataPathSelectionParameter.hpp>
#include <simplnx/Parameters/DataStoreFormatParameter.hpp>
#include <simplnx/Parameters/DataTypeParameter.hpp>
#include <simplnx/Parameters/Dream3dImportParameter.hpp>
#include <simplnx/Parameters/DynamicTableParameter.hpp>
#include <simplnx/Parameters/EnsembleInfoParameter.hpp>
#include <simplnx/Parameters/FileSystemPathParameter.hpp>
#include <simplnx/Parameters/GeneratedFileListParameter.hpp>
#include <simplnx/Parameters/GeometrySelectionParameter.hpp>
#include <simplnx/Parameters/MultiArraySelectionParameter.hpp>
#include <simplnx/Parameters/MultiPathSelectionParameter.hpp>
#include <simplnx/Parameters/NeighborListSelectionParameter.hpp>
#include <simplnx/Parameters/NumberParameter.hpp>
#include <simplnx/Parameters/NumericTypeParameter.hpp>
#include <simplnx/Parameters/ReadCSVFileParameter.hpp>
#include <simplnx/Parameters/ReadHDF5DatasetParameter.hpp>
#include <simplnx/Parameters/StringParameter.hpp>
#include <simplnx/Parameters/VectorParameter.hpp>
#include <simplnx/Parameters/util/ReadCSVData.hpp>
#include <simplnx/Pipeline/AbstractPipelineNode.hpp>
#include <simplnx/Pipeline/Pipeline.hpp>
#include <simplnx/Pipeline/PipelineFilter.hpp>
#include <simplnx/Utilities/DataGroupUtilities.hpp>
#include <simplnx/Utilities/Parsing/DREAM3D/Dream3dIO.hpp>
#include <fmt/ranges.h>
#include <filesystem>
using namespace nx::core;
using namespace nx::core::NxPybind;
namespace py = pybind11;
namespace fs = std::filesystem;
using namespace pybind11::literals;
template <>
struct fmt::formatter<nx::core::Error>
{
constexpr format_parse_context::iterator parse(format_parse_context& ctx)
{
return ctx.begin();
}
format_context::iterator format(const nx::core::Error& value, format_context& ctx) const
{
return fmt::format_to(ctx.out(), "Error(code={}, message='{}')", value.code, value.message);
}
};
template <>
struct fmt::formatter<nx::core::Warning>
{
constexpr format_parse_context::iterator parse(format_parse_context& ctx)
{
return ctx.begin();
}
format_context::iterator format(const nx::core::Warning& value, format_context& ctx) const
{
return fmt::format_to(ctx.out(), "Warning(code={}, message='{}')", value.code, value.message);
}
};
/**
* @brief Equivalent to lhs.__eq__(rhs) in python
* @param lhs
* @param rhs
* @return bool
*/
bool PyIsEqual(py::handle lhs, py::handle rhs)
{
return (lhs.attr("__eq__")(rhs)).cast<bool>();
}
template <class ParameterT>
void PyInsertLinkableParameter(Parameters& self, const ParameterT& param)
{
auto clonedParam = std::unique_ptr<ParameterT>(dynamic_cast<ParameterT*>(param.clone().release()));
self.insertLinkableParameter(std::move(clonedParam));
}
template <class ParameterT>
auto BindNumberParameter(py::handle scope, const char* name)
{
auto numberParameter = py::class_<ParameterT, IParameter>(scope, name);
numberParameter.def(py::init<const std::string&, const std::string&, const std::string&, typename ParameterT::ValueType>(), "name"_a, "human_name"_a, "help_text"_a, "default_value"_a);
return numberParameter;
}
template <class ParameterT>
auto BindVectorParameter(py::handle scope, const char* name)
{
auto vectorParameter = py::class_<ParameterT, IParameter>(scope, name);
vectorParameter.def(py::init<const std::string&, const std::string&, const std::string&, const typename ParameterT::ValueType&>(), "name"_a, "human_name"_a, "help_text"_a, "default_value"_a);
vectorParameter.def(py::init<const std::string&, const std::string&, const std::string&, const typename ParameterT::ValueType&, const typename ParameterT::NamesType&>(), "name"_a, "human_name"_a,
"help_text"_a, "default_value"_a, "names"_a);
return vectorParameter;
}
#define SIMPLNX_PY_BIND_NUMBER_PARAMETER(scope, className) BindNumberParameter<className>(scope, #className)
#define SIMPLNX_PY_BIND_VECTOR_PARAMETER(scope, className) BindVectorParameter<className>(scope, #className)
template <class T>
static void BindVec2(py::module_& m, const char* name)
{
using Vec = nx::core::Vec2<T>;
py::class_<Vec>(m, name)
.def(py::init<>())
.def(py::init<T, T>())
.def(py::init([](py::sequence s) {
if(py::len(s) != 2)
throw py::type_error("Expected length-2 sequence");
return Vec{s[0].cast<T>(), s[1].cast<T>()};
}))
.def_property(
"min", [](const Vec& v) { return v[0]; }, [](Vec& v, T x) { v[0] = x; })
.def_property(
"max", [](const Vec& v) { return v[1]; }, [](Vec& v, T x) { v[1] = x; })
.def("__getitem__",
[](const Vec& v, size_t i) {
if(i >= 2)
throw py::index_error();
return v[i];
})
.def("__setitem__",
[](Vec& v, size_t i, T x) {
if(i >= 2)
throw py::index_error();
v[i] = x;
})
.def(
"__iter__", [](const Vec& v) { return py::make_iterator(&v[0], &v[0] + 2); }, py::keep_alive<0, 1>())
.def("__repr__", [](const Vec& v) { return fmt::format("Vec2({}, {})", v[0], v[1]); });
py::implicitly_convertible<py::sequence, Vec>();
}
template <class T>
auto BindDataStore(py::handle scope, const char* name)
{
py::class_<DataStore<T>, AbstractDataStore<T>, std::shared_ptr<DataStore<T>>> dataStore(scope, name);
dataStore.def(py::init<const ShapeType&, const ShapeType&, std::optional<T>>(), "tuple_shape"_a, "component_shape"_a, "init_value"_a = std::optional<T>{});
dataStore.def_property_readonly_static("dtype", []([[maybe_unused]] py::object self) { return py::dtype::of<T>(); });
dataStore.def(
"npview",
[](DataStore<T>& dataStore_) {
ShapeType shape = dataStore_.getTupleShape();
ShapeType componentShape = dataStore_.getComponentShape();
shape.insert(shape.end(), componentShape.cbegin(), componentShape.cend());
return py::array_t<T, py::array::c_style>(shape, dataStore_.data(), py::cast(dataStore_));
},
py::return_value_policy::reference_internal);
dataStore.def("__getitem__", &DataStore<T>::at);
dataStore.def("__len__", &DataStore<T>::getSize);
dataStore.def("resize_tuples", &DataStore<T>::resizeTuples, "Resize the tuples with the given shape");
return dataStore;
}
template <class T>
auto BindDataArray(py::handle scope, const char* name)
{
py::class_<DataArray<T>, IDataArray, std::shared_ptr<DataArray<T>>> dataArray(scope, name);
dataArray.def_property_readonly_static("dtype", []([[maybe_unused]] py::object self) { return py::dtype::of<T>(); });
dataArray.def(
"npview",
[](DataArray<T>& dataArray_) {
using DataArrayType = DataArray<T>;
using DataStoreType = DataStore<T>;
const typename DataArrayType::store_type& abstractDataStore = dataArray_.getDataStoreRef();
const DataStoreType& dataStore = dynamic_cast<const DataStoreType&>(abstractDataStore);
ShapeType shape = dataStore.getTupleShape();
ShapeType componentShape = dataStore.getComponentShape();
shape.insert(shape.end(), componentShape.cbegin(), componentShape.cend());
return py::array_t<T, py::array::c_style>(shape, dataStore.data(), py::cast(dataStore));
},
py::return_value_policy::reference_internal);
return dataArray;
}
#define SIMPLNX_PY_BIND_DATA_ARRAY(scope, className) BindDataArray<className::value_type>(scope, #className)
#define SIMPLNX_PY_BIND_DATA_STORE(scope, className) BindDataStore<className::value_type>(scope, #className)
#define SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(scope, className) SIMPLNX_PY_BIND_CLASS_VARIADIC(scope, className, IDataStore, std::shared_ptr<className>)
template <class T>
auto BindNeighborList(py::handle scope, const char* name)
{
using NeighborListType = NeighborList<T>;
auto neighborList = py::class_<NeighborListType, INeighborList, std::shared_ptr<NeighborListType>>(scope, name);
neighborList.def_property_readonly_static("dtype", []([[maybe_unused]] py::object self) { return py::dtype::of<T>(); });
neighborList.def("get_list", &NeighborListType::getList, "grain_id"_a);
neighborList.def("set_list", py::overload_cast<int32, const typename NeighborListType::VectorType&>(&NeighborListType::setList), "grain_id"_a, "neighbor_list"_a);
neighborList.def(
"get_value",
[](const NeighborListType& self, int32 grainId, int32 index) {
bool ok = false;
int32 value = self.getValue(grainId, index, ok);
if(!ok)
{
throw std::out_of_range(fmt::format("NeighborList.get_value called with grain_id = {} and index = {} which was out of range", grainId, index));
}
return value;
},
"grain_id"_a, "index"_a);
neighborList.def("add_entry", &NeighborListType::addEntry, "grain_id"_a, "value"_a);
neighborList.def("get_list_size", &NeighborListType::getListSize, "grain_id"_a);
neighborList.def("get_number_of_lists", &NeighborListType::getNumberOfLists);
return neighborList;
}
#define SIMPLNX_PY_BIND_NEIGHBOR_LIST(scope, className) BindNeighborList<className::value_type>(scope, #className)
template <class GeomT>
auto BindCreateGeometry2DAction(py::handle scope, const char* name)
{
auto createGeometry2DAction = py::class_<GeomT, IDataCreationAction>(scope, name);
createGeometry2DAction.def(py::init<const DataPath&, size_t, size_t, const std::string&, const std::string&, const std::string&, const std::string&>(), "geometry_path"_a, "num_faces"_a,
"num_vertices"_a, "vertex_attribute_matrix_name"_a, "face_attribute_matrix_name"_a, "shared_vertices_name"_a, "shared_faces_name"_a);
createGeometry2DAction.def(py::init<const DataPath&, const DataPath&, const DataPath&, const std::string&, const std::string&, const ArrayHandlingType&>(), "geometry_path"_a,
"input_vertices_array_path"_a, "input_faces_array_path"_a, "vertex_attribute_matrix_name"_a, "face_attribute_matrix_name"_a, "array_type"_a);
return createGeometry2DAction;
}
template <class GeomT>
auto BindCreateGeometry3DAction(py::handle scope, const char* name)
{
auto createGeometry3DAction = py::class_<GeomT, IDataCreationAction>(scope, name);
createGeometry3DAction.def(py::init<const DataPath&, size_t, size_t, const std::string&, const std::string&, const std::string&, const std::string&>(), "geometry_path"_a, "num_cells"_a,
"num_vertices"_a, "vertex_data_name"_a, "cell_data_name"_a, "shared_vertices_name"_a, "shared_cells_name"_a);
createGeometry3DAction.def(py::init<const DataPath&, const DataPath&, const DataPath&, const std::string&, const std::string&, const ArrayHandlingType&>(), "geometry_path"_a,
"input_vertices_array_path"_a, "input_cell_array_path"_a, "vertex_attribute_matrix_name"_a, "cell_attribute_matrix_name"_a, "array_type"_a);
return createGeometry3DAction;
}
#define SIMPLNX_PY_BIND_CREATE_GEOMETRY_2D_ACTION(scope, className) BindCreateGeometry2DAction<className>(scope, #className)
#define SIMPLNX_PY_BIND_CREATE_GEOMETRY_3D_ACTION(scope, className) BindCreateGeometry3DAction<className>(scope, #className)
std::pair<std::vector<Error>, std::vector<Warning>> GetPipelineFilterResult(const PipelineFilter& filter)
{
std::vector<Error> filterErrors = filter.getErrors();
std::vector<Warning> filterWarnings = filter.getWarnings();
return {std::move(filterErrors), std::move(filterWarnings)};
}
std::pair<std::vector<Error>, std::vector<Warning>> GetPipelineResult(const Pipeline& pipeline)
{
std::vector<Error> errors;
std::vector<Warning> warnings;
for(usize index = 0; index < pipeline.size(); index++)
{
const AbstractPipelineNode* node = pipeline.at(index);
std::vector<Error> nodeErrors;
std::vector<Warning> nodeWarnings;
AbstractPipelineNode::NodeType nodeType = node->getType();
switch(nodeType)
{
case AbstractPipelineNode::NodeType::Pipeline: {
const auto& subPipeline = dynamic_cast<const Pipeline&>(*node);
std::tie(nodeErrors, nodeWarnings) = GetPipelineResult(subPipeline);
break;
}
case AbstractPipelineNode::NodeType::Filter: {
const auto& filter = dynamic_cast<const PipelineFilter&>(*node);
std::tie(nodeErrors, nodeWarnings) = GetPipelineFilterResult(filter);
break;
}
}
errors.insert(errors.end(), nodeErrors.begin(), nodeErrors.end());
warnings.insert(warnings.end(), nodeWarnings.begin(), nodeWarnings.end());
FaultState faultState = node->getFaultState();
if(faultState == FaultState::Errors)
{
break;
}
}
return {std::move(errors), std::move(warnings)};
}
Result<> ExecutePipeline(Pipeline& pipeline, DataStructure& dataStructure)
{
bool success = pipeline.execute(dataStructure, false);
auto&& [errors, warnings] = GetPipelineResult(pipeline);
Result<> result;
if(!success)
{
result.m_Expected = nonstd::make_unexpected(std::move(errors));
}
result.m_Warnings = std::move(warnings);
return result;
}
nx::core::DataPath CreateDataPath(std::string_view path)
{
auto result = DataPath::FromString(path);
return result.value();
}
class ManualImportFinder
{
public:
bool insert(const fs::path& path)
{
if(containsPath(path))
{
return false;
}
std::string modName = GetModuleNameFromPath(path);
if(containsModule(modName))
{
return false;
}
m_ModuleToPathMap.insert({modName, path});
m_PathToModuleMap.insert({path, modName});
return true;
}
void removePath(const fs::path& path)
{
if(!containsPath(path))
{
return;
}
std::string modName = GetModuleNameFromPath(path);
m_ModuleToPathMap.erase(modName);
m_PathToModuleMap.erase(path);
}
void removeModule(const std::string& modName)
{
if(!containsModule(modName))
{
return;
}
fs::path modPath = m_ModuleToPathMap.at(modName);
m_ModuleToPathMap.erase(modName);
m_PathToModuleMap.erase(modPath);
}
void clear()
{
m_ModuleToPathMap.clear();
m_PathToModuleMap.clear();
}
bool containsPath(const fs::path& path) const
{
return m_PathToModuleMap.count(path) > 0;
}
bool containsModule(const std::string& modName) const
{
return m_ModuleToPathMap.count(modName) > 0;
}
py::object findSpec(const std::string& fullname, py::object path, py::object target) const
{
if(!containsModule(fullname))
{
return py::none();
}
fs::path modPath = m_ModuleToPathMap.at(fullname);
bool isPackage = modPath.extension() != ".py";
auto importLibUtil = py::module_::import("importlib.util");
fs::path initPyPath = isPackage ? modPath / "__init__.py" : modPath;
py::object submoduleSearchLocations = isPackage ? py::list() : py::object(py::none());
auto spec = importLibUtil.attr("spec_from_file_location")(fullname, initPyPath, py::arg("submodule_search_locations") = submoduleSearchLocations);
return spec;
}
private:
static std::string GetModuleNameFromPath(const fs::path& path)
{
return path.stem().string();
}
std::map<std::string, fs::path> m_ModuleToPathMap;
std::map<fs::path, std::string> m_PathToModuleMap;
};
PYBIND11_MODULE(simplnx, mod)
{
auto* internals = new Internals();
const auto* corePlugin = internals->addPlugin<SimplnxCorePlugin>();
py::set_shared_data(Internals::k_Key, internals);
// This is required until the pybind11_json library is added which adds the appropriate type casters
// auto json = py::class_<nlohmann::json>(mod, "Json");
// json.def(py::init<>([](std::string_view text) { return nlohmann::json::parse(text); }), "text"_a);
// json.def("__str__", [](nlohmann::json& self) { return self.dump(); });
py::class_<Error> error(mod, "Error");
error.def(py::init<>());
error.def(py::init<int32, std::string>());
error.def_readwrite("code", &Error::code);
error.def_readwrite("message", &Error::message);
error.def("__repr__", [](const Error& self) { return fmt::format("<simplnx.Error(code={}, message='{}')>", self.code, self.message); });
error.def("__str__", [](const Error& self) { return fmt::format("<simplnx.Error(code={}, message='{}')>", self.code, self.message); });
py::class_<Warning> warning(mod, "Warning");
warning.def(py::init<>());
warning.def(py::init<int32, std::string>());
warning.def_readwrite("code", &Warning::code);
warning.def_readwrite("message", &Warning::message);
warning.def("__repr__", [](const Warning& self) { return fmt::format("<simplnx.Warning(code={}, message='{}')>", self.code, self.message); });
warning.def("__str__", [](const Warning& self) { return fmt::format("<simplnx.Warning(code={}, message='{}')>", self.code, self.message); });
py::class_<Result<>> result(mod, "Result");
result.def(py::init<>([](std::optional<std::vector<Error>> errors, std::optional<std::vector<Warning>> warnings) {
Result<> result_;
if(errors.has_value())
{
result_.m_Expected = nonstd::make_unexpected(std::move(*errors));
}
if(warnings.has_value())
{
result_.warnings() = std::move(*warnings);
}
return result_;
}),
"errors"_a = py::none(), "warnings"_a = py::none());
result.def_property_readonly("errors", [](Result<>& self) {
if(self.valid())
{
return std::vector<Error>{};
}
return self.errors();
});
result.def_property_readonly("warnings", [](Result<>& self) { return self.warnings(); });
result.def("__repr__", [](const Result<>& self) {
std::vector<Error> errors;
if(self.invalid())
{
errors = self.errors();
}
return fmt::format("<simplnx.Result(errors={}, warnings={})>", errors, self.warnings());
});
result.def("valid", &Result<>::valid);
result.def("invalid", &Result<>::invalid);
BindVec2<int32>(mod, "IntVec2");
BindVec2<float32>(mod, "FloatVec2");
py::enum_<NumericType> numericType(mod, "NumericType");
numericType.value("int8", NumericType::int8);
numericType.value("uint8", NumericType::uint8);
numericType.value("int16", NumericType::int16);
numericType.value("uint16", NumericType::uint16);
numericType.value("int32", NumericType::int32);
numericType.value("uint32", NumericType::uint32);
numericType.value("int64", NumericType::int64);
numericType.value("uint64", NumericType::uint64);
numericType.value("float32", NumericType::float32);
numericType.value("float64", NumericType::float64);
py::enum_<DataType> dataType(mod, "DataType");
dataType.value("int8", DataType::int8);
dataType.value("uint8", DataType::uint8);
dataType.value("int16", DataType::int16);
dataType.value("uint16", DataType::uint16);
dataType.value("int32", DataType::int32);
dataType.value("uint32", DataType::uint32);
dataType.value("int64", DataType::int64);
dataType.value("uint64", DataType::uint64);
dataType.value("float32", DataType::float32);
dataType.value("float64", DataType::float64);
dataType.value("boolean", DataType::boolean);
py::enum_<CSVType> csvType(mod, "CSVType");
csvType.value("int8", CSVType::int8);
csvType.value("uint8", CSVType::uint8);
csvType.value("int16", CSVType::int16);
csvType.value("uint16", CSVType::uint16);
csvType.value("int32", CSVType::int32);
csvType.value("uint32", CSVType::uint32);
csvType.value("int64", CSVType::int64);
csvType.value("uint64", CSVType::uint64);
csvType.value("float32", CSVType::float32);
csvType.value("float64", CSVType::float64);
csvType.value("boolean", CSVType::boolean);
csvType.value("string", CSVType::string);
mod.def(
"convert_np_dtype_to_datatype",
[](const py::dtype& dtype) {
if(PyIsEqual(dtype, py::dtype::of<int8>()))
{
return DataType::int8;
}
if(PyIsEqual(dtype, py::dtype::of<uint8>()))
{
return DataType::uint8;
}
if(PyIsEqual(dtype, py::dtype::of<int16>()))
{
return DataType::int16;
}
if(PyIsEqual(dtype, py::dtype::of<uint16>()))
{
return DataType::uint16;
}
if(PyIsEqual(dtype, py::dtype::of<int32>()))
{
return DataType::int32;
}
if(PyIsEqual(dtype, py::dtype::of<uint32>()))
{
return DataType::uint32;
}
if(PyIsEqual(dtype, py::dtype::of<int64>()))
{
return DataType::int64;
}
if(PyIsEqual(dtype, py::dtype::of<uint64>()))
{
return DataType::uint64;
}
if(PyIsEqual(dtype, py::dtype::of<float32>()))
{
return DataType::float32;
}
if(PyIsEqual(dtype, py::dtype::of<float64>()))
{
return DataType::float64;
}
if(PyIsEqual(dtype, py::dtype::of<bool>()))
{
return DataType::boolean;
}
std::string dtypeStr = py::str(static_cast<py::object>(dtype));
throw std::invalid_argument(fmt::format("Unable to convert dtype to DataType: Unsupported dtype '{}'.", dtypeStr));
},
"Convert numpy dtype to simplnx DataType", "dtype"_a);
mod.def(
"convert_np_dtype_to_numeric_type",
[](const py::dtype& dtype) {
if(PyIsEqual(dtype, py::dtype::of<int8>()))
{
return NumericType::int8;
}
if(PyIsEqual(dtype, py::dtype::of<uint8>()))
{
return NumericType::uint8;
}
if(PyIsEqual(dtype, py::dtype::of<int16>()))
{
return NumericType::int16;
}
if(PyIsEqual(dtype, py::dtype::of<uint16>()))
{
return NumericType::uint16;
}
if(PyIsEqual(dtype, py::dtype::of<int32>()))
{
return NumericType::int32;
}
if(PyIsEqual(dtype, py::dtype::of<uint32>()))
{
return NumericType::uint32;
}
if(PyIsEqual(dtype, py::dtype::of<int64>()))
{
return NumericType::int64;
}
if(PyIsEqual(dtype, py::dtype::of<uint64>()))
{
return NumericType::uint64;
}
if(PyIsEqual(dtype, py::dtype::of<float32>()))
{
return NumericType::float32;
}
if(PyIsEqual(dtype, py::dtype::of<float64>()))
{
return NumericType::float64;
}
std::string dtypeStr = py::str(static_cast<py::object>(dtype));
throw std::invalid_argument(fmt::format("Unable to convert dtype to NumericType: Unsupported dtype '{}'.", dtypeStr));
},
"Convert numpy dtype to simplnx NumericType", "dtype"_a);
py::enum_<ArrayHandlingType> arrayHandlingType(mod, "ArrayHandlingType");
arrayHandlingType.value("Copy", ArrayHandlingType::Copy);
arrayHandlingType.value("Move", ArrayHandlingType::Move);
py::class_<Uuid> uuid(mod, "Uuid");
uuid.def(py::init<>());
uuid.def(py::init([](std::string_view text) {
std::optional<Uuid> uuid_ = Uuid::FromString(text);
if(!uuid_.has_value())
{
throw std::invalid_argument(fmt::format("Invalid uuid string '{}'", text));
}
return *uuid_;
}));
uuid.def("__str__", &Uuid::str);
uuid.def("__repr__", [](const Uuid& self) { return fmt::format("<simplnx.Uuid('{}')>", self.str()); });
uuid.def("__getitem__", [](const Uuid& self, usize i) { return static_cast<uint8>(self.data.at(i)); });
uuid.def("__setitem__", [](Uuid& self, usize i, uint8 value) { self.data.at(i) = std::byte{value}; });
uuid.def("__len__", [](const Uuid& self) { return self.data.size(); });
uuid.def_property_readonly("bytes", [](const Uuid& self) { return py::bytes(reinterpret_cast<const char*>(self.data.data()), self.data.size()); });
py::class_<AtomicBoolProxy, std::shared_ptr<AtomicBoolProxy>> atomicBool(mod, "AtomicBoolProxy");
atomicBool.def("__bool__", [](const AtomicBoolProxy& self) { return self.get()->load(); });
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("{}", self.toString("/")); });
dataPath.def("__len__", [](const DataPath& self) { return self.getLength(); });
dataPath.def("to_string", [](const DataPath& self, const std::string& delimiter) { return self.toString(delimiter); });
dataPath.def("create_child_path", [](const DataPath& self, const std::string& name) { return self.createChildPath(name); });
// Python "PathLib" type operations
dataPath.def("parts", [](const DataPath& self) { return self.getPathVector(); });
dataPath.def("parent", [](const DataPath& self) { return self.getParent(); });
dataPath.def("name", [](const DataPath& self) { return self.getTargetName(); });
dataPath.def("with_name", [](const DataPath& self, const std::string& name) {
auto pathVector = self.getPathVector();
if(pathVector.size() == 0)
{
return DataPath(std::vector<std::string>{name});
}
pathVector.back() = name;
return DataPath(pathVector);
});
py::class_<AbstractPipelineNode, std::shared_ptr<AbstractPipelineNode>> abstractPipelineNode(mod, "AbstractPipelineNode");
abstractPipelineNode.def("to_json_str", [](const AbstractPipelineNode& self) { return self.toJson().dump(); });
py::class_<PipelineFilter, AbstractPipelineNode, std::shared_ptr<PipelineFilter>> pipelineFilter(mod, "PipelineFilter");
py::class_<IParameter> parameter(mod, "IParameter");
py::enum_<IParameter::Type> parameterType(parameter, "Type");
parameterType.value("Value", IParameter::Type::Value);
parameterType.value("Data", IParameter::Type::Data);
parameter.def_property_readonly("name", &IParameter::name);
parameter.def_property_readonly("uuid", &IParameter::uuid);
parameter.def_property_readonly("human_name", &IParameter::humanName);
parameter.def_property_readonly("help_text", &IParameter::helpText);
parameter.def_property_readonly("type", &IParameter::type);
parameter.def_property_readonly("version", &IParameter::getVersion);
py::class_<Parameters> parameters(mod, "Parameters");
py::class_<Parameters::Separator> separator(parameters, "Separator");
separator.def(py::init<>());
separator.def(py::init<std::string>(), "name"_a);
separator.def_readwrite("name", &Parameters::Separator::name);
parameters.def(py::init<>());
parameters.def("insert", [](Parameters& self, const IParameter& param) { self.insert(param.clone()); });
parameters.def("insert", py::overload_cast<Parameters::Separator>(&Parameters::insert));
parameters.def("insert_linkable_parameter", &PyInsertLinkableParameter<BoolParameter>);
parameters.def("insert_linkable_parameter", &PyInsertLinkableParameter<ChoicesParameter>);
parameters.def("link_parameters", [](Parameters& self, std::string groupKey, std::string childKey, BoolParameter::ValueType value) { self.linkParameters(groupKey, childKey, value); });
parameters.def("link_parameters", [](Parameters& self, std::string groupKey, std::string childKey, ChoicesParameter::ValueType value) { self.linkParameters(groupKey, childKey, value); });
parameters.def(
"__getitem__", [](Parameters& self, std::string_view key) { return self.at(key).get(); }, py::return_value_policy::reference_internal);
py::class_<IArrayThreshold, std::shared_ptr<IArrayThreshold>> iArrayThreshold(mod, "IArrayThreshold");
py::enum_<IArrayThreshold::UnionOperator> unionOperator(iArrayThreshold, "UnionOperator");
unionOperator.value("And", IArrayThreshold::UnionOperator::And);
unionOperator.value("Or", IArrayThreshold::UnionOperator::Or);
iArrayThreshold.def_property("inverted", &IArrayThreshold::isInverted, &IArrayThreshold::setInverted);
iArrayThreshold.def_property("union_op", &IArrayThreshold::getUnionOperator, &IArrayThreshold::setUnionOperator);
iArrayThreshold.def("get_required_paths", &IArrayThreshold::getRequiredPaths);
py::class_<ArrayThreshold, IArrayThreshold, std::shared_ptr<ArrayThreshold>> arrayThreshold(mod, "ArrayThreshold");
py::enum_<ArrayThreshold::ComparisonType> comparisonType(arrayThreshold, "ComparisonType");
comparisonType.value("GreaterThan", ArrayThreshold::ComparisonType::GreaterThan);
comparisonType.value("LessThan", ArrayThreshold::ComparisonType::LessThan);
comparisonType.value("Equal", ArrayThreshold::ComparisonType::Operator_Equal);
comparisonType.value("NotEqual", ArrayThreshold::ComparisonType::Operator_NotEqual);
arrayThreshold.def(py::init<>());
arrayThreshold.def_property("array_path", &ArrayThreshold::getArrayPath, &ArrayThreshold::setArrayPath);
arrayThreshold.def_property("value", &ArrayThreshold::getComparisonValue, &ArrayThreshold::setComparisonValue);
arrayThreshold.def_property("comparison", &ArrayThreshold::getComparisonType, &ArrayThreshold::setComparisonType);
arrayThreshold.def_property("component_index", &ArrayThreshold::getComponentIndex, &ArrayThreshold::setComponentIndex);
py::class_<ArrayThresholdSet, IArrayThreshold, std::shared_ptr<ArrayThresholdSet>> arrayThresholdSet(mod, "ArrayThresholdSet");
arrayThresholdSet.def(py::init<>());
arrayThresholdSet.def_property("thresholds", &ArrayThresholdSet::getArrayThresholds, &ArrayThresholdSet::setArrayThresholds);
arrayThresholdSet.def("__repr__", [](const ArrayThresholdSet& self) { return "ArrayThresholdSet()"; });
py::class_<ReadCSVData> readCSVData(mod, "ReadCSVDataParameter");
py::enum_<ReadCSVData::HeaderMode> csvHeaderMode(readCSVData, "HeaderMode");
csvHeaderMode.value("Line", ReadCSVData::HeaderMode::LINE);
csvHeaderMode.value("Custom", ReadCSVData::HeaderMode::CUSTOM);
readCSVData.def(py::init<>());
readCSVData.def_readwrite("input_file_path", &ReadCSVData::inputFilePath);
readCSVData.def_readwrite("custom_headers", &ReadCSVData::customHeaders);
readCSVData.def_readwrite("start_import_row", &ReadCSVData::startImportRow);
readCSVData.def_readwrite("column_data_types", &ReadCSVData::dataTypes);
readCSVData.def_readwrite("skipped_array_mask", &ReadCSVData::skippedArrayMask);
readCSVData.def_readwrite("headers_line", &ReadCSVData::headersLine);
readCSVData.def_readwrite("header_mode", &ReadCSVData::headerMode);
readCSVData.def_readwrite("tuple_dims", &ReadCSVData::tupleDims);
readCSVData.def_readwrite("delimiters", &ReadCSVData::delimiters);
readCSVData.def_readwrite("consecutive_delimiters", &ReadCSVData::consecutiveDelimiters);
readCSVData.def("__repr__", [](const ReadCSVData& self) { return "ReadCSVDataParameter()"; });
py::class_<AbstractPlugin, std::shared_ptr<AbstractPlugin>> abstractPlugin(mod, "AbstractPlugin");
py::class_<PythonPlugin, AbstractPlugin, std::shared_ptr<PythonPlugin>> pythonPlugin(mod, "PythonPlugin");
py::class_<IDataStore, std::shared_ptr<IDataStore>> iDataStore(mod, "IDataStore");
iDataStore.def_property_readonly("data_type", &IDataStore::getDataType);
iDataStore.def_property_readonly("tdims", &IDataStore::getTupleShape);
iDataStore.def_property_readonly("cdims", &IDataStore::getComponentShape);
auto abstractDataStoreInt8 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, Int8AbstractDataStore);
auto abstractDataStoreUInt8 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, UInt8AbstractDataStore);
auto abstractDataStoreInt16 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, Int16AbstractDataStore);
auto abstractDataStoreUInt16 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, UInt16AbstractDataStore);
auto abstractDataStoreInt32 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, Int32AbstractDataStore);
auto abstractDataStoreUInt32 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, UInt32AbstractDataStore);
auto abstractDataStoreInt64 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, Int64AbstractDataStore);
auto abstractDataStoreUInt64 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, UInt64AbstractDataStore);
auto abstractDataStoreFloat32 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, Float32AbstractDataStore);
auto abstractDataStoreFloat64 = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, Float64AbstractDataStore);
auto abstractDataStoreBool = SIMPLNX_PY_BIND_ABSTRACT_DATA_STORE(mod, BoolAbstractDataStore);
auto dataStoreInt8 = SIMPLNX_PY_BIND_DATA_STORE(mod, Int8DataStore);
auto dataStoreUInt8 = SIMPLNX_PY_BIND_DATA_STORE(mod, UInt8DataStore);
auto dataStoreInt16 = SIMPLNX_PY_BIND_DATA_STORE(mod, Int16DataStore);
auto dataStoreUInt16 = SIMPLNX_PY_BIND_DATA_STORE(mod, UInt16DataStore);
auto dataStoreInt32 = SIMPLNX_PY_BIND_DATA_STORE(mod, Int32DataStore);
auto dataStoreUInt32 = SIMPLNX_PY_BIND_DATA_STORE(mod, UInt32DataStore);
auto dataStoreInt64 = SIMPLNX_PY_BIND_DATA_STORE(mod, Int64DataStore);
auto dataStoreUInt64 = SIMPLNX_PY_BIND_DATA_STORE(mod, UInt64DataStore);
auto dataStoreFloat32 = SIMPLNX_PY_BIND_DATA_STORE(mod, Float32DataStore);
auto dataStoreFloat64 = SIMPLNX_PY_BIND_DATA_STORE(mod, Float64DataStore);
auto dataStoreBool = SIMPLNX_PY_BIND_DATA_STORE(mod, BoolDataStore);
py::class_<DataStructure> dataStructure(mod, "DataStructure");
py::class_<DataObject, std::shared_ptr<DataObject>> dataObject(mod, "DataObject");
dataObject.def_property_readonly("id", &DataObject::getId);
dataObject.def_property_readonly("name", &DataObject::getName);
dataObject.def_property_readonly("type", &DataObject::getDataObjectType);
dataStructure.def(py::init<>());
dataStructure.def("__getitem__", py::overload_cast<const DataPath&>(&DataStructure::getSharedData));
dataStructure.def("__getitem__", [](DataStructure& self, const std::string& path) {
auto pathConversionResult = DataPath::FromString(path);
if(!pathConversionResult)
{
return std::shared_ptr<DataObject>(nullptr);
}
return self.getSharedData(pathConversionResult.value());
});
dataStructure.def_property_readonly("size", &DataStructure::getSize);
dataStructure.def("__len__", &DataStructure::getSize);
dataStructure.def("remove", py::overload_cast<const DataPath&>(&DataStructure::removeData));
dataStructure.def("remove", [](DataStructure& self, const std::string& path) {
auto pathConversionResult = DataPath::FromString(path);
if(!pathConversionResult)
{
return false;
}
return self.removeData(pathConversionResult.value());
});
dataStructure.def(
"exists",
[](const DataStructure& self, std::string_view path) {
auto convertedPath = DataPath::FromString(path);
if(!convertedPath)
{
return false;
}
return self.containsData(convertedPath.value());
},
"Returns true if there is a DataStructure object at the given path", "path"_a);
dataStructure.def("exists", py::overload_cast<const DataPath&>(&DataStructure::containsData, py::const_), "Returns true if there is a DataStructure object at the given path", "path"_a);
dataStructure.def("__contains__", py::overload_cast<const DataPath&>(&DataStructure::containsData, py::const_), "Returns true if there is a DataStructure object at the given path", "path"_a);
dataStructure.def("hierarchy_to_str", [](DataStructure& self) {
std::stringstream ss;
self.exportHierarchyAsText(ss);
return ss.str();
});
dataStructure.def(
"hierarchy_to_graphviz",
[](DataStructure& self) {
std::stringstream ss;
self.exportHierarchyAsGraphViz(ss);
return ss.str();
},
"Returns the DataStructure hierarchy expressed in the 'dot' language. Use a GraphViz package to render.");
dataStructure.def("get_children", [](DataStructure& self, nx::core::DataPath& parentPath) {
if(parentPath.empty())
{
std::vector<DataPath> outputPaths;
for(const auto* object : self.getTopLevelData())
{
if(object != nullptr)
{
auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value();
outputPaths.push_back(topLevelPath);
}
}
return outputPaths;
}
else
{
auto result_ = nx::core::GetAllChildDataPaths(self, parentPath);
if(result_)
{
return result_.value();
}
return std::vector<DataPath>{};
}
});
dataStructure.def("get_children", [](DataStructure& self, const std::string& parentPath) {
if(parentPath.empty())
{
std::vector<DataPath> outputPaths;
for(const auto* object : self.getTopLevelData())
{
auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value();
outputPaths.push_back(topLevelPath);
}
return outputPaths;
}
else
{
auto pathConversionResult = DataPath::FromString(parentPath);
if(!pathConversionResult)
{
return std::vector<DataPath>{};
}
auto result_ = nx::core::GetAllChildDataPaths(self, pathConversionResult.value());
if(result_)
{
return result_.value();
}
return std::vector<DataPath>{};
}
});
auto dataObjectType = py::enum_<DataObject::Type>(dataObject, "DataObjectType");
dataObjectType.value("DataObject", DataObject::Type::DataObject);
dataObjectType.value("DynamicListArray", DataObject::Type::DynamicListArray);
dataObjectType.value("ScalarData", DataObject::Type::ScalarData);
dataObjectType.value("BaseGroup", DataObject::Type::BaseGroup);
dataObjectType.value("AttributeMatrix", DataObject::Type::AttributeMatrix);
dataObjectType.value("DataGroup", DataObject::Type::DataGroup);
dataObjectType.value("IDataArray", DataObject::Type::IDataArray);
dataObjectType.value("DataArray", DataObject::Type::DataArray);
dataObjectType.value("IGeometry", DataObject::Type::IGeometry);
dataObjectType.value("IGridGeometry", DataObject::Type::IGridGeometry);
dataObjectType.value("RectGridGeom", DataObject::Type::RectGridGeom);
dataObjectType.value("ImageGeom", DataObject::Type::ImageGeom);
dataObjectType.value("INodeGeometry0D", DataObject::Type::INodeGeometry0D);
dataObjectType.value("VertexGeom", DataObject::Type::VertexGeom);
dataObjectType.value("INodeGeometry1D", DataObject::Type::INodeGeometry1D);
dataObjectType.value("EdgeGeom", DataObject::Type::EdgeGeom);
dataObjectType.value("INodeGeometry2D", DataObject::Type::INodeGeometry2D);
dataObjectType.value("QuadGeom", DataObject::Type::QuadGeom);
dataObjectType.value("TriangleGeom", DataObject::Type::TriangleGeom);
dataObjectType.value("INodeGeometry3D", DataObject::Type::INodeGeometry3D);
dataObjectType.value("HexahedralGeom", DataObject::Type::HexahedralGeom);
dataObjectType.value("TetrahedralGeom", DataObject::Type::TetrahedralGeom);
dataObjectType.value("INeighborList", DataObject::Type::INeighborList);
dataObjectType.value("NeighborList", DataObject::Type::NeighborList);
dataObjectType.value("StringArray", DataObject::Type::StringArray);
dataObjectType.value("AbstractMontage", DataObject::Type::AbstractMontage);
dataObjectType.value("GridMontage", DataObject::Type::GridMontage);
dataObjectType.value("Unknown", DataObject::Type::Unknown);
dataObjectType.value("Any", DataObject::Type::Any);
py::class_<BaseGroup, DataObject, std::shared_ptr<BaseGroup>> baseGroup(mod, "BaseGroup");
baseGroup.def("contains", py::overload_cast<const std::string&>(&BaseGroup::contains, py::const_));
baseGroup.def("__getitem__", py::overload_cast<const std::string&>(&BaseGroup::at), py::return_value_policy::reference_internal);
baseGroup.def("__len__", &BaseGroup::getSize);
baseGroup.def("__iter__", [](BaseGroup& self) { return py::make_iterator(self.begin(), self.end()); });
baseGroup.def("keys", [](const BaseGroup& self) { return self.getDataMap().getNames(); });
auto baseGroupType = py::enum_<BaseGroup::GroupType>(baseGroup, "GroupType");
baseGroupType.value("BaseGroup", BaseGroup::GroupType::BaseGroup);
baseGroupType.value("DataGroup", BaseGroup::GroupType::DataGroup);
baseGroupType.value("AttributeMatrix", BaseGroup::GroupType::AttributeMatrix);
baseGroupType.value("IGeometry", BaseGroup::GroupType::IGeometry);
baseGroupType.value("IGridGeometry", BaseGroup::GroupType::IGridGeometry);
baseGroupType.value("RectGridGeom", BaseGroup::GroupType::RectGridGeom);
baseGroupType.value("ImageGeom", BaseGroup::GroupType::ImageGeom);
baseGroupType.value("INodeGeometry0D", BaseGroup::GroupType::INodeGeometry0D);
baseGroupType.value("VertexGeom", BaseGroup::GroupType::VertexGeom);
baseGroupType.value("INodeGeometry1D", BaseGroup::GroupType::INodeGeometry1D);
baseGroupType.value("EdgeGeom", BaseGroup::GroupType::EdgeGeom);
baseGroupType.value("INodeGeometry2D", BaseGroup::GroupType::INodeGeometry2D);
baseGroupType.value("QuadGeom", BaseGroup::GroupType::QuadGeom);
baseGroupType.value("TriangleGeom", BaseGroup::GroupType::TriangleGeom);
baseGroupType.value("INodeGeometry3D", BaseGroup::GroupType::INodeGeometry3D);
baseGroupType.value("HexahedralGeom", BaseGroup::GroupType::HexahedralGeom);
baseGroupType.value("TetrahedralGeom", BaseGroup::GroupType::TetrahedralGeom);
baseGroupType.value("Unknown", BaseGroup::GroupType::Unknown);
py::class_<IGeometry, BaseGroup, std::shared_ptr<IGeometry>> iGeometry(mod, "IGeometry");
py::enum_<IGeometry::Type> geomType(iGeometry, "Type");
geomType.value("Image", IGeometry::Type::Image);
geomType.value("RectGrid", IGeometry::Type::RectGrid);
geomType.value("Vertex", IGeometry::Type::Vertex);
geomType.value("Edge", IGeometry::Type::Edge);
geomType.value("Triangle", IGeometry::Type::Triangle);
geomType.value("Quad", IGeometry::Type::Quad);
geomType.value("Tetrahedral", IGeometry::Type::Tetrahedral);
geomType.value("Hexahedral", IGeometry::Type::Hexahedral);
py::class_<IGridGeometry, IGeometry, std::shared_ptr<IGridGeometry>> iGridGeometry(mod, "IGridGeometry");
iGridGeometry.def_property_readonly("dimensions", [](const IGridGeometry& self) { return self.getDimensions().toTuple(); });
iGridGeometry.def_property_readonly("num_x_cells", &IGridGeometry::getNumXCells);
iGridGeometry.def_property_readonly("num_y_cells", &IGridGeometry::getNumYCells);
iGridGeometry.def_property_readonly("num_z_cells", &IGridGeometry::getNumZCells);