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 gempy as gp
12
+ import gempy_viewer as gpv
13
+ import numpy as np
14
+ import json
15
+ from pathlib import Path
16
+
17
+ # %%
18
+ # Define the model data
19
+ model_data = {
20
+ "metadata" : {
21
+ "name" : "horizontal_stratigraphic" ,
22
+ "creation_date" : "2024-03-19" ,
23
+ "last_modification_date" : "2024-03-19" ,
24
+ "owner" : "tutorial"
25
+ },
26
+ "surface_points" : [
27
+ # rock1 surface points
28
+ {"x" : 500.0 , "y" : 500.0 , "z" : 500.0 , "id" : 0 , "nugget" : 0.00002 },
29
+ {"x" : 500.0 , "y" : 500.0 , "z" : 600.0 , "id" : 0 , "nugget" : 0.00002 },
30
+ {"x" : 500.0 , "y" : 500.0 , "z" : 700.0 , "id" : 0 , "nugget" : 0.00002 },
31
+ {"x" : 500.0 , "y" : 500.0 , "z" : 800.0 , "id" : 0 , "nugget" : 0.00002 },
32
+ {"x" : 500.0 , "y" : 500.0 , "z" : 900.0 , "id" : 0 , "nugget" : 0.00002 },
33
+ # rock2 surface points
34
+ {"x" : 500.0 , "y" : 500.0 , "z" : 200.0 , "id" : 1 , "nugget" : 0.00002 },
35
+ {"x" : 500.0 , "y" : 500.0 , "z" : 300.0 , "id" : 1 , "nugget" : 0.00002 },
36
+ {"x" : 500.0 , "y" : 500.0 , "z" : 400.0 , "id" : 1 , "nugget" : 0.00002 },
37
+ {"x" : 500.0 , "y" : 500.0 , "z" : 500.0 , "id" : 1 , "nugget" : 0.00002 },
38
+ {"x" : 500.0 , "y" : 500.0 , "z" : 600.0 , "id" : 1 , "nugget" : 0.00002 },
39
+ ],
40
+ "orientations" : [
41
+ # rock1 orientations
42
+ {"x" : 500.0 , "y" : 500.0 , "z" : 500.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 0 , "nugget" : 0.01 , "polarity" : 1 },
43
+ {"x" : 500.0 , "y" : 500.0 , "z" : 700.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 0 , "nugget" : 0.01 , "polarity" : 1 },
44
+ {"x" : 500.0 , "y" : 500.0 , "z" : 900.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 0 , "nugget" : 0.01 , "polarity" : 1 },
45
+ # rock2 orientations
46
+ {"x" : 500.0 , "y" : 500.0 , "z" : 200.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 1 , "nugget" : 0.01 , "polarity" : 1 },
47
+ {"x" : 500.0 , "y" : 500.0 , "z" : 400.0 , "G_x" : 0.0 , "G_y" : 0.0 , "G_z" : 1.0 , "id" : 1 , "nugget" : 0.01 , "polarity" : 1 },
48
+ {"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 },
49
+ ],
50
+ "series" : [
51
+ {
52
+ "name" : "Strat_Series" ,
53
+ "surfaces" : ["rock2" , "rock1" ]
54
+ }
55
+ ],
56
+ "grid_settings" : {
57
+ "regular_grid_resolution" : [10 , 10 , 10 ],
58
+ "regular_grid_extent" : [0 , 1000 , 0 , 1000 , 0 , 1000 ],
59
+ "octree_levels" : None
60
+ },
61
+ "interpolation_options" : {}
62
+ }
63
+
64
+ # %%
65
+ # Save the model data to a JSON file
66
+ tutorial_dir = Path (__file__ ).parent
67
+ json_file = tutorial_dir / "horizontal_stratigraphic.json"
68
+ with open (json_file , "w" ) as f :
69
+ json .dump (model_data , f , indent = 4 )
70
+
71
+ # %%
72
+ # Load the model from JSON
73
+ model = gp .modules .json_io .JsonIO .load_model_from_json (str (json_file ))
74
+
75
+ # %%
76
+ # Plot the model
77
+ # Plot the initial geological model in the y direction without results
78
+ gpv .plot_2d (model , direction = ['y' ], show_results = False )
79
+
80
+ # Plot the result of the model in the x and y direction with data and without boundaries
81
+ gpv .plot_2d (model , direction = ['x' ], show_data = True , show_boundaries = False )
82
+ gpv .plot_2d (model , direction = ['y' ], show_data = True , show_boundaries = False )
0 commit comments