-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeotech-ztem-example.py
299 lines (198 loc) · 7.49 KB
/
Geotech-ztem-example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python
# coding: utf-8
# # 3D forward simulation of ZTEM data
import numpy as np
import time
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm, Normalize
import discretize
from pymatsolver import Pardiso as Solver
from SimPEG import maps, data
# from SimPEG import maps, utils, data, optimization, maps, objective_function, regularization, inverse_problem, directives, inversion, data_misfit
from SimPEG.electromagnetics import natural_source as nsem
from SimPEG.utils import plot2Ddata, surface2ind_topo
# ## create a tensor mesh
# core mesh
csx = 100 # cell size in the x, y directions
ncx = 13 # number of cells in the x, y directions
csz = 25 # number of cells in the z direction
ncz = int(350/csz) # number of cells in the z direction
nca = 3 # number of core cells above z=0 (for modelling topography)
npad = 5 # number of padding cells in x, y
npadz = 8 # number of padding cells in z
# create the tensor mesh
mesh = discretize.TensorMesh(
[
[(csx, npad, -1.5), (csx, ncx), (csx, npad, 1.5)],
[(csx, npad, -1.5), (csx, ncx), (csx, npad, 1.5)],
[(csz, npadz, -1.6), (csz, ncz+nca), (csz, npadz, 1.6)],
], origin="CC0"
)
mesh.origin = mesh.origin + np.r_[0, 0, -mesh.h[2][:npadz+ncz].sum()]
mesh
# Setup the model
sig_back = 1e-2
sig_block = 1
sig_air = 1e-8
frequencies = np.r_[30, 45, 90, 180, 360, 720]
print("skin depths")
print(503/np.sqrt(sig_back * frequencies))
def topography(x, y, length_scale=500, height=150):
return -height*np.sin(x/length_scale) * np.exp(-(x/length_scale)**2) * np.exp(-(y/length_scale)**2)
models = {}
block_x = np.r_[-150, 150]
block_y = np.r_[-150, 150]
block_z = np.r_[-200, -350]
block_inds = (
(mesh.cell_centers[:, 0] <= block_x.max()) & (mesh.cell_centers[:, 0] >= block_x.min()) &
(mesh.cell_centers[:, 1] <= block_y.max()) & (mesh.cell_centers[:, 1] >= block_y.min()) &
(mesh.cell_centers[:, 2] <= block_z.max()) & (mesh.cell_centers[:, 2] >= block_z.min())
)
halfspace = sig_air * np.ones(mesh.n_cells)
halfspace[mesh.cell_centers[:, 2] < 0] = sig_back
models["halfspace"] = halfspace
block_in_halfspace = halfspace.copy()
block_in_halfspace[block_inds] = sig_block
models["block"] = block_in_halfspace
topo_model = sig_air * np.ones(mesh.n_cells)
topo = topography(mesh.cell_centers[:, 0], mesh.cell_centers[:,1])
topo_model[mesh.cell_centers[:, 2] <= topo] = sig_back
models["topo"] = topo_model
topo_block = topo_model.copy()
topo_block[block_inds] = sig_block
models["topo_block"] = topo_block
fig, ax = plt.subplots(1, 4, figsize=(16, 3))
xlim = 700*np.r_[-1, 1]
ylim = np.r_[-800, 150]
for i, key in enumerate(models.keys()):
out = mesh.plot_slice(
np.log10(models[key]), grid=True, normal="Y", ax=ax[i],
pcolor_opts={"vmin":np.log10(sig_air), "vmax":np.log10(sig_block)},
grid_opts={"color":"k", "lw":0.5},
)
cb = plt.colorbar(out[0], orientation="horizontal")
ax[i].set_title(key)
ax[i].set_xlim(xlim)
ax[i].set_ylim(ylim)
ax[i].set_aspect(1)
# ax.plot(mesh.cell_centers_x, topography(mesh.cell_centers_x, np.zeros_like(mesh.cell_centers_x)))
# ## create the SimPEG survey
# Setup the the survey object
# Receiver locations
rx_x = np.arange(-600, 601, 100)
rx_z = 90
rx_loc = np.vstack([discretize.utils.mkvc(x) for x in np.meshgrid(rx_x, np.r_[0], np.r_[rx_z])]).T
# Make a receiver list
rx_list = []
for rx_orientation in ["zx", "zy"]:
# specify that we are using tipper data
rx_real = nsem.Rx.Point3DTipper(rx_loc, rx_orientation, "real")
rx_imag = nsem.Rx.Point3DTipper(rx_loc, rx_orientation, "imag")
# append to the receiver list
rx_list.append(rx_real)
rx_list.append(rx_imag)
# Source list
source_list = [
nsem.sources.PlanewaveXYPrimary(rx_list, freq, sigma_primary=halfspace) for freq in frequencies
# Planewave_xy_1Dprimary(rx_list, freq, sigma_primary=halfspace) for freq in frequencies
]
# Survey MT
survey = nsem.Survey(source_list)
# Setup the problem object
sim = nsem.Simulation3DPrimarySecondary(
mesh, survey=survey, solver=Solver, sigmaMap=maps.IdentityMap(mesh), sigmaPrimary=halfspace
)
# ### plot topography and survey line
fig, ax = plt.subplots(1, 1)
out = mesh.plot_slice(topo, "CC", pcolor_opts={"cmap":"coolwarm"}, ax=ax)
lims = 1000
ax.set_xlim(lims*np.r_[-1, 1])
ax.set_ylim(lims*np.r_[-1, 1])
ax.plot(rx_x, np.zeros_like(rx_x), "ko")
ax.plot(
np.r_[block_x.min(), block_x.min(), block_x.max(), block_x.max(), block_x.min()],
np.r_[block_y.min(), block_y.max(), block_y.max(), block_y.min(), block_y.min()],
"--k"
)
ax.set_title("topography")
cb=plt.colorbar(out[0], ax=ax)
cb.set_label("elevation (m)")
# ## run the forward simulation
fields = {}
dobs = {}
for key, sig in models.items():
if key not in fields.keys():
print(f"starting {key}")
t = time.time()
fields[key] = sim.fields(sig)
dobs[key] = sim.dpred(sig, f=fields[key])
print(f"done {key}... elapsed time: {time.time()-t:1.1e}s \n")
# ### put data into a data object
data_dict = {}
for key, d in dobs.items():
data_dict[key] = data.Data(dobs=d, survey=survey)
# ## Plot the results
#
# You can change the `key` to view different results
fig, ax = plt.subplots(3, 1, height_ratios=[1, 1, 2], figsize=(6, 8))
xlim = 620*np.r_[-1, 1]
ylim= np.r_[-600, 120]
key = "topo_block"
src_ind = 4
plotme = "model"
for j, src in enumerate(source_list[::2]):
for i, rx in enumerate(rx_list[:2]):
ax[i].plot(rx_x, data_dict[key][src, rx], "-o", color=f"C{j}", label=f"{src.frequency:1.0f} Hz")
ax[i].set_title(f"T{rx.orientation}, {rx.component}")
ax[i].set_ylabel(f"T{rx.orientation}")
for a in ax[:2]:
a.grid("both", alpha=0.7)
a.set_xticklabels("")
a.set_xlim(xlim)
ax[0].legend()
if plotme=="model":
out = mesh.plot_slice(models[key], normal="Y", ax=ax[2], pcolor_opts={"norm":LogNorm(vmin=1e-6, vmax=10), "cmap":"Spectral_r"})
elif plotme=="b":
out = mesh.plot_slice(
fields[key][srcList[src_ind], plotme][:, 0].real, "F", view="vec", normal="Y", ax=ax[2],
range_x=xlim, range_y=ylim
)
elif plotme=="j":
out = mesh.plot_slice(
fields[key][srcList[src_ind], plotme][:, 0].imag, "E", view="vec", normal="Y", ax=ax[2],
range_x=xlim, range_y=ylim
)
# cb = plt.colorbar(out[0], shrink=0.4)
# cb.set_label("conductivity (S/m)")
ax[2].set_xlim(xlim)
ax[2].set_ylim(ylim)
ax[2].set_aspect(1)
ax[2].set_title("")
ax[2].plot(rx_x, np.ones_like(rx_x)*rx_z, "C9s")
ax[2].set_xlabel("x (m)")
fig, ax = plt.subplots(1, 1)
key = "topo_block"
src_ind = 4
out = mesh.plot_slice(
fields[key][source_list[src_ind], "j"][:, 0].imag, "E", view="vec", normal="Y", ax=ax,
range_x=xlim, range_y=ylim, pcolor_opts={"norm": Normalize(vmax=8e-4)},
stream_threshold=1e-5
)
plt.colorbar(out[0], ax=ax, shrink=0.5)
ax.set_title(f"J imag, {frequencies[src_ind]} Hz, XZ-slice")
ax.set_aspect(1)
fig, ax = plt.subplots(1, 1)
key = "topo_block"
src_ind = 4
subtract = "halfspace"
plotme = fields[key][source_list[src_ind], "b"][:, 0].real
if subtract is not None:
plotme = plotme - fields[subtract][source_list[src_ind], "b"][:, 0].real
out = mesh.plot_slice(
plotme, "F", view="vec", normal="X", ax=ax,
range_x=xlim, range_y=ylim, pcolor_opts={"norm": Normalize(vmin=0, vmax=2.7e-8)}, #LogNorm(vmin=3e-11, vmax=1e-7)},
stream_threshold=1e-11
)
plt.colorbar(out[0], ax=ax, shrink=0.5, pad=0.1)
ax.set_title(f"Anomalous B real, {frequencies[src_ind]} Hz, YZ slice")
ax.set_aspect(1)