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
Updated minimal json examples and comparison to minimal GemPy model
  • Loading branch information
flohorovicic committed Mar 25, 2025
commit 84d33323804cfe5fa2488c90889b5efd08c60af9
42 changes: 31 additions & 11 deletions examples/tutorials/z_other_tutorials/json_io/05_minimal_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,41 @@


# %%
# Define the model data with minimal required fields
# Create the corresponding minimal JSON model
model_data = {
"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": 800.0, "z": 400.0, "id": 0, "nugget": 0.00002},
{
"x": 50.0,
"y": 0.0,
"z": -20.0,
"id": 0,
"nugget": 0.001 # Default nugget value
},
{
"x": 120.0,
"y": 0.0,
"z": -20.0,
"id": 0,
"nugget": 0.001 # Default nugget value
}
],
"orientations": [
{"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},
{"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},
]
# series will be automatically created with default values:
# - name: "Strat_Series"
# - surfaces: ["surface_0", "surface_1"] (based on unique IDs)
# - structural_relation: "ERODE"
{
"x": 50.0,
"y": 0.0,
"z": -20.0,
"G_x": 1.0,
"G_y": 0.0,
"G_z": 1.0,
"id": 0,
"nugget": 0.001, # Default nugget value
"polarity": 1
}
],
"grid_settings": {
"regular_grid_resolution": [100, 2, 100],
"regular_grid_extent": [0, 150, -10, 10, -100, 0]
}
}

# %%
Expand Down
151 changes: 151 additions & 0 deletions examples/tutorials/z_other_tutorials/json_io/05c_minimal_comparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"""
Tutorial: Compare minimal GemPy model with JSON representation
This tutorial demonstrates how to create a minimal GemPy model and compare it with its JSON representation.
"""

# %%
import gempy as gp
import gempy_viewer as gpv
import json
import numpy as np
from gempy.modules.json_io.json_operations import JsonIO

# %%
# Set up the basic model
geo_model: gp.data.GeoModel = gp.create_geomodel(
project_name='Model1',
extent=[0, 150, -10, 10, -100, 0],
resolution=[100, 2, 100],
structural_frame=gp.data.StructuralFrame.initialize_default_structure()
)

# Add a surface point
gp.add_surface_points(
geo_model=geo_model,
x=[50],
y=[0],
z=[-20],
elements_names=['surface1']
)

# Add an orientation
gp.add_orientations(
geo_model=geo_model,
x=[50],
y=[0],
z=[-68],
elements_names=['surface1'],
pole_vector=[[1, 0, 1]]
)

# Set interpolation options
geo_model.interpolation_options.kernel_options.range = 10.
geo_model.interpolation_options.kernel_options.c_o = 5.
geo_model.interpolation_options.mesh_extraction = True
geo_model.interpolation_options.number_octree_levels = 2

geo_model.update_transform(gp.data.GlobalAnisotropy.NONE)
gp.compute_model(geo_model, engine_config=gp.data.GemPyEngineConfig())

# %%
# Plot the model
p2d = gpv.plot_2d(geo_model)

# %%
# Create the corresponding minimal JSON model
json_model_data = {
"surface_points": [
{
"x": 50.0,
"y": 0.0,
"z": -20.0,
"id": 0,
"nugget": 0.000001 # Default nugget value
}
],
"orientations": [
{
"x": 50.0,
"y": 0.0,
"z": -68.0,
"G_x": 1.0,
"G_y": 0.0,
"G_z": 1.0,
"id": 0,
"nugget": 0.01, # Default nugget value
"polarity": 1
}
],
"grid_settings": {
"regular_grid_resolution": [100, 2, 100],
"regular_grid_extent": [0, 150, -10, 10, -100, 0]
},
"interpolation_options": {
"kernel_options": {
"range": 10.0,
"c_o": 5.0
},
"mesh_extraction": True,
"number_octree_levels": 4
}
}

# Save the JSON model
with open("minimal_model.json", "w") as f:
json.dump(json_model_data, f, indent=4)

# Load the model from JSON
json_geo_model = JsonIO.load_model_from_json("minimal_model.json")

# Compute the JSON model
gp.compute_model(json_geo_model, engine_config=gp.data.GemPyEngineConfig())

# %%
# Compare the models
print("\nComparing GemPy and JSON models:")
print("\n1. Surface Points:")
print("GemPy model:")
print(geo_model.surface_points_copy)
print("\nJSON model:")
print(json_geo_model.surface_points_copy)

print("\n2. Orientations:")
print("GemPy model:")
print(geo_model.orientations_copy)
print("\nJSON model:")
print(json_geo_model.orientations_copy)

print("\n3. Grid Settings:")
print("GemPy model:")
print(f"Resolution: {geo_model.grid._dense_grid.resolution}")
print(f"Extent: {geo_model.grid._dense_grid.extent}")
print("\nJSON model:")
print(f"Resolution: {json_geo_model.grid._dense_grid.resolution}")
print(f"Extent: {json_geo_model.grid._dense_grid.extent}")

print("\n4. Interpolation Options:")
print("GemPy model:")
print(f"Range: {geo_model.interpolation_options.kernel_options.range}")
print(f"C_o: {geo_model.interpolation_options.kernel_options.c_o}")
print(f"Mesh Extraction: {geo_model.interpolation_options.mesh_extraction}")
print(f"Number Octree Levels: {geo_model.interpolation_options.number_octree_levels}")
print("\nJSON model:")
print(f"Range: {json_geo_model.interpolation_options.kernel_options.range}")
print(f"C_o: {json_geo_model.interpolation_options.kernel_options.c_o}")
print(f"Mesh Extraction: {json_geo_model.interpolation_options.mesh_extraction}")
print(f"Number Octree Levels: {json_geo_model.interpolation_options.number_octree_levels}")

print("\n5. Structural Groups:")
print("GemPy model:")
for group in geo_model.structural_frame.structural_groups:
print(group)
print("\nJSON model:")
for group in json_geo_model.structural_frame.structural_groups:
print(group)

# %%
# Plot both models side by side
p2d_gempy = gpv.plot_2d(geo_model, title="GemPy Model")
p2d_json = gpv.plot_2d(json_geo_model, title="JSON Model")

# %%