Skip to content

Commit 949f7e0

Browse files
committed
fix: Update fault model example with correct series mapping and visualization - Fixed series mapping, fault orientation, and plotting
1 parent 36fec0d commit 949f7e0

File tree

5 files changed

+237
-74
lines changed

5 files changed

+237
-74
lines changed

examples/tutorials/z_other_tutorials/json_io/03_multiple_series_faults.py

Lines changed: 107 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,58 @@
3030
"owner": "GemPy Team"
3131
},
3232
"surface_points": [
33-
{"x": 0, "y": 200, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
34-
{"x": 0, "y": 500, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
35-
{"x": 0, "y": 800, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
36-
{"x": 200, "y": 200, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
37-
{"x": 200, "y": 500, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
38-
{"x": 200, "y": 800, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
39-
{"x": 800, "y": 200, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
40-
{"x": 800, "y": 500, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
41-
{"x": 800, "y": 800, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
42-
{"x": 1000, "y": 200, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
43-
{"x": 1000, "y": 500, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
44-
{"x": 1000, "y": 800, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
45-
{"x": 0, "y": 200, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
46-
{"x": 0, "y": 800, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
47-
{"x": 200, "y": 200, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
48-
{"x": 200, "y": 800, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
49-
{"x": 800, "y": 200, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
50-
{"x": 800, "y": 800, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
51-
{"x": 1000, "y": 200, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
52-
{"x": 1000, "y": 800, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
53-
{"x": 500, "y": 500, "z": 500, "id": 2, "nugget": 0.00002}, # fault
54-
{"x": 450, "y": 500, "z": 600, "id": 2, "nugget": 0.00002}, # fault
55-
{"x": 500, "y": 200, "z": 500, "id": 2, "nugget": 0.00002}, # fault
56-
{"x": 450, "y": 200, "z": 600, "id": 2, "nugget": 0.00002}, # fault
57-
{"x": 500, "y": 800, "z": 500, "id": 2, "nugget": 0.00002}, # fault
58-
{"x": 450, "y": 800, "z": 600, "id": 2, "nugget": 0.00002} # fault
33+
# rock1 points
34+
{"x": 0, "y": 200, "z": 600, "id": 0, "nugget": 0.00002},
35+
{"x": 0, "y": 500, "z": 600, "id": 0, "nugget": 0.00002},
36+
{"x": 0, "y": 800, "z": 600, "id": 0, "nugget": 0.00002},
37+
{"x": 200, "y": 200, "z": 600, "id": 0, "nugget": 0.00002},
38+
{"x": 200, "y": 500, "z": 600, "id": 0, "nugget": 0.00002},
39+
{"x": 200, "y": 800, "z": 600, "id": 0, "nugget": 0.00002},
40+
{"x": 800, "y": 200, "z": 200, "id": 0, "nugget": 0.00002},
41+
{"x": 800, "y": 500, "z": 200, "id": 0, "nugget": 0.00002},
42+
{"x": 800, "y": 800, "z": 200, "id": 0, "nugget": 0.00002},
43+
{"x": 1000, "y": 200, "z": 200, "id": 0, "nugget": 0.00002},
44+
{"x": 1000, "y": 500, "z": 200, "id": 0, "nugget": 0.00002},
45+
{"x": 1000, "y": 800, "z": 200, "id": 0, "nugget": 0.00002},
46+
# rock2 points
47+
{"x": 0, "y": 200, "z": 800, "id": 1, "nugget": 0.00002},
48+
{"x": 0, "y": 800, "z": 800, "id": 1, "nugget": 0.00002},
49+
{"x": 200, "y": 200, "z": 800, "id": 1, "nugget": 0.00002},
50+
{"x": 200, "y": 800, "z": 800, "id": 1, "nugget": 0.00002},
51+
{"x": 800, "y": 200, "z": 400, "id": 1, "nugget": 0.00002},
52+
{"x": 800, "y": 800, "z": 400, "id": 1, "nugget": 0.00002},
53+
{"x": 1000, "y": 200, "z": 400, "id": 1, "nugget": 0.00002},
54+
{"x": 1000, "y": 800, "z": 400, "id": 1, "nugget": 0.00002},
55+
# fault points
56+
{"x": 500, "y": 500, "z": 500, "id": 2, "nugget": 0.00002},
57+
{"x": 450, "y": 500, "z": 600, "id": 2, "nugget": 0.00002},
58+
{"x": 500, "y": 200, "z": 500, "id": 2, "nugget": 0.00002},
59+
{"x": 450, "y": 200, "z": 600, "id": 2, "nugget": 0.00002},
60+
{"x": 500, "y": 800, "z": 500, "id": 2, "nugget": 0.00002},
61+
{"x": 450, "y": 800, "z": 600, "id": 2, "nugget": 0.00002}
5962
],
6063
"orientations": [
61-
{"x": 100, "y": 500, "z": 800, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1}, # rock2
62-
{"x": 100, "y": 500, "z": 600, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1}, # rock1
63-
{"x": 900, "y": 500, "z": 400, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1}, # rock2
64-
{"x": 900, "y": 500, "z": 200, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1}, # rock1
65-
{"x": 500, "y": 500, "z": 500, "G_x": 0.866, "G_y": 0, "G_z": 0.5, "id": 2, "nugget": 0.00002, "polarity": 1} # fault
64+
# rock2 orientations
65+
{"x": 100, "y": 500, "z": 800, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1},
66+
{"x": 900, "y": 500, "z": 400, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1},
67+
# rock1 orientations
68+
{"x": 100, "y": 500, "z": 600, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1},
69+
{"x": 900, "y": 500, "z": 200, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1},
70+
# fault orientation (60-degree dip)
71+
{"x": 500, "y": 500, "z": 500, "G_x": 0.866, "G_y": 0, "G_z": 0.5, "id": 2, "nugget": 0.00002, "polarity": 1}
6672
],
6773
"series": [
6874
{
69-
"name": "series1",
70-
"surfaces": ["rock1", "rock2"],
71-
"structural_relation": "ERODE",
72-
"colors": ["#015482", "#9f0052"]
73-
},
74-
{
75-
"name": "fault_series",
75+
"name": "Fault_Series",
7676
"surfaces": ["fault"],
7777
"structural_relation": "FAULT",
7878
"colors": ["#ffbe00"]
79+
},
80+
{
81+
"name": "Strat_Series",
82+
"surfaces": ["rock2", "rock1"],
83+
"structural_relation": "ERODE",
84+
"colors": ["#015482", "#9f0052"]
7985
}
8086
],
8187
"grid_settings": {
@@ -91,7 +97,7 @@
9197
"mesh_extraction": True,
9298
"number_octree_levels": 1
9399
},
94-
"fault_relations": [[0, 1], [0, 0]], # Fault series affects series1
100+
"fault_relations": [[0, 1], [0, 0]], # Fault series affects Strat_Series
95101
"id_name_mapping": {
96102
"name_to_id": {
97103
"rock1": 0,
@@ -123,21 +129,6 @@
123129
print("\nStructural Groups:")
124130
print(model.structural_frame.structural_groups)
125131

126-
# %%
127-
# Set fault relations
128-
# Create a 2x2 matrix for fault relations (2 series: Fault_Series, Strat_Series)
129-
# 1 means the fault affects the series, 0 means it doesn't
130-
model.structural_frame.fault_relations = np.array([[0, 1], [0, 0]], dtype=bool) # Using NumPy array with boolean type
131-
132-
# Explicitly set the structural relation for the fault series
133-
model.structural_frame.structural_groups[1].structural_relation = StackRelationType.FAULT
134-
135-
# Set the fault series as a fault
136-
gp.set_is_fault(
137-
frame=model,
138-
fault_groups=['fault_series']
139-
)
140-
141132
# %%
142133
# Compute the geological model
143134
gp.compute_model(model)
@@ -158,28 +149,70 @@
158149
print(f"Owner: {reloaded_model.meta.owner}")
159150

160151
# %%
161-
# Plot the model
162-
# Plot the initial geological model in the y direction without results
163-
fig, ax = plt.subplots(figsize=(10, 6))
164-
gpv.plot_2d(model, direction=['y'], show_results=False, ax=ax)
165-
plt.title("Initial Geological Model (y direction)")
166-
plt.savefig('initial_model_y.png')
152+
# Create plots with proper configuration
153+
# Plot 1: Cross-section in Y direction (XZ plane)
154+
fig = plt.figure(figsize=(10, 8))
155+
ax = fig.add_subplot(111)
156+
gpv.plot_2d(
157+
model,
158+
cell_number=25, # Middle of the model
159+
direction='y',
160+
show_data=True,
161+
show_boundaries=True,
162+
show_results=True,
163+
ax=ax
164+
)
165+
plt.title("Geological Model - Y Direction (XZ plane)")
166+
plt.savefig('model_y_direction.png', dpi=300, bbox_inches='tight')
167167
plt.close()
168168

169-
# Plot the result of the model in the x and y direction with data and without boundaries
170-
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))
171-
gpv.plot_2d(model, direction=['x'], show_data=True, show_boundaries=False, ax=ax1)
172-
ax1.set_title("Model with Data (x direction)")
173-
gpv.plot_2d(model, direction=['y'], show_data=True, show_boundaries=False, ax=ax2)
174-
ax2.set_title("Model with Data (y direction)")
175-
plt.tight_layout()
176-
plt.savefig('model_with_data.png')
169+
# Plot 2: Cross-section in X direction (YZ plane)
170+
fig = plt.figure(figsize=(10, 8))
171+
ax = fig.add_subplot(111)
172+
gpv.plot_2d(
173+
model,
174+
cell_number=25, # Middle of the model
175+
direction='x',
176+
show_data=True,
177+
show_boundaries=True,
178+
show_results=True,
179+
ax=ax
180+
)
181+
plt.title("Geological Model - X Direction (YZ plane)")
182+
plt.savefig('model_x_direction.png', dpi=300, bbox_inches='tight')
183+
plt.close()
184+
185+
# Plot 3: Scalar field of the fault
186+
fig = plt.figure(figsize=(10, 8))
187+
ax = fig.add_subplot(111)
188+
gpv.plot_2d(
189+
model,
190+
cell_number=25,
191+
direction='y',
192+
show_scalar=True,
193+
show_data=True,
194+
series_n=0, # Fault series
195+
show_results=False,
196+
ax=ax
197+
)
198+
plt.title("Fault Scalar Field - Y Direction")
199+
plt.savefig('fault_scalar_field.png', dpi=300, bbox_inches='tight')
177200
plt.close()
178201

179-
# Plot the scalar field of the fault
180-
fig, ax = plt.subplots(figsize=(10, 6))
181-
gpv.plot_2d(model, show_scalar=True, show_lith=False, series_n=0, ax=ax)
182-
plt.title("Fault Scalar Field")
183-
plt.savefig('fault_scalar_field.png')
184-
plt.close()
202+
# Plot 4: 3D visualization
203+
# Note: 3D plotting requires interactive backend
204+
try:
205+
import pyvista as pv
206+
p = pv.Plotter(notebook=False, off_screen=True)
207+
gpv.plot_3d(
208+
model,
209+
show_data=True,
210+
show_surfaces=True,
211+
show_boundaries=True,
212+
plotter=p
213+
)
214+
p.screenshot('model_3d.png', transparent_background=False)
215+
p.close()
216+
except Exception as e:
217+
print(f"Could not create 3D plot: {e}")
185218
# %%
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"surface_points": [
3+
{
4+
"x": 50.0,
5+
"y": 0.0,
6+
"z": -20.0,
7+
"id": 0
8+
}
9+
],
10+
"orientations": [
11+
{
12+
"x": 50.0,
13+
"y": 0.0,
14+
"z": -68.0,
15+
"G_x": 1.0,
16+
"G_y": 0.0,
17+
"G_z": 1.0,
18+
"id": 0
19+
}
20+
],
21+
"grid_settings": {
22+
"regular_grid_resolution": [
23+
100,
24+
2,
25+
100
26+
],
27+
"regular_grid_extent": [
28+
0,
29+
150,
30+
-10,
31+
10,
32+
-100,
33+
0
34+
]
35+
},
36+
"interpolation_options": {
37+
"kernel_options": {
38+
"range": 10.0,
39+
"c_o": 5.0
40+
},
41+
"mesh_extraction": true,
42+
"number_octree_levels": 2
43+
},
44+
"series": [
45+
{
46+
"name": "default_formations",
47+
"surfaces": [
48+
"surface1"
49+
],
50+
"structural_relation": "ERODE"
51+
}
52+
]
53+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"metadata": {
3+
"name": "GemPy Model",
4+
"creation_date": "2025-03-28",
5+
"last_modification_date": "2025-03-28",
6+
"owner": "GemPy Modeller"
7+
},
8+
"surface_points": [
9+
{
10+
"x": 50.0,
11+
"y": 0.0,
12+
"z": -20.0,
13+
"id": 34966260,
14+
"nugget": 0.0
15+
}
16+
],
17+
"orientations": [
18+
{
19+
"x": 50.0,
20+
"y": 0.0,
21+
"z": -20.0,
22+
"G_x": 1.0,
23+
"G_y": 0.0,
24+
"G_z": 1.0,
25+
"id": 34966260,
26+
"nugget": 0.01,
27+
"polarity": 1
28+
}
29+
],
30+
"series": [
31+
{
32+
"name": "Strat_Series",
33+
"surfaces": [
34+
"surface_0"
35+
],
36+
"structural_relation": "ERODE",
37+
"colors": [
38+
"#015482"
39+
]
40+
}
41+
],
42+
"grid_settings": {
43+
"regular_grid_resolution": [
44+
100,
45+
2,
46+
100
47+
],
48+
"regular_grid_extent": [
49+
0.0,
50+
150.0,
51+
-10.0,
52+
10.0,
53+
-100.0,
54+
0.0
55+
],
56+
"octree_levels": null
57+
},
58+
"interpolation_options": {
59+
"kernel_options": {
60+
"range": 1.7,
61+
"c_o": 10.0
62+
},
63+
"mesh_extraction": true,
64+
"number_octree_levels": 4
65+
},
66+
"fault_relations": [
67+
[
68+
0
69+
]
70+
],
71+
"id_name_mapping": {
72+
"name_to_id": {
73+
"surface_0": 34966260,
74+
"basement": 91927817
75+
}
76+
}
77+
}
150 KB
Loading
189 KB
Loading

0 commit comments

Comments
 (0)