1
+ """
2
+ Tutorial: Loading a Horizontal Stratigraphic Model using JSON I/O
3
+ ===============================================================
4
+
5
+ This tutorial demonstrates how to load a horizontal stratigraphic model using GemPy's JSON I/O functionality.
6
+ The model consists of two horizontal layers (rock1 and rock2) with surface points and orientations.
7
+ """
8
+
9
+ # %%
10
+ # Import necessary libraries
11
+ import matplotlib
12
+ matplotlib .use ('Agg' ) # Use non-interactive backend
13
+ import gempy as gp
14
+ import gempy_viewer as gpv
15
+ import numpy as np
16
+ import json
17
+ from pathlib import Path
18
+ import matplotlib .pyplot as plt
19
+ from datetime import datetime
20
+
21
+ # %%
22
+ # Define the model data
23
+ model_data = {
24
+ "metadata" : {
25
+ "name" : "Horizontal Stratigraphic Model" ,
26
+ "creation_date" : "2024-03-24" ,
27
+ "last_modification_date" : datetime .now ().strftime ("%Y-%m-%d" ),
28
+ "owner" : "GemPy Team"
29
+ },
30
+ "surface_points" : [
31
+ {"x" : 0.0 , "y" : 0.0 , "z" : 0.0 , "id" : 1 , "nugget" : 0.0 },
32
+ {"x" : 1.0 , "y" : 0.0 , "z" : 0.0 , "id" : 1 , "nugget" : 0.0 },
33
+ {"x" : 0.0 , "y" : 1.0 , "z" : 0.0 , "id" : 1 , "nugget" : 0.0 },
34
+ {"x" : 1.0 , "y" : 1.0 , "z" : 0.0 , "id" : 1 , "nugget" : 0.0 },
35
+ {"x" : 0.0 , "y" : 0.0 , "z" : 1.0 , "id" : 2 , "nugget" : 0.0 },
36
+ {"x" : 1.0 , "y" : 0.0 , "z" : 1.0 , "id" : 2 , "nugget" : 0.0 },
37
+ {"x" : 0.0 , "y" : 1.0 , "z" : 1.0 , "id" : 2 , "nugget" : 0.0 },
38
+ {"x" : 1.0 , "y" : 1.0 , "z" : 1.0 , "id" : 2 , "nugget" : 0.0 }
39
+ ],
40
+ "orientations" : [
41
+ {"x" : 0.5 , "y" : 0.5 , "z" : 0.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 1 , "nugget" : 0.0 , "polarity" : 1 },
42
+ {"x" : 0.5 , "y" : 0.5 , "z" : 1.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 2 , "nugget" : 0.0 , "polarity" : 1 }
43
+ ],
44
+ "series" : [
45
+ {
46
+ "name" : "series1" ,
47
+ "surfaces" : ["layer1" , "layer2" ],
48
+ "structural_relation" : "ERODE" ,
49
+ "colors" : ["#ff0000" , "#00ff00" ]
50
+ }
51
+ ],
52
+ "grid_settings" : {
53
+ "regular_grid_resolution" : [10 , 10 , 10 ],
54
+ "regular_grid_extent" : [0.0 , 1.0 , 0.0 , 1.0 , 0.0 , 1.0 ],
55
+ "octree_levels" : None
56
+ },
57
+ "interpolation_options" : {
58
+ "kernel_options" : {
59
+ "range" : 1.7 ,
60
+ "c_o" : 10
61
+ },
62
+ "mesh_extraction" : True ,
63
+ "number_octree_levels" : 1
64
+ },
65
+ "fault_relations" : None ,
66
+ "id_name_mapping" : {
67
+ "name_to_id" : {
68
+ "layer1" : 1 ,
69
+ "layer2" : 2
70
+ }
71
+ }
72
+ }
73
+
74
+ # %%
75
+ # Save the model data to a JSON file
76
+ tutorial_dir = Path (__file__ ).parent
77
+ json_file = tutorial_dir / "horizontal_stratigraphic.json"
78
+ with open (json_file , "w" ) as f :
79
+ json .dump (model_data , f , indent = 4 )
80
+
81
+ # %%
82
+ # Load the model from JSON
83
+ model = gp .modules .json_io .JsonIO .load_model_from_json (str (json_file ))
84
+
85
+ # %%
86
+ # Compute the geological model
87
+ gp .compute_model (model )
88
+
89
+ # %%
90
+ # Plot the model
91
+ # Plot the initial geological model in the y direction without results
92
+ fig , ax = plt .subplots (figsize = (10 , 6 ))
93
+ gpv .plot_2d (model , direction = ['y' ], show_results = False , ax = ax )
94
+ plt .title ("Initial Geological Model (y direction)" )
95
+ plt .savefig ('initial_model_y.png' )
96
+ plt .close ()
97
+
98
+ # Plot the result of the model in the x and y direction with data and without boundaries
99
+ fig , (ax1 , ax2 ) = plt .subplots (1 , 2 , figsize = (15 , 6 ))
100
+ gpv .plot_2d (model , direction = ['x' ], show_data = True , show_boundaries = False , ax = ax1 )
101
+ ax1 .set_title ("Model with Data (x direction)" )
102
+ gpv .plot_2d (model , direction = ['y' ], show_data = True , show_boundaries = False , ax = ax2 )
103
+ ax2 .set_title ("Model with Data (y direction)" )
104
+ plt .tight_layout ()
105
+ plt .savefig ('model_with_data.png' )
106
+ plt .close ()
0 commit comments