Skip to content

Commit ea35f3d

Browse files
authored
Merge pull request #290 from MiraGeoscience/GEOPY-2421
GEOPY-2421: Add custom error for topography grid selected without data
2 parents 75a2c39 + f4ff38c commit ea35f3d

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

simpeg_drivers/options.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import numpy as np
1919
from geoapps_utils.base import Options
20-
from geoapps_utils.utils.importing import GeoAppsError
2120
from geoh5py.data import (
2221
BooleanData,
2322
DataAssociationEnum,
@@ -92,6 +91,16 @@ def at_least_one(cls, data):
9291
raise ValueError("Must provide either topography or active model.")
9392
return data
9493

94+
@model_validator(mode="before")
95+
@classmethod
96+
def topo_grid_must_have_elevation_channel(cls, data):
97+
if isinstance(data.get("topography_object", None), Grid2D):
98+
if data.get("topography", None) is None:
99+
raise ValueError(
100+
"Grid2D topography must be accompanied by a valid elevation channel."
101+
)
102+
return data
103+
95104
@model_serializer(mode="wrap")
96105
def serialize_model(self, handler) -> dict[str, Any]:
97106
result = handler(self)

tests/validations_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pytest
1212
from geoapps_utils.utils.importing import GeoAppsError
1313
from geoh5py import Workspace
14+
from geoh5py.objects import Grid2D
1415

1516
from simpeg_drivers.options import CoreOptions
1617

@@ -23,3 +24,25 @@ def test_topo_or_active_validation(tmp_path):
2324
}
2425
with pytest.raises(GeoAppsError, match="active_cells: Value error, Must"):
2526
CoreOptions.build(data)
27+
28+
29+
def test_topo_grid_missing_elevation(tmp_path):
30+
with Workspace(tmp_path / "test.geoh5") as workspace:
31+
grid = Grid2D.create(
32+
workspace,
33+
name="grid",
34+
u_cell_size=10,
35+
v_cell_size=10,
36+
u_count=10,
37+
v_count=10,
38+
origin=[0, 0, 0],
39+
)
40+
41+
data = {
42+
"geoh5": workspace,
43+
"inversion_type": "mvi",
44+
"topography_object": grid,
45+
"topography": None,
46+
}
47+
with pytest.raises(GeoAppsError, match="active_cells: Value error, Grid2D"):
48+
CoreOptions.build(data)

0 commit comments

Comments
 (0)