Skip to content

Commit 6d1e029

Browse files
committed
Simplified minimal input even further: now only points and orientations requried; standard stack created by default based on point/ orientation ids.
1 parent c92878b commit 6d1e029

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

examples/tutorials/z_other_tutorials/json_io/05_minimal_json.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727
"orientations": [
2828
{"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},
2929
{"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},
30-
],
31-
"series": [
32-
{
33-
"name": "Strat_Series",
34-
"surfaces": ["surface_1", "surface_2"]
35-
# structural_relation will default to "ONLAP"
36-
# colors are optional
37-
}
3830
]
31+
# series will be automatically created with default values:
32+
# - name: "Strat_Series"
33+
# - surfaces: ["surface_0", "surface_1"] (based on unique IDs)
34+
# - structural_relation: "ERODE"
3935
}
4036

4137
# %%

gempy/modules/json_io/json_operations.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ def load_model_from_json(file_path: str):
107107
if not JsonIO._validate_json_schema(data):
108108
raise ValueError("Invalid JSON schema")
109109

110+
# Get unique surface IDs from surface points and orientations
111+
surface_ids = set(sp['id'] for sp in data['surface_points'])
112+
surface_ids.update(ori['id'] for ori in data['orientations'])
113+
114+
# Create default series if not provided
115+
if 'series' not in data:
116+
data['series'] = [{
117+
'name': 'Strat_Series',
118+
'surfaces': [f'surface_{id}' for id in sorted(surface_ids)],
119+
'structural_relation': 'ERODE'
120+
}]
121+
110122
# Get surface names from series data
111123
surface_names = []
112124
for series in data['series']:
@@ -409,8 +421,8 @@ def _validate_json_schema(data: Dict[str, Any]) -> bool:
409421
Returns:
410422
bool: True if valid, False otherwise
411423
"""
412-
# Check required top-level keys (metadata, grid_settings, and interpolation_options are optional)
413-
required_keys = {'surface_points', 'orientations', 'series'}
424+
# Check required top-level keys (metadata, grid_settings, interpolation_options, and series are optional)
425+
required_keys = {'surface_points', 'orientations'}
414426
if not all(key in data for key in required_keys):
415427
return False
416428

@@ -442,27 +454,28 @@ def _validate_json_schema(data: Dict[str, Any]) -> bool:
442454
if not isinstance(ori['polarity'], int):
443455
return False
444456

445-
# Validate series
446-
if not isinstance(data['series'], list):
447-
return False
448-
449-
for series in data['series']:
450-
# Only name and surfaces are required
451-
required_series_keys = {'name', 'surfaces'}
452-
if not all(key in series for key in required_series_keys):
453-
return False
454-
if not isinstance(series['name'], str):
457+
# Validate series if present
458+
if 'series' in data:
459+
if not isinstance(data['series'], list):
455460
return False
456-
if not isinstance(series['surfaces'], list):
457-
return False
458-
# Validate optional fields if present
459-
if 'structural_relation' in series and not isinstance(series['structural_relation'], str):
460-
return False
461-
if 'colors' in series:
462-
if not isinstance(series['colors'], list):
461+
462+
for series in data['series']:
463+
# Only name and surfaces are required
464+
required_series_keys = {'name', 'surfaces'}
465+
if not all(key in series for key in required_series_keys):
466+
return False
467+
if not isinstance(series['name'], str):
468+
return False
469+
if not isinstance(series['surfaces'], list):
463470
return False
464-
if not all(isinstance(color, str) for color in series['colors']):
471+
# Validate optional fields if present
472+
if 'structural_relation' in series and not isinstance(series['structural_relation'], str):
465473
return False
474+
if 'colors' in series:
475+
if not isinstance(series['colors'], list):
476+
return False
477+
if not all(isinstance(color, str) for color in series['colors']):
478+
return False
466479

467480
# Validate grid settings if present
468481
if 'grid_settings' in data:

0 commit comments

Comments
 (0)