Skip to content

Commit 84d3332

Browse files
committed
Updated minimal json examples and comparison to minimal GemPy model
1 parent 6d1e029 commit 84d3332

File tree

2 files changed

+182
-11
lines changed

2 files changed

+182
-11
lines changed

examples/tutorials/z_other_tutorials/json_io/05_minimal_json.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,41 @@
1717

1818

1919
# %%
20-
# Define the model data with minimal required fields
20+
# Create the corresponding minimal JSON model
2121
model_data = {
2222
"surface_points": [
23-
{"x": 100.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
24-
{"x": 500.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
25-
{"x": 900.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
23+
{
24+
"x": 50.0,
25+
"y": 0.0,
26+
"z": -20.0,
27+
"id": 0,
28+
"nugget": 0.001 # Default nugget value
29+
},
30+
{
31+
"x": 120.0,
32+
"y": 0.0,
33+
"z": -20.0,
34+
"id": 0,
35+
"nugget": 0.001 # Default nugget value
36+
}
2637
],
2738
"orientations": [
28-
{"x": 500.0, "y": 500.0, "z": 600.0, "G_x": 0.0, "G_y": 0.0, "G_z": 1.0, "id": 1, "nugget": 0.01, "polarity": 1},
29-
{"x": 500.0, "y": 500.0, "z": 400.0, "G_x": 0.0, "G_y": 0.0, "G_z": 1.0, "id": 0, "nugget": 0.01, "polarity": 1},
30-
]
31-
# series will be automatically created with default values:
32-
# - name: "Strat_Series"
33-
# - surfaces: ["surface_0", "surface_1"] (based on unique IDs)
34-
# - structural_relation: "ERODE"
39+
{
40+
"x": 50.0,
41+
"y": 0.0,
42+
"z": -20.0,
43+
"G_x": 1.0,
44+
"G_y": 0.0,
45+
"G_z": 1.0,
46+
"id": 0,
47+
"nugget": 0.001, # Default nugget value
48+
"polarity": 1
49+
}
50+
],
51+
"grid_settings": {
52+
"regular_grid_resolution": [100, 2, 100],
53+
"regular_grid_extent": [0, 150, -10, 10, -100, 0]
54+
}
3555
}
3656

3757
# %%
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"""
2+
Tutorial: Compare minimal GemPy model with JSON representation
3+
This tutorial demonstrates how to create a minimal GemPy model and compare it with its JSON representation.
4+
"""
5+
6+
# %%
7+
import gempy as gp
8+
import gempy_viewer as gpv
9+
import json
10+
import numpy as np
11+
from gempy.modules.json_io.json_operations import JsonIO
12+
13+
# %%
14+
# Set up the basic model
15+
geo_model: gp.data.GeoModel = gp.create_geomodel(
16+
project_name='Model1',
17+
extent=[0, 150, -10, 10, -100, 0],
18+
resolution=[100, 2, 100],
19+
structural_frame=gp.data.StructuralFrame.initialize_default_structure()
20+
)
21+
22+
# Add a surface point
23+
gp.add_surface_points(
24+
geo_model=geo_model,
25+
x=[50],
26+
y=[0],
27+
z=[-20],
28+
elements_names=['surface1']
29+
)
30+
31+
# Add an orientation
32+
gp.add_orientations(
33+
geo_model=geo_model,
34+
x=[50],
35+
y=[0],
36+
z=[-68],
37+
elements_names=['surface1'],
38+
pole_vector=[[1, 0, 1]]
39+
)
40+
41+
# Set interpolation options
42+
geo_model.interpolation_options.kernel_options.range = 10.
43+
geo_model.interpolation_options.kernel_options.c_o = 5.
44+
geo_model.interpolation_options.mesh_extraction = True
45+
geo_model.interpolation_options.number_octree_levels = 2
46+
47+
geo_model.update_transform(gp.data.GlobalAnisotropy.NONE)
48+
gp.compute_model(geo_model, engine_config=gp.data.GemPyEngineConfig())
49+
50+
# %%
51+
# Plot the model
52+
p2d = gpv.plot_2d(geo_model)
53+
54+
# %%
55+
# Create the corresponding minimal JSON model
56+
json_model_data = {
57+
"surface_points": [
58+
{
59+
"x": 50.0,
60+
"y": 0.0,
61+
"z": -20.0,
62+
"id": 0,
63+
"nugget": 0.000001 # Default nugget value
64+
}
65+
],
66+
"orientations": [
67+
{
68+
"x": 50.0,
69+
"y": 0.0,
70+
"z": -68.0,
71+
"G_x": 1.0,
72+
"G_y": 0.0,
73+
"G_z": 1.0,
74+
"id": 0,
75+
"nugget": 0.01, # Default nugget value
76+
"polarity": 1
77+
}
78+
],
79+
"grid_settings": {
80+
"regular_grid_resolution": [100, 2, 100],
81+
"regular_grid_extent": [0, 150, -10, 10, -100, 0]
82+
},
83+
"interpolation_options": {
84+
"kernel_options": {
85+
"range": 10.0,
86+
"c_o": 5.0
87+
},
88+
"mesh_extraction": True,
89+
"number_octree_levels": 4
90+
}
91+
}
92+
93+
# Save the JSON model
94+
with open("minimal_model.json", "w") as f:
95+
json.dump(json_model_data, f, indent=4)
96+
97+
# Load the model from JSON
98+
json_geo_model = JsonIO.load_model_from_json("minimal_model.json")
99+
100+
# Compute the JSON model
101+
gp.compute_model(json_geo_model, engine_config=gp.data.GemPyEngineConfig())
102+
103+
# %%
104+
# Compare the models
105+
print("\nComparing GemPy and JSON models:")
106+
print("\n1. Surface Points:")
107+
print("GemPy model:")
108+
print(geo_model.surface_points_copy)
109+
print("\nJSON model:")
110+
print(json_geo_model.surface_points_copy)
111+
112+
print("\n2. Orientations:")
113+
print("GemPy model:")
114+
print(geo_model.orientations_copy)
115+
print("\nJSON model:")
116+
print(json_geo_model.orientations_copy)
117+
118+
print("\n3. Grid Settings:")
119+
print("GemPy model:")
120+
print(f"Resolution: {geo_model.grid._dense_grid.resolution}")
121+
print(f"Extent: {geo_model.grid._dense_grid.extent}")
122+
print("\nJSON model:")
123+
print(f"Resolution: {json_geo_model.grid._dense_grid.resolution}")
124+
print(f"Extent: {json_geo_model.grid._dense_grid.extent}")
125+
126+
print("\n4. Interpolation Options:")
127+
print("GemPy model:")
128+
print(f"Range: {geo_model.interpolation_options.kernel_options.range}")
129+
print(f"C_o: {geo_model.interpolation_options.kernel_options.c_o}")
130+
print(f"Mesh Extraction: {geo_model.interpolation_options.mesh_extraction}")
131+
print(f"Number Octree Levels: {geo_model.interpolation_options.number_octree_levels}")
132+
print("\nJSON model:")
133+
print(f"Range: {json_geo_model.interpolation_options.kernel_options.range}")
134+
print(f"C_o: {json_geo_model.interpolation_options.kernel_options.c_o}")
135+
print(f"Mesh Extraction: {json_geo_model.interpolation_options.mesh_extraction}")
136+
print(f"Number Octree Levels: {json_geo_model.interpolation_options.number_octree_levels}")
137+
138+
print("\n5. Structural Groups:")
139+
print("GemPy model:")
140+
for group in geo_model.structural_frame.structural_groups:
141+
print(group)
142+
print("\nJSON model:")
143+
for group in json_geo_model.structural_frame.structural_groups:
144+
print(group)
145+
146+
# %%
147+
# Plot both models side by side
148+
p2d_gempy = gpv.plot_2d(geo_model, title="GemPy Model")
149+
p2d_json = gpv.plot_2d(json_geo_model, title="JSON Model")
150+
151+
# %%

0 commit comments

Comments
 (0)