Skip to content

Commit 5403deb

Browse files
authored
Merge pull request #340 from MiraGeoscience/GEOPY-2519
GEOPY-2519: Synthetic topography for runtests is overly sampled
2 parents 4027423 + 626bf90 commit 5403deb

27 files changed

Lines changed: 90 additions & 53 deletions

simpeg_drivers/utils/synthetics/driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def topography(self):
5050
assert self.options is not None
5151
entity = get_topography_surface(
5252
geoh5=self.geoh5,
53-
options=self.options.survey,
53+
options=self.options,
5454
)
5555
self._topography = entity
5656
return self._topography

simpeg_drivers/utils/synthetics/meshes/octrees.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_octree_mesh(
7575
:return mesh: The discretize TreeMesh object for computations.
7676
"""
7777

78-
mesh = get_base_octree(survey, topography, cell_size, (0, 0, 2), padding_distance)
78+
mesh = get_base_octree(survey, topography, cell_size, (0, 1), padding_distance)
7979

8080
mesh = OctreeDriver.refine_tree_from_points(
8181
mesh, survey.vertices, levels=refinement, finalize=False

simpeg_drivers/utils/synthetics/surveys/factory.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626

2727
def grid_layout(
2828
limits: list[float],
29-
station_spacing: int,
30-
line_spacing: int,
29+
n_stations: int,
30+
n_lines: int,
3131
topography: Callable,
3232
):
3333
"""
3434
Generates grid locations based on limits and spacing.
3535
3636
:param limits: Tuple of (xmin, xmax, ymin, ymax).
37-
:param station_spacing: Number of stations along each line.
38-
:param line_spacing: Number of lines in the grid.
37+
:param n_stations: Number of stations along each line.
38+
:param n_lines: Number of lines in the grid.
3939
:param topography: Callable that generates the topography (z values).
4040
"""
4141

42-
x = np.linspace(limits[0], limits[1], station_spacing)
43-
y = np.linspace(limits[2], limits[3], line_spacing)
42+
x = np.linspace(limits[0], limits[1], n_stations)
43+
y = np.linspace(limits[2], limits[3], n_lines)
4444
X, Y = np.meshgrid(x, y)
4545
Z = topography(X, Y)
4646

@@ -62,8 +62,8 @@ def get_survey(
6262

6363
X, Y, Z = grid_layout(
6464
limits=options.limits,
65-
station_spacing=options.n_stations,
66-
line_spacing=options.n_lines,
65+
n_stations=options.n_stations,
66+
n_lines=options.n_lines,
6767
topography=options.topography,
6868
)
6969
Z += options.drape

simpeg_drivers/utils/synthetics/topography.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,36 @@
1313
from geoh5py.objects import DrapeModel, Octree, Surface
1414
from scipy.spatial import Delaunay
1515

16-
from simpeg_drivers.utils.synthetics.options import SurveyOptions
16+
from simpeg_drivers.utils.synthetics.options import (
17+
MeshOptions,
18+
SurveyOptions,
19+
SyntheticsComponentsOptions,
20+
)
1721
from simpeg_drivers.utils.synthetics.surveys.factory import grid_layout
1822
from simpeg_drivers.utils.utils import active_from_xyz
1923

2024

21-
def get_topography_surface(geoh5: Workspace, options: SurveyOptions) -> Surface:
25+
def get_topography_surface(
26+
geoh5: Workspace, options: SyntheticsComponentsOptions
27+
) -> Surface:
2228
"""
23-
Returns a topography surface with 2x the limits of the survey.
29+
Returns topography with same limits as the mesh and 2x resolution of the survey.
2430
2531
:param geoh5: Geoh5 workspace.
26-
:param options: Survey options. Extents will be 2x the survey extents.
32+
:param options: Options containing survey and mesh specifications.
2733
"""
2834

35+
width, height = compute_mesh_extents(options.survey, options.mesh)
2936
X, Y, Z = grid_layout(
30-
limits=[4 * k for k in options.limits], # type: ignore
31-
station_spacing=int(np.ceil((options.limits[1] - options.limits[0]) / 16)),
32-
line_spacing=int(np.ceil((options.limits[3] - options.limits[2]) / 16)),
33-
topography=options.topography,
37+
limits=[
38+
options.survey.center[0] - width / 2,
39+
options.survey.center[0] + width / 2,
40+
options.survey.center[1] - height / 2,
41+
options.survey.center[1] + height / 2,
42+
],
43+
n_stations=int(2 * width / (options.survey.width / options.survey.n_stations)),
44+
n_lines=int(2 * height / (options.survey.height / options.survey.n_lines)),
45+
topography=options.survey.topography,
3446
)
3547

3648
vertices = np.column_stack(
@@ -45,6 +57,32 @@ def get_topography_surface(geoh5: Workspace, options: SurveyOptions) -> Surface:
4557
)
4658

4759

60+
def compute_mesh_extents(
61+
survey_options: SurveyOptions, mesh_options: MeshOptions
62+
) -> tuple[float, float]:
63+
"""
64+
Estimates the extent of the mesh from survey and mesh options.
65+
66+
:param survey_options: Survey options.
67+
:param mesh_options: Mesh options.
68+
69+
:return: mesh width including padding.
70+
:return: mesh height including padding.
71+
"""
72+
width = survey_options.width
73+
height = survey_options.height
74+
cell_size = mesh_options.cell_size
75+
padding = mesh_options.padding_distance
76+
77+
def next_pow2_cells(span, cell_size, padding):
78+
return 2 ** np.ceil(np.log2((span + 2 * padding) / cell_size))
79+
80+
return (
81+
cell_size[0] * next_pow2_cells(width, cell_size[0], padding),
82+
cell_size[1] * next_pow2_cells(height, cell_size[1], padding),
83+
)
84+
85+
4886
def get_active(
4987
mesh: Octree | DrapeModel, topography: Surface, name: str = "active_cells"
5088
):

tests/plate_simulation/runtest/sweep_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
from simpeg_drivers import assets_path
1717
from simpeg_drivers.plate_simulation.options import PlateSimulationOptions
1818
from simpeg_drivers.plate_simulation.sweep.driver import PlateSweepDriver
19-
from simpeg_drivers.plate_simulation.sweep.options import SweepOptions
2019
from simpeg_drivers.potential_fields.gravity.options import GravityForwardOptions
21-
from simpeg_drivers.utils.synthetics.options import SurveyOptions
20+
from simpeg_drivers.utils.synthetics.options import SyntheticsComponentsOptions
2221
from simpeg_drivers.utils.synthetics.surveys.factory import get_survey
2322
from simpeg_drivers.utils.synthetics.topography import get_topography_surface
2423

2524

2625
def setup_plate_sweep(workspace) -> SimPEGGroup:
27-
survey_options = SurveyOptions()
28-
data = get_survey(workspace, method="gravity", options=survey_options)
29-
topo = get_topography_surface(workspace, survey_options)
26+
options = SyntheticsComponentsOptions()
27+
data = get_survey(workspace, method="gravity", options=options.survey)
28+
topo = get_topography_surface(workspace, options)
3029

3130
gravity = SimPEGGroup.create(workspace, name="gravity fwd")
3231
options = GravityForwardOptions.model_construct()

tests/run_tests/driver_2d_rotated_gradients_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# To test the full run and validate the inversion.
4343
# Move this file out of the test directory and run.
4444

45-
target_run = {"data_norm": 0.688327405060795, "phi_d": 190, "phi_m": 70.5}
45+
target_run = {"data_norm": 0.644727102942656, "phi_d": 182, "phi_m": 66.3}
4646

4747

4848
def test_dc2d_rotated_grad_fwr_run(

tests/run_tests/driver_airborne_fem_1d_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# To test the full run and validate the inversion.
4242
# Move this file out of the test directory and run.
4343

44-
target_run = {"data_norm": 654.2956399855235, "phi_d": 58300, "phi_m": 396}
44+
target_run = {"data_norm": 652.4097142104288, "phi_d": 52800, "phi_m": 341}
4545

4646

4747
def test_fem_fwr_1d_run(

tests/run_tests/driver_airborne_tem_1d_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# To test the full run and validate the inversion.
4040
# Move this file out of the test directory and run.
41-
target_run = {"data_norm": 5.08855682e-10, "phi_d": 20.2, "phi_m": 169000}
41+
target_run = {"data_norm": 5.043446361560613e-10, "phi_d": 23, "phi_m": 194000}
4242

4343

4444
def test_airborne_tem_1d_fwr_run(

tests/run_tests/driver_airborne_tem_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# To test the full run and validate the inversion.
4141
# Move this file out of the test directory and run.
42-
target_run = {"data_norm": 4.0476883635425e-08, "phi_d": 22700000, "phi_m": 1030}
42+
target_run = {"data_norm": 4.047707815081421e-08, "phi_d": 22100000, "phi_m": 2920}
4343

4444

4545
def test_bad_waveform(tmp_path: Path):

tests/run_tests/driver_dc_2d_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# To test the full run and validate the inversion.
4444
# Move this file out of the test directory and run.
4545

46-
target_run = {"data_norm": 0.6441011110410102, "phi_d": 644, "phi_m": 107}
46+
target_run = {"data_norm": 0.606697124141973, "phi_d": 693, "phi_m": 88.5}
4747

4848

4949
def test_dc_2d_fwr_run(

0 commit comments

Comments
 (0)