Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cec6e0f
feat: Add JSON I/O functionality for surface points
flohorovicic Mar 19, 2025
1e86bcd
feat: Add orientation data loading functionality
flohorovicic Mar 19, 2025
8d031e6
feat: Add horizontal stratigraphic model tutorial
flohorovicic Mar 19, 2025
7790956
fix: Update JSON loading to use surface names from series data - Add …
flohorovicic Mar 19, 2025
74ef1d3
fix: Update horizontal stratigraphic tutorial with correct data and m…
flohorovicic Mar 19, 2025
8e580d8
fix: correct IDs and positions for fault and rock1 in multiple series…
flohorovicic Mar 19, 2025
3eb7dc0
Added .json input file
flohorovicic Mar 19, 2025
5c2b339
Updated .json input file
flohorovicic Mar 19, 2025
430a5ac
Adjustments in stack-mapping for more flexible handling of faults
flohorovicic Mar 19, 2025
2f5a6b5
Added modules __init__ and minor changes in json module
flohorovicic Mar 19, 2025
04e87a1
fix: Fix metadata handling in JSON I/O for proper preservation when l…
flohorovicic Mar 22, 2025
1df8dac
Updated .gitignore (only to ignore files generated by new tutorial)
flohorovicic Mar 22, 2025
1c60ddd
Extended functionality to save .json and adjusted tests. Simple model…
flohorovicic Mar 23, 2025
427092e
Added structural relations to .json and fixed error in second example
flohorovicic Mar 23, 2025
3fd2106
Fixed problem with loading of surface layer stack
flohorovicic Mar 23, 2025
9caa992
Fixed stratigraphic pile handling in JSON I/O by reverting to working…
flohorovicic Mar 23, 2025
c5ddb5a
Included name-id mapping in .json
flohorovicic Mar 24, 2025
e6d8c23
Fix JSON serialization for NumPy types and update example data
flohorovicic Mar 24, 2025
f80c4b0
Adjusted date format
flohorovicic Mar 24, 2025
c06aa90
Simplified required json input further and added "minimal working exa…
flohorovicic Mar 25, 2025
2a2c46b
Simplified minimal input even further: now only points and orientatio…
flohorovicic Mar 25, 2025
c4f60aa
Updated minimal json examples and comparison to minimal GemPy model
flohorovicic Mar 25, 2025
e6f9794
Additional fixes to get defaults right
flohorovicic Mar 25, 2025
558a185
Added default nugget value to minimize input even further
flohorovicic Mar 25, 2025
f9862ed
Updated tests and fixed code to pass tests.
flohorovicic Mar 28, 2025
bf069e9
fix: Update fault model example with correct series mapping and visua…
flohorovicic Apr 5, 2025
77a9625
Improve scalar field visualization in fault model example - Add prope…
flohorovicic Apr 6, 2025
5948e42
Example model for a combination of series and faults from json
flohorovicic Apr 6, 2025
a615e8d
Add combination model JSON files to gitignore
flohorovicic Apr 6, 2025
56ac045
fix: preserve colors when loading models from JSON - Added color pres…
flohorovicic Apr 6, 2025
e35ec32
test: update JSON I/O tests to verify color preservation - Added colo…
flohorovicic Apr 6, 2025
986d6c8
Added TODOs for PR.
javoha Apr 11, 2025
27b2292
Added TODOs for PR.
javoha Apr 11, 2025
bb3dc7a
fix: ensure NotRequired import works for both Python 3.11+ and earlie…
flohorovicic Apr 27, 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
Added structural relations to .json and fixed error in second example
  • Loading branch information
flohorovicic authored and Leguark committed May 1, 2025
commit 427092e6f07b1bc5beb084fe08083279e3fdea1b
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"series": [
{
"name": "Strat_Series",
"surfaces": ["rock2", "rock1"]
"surfaces": ["rock2", "rock1"],
"structural_relation": "ERODE"
}
],
"grid_settings": {
Expand Down
41 changes: 30 additions & 11 deletions gempy/modules/json_io/json_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,16 @@ def load_model_from_json(file_path: str):
# Create a mapping from surface points to their names
surface_point_names = {}
for sp in data['surface_points']:
surface_point_names[sp['id']] = next((name for series in data['series']
for name in series['surfaces']
if name in surface_names), "surface_0")
# Find the surface name that corresponds to this ID
surface_name = None
for series in data['series']:
for i, name in enumerate(series['surfaces']):
if i == sp['id']: # Match the ID with the index in the series
surface_name = name
break
if surface_name is not None:
break
surface_point_names[sp['id']] = surface_name if surface_name is not None else f"surface_{sp['id']}"

# Load surface points and orientations
surface_points = JsonIO._load_surface_points(data['surface_points'], surface_point_names)
Expand Down Expand Up @@ -114,13 +121,13 @@ def load_model_from_json(file_path: str):
return model

@staticmethod
def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Dict[int, str]):
def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Optional[Dict[int, str]] = None):
"""
Load surface points from JSON data.

Args:
surface_points_data (List[SurfacePoint]): List of surface point dictionaries
id_to_name (Dict[int, str]): Mapping from surface IDs to names
id_to_name (Optional[Dict[int, str]]): Optional mapping from surface IDs to names

Returns:
SurfacePointsTable: A new SurfacePointsTable instance
Expand All @@ -132,7 +139,7 @@ def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Di
from gempy.core.data.surface_points import SurfacePointsTable

# Validate data structure
required_fields = {'x', 'y', 'z', 'nugget', 'id'} # Add 'id' back to required fields
required_fields = {'x', 'y', 'z', 'nugget', 'id'}
for i, sp in enumerate(surface_points_data):
missing_fields = required_fields - set(sp.keys())
if missing_fields:
Expand All @@ -149,7 +156,13 @@ def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Di
y = np.array([sp['y'] for sp in surface_points_data])
z = np.array([sp['z'] for sp in surface_points_data])
nugget = np.array([sp['nugget'] for sp in surface_points_data])
names = [id_to_name.get(sp['id'], "surface_0") for sp in surface_points_data]

# Handle names based on whether id_to_name mapping is provided
if id_to_name is not None:
names = [id_to_name.get(sp['id'], f"surface_{sp['id']}") for sp in surface_points_data]
else:
# If no mapping provided, use surface IDs as names
names = [f"surface_{sp['id']}" for sp in surface_points_data]

# Create SurfacePointsTable
return SurfacePointsTable.from_arrays(
Expand All @@ -161,13 +174,13 @@ def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Di
)

@staticmethod
def _load_orientations(orientations_data: List[Orientation], id_to_name: Dict[int, str]):
def _load_orientations(orientations_data: List[Orientation], id_to_name: Optional[Dict[int, str]] = None):
"""
Load orientations from JSON data.

Args:
orientations_data (List[Orientation]): List of orientation dictionaries
id_to_name (Dict[int, str]): Mapping from surface IDs to names
id_to_name (Optional[Dict[int, str]]): Optional mapping from surface IDs to names

Returns:
OrientationsTable: A new OrientationsTable instance
Expand All @@ -179,7 +192,7 @@ def _load_orientations(orientations_data: List[Orientation], id_to_name: Dict[in
from gempy.core.data.orientations import OrientationsTable

# Validate data structure
required_fields = {'x', 'y', 'z', 'G_x', 'G_y', 'G_z', 'nugget', 'polarity', 'id'} # Add 'id' back to required fields
required_fields = {'x', 'y', 'z', 'G_x', 'G_y', 'G_z', 'nugget', 'polarity', 'id'}
for i, ori in enumerate(orientations_data):
missing_fields = required_fields - set(ori.keys())
if missing_fields:
Expand All @@ -201,7 +214,13 @@ def _load_orientations(orientations_data: List[Orientation], id_to_name: Dict[in
G_y = np.array([ori['G_y'] for ori in orientations_data])
G_z = np.array([ori['G_z'] for ori in orientations_data])
nugget = np.array([ori['nugget'] for ori in orientations_data])
names = [id_to_name.get(ori['id'], "surface_0") for ori in orientations_data]

# Handle names based on whether id_to_name mapping is provided
if id_to_name is not None:
names = [id_to_name.get(ori['id'], f"surface_{ori['id']}") for ori in orientations_data]
else:
# If no mapping provided, use surface IDs as names
names = [f"surface_{ori['id']}" for ori in orientations_data]

# Apply polarity to gradients
for i, ori in enumerate(orientations_data):
Expand Down