1
+ # %%
2
+ """
3
+ Combination Model with JSON I/O
4
+ ==============================
5
+
6
+ This example demonstrates how to create a model combining faults and unconformities using GemPy's JSON I/O functionality.
7
+ The model is based on the g07_combination.py example, featuring a folded domain with an unconformity and a fault.
8
+
9
+ Part 1: Create and save the initial model structure
10
+ Part 2: Load the model, compute it, and visualize results
11
+ """
12
+
13
+ import gempy as gp
14
+ import gempy_viewer as gpv
15
+ import numpy as np
16
+ import os
17
+ from gempy_engine .core .data .stack_relation_type import StackRelationType
18
+ from gempy_engine .config import AvailableBackends
19
+ from gempy .modules .json_io .json_operations import JsonIO
20
+
21
+ # %%
22
+ # Part 1: Create and save the initial model structure
23
+ # -------------------------------------------------
24
+
25
+ # Define paths
26
+ data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
27
+ path_to_data = data_path + "/data/input_data/jan_models/"
28
+ json_file = "combination_model.json"
29
+ computed_json_file = "combination_model_computed.json"
30
+
31
+ # Create the model with data import
32
+ model = gp .create_geomodel (
33
+ project_name = 'Combination Model' ,
34
+ extent = [0 , 2500 , 0 , 1000 , 0 , 1000 ],
35
+ resolution = [20 , 20 , 20 ],
36
+ refinement = 6 ,
37
+ importer_helper = gp .data .ImporterHelper (
38
+ path_to_orientations = path_to_data + "model7_orientations.csv" ,
39
+ path_to_surface_points = path_to_data + "model7_surface_points.csv"
40
+ )
41
+ )
42
+
43
+ # Set metadata
44
+ model .meta .creation_date = "2024-03-24"
45
+ model .meta .last_modification_date = "2024-03-24"
46
+
47
+ # Map geological series to surfaces
48
+ gp .map_stack_to_surfaces (
49
+ gempy_model = model ,
50
+ mapping_object = {
51
+ "Fault_Series" : ('fault' ,),
52
+ "Strat_Series1" : ('rock3' ,),
53
+ "Strat_Series2" : ('rock2' , 'rock1' ),
54
+ }
55
+ )
56
+
57
+ # Set structural relations
58
+ model .structural_frame .structural_groups [0 ].structural_relation = StackRelationType .FAULT
59
+ model .structural_frame .fault_relations = np .array ([
60
+ [0 , 1 , 1 ],
61
+ [0 , 0 , 0 ],
62
+ [0 , 0 , 0 ]
63
+ ])
64
+
65
+ # Set colors for visualization
66
+ model .structural_frame .get_element_by_name ("fault" ).color = "#015482"
67
+ model .structural_frame .get_element_by_name ("rock3" ).color = "#9f0052"
68
+ model .structural_frame .get_element_by_name ("rock2" ).color = "#ffbe00"
69
+ model .structural_frame .get_element_by_name ("rock1" ).color = "#728f02"
70
+
71
+ # Set interpolation options
72
+ model .interpolation_options .number_octree_levels_surface = 5
73
+
74
+ # Save the model data to a JSON file
75
+ JsonIO .save_model_to_json (model , json_file )
76
+ print (f"\n Saved initial model to: { os .path .abspath (json_file )} " )
77
+
78
+ # %%
79
+ # Part 2: Load the model and compute
80
+ # ---------------------------------
81
+
82
+ print ("\n Loading model from JSON..." )
83
+ model = JsonIO .load_model_from_json (json_file )
84
+
85
+ print ("\n Model Metadata:" )
86
+ print (f"Name: { model .meta .name } " )
87
+ print (f"Creation Date: { model .meta .creation_date } " )
88
+ print (f"Last Modified: { model .meta .last_modification_date } " )
89
+
90
+ print ("\n Structural Groups:" )
91
+ print (model .structural_frame )
92
+
93
+ # Compute the model
94
+ print ("\n Computing the model..." )
95
+ s = gp .compute_model (
96
+ gempy_model = model ,
97
+ engine_config = gp .data .GemPyEngineConfig (
98
+ backend = AvailableBackends .numpy
99
+ )
100
+ )
101
+
102
+ # Save the computed model
103
+ JsonIO .save_model_to_json (model , computed_json_file )
104
+ print (f"\n Saved computed model to: { os .path .abspath (computed_json_file )} " )
105
+
106
+ # Plot the results
107
+ print ("\n Generating plots..." )
108
+
109
+ # 2D plots
110
+ gpv .plot_2d (model , direction = ['y' ], show_results = False )
111
+ gpv .plot_2d (model , direction = 'y' , show_data = True , show_boundaries = True )
112
+ gpv .plot_2d (model , direction = 'x' , show_data = True )
113
+
114
+ # Plot the blocks accounting for fault blocks
115
+ gpv .plot_2d (
116
+ model = model ,
117
+ override_regular_grid = model .solutions .raw_arrays .litho_faults_block ,
118
+ show_data = True , kwargs_lithology = {'cmap' : 'Set1' , 'norm' : None }
119
+ )
120
+
121
+ # 3D plot
122
+ gpv .plot_3d (model )
123
+
124
+ print ("\n Done! The model has been:" )
125
+ print ("1. Created and saved to:" , json_file )
126
+ print ("2. Loaded from JSON" )
127
+ print ("3. Computed" )
128
+ print ("4. Saved with computation results to:" , computed_json_file )
129
+ print ("5. Visualized with various plots" )
0 commit comments