Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b4548f2
feat: Add JSON I/O functionality for surface points
flohorovicic Mar 19, 2025
e27ca15
feat: Add orientation data loading functionality
flohorovicic Mar 19, 2025
cb34e62
feat: Add horizontal stratigraphic model tutorial
flohorovicic Mar 19, 2025
f91fa03
fix: Update JSON loading to use surface names from series data - Add …
flohorovicic Mar 19, 2025
9b78ac2
fix: Update horizontal stratigraphic tutorial with correct data and m…
flohorovicic Mar 19, 2025
49b4f25
fix: correct IDs and positions for fault and rock1 in multiple series…
flohorovicic Mar 19, 2025
1e7b405
Added .json input file
flohorovicic Mar 19, 2025
c926296
Updated .json input file
flohorovicic Mar 19, 2025
f82abf2
Adjustments in stack-mapping for more flexible handling of faults
flohorovicic Mar 19, 2025
0f1734b
Added modules __init__ and minor changes in json module
flohorovicic Mar 19, 2025
6cf9a44
fix: Fix metadata handling in JSON I/O for proper preservation when l…
flohorovicic Mar 22, 2025
4c1d177
Updated .gitignore (only to ignore files generated by new tutorial)
flohorovicic Mar 22, 2025
61b7dec
Extended functionality to save .json and adjusted tests. Simple model…
flohorovicic Mar 23, 2025
6a40125
Added structural relations to .json and fixed error in second example
flohorovicic Mar 23, 2025
2a7d8f8
Fixed problem with loading of surface layer stack
flohorovicic Mar 23, 2025
e6fade1
Fixed stratigraphic pile handling in JSON I/O by reverting to working…
flohorovicic Mar 23, 2025
660ae65
Included name-id mapping in .json
flohorovicic Mar 24, 2025
1637ddb
Fix JSON serialization for NumPy types and update example data
flohorovicic Mar 24, 2025
e31bda4
Adjusted date format
flohorovicic Mar 24, 2025
c92878b
Simplified required json input further and added "minimal working exa…
flohorovicic Mar 25, 2025
6d1e029
Simplified minimal input even further: now only points and orientatio…
flohorovicic Mar 25, 2025
84d3332
Updated minimal json examples and comparison to minimal GemPy model
flohorovicic Mar 25, 2025
0386163
Additional fixes to get defaults right
flohorovicic Mar 25, 2025
360a103
Added default nugget value to minimize input even further
flohorovicic Mar 25, 2025
36fec0d
Updated tests and fixed code to pass tests.
flohorovicic Mar 28, 2025
949f7e0
fix: Update fault model example with correct series mapping and visua…
flohorovicic Apr 5, 2025
601e523
Improve scalar field visualization in fault model example - Add prope…
flohorovicic Apr 6, 2025
94f6fd3
Example model for a combination of series and faults from json
flohorovicic Apr 6, 2025
593dbbd
Add combination model JSON files to gitignore
flohorovicic Apr 6, 2025
a4f4264
fix: preserve colors when loading models from JSON - Added color pres…
flohorovicic Apr 6, 2025
cb5693c
test: update JSON I/O tests to verify color preservation - Added colo…
flohorovicic Apr 6, 2025
0e95fb7
Added TODOs for PR.
javoha Apr 11, 2025
369ef46
Added TODOs for PR.
javoha Apr 11, 2025
20ad605
fix: ensure NotRequired import works for both Python 3.11+ and earlie…
flohorovicic Apr 27, 2025
9d9f304
[BUG] Ensure compatibility with older Python versions
Leguark May 1, 2025
040d84a
Merge branch 'main' into fork/flohorovicic/feature/json_io
Leguark May 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Included name-id mapping in .json
  • Loading branch information
flohorovicic committed Mar 24, 2025
commit 660ae656d1636ad436470be6e25cdc2f68a62b1a
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,53 @@
# Define the model data
model_data = {
"metadata": {
"name": "horizontal_stratigraphic",
"creation_date": "2024-03-19",
"last_modification_date": "2024-03-19",
"owner": "tutorial"
"name": "Horizontal Stratigraphic Model",
"creation_date": "2024-01-01T00:00:00",
"last_modification_date": "2024-01-01T00:00:00",
"owner": "GemPy Team"
},
"surface_points": [
# rock2 surface points
{"x": 100.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
{"x": 500.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
{"x": 900.0, "y": 200.0, "z": 600.0, "id": 1, "nugget": 0.00002},
{"x": 100.0, "y": 800.0, "z": 600.0, "id": 1, "nugget": 0.00002},
{"x": 500.0, "y": 800.0, "z": 600.0, "id": 1, "nugget": 0.00002},
{"x": 900.0, "y": 800.0, "z": 600.0, "id": 1, "nugget": 0.00002},
# rock1 surface points
{"x": 100.0, "y": 200.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{"x": 500.0, "y": 200.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{"x": 900.0, "y": 200.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{"x": 100.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{"x": 500.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{"x": 900.0, "y": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{"x": 0.0, "y": 0.0, "z": 0.0, "id": 1, "nugget": 0.0},
{"x": 1.0, "y": 0.0, "z": 0.0, "id": 1, "nugget": 0.0},
{"x": 0.0, "y": 1.0, "z": 0.0, "id": 1, "nugget": 0.0},
{"x": 1.0, "y": 1.0, "z": 0.0, "id": 1, "nugget": 0.0},
{"x": 0.0, "y": 0.0, "z": 1.0, "id": 2, "nugget": 0.0},
{"x": 1.0, "y": 0.0, "z": 1.0, "id": 2, "nugget": 0.0},
{"x": 0.0, "y": 1.0, "z": 1.0, "id": 2, "nugget": 0.0},
{"x": 1.0, "y": 1.0, "z": 1.0, "id": 2, "nugget": 0.0}
],
"orientations": [
# rock2 orientation
{"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},
# rock1 orientation
{"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},
{"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},
{"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}
],
"series": [
{
"name": "Strat_Series",
"surfaces": ["rock2", "rock1"],
"structural_relation": "ERODE"
"name": "series1",
"surfaces": ["layer1", "layer2"],
"structural_relation": "ERODE",
"colors": ["#ff0000", "#00ff00"]
}
],
"grid_settings": {
"regular_grid_resolution": [10, 10, 10],
"regular_grid_extent": [0, 1000, 0, 1000, 0, 1000],
"regular_grid_extent": [0.0, 1.0, 0.0, 1.0, 0.0, 1.0],
"octree_levels": None
},
"interpolation_options": {}
"interpolation_options": {
"kernel_options": {
"range": 1.7,
"c_o": 10
},
"mesh_extraction": True,
"number_octree_levels": 1
},
"fault_relations": None,
"id_name_mapping": {
"name_to_id": {
"layer1": 1,
"layer2": 2
}
}
}

# %%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# %%
# Import necessary libraries
import matplotlib
matplotlib.use('Agg') # Use non-interactive backend
# matplotlib.use('Agg') # Use non-interactive backend
import gempy as gp
import gempy_viewer as gpv
import numpy as np
Expand All @@ -18,79 +18,87 @@
import matplotlib.pyplot as plt
from gempy_engine.core.data.stack_relation_type import StackRelationType
from gempy.modules.json_io.json_operations import JsonIO # Updated import path
from datetime import datetime

# %%
# Define the model data
model_data = {
"metadata": {
"name": "multiple_series_faults",
"creation_date": "2024-03-19",
"last_modification_date": "2024-03-19",
"owner": "tutorial"
"name": "Multiple Series and Faults Model",
"creation_date": datetime.now().isoformat(),
"last_modification_date": datetime.now().isoformat(),
"owner": "GemPy Team"
},
"surface_points": [
# fault surface points (previously rock1 points)
{"x": 0.0, "y": 200.0, "z": 600.0, "id": 2, "nugget": 0.00002},
{"x": 0.0, "y": 500.0, "z": 600.0, "id": 2, "nugget": 0.00002},
{"x": 0.0, "y": 800.0, "z": 600.0, "id": 2, "nugget": 0.00002},
{"x": 200.0, "y": 200.0, "z": 600.0, "id": 2, "nugget": 0.00002},
{"x": 200.0, "y": 500.0, "z": 600.0, "id": 2, "nugget": 0.00002},
{"x": 200.0, "y": 800.0, "z": 600.0, "id": 2, "nugget": 0.00002},
{"x": 800.0, "y": 200.0, "z": 200.0, "id": 2, "nugget": 0.00002},
{"x": 800.0, "y": 500.0, "z": 200.0, "id": 2, "nugget": 0.00002},
{"x": 800.0, "y": 800.0, "z": 200.0, "id": 2, "nugget": 0.00002},
{"x": 1000.0, "y": 200.0, "z": 200.0, "id": 2, "nugget": 0.00002},
{"x": 1000.0, "y": 500.0, "z": 200.0, "id": 2, "nugget": 0.00002},
{"x": 1000.0, "y": 800.0, "z": 200.0, "id": 2, "nugget": 0.00002},
# rock2 surface points
{"x": 0.0, "y": 200.0, "z": 800.0, "id": 1, "nugget": 0.00002},
{"x": 0.0, "y": 800.0, "z": 800.0, "id": 1, "nugget": 0.00002},
{"x": 200.0, "y": 200.0, "z": 800.0, "id": 1, "nugget": 0.00002},
{"x": 200.0, "y": 800.0, "z": 800.0, "id": 1, "nugget": 0.00002},
{"x": 800.0, "y": 200.0, "z": 400.0, "id": 1, "nugget": 0.00002},
{"x": 800.0, "y": 800.0, "z": 400.0, "id": 1, "nugget": 0.00002},
{"x": 1000.0, "y": 200.0, "z": 400.0, "id": 1, "nugget": 0.00002},
{"x": 1000.0, "y": 800.0, "z": 400.0, "id": 1, "nugget": 0.00002},
# rock1 surface points (previously fault points)
{"x": 500.0, "y": 500.0, "z": 500.0, "id": 0, "nugget": 0.00002},
{"x": 450.0, "y": 500.0, "z": 600.0, "id": 0, "nugget": 0.00002},
{"x": 500.0, "y": 200.0, "z": 500.0, "id": 0, "nugget": 0.00002},
{"x": 450.0, "y": 200.0, "z": 600.0, "id": 0, "nugget": 0.00002},
{"x": 500.0, "y": 800.0, "z": 500.0, "id": 0, "nugget": 0.00002},
{"x": 450.0, "y": 800.0, "z": 600.0, "id": 0, "nugget": 0.00002},
{"x": 0, "y": 200, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
{"x": 0, "y": 500, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
{"x": 0, "y": 800, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
{"x": 200, "y": 200, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
{"x": 200, "y": 500, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
{"x": 200, "y": 800, "z": 600, "id": 0, "nugget": 0.00002}, # rock1
{"x": 800, "y": 200, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
{"x": 800, "y": 500, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
{"x": 800, "y": 800, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
{"x": 1000, "y": 200, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
{"x": 1000, "y": 500, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
{"x": 1000, "y": 800, "z": 200, "id": 0, "nugget": 0.00002}, # rock1
{"x": 0, "y": 200, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
{"x": 0, "y": 800, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
{"x": 200, "y": 200, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
{"x": 200, "y": 800, "z": 800, "id": 1, "nugget": 0.00002}, # rock2
{"x": 800, "y": 200, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
{"x": 800, "y": 800, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
{"x": 1000, "y": 200, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
{"x": 1000, "y": 800, "z": 400, "id": 1, "nugget": 0.00002}, # rock2
{"x": 500, "y": 500, "z": 500, "id": 2, "nugget": 0.00002}, # fault
{"x": 450, "y": 500, "z": 600, "id": 2, "nugget": 0.00002}, # fault
{"x": 500, "y": 200, "z": 500, "id": 2, "nugget": 0.00002}, # fault
{"x": 450, "y": 200, "z": 600, "id": 2, "nugget": 0.00002}, # fault
{"x": 500, "y": 800, "z": 500, "id": 2, "nugget": 0.00002}, # fault
{"x": 450, "y": 800, "z": 600, "id": 2, "nugget": 0.00002} # fault
],
"orientations": [
# rock2 orientation (upper layer at x=100)
{"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},
# rock1 orientation (lower layer at x=100)
{"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},
# fault orientation (at x=500)
{"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},
# rock2 orientation (upper layer at x=900)
{"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},
# rock1 orientation (lower layer at x=900)
{"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},
{"x": 100, "y": 500, "z": 800, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1}, # rock2
{"x": 100, "y": 500, "z": 600, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1}, # rock1
{"x": 900, "y": 500, "z": 400, "G_x": 0, "G_y": 0, "G_z": 1, "id": 1, "nugget": 0.00002, "polarity": 1}, # rock2
{"x": 900, "y": 500, "z": 200, "G_x": 0, "G_y": 0, "G_z": 1, "id": 0, "nugget": 0.00002, "polarity": 1}, # rock1
{"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
],
"series": [
{
"name": "Fault_Series",
"surfaces": ["fault"],
"structural_relation": "FAULT",
"color": "#015482" # Blue color for fault
"name": "series1",
"surfaces": ["rock1", "rock2"],
"structural_relation": "ERODE",
"colors": ["#015482", "#9f0052"]
},
{
"name": "Strat_Series",
"surfaces": ["rock2", "rock1"],
"structural_relation": "ERODE",
"colors": ["#ffbe00", "#9f0052"] # Yellow for rock2, Pink for rock1
"name": "fault_series",
"surfaces": ["fault"],
"structural_relation": "FAULT",
"colors": ["#ffbe00"]
}
],
"grid_settings": {
"regular_grid_resolution": [90, 30, 30], # Increased resolution for better visualization
"regular_grid_resolution": [50, 50, 50],
"regular_grid_extent": [0, 1000, 0, 1000, 0, 1000],
"octree_levels": None
},
"interpolation_options": {}
"interpolation_options": {
"kernel_options": {
"range": 1.7,
"c_o": 10
},
"mesh_extraction": True,
"number_octree_levels": 1
},
"fault_relations": [[0, 1], [0, 0]], # Fault series affects series1
"id_name_mapping": {
"name_to_id": {
"rock1": 0,
"rock2": 1,
"fault": 2
}
}
}

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

# Explicitly set the structural relation for the fault series
model.structural_frame.structural_groups[0].structural_relation = StackRelationType.FAULT
model.structural_frame.structural_groups[1].structural_relation = StackRelationType.FAULT

# Set the fault series as a fault
gp.set_is_fault(
frame=model,
fault_groups=['Fault_Series']
fault_groups=['fault_series']
)

# %%
Expand Down Expand Up @@ -176,4 +181,5 @@
gpv.plot_2d(model, show_scalar=True, show_lith=False, series_n=0, ax=ax)
plt.title("Fault Scalar Field")
plt.savefig('fault_scalar_field.png')
plt.close()
plt.close()
# %%
10 changes: 8 additions & 2 deletions gempy/modules/json_io/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Series(TypedDict):
order_series: int
surfaces: List[Surface]
faults: List[Fault]
structural_relation: str
colors: Optional[List[str]]

class GridSettings(TypedDict):
regular_grid_resolution: List[int]
Expand All @@ -53,12 +55,16 @@ class ModelMetadata(TypedDict):
name: str
creation_date: str
last_modification_date: str
owner: str
owner: Optional[str]

class IdNameMapping(TypedDict):
name_to_id: Dict[str, int]

class GemPyModelJson(TypedDict):
metadata: ModelMetadata
surface_points: List[SurfacePoint]
orientations: List[Orientation]
series: List[Series]
grid_settings: GridSettings
interpolation_options: Dict[str, Any]
interpolation_options: Dict[str, Any]
id_name_mapping: IdNameMapping