PySimultan 0.1.54__py3-none-any.whl → 0.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- PySimultan-0.2.dist-info/LICENSE.txt +17 -0
- PySimultan-0.2.dist-info/METADATA +36 -0
- PySimultan-0.2.dist-info/RECORD +82 -0
- {PySimultan-0.1.54.dist-info → PySimultan-0.2.dist-info}/WHEEL +1 -1
- PySimultan-0.2.dist-info/top_level.txt +1 -0
- {PySimultan → PySimultan2}/__init__.py +11 -6
- PySimultan2/config.py +52 -0
- PySimultan2/data_model.py +713 -0
- PySimultan2/default_types.py +507 -0
- PySimultan2/files.py +371 -0
- PySimultan2/geometry/__init__.py +4 -0
- PySimultan2/geometry/geometry_base.py +654 -0
- PySimultan2/geometry/utils.py +181 -0
- PySimultan2/multi_values.py +277 -0
- PySimultan2/object_mapper.py +200 -0
- PySimultan2/resources/AssimpNet.dll +0 -0
- PySimultan2/resources/AvalonDock.dll +0 -0
- PySimultan2/resources/BruTile.dll +0 -0
- PySimultan2/resources/ClosedXML.dll +0 -0
- PySimultan2/resources/ComponentBuilder.dll +0 -0
- PySimultan/resources/ComponentBuilder.exe.config → PySimultan2/resources/ComponentBuilder.dll.config +6 -2
- PySimultan2/resources/ComponentBuilder.runtimeconfig.json +18 -0
- {PySimultan → PySimultan2}/resources/ComponentBuilder.xml +11877 -6754
- PySimultan2/resources/ControlzEx.dll +0 -0
- PySimultan2/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
- PySimultan2/resources/DocumentFormat.OpenXml.dll +0 -0
- PySimultan2/resources/ExcelNumberFormat.dll +0 -0
- PySimultan2/resources/Fluent.dll +0 -0
- PySimultan2/resources/GeometryViewer.dll +0 -0
- {PySimultan → PySimultan2}/resources/GeometryViewer.xml +2201 -1155
- PySimultan2/resources/HelixToolkit.Core.Wpf.dll +0 -0
- PySimultan2/resources/HelixToolkit.SharpDX.Core.Wpf.dll +0 -0
- PySimultan2/resources/HelixToolkit.SharpDX.Core.dll +0 -0
- PySimultan2/resources/HelixToolkit.dll +0 -0
- PySimultan2/resources/MathNet.Numerics.dll +0 -0
- PySimultan2/resources/Microsoft.AspNetCore.Authorization.dll +0 -0
- PySimultan2/resources/Microsoft.AspNetCore.Metadata.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Options.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Primitives.dll +0 -0
- PySimultan2/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
- PySimultan2/resources/Microsoft.WindowsAPICodePack.dll +0 -0
- PySimultan2/resources/Microsoft.Xaml.Behaviors.dll +0 -0
- PySimultan2/resources/Newtonsoft.Json.Bson.dll +0 -0
- PySimultan2/resources/Newtonsoft.Json.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll.config +15 -0
- PySimultan2/resources/SIMULTAN.Lang.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.Lang.xml +5282 -3252
- PySimultan2/resources/SIMULTAN.Plugins.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.Plugins.xml +110 -0
- PySimultan2/resources/SIMULTAN.UI.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.UI.xml +10483 -4937
- PySimultan2/resources/SIMULTAN.dll +0 -0
- PySimultan2/resources/SIMULTAN.xml +34122 -0
- PySimultan2/resources/SharpDX.D3DCompiler.dll +0 -0
- PySimultan2/resources/SharpDX.DXGI.dll +0 -0
- PySimultan2/resources/SharpDX.Direct2D1.dll +0 -0
- PySimultan2/resources/SharpDX.Direct3D11.dll +0 -0
- PySimultan2/resources/SharpDX.Direct3D9.dll +0 -0
- {PySimultan → PySimultan2}/resources/SharpDX.Mathematics.dll +0 -0
- PySimultan2/resources/SharpDX.dll +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.dll +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.xml +959 -1110
- PySimultan2/resources/Sprache.dll +0 -0
- PySimultan2/resources/System.Data.OleDb.dll +0 -0
- PySimultan2/resources/System.Net.Http.Formatting.dll +0 -0
- PySimultan2/resources/XAMLMarkupExtensions.dll +0 -0
- PySimultan2/resources/assimp.dll +0 -0
- {PySimultan → PySimultan2}/resources/defaultsettings.xml +0 -0
- PySimultan2/simultan_object.py +366 -0
- PySimultan2/taxonomy_maps.py +169 -0
- PySimultan2/utils.py +1383 -0
- PySimultan/config.py +0 -57
- PySimultan/data_model.py +0 -376
- PySimultan/default_types.py +0 -1771
- PySimultan/geo_default_types.py +0 -763
- PySimultan/geometry.py +0 -309
- PySimultan/resources/AssimpNet.dll +0 -0
- PySimultan/resources/AssimpNet.xml +0 -12074
- PySimultan/resources/BruTile.dll +0 -0
- PySimultan/resources/BruTile.xml +0 -1845
- PySimultan/resources/ControlzEx.dll +0 -0
- PySimultan/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
- PySimultan/resources/DXFImportExport.dll +0 -0
- PySimultan/resources/DotSpatial.Projections.xml +0 -5879
- PySimultan/resources/EXCELImportExport.dll +0 -0
- PySimultan/resources/Fluent.dll +0 -0
- PySimultan/resources/Fluent.xml +0 -9103
- PySimultan/resources/GeoJSON.Net.dll +0 -0
- PySimultan/resources/GeometryViewer.Data.dll +0 -0
- PySimultan/resources/GeometryViewer.Data.xml +0 -4443
- PySimultan/resources/GeometryViewer.Shared.dll +0 -0
- PySimultan/resources/GeometryViewer.Shared.xml +0 -588
- PySimultan/resources/GeometryViewer.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.SharpDX.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.SharpDX.xml +0 -43219
- PySimultan/resources/HelixToolkit.Wpf.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.xml +0 -22363
- PySimultan/resources/HelixToolkit.dll +0 -0
- PySimultan/resources/HelixToolkit.xml +0 -144
- PySimultan/resources/ImportLog_SMART_CAMPUS_TU_WIEN_BIBLIOTHEK_20210305_ZONENMODELL_23_11_2021-06_54_54.txt +0 -1
- PySimultan/resources/LibGit2Sharp.dll +0 -0
- PySimultan/resources/LibGit2Sharp.dll.config +0 -4
- PySimultan/resources/LibGit2Sharp.xml +0 -13770
- PySimultan/resources/MathNet.Numerics.dll +0 -0
- PySimultan/resources/MathNet.Numerics.xml +0 -57152
- PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
- PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.xml +0 -25496
- PySimultan/resources/Microsoft.WindowsAPICodePack.dll +0 -0
- PySimultan/resources/Microsoft.WindowsAPICodePack.xml +0 -2934
- PySimultan/resources/Newtonsoft.Json.dll +0 -0
- PySimultan/resources/Newtonsoft.Json.xml +0 -11305
- PySimultan/resources/ParameterStructure.dll +0 -0
- PySimultan/resources/ParameterStructure.xml +0 -10750
- PySimultan/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
- PySimultan/resources/SIMULTAN.DataExchange.dll +0 -0
- PySimultan/resources/SIMULTAN.Lang.dll +0 -0
- PySimultan/resources/SIMULTAN.Legacy.dll +0 -0
- PySimultan/resources/SIMULTAN.Legacy.xml +0 -254
- PySimultan/resources/SIMULTAN.Plugins.dll +0 -0
- PySimultan/resources/SIMULTAN.Project.dll +0 -0
- PySimultan/resources/SIMULTAN.Project.dll.config +0 -11
- PySimultan/resources/SIMULTAN.UI.dll +0 -0
- PySimultan/resources/SIMULTAN.Util.dll +0 -0
- PySimultan/resources/SIMULTAN.Util.xml +0 -3430
- PySimultan/resources/SharpDX.D3DCompiler.dll +0 -0
- PySimultan/resources/SharpDX.D3DCompiler.xml +0 -5897
- PySimultan/resources/SharpDX.DXGI.dll +0 -0
- PySimultan/resources/SharpDX.DXGI.xml +0 -8737
- PySimultan/resources/SharpDX.Direct2D1.dll +0 -0
- PySimultan/resources/SharpDX.Direct2D1.xml +0 -46691
- PySimultan/resources/SharpDX.Direct3D11.dll +0 -0
- PySimultan/resources/SharpDX.Direct3D11.xml +0 -31826
- PySimultan/resources/SharpDX.Direct3D9.dll +0 -0
- PySimultan/resources/SharpDX.Direct3D9.xml +0 -36489
- PySimultan/resources/SharpDX.Mathematics.xml +0 -16449
- PySimultan/resources/SharpDX.dll +0 -0
- PySimultan/resources/Sprache.dll +0 -0
- PySimultan/resources/Sprache.xml +0 -1199
- PySimultan/resources/System.Net.Http.Formatting.dll +0 -0
- PySimultan/resources/System.Net.Http.Formatting.xml +0 -2094
- PySimultan/resources/System.Windows.Interactivity.dll +0 -0
- PySimultan/resources/TalkGit.dll +0 -0
- PySimultan/resources/TalkGit.dll.config +0 -11
- PySimultan/resources/WebServiceConnector.dll +0 -0
- PySimultan/resources/WebServiceConnector.dll.config +0 -11
- PySimultan/resources/XAMLMarkupExtensions.dll +0 -0
- PySimultan/resources/XAMLMarkupExtensions.xml +0 -862
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Aero.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Metro.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.VS2010.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.dll +0 -0
- PySimultan/resources/Xceed.Wpf.Toolkit.dll +0 -0
- PySimultan/resources/assimp.dll +0 -0
- PySimultan/resources/schema.yaml +0 -13
- PySimultan/resources/simultan_exception_07_10_2021-08_34_24.txt +0 -17
- PySimultan/resources/simultan_exception_07_10_2021-10_13_31.txt +0 -17
- PySimultan/resources/simultan_exception_11_10_2021-19_45_42.txt +0 -17
- PySimultan/resources/simultan_exception_22_11_2021-16_41_52.txt +0 -14
- PySimultan/resources/simultan_exception_22_11_2021-17_37_40.txt +0 -14
- PySimultan/simultan_geometry_utils.py +0 -81
- PySimultan/simultan_utils.py +0 -165
- PySimultan/slots.py +0 -51
- PySimultan/template_tools.py +0 -631
- PySimultan/utils.py +0 -298
- PySimultan-0.1.54.dist-info/LICENSE +0 -674
- PySimultan-0.1.54.dist-info/LICENSE.txt +0 -674
- PySimultan-0.1.54.dist-info/METADATA +0 -690
- PySimultan-0.1.54.dist-info/RECORD +0 -119
- PySimultan-0.1.54.dist-info/entry_points.txt +0 -3
- PySimultan-0.1.54.dist-info/top_level.txt +0 -1
- PySimultan-0.1.54.dist-info/zip-safe +0 -1
- {PySimultan → PySimultan2}/resources/DotSpatial.Projections.dll +0 -0
- {PySimultan → PySimultan2}/resources/GeometryViewer.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.AutoUpdate.Client.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/Sprache.Calc.dll +0 -0
- {PySimultan → PySimultan2}/resources/__init__.py +0 -0
- {PySimultan → PySimultan2}/resources/setup.bat +0 -0
@@ -0,0 +1,181 @@
|
|
1
|
+
from typing import List, Type, Union, Optional
|
2
|
+
from numpy import array
|
3
|
+
from .. import config
|
4
|
+
from .geometry_base import (GeometryModel, SimultanLayer, SimultanVertex, SimultanEdge, SimultanEdgeLoop, SimultanFace,
|
5
|
+
SimultanVolume, BaseGeometry)
|
6
|
+
|
7
|
+
from SIMULTAN.Data.Geometry import (Layer, Vertex, Edge, PEdge, Face, Volume, EdgeLoop, OperationPermission,
|
8
|
+
GeometryModelOperationPermissions, GeometryOperationPermissions,
|
9
|
+
LayerOperationPermissions, GeometryModelData, GeometricOrientation,
|
10
|
+
BaseEdgeContainer)
|
11
|
+
|
12
|
+
from SIMULTAN.Data.Geometry import GeometryModel as NetGeometryModel
|
13
|
+
|
14
|
+
|
15
|
+
from typing import TYPE_CHECKING
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from ..default_types import ComponentList
|
18
|
+
from ..simultan_object import SimultanObject
|
19
|
+
from ..data_model import DataModel
|
20
|
+
from ..object_mapper import PythonMapper
|
21
|
+
|
22
|
+
|
23
|
+
python_map_dict = {Layer: SimultanLayer,
|
24
|
+
Vertex: SimultanVertex,
|
25
|
+
Edge: SimultanEdge,
|
26
|
+
EdgeLoop: SimultanEdgeLoop,
|
27
|
+
Face: SimultanFace,
|
28
|
+
Volume: SimultanVolume}
|
29
|
+
|
30
|
+
|
31
|
+
def create_python_geometry(cls,
|
32
|
+
sim_geometry: Union[Layer, Vertex, Edge, Face, Volume, EdgeLoop],
|
33
|
+
data_model: 'DataModel',
|
34
|
+
python_mapper: 'PythonMapper',
|
35
|
+
geometry_model: Union[GeometryModel, NetGeometryModel] = None,
|
36
|
+
) -> Union[SimultanLayer, SimultanVertex, SimultanEdge, SimultanEdgeLoop, SimultanFace, SimultanVolume]:
|
37
|
+
|
38
|
+
if isinstance(geometry_model, NetGeometryModel):
|
39
|
+
geometry_model = GeometryModel(wrapped_object=geometry_model,
|
40
|
+
data_model=data_model,
|
41
|
+
python_mapper=python_mapper)
|
42
|
+
|
43
|
+
if type(sim_geometry) in python_map_dict:
|
44
|
+
if cls is None:
|
45
|
+
cls = python_map_dict.get(type(sim_geometry))
|
46
|
+
return cls(wrapped_object=sim_geometry,
|
47
|
+
data_model=data_model,
|
48
|
+
geometry_model=geometry_model,
|
49
|
+
python_mapper=python_mapper)
|
50
|
+
else:
|
51
|
+
raise ValueError(f'Could not create python object for {sim_geometry}')
|
52
|
+
|
53
|
+
|
54
|
+
def create_cube(data_model,
|
55
|
+
geo_model: GeometryModel,
|
56
|
+
obj_mapper: Optional['PythonMapper'] = None,
|
57
|
+
scale: Optional[float] = 1):
|
58
|
+
|
59
|
+
if obj_mapper is None:
|
60
|
+
obj_mapper = config.default_mapper
|
61
|
+
|
62
|
+
new_layer = obj_mapper.registered_geometry_classes[Layer](geometry_model=geo_model,
|
63
|
+
data_model=data_model,
|
64
|
+
name='new_layer')
|
65
|
+
|
66
|
+
def create_vertex(layer, x, y, z, name, geo_model):
|
67
|
+
new_vertex = obj_mapper.registered_geometry_classes[Vertex](geometry_model=geo_model,
|
68
|
+
x=x,
|
69
|
+
y=y,
|
70
|
+
z=z,
|
71
|
+
data_model=data_model,
|
72
|
+
name=name,
|
73
|
+
layer=layer)
|
74
|
+
assert isinstance(new_vertex, SimultanVertex)
|
75
|
+
return new_vertex
|
76
|
+
|
77
|
+
def create_edge(layer, vertices, name, geo_model):
|
78
|
+
new_edge = obj_mapper.registered_geometry_classes[Edge](geometry_model=geo_model,
|
79
|
+
data_model=data_model,
|
80
|
+
name=name,
|
81
|
+
layer=layer,
|
82
|
+
vertices=vertices)
|
83
|
+
assert isinstance(new_edge, SimultanEdge)
|
84
|
+
return new_edge
|
85
|
+
|
86
|
+
def create_edge_loop(layer, edges, name, geo_model):
|
87
|
+
new_edge_loop = obj_mapper.registered_geometry_classes[EdgeLoop](geometry_model=geo_model,
|
88
|
+
data_model=data_model,
|
89
|
+
name=name,
|
90
|
+
layer=layer,
|
91
|
+
edges=edges)
|
92
|
+
assert isinstance(new_edge_loop, SimultanEdgeLoop)
|
93
|
+
return new_edge_loop
|
94
|
+
|
95
|
+
def create_face(layer, edge_loop, name, geo_model):
|
96
|
+
new_face = obj_mapper.registered_geometry_classes[Face](geometry_model=geo_model,
|
97
|
+
data_model=data_model,
|
98
|
+
name=name,
|
99
|
+
layer=layer,
|
100
|
+
edge_loop=edge_loop)
|
101
|
+
assert isinstance(new_face, SimultanFace)
|
102
|
+
return new_face
|
103
|
+
|
104
|
+
# create a cube
|
105
|
+
vertex_pos = array([(0, 0, 0), (0.707, 0.707, 0), (0, 1.414, 0), (-0.707, 0.707, 0),
|
106
|
+
(0, 0, 1), (0.707, 0.707, 1), (0, 1.414, 1), (-0.707, 0.707, 1)]) * scale
|
107
|
+
|
108
|
+
vertices = []
|
109
|
+
for i, pos in enumerate(vertex_pos.tolist()):
|
110
|
+
vertices.append(create_vertex(new_layer,
|
111
|
+
*pos,
|
112
|
+
'new_vertex_{}'.format(i),
|
113
|
+
geo_model
|
114
|
+
)
|
115
|
+
)
|
116
|
+
|
117
|
+
edges_vertices = [(vertices[0], vertices[1]),
|
118
|
+
(vertices[1], vertices[2]),
|
119
|
+
(vertices[2], vertices[3]),
|
120
|
+
(vertices[3], vertices[0]),
|
121
|
+
(vertices[4], vertices[5]),
|
122
|
+
(vertices[5], vertices[6]),
|
123
|
+
(vertices[6], vertices[7]),
|
124
|
+
(vertices[7], vertices[4]),
|
125
|
+
(vertices[0], vertices[4]),
|
126
|
+
(vertices[1], vertices[5]),
|
127
|
+
(vertices[2], vertices[6]),
|
128
|
+
(vertices[3], vertices[7])
|
129
|
+
]
|
130
|
+
edges = []
|
131
|
+
|
132
|
+
for i, edge_vertices in enumerate(edges_vertices):
|
133
|
+
edges.append(create_edge(new_layer,
|
134
|
+
edge_vertices,
|
135
|
+
'new_edge_{}'.format(i),
|
136
|
+
geo_model
|
137
|
+
))
|
138
|
+
|
139
|
+
# create 6 edge loops as boundary for the cube
|
140
|
+
edge_loop_edges = [
|
141
|
+
# Front face loop
|
142
|
+
[edges[0], edges[1], edges[2], edges[3]],
|
143
|
+
# Back face loop
|
144
|
+
[edges[4], edges[5], edges[6], edges[7]],
|
145
|
+
# Top face loop
|
146
|
+
[edges[1], edges[10], edges[5], edges[9]],
|
147
|
+
# Bottom face loop
|
148
|
+
[edges[3], edges[11], edges[7], edges[8]],
|
149
|
+
# Left face loop
|
150
|
+
[edges[0], edges[9], edges[4], edges[8]],
|
151
|
+
# Right face loop
|
152
|
+
[edges[2], edges[11], edges[6], edges[10]]
|
153
|
+
]
|
154
|
+
|
155
|
+
edge_loops = []
|
156
|
+
for i, edge_loop_edge in enumerate(edge_loop_edges):
|
157
|
+
edge_loops.append(create_edge_loop(new_layer,
|
158
|
+
edge_loop_edge,
|
159
|
+
'new_edge_loop_{}'.format(i),
|
160
|
+
geo_model),
|
161
|
+
)
|
162
|
+
|
163
|
+
# create faces
|
164
|
+
faces = []
|
165
|
+
for i, edge_loop in enumerate(edge_loops):
|
166
|
+
faces.append(create_face(new_layer,
|
167
|
+
edge_loop,
|
168
|
+
'new_face_{}'.format(i),
|
169
|
+
geo_model
|
170
|
+
)
|
171
|
+
)
|
172
|
+
|
173
|
+
# create a volume
|
174
|
+
|
175
|
+
volume = obj_mapper.registered_geometry_classes[Volume](geometry_model=geo_model,
|
176
|
+
data_model=data_model,
|
177
|
+
name='new_volume',
|
178
|
+
layer=new_layer,
|
179
|
+
faces=faces)
|
180
|
+
|
181
|
+
return volume
|
@@ -0,0 +1,277 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import Union
|
3
|
+
from itertools import product
|
4
|
+
|
5
|
+
import numpy as np
|
6
|
+
import pandas as pd
|
7
|
+
from SIMULTAN.Data.Components import SimDoubleParameter, SimParameterOperations
|
8
|
+
from SIMULTAN.Data.MultiValues import (SimMultiValueField3D, SimMultiValueField3DParameterSource, SimMultiValueBigTable,
|
9
|
+
SimMultiValueBigTableHeader, SimMultiValueBigTableParameterSource)
|
10
|
+
from SIMULTAN.Data.Taxonomy import SimTaxonomyEntry
|
11
|
+
from System import Array, Double, Object, Boolean, String
|
12
|
+
from System.Collections.Generic import List as NetList
|
13
|
+
from System.Collections.Generic import ICollection as NetICollection
|
14
|
+
from pandas import DataFrame
|
15
|
+
|
16
|
+
import System
|
17
|
+
|
18
|
+
|
19
|
+
def numpy_to_simultan_multi_value_field_3d(array: np.ndarray,
|
20
|
+
name: str = 'UnnamedField',
|
21
|
+
x_axis: list = None,
|
22
|
+
y_axis: list = None,
|
23
|
+
z_axis: list = None,
|
24
|
+
unit_x: str = '',
|
25
|
+
unit_y: str = '',
|
26
|
+
unit_z: str = '',
|
27
|
+
can_interpolate: bool = True) -> SimMultiValueField3D:
|
28
|
+
"""
|
29
|
+
Convert a numpy array to a SimMultiValueField3D object. The x, y, and z axes can be provided as lists.
|
30
|
+
If not provided, the axes will be generated based on the shape of the input array.
|
31
|
+
:param array: The input numpy array
|
32
|
+
:param name: The name of the field, default is 'UnnamedField'
|
33
|
+
:param x_axis: The x-axis of the field, default is None
|
34
|
+
:param y_axis: The y-axis of the field, default is None
|
35
|
+
:param z_axis: The z-axis of the field, default is None
|
36
|
+
:param unit_x: The unit of the x-axis, default is ''
|
37
|
+
:param unit_y: The unit of the y-axis, default is ''
|
38
|
+
:param unit_z: The unit of the z-axis, default is ''
|
39
|
+
:param can_interpolate: If True, the field can be interpolated. Default is True.
|
40
|
+
data_model = None
|
41
|
+
:return:
|
42
|
+
"""
|
43
|
+
if not isinstance(array, np.ndarray):
|
44
|
+
raise ValueError('The input array must be a numpy array.')
|
45
|
+
|
46
|
+
if array.ndim < 3:
|
47
|
+
if array.ndim == 1:
|
48
|
+
array = np.expand_dims(array, axis=(1, 2))
|
49
|
+
elif array.ndim == 2:
|
50
|
+
array = np.expand_dims(array, axis=2)
|
51
|
+
else:
|
52
|
+
raise ValueError('The input array must be at least 2-dimensional.')
|
53
|
+
|
54
|
+
if x_axis is None:
|
55
|
+
x_axis = NetList[Double](Array[Double](list(range(array.astype(float).shape[0]))))
|
56
|
+
|
57
|
+
if y_axis is None:
|
58
|
+
y_axis = NetList[Double](Array[Double](list(range(array.astype(float).shape[1]))))
|
59
|
+
|
60
|
+
if z_axis is None:
|
61
|
+
z_axis = NetList[Double](Array[Double](list(range(array.astype(float).shape[2]))))
|
62
|
+
|
63
|
+
data = NetList[Double](Array[Double](array.astype(float).flatten(order='F')))
|
64
|
+
|
65
|
+
field = SimMultiValueField3D(name, x_axis, unit_x, y_axis, unit_y, z_axis, unit_z, data, can_interpolate)
|
66
|
+
|
67
|
+
return field
|
68
|
+
|
69
|
+
|
70
|
+
def pandas_to_simultan_multi_value_big_table(df: pd.DataFrame,
|
71
|
+
name: str = 'UnnamedField',
|
72
|
+
unit_columns: str = '',
|
73
|
+
unit_rows: str = '',
|
74
|
+
column_headers: SimMultiValueBigTableHeader = None,
|
75
|
+
row_headers: SimMultiValueBigTableHeader = None) -> SimMultiValueBigTable:
|
76
|
+
"""
|
77
|
+
Convert a pandas DataFrame to a SimMultiValueField3D object. The x, y, and z axes can be provided as lists. If not
|
78
|
+
provided, the axes will be generated based on the shape of the input DataFrame.
|
79
|
+
:param df:
|
80
|
+
:param name:
|
81
|
+
:param unit_columns: The unit of the columns
|
82
|
+
:param unit_rows: The unit of the rows
|
83
|
+
:param column_headers: The column headers
|
84
|
+
:param row_headers: The row headers
|
85
|
+
:return: SimMultiValueBigTable
|
86
|
+
"""
|
87
|
+
|
88
|
+
if not isinstance(df, DataFrame):
|
89
|
+
raise ValueError('The input df must be a pandas DataFrame.')
|
90
|
+
|
91
|
+
if column_headers is None:
|
92
|
+
column_headers = NetICollection[SimMultiValueBigTableHeader](
|
93
|
+
Array[SimMultiValueBigTableHeader]([SimMultiValueBigTableHeader(str(x), '') for x in df.columns]))
|
94
|
+
|
95
|
+
if row_headers is None:
|
96
|
+
row_headers = NetICollection[SimMultiValueBigTableHeader](
|
97
|
+
Array[SimMultiValueBigTableHeader]([SimMultiValueBigTableHeader(str(x), '') for x in df.index]))
|
98
|
+
|
99
|
+
#
|
100
|
+
data = NetList[NetList[Double]]()
|
101
|
+
for i in range(len(df.index)):
|
102
|
+
data.Add(NetList[Double](Array[Double](df.values[i].astype(float))))
|
103
|
+
|
104
|
+
field = SimMultiValueBigTable(name,
|
105
|
+
unit_columns,
|
106
|
+
unit_rows,
|
107
|
+
column_headers,
|
108
|
+
row_headers,
|
109
|
+
data,
|
110
|
+
True)
|
111
|
+
return field
|
112
|
+
|
113
|
+
|
114
|
+
def simultan_multi_value_big_table_to_pandas(field: SimMultiValueBigTable) -> pd.DataFrame:
|
115
|
+
"""
|
116
|
+
Convert a SimMultiValueBigTable object to a pandas DataFrame.
|
117
|
+
:param field:
|
118
|
+
:return:
|
119
|
+
"""
|
120
|
+
if not isinstance(field, SimMultiValueBigTable):
|
121
|
+
raise ValueError('The input field must be a SimMultiValueBigTable object.')
|
122
|
+
|
123
|
+
data = np.ndarray((field.RowHeaders.Count, field.ColumnHeaders.Count))
|
124
|
+
for i in range(field.RowHeaders.Count):
|
125
|
+
data[i, :] = list(field.GetRow(i))
|
126
|
+
|
127
|
+
df = pd.DataFrame(data, columns=[x.Name for x in field.ColumnHeaders], index=[x.Name for x in field.RowHeaders])
|
128
|
+
|
129
|
+
return df
|
130
|
+
|
131
|
+
|
132
|
+
def simultan_multi_value_field_3d_to_numpy(field: SimMultiValueField3D, assert_ordered=False) -> np.ndarray:
|
133
|
+
"""
|
134
|
+
Convert a SimMultiValueField3D object to a numpy array.
|
135
|
+
:param field:
|
136
|
+
:param assert_ordered: If True, the function will check if the field is ordered. Default is True.
|
137
|
+
:return:
|
138
|
+
"""
|
139
|
+
if not isinstance(field, SimMultiValueField3D):
|
140
|
+
raise ValueError('The input field must be a SimMultiValueField3D object.')
|
141
|
+
|
142
|
+
if assert_ordered:
|
143
|
+
data = [x.Value for x in field.Field]
|
144
|
+
x_axis = list(field.XAxis)
|
145
|
+
y_axis = list(field.YAxis)
|
146
|
+
z_axis = list(field.ZAxis)
|
147
|
+
array = np.array(data).reshape(len(x_axis), len(y_axis), len(z_axis))
|
148
|
+
else:
|
149
|
+
array = np.empty((len(field.XAxis), len(field.YAxis), len(field.ZAxis)))
|
150
|
+
for comb in product(range(len(field.XAxis)), range(len(field.YAxis)), range(len(field.ZAxis)), repeat=1):
|
151
|
+
array[comb[0], comb[1], comb[2]] = field[comb[0], comb[1], comb[2]]
|
152
|
+
|
153
|
+
return np.squeeze(array)
|
154
|
+
|
155
|
+
|
156
|
+
def add_field_to_data_model(field: SimMultiValueField3D, data_model: 'SimultanObject') -> SimMultiValueField3D:
|
157
|
+
"""
|
158
|
+
Add a SimMultiValueField3D object to a data model.
|
159
|
+
:param field: The SimMultiValueField3D object
|
160
|
+
:param data_model: The data model
|
161
|
+
:return: SimMultiValueField3D
|
162
|
+
"""
|
163
|
+
if not isinstance(field, SimMultiValueField3D):
|
164
|
+
raise ValueError('The input field must be a SimMultiValueField3D object.')
|
165
|
+
|
166
|
+
if data_model is None:
|
167
|
+
raise ValueError('The data model must not be None.')
|
168
|
+
data_model.add_field(field)
|
169
|
+
|
170
|
+
|
171
|
+
def set_parameter_to_value_field(parameter: SimDoubleParameter,
|
172
|
+
value: Union[SimMultiValueField3D, np.ndarray, DataFrame],
|
173
|
+
field_name: str = None,
|
174
|
+
x_ax_val: float = None,
|
175
|
+
y_ax_val: float = None,
|
176
|
+
z_ax_val: float = None,
|
177
|
+
data_model=None) -> SimDoubleParameter:
|
178
|
+
"""
|
179
|
+
Set the value of a field parameter to a SimMultiValueField3D object. The value can be a SimMultiValueField3D object,
|
180
|
+
a numpy array, or a DataFrame.
|
181
|
+
:param parameter: The field parameter
|
182
|
+
:param value: The value of the parameter (SimMultiValueField3D, numpy array, or DataFrame)
|
183
|
+
:param field_name: The name of the field, default is None
|
184
|
+
:param x_ax_val: The value on the X-Axis (NOT the index/position)
|
185
|
+
:param y_ax_val: The value on the Y-Axis (NOT the index/position)
|
186
|
+
:param z_ax_val: The value on the Z-Axis (NOT the index/position)
|
187
|
+
:param data_model: The data model, default is None. If data_model is not None, the SimMultiValueField3D will be
|
188
|
+
added to the data model (if SimMultiValueField3D is created).
|
189
|
+
:return: SimDoubleParameter
|
190
|
+
"""
|
191
|
+
|
192
|
+
if not isinstance(parameter, SimDoubleParameter):
|
193
|
+
raise ValueError('The input parameter must be a SimDoubleParameter object.')
|
194
|
+
|
195
|
+
if isinstance(value, SimMultiValueField3D):
|
196
|
+
source = value
|
197
|
+
elif isinstance(value, np.ndarray):
|
198
|
+
value_field = numpy_to_simultan_multi_value_field_3d(value,
|
199
|
+
name=field_name if field_name is not None else str(
|
200
|
+
parameter.Id) + '_field')
|
201
|
+
if data_model is not None:
|
202
|
+
data_model.add_field(value_field)
|
203
|
+
|
204
|
+
x_ax_val = x_ax_val if x_ax_val is not None else value_field.XAxis[0]
|
205
|
+
y_ax_val = y_ax_val if y_ax_val is not None else value_field.YAxis[0]
|
206
|
+
z_ax_val = z_ax_val if z_ax_val is not None else value_field.ZAxis[0]
|
207
|
+
|
208
|
+
source = SimMultiValueField3DParameterSource(value_field, x_ax_val, y_ax_val, z_ax_val)
|
209
|
+
|
210
|
+
elif isinstance(value, pd.DataFrame):
|
211
|
+
value_field = pandas_to_simultan_multi_value_big_table(value,
|
212
|
+
name=field_name if field_name is not None else str(
|
213
|
+
parameter.Id) + '_field')
|
214
|
+
if data_model is not None:
|
215
|
+
data_model.add_field(value_field)
|
216
|
+
|
217
|
+
source = SimMultiValueBigTableParameterSource(value_field, 0, 0)
|
218
|
+
|
219
|
+
else:
|
220
|
+
raise ValueError('The value of the field parameter must be a numpy array or a DataFrame.')
|
221
|
+
|
222
|
+
parameter.set_ValueSource(source)
|
223
|
+
return parameter
|
224
|
+
|
225
|
+
|
226
|
+
def create_field_parameter(value: Union[SimMultiValueField3D, np.ndarray, DataFrame],
|
227
|
+
name: str = 'unnamed parameter',
|
228
|
+
field_name: str = None,
|
229
|
+
unit: str = '',
|
230
|
+
slot: SimTaxonomyEntry = None,
|
231
|
+
min_value: float = None,
|
232
|
+
max_value: float = None,
|
233
|
+
allowed_operations: int = SimParameterOperations(0).All,
|
234
|
+
x_ax_val: float = None,
|
235
|
+
y_ax_val: float = None,
|
236
|
+
z_ax_val: float = None,
|
237
|
+
data_model=None
|
238
|
+
) -> SimDoubleParameter:
|
239
|
+
"""
|
240
|
+
Create a field parameter with a SimMultiValueField3D as value. The value can be a SimMultiValueField3D object, a
|
241
|
+
numpy array, or a DataFrame.
|
242
|
+
:param value: The value of the parameter (SimMultiValueField3D, numpy array, or DataFrame)
|
243
|
+
:param name: The name of the parameter, default is 'unnamed parameter'
|
244
|
+
:param field_name: The name of the field, default is None
|
245
|
+
:param unit: The unit of the parameter, default is ''
|
246
|
+
:param slot: SimTaxonomyEntry
|
247
|
+
:param min_value: The minimum value for the parameter, default is None
|
248
|
+
:param max_value: The maximum value for the parameter, default is None
|
249
|
+
:param allowed_operations: The allowed operations for the parameter (e.g. SimParameterOperations(0).All)
|
250
|
+
:param x_ax_val: The value on the X-Axis (NOT the index/position)
|
251
|
+
:param y_ax_val: The value on the Y-Axis (NOT the index/position)
|
252
|
+
:param z_ax_val: The value on the Z-Axis (NOT the index/position)
|
253
|
+
:param data_model: The data model, default is None. If data_model is not None, the SimMultiValueField3D will be
|
254
|
+
added to the data model.
|
255
|
+
:return: SimDoubleParameter
|
256
|
+
"""
|
257
|
+
|
258
|
+
from .utils import create_sim_double_parameter
|
259
|
+
|
260
|
+
param_init_dict = {'value': 0}
|
261
|
+
|
262
|
+
for key in ['name', 'unit', 'slot', 'min_value', 'max_value', 'allowed_operations']:
|
263
|
+
if locals()[key] is not None:
|
264
|
+
param_init_dict[key] = locals()[key]
|
265
|
+
|
266
|
+
param = create_sim_double_parameter(**param_init_dict)
|
267
|
+
|
268
|
+
set_parameter_to_value_field(param,
|
269
|
+
value,
|
270
|
+
field_name=field_name,
|
271
|
+
x_ax_val=x_ax_val,
|
272
|
+
y_ax_val=y_ax_val,
|
273
|
+
z_ax_val=z_ax_val,
|
274
|
+
data_model=data_model
|
275
|
+
)
|
276
|
+
|
277
|
+
return param
|
@@ -0,0 +1,200 @@
|
|
1
|
+
from collections import UserList
|
2
|
+
from weakref import WeakSet
|
3
|
+
from typing import Type
|
4
|
+
from colorlog import getLogger
|
5
|
+
|
6
|
+
from . import config
|
7
|
+
from .data_model import data_models
|
8
|
+
from .utils import *
|
9
|
+
from .default_types import ComponentList, component_list_map, ComponentDictionary, component_dict_map
|
10
|
+
|
11
|
+
from .simultan_object import SimultanObject
|
12
|
+
from .geometry.utils import create_python_geometry
|
13
|
+
|
14
|
+
from SIMULTAN.Data.Geometry import (Layer, Vertex, Edge, PEdge, Face, Volume, EdgeLoop)
|
15
|
+
from .geometry.geometry_base import (SimultanLayer, SimultanVertex, SimultanEdge, SimultanEdgeLoop, SimultanFace,
|
16
|
+
SimultanVolume)
|
17
|
+
|
18
|
+
logger = getLogger('PySimultan')
|
19
|
+
|
20
|
+
default_registered_classes = {'ComponentList': ComponentList,
|
21
|
+
'ComponentDict': ComponentDictionary}
|
22
|
+
default_mapped_classes = {}
|
23
|
+
default_taxonomy_maps = {'ComponentList': component_list_map,
|
24
|
+
'ComponentDict': component_dict_map}
|
25
|
+
|
26
|
+
|
27
|
+
class PythonMapper(object):
|
28
|
+
|
29
|
+
def __new__(cls, *args, **kwargs):
|
30
|
+
instance = super(PythonMapper, cls).__new__(cls)
|
31
|
+
config.default_mapper = instance
|
32
|
+
return instance
|
33
|
+
|
34
|
+
def __init__(self, *args, **kwargs):
|
35
|
+
self.registered_classes = default_registered_classes # dict with all registered classes: {taxonomy: class}
|
36
|
+
self.mapped_classes = default_mapped_classes # dict with all mapped classes: {taxonomy: class}
|
37
|
+
self.taxonomy_maps = default_taxonomy_maps # dict with all taxonomie maps: {taxonomy: taxonomie_map}
|
38
|
+
|
39
|
+
self.registered_geometry_classes = {Layer: SimultanLayer,
|
40
|
+
Vertex: SimultanVertex,
|
41
|
+
Edge: SimultanEdge,
|
42
|
+
Face: SimultanFace,
|
43
|
+
Volume: SimultanVolume,
|
44
|
+
EdgeLoop: SimultanEdgeLoop}
|
45
|
+
|
46
|
+
self.re_register = False
|
47
|
+
|
48
|
+
def register(self, taxonomy, cls, taxonomy_map=None):
|
49
|
+
if not self.re_register and taxonomy in self.registered_classes.keys():
|
50
|
+
return
|
51
|
+
|
52
|
+
self.registered_classes[taxonomy] = cls
|
53
|
+
self.taxonomy_maps[taxonomy] = taxonomy_map
|
54
|
+
|
55
|
+
def create_mapped_class(self, taxonomy, cls):
|
56
|
+
|
57
|
+
if any([issubclass(cls, x) for x in (SimultanObject, UserList)]):
|
58
|
+
bases = (cls,)
|
59
|
+
else:
|
60
|
+
bases = (SimultanObject,) + (cls,)
|
61
|
+
|
62
|
+
def new_init(self, *args, **kwargs):
|
63
|
+
for base in self.__class__.__bases__:
|
64
|
+
base.__init__(self, *args, **kwargs)
|
65
|
+
|
66
|
+
new_class_dict = {'__init__': new_init,
|
67
|
+
'__name__': cls.__name__,
|
68
|
+
'_taxonomy': taxonomy,
|
69
|
+
'_taxonomy_map': self.taxonomy_maps.get(taxonomy, None),
|
70
|
+
'_base': bases,
|
71
|
+
'_object_mapper': self}
|
72
|
+
|
73
|
+
new_class_dict.update(self.get_properties(taxonomy))
|
74
|
+
new_class = type(cls.__name__, bases, new_class_dict)
|
75
|
+
|
76
|
+
self.mapped_classes[taxonomy] = new_class
|
77
|
+
|
78
|
+
return new_class
|
79
|
+
|
80
|
+
def get_mapped_class(self, taxonomy) -> Type[SimultanObject]:
|
81
|
+
if self.mapped_classes.get(taxonomy, None) is None:
|
82
|
+
self.create_mapped_class(taxonomy, self.registered_classes[taxonomy])
|
83
|
+
|
84
|
+
return self.mapped_classes.get(taxonomy, None)
|
85
|
+
|
86
|
+
def get_typed_data(self, data_model=None, component_list=None, create_all=False):
|
87
|
+
|
88
|
+
typed_data = []
|
89
|
+
|
90
|
+
if component_list is None:
|
91
|
+
component_list = list(data_model.data.Items)
|
92
|
+
|
93
|
+
if data_model is None:
|
94
|
+
data_model = list(data_models)[0]
|
95
|
+
|
96
|
+
for component in component_list:
|
97
|
+
typed_object = self.create_python_object(component, data_model=data_model)
|
98
|
+
typed_data.append(typed_object)
|
99
|
+
if create_all:
|
100
|
+
|
101
|
+
def get_content(typed_object):
|
102
|
+
if isinstance(typed_object, SimultanObject):
|
103
|
+
for content in typed_object.__class__._taxonomy_map.content:
|
104
|
+
val = getattr(typed_object, content.property_name)
|
105
|
+
if isinstance(val, (SimultanObject, ComponentList, ComponentDictionary)):
|
106
|
+
typed_data.append(val)
|
107
|
+
get_content(val)
|
108
|
+
elif isinstance(typed_object, ComponentList):
|
109
|
+
for item in typed_object:
|
110
|
+
if isinstance(item, (SimultanObject, ComponentList, ComponentDictionary)):
|
111
|
+
typed_data.append(item)
|
112
|
+
get_content(item)
|
113
|
+
elif isinstance(typed_object, ComponentDictionary):
|
114
|
+
for item in typed_object.values():
|
115
|
+
if isinstance(item, (SimultanObject, ComponentList, ComponentDictionary)):
|
116
|
+
typed_data.append(item)
|
117
|
+
get_content(item)
|
118
|
+
|
119
|
+
get_content(typed_object)
|
120
|
+
|
121
|
+
return typed_data
|
122
|
+
|
123
|
+
# @lru_cache(maxsize=None)
|
124
|
+
def create_python_object(self, component, cls=None, data_model=None, *args, **kwargs):
|
125
|
+
|
126
|
+
if component is None:
|
127
|
+
return None
|
128
|
+
|
129
|
+
if data_model is None:
|
130
|
+
data_model_id = list(data_models)[0].id
|
131
|
+
data_model = list(data_models)[0]
|
132
|
+
else:
|
133
|
+
data_model_id = data_model.id
|
134
|
+
|
135
|
+
if isinstance(component, (Layer, Vertex, Edge, PEdge, Face, Volume, EdgeLoop)):
|
136
|
+
if isinstance(component, Layer):
|
137
|
+
geometry_model = component.Model.Model
|
138
|
+
else:
|
139
|
+
geometry_model = component.Layer.Model.Model
|
140
|
+
cls = self.registered_geometry_classes[type(component)]
|
141
|
+
return create_python_geometry(cls, component, data_model_id, self, geometry_model)
|
142
|
+
|
143
|
+
if cls is None:
|
144
|
+
c_slots = [x.Target.Key for x in component.Slots.Items]
|
145
|
+
c_slot = list(set(c_slots) & set(self.registered_classes.keys()))
|
146
|
+
if len(c_slot) == 0:
|
147
|
+
if c_slots[0] not in self.registered_classes.keys():
|
148
|
+
self.register(c_slots[0], SimultanObject)
|
149
|
+
c_slot = [c_slots[0]]
|
150
|
+
elif len(c_slot) > 1:
|
151
|
+
num_superclasses = [len(self.registered_classes[x].__mro__) for x in c_slot]
|
152
|
+
c_slot = [c_slot[num_superclasses.index(max(num_superclasses))]]
|
153
|
+
# raise Warning(f'Component {component} has more than one registered taxonomy: {c_slot}')
|
154
|
+
|
155
|
+
if c_slot[0] not in self.mapped_classes.keys():
|
156
|
+
self.create_mapped_class(c_slot[0], self.registered_classes[c_slot[0]])
|
157
|
+
|
158
|
+
cls = self.mapped_classes[c_slot[0]]
|
159
|
+
|
160
|
+
if component is not None and component.Id in cls._cls_instances_dict.keys():
|
161
|
+
return cls._cls_instances_dict[component.Id]
|
162
|
+
else:
|
163
|
+
return create_python_object(component,
|
164
|
+
cls,
|
165
|
+
data_model_id=data_model_id,
|
166
|
+
object_mapper=self,
|
167
|
+
data_model=data_model,
|
168
|
+
|
169
|
+
*args,
|
170
|
+
**kwargs)
|
171
|
+
|
172
|
+
def get_typed_data_with_taxonomy(self, taxonomy: str, data_model=None, first=False):
|
173
|
+
|
174
|
+
tax_components = data_model.find_components_with_taxonomy(taxonomy=taxonomy, first=first)
|
175
|
+
return self.get_typed_data(component_list=tax_components)
|
176
|
+
|
177
|
+
def get_properties(self, taxonomy):
|
178
|
+
|
179
|
+
prop_dict = {}
|
180
|
+
taxonomy_map = self.taxonomy_maps.get(taxonomy, None)
|
181
|
+
|
182
|
+
if taxonomy_map is None:
|
183
|
+
return prop_dict
|
184
|
+
|
185
|
+
for prop in taxonomy_map.content:
|
186
|
+
|
187
|
+
prop_dict[prop.property_name] = add_properties(prop_name=prop.property_name,
|
188
|
+
content=prop,
|
189
|
+
taxonomy_map=taxonomy_map,
|
190
|
+
taxonomy=taxonomy)
|
191
|
+
|
192
|
+
return prop_dict
|
193
|
+
|
194
|
+
def clear(self):
|
195
|
+
for cls in self.mapped_classes.values():
|
196
|
+
cls._cls_instances = WeakSet()
|
197
|
+
|
198
|
+
|
199
|
+
if config.default_mapper is None:
|
200
|
+
config.default_mapper = PythonMapper()
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|