subsurface-terra 2025.1.0rc15__py3-none-any.whl → 2025.1.0rc17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. subsurface/__init__.py +31 -31
  2. subsurface/_version.py +34 -21
  3. subsurface/api/__init__.py +13 -13
  4. subsurface/api/interfaces/__init__.py +3 -3
  5. subsurface/api/interfaces/stream.py +136 -136
  6. subsurface/api/reader/read_wells.py +78 -78
  7. subsurface/core/geological_formats/boreholes/_combine_trajectories.py +117 -117
  8. subsurface/core/geological_formats/boreholes/_map_attrs_to_survey.py +236 -234
  9. subsurface/core/geological_formats/boreholes/_survey_to_unstruct.py +163 -163
  10. subsurface/core/geological_formats/boreholes/boreholes.py +140 -140
  11. subsurface/core/geological_formats/boreholes/collars.py +26 -26
  12. subsurface/core/geological_formats/boreholes/survey.py +86 -86
  13. subsurface/core/geological_formats/fault.py +47 -47
  14. subsurface/core/reader_helpers/reader_unstruct.py +11 -11
  15. subsurface/core/reader_helpers/readers_data.py +130 -130
  16. subsurface/core/reader_helpers/readers_wells.py +13 -13
  17. subsurface/core/structs/__init__.py +3 -3
  18. subsurface/core/structs/base_structures/__init__.py +2 -2
  19. subsurface/core/structs/base_structures/_aux.py +69 -0
  20. subsurface/core/structs/base_structures/_liquid_earth_mesh.py +121 -121
  21. subsurface/core/structs/base_structures/_unstructured_data_constructor.py +70 -70
  22. subsurface/core/structs/base_structures/base_structures_enum.py +6 -6
  23. subsurface/core/structs/base_structures/structured_data.py +282 -282
  24. subsurface/core/structs/base_structures/unstructured_data.py +338 -319
  25. subsurface/core/structs/structured_elements/octree_mesh.py +10 -10
  26. subsurface/core/structs/structured_elements/structured_grid.py +59 -59
  27. subsurface/core/structs/structured_elements/structured_mesh.py +9 -9
  28. subsurface/core/structs/unstructured_elements/__init__.py +3 -3
  29. subsurface/core/structs/unstructured_elements/line_set.py +72 -72
  30. subsurface/core/structs/unstructured_elements/point_set.py +43 -43
  31. subsurface/core/structs/unstructured_elements/tetrahedron_mesh.py +35 -35
  32. subsurface/core/structs/unstructured_elements/triangular_surface.py +62 -62
  33. subsurface/core/utils/utils_core.py +38 -38
  34. subsurface/modules/reader/__init__.py +13 -13
  35. subsurface/modules/reader/faults/faults.py +80 -80
  36. subsurface/modules/reader/from_binary.py +46 -46
  37. subsurface/modules/reader/mesh/_GOCAD_mesh.py +82 -82
  38. subsurface/modules/reader/mesh/_trimesh_reader.py +447 -447
  39. subsurface/modules/reader/mesh/csv_mesh_reader.py +53 -53
  40. subsurface/modules/reader/mesh/dxf_reader.py +177 -177
  41. subsurface/modules/reader/mesh/glb_reader.py +30 -30
  42. subsurface/modules/reader/mesh/mx_reader.py +232 -232
  43. subsurface/modules/reader/mesh/obj_reader.py +53 -53
  44. subsurface/modules/reader/mesh/omf_mesh_reader.py +43 -43
  45. subsurface/modules/reader/mesh/surface_reader.py +56 -56
  46. subsurface/modules/reader/mesh/surfaces_api.py +41 -41
  47. subsurface/modules/reader/profiles/__init__.py +3 -3
  48. subsurface/modules/reader/profiles/profiles_core.py +197 -197
  49. subsurface/modules/reader/read_netcdf.py +38 -38
  50. subsurface/modules/reader/topography/__init__.py +7 -7
  51. subsurface/modules/reader/topography/topo_core.py +100 -100
  52. subsurface/modules/reader/volume/read_grav3d.py +447 -428
  53. subsurface/modules/reader/volume/read_volume.py +327 -230
  54. subsurface/modules/reader/volume/segy_reader.py +105 -105
  55. subsurface/modules/reader/volume/seismic.py +173 -173
  56. subsurface/modules/reader/volume/volume_utils.py +43 -43
  57. subsurface/modules/reader/wells/DEP/__init__.py +43 -43
  58. subsurface/modules/reader/wells/DEP/_well_files_reader.py +167 -167
  59. subsurface/modules/reader/wells/DEP/_wells_api.py +61 -61
  60. subsurface/modules/reader/wells/DEP/_welly_reader.py +180 -180
  61. subsurface/modules/reader/wells/DEP/pandas_to_welly.py +212 -212
  62. subsurface/modules/reader/wells/_read_to_df.py +57 -57
  63. subsurface/modules/reader/wells/read_borehole_interface.py +148 -148
  64. subsurface/modules/reader/wells/wells_utils.py +68 -68
  65. subsurface/modules/tools/mocking_aux.py +104 -104
  66. subsurface/modules/visualization/__init__.py +2 -2
  67. subsurface/modules/visualization/to_pyvista.py +320 -320
  68. subsurface/modules/writer/to_binary.py +12 -12
  69. subsurface/modules/writer/to_rex/common.py +78 -78
  70. subsurface/modules/writer/to_rex/data_struct.py +74 -74
  71. subsurface/modules/writer/to_rex/gempy_to_rexfile.py +791 -791
  72. subsurface/modules/writer/to_rex/material_encoder.py +44 -44
  73. subsurface/modules/writer/to_rex/mesh_encoder.py +152 -152
  74. subsurface/modules/writer/to_rex/to_rex.py +115 -115
  75. subsurface/modules/writer/to_rex/utils.py +15 -15
  76. subsurface/optional_requirements.py +116 -116
  77. {subsurface_terra-2025.1.0rc15.dist-info → subsurface_terra-2025.1.0rc17.dist-info}/METADATA +194 -194
  78. subsurface_terra-2025.1.0rc17.dist-info/RECORD +99 -0
  79. {subsurface_terra-2025.1.0rc15.dist-info → subsurface_terra-2025.1.0rc17.dist-info}/WHEEL +1 -1
  80. {subsurface_terra-2025.1.0rc15.dist-info → subsurface_terra-2025.1.0rc17.dist-info}/licenses/LICENSE +203 -203
  81. subsurface_terra-2025.1.0rc15.dist-info/RECORD +0 -98
  82. {subsurface_terra-2025.1.0rc15.dist-info → subsurface_terra-2025.1.0rc17.dist-info}/top_level.txt +0 -0
@@ -1,44 +1,44 @@
1
- from subsurface.writer.to_rex.common import write_data_block_header, encode
2
- from subsurface.writer.to_rex.data_struct import RexMaterial
3
-
4
-
5
- __all__ = ['material_encode', 'write_material_data']
6
-
7
-
8
- def material_encode(rex_material: RexMaterial, data_id: int):
9
- # Write data block header for Material
10
- data_header_bytes = write_data_block_header(
11
- data_type=5, # Material data type
12
- version_data=1, # Version. Probably useful for operation counter
13
- size_data=68, # Size of the block is FIXED
14
- data_id=data_id # self.data_id
15
- )
16
-
17
- # Write Material
18
- material_bytes = write_material_data(rex_material)
19
- rex_bytes = data_header_bytes + material_bytes
20
- return rex_bytes
21
-
22
-
23
- def write_material_data(rex_material: RexMaterial):
24
- """Writes a standard material definition block
25
-
26
- Returns: bytes (size:68) representation of the material
27
-
28
- """
29
- input_ = [(rex_material.ka_red, 'float32'),
30
- (rex_material.ka_green, 'float32'),
31
- (rex_material.ka_blue, 'float32'),
32
- (rex_material.ka_texture_ID, 'uint64'),
33
- (rex_material.ks_red, 'float32'),
34
- (rex_material.ks_green, 'float32'),
35
- (rex_material.ks_blue, 'float32'),
36
- (rex_material.ks_texture_ID, 'uint64'),
37
- (rex_material.kd_red, 'float32'),
38
- (rex_material.kd_green, 'float32'),
39
- (rex_material.kd_blue, 'float32'),
40
- (rex_material.kd_texture_ID, 'uint64'),
41
- (rex_material.ns, 'float32'),
42
- (rex_material.alpha, 'float32')]
43
- block_bytes = encode(input_)
44
- return block_bytes
1
+ from subsurface.writer.to_rex.common import write_data_block_header, encode
2
+ from subsurface.writer.to_rex.data_struct import RexMaterial
3
+
4
+
5
+ __all__ = ['material_encode', 'write_material_data']
6
+
7
+
8
+ def material_encode(rex_material: RexMaterial, data_id: int):
9
+ # Write data block header for Material
10
+ data_header_bytes = write_data_block_header(
11
+ data_type=5, # Material data type
12
+ version_data=1, # Version. Probably useful for operation counter
13
+ size_data=68, # Size of the block is FIXED
14
+ data_id=data_id # self.data_id
15
+ )
16
+
17
+ # Write Material
18
+ material_bytes = write_material_data(rex_material)
19
+ rex_bytes = data_header_bytes + material_bytes
20
+ return rex_bytes
21
+
22
+
23
+ def write_material_data(rex_material: RexMaterial):
24
+ """Writes a standard material definition block
25
+
26
+ Returns: bytes (size:68) representation of the material
27
+
28
+ """
29
+ input_ = [(rex_material.ka_red, 'float32'),
30
+ (rex_material.ka_green, 'float32'),
31
+ (rex_material.ka_blue, 'float32'),
32
+ (rex_material.ka_texture_ID, 'uint64'),
33
+ (rex_material.ks_red, 'float32'),
34
+ (rex_material.ks_green, 'float32'),
35
+ (rex_material.ks_blue, 'float32'),
36
+ (rex_material.ks_texture_ID, 'uint64'),
37
+ (rex_material.kd_red, 'float32'),
38
+ (rex_material.kd_green, 'float32'),
39
+ (rex_material.kd_blue, 'float32'),
40
+ (rex_material.kd_texture_ID, 'uint64'),
41
+ (rex_material.ns, 'float32'),
42
+ (rex_material.alpha, 'float32')]
43
+ block_bytes = encode(input_)
44
+ return block_bytes
@@ -1,152 +1,152 @@
1
- from subsurface.writer.to_rex.common import mesh_header_size, \
2
- write_data_block_header, encode
3
- from subsurface.writer.to_rex.data_struct import RexMesh
4
-
5
-
6
- __all__ = ['mesh_encode', 'write_mesh_coordinates', 'write_mesh_header']
7
-
8
-
9
- def mesh_encode(rex_mesh: RexMesh, data_id: int):
10
- material_id = rex_mesh.material_id
11
- n_vtx_coord = rex_mesh.n_vtx
12
- n_triangles = rex_mesh.n_triangles
13
- n_vtx_colors = rex_mesh.n_color
14
- surface_name = rex_mesh.name
15
- ver_ravel = rex_mesh.ver_ravel
16
- tri_ravel = rex_mesh.tri_ravel
17
- c_r = rex_mesh.color_ravel
18
-
19
- # Write Mesh block - header
20
- mesh_header_bytes = write_mesh_header(
21
- n_vtx_coord / 3, n_triangles / 3,
22
- n_vtx_colors=n_vtx_colors / 3,
23
- start_vtx_coord=mesh_header_size,
24
- start_nor_coord=mesh_header_size + n_vtx_coord * 4,
25
- start_tex_coord=mesh_header_size + n_vtx_coord * 4,
26
- start_vtx_colors=mesh_header_size + n_vtx_coord * 4,
27
- start_triangles=mesh_header_size +
28
- ((n_vtx_coord + n_vtx_colors) * 4),
29
- name=surface_name,
30
- material_id=material_id # self.data_id + surface_df.shape[0]
31
- )
32
-
33
- # Write Mesh block - Vertex, triangles
34
- mesh_block_bytes = write_mesh_coordinates(ver_ravel,
35
- tri_ravel,
36
- colors=c_r # When using
37
- # material we can avoid this
38
- )
39
-
40
- # Calculate the size of the mesh block
41
- mesh_block_size_no_data_block_header = len(mesh_header_bytes) + \
42
- len(mesh_block_bytes) # This is cte 128
43
-
44
- # Write data block header for Mesh 1
45
- data_header_bytes = write_data_block_header(
46
- size_data=mesh_block_size_no_data_block_header,
47
- data_id=data_id,
48
- data_type=3, # 3 for mesh
49
- version_data=1 # Probably useful for counting
50
- # the operation number
51
- )
52
-
53
- rex_bytes = data_header_bytes + mesh_header_bytes + mesh_block_bytes
54
- return rex_bytes
55
-
56
-
57
- def write_mesh_coordinates(vertex, triangles, normal=None, texture=None,
58
- colors=None):
59
- """Block with the coordinates of a mesh. This has to go with a header!
60
-
61
- Args:
62
- vertex (numpy.ndarray[float32]): Array of vertex XYZXYZ...
63
- triangles (numpy.ndarray[int32]): This is a list of integers which form
64
- one triangle. Please make sure that normal and texture coordinates are inline with the
65
- vertex coordinates. One index refers to the same normal and texture position. The
66
- triangle orientation is required to be counter-clockwise (CCW)
67
- normal (numpy.ndarray):
68
- texture (numpy.ndarray):
69
- colors (numpy.ndarray):
70
-
71
- Returns:
72
-
73
- """
74
-
75
- # ver = vertex.ravel()
76
- # tri = triangles.ravel()
77
- if normal is None:
78
- normal = []
79
- if texture is None:
80
- texture = []
81
- if colors is None:
82
- colors = []
83
-
84
- input_ = [(vertex, 'float32'),
85
- (normal, 'float32'),
86
- (texture, 'float32'),
87
- (colors, 'float32'),
88
- (triangles, 'uint32')]
89
-
90
- block_bytes = encode(input_)
91
- return block_bytes
92
-
93
-
94
- def write_mesh_header(n_vtx_coord, n_triangles,
95
- start_vtx_coord, start_nor_coord, start_tex_coord,
96
- start_vtx_colors,
97
- start_triangles,
98
- name, material_id=1, # material_id=9223372036854775807
99
- n_nor_coord=0, n_tex_coord=0, n_vtx_colors=0,
100
- lod=1, max_lod=1):
101
- """Function to write MESH DATA BLOCK header. The header size is fixed at 128 bytes.
102
-
103
- Args:
104
- n_vtx_coord: number of vertex coordinates
105
- n_triangles: number of triangles
106
- start_vtx_coord: start vertex coordinate block (relative to mesh block start)
107
- start_nor_coord: start vertex normals block (relative to mesh block start)
108
- start_tex_coord: start of texture coordinate block (relative to mesh block start)
109
- start_vtx_colors: start of colors block (relative to mesh block start)
110
- start_triangles: start triangle block for vertices (relative to mesh block start)
111
- name (str): Name of the mesh
112
- material_id (int): id which refers to the corresponding material block in this file
113
- n_nor_coord: number of normal coordinates (can be zero)
114
- n_tex_coord: number of texture coordinates (can be zero)
115
- n_vtx_colors: number of vertex colors (can be zero)
116
- lod (int): level of detail for the given geometry
117
- max_lod (int): maximal level of detail for given geometry
118
-
119
- Returns:
120
- bytes: array of bytes
121
- """
122
-
123
- # Strings are immutable so there is no way to modify them in place
124
- str_size = len(name) # Size of the actual name of the mesh
125
- rest_name = ' ' * (74 - str_size) #
126
- full_name = name + rest_name
127
-
128
- input_ = [([lod, max_lod], 'uint16'), # Level of detail
129
- ([n_vtx_coord, # number of vertex coordinates
130
- n_nor_coord, # number of normal coordinates (can be zero)
131
- n_tex_coord, # number of texture coordinates (can be zero)
132
- n_vtx_colors, # number of vertex colors (can be zero)
133
- n_triangles, # number of triangles
134
- start_vtx_coord,
135
- # start vertex coordinate block (relative to mesh block start)
136
- start_nor_coord,
137
- # start vertex normals block (relative to mesh block start)
138
- start_tex_coord,
139
- # start of texture coordinate block (relative to mesh block start)
140
- start_vtx_colors,
141
- # start of colors block (relative to mesh block start)
142
- start_triangles
143
- # start triangle block for vertices (relative to mesh block start)
144
- ],
145
- 'uint32'),
146
- (material_id, 'uint64'),
147
- # id which refers to the corresponding material block in this file
148
- (str_size, 'uint16'), # size of the following string name
149
- (full_name, 'bytes')] # name of the mesh (this is user-readable)
150
-
151
- block_bytes = encode(input_)
152
- return block_bytes
1
+ from subsurface.writer.to_rex.common import mesh_header_size, \
2
+ write_data_block_header, encode
3
+ from subsurface.writer.to_rex.data_struct import RexMesh
4
+
5
+
6
+ __all__ = ['mesh_encode', 'write_mesh_coordinates', 'write_mesh_header']
7
+
8
+
9
+ def mesh_encode(rex_mesh: RexMesh, data_id: int):
10
+ material_id = rex_mesh.material_id
11
+ n_vtx_coord = rex_mesh.n_vtx
12
+ n_triangles = rex_mesh.n_triangles
13
+ n_vtx_colors = rex_mesh.n_color
14
+ surface_name = rex_mesh.name
15
+ ver_ravel = rex_mesh.ver_ravel
16
+ tri_ravel = rex_mesh.tri_ravel
17
+ c_r = rex_mesh.color_ravel
18
+
19
+ # Write Mesh block - header
20
+ mesh_header_bytes = write_mesh_header(
21
+ n_vtx_coord / 3, n_triangles / 3,
22
+ n_vtx_colors=n_vtx_colors / 3,
23
+ start_vtx_coord=mesh_header_size,
24
+ start_nor_coord=mesh_header_size + n_vtx_coord * 4,
25
+ start_tex_coord=mesh_header_size + n_vtx_coord * 4,
26
+ start_vtx_colors=mesh_header_size + n_vtx_coord * 4,
27
+ start_triangles=mesh_header_size +
28
+ ((n_vtx_coord + n_vtx_colors) * 4),
29
+ name=surface_name,
30
+ material_id=material_id # self.data_id + surface_df.shape[0]
31
+ )
32
+
33
+ # Write Mesh block - Vertex, triangles
34
+ mesh_block_bytes = write_mesh_coordinates(ver_ravel,
35
+ tri_ravel,
36
+ colors=c_r # When using
37
+ # material we can avoid this
38
+ )
39
+
40
+ # Calculate the size of the mesh block
41
+ mesh_block_size_no_data_block_header = len(mesh_header_bytes) + \
42
+ len(mesh_block_bytes) # This is cte 128
43
+
44
+ # Write data block header for Mesh 1
45
+ data_header_bytes = write_data_block_header(
46
+ size_data=mesh_block_size_no_data_block_header,
47
+ data_id=data_id,
48
+ data_type=3, # 3 for mesh
49
+ version_data=1 # Probably useful for counting
50
+ # the operation number
51
+ )
52
+
53
+ rex_bytes = data_header_bytes + mesh_header_bytes + mesh_block_bytes
54
+ return rex_bytes
55
+
56
+
57
+ def write_mesh_coordinates(vertex, triangles, normal=None, texture=None,
58
+ colors=None):
59
+ """Block with the coordinates of a mesh. This has to go with a header!
60
+
61
+ Args:
62
+ vertex (numpy.ndarray[float32]): Array of vertex XYZXYZ...
63
+ triangles (numpy.ndarray[int32]): This is a list of integers which form
64
+ one triangle. Please make sure that normal and texture coordinates are inline with the
65
+ vertex coordinates. One index refers to the same normal and texture position. The
66
+ triangle orientation is required to be counter-clockwise (CCW)
67
+ normal (numpy.ndarray):
68
+ texture (numpy.ndarray):
69
+ colors (numpy.ndarray):
70
+
71
+ Returns:
72
+
73
+ """
74
+
75
+ # ver = vertex.ravel()
76
+ # tri = triangles.ravel()
77
+ if normal is None:
78
+ normal = []
79
+ if texture is None:
80
+ texture = []
81
+ if colors is None:
82
+ colors = []
83
+
84
+ input_ = [(vertex, 'float32'),
85
+ (normal, 'float32'),
86
+ (texture, 'float32'),
87
+ (colors, 'float32'),
88
+ (triangles, 'uint32')]
89
+
90
+ block_bytes = encode(input_)
91
+ return block_bytes
92
+
93
+
94
+ def write_mesh_header(n_vtx_coord, n_triangles,
95
+ start_vtx_coord, start_nor_coord, start_tex_coord,
96
+ start_vtx_colors,
97
+ start_triangles,
98
+ name, material_id=1, # material_id=9223372036854775807
99
+ n_nor_coord=0, n_tex_coord=0, n_vtx_colors=0,
100
+ lod=1, max_lod=1):
101
+ """Function to write MESH DATA BLOCK header. The header size is fixed at 128 bytes.
102
+
103
+ Args:
104
+ n_vtx_coord: number of vertex coordinates
105
+ n_triangles: number of triangles
106
+ start_vtx_coord: start vertex coordinate block (relative to mesh block start)
107
+ start_nor_coord: start vertex normals block (relative to mesh block start)
108
+ start_tex_coord: start of texture coordinate block (relative to mesh block start)
109
+ start_vtx_colors: start of colors block (relative to mesh block start)
110
+ start_triangles: start triangle block for vertices (relative to mesh block start)
111
+ name (str): Name of the mesh
112
+ material_id (int): id which refers to the corresponding material block in this file
113
+ n_nor_coord: number of normal coordinates (can be zero)
114
+ n_tex_coord: number of texture coordinates (can be zero)
115
+ n_vtx_colors: number of vertex colors (can be zero)
116
+ lod (int): level of detail for the given geometry
117
+ max_lod (int): maximal level of detail for given geometry
118
+
119
+ Returns:
120
+ bytes: array of bytes
121
+ """
122
+
123
+ # Strings are immutable so there is no way to modify them in place
124
+ str_size = len(name) # Size of the actual name of the mesh
125
+ rest_name = ' ' * (74 - str_size) #
126
+ full_name = name + rest_name
127
+
128
+ input_ = [([lod, max_lod], 'uint16'), # Level of detail
129
+ ([n_vtx_coord, # number of vertex coordinates
130
+ n_nor_coord, # number of normal coordinates (can be zero)
131
+ n_tex_coord, # number of texture coordinates (can be zero)
132
+ n_vtx_colors, # number of vertex colors (can be zero)
133
+ n_triangles, # number of triangles
134
+ start_vtx_coord,
135
+ # start vertex coordinate block (relative to mesh block start)
136
+ start_nor_coord,
137
+ # start vertex normals block (relative to mesh block start)
138
+ start_tex_coord,
139
+ # start of texture coordinate block (relative to mesh block start)
140
+ start_vtx_colors,
141
+ # start of colors block (relative to mesh block start)
142
+ start_triangles
143
+ # start triangle block for vertices (relative to mesh block start)
144
+ ],
145
+ 'uint32'),
146
+ (material_id, 'uint64'),
147
+ # id which refers to the corresponding material block in this file
148
+ (str_size, 'uint16'), # size of the following string name
149
+ (full_name, 'bytes')] # name of the mesh (this is user-readable)
150
+
151
+ block_bytes = encode(input_)
152
+ return block_bytes
@@ -1,115 +1,115 @@
1
- from typing import List
2
-
3
- from subsurface.writer.to_rex.common import file_header_size, encode
4
- from subsurface.writer.to_rex.data_struct import RexLineSet, RexMesh, RexMaterial
5
- from subsurface.writer.to_rex.material_encoder import material_encode
6
- from subsurface.writer.to_rex.mesh_encoder import mesh_encode
7
-
8
-
9
- __all__ = ['numpy_to_rex', 'w_data_blocks', 'w_block_data_type',
10
- 'w_file_header_and_coord_system_block',
11
- 'w_file_header_and_coord_system_block', 'write_rex_file',
12
- 'read_rex_file']
13
-
14
-
15
- def numpy_to_rex(
16
- rex_line_set: List[RexLineSet] = None,
17
- rex_meshes: List[RexMesh] = None,
18
- rex_material: List[RexMaterial] = None
19
- ):
20
- if rex_line_set is None:
21
- rex_line_set = list()
22
- if rex_meshes is None:
23
- rex_meshes = list()
24
- if rex_material is None:
25
- rex_material = list()
26
-
27
- data_block_bytes = bytearray()
28
- byte_size = 0
29
-
30
- data_block_bytes, data_id = w_data_blocks(rex_meshes, rex_material)
31
-
32
- n_data_blocks = data_id
33
- header_and_coord_block_bytes = w_file_header_and_coord_system_block(
34
- n_data_blocks=n_data_blocks,
35
- size_data_blocks=len(data_block_bytes),
36
- start_data=file_header_size
37
- )
38
-
39
- return header_and_coord_block_bytes + data_block_bytes
40
-
41
-
42
- def w_data_blocks(rex_meshes: List[RexMesh], rex_material: List[RexMaterial]):
43
- data_id = 0
44
-
45
- rmesh_bytes, data_id = w_block_data_type(mesh_encode, rex_meshes, data_id)
46
- rmaterial_bytes, data_id = w_block_data_type(material_encode, rex_material,
47
- data_id)
48
-
49
- blocks_bytes = rmesh_bytes + rmaterial_bytes
50
- return blocks_bytes, data_id
51
-
52
-
53
- def w_block_data_type(encoder, rex_objects: List, data_id: int):
54
- data_block_bytes = bytearray()
55
- for rex_obj in rex_objects:
56
- data_block_bytes += encoder(rex_obj, data_id=data_id)
57
- data_id += 1
58
-
59
- return data_block_bytes, data_id
60
-
61
-
62
- def w_file_header_and_coord_system_block():
63
- return
64
-
65
-
66
- def w_file_header_and_coord_system_block(n_data_blocks, size_data_blocks, version=1,
67
- start_data=86, srid=3876, offsets=None):
68
- """
69
- Function that writes the header block of a rexfile:
70
-
71
- Args:
72
- n_data_blocks:
73
- size_data_blocks:
74
- version (int): Version of the file
75
- start_data (int): Position where data start. This is after the header
76
- and coordinate system. If everything works fine it should be 86
77
- srid (int): Spatial reference system identifier (srid)
78
- offsets:
79
-
80
- Returns:
81
-
82
- """
83
- reserved = '0' * 42
84
- if offsets is None:
85
- offsets = [0, 0, 0]
86
-
87
- input_ = [('REX1', 'bytes'), # REX1
88
- (version, 'uint16'), # file version
89
- (0, 'uint32'), # CRC32
90
- (n_data_blocks, 'uint16'), # Number of DATA BLOCKS
91
- (start_data, 'uint16'), # StartData
92
- (size_data_blocks, 'uint64'), # Size of all data blocks
93
- (reserved, 'bytes'), # Reserved
94
- # Coordinate system block
95
- (srid, 'uint32'), # Spatial reference system identifier (srid)
96
- (4, 'uint16'), # Size of the name of the used system.
97
- ('EPSG', 'bytes'), # name of the used system.
98
- (offsets, 'float32')] # Global x, y, z offset
99
-
100
- block_bytes = encode(input_)
101
- return block_bytes
102
-
103
-
104
- def write_rex_file(bytes, path: str):
105
- """Write to disk a rexfile from its binary format"""
106
-
107
- new_file = open(path + ".rex", "wb")
108
- new_file.write(bytes)
109
- return True
110
-
111
-
112
- def read_rex_file(path: str) -> bytes:
113
- with open(path, "rb") as f:
114
- bytes_read = f.read()
115
- return bytes_read
1
+ from typing import List
2
+
3
+ from subsurface.writer.to_rex.common import file_header_size, encode
4
+ from subsurface.writer.to_rex.data_struct import RexLineSet, RexMesh, RexMaterial
5
+ from subsurface.writer.to_rex.material_encoder import material_encode
6
+ from subsurface.writer.to_rex.mesh_encoder import mesh_encode
7
+
8
+
9
+ __all__ = ['numpy_to_rex', 'w_data_blocks', 'w_block_data_type',
10
+ 'w_file_header_and_coord_system_block',
11
+ 'w_file_header_and_coord_system_block', 'write_rex_file',
12
+ 'read_rex_file']
13
+
14
+
15
+ def numpy_to_rex(
16
+ rex_line_set: List[RexLineSet] = None,
17
+ rex_meshes: List[RexMesh] = None,
18
+ rex_material: List[RexMaterial] = None
19
+ ):
20
+ if rex_line_set is None:
21
+ rex_line_set = list()
22
+ if rex_meshes is None:
23
+ rex_meshes = list()
24
+ if rex_material is None:
25
+ rex_material = list()
26
+
27
+ data_block_bytes = bytearray()
28
+ byte_size = 0
29
+
30
+ data_block_bytes, data_id = w_data_blocks(rex_meshes, rex_material)
31
+
32
+ n_data_blocks = data_id
33
+ header_and_coord_block_bytes = w_file_header_and_coord_system_block(
34
+ n_data_blocks=n_data_blocks,
35
+ size_data_blocks=len(data_block_bytes),
36
+ start_data=file_header_size
37
+ )
38
+
39
+ return header_and_coord_block_bytes + data_block_bytes
40
+
41
+
42
+ def w_data_blocks(rex_meshes: List[RexMesh], rex_material: List[RexMaterial]):
43
+ data_id = 0
44
+
45
+ rmesh_bytes, data_id = w_block_data_type(mesh_encode, rex_meshes, data_id)
46
+ rmaterial_bytes, data_id = w_block_data_type(material_encode, rex_material,
47
+ data_id)
48
+
49
+ blocks_bytes = rmesh_bytes + rmaterial_bytes
50
+ return blocks_bytes, data_id
51
+
52
+
53
+ def w_block_data_type(encoder, rex_objects: List, data_id: int):
54
+ data_block_bytes = bytearray()
55
+ for rex_obj in rex_objects:
56
+ data_block_bytes += encoder(rex_obj, data_id=data_id)
57
+ data_id += 1
58
+
59
+ return data_block_bytes, data_id
60
+
61
+
62
+ def w_file_header_and_coord_system_block():
63
+ return
64
+
65
+
66
+ def w_file_header_and_coord_system_block(n_data_blocks, size_data_blocks, version=1,
67
+ start_data=86, srid=3876, offsets=None):
68
+ """
69
+ Function that writes the header block of a rexfile:
70
+
71
+ Args:
72
+ n_data_blocks:
73
+ size_data_blocks:
74
+ version (int): Version of the file
75
+ start_data (int): Position where data start. This is after the header
76
+ and coordinate system. If everything works fine it should be 86
77
+ srid (int): Spatial reference system identifier (srid)
78
+ offsets:
79
+
80
+ Returns:
81
+
82
+ """
83
+ reserved = '0' * 42
84
+ if offsets is None:
85
+ offsets = [0, 0, 0]
86
+
87
+ input_ = [('REX1', 'bytes'), # REX1
88
+ (version, 'uint16'), # file version
89
+ (0, 'uint32'), # CRC32
90
+ (n_data_blocks, 'uint16'), # Number of DATA BLOCKS
91
+ (start_data, 'uint16'), # StartData
92
+ (size_data_blocks, 'uint64'), # Size of all data blocks
93
+ (reserved, 'bytes'), # Reserved
94
+ # Coordinate system block
95
+ (srid, 'uint32'), # Spatial reference system identifier (srid)
96
+ (4, 'uint16'), # Size of the name of the used system.
97
+ ('EPSG', 'bytes'), # name of the used system.
98
+ (offsets, 'float32')] # Global x, y, z offset
99
+
100
+ block_bytes = encode(input_)
101
+ return block_bytes
102
+
103
+
104
+ def write_rex_file(bytes, path: str):
105
+ """Write to disk a rexfile from its binary format"""
106
+
107
+ new_file = open(path + ".rex", "wb")
108
+ new_file.write(bytes)
109
+ return True
110
+
111
+
112
+ def read_rex_file(path: str) -> bytes:
113
+ with open(path, "rb") as f:
114
+ bytes_read = f.read()
115
+ return bytes_read
@@ -1,15 +1,15 @@
1
- import numpy as np
2
-
3
-
4
- __all__ = ['hex_to_rgb', ]
5
-
6
-
7
- def hex_to_rgb(hex: str, normalize: bool = True) -> np.ndarray:
8
- """Transform colors from hex to rgb"""
9
- hex = hex.lstrip('#')
10
- hlen = len(hex)
11
- rgb = np.array(
12
- [int(hex[i:i + hlen // 3], 16) for i in range(0, hlen, hlen // 3)])
13
- if normalize is True:
14
- rgb = rgb / 255
15
- return rgb
1
+ import numpy as np
2
+
3
+
4
+ __all__ = ['hex_to_rgb', ]
5
+
6
+
7
+ def hex_to_rgb(hex: str, normalize: bool = True) -> np.ndarray:
8
+ """Transform colors from hex to rgb"""
9
+ hex = hex.lstrip('#')
10
+ hlen = len(hex)
11
+ rgb = np.array(
12
+ [int(hex[i:i + hlen // 3], 16) for i in range(0, hlen, hlen // 3)])
13
+ if normalize is True:
14
+ rgb = rgb / 255
15
+ return rgb