Skip to content
Merged
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
test: update JSON I/O tests to verify color preservation - Added colo…
…r assertions in test_multiple_series_relationships and test_combination_model
  • Loading branch information
flohorovicic committed Apr 6, 2025
commit cb5693cfb1dd8ff3fc35808978f342b760924884
235 changes: 234 additions & 1 deletion test/test_modules/test_json_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import gempy as gp
from gempy.modules.json_io import JsonIO
from gempy_engine.core.data.stack_relation_type import StackRelationType
from gempy.core.data.importer_helper import ImporterHelper
import pandas as pd
from gempy.core.data.structural_group import FaultsRelationSpecialCase


@pytest.fixture
Expand Down Expand Up @@ -580,4 +583,234 @@ def test_interpolation_options_handling(tmp_path, sample_model_with_series):
assert loaded_model.interpolation_options.kernel_options.range == 10.0
assert loaded_model.interpolation_options.kernel_options.c_o == 15.0
assert loaded_model.interpolation_options.mesh_extraction is False
assert loaded_model.interpolation_options.number_octree_levels == 2
assert loaded_model.interpolation_options.number_octree_levels == 2


def test_fault_relationships(tmp_path):
"""Test saving and loading models with fault relationships."""
# Create temporary CSV files for surface points and orientations
surface_points_data = pd.DataFrame({
'X': [500, 500, 500],
'Y': [500, 500, 500],
'Z': [800, 500, 200],
'surface': ['fault', 'rock2', 'rock1']
})
orientations_data = pd.DataFrame({
'X': [500, 500, 500],
'Y': [500, 500, 500],
'Z': [800, 500, 200],
'dip': [90, 0, 0],
'azimuth': [90, 90, 90],
'polarity': [1, 1, 1],
'surface': ['fault', 'rock2', 'rock1']
})

surface_points_path = tmp_path / "surface_points.csv"
orientations_path = tmp_path / "orientations.csv"
surface_points_data.to_csv(surface_points_path, index=False)
orientations_data.to_csv(orientations_path, index=False)

# Create a model with fault relationships
importer_helper = ImporterHelper(
path_to_surface_points=str(surface_points_path),
path_to_orientations=str(orientations_path)
)
model = gp.create_geomodel(
project_name='fault_test',
extent=[0, 1000, 0, 1000, 0, 1000],
resolution=[10, 10, 10],
importer_helper=importer_helper
)

# Map stack to surfaces
gp.map_stack_to_surfaces(
gempy_model=model,
mapping_object={
"Fault_Series": ['fault'],
"Strat_Series1": ['rock2'],
"Strat_Series2": ['rock1']
}
)

# Set structural relations
model.structural_frame.structural_groups[0].structural_relation = StackRelationType.FAULT
model.structural_frame.structural_groups[0].fault_relations = FaultsRelationSpecialCase.OFFSET_ALL

# Save the model
file_path = tmp_path / "fault_model.json"
JsonIO.save_model_to_json(model, str(file_path))

# Load the model and verify
loaded_model = JsonIO.load_model_from_json(str(file_path))

# Check structural groups
assert len(loaded_model.structural_frame.structural_groups) == 3
assert loaded_model.structural_frame.structural_groups[0].name == "Fault_Series"
assert loaded_model.structural_frame.structural_groups[0].structural_relation == StackRelationType.FAULT
assert loaded_model.structural_frame.structural_groups[0].fault_relations == FaultsRelationSpecialCase.OFFSET_ALL

# Check fault relations matrix
np.testing.assert_array_equal(
loaded_model.structural_frame.fault_relations,
np.array([[0, 1, 1], [0, 0, 0], [0, 0, 0]])
)


def test_multiple_series_relationships(tmp_path):
"""Test saving and loading models with multiple series and different structural relationships."""
# Create temporary CSV files for surface points and orientations
surface_points_data = pd.DataFrame({
'X': [500, 500, 500, 500],
'Y': [500, 500, 500, 500],
'Z': [800, 600, 400, 200],
'surface': ['fault', 'rock3', 'rock2', 'rock1']
})
orientations_data = pd.DataFrame({
'X': [500, 500, 500, 500],
'Y': [500, 500, 500, 500],
'Z': [800, 600, 400, 200],
'dip': [90, 0, 0, 0],
'azimuth': [90, 90, 90, 90],
'polarity': [1, 1, 1, 1],
'surface': ['fault', 'rock3', 'rock2', 'rock1']
})

surface_points_path = tmp_path / "surface_points.csv"
orientations_path = tmp_path / "orientations.csv"
surface_points_data.to_csv(surface_points_path, index=False)
orientations_data.to_csv(orientations_path, index=False)

# Create a model with multiple series relationships
importer_helper = ImporterHelper(
path_to_surface_points=str(surface_points_path),
path_to_orientations=str(orientations_path)
)
model = gp.create_geomodel(
project_name='multiple_series_test',
extent=[0, 1000, 0, 1000, 0, 1000],
resolution=[10, 10, 10],
importer_helper=importer_helper
)

# Map stack to surfaces
gp.map_stack_to_surfaces(
gempy_model=model,
mapping_object={
"Fault_Series": ['fault'],
"Series3": ['rock3'],
"Series2": ['rock2'],
"Series1": ['rock1']
}
)

# Set structural relations
model.structural_frame.structural_groups[0].structural_relation = StackRelationType.FAULT
model.structural_frame.structural_groups[0].fault_relations = FaultsRelationSpecialCase.OFFSET_ALL
model.structural_frame.structural_groups[1].structural_relation = StackRelationType.ONLAP
model.structural_frame.structural_groups[2].structural_relation = StackRelationType.ERODE
model.structural_frame.structural_groups[3].structural_relation = StackRelationType.ERODE

# Set colors for verification
model.structural_frame.get_element_by_name("fault").color = '#527682' # Fault color
model.structural_frame.get_element_by_name("rock3").color = '#9f0052' # rock3 color
model.structural_frame.get_element_by_name("rock2").color = '#015482' # rock2 color
model.structural_frame.get_element_by_name("rock1").color = '#728f02' # rock1 color

# Save the model
file_path = tmp_path / "multiple_series_model.json"
JsonIO.save_model_to_json(model, str(file_path))

# Load the model and verify
loaded_model = JsonIO.load_model_from_json(str(file_path))

# Check structural groups
assert len(loaded_model.structural_frame.structural_groups) == 4
assert loaded_model.structural_frame.structural_groups[0].structural_relation == StackRelationType.FAULT
assert loaded_model.structural_frame.structural_groups[1].structural_relation == StackRelationType.ONLAP
assert loaded_model.structural_frame.structural_groups[2].structural_relation == StackRelationType.ERODE

# Check colors are preserved
assert loaded_model.structural_frame.get_element_by_name("fault").color == '#527682'
assert loaded_model.structural_frame.get_element_by_name("rock3").color == '#9f0052'
assert loaded_model.structural_frame.get_element_by_name("rock2").color == '#015482'
assert loaded_model.structural_frame.get_element_by_name("rock1").color == '#728f02'


def test_combination_model(tmp_path):
"""Test saving and loading a complex model that combines faults and unconformities."""
# Create temporary CSV files for surface points and orientations
surface_points_data = pd.DataFrame({
'X': [500, 500, 500],
'Y': [500, 500, 500],
'Z': [800, 500, 200],
'surface': ['fault', 'rock2', 'rock1']
})
orientations_data = pd.DataFrame({
'X': [500, 500, 500],
'Y': [500, 500, 500],
'Z': [800, 500, 200],
'dip': [90, 0, 0],
'azimuth': [90, 90, 90],
'polarity': [1, 1, 1],
'surface': ['fault', 'rock2', 'rock1']
})

surface_points_path = tmp_path / "surface_points.csv"
orientations_path = tmp_path / "orientations.csv"
surface_points_data.to_csv(surface_points_path, index=False)
orientations_data.to_csv(orientations_path, index=False)

# Create a combination model
importer_helper = ImporterHelper(
path_to_surface_points=str(surface_points_path),
path_to_orientations=str(orientations_path)
)
model = gp.create_geomodel(
project_name='Combination Model',
extent=[0, 1000, 0, 1000, 0, 1000],
resolution=[10, 10, 10],
importer_helper=importer_helper
)

# Map stack to surfaces
gp.map_stack_to_surfaces(
gempy_model=model,
mapping_object={
"Fault_Series": ['fault'],
"Strat_Series1": ['rock2'],
"Strat_Series2": ['rock1']
}
)

# Set structural relations
model.structural_frame.structural_groups[0].structural_relation = StackRelationType.FAULT
model.structural_frame.structural_groups[0].fault_relations = FaultsRelationSpecialCase.OFFSET_ALL
model.structural_frame.structural_groups[1].structural_relation = StackRelationType.ERODE
model.structural_frame.structural_groups[2].structural_relation = StackRelationType.ONLAP

# Set metadata
model.meta.creation_date = "2024-03-24"
model.meta.last_modification_date = "2024-03-24"

# Save the model
file_path = tmp_path / "combination_model.json"
JsonIO.save_model_to_json(model, str(file_path))

# Load the model and verify
loaded_model = JsonIO.load_model_from_json(str(file_path))

# Check structural setup
assert len(loaded_model.structural_frame.structural_groups) == 3
assert loaded_model.structural_frame.structural_groups[0].structural_relation == StackRelationType.FAULT
assert loaded_model.structural_frame.structural_groups[1].structural_relation == StackRelationType.ERODE
assert loaded_model.structural_frame.structural_groups[2].structural_relation == StackRelationType.ONLAP

# Check fault relations
np.testing.assert_array_equal(
loaded_model.structural_frame.fault_relations,
np.array([[0, 1, 1], [0, 0, 0], [0, 0, 0]])
)

# Check metadata
assert loaded_model.meta.creation_date == "2024-03-24"
assert loaded_model.meta.last_modification_date == "2024-03-24"