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
12 changes: 12 additions & 0 deletions simpeg_drivers/utils/tile_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from geoapps_utils.base import Driver, Options
from geoapps_utils.utils.numerical import fibonacci_series, fit_circle
from geoh5py.groups import SimPEGGroup, UIJsonGroup
from pydantic import field_validator
from scipy.interpolate import interp1d
from tqdm import tqdm

Expand Down Expand Up @@ -46,6 +47,17 @@ class TileParameters(Options):
render_plot: bool = True
out_group: UIJsonGroup | None = None

@field_validator("simulation", mode="before")
@classmethod
def forward_and_inverse_drivers_only(cls, value):
Comment thread
domfournier marked this conversation as resolved.
"""Prevents users from running with incompatible apps."""
run_command = value.options.get("run_command", "nope")
invalid = ["plate_simulation", "depth_of_investigation"]
if any(k in run_command for k in invalid):
title = value.options.get("title", "Requested application")
raise ValueError(f"{title} is not a valid target for tile estimation.")
return value


class TileEstimator(Driver):
"""
Expand Down
30 changes: 30 additions & 0 deletions tests/utils_tile_estimate_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Copyright (c) 2023-2026 Mira Geoscience Ltd. '
# '
# This file is part of simpeg-drivers package. '
# '
# simpeg-drivers is distributed under the terms and conditions of the MIT License '
# (see LICENSE file at the root of this source code package). '
# '
# '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

from unittest.mock import MagicMock

import pytest
from geoh5py import Workspace
from geoh5py.groups import SimPEGGroup
from pydantic import ValidationError

from simpeg_drivers.utils.tile_estimate import TileParameters


def test_simulation_validation_rejects_plate_simulation(tmp_path):
simulation = MagicMock(spec=SimPEGGroup)
simulation.options = {
"run_command": "simpeg_drivers.plate_simulation.driver",
"title": "Plate Simulation",
}

with Workspace.create(tmp_path / "test.geoh5") as geoh5:
with pytest.raises(ValidationError, match="not a valid target"):
TileParameters(geoh5=geoh5, simulation=simulation)
Comment thread
benk-mira marked this conversation as resolved.
Loading