Skip to content

Commit 78b6111

Browse files
SimonVirgoSimon VirgoLeguark
authored
[WIP] Development rexview (#296)
* refactored write_data_block to write_data_block_header The name of the function was misleading, it does not write the full data block but only the header. A data block consist of a header and the data, depending on the data itself it can have also sub headers. * add function to write material data block * added credential file for rexos Api key * Revert "added credential file for rexos Api key" This reverts commit e8cc48c * added credential file for rexos Api key... again * added api file to .gitignore this prevents that api keys are accidentally added to the repository * added rex_api file * updated rex_api file to use token and secret * added api call to authorize session and retrieve access_|token * added api calls to get user information and to create new projects * safety commit * added api call to create project file * added api calls for ressource management, fixed file upload * wrapper function for api calls * [ENH] AR: Added normals to both sides of the surfaces * added method to create and display rextag * [ENH] WIP Passing gempy colors to rex * [ENH] Both sided colors kind of running * [ENH] Double side layers running * [ENH] Added Test to update to rexos * fixed bug in rex ressource referencing * [TEST] Skip gempy_to_rex tests in Travis * refactoring class to be more explizit seperated rextag top its own class added function to automate upload and create rextag * [DOC] Preparing README.md for GemPy 2.1 * [GIT] - * [TEST] skipping test in travis * [ENH] rex_api.py will write the RexCloud_Api_key.txt if needed * [BUG] Added pyqrcode travis * [ENH] Add error if pyqr code is not installed * [ENH] On rex file export: name layers based on their layername #316 [CLN] - Deleted prototype code * [ENH] Minor improvements in rex_api.py/gempy.plot.plot_ar - Surfaces take the name of the gempy model - Project take the name of the gempy model [TEXT] - plot_ar * [ENH] Added the option to rescale vertex coordinates between 0-1 - Change requirements.txt for pandas and qgrid * [BUG] Pandas version * [DOC] Docstring for plot_ar * [BUG] Pandas 1.0.1 breaks gempy! * [BUG] Fix bug when no passing marching_cubes options * Revert "[BUG] Fix bug when no passing marching_cubes options" This reverts commit 5524365 * Revert "[BUG] Fix bug when no passing marching_cubes options" This reverts commit 5524365 * [BUG] Removed ipyvisualization Co-authored-by: Simon Virgo <[email protected]> Co-authored-by: varga <[email protected]>
1 parent 5080480 commit 78b6111

File tree

15 files changed

+885
-385
lines changed

15 files changed

+885
-385
lines changed

.gitignore

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,7 @@ GeMpy/__pycache__/__init__.cpython-36.pyc
88
GeMpy/__pycache__/geomodeller_xml_obj.cpython-36.pyc
99
GeMpy/geomodeller_xml_obj.py.bak
1010
GeMpy/qgrid/__pycache__/
11-
notebooks/prototype notebooks/Example_4_faults_network.ipynb
12-
notebooks/prototype notebooks/Example_Peter_Model.ipynb
13-
notebooks/prototype notebooks/Fabian.vtp
14-
notebooks/prototype notebooks/Fabian1.vtp
15-
notebooks/prototype notebooks/Fabian2.vtp
16-
notebooks/prototype notebooks/Fabian3.vtp
17-
notebooks/prototype notebooks/Fabian4.vtp
18-
notebooks/prototype notebooks/FabianModelBigPoints.vtk
19-
notebooks/prototype notebooks/FabianModelSmallPoints.vtk
20-
notebooks/prototype notebooks/FabianModel_point.vti
21-
notebooks/prototype notebooks/FabianModel_point_good_res.vti
22-
notebooks/prototype notebooks/Fabian_f.vtp
23-
notebooks/prototype notebooks/Fault.vtk
24-
notebooks/prototype notebooks/Intrusions.ipynb
25-
notebooks/prototype notebooks/Layer1.vtk
26-
notebooks/prototype notebooks/Layer2.vtk
27-
notebooks/prototype notebooks/Layer3.vtk
28-
notebooks/prototype notebooks/Layer4.vtk
29-
notebooks/prototype notebooks/More cave/
30-
notebooks/prototype notebooks/PF_over_TKC/
31-
notebooks/prototype notebooks/PerthBasin.vti
32-
notebooks/prototype notebooks/PerthBasin.vtk
33-
notebooks/prototype notebooks/PerthBasinOtherColors.vtk
34-
notebooks/prototype notebooks/Physics.ipynb
35-
notebooks/prototype notebooks/SandstoneSol.npy
36-
notebooks/prototype notebooks/TriangleColoredPoints.vtp
37-
notebooks/prototype notebooks/TriangleSolidColor.vtp
38-
notebooks/prototype notebooks/Visualization3_vtkBasics.ipynb
39-
notebooks/prototype notebooks/files fab/
40-
notebooks/prototype notebooks/geomodels.sqlite
41-
notebooks/prototype notebooks/legacy/.ipynb_checkpoints/
42-
notebooks/prototype notebooks/models.npy
43-
notebooks/prototype notebooks/olaqases.vox
44-
notebooks/prototype notebooks/preth.npy
45-
notebooks/prototype notebooks/sandstone.vtk
46-
notebooks/prototype notebooks/sandstone.vtr
47-
notebooks/prototype notebooks/simplices.npy
48-
notebooks/prototype notebooks/vertices.npy
49-
notebooks/prototype notebooks/voxet_sub.vox
50-
notebooks/prototype notebooks/withfault.npy
11+
gempy/addons/RexCloud_Api_key.txt
5112
docs/source/Notebooks/Erosion.rst
5213
docs/source/Notebooks/Example_1_Sandstone_files/Example_1_Sandstone_39_0.png
5314
docs/source/Notebooks/Example_1_Sandstone_files/Example_1_Sandstone_41_0.png

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ dist: xenial
55
python:
66
- '3.7'
77

8+
env: TRAVIS=true
9+
810
install:
911
- pip install --upgrade setuptools pip
1012
- pip install cython
@@ -15,7 +17,6 @@ install:
1517
- pip install vtk
1618
- pip install pyevtk
1719
- pip install dataclasses emg3d pyvista panel discretize
18-
- pip install nptyping
1920

2021
script:
2122

README.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,6 @@ Check out the documentation either in [gempy.org](https://www.gempy.org/) (bette
3434
* [References](#ref)
3535

3636
<a name="feat"></a>
37-
## News
38-
### GemPy v2.0 release
39-
40-
It has been a long journey since the release of GemPy v1.0. What started as a small library to carry out research
41-
on uncertainty analysis for structural geology has grown to be used in multiple projects around the world. Carried
42-
by the community enthusiasm, we commenced a way-longer-than-planned rewritten of the code in order to
43-
not only be able to fulfill the needs of many of you but also to set the foundations of a package driven by the
44-
community. For this end, all the logic has been splat into multiple modules, classes and containers limiting
45-
duplicities and exposing a large mutation api at different levels of abstraction. Hope the work has been worth it.
46-
47-
So long,
48-
49-
Miguel
50-
51-
#### What is new
52-
- Full redesign of the back-end: much more modular, explicit and avoiding object duplicities to insane levels
53-
- Topography
54-
- Onlap, Erosion relations
55-
- Choose your favourite type of fault: infinite faults, finite faults, faults offsetting faults, faults ending on series
56-
- Masked marching cubes: this fix the ugly surfaces following the voxels faces
57-
- All series are fully stored after interpolation
58-
- Save your model
59-
- Compile once, modify as much as you want
60-
- Full integration with qgrid
61-
- Real time computations via vtk or python-qgrid
62-
- Adaptive regular grids for geophysics
63-
- Refactored some legacy names:
64-
+ formations renamed to surfaces
65-
+ interfaces renamed to surfaces_points
66-
- Minor changes:
67-
+ New colormap and easy way to change the surfaces colors (even integration with widgets!)
68-
+ The order of the formations will be given by the interpolation itself if the input was wrong
69-
+ The split between reference and rest surface_points happens in theano. This makes the modification
70-
of reference points much easier
7137

7238

7339
## Features

gempy/addons/gempy_to_rexfile.py

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def write_header_block(n_data_blocks, size_data_blocks, version=1, start_data=86
9393
return block_bytes
9494

9595

96-
def write_data_block(size_data, data_id = 1, data_type=3, version_data=1):
96+
def write_data_block_header(size_data, data_id = 1, data_type=3, version_data=1):
9797
"""
9898
Function to write a data block header.
9999
@@ -118,7 +118,7 @@ def write_data_block(size_data, data_id = 1, data_type=3, version_data=1):
118118

119119
def write_mesh_header(n_vtx_coord, n_triangles,
120120
start_vtx_coord, start_nor_coord, start_tex_coord, start_vtx_colors, start_triangles,
121-
name, material_id=9223372036854775807,
121+
name, material_id=1, # material_id=9223372036854775807
122122
n_nor_coord=0, n_tex_coord=0, n_vtx_colors=0,
123123
lod=1, max_lod=1):
124124
"""
@@ -143,6 +143,7 @@ def write_mesh_header(n_vtx_coord, n_triangles,
143143
144144
"""
145145

146+
146147
str_size = len(name)
147148
rest_name_ = ' ' * (74 - str_size)
148149
full_name = name + rest_name_
@@ -207,51 +208,121 @@ def write_file(bytes, path: str):
207208
return True
208209

209210

210-
def geo_model_to_res(geo_model, path='./gempy_rex'):
211+
def write_material_data(ka_red=255.0/255, ka_green=255.0/255, ka_blue=255.0/255, ka_texture_ID=9223372036854775807, # ambient
212+
ks_red=255.0/255, ks_green=255.0/255, ks_blue=255.0/255, ks_texture_ID=9223372036854775807, # specular
213+
kd_red=255.0/255, kd_green=255.0/255, kd_blue=255.0/255, kd_texture_ID=9223372036854775807, # diffuse
214+
ns=0.1, #specular exponent
215+
alpha=1 #opacity
216+
):
217+
"""
218+
writes a standard material definition block
219+
220+
Returns: bytes (size:68) representation of the material
221+
222+
"""
223+
224+
input_ = [(ka_red, 'float32'), (ka_green, 'float32'), (ka_blue, 'float32'), (ka_texture_ID, 'uint64'),
225+
(ks_red, 'float32'), (ks_green, 'float32'), (ks_blue, 'float32'), (ks_texture_ID, 'uint64'),
226+
(kd_red, 'float32'), (kd_green, 'float32'), (kd_blue, 'float32'), (kd_texture_ID, 'uint64'),
227+
(ns,'float32'), (alpha, 'float32')]
228+
229+
block_bytes = encode(input_)
230+
return block_bytes
211231

232+
233+
# TODO Move to utils
234+
def hex_to_rgb(hex):
235+
hex = hex.lstrip('#')
236+
hlen = len(hex)
237+
return tuple(int(hex[i:i + hlen // 3], 16) for i in range(0, hlen, hlen // 3))
238+
239+
240+
def geo_model_to_rex(geo_model, path='./gempy_rex'):
241+
file_names = []
212242
mesh_header_size = 128
213243
file_header_size = 86
214244
e = 0
215-
for ver, tri in zip(geo_model.solutions.vertices, geo_model.solutions.edges):
216245

217-
colors = np.ones_like(ver) * 200
246+
for idx, surface_vals in geo_model.surfaces.df.iterrows():
247+
ver = surface_vals['vertices']
248+
tri = surface_vals['edges']
249+
if tri is np.nan:
250+
break
251+
252+
col = surface_vals['color']
253+
254+
colors = (np.zeros_like(ver) + hex_to_rgb(col))/255
218255

219256
ver_ = np.copy(ver)
220257
ver_[:, 2] = ver[:, 1]
221258
ver_[:, 1] = ver[:, 2]
222259

223260
tri_ = np.copy(tri)
224-
tri_[:, 2] = tri[:, 1]
225-
tri_[:, 1] = tri[:, 2]
226261

227262
ver_ravel, tri_ravel, n_vtx_coord, n_triangles = mesh_preprocess(ver_, tri_)
228-
data_block_size_no_header = 2 * (n_vtx_coord + n_triangles) * 4 + mesh_header_size
229-
263+
mesh_block_size_no_data_block_header = (2 * n_vtx_coord + n_triangles) * 4 + mesh_header_size
264+
material_block_size_no_data_block_header = 68
230265
# Write header
231-
header_bytes = write_header_block(n_data_blocks=1,
232-
size_data_blocks=data_block_size_no_header + rexDataBlockHeaderSize,
266+
n_data_blocks = 3
267+
header_bytes = write_header_block(n_data_blocks=n_data_blocks,
268+
size_data_blocks=mesh_block_size_no_data_block_header +
269+
rexDataBlockHeaderSize +
270+
material_block_size_no_data_block_header,
233271
start_data=file_header_size)
234272

235273
# Write data block
236-
data_bytes = write_data_block(size_data=data_block_size_no_header,
237-
data_id=1, data_type=3, version_data=1)
274+
data_bytes = write_data_block_header(size_data=mesh_block_size_no_data_block_header,
275+
data_id=1, data_type=3, version_data=1)
238276

239277
# Write mesh block
240278
mesh_header_bytes = write_mesh_header(n_vtx_coord / 3, n_triangles / 3, n_vtx_colors=n_vtx_coord/3,
241279
start_vtx_coord=mesh_header_size,
242280
start_nor_coord=mesh_header_size + n_vtx_coord * 4,
243281
start_tex_coord=mesh_header_size + n_vtx_coord * 4,
244282
start_vtx_colors=mesh_header_size + n_vtx_coord * 4,
245-
start_triangles=mesh_header_size + 2 * (n_vtx_coord * 4),
246-
name='test_a')
283+
start_triangles=mesh_header_size + 2 *
284+
(n_vtx_coord * 4),
285+
name='test_a', material_id=0)
247286

248287
mesh_block_bytes = write_mesh_coordinates(ver_ravel, tri_ravel, colors=colors.ravel())
249288

250-
all_bytes = header_bytes + data_bytes + mesh_header_bytes + mesh_block_bytes
289+
# Write data block
290+
data_bytes_r = write_data_block_header(size_data=mesh_block_size_no_data_block_header,
291+
data_id=2, data_type=3, version_data=1)
292+
293+
# One side of the normals
294+
tri_[:, 2] = tri[:, 1]
295+
tri_[:, 1] = tri[:, 2]
296+
297+
ver_ravel, tri_ravel, n_vtx_coord, n_triangles = mesh_preprocess(ver_, tri_)
298+
299+
# Write mesh block
300+
mesh_header_bytes_r = write_mesh_header(n_vtx_coord / 3, n_triangles / 3, n_vtx_colors=n_vtx_coord / 3,
301+
start_vtx_coord=mesh_header_size,
302+
start_nor_coord=mesh_header_size + n_vtx_coord * 4,
303+
start_tex_coord=mesh_header_size + n_vtx_coord * 4,
304+
start_vtx_colors=mesh_header_size + n_vtx_coord * 4,
305+
start_triangles=mesh_header_size + 2 *
306+
(n_vtx_coord * 4),
307+
name='test_a', material_id=0)
251308

252-
write_file(all_bytes, path+str(e))
309+
mesh_block_bytes_r = write_mesh_coordinates(ver_ravel, tri_ravel, colors=colors.ravel())
310+
311+
# Write material block
312+
material_header_bytes = write_data_block_header(data_type=5, version_data=1, size_data=68, data_id=0)
313+
material_bytes = write_material_data()
314+
315+
all_bytes = header_bytes + data_bytes + mesh_header_bytes + mesh_block_bytes +\
316+
data_bytes_r + mesh_header_bytes_r + mesh_block_bytes_r +\
317+
material_header_bytes + material_bytes
318+
319+
file_name = path+surface_vals['surface']
320+
write_file(all_bytes, file_name)
321+
file_names.append(file_name+'.rex')
253322
e += 1
254323

324+
return file_names
325+
255326

256327

257328

0 commit comments

Comments
 (0)