File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717
1818import numpy as np
1919from geoapps_utils .base import Options
20- from geoapps_utils .utils .importing import GeoAppsError
2120from 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 )
Original file line number Diff line number Diff line change 1111import pytest
1212from geoapps_utils .utils .importing import GeoAppsError
1313from geoh5py import Workspace
14+ from geoh5py .objects import Grid2D
1415
1516from 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 )
You can’t perform that action at this time.
0 commit comments