1
+ """
2
+ Tutorial: Compare minimal GemPy model with JSON representation
3
+ This tutorial demonstrates how to create a minimal GemPy model and compare it with its JSON representation.
4
+ """
5
+
6
+ # %%
7
+ import gempy as gp
8
+ import gempy_viewer as gpv
9
+ import json
10
+ import numpy as np
11
+ from gempy .modules .json_io .json_operations import JsonIO
12
+
13
+ # %%
14
+ # Set up the basic model
15
+ geo_model : gp .data .GeoModel = gp .create_geomodel (
16
+ project_name = 'Model1' ,
17
+ extent = [0 , 150 , - 10 , 10 , - 100 , 0 ],
18
+ resolution = [100 , 2 , 100 ],
19
+ structural_frame = gp .data .StructuralFrame .initialize_default_structure ()
20
+ )
21
+
22
+ # Add a surface point
23
+ gp .add_surface_points (
24
+ geo_model = geo_model ,
25
+ x = [50 ],
26
+ y = [0 ],
27
+ z = [- 20 ],
28
+ elements_names = ['surface1' ]
29
+ )
30
+
31
+ # Add an orientation
32
+ gp .add_orientations (
33
+ geo_model = geo_model ,
34
+ x = [50 ],
35
+ y = [0 ],
36
+ z = [- 68 ],
37
+ elements_names = ['surface1' ],
38
+ pole_vector = [[1 , 0 , 1 ]]
39
+ )
40
+
41
+ # Set interpolation options
42
+ geo_model .interpolation_options .kernel_options .range = 10.
43
+ geo_model .interpolation_options .kernel_options .c_o = 5.
44
+ geo_model .interpolation_options .mesh_extraction = True
45
+ geo_model .interpolation_options .number_octree_levels = 2
46
+
47
+ geo_model .update_transform (gp .data .GlobalAnisotropy .NONE )
48
+ gp .compute_model (geo_model , engine_config = gp .data .GemPyEngineConfig ())
49
+
50
+ # %%
51
+ # Plot the model
52
+ p2d = gpv .plot_2d (geo_model )
53
+
54
+ # %%
55
+ # Create the corresponding minimal JSON model
56
+ json_model_data = {
57
+ "surface_points" : [
58
+ {
59
+ "x" : 50.0 ,
60
+ "y" : 0.0 ,
61
+ "z" : - 20.0 ,
62
+ "id" : 0 ,
63
+ "nugget" : 0.000001 # Default nugget value
64
+ }
65
+ ],
66
+ "orientations" : [
67
+ {
68
+ "x" : 50.0 ,
69
+ "y" : 0.0 ,
70
+ "z" : - 68.0 ,
71
+ "G_x" : 1.0 ,
72
+ "G_y" : 0.0 ,
73
+ "G_z" : 1.0 ,
74
+ "id" : 0 ,
75
+ "nugget" : 0.01 , # Default nugget value
76
+ "polarity" : 1
77
+ }
78
+ ],
79
+ "grid_settings" : {
80
+ "regular_grid_resolution" : [100 , 2 , 100 ],
81
+ "regular_grid_extent" : [0 , 150 , - 10 , 10 , - 100 , 0 ]
82
+ },
83
+ "interpolation_options" : {
84
+ "kernel_options" : {
85
+ "range" : 10.0 ,
86
+ "c_o" : 5.0
87
+ },
88
+ "mesh_extraction" : True ,
89
+ "number_octree_levels" : 4
90
+ }
91
+ }
92
+
93
+ # Save the JSON model
94
+ with open ("minimal_model.json" , "w" ) as f :
95
+ json .dump (json_model_data , f , indent = 4 )
96
+
97
+ # Load the model from JSON
98
+ json_geo_model = JsonIO .load_model_from_json ("minimal_model.json" )
99
+
100
+ # Compute the JSON model
101
+ gp .compute_model (json_geo_model , engine_config = gp .data .GemPyEngineConfig ())
102
+
103
+ # %%
104
+ # Compare the models
105
+ print ("\n Comparing GemPy and JSON models:" )
106
+ print ("\n 1. Surface Points:" )
107
+ print ("GemPy model:" )
108
+ print (geo_model .surface_points_copy )
109
+ print ("\n JSON model:" )
110
+ print (json_geo_model .surface_points_copy )
111
+
112
+ print ("\n 2. Orientations:" )
113
+ print ("GemPy model:" )
114
+ print (geo_model .orientations_copy )
115
+ print ("\n JSON model:" )
116
+ print (json_geo_model .orientations_copy )
117
+
118
+ print ("\n 3. Grid Settings:" )
119
+ print ("GemPy model:" )
120
+ print (f"Resolution: { geo_model .grid ._dense_grid .resolution } " )
121
+ print (f"Extent: { geo_model .grid ._dense_grid .extent } " )
122
+ print ("\n JSON model:" )
123
+ print (f"Resolution: { json_geo_model .grid ._dense_grid .resolution } " )
124
+ print (f"Extent: { json_geo_model .grid ._dense_grid .extent } " )
125
+
126
+ print ("\n 4. Interpolation Options:" )
127
+ print ("GemPy model:" )
128
+ print (f"Range: { geo_model .interpolation_options .kernel_options .range } " )
129
+ print (f"C_o: { geo_model .interpolation_options .kernel_options .c_o } " )
130
+ print (f"Mesh Extraction: { geo_model .interpolation_options .mesh_extraction } " )
131
+ print (f"Number Octree Levels: { geo_model .interpolation_options .number_octree_levels } " )
132
+ print ("\n JSON model:" )
133
+ print (f"Range: { json_geo_model .interpolation_options .kernel_options .range } " )
134
+ print (f"C_o: { json_geo_model .interpolation_options .kernel_options .c_o } " )
135
+ print (f"Mesh Extraction: { json_geo_model .interpolation_options .mesh_extraction } " )
136
+ print (f"Number Octree Levels: { json_geo_model .interpolation_options .number_octree_levels } " )
137
+
138
+ print ("\n 5. Structural Groups:" )
139
+ print ("GemPy model:" )
140
+ for group in geo_model .structural_frame .structural_groups :
141
+ print (group )
142
+ print ("\n JSON model:" )
143
+ for group in json_geo_model .structural_frame .structural_groups :
144
+ print (group )
145
+
146
+ # %%
147
+ # Plot both models side by side
148
+ p2d_gempy = gpv .plot_2d (geo_model , title = "GemPy Model" )
149
+ p2d_json = gpv .plot_2d (json_geo_model , title = "JSON Model" )
150
+
151
+ # %%
0 commit comments