Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
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: 4 additions & 7 deletions tests/base/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import scipy.sparse as sp

from simpeg import maps, models, utils
from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
from discretize.utils import mesh_builder_xyz, active_from_xyz
import inspect

from simpeg.maps._parametric import (
Expand Down Expand Up @@ -508,14 +508,11 @@ def test_Tile(self):
local_mesh = mesh_builder_xyz(
rxLocs, h, padding_distance=padDist, mesh_type="tree"
)
local_mesh = refine_tree_xyz(
local_mesh,
rxLocs[ii, :].reshape((1, -1)),
method="radial",
octree_levels=[1],
local_mesh.refine_points(
points=rxLocs[ii, :].reshape((1, -1)),
padding_cells_by_level=[1],
finalize=True,
)

local_meshes.append(local_mesh)

mesh = mesh_builder_xyz(rxLocs, h, padding_distance=padDist, mesh_type="tree")
Expand Down
6 changes: 2 additions & 4 deletions tests/dask/test_mag_MVI_Octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)


from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
from discretize.utils import mesh_builder_xyz, active_from_xyz
import numpy as np
from simpeg.potential_fields import magnetics as mag
import shutil
Expand Down Expand Up @@ -62,9 +62,7 @@ def setUp(self):
mesh = mesh_builder_xyz(
xyzLoc, h, padding_distance=padDist, depth_core=100, mesh_type="tree"
)
mesh = refine_tree_xyz(
mesh, topo, method="surface", octree_levels=[4, 4], finalize=True
)
mesh.refine_surface(topo, padding_cells_by_level=[4, 4], finalize=True)
self.mesh = mesh
# Define an active cells from topo
actv = active_from_xyz(mesh, topo)
Expand Down
9 changes: 1 addition & 8 deletions tests/dask/test_mag_inversion_linear_Octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ def setUp(self):
mesh_type="TREE",
)

self.mesh = mesh_utils.refine_tree_xyz(
self.mesh,
topo,
method="surface",
octree_levels=nCpad,
octree_levels_padding=nCpad,
finalize=True,
)
self.mesh.refine_surface(topo, padding_cells_by_level=nCpad, finalize=True)

# Define an active cells from topo
actv = active_from_xyz(self.mesh, topo)
Expand Down
6 changes: 2 additions & 4 deletions tests/dask/test_mag_nonLinear_Amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from simpeg.potential_fields import magnetics
from simpeg import utils
from simpeg.utils import mkvc
from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
from discretize.utils import mesh_builder_xyz, active_from_xyz
import unittest
import shutil

Expand Down Expand Up @@ -65,9 +65,7 @@ def setUp(self):
mesh = mesh_builder_xyz(
rxLoc, h, padding_distance=padDist, depth_core=100, mesh_type="tree"
)
mesh = refine_tree_xyz(
mesh, topo, method="surface", octree_levels=[4, 4], finalize=True
)
mesh.refine_surface(topo, padding_cells_by_level=[4, 4], finalize=True)

# Define an active cells from topo
actv = active_from_xyz(mesh, topo)
Expand Down
6 changes: 2 additions & 4 deletions tests/pf/test_mag_MVI_Octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)


from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
from discretize.utils import mesh_builder_xyz, active_from_xyz
import numpy as np
from simpeg.potential_fields import magnetics as mag
import shutil
Expand Down Expand Up @@ -60,9 +60,7 @@ def setUp(self):
mesh = mesh_builder_xyz(
xyzLoc, h, padding_distance=padDist, depth_core=100, mesh_type="tree"
)
mesh = refine_tree_xyz(
mesh, topo, method="surface", octree_levels=[4, 4], finalize=True
)
mesh.refine_surface(topo, padding_cells_by_level=[4, 4], finalize=True)
self.mesh = mesh
# Define an active cells from topo
actv = active_from_xyz(mesh, topo)
Expand Down
10 changes: 2 additions & 8 deletions tests/pf/test_mag_inversion_linear_Octree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import shutil
import unittest
import numpy as np

import pytest
import matplotlib.pyplot as plt
from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
Expand Down Expand Up @@ -70,14 +71,7 @@ def setUp(self):
mesh_type="TREE",
)

self.mesh = refine_tree_xyz(
self.mesh,
topo,
method="surface",
octree_levels=nCpad,
octree_levels_padding=nCpad,
finalize=True,
)
Comment on lines -73 to -80
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my bad. The issue is not with radial methods, but with surface methods. When passing octree_levels_padding, the refined meshes are different between the old code and the new code.

Minimal example:

import numpy as np
from simpeg import utils
from discretize.utils import mesh_builder_xyz, refine_tree_xyz

# First we need to define the direction of the inducing field
# As a simple case, we pick a vertical inducing field of magnitude
# 50,000nT.
# From old convention, field orientation is given as an
# azimuth from North (positive clockwise)
# and dip from the horizontal (positive downward).
h0_amplitude, h0_inclination, h0_declination = (50000.0, 90.0, 0.0)

# Create a mesh
h = [5, 5, 5]
padDist = np.ones((3, 2)) * 100
nCpad = [2, 4, 2]

# Create grid of points for topography
# Lets create a simple Gaussian topo and set the active cells
[xx, yy] = np.meshgrid(np.linspace(-200.0, 200.0, 50), np.linspace(-200.0, 200.0, 50))

b = 100
A = 50
zz = A * np.exp(-0.5 * ((xx / b) ** 2.0 + (yy / b) ** 2.0))

# We would usually load a topofile
topo = np.c_[utils.mkvc(xx), utils.mkvc(yy), utils.mkvc(zz)]

# Create and array of observation points
xr = np.linspace(-100.0, 100.0, 20)
yr = np.linspace(-100.0, 100.0, 20)
X, Y = np.meshgrid(xr, yr)
Z = A * np.exp(-0.5 * ((X / b) ** 2.0 + (Y / b) ** 2.0)) + 5

xyzLoc = np.c_[utils.mkvc(X.T), utils.mkvc(Y.T), utils.mkvc(Z.T)]

# Build mesh with deprecated functions
old_mesh = mesh_builder_xyz(
    xyzLoc,
    h,
    padding_distance=padDist,
    mesh_type="TREE",
)
old_mesh = refine_tree_xyz(
    old_mesh,
    topo,
    method="surface",
    octree_levels=nCpad,
    octree_levels_padding=nCpad,
    finalize=True,
)

# Build mesh with new methods
new_mesh = mesh_builder_xyz(
    xyzLoc,
    h,
    padding_distance=padDist,
    mesh_type="TREE",
)

new_mesh.refine_surface(topo, padding_cells_by_level=nCpad, finalize=True)

print(f"old_mesh.n_cells: {old_mesh.n_cells}")
print(f"new_mesh.n_cells: {new_mesh.n_cells}")
old_mesh.n_cells: 39624
new_mesh.n_cells: 57516

self.mesh.refine_surface(topo, padding_cells_by_level=nCpad, finalize=True)

# Define an active cells from topo
actv = active_from_xyz(self.mesh, topo)
Expand Down
6 changes: 2 additions & 4 deletions tests/pf/test_mag_nonLinear_Amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from simpeg.potential_fields import magnetics
from simpeg import utils
from simpeg.utils import mkvc
from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
from discretize.utils import mesh_builder_xyz, active_from_xyz
import unittest
import shutil

Expand Down Expand Up @@ -66,9 +66,7 @@ def setUp(self):
mesh = mesh_builder_xyz(
rxLoc, h, padding_distance=padDist, depth_core=100, mesh_type="tree"
)
mesh = refine_tree_xyz(
mesh, topo, method="surface", octree_levels=[4, 4], finalize=True
)
mesh.refine_surface(topo, padding_cells_by_level=[4, 4], finalize=True)

# Define an active cells from topo
actv = active_from_xyz(mesh, topo)
Expand Down
6 changes: 2 additions & 4 deletions tests/pf/test_mag_vector_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)


from discretize.utils import mesh_builder_xyz, refine_tree_xyz, active_from_xyz
from discretize.utils import mesh_builder_xyz, active_from_xyz
import numpy as np
from simpeg.potential_fields import magnetics as mag
import shutil
Expand Down Expand Up @@ -62,9 +62,7 @@ def setUp(self):
mesh = mesh_builder_xyz(
xyzLoc, h, padding_distance=padDist, depth_core=100, mesh_type="tree"
)
mesh = refine_tree_xyz(
mesh, topo, method="surface", octree_levels=[4, 4], finalize=True
)
mesh.refine_surface(topo, padding_cells_by_level=[4, 4], finalize=True)
self.mesh = mesh
# Define an active cells from topo
actv = active_from_xyz(mesh, topo)
Expand Down
13 changes: 4 additions & 9 deletions tests/pf/test_pf_quadtree_inversion_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
from discretize import TensorMesh
from discretize.utils import mesh_builder_xyz, mkvc, refine_tree_xyz
from discretize.utils import mesh_builder_xyz, mkvc

from simpeg import (
data_misfit,
Expand Down Expand Up @@ -50,20 +50,15 @@ def create_mesh(h, padDist, nCpad, topo, data, min_height=1.0):
padDist = np.ones((2, 2)) * 100
nCpad = [2, 4]

mesh = mesh_builder_xyz(
self.mesh = mesh_builder_xyz(
topo[:, :2],
h,
padding_distance=padDist,
mesh_type="TREE",
)

self.mesh = refine_tree_xyz(
mesh,
data[:, :2],
method="radial",
octree_levels=nCpad,
octree_levels_padding=nCpad,
finalize=True,
self.mesh.refine_points(
data[:, :2], padding_cells_by_level=nCpad, finalize=True
)

# elevations are Nx2 array of [bottom-southwest, top-northeast] corners
Expand Down
Loading