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
Updated tests and fixed code to pass tests.
  • Loading branch information
flohorovicic authored and Leguark committed May 1, 2025
commit f9862ed09595bce52a4e0661963bc21194b435c0
82 changes: 54 additions & 28 deletions gempy/modules/json_io/json_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ def load_model_from_json(file_path: str):
interpolation_options=interpolation_options
)

# Set the metadata with proper dates
# Set the metadata with proper dates and defaults
metadata = data.get('metadata', {})
model_meta = GeoModelMeta(
name=model_name,
creation_date=data.get('metadata', {}).get('creation_date', current_date),
last_modification_date=data.get('metadata', {}).get('last_modification_date', current_date),
owner=data.get('metadata', {}).get('owner', "GemPy Modeller")
name=metadata.get('name', model.meta.name), # Use model's name if available
creation_date=metadata.get('creation_date', current_date), # Set current date as default
last_modification_date=metadata.get('last_modification_date', current_date), # Set current date as default
owner=metadata.get('owner', "GemPy Modeller") # Set default owner
)
model.meta = model_meta

Expand Down Expand Up @@ -331,13 +332,16 @@ def save_model_to_json(model, file_path: str) -> None:
model: The GemPy model to save
file_path (str): Path where to save the JSON file
"""
# Create JSON structure
# Get current date for default values
current_date = datetime.now().strftime("%Y-%m-%d")

# Create JSON structure with metadata handling
json_data = {
"metadata": {
"name": model.meta.name,
"creation_date": model.meta.creation_date,
"last_modification_date": model.meta.last_modification_date,
"owner": model.meta.owner
"name": model.meta.name if model.meta.name is not None else "GemPy Model",
"creation_date": model.meta.creation_date if model.meta.creation_date is not None else current_date,
"last_modification_date": model.meta.last_modification_date if model.meta.last_modification_date is not None else current_date,
"owner": model.meta.owner if model.meta.owner is not None else "GemPy Modeller"
},
"surface_points": [],
"orientations": [],
Expand All @@ -364,10 +368,10 @@ def save_model_to_json(model, file_path: str) -> None:
# Get series and surface information
for group in model.structural_frame.structural_groups:
series_entry = {
"name": group.name,
"surfaces": [element.name for element in group.elements],
"structural_relation": group.structural_relation.name,
"colors": [element.color for element in group.elements]
"name": str(group.name),
"surfaces": [str(element.name) for element in group.elements],
"structural_relation": str(group.structural_relation.name),
"colors": [str(element.color) for element in group.elements]
}
json_data["series"].append(series_entry)

Expand Down Expand Up @@ -430,6 +434,9 @@ def _validate_json_schema(data: Dict) -> None:
# Set default nugget if not provided
if 'nugget' not in point:
point['nugget'] = 0.0 # Default nugget for surface points
# Set default id if not provided
if 'id' not in point:
point['id'] = 0 # Default id

# Validate orientations
for orientation in data['orientations']:
Expand All @@ -443,6 +450,9 @@ def _validate_json_schema(data: Dict) -> None:
# Set default polarity if not provided
if 'polarity' not in orientation:
orientation['polarity'] = 1
# Set default id if not provided
if 'id' not in orientation:
orientation['id'] = 0 # Default id

# Validate grid settings
grid_settings = data['grid_settings']
Expand Down Expand Up @@ -485,18 +495,34 @@ def _validate_json_schema(data: Dict) -> None:
if 'number_octree_levels' in data['interpolation_options'] and not isinstance(data['interpolation_options']['number_octree_levels'], int):
raise ValueError("Number of octree levels must be an integer")

# Validate metadata if present
if 'metadata' in data:
metadata = data['metadata']
if not isinstance(metadata, dict):
raise ValueError("Metadata must be a dictionary")
if 'name' in metadata and not isinstance(metadata['name'], str):
raise ValueError("Metadata name must be a string")
if 'creation_date' in metadata and not isinstance(metadata['creation_date'], str):
raise ValueError("Metadata creation date must be a string")
if 'last_modification_date' in metadata and not isinstance(metadata['last_modification_date'], str):
raise ValueError("Metadata last modification date must be a string")
if 'owner' in metadata and not isinstance(metadata['owner'], str):
raise ValueError("Metadata owner must be a string")

# Validate and set default metadata
if 'metadata' not in data:
data['metadata'] = {}

metadata = data['metadata']
if not isinstance(metadata, dict):
raise ValueError("Metadata must be a dictionary")

# Set default values for metadata
current_date = datetime.now().strftime("%Y-%m-%d")
if 'name' not in metadata or metadata['name'] is None:
metadata['name'] = "GemPy Model"
elif not isinstance(metadata['name'], str):
raise ValueError("Metadata name must be a string")

if 'creation_date' not in metadata or metadata['creation_date'] is None:
metadata['creation_date'] = current_date
elif not isinstance(metadata['creation_date'], str):
raise ValueError("Metadata creation_date must be a string")

if 'last_modification_date' not in metadata or metadata['last_modification_date'] is None:
metadata['last_modification_date'] = current_date
elif not isinstance(metadata['last_modification_date'], str):
raise ValueError("Metadata last_modification_date must be a string")

if 'owner' not in metadata or metadata['owner'] is None:
metadata['owner'] = "GemPy Modeller"
elif not isinstance(metadata['owner'], str):
raise ValueError("Metadata owner must be a string")

return True
Loading