Skip to content

Commit 360a103

Browse files
committed
Added default nugget value to minimize input even further
1 parent 0386163 commit 360a103

File tree

3 files changed

+62
-99
lines changed

3 files changed

+62
-99
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525
"y": 0.0,
2626
"z": -20.0,
2727
"id": 0,
28-
"nugget": 0.001 # Default nugget value
29-
},
30-
{
31-
"x": 120.0,
32-
"y": 0.0,
33-
"z": -20.0,
34-
"id": 0,
35-
"nugget": 0.001 # Default nugget value
3628
}
3729
],
3830
"orientations": [
@@ -44,7 +36,6 @@
4436
"G_y": 0.0,
4537
"G_z": 1.0,
4638
"id": 0,
47-
"nugget": 0.001, # Default nugget value
4839
"polarity": 1
4940
}
5041
],

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
"x": 50.0,
6060
"y": 0.0,
6161
"z": -20.0,
62-
"id": 0,
63-
"nugget": 0.0 # Default nugget value
62+
"id": 0
6463
}
6564
],
6665
"orientations": [
@@ -71,9 +70,7 @@
7170
"G_x": 1.0,
7271
"G_y": 0.0,
7372
"G_z": 1.0,
74-
"id": 0,
75-
"nugget": 0.01, # Default nugget value
76-
"polarity": 1
73+
"id": 0
7774
}
7875
],
7976
"grid_settings": {

gempy/modules/json_io/json_operations.py

Lines changed: 60 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _calculate_default_grid_settings(surface_points: List[SurfacePoint], orienta
7474
z_padding = z_range * 0.1
7575

7676
return {
77-
"regular_grid_resolution": [10, 10, 10],
77+
"regular_grid_resolution": [20, 20, 20],
7878
"regular_grid_extent": [
7979
x_min - x_padding, x_max + x_padding,
8080
y_min - y_padding, y_max + y_padding,
@@ -413,115 +413,90 @@ def save_model_to_json(model, file_path: str) -> None:
413413
json.dump(json_data, f, indent=4)
414414

415415
@staticmethod
416-
def _validate_json_schema(data: Dict[str, Any]) -> bool:
417-
"""
418-
Validate the JSON data against the expected schema.
419-
420-
Args:
421-
data (Dict[str, Any]): The JSON data to validate
422-
423-
Returns:
424-
bool: True if valid, False otherwise
425-
"""
426-
# Check required top-level keys (metadata, grid_settings, interpolation_options, and series are optional)
427-
required_keys = {'surface_points', 'orientations'}
428-
if not all(key in data for key in required_keys):
429-
return False
430-
416+
def _validate_json_schema(data: Dict) -> None:
417+
"""Validate the JSON schema and set default values."""
418+
# Required top-level keys
419+
required_keys = ['surface_points', 'orientations', 'grid_settings']
420+
for key in required_keys:
421+
if key not in data:
422+
raise ValueError(f"Missing required key: {key}")
423+
431424
# Validate surface points
432-
if not isinstance(data['surface_points'], list):
433-
return False
434-
435-
for sp in data['surface_points']:
436-
required_sp_keys = {'x', 'y', 'z', 'id', 'nugget'}
437-
if not all(key in sp for key in required_sp_keys):
438-
return False
439-
if not all(isinstance(sp[key], (int, float)) for key in ['x', 'y', 'z', 'nugget']):
440-
return False
441-
if not isinstance(sp['id'], int):
442-
return False
443-
425+
for point in data['surface_points']:
426+
required_point_keys = ['x', 'y', 'z']
427+
for key in required_point_keys:
428+
if key not in point:
429+
raise ValueError(f"Missing required key in surface point: {key}")
430+
# Set default nugget if not provided
431+
if 'nugget' not in point:
432+
point['nugget'] = 0.0 # Default nugget for surface points
433+
444434
# Validate orientations
445-
if not isinstance(data['orientations'], list):
446-
return False
447-
448-
for ori in data['orientations']:
449-
required_ori_keys = {'x', 'y', 'z', 'G_x', 'G_y', 'G_z', 'id', 'nugget', 'polarity'}
450-
if not all(key in ori for key in required_ori_keys):
451-
return False
452-
if not all(isinstance(ori[key], (int, float)) for key in ['x', 'y', 'z', 'G_x', 'G_y', 'G_z', 'nugget']):
453-
return False
454-
if not isinstance(ori['id'], int):
455-
return False
456-
if not isinstance(ori['polarity'], int):
457-
return False
458-
459-
# Validate series if present
435+
for orientation in data['orientations']:
436+
required_orientation_keys = ['x', 'y', 'z', 'G_x', 'G_y', 'G_z']
437+
for key in required_orientation_keys:
438+
if key not in orientation:
439+
raise ValueError(f"Missing required key in orientation: {key}")
440+
# Set default nugget if not provided
441+
if 'nugget' not in orientation:
442+
orientation['nugget'] = 0.01 # Default nugget for orientations
443+
# Set default polarity if not provided
444+
if 'polarity' not in orientation:
445+
orientation['polarity'] = 1
446+
447+
# Validate grid settings
448+
grid_settings = data['grid_settings']
449+
required_grid_keys = ['regular_grid_resolution', 'regular_grid_extent']
450+
for key in required_grid_keys:
451+
if key not in grid_settings:
452+
raise ValueError(f"Missing required key in grid_settings: {key}")
453+
454+
# Validate series if provided
460455
if 'series' in data:
461-
if not isinstance(data['series'], list):
462-
return False
463-
464456
for series in data['series']:
465-
# Only name and surfaces are required
466-
required_series_keys = {'name', 'surfaces'}
467-
if not all(key in series for key in required_series_keys):
468-
return False
469-
if not isinstance(series['name'], str):
470-
return False
471-
if not isinstance(series['surfaces'], list):
472-
return False
473-
# Validate optional fields if present
474-
if 'structural_relation' in series and not isinstance(series['structural_relation'], str):
475-
return False
457+
required_series_keys = ['name', 'surfaces']
458+
for key in required_series_keys:
459+
if key not in series:
460+
raise ValueError(f"Missing required key in series: {key}")
461+
# Set default structural relation if not provided
462+
if 'structural_relation' not in series:
463+
series['structural_relation'] = "ERODE"
464+
# Validate colors if provided
476465
if 'colors' in series:
477466
if not isinstance(series['colors'], list):
478-
return False
479-
if not all(isinstance(color, str) for color in series['colors']):
480-
return False
481-
482-
# Validate grid settings if present
483-
if 'grid_settings' in data:
484-
if not isinstance(data['grid_settings'], dict):
485-
return False
486-
487-
required_grid_keys = {'regular_grid_resolution', 'regular_grid_extent'}
488-
if not all(key in data['grid_settings'] for key in required_grid_keys):
489-
return False
490-
491-
if not isinstance(data['grid_settings']['regular_grid_resolution'], list):
492-
return False
493-
if not isinstance(data['grid_settings']['regular_grid_extent'], list):
494-
return False
467+
raise ValueError("Colors must be a list")
468+
if not all(isinstance(color, str) and color.startswith('#') for color in series['colors']):
469+
raise ValueError("Colors must be hex color codes starting with #")
495470

496471
# Validate interpolation options if present
497472
if 'interpolation_options' in data:
498473
if not isinstance(data['interpolation_options'], dict):
499-
return False
474+
raise ValueError("Interpolation options must be a dictionary")
500475
if 'kernel_options' in data['interpolation_options']:
501476
kernel_options = data['interpolation_options']['kernel_options']
502477
if not isinstance(kernel_options, dict):
503-
return False
478+
raise ValueError("Kernel options must be a dictionary")
504479
if 'range' in kernel_options and not isinstance(kernel_options['range'], (int, float)):
505-
return False
480+
raise ValueError("Kernel range must be a number")
506481
if 'c_o' in kernel_options and not isinstance(kernel_options['c_o'], (int, float)):
507-
return False
482+
raise ValueError("Kernel c_o must be a number")
508483
if 'mesh_extraction' in data['interpolation_options'] and not isinstance(data['interpolation_options']['mesh_extraction'], bool):
509-
return False
484+
raise ValueError("Mesh extraction must be a boolean")
510485
if 'number_octree_levels' in data['interpolation_options'] and not isinstance(data['interpolation_options']['number_octree_levels'], int):
511-
return False
486+
raise ValueError("Number of octree levels must be an integer")
512487

513488
# Validate metadata if present
514489
if 'metadata' in data:
515490
metadata = data['metadata']
516491
if not isinstance(metadata, dict):
517-
return False
492+
raise ValueError("Metadata must be a dictionary")
518493
if 'name' in metadata and not isinstance(metadata['name'], str):
519-
return False
494+
raise ValueError("Metadata name must be a string")
520495
if 'creation_date' in metadata and not isinstance(metadata['creation_date'], str):
521-
return False
496+
raise ValueError("Metadata creation date must be a string")
522497
if 'last_modification_date' in metadata and not isinstance(metadata['last_modification_date'], str):
523-
return False
498+
raise ValueError("Metadata last modification date must be a string")
524499
if 'owner' in metadata and not isinstance(metadata['owner'], str):
525-
return False
500+
raise ValueError("Metadata owner must be a string")
526501

527502
return True

0 commit comments

Comments
 (0)