import simpeg.utils as utils import numpy as np # Define the x, y, and z coordinates of the surface x = np.linspace(-10, 10, 21) y = np.linspace(-10, 10, 21) z = np.zeros((21, 21)) # Generate a random topographic surface for i in range(21): for j in range(21): z[i,j] = np.random.uniform(-1, 1) # Convert the topographic surface to an index array ind = utils.surface2ind_topo(x, y, z) # Print the shape of the index array print(ind.shape)
import simpeg.utils as utils import numpy as np import matplotlib.pyplot as plt # Define the x, y, and z coordinates of the surface x = np.linspace(-10, 10, 21) y = np.linspace(-10, 10, 21) z = np.zeros((21, 21)) # Add a hill to the topographic surface for i in range(21): for j in range(21): r = np.sqrt((x[i]**2 + y[j]**2)) z[i,j] = np.sin(r) # Convert the topographic surface to an index array ind = utils.surface2ind_topo(x, y, z) # Plot the topographic surface and the resulting index array fig, ax = plt.subplots(1,2) ax[0].imshow(z, origin='lower', extent=[-10, 10, -10, 10]) ax[0].set_title('Topographic surface') ax[1].imshow(ind, origin='lower', cmap='viridis', extent=[-10, 10, -10, 10]) ax[1].set_title('Index array') plt.show()In this example, we add a hill to the topographic surface and convert it to an index array using the surface2ind_topo function. We then plot the topographic surface and the resulting index array side by side to visualize the conversion. Package Library: SimPEG Utils library.