Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion simpeg_drivers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import numpy as np
from geoapps_utils.base import Options
from geoapps_utils.utils.importing import GeoAppsError
from geoh5py.data import (
BooleanData,
DataAssociationEnum,
Expand Down Expand Up @@ -92,6 +91,16 @@ def at_least_one(cls, data):
raise ValueError("Must provide either topography or active model.")
return data

@model_validator(mode="before")
@classmethod
def topo_grid_must_have_elevation_channel(cls, data):
if isinstance(data.get("topography_object", None), Grid2D):
if data.get("topography", None) is None:
raise ValueError(
"Grid2D topography must be accompanied by a valid elevation channel."
)
return data

@model_serializer(mode="wrap")
def serialize_model(self, handler) -> dict[str, Any]:
result = handler(self)
Expand Down
23 changes: 23 additions & 0 deletions tests/validations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytest
from geoapps_utils.utils.importing import GeoAppsError
from geoh5py import Workspace
from geoh5py.objects import Grid2D

from simpeg_drivers.options import CoreOptions

Expand All @@ -23,3 +24,25 @@ def test_topo_or_active_validation(tmp_path):
}
with pytest.raises(GeoAppsError, match="active_cells: Value error, Must"):
CoreOptions.build(data)


def test_topo_grid_missing_elevation(tmp_path):
with Workspace(tmp_path / "test.geoh5") as workspace:
grid = Grid2D.create(
workspace,
name="grid",
u_cell_size=10,
v_cell_size=10,
u_count=10,
v_count=10,
origin=[0, 0, 0],
)

data = {
"geoh5": workspace,
"inversion_type": "mvi",
"topography_object": grid,
"topography": None,
}
with pytest.raises(GeoAppsError, match="active_cells: Value error, Grid2D"):
CoreOptions.build(data)