Skip to content

Commit 660ae65

Browse files
committed
Included name-id mapping in .json
1 parent e6fade1 commit 660ae65

File tree

3 files changed

+109
-90
lines changed

3 files changed

+109
-90
lines changed

examples/tutorials/z_other_tutorials/json_io/02_horizontal_stratigraphic.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,53 @@
2121
# Define the model data
2222
model_data = {
2323
"metadata": {
24-
"name": "horizontal_stratigraphic",
25-
"creation_date": "2024-03-19",
26-
"last_modification_date": "2024-03-19",
27-
"owner": "tutorial"
24+
"name": "Horizontal Stratigraphic Model",
25+
"creation_date": "2024-01-01T00:00:00",
26+
"last_modification_date": "2024-01-01T00:00:00",
27+
"owner": "GemPy Team"
2828
},
2929
"surface_points": [
30-
# rock2 surface points
31-
{"x": 100.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
32-
{"x": 500.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
33-
{"x": 900.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
34-
{"x": 100.0, "y": 800.0, "z": 600.0, "id": 1, "nugget": 0.00002},
35-
{"x": 500.0, "y": 800.0, "z": 600.0, "id": 1, "nugget": 0.00002},
36-
{"x": 900.0, "y": 800.0, "z": 600.0, "id": 1, "nugget": 0.00002},
37-
# rock1 surface points
38-
{"x": 100.0, "y": 200.0, "z": 400.0, "id": 0, "nugget": 0.00002},
39-
{"x": 500.0, "y": 200.0, "z": 400.0, "id": 0, "nugget": 0.00002},
40-
{"x": 900.0, "y": 200.0, "z": 400.0, "id": 0, "nugget": 0.00002},
41-
{"x": 100.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
42-
{"x": 500.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
43-
{"x": 900.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
30+
{"x": 0.0, "y": 0.0, "z": 0.0, "id": 1, "nugget": 0.0},
31+
{"x": 1.0, "y": 0.0, "z": 0.0, "id": 1, "nugget": 0.0},
32+
{"x": 0.0, "y": 1.0, "z": 0.0, "id": 1, "nugget": 0.0},
33+
{"x": 1.0, "y": 1.0, "z": 0.0, "id": 1, "nugget": 0.0},
34+
{"x": 0.0, "y": 0.0, "z": 1.0, "id": 2, "nugget": 0.0},
35+
{"x": 1.0, "y": 0.0, "z": 1.0, "id": 2, "nugget": 0.0},
36+
{"x": 0.0, "y": 1.0, "z": 1.0, "id": 2, "nugget": 0.0},
37+
{"x": 1.0, "y": 1.0, "z": 1.0, "id": 2, "nugget": 0.0}
4438
],
4539
"orientations": [
46-
# rock2 orientation
47-
{"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},
48-
# rock1 orientation
49-
{"x": 500.0, "y": 500.0, "z": 400.0, "G_x": 0.0, "G_y": 0.0, "G_z": 1.0, "id": 0, "nugget": 0.01, "polarity": 1},
40+
{"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},
41+
{"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}
5042
],
5143
"series": [
5244
{
53-
"name": "Strat_Series",
54-
"surfaces": ["rock2", "rock1"],
55-
"structural_relation": "ERODE"
45+
"name": "series1",
46+
"surfaces": ["layer1", "layer2"],
47+
"structural_relation": "ERODE",
48+
"colors": ["#ff0000", "#00ff00"]
5649
}
5750
],
5851
"grid_settings": {
5952
"regular_grid_resolution": [10, 10, 10],
60-
"regular_grid_extent": [0, 1000, 0, 1000, 0, 1000],
53+
"regular_grid_extent": [0.0, 1.0, 0.0, 1.0, 0.0, 1.0],
6154
"octree_levels": None
6255
},
63-
"interpolation_options": {}
56+
"interpolation_options": {
57+
"kernel_options": {
58+
"range": 1.7,
59+
"c_o": 10
60+
},
61+
"mesh_extraction": True,
62+
"number_octree_levels": 1
63+
},
64+
"fault_relations": None,
65+
"id_name_mapping": {
66+
"name_to_id": {
67+
"layer1": 1,
68+
"layer2": 2
69+
}
70+
}
6471
}
6572

6673
# %%

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

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# %%
1010
# Import necessary libraries
1111
import matplotlib
12-
matplotlib.use('Agg') # Use non-interactive backend
12+
# matplotlib.use('Agg') # Use non-interactive backend
1313
import gempy as gp
1414
import gempy_viewer as gpv
1515
import numpy as np
@@ -18,79 +18,87 @@
1818
import matplotlib.pyplot as plt
1919
from gempy_engine.core.data.stack_relation_type import StackRelationType
2020
from gempy.modules.json_io.json_operations import JsonIO # Updated import path
21+
from datetime import datetime
2122

2223
# %%
2324
# Define the model data
2425
model_data = {
2526
"metadata": {
26-
"name": "multiple_series_faults",
27-
"creation_date": "2024-03-19",
28-
"last_modification_date": "2024-03-19",
29-
"owner": "tutorial"
27+
"name": "Multiple Series and Faults Model",
28+
"creation_date": datetime.now().isoformat(),
29+
"last_modification_date": datetime.now().isoformat(),
30+
"owner": "GemPy Team"
3031
},
3132
"surface_points": [
32-
# fault surface points (previously rock1 points)
33-
{"x": 0.0, "y": 200.0, "z": 600.0, "id": 2, "nugget": 0.00002},
34-
{"x": 0.0, "y": 500.0, "z": 600.0, "id": 2, "nugget": 0.00002},
35-
{"x": 0.0, "y": 800.0, "z": 600.0, "id": 2, "nugget": 0.00002},
36-
{"x": 200.0, "y": 200.0, "z": 600.0, "id": 2, "nugget": 0.00002},
37-
{"x": 200.0, "y": 500.0, "z": 600.0, "id": 2, "nugget": 0.00002},
38-
{"x": 200.0, "y": 800.0, "z": 600.0, "id": 2, "nugget": 0.00002},
39-
{"x": 800.0, "y": 200.0, "z": 200.0, "id": 2, "nugget": 0.00002},
40-
{"x": 800.0, "y": 500.0, "z": 200.0, "id": 2, "nugget": 0.00002},
41-
{"x": 800.0, "y": 800.0, "z": 200.0, "id": 2, "nugget": 0.00002},
42-
{"x": 1000.0, "y": 200.0, "z": 200.0, "id": 2, "nugget": 0.00002},
43-
{"x": 1000.0, "y": 500.0, "z": 200.0, "id": 2, "nugget": 0.00002},
44-
{"x": 1000.0, "y": 800.0, "z": 200.0, "id": 2, "nugget": 0.00002},
45-
# rock2 surface points
46-
{"x": 0.0, "y": 200.0, "z": 800.0, "id": 1, "nugget": 0.00002},
47-
{"x": 0.0, "y": 800.0, "z": 800.0, "id": 1, "nugget": 0.00002},
48-
{"x": 200.0, "y": 200.0, "z": 800.0, "id": 1, "nugget": 0.00002},
49-
{"x": 200.0, "y": 800.0, "z": 800.0, "id": 1, "nugget": 0.00002},
50-
{"x": 800.0, "y": 200.0, "z": 400.0, "id": 1, "nugget": 0.00002},
51-
{"x": 800.0, "y": 800.0, "z": 400.0, "id": 1, "nugget": 0.00002},
52-
{"x": 1000.0, "y": 200.0, "z": 400.0, "id": 1, "nugget": 0.00002},
53-
{"x": 1000.0, "y": 800.0, "z": 400.0, "id": 1, "nugget": 0.00002},
54-
# rock1 surface points (previously fault points)
55-
{"x": 500.0, "y": 500.0, "z": 500.0, "id": 0, "nugget": 0.00002},
56-
{"x": 450.0, "y": 500.0, "z": 600.0, "id": 0, "nugget": 0.00002},
57-
{"x": 500.0, "y": 200.0, "z": 500.0, "id": 0, "nugget": 0.00002},
58-
{"x": 450.0, "y": 200.0, "z": 600.0, "id": 0, "nugget": 0.00002},
59-
{"x": 500.0, "y": 800.0, "z": 500.0, "id": 0, "nugget": 0.00002},
60-
{"x": 450.0, "y": 800.0, "z": 600.0, "id": 0, "nugget": 0.00002},
33+
{"x": 0, "y": 200, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
34+
{"x": 0, "y": 500, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
35+
{"x": 0, "y": 800, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
36+
{"x": 200, "y": 200, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
37+
{"x": 200, "y": 500, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
38+
{"x": 200, "y": 800, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
39+
{"x": 800, "y": 200, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
40+
{"x": 800, "y": 500, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
41+
{"x": 800, "y": 800, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
42+
{"x": 1000, "y": 200, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
43+
{"x": 1000, "y": 500, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
44+
{"x": 1000, "y": 800, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
45+
{"x": 0, "y": 200, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
46+
{"x": 0, "y": 800, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
47+
{"x": 200, "y": 200, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
48+
{"x": 200, "y": 800, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
49+
{"x": 800, "y": 200, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
50+
{"x": 800, "y": 800, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
51+
{"x": 1000, "y": 200, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
52+
{"x": 1000, "y": 800, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
53+
{"x": 500, "y": 500, "z": 500, "id": 2, "nugget": 0.00002}, # fault
54+
{"x": 450, "y": 500, "z": 600, "id": 2, "nugget": 0.00002}, # fault
55+
{"x": 500, "y": 200, "z": 500, "id": 2, "nugget": 0.00002}, # fault
56+
{"x": 450, "y": 200, "z": 600, "id": 2, "nugget": 0.00002}, # fault
57+
{"x": 500, "y": 800, "z": 500, "id": 2, "nugget": 0.00002}, # fault
58+
{"x": 450, "y": 800, "z": 600, "id": 2, "nugget": 0.00002} # fault
6159
],
6260
"orientations": [
63-
# rock2 orientation (upper layer at x=100)
64-
{"x": 100.0, "y": 500.0, "z": 800.0, "G_x": 0.0, "G_y": 0.0, "G_z": 1.0, "id": 1, "nugget": 0.01, "polarity": 1},
65-
# rock1 orientation (lower layer at x=100)
66-
{"x": 100.0, "y": 500.0, "z": 600.0, "G_x": 0.0, "G_y": 0.0, "G_z": 1.0, "id": 2, "nugget": 0.01, "polarity": 1},
67-
# fault orientation (at x=500)
68-
{"x": 500.0, "y": 500.0, "z": 500.0, "G_x": 0.8, "G_y": 0.0, "G_z": 0.6, "id": 0, "nugget": 0.01, "polarity": 1},
69-
# rock2 orientation (upper layer at x=900)
70-
{"x": 900.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},
71-
# rock1 orientation (lower layer at x=900)
72-
{"x": 900.0, "y": 500.0, "z": 200.0, "G_x": 0.0, "G_y": 0.0, "G_z": 1.0, "id": 2, "nugget": 0.01, "polarity": 1},
61+
{"x": 100, "y": 500, "z": 800, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1}, # rock2
62+
{"x": 100, "y": 500, "z": 600, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1}, # rock1
63+
{"x": 900, "y": 500, "z": 400, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1}, # rock2
64+
{"x": 900, "y": 500, "z": 200, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1}, # rock1
65+
{"x": 500, "y": 500, "z": 500, "G_x": 0.866, "G_y": 0, "G_z": 0.5, "id": 2, "nugget": 0.00002, "polarity": 1} # fault
7366
],
7467
"series": [
7568
{
76-
"name": "Fault_Series",
77-
"surfaces": ["fault"],
78-
"structural_relation": "FAULT",
79-
"color": "#015482" # Blue color for fault
69+
"name": "series1",
70+
"surfaces": ["rock1", "rock2"],
71+
"structural_relation": "ERODE",
72+
"colors": ["#015482", "#9f0052"]
8073
},
8174
{
82-
"name": "Strat_Series",
83-
"surfaces": ["rock2", "rock1"],
84-
"structural_relation": "ERODE",
85-
"colors": ["#ffbe00", "#9f0052"] # Yellow for rock2, Pink for rock1
75+
"name": "fault_series",
76+
"surfaces": ["fault"],
77+
"structural_relation": "FAULT",
78+
"colors": ["#ffbe00"]
8679
}
8780
],
8881
"grid_settings": {
89-
"regular_grid_resolution": [90, 30, 30], # Increased resolution for better visualization
82+
"regular_grid_resolution": [50, 50, 50],
9083
"regular_grid_extent": [0, 1000, 0, 1000, 0, 1000],
9184
"octree_levels": None
9285
},
93-
"interpolation_options": {}
86+
"interpolation_options": {
87+
"kernel_options": {
88+
"range": 1.7,
89+
"c_o": 10
90+
},
91+
"mesh_extraction": True,
92+
"number_octree_levels": 1
93+
},
94+
"fault_relations": [[0, 1], [0, 0]], # Fault series affects series1
95+
"id_name_mapping": {
96+
"name_to_id": {
97+
"rock1": 0,
98+
"rock2": 1,
99+
"fault": 2
100+
}
101+
}
94102
}
95103

96104
# %%
@@ -119,18 +127,15 @@
119127
# Set fault relations
120128
# Create a 2x2 matrix for fault relations (2 series: Fault_Series, Strat_Series)
121129
# 1 means the fault affects the series, 0 means it doesn't
122-
model.structural_frame.fault_relations = np.array([
123-
[0, 1], # Fault_Series affects Strat_Series
124-
[0, 0] # Strat_Series doesn't affect any series
125-
])
130+
model.structural_frame.fault_relations = np.array([[0, 1], [0, 0]], dtype=bool) # Using NumPy array with boolean type
126131

127132
# Explicitly set the structural relation for the fault series
128-
model.structural_frame.structural_groups[0].structural_relation = StackRelationType.FAULT
133+
model.structural_frame.structural_groups[1].structural_relation = StackRelationType.FAULT
129134

130135
# Set the fault series as a fault
131136
gp.set_is_fault(
132137
frame=model,
133-
fault_groups=['Fault_Series']
138+
fault_groups=['fault_series']
134139
)
135140

136141
# %%
@@ -176,4 +181,5 @@
176181
gpv.plot_2d(model, show_scalar=True, show_lith=False, series_n=0, ax=ax)
177182
plt.title("Fault Scalar Field")
178183
plt.savefig('fault_scalar_field.png')
179-
plt.close()
184+
plt.close()
185+
# %%

gempy/modules/json_io/schema.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Series(TypedDict):
4343
order_series: int
4444
surfaces: List[Surface]
4545
faults: List[Fault]
46+
structural_relation: str
47+
colors: Optional[List[str]]
4648

4749
class GridSettings(TypedDict):
4850
regular_grid_resolution: List[int]
@@ -53,12 +55,16 @@ class ModelMetadata(TypedDict):
5355
name: str
5456
creation_date: str
5557
last_modification_date: str
56-
owner: str
58+
owner: Optional[str]
59+
60+
class IdNameMapping(TypedDict):
61+
name_to_id: Dict[str, int]
5762

5863
class GemPyModelJson(TypedDict):
5964
metadata: ModelMetadata
6065
surface_points: List[SurfacePoint]
6166
orientations: List[Orientation]
6267
series: List[Series]
6368
grid_settings: GridSettings
64-
interpolation_options: Dict[str, Any]
69+
interpolation_options: Dict[str, Any]
70+
id_name_mapping: IdNameMapping

0 commit comments

Comments
 (0)