Skip to content

Commit 601e523

Browse files
committed
Improve scalar field visualization in fault model example - Add proper visualization, fix surface points plotting, add colorbar and labels
1 parent 949f7e0 commit 601e523

File tree

1 file changed

+63
-29
lines changed

1 file changed

+63
-29
lines changed

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

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@
133133
# Compute the geological model
134134
gp.compute_model(model)
135135

136+
# Print scalar field values to verify they are calculated
137+
print("\nScalar Field Values (Fault Series):")
138+
print(f"Shape: {model.solutions.raw_arrays.scalar_field_matrix.shape}")
139+
print(f"Min value: {model.solutions.raw_arrays.scalar_field_matrix[0].min()}")
140+
print(f"Max value: {model.solutions.raw_arrays.scalar_field_matrix[0].max()}")
141+
print(f"Mean value: {model.solutions.raw_arrays.scalar_field_matrix[0].mean()}")
142+
136143
# %%
137144
# Save the computed model to a new JSON file
138145
computed_json_file = tutorial_dir / "multiple_series_faults_computed.json"
@@ -183,36 +190,63 @@
183190
plt.close()
184191

185192
# 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")
193+
plt.figure(figsize=(10, 8))
194+
ax = plt.gca()
195+
196+
# Get scalar field values and reshape to grid
197+
scalar_field = model.solutions.raw_arrays.scalar_field_matrix[0].reshape(50, 50, 50)
198+
199+
# Plot middle slice in Y direction
200+
middle_slice = scalar_field[:, 25, :]
201+
im = ax.imshow(middle_slice.T,
202+
extent=[0, 1000, 0, 1000],
203+
origin='lower',
204+
cmap='RdBu',
205+
aspect='equal')
206+
207+
# Add colorbar
208+
plt.colorbar(im, ax=ax, label='Scalar Field Value')
209+
210+
# Plot surface points
211+
fault_element = model.structural_frame.get_element_by_name("fault")
212+
if fault_element and fault_element.surface_points is not None:
213+
fault_points_coords = fault_element.surface_points.xyz
214+
215+
# Filter points near the slice (Y around 500)
216+
mask = np.abs(fault_points_coords[:, 1] - 500) < 100
217+
filtered_points = fault_points_coords[mask]
218+
219+
if len(filtered_points) > 0:
220+
ax.scatter(filtered_points[:, 0], filtered_points[:, 2],
221+
c='red', s=50, label='Surface Points')
222+
ax.legend()
223+
224+
ax.set_xlabel('X')
225+
ax.set_ylabel('Z')
226+
ax.set_title('Fault Scalar Field - Y Direction (Middle Slice)')
227+
228+
# Save plot
199229
plt.savefig('fault_scalar_field.png', dpi=300, bbox_inches='tight')
200230
plt.close()
201231

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}")
232+
print("\nPlot saved as fault_scalar_field.png")
233+
234+
# Plot 4: 3D visualization (optional)
235+
PLOT_3D = False # Set to True to enable 3D plotting
236+
237+
if PLOT_3D:
238+
try:
239+
import pyvista as pv
240+
p = pv.Plotter(notebook=False, off_screen=True)
241+
gpv.plot_3d(
242+
model,
243+
show_data=True,
244+
show_surfaces=True,
245+
show_boundaries=True,
246+
plotter=p
247+
)
248+
p.screenshot('model_3d.png', transparent_background=False)
249+
p.close()
250+
except Exception as e:
251+
print(f"Could not create 3D plot: {e}")
218252
# %%

0 commit comments

Comments
 (0)