def test_freq2transform(self, capsys): times = np.linspace(0.1, 10, 101) x = 900 model = { 'src': [0, 0, 0], 'rec': [x, 0, 0], 'res': 1, 'depth': [], 'verb': 1 } # Initiate Fourier instance. Fourier = time.Fourier(times, 0.001, 100) # Calculate required frequencies. data = empymod.dipole(freqtime=Fourier.freq_compute, **model) # Transform the data. tdata = Fourier.freq2time(data, x) # Calculate data in empymod. data_true = empymod.dipole(freqtime=times, signal=0, **model) # Compare. assert_allclose(data_true, tdata, rtol=1e-4)
def test_tem(): # Just ensure functionality stays the same, with one example. for i in ['6', '7', '8']: # Signal = 0, 1, -1 res = DATAFEMTEM['out'+i][()] tEM, _ = tem(**res['inp']) assert_allclose(tEM, res['EM']) # Test `xdirect=None` through analytical/dipole-comparison with a simple # model # Fullspace model inp = {'src': [[0, -100], [0, -200], 200], 'rec': [np.arange(1, 11)*500, np.arange(1, 11)*100, 300], 'freqtime': [0.1, 1, 10], 'res': 1} fEM_fs = analytical(**inp) # Add two layers inp['depth'] = [0, 500] inp['res'] = [10, 1, 30] fEM_tot1 = dipole(xdirect=False, **inp) fEM_tot2 = dipole(xdirect=True, **inp) fEM_secondary = dipole(xdirect=None, **inp) # `xdirect=False` and `xdirect=True` have to agree assert_allclose(fEM_tot2, fEM_tot1) # Total field minus minus direct field equals secondary field assert_allclose(fEM_tot1 - fEM_fs, fEM_secondary)
def test_dipole(): # As this is a subset of bipole, just run two tests to ensure # it is equivalent to bipole. # 1. Frequency src = [5000, 1000, -200] rec = [0, 0, 1200] model = {'depth': [100, 1000], 'res': [2, 0.3, 100], 'aniso': [2, .5, 2]} f = 0.01 # v dipole : ab = 26 # \> bipole : src-dip = 90, rec-azimuth=90, msrc=True dip_res = dipole(src, rec, freqtime=f, ab=26, verb=0, **model) bip_res = bipole([src[0], src[1], src[2], 0, 90], [rec[0], rec[1], rec[2], 90, 0], msrc=True, freqtime=f, verb=0, **model) assert_allclose(dip_res, bip_res) # 2. Time t = 1 dip_res = dipole(src, rec, freqtime=t, signal=1, ab=62, verb=0, **model) bip_res = bipole([src[0], src[1], src[2], 0, 90], [rec[0], rec[1], rec[2], 90, 0], msrc=True, freqtime=t, signal=1, verb=0, **model) assert_allclose(dip_res, bip_res)
def plot_coarse_model(self): """Update coarse model.""" # Calculate the f-responses for required and the calculation range. f_req = empymod.dipole(freqtime=self.freq_req, **self.model) f_calc = empymod.dipole(freqtime=self.freq_calc, **self.model) # Interpolate from calculated to required frequencies and transform. f_int = self.interpolate(f_calc) t_int = self.freq2time(f_calc, self.model['rec'][0]) # Calculate the errors. f_error = 100*abs((self.reim(f_int)-self.reim(f_req)) / self.reim(f_req)) t_error = 100*abs((t_int-self.t_base)/self.t_base) # Clear existing handles self.clear_handle(['f_int', 't_int', 'f_inti', 'f_inte', 't_inte']) # Plot frequency-domain result self.h_f_inti, = self.axs[0].plot( self.freq_req, self.reim(f_int), 'k.', ms=4) self.h_f_int, = self.axs[0].plot( self.freq_calc, self.reim(f_calc), 'C0.', ms=8) self.h_f_inte, = self.axs[2].plot(self.freq_req, f_error, 'k') # Plot time-domain result self.h_t_int, = self.axs[1].plot(self.time, t_int, 'k--') self.h_t_inte, = self.axs[3].plot(self.time, t_error, 'k') # Update legend self.print_legend()
def test_all_depths(): # Test RHS/LHS low-to-high/high-to-low src = [0, 0, 10] rec = [500, 100, 50] freq = 1 depth = np.array([-50, 0, 100, 2000]) res = [6, 1, 2, 3, 4] aniso = [6, 7, 8, 9, 10] epermH = [1.0, 1.1, 1.2, 1.3, 1.4] epermV = [1.5, 1.6, 1.7, 1.8, 1.9] mpermH = [2.0, 2.1, 2.2, 2.3, 2.4] mpermV = [2.5, 2.6, 2.7, 2.8, 2.9] # 1. Ordering as internally used: inp = { 'ab': 11, 'aniso': aniso, 'epermH': epermH, 'epermV': epermV, 'mpermH': mpermH, 'mpermV': mpermV } # LHS low-to-high (+1, ::+1) lhs_l2h = dipole(src, rec, depth, res, freq, **inp) # RHS high-to-low (-1, ::+1) rhs_h2l = dipole([src[0], src[1], -src[2]], [rec[0], rec[1], -rec[2]], -depth, res, freq, **inp) # 2. Reversed ordering: inp_r = { 'ab': 11, 'aniso': aniso[::-1], 'epermH': epermH[::-1], 'epermV': epermV[::-1], 'mpermH': mpermH[::-1], 'mpermV': mpermV[::-1] } # LHS high-to-low (+1, ::-1) lhs_h2l = dipole(src, rec, depth[::-1], res[::-1], freq, **inp_r) # RHS low-to-high (-1, ::-1) rhs_l2h = dipole([src[0], src[1], -src[2]], [rec[0], rec[1], -rec[2]], -depth[::-1], res[::-1], freq, **inp_r) assert_allclose(lhs_l2h, lhs_h2l) assert_allclose(lhs_l2h, rhs_l2h) assert_allclose(lhs_l2h, rhs_h2l)
def test_dipole(): # As this is a subset of bipole, just run two tests to ensure # it is equivalent to bipole. # 1. Frequency src = [5000, 1000, -200] rec = [0, 0, 1200] model = {'depth': [100, 1000], 'res': [2, 0.3, 100], 'aniso': [2, .5, 2]} f = 0.01 # v dipole : ab = 26 # \> bipole : src-dip = 90, rec-azimuth=90, msrc=True dip_res = dipole(src, rec, freqtime=f, ab=26, verb=0, **model) bip_res = bipole([src[0], src[1], src[2], 0, 90], [rec[0], rec[1], rec[2], 90, 0], msrc=True, freqtime=f, verb=0, **model) assert_allclose(dip_res, bip_res) # 2. Time t = 1 dip_res = dipole(src, rec, freqtime=t, signal=1, ab=62, verb=0, **model) bip_res = bipole([src[0], src[1], src[2], 0, 90], [rec[0], rec[1], rec[2], 90, 0], msrc=True, freqtime=t, signal=1, verb=0, **model) assert_allclose(dip_res, bip_res) # 3. Check user-hook for eta/zeta def func_eta(inp, pdict): # Dummy function to check if it works. etaH = pdict['etaH'].real*inp['fact'] + 1j*pdict['etaH'].imag etaV = pdict['etaV'].real*inp['fact'] + 1j*pdict['etaV'].imag return etaH, etaV def func_zeta(inp, pdict): # Dummy function to check if it works. etaH = pdict['zetaH']/inp['fact'] etaV = pdict['zetaV']/inp['fact'] return etaH, etaV model = {'src': [0, 0, 500], 'rec': [500, 0, 600], 'depth': [0, 550], 'freqtime': [0.1, 1, 10]} res = np.array([2, 10, 5]) fact = np.array([2, 2, 2]) eta = {'res': fact*res, 'fact': fact, 'func_eta': func_eta} zeta = {'res': res, 'fact': fact, 'func_zeta': func_zeta} # Frequency domain standard = dipole(res=res, **model) outeta = dipole(res=eta, **model) assert_allclose(standard, outeta) outzeta = dipole(res=zeta, mpermH=fact, mpermV=fact, **model) assert_allclose(standard, outzeta) # Time domain standard = dipole(res=res, signal=0, **model) outeta = dipole(res=eta, signal=0, **model) assert_allclose(standard, outeta) outzeta = dipole(res=zeta, signal=0, mpermH=fact, mpermV=fact, **model) assert_allclose(standard, outzeta)
def test_intracasing_segment(self): print( 'VEB_Ez, Gij, and dipole agree for distant segments within one casing' ) zi = 52.5 zj = 1352.5 segment_length = 5 zj1 = zj - segment_length / 2 zj2 = zj + segment_length / 2 gij = chs.Gij(zi, zj, segment_length, frequency=freq, background_conductivity=con, outer_radius=outer_radius, inner_radius=inner_radius) gij = np.conj(gij) epm_gij = dipole([0, 0, zj], [.01, 0, zi], depth=[0], res=[3e14, 1 / con], freqtime=freq, ab=33, ht='quad', verb=0) * casing_area * segment_length veb_gij = chs.VEB_Ez(0, 0, zi, xp=0, yp=0, zp1=zj1, zp2=zj2, conductivity=con, frequency=freq) * casing_area self.assertTrue(np.isclose(gij, epm_gij, rtol=1e-4, atol=1e-20)) self.assertTrue(np.isclose(gij, veb_gij, rtol=1e-4, atol=1e-20))
def test_regres(): # Comparison to self (regression test) # 1836 cases; f = [0.01, 1, 100] Hz.; 18 models, 34 ab's, f altern. dat = REGRES['res'][()] for _, val in dat.items(): res = dipole(**val[0]) assert_allclose(res, val[1], 3e-2, 1e-17, True)
def plot_base_model(self): """Update smooth, 'correct' model.""" # Calculate responses self.f_dense = empymod.dipole(freqtime=self.freq_dense, **self.model) self.t_base = empymod.dipole( freqtime=self.time, signal=self.signal, **self.model) # Clear existing handles self.clear_handle(['f_base', 't_base']) # Plot new result self.h_f_base, = self.axs[0].plot( self.freq_dense, self.reim(self.f_dense), 'C3') self.h_t_base, = self.axs[1].plot(self.time, self.t_base, 'C3') self.adjust_lim()
def test_analytical(): # 1. fullspace model = {'src': [500, -100, -200], 'rec': [0, 1000, 200], 'res': 6.71, 'aniso': 1.2, 'freqtime': 40, 'ab': 42, 'verb': 0} dip_res = dipole(depth=[], **model) ana_res = analytical(**model) assert_allclose(dip_res, ana_res) # \= Check 36/63 model['ab'] = 63 ana_res2 = analytical(**model) assert_allclose(ana_res.shape, ana_res.shape) assert np.count_nonzero(ana_res2) == 0 # 2. halfspace for signal in [0, 1]: # Frequency, Time model = {'src': [500, -100, 5], 'rec': [0, 1000, 20], 'res': 6.71, 'aniso': 1.2, 'freqtime': 1, 'signal': signal, 'ab': 12, 'verb': 0} # Check dhs, dsplit, and dtetm ana_res = analytical(solution='dhs', **model) res1, res2, res3 = analytical(solution='dsplit', **model) dTE, dTM, rTE, rTM, air = analytical(solution='dtetm', **model) model['res'] = [2e14, model['res']] model['aniso'] = [1, model['aniso']] dip_res = dipole(depth=0, **model) # Check dhs, dsplit assert_allclose(dip_res, ana_res, rtol=1e-3) assert_allclose(ana_res, res1+res2+res3) # Check dsplit and dtetm assert_allclose(res1, dTE+dTM) assert_allclose(res2, rTE+rTM) assert_allclose(res3, air)
def test_HED_Ez(self): print('HED_Ez and dipole agree') epm_hed = dipole([0, 0, 1e-2], [1, 0, 100], depth=[0], res=[3e14, 1 / con], freqtime=freq, ab=31, epermH=[0, 1], epermV=[0, 1], verb=0) chs_hed = chs.HED_Ez(1, 0, 100, 0, 0, conductivity=con, frequency=freq) self.assertTrue(np.isclose(epm_hed, chs_hed, atol=1e-20))
def test_analytical(): # 1. fullspace model = { 'src': [500, -100, -200], 'rec': [0, 1000, 200], 'res': 6.71, 'aniso': 1.2, 'freqtime': 40, 'ab': 42, 'verb': 0 } dip_res = dipole(depth=[], **model) ana_res = analytical(**model) assert_allclose(dip_res, ana_res) # 2. halfspace model = { 'src': [500, -100, 5], 'rec': [0, 1000, 20], 'res': 6.71, 'aniso': 1.2, 'freqtime': 10, 'signal': 1, 'ab': 12, 'verb': 0 } # Check dhs, dsplit, and dtetm ana_res = analytical(solution='dhs', **model) res1, res2, res3 = analytical(solution='dsplit', **model) dTE, dTM, rTE, rTM, air = analytical(solution='dtetm', **model) model['res'] = [2e14, model['res']] model['aniso'] = [1, model['aniso']] dip_res = dipole(depth=0, **model) # Check dhs, dsplit assert_allclose(dip_res, ana_res, rtol=1e-4) assert_allclose(ana_res, res1 + res2 + res3) # Check dsplit and dtetm assert_allclose(res1, dTE + dTM) assert_allclose(res2, rTE + rTM) assert_allclose(res3, air)
def test_interpolation(self, capsys): times = np.logspace(-2, 1, 201) model = { 'src': [0, 0, 0], 'rec': [900, 0, 0], 'res': 1, 'depth': [], 'verb': 1 } Fourier = time.Fourier(times, 0.005, 10) # Calculate data. data_true = empymod.dipole(freqtime=Fourier.freq_required, **model) data = empymod.dipole(freqtime=Fourier.freq_compute, **model) # Interpolate. data_int = Fourier.interpolate(data) # Compare, extrapolate < 0.05; interpolate equal. assert_allclose(data_int[Fourier.ifreq_extrapolate].imag, data_true[Fourier.ifreq_extrapolate].imag, rtol=0.05) assert_allclose(data_int[Fourier.ifreq_compute].imag, data_true[Fourier.ifreq_compute].imag) # Now set every_x_freq and again. Fourier.every_x_freq = 2 data = empymod.dipole(freqtime=Fourier.freq_compute, **model) # Interpolate. data_int = Fourier.interpolate(data) # Compare, extrapolate < 0.05; interpolate < 0.01. assert_allclose(data_int[Fourier.ifreq_extrapolate].imag, data_true[Fourier.ifreq_extrapolate].imag, rtol=0.05) assert_allclose(data_int[Fourier.ifreq_interpolate].imag, data_true[Fourier.ifreq_interpolate].imag, rtol=0.01)
def test_dipole(): for lay in [0, 1, 5]: # Src/rec in first, second, and last layer for f in freq: # One freq at a time src = [0, 0, depth[lay + 1] - 50] # Offset depending on frequency if f < 1: rec = [10000, 0, depth[lay + 1] - 10] elif f > 10: rec = [2, 0, depth[lay + 1] - 10] else: rec = [1000, 0, depth[lay + 1] - 10] inp = { 'src': src, 'rec': rec, 'depth': depth[1:-1], 'res': res, 'freqtime': f, 'aniso': aniso, 'verb': 0 } # empymod-version out = dipole(epermH=eperm, epermV=eperm, mpermH=mperm, mpermV=mperm, xdirect=False, **inp) # empymod.scripts-version TM, TE = tmtemod.dipole(eperm=eperm, mperm=mperm, **inp) TM = TM[0] + TM[1] + TM[2] + TM[3] + TM[4] TE = TE[0] + TE[1] + TE[2] + TE[3] + TE[4] # Check assert_allclose(out, TM + TE, rtol=1e-5, atol=1e-50) # Check the 3 errors with pytest.raises(ValueError): # scr/rec not in same layer tmtemod.dipole([0, 0, 90], [4000, 0, 180], depth[1:-1], res, 1) with pytest.raises(ValueError): # more than one frequency tmtemod.dipole([0, 0, 90], [4000, 0, 110], depth[1:-1], res, [1, 10]) with pytest.raises(ValueError): # only one layer tmtemod.dipole([0, 0, 90], [4000, 0, 110], [], 10, 1)
def plotresult(depth, res, zsrc, zrec): x = np.arange(1, 101) * 200 inp = { 'src': [0, 0, depth[1] - zsrc], 'rec': [x, x * 0, depth[1] - zrec], 'depth': depth, 'res': res, 'ab': 11, 'freqtime': 1, 'verb': 1, } kong241 = empymod.dipole(htarg={'dlf': 'kong_241_2007'}, **inp) key201 = empymod.dipole(htarg={'dlf': 'key_201_2012'}, **inp) and801 = empymod.dipole(htarg={'dlf': 'anderson_801_1982'}, **inp) test = empymod.dipole(htarg={'dlf': filt}, **inp) wer201 = empymod.dipole(htarg={'dlf': 'wer_201_2018'}, **inp) qwe = empymod.dipole(ht='qwe', **inp) plt.figure(figsize=(8, 3.5)) plt.subplot(121) plt.semilogy(x, qwe.amp(), c='0.5', label='QWE') plt.semilogy(x, kong241.amp(), 'k--', label='Kong241') plt.semilogy(x, key201.amp(), 'k:', label='Key201') plt.semilogy(x, and801.amp(), 'k-.', label='And801') plt.semilogy(x, test.amp(), 'r', label='This filter') plt.semilogy(x, wer201.amp(), 'b', label='Wer201') plt.legend() plt.xticks([0, 5e3, 10e3, 15e3, 20e3]) plt.xlim([0, 20e3]) plt.subplot(122) plt.semilogy(x, np.abs((kong241 - qwe) / qwe), 'k--', label='Kong241') plt.semilogy(x, np.abs((key201 - qwe) / qwe), 'k:', label='Key201') plt.semilogy(x, np.abs((and801 - qwe) / qwe), 'k-.', label='And801') plt.semilogy(x, np.abs((test - qwe) / qwe), 'r', label='This filter') plt.semilogy(x, np.abs((wer201 - qwe) / qwe), 'b', label='Wer201') plt.legend() plt.xticks([0, 5e3, 10e3, 15e3, 20e3]) plt.xlim([0, 20e3]) plt.ylim([1e-14, 1]) plt.show()
'depth': [], # Homogenous space 'res': 3, # 3 Ohm.m 'ab': 11, # Ex-source, Ex-receiver} } # Single offset and offsets offs = np.linspace(1000, 15000, 201) off = 5000 # Single frequency and frequencies freqs = np.logspace(-3, 2, 201) freq = 1 # Responses oresp = empymod.dipole( rec=(offs, offs * 0, 0), # Inline receivers freqtime=freq, **model) fresp = empymod.dipole( rec=(5000, 0, 0), # Inline receiver freqtime=freqs, **model, ) # Relative error, noise floor, mean of noise rel_error = 0.05 noise_floor = 1e-15 n_stack = 1000 # Phase settings: wrapped, radians, lag-defined (+iw) phase = {'unwrap': False, 'deg': False, 'lag': True}
inp3 = { 'src': [0, 0, 900], 'rec': [x, np.zeros(x.shape), 1000], 'depth': [0, 1000, 2000, 2100], 'res': [2e14, 0.3, 1, 100, 1], 'freqtime': 1, 'verb': 1 } # HS model inp4 = dc(inp3) inp4['depth'] = inp3['depth'][:2] inp4['res'] = inp3['res'][:3] # Compute radial responses rhs = empymod.dipole(**inp4) # Step, HS rhs = empymod.utils.EMArray(np.nan_to_num(rhs)) rtg = empymod.dipole(**inp3) # " " Target rtg = empymod.utils.EMArray(np.nan_to_num(rtg)) # Compute azimuthal response ahs = empymod.dipole(**inp4, ab=22) # Step, HS ahs = empymod.utils.EMArray(np.nan_to_num(ahs)) atg = empymod.dipole(**inp3, ab=22) # " " Target atg = empymod.utils.EMArray(np.nan_to_num(atg)) ############################################################################### # Plot # ---- plt.figure(figsize=(9, 13))
def plot_t(EM, HS, title, i): plt.figure(title, figsize=(10, 8)) plt.subplot(i) plt.semilogx(t, EM) plt.semilogx(t, HS, '--') ############################################################################### # Impulse HS plt.figure('Impulse HS') i = 330 for ab in all_abs: i += 1 EM = empymod.dipole(**inpEM, **modHS, ab=ab, signal=0, depth=0) HS = empymod.analytical(**inpEM, **modFS, solution='dhs', ab=ab, signal=0) plot_t(EM, HS, 'Impulse HS', i) plt.suptitle('Impulse HS') plt.show() ############################################################################### # Switch-on HS plt.figure('Switch-on HS') i = 330 for ab in all_abs: i += 1 EM = empymod.dipole(**inpEM, **modHS, ab=ab, signal=1, depth=0) HS = empymod.analytical(**inpEM, **modFS, solution='dhs', ab=ab, signal=1) plot_t(EM, HS, 'Switch-on HS', i)
def test_analytical(): # 1. fullspace model = {'src': [500, -100, -200], 'rec': [0, 1000, 200], 'res': 6.71, 'aniso': 1.2, 'freqtime': 40, 'ab': 42, 'verb': 0} dip_res = dipole(depth=[], **model) ana_res = analytical(**model) assert_allclose(dip_res, ana_res) # \= Check 36/63 model['ab'] = 63 ana_res2 = analytical(**model) assert_allclose(ana_res.shape, ana_res.shape) assert np.count_nonzero(ana_res2) == 0 # 2. halfspace for signal in [None, 0, 1]: # Frequency, Time model = {'src': [500, -100, 5], 'rec': [0, 1000, 20], 'res': 6.71, 'aniso': 1.2, 'freqtime': 1, 'signal': signal, 'ab': 12, 'verb': 0} # Check dhs, dsplit, and dtetm ana_res = analytical(solution='dhs', **model) res1, res2, res3 = analytical(solution='dsplit', **model) dTE, dTM, rTE, rTM, air = analytical(solution='dtetm', **model) model['res'] = [2e14, model['res']] model['aniso'] = [1, model['aniso']] dip_res = dipole(depth=0, **model) # Check dhs, dsplit assert_allclose(dip_res, ana_res, rtol=1e-3) assert_allclose(ana_res, res1+res2+res3) # Check dsplit and dtetm assert_allclose(res1, dTE+dTM) assert_allclose(res2, rTE+rTM) assert_allclose(res3, air) # As above, but Laplace domain. model = {'src': [500, -100, 5], 'rec': [0, 1000, 20], 'res': 6.71, 'aniso': 1.2, 'freqtime': -1, 'signal': None, 'ab': 12, 'verb': 0} # Check dhs, dsplit, and dtetm ana_res = analytical(solution='dhs', **model) res1, res2, res3 = analytical(solution='dsplit', **model) dTE, dTM, rTE, rTM, air = analytical(solution='dtetm', **model) model['res'] = [2e14, model['res']] model['aniso'] = [1, model['aniso']] dip_res = dipole(depth=0, **model) # Check dhs, dsplit assert_allclose(dip_res, ana_res, rtol=1e-3) assert_allclose(ana_res, res1+res2+res3) # Check dsplit and dtetm assert_allclose(res1, dTE+dTM) assert_allclose(res2, rTE+rTM) assert_allclose(res3, air) # 3. Check user-hook for eta/zeta def func_eta(inp, pdict): # Dummy function to check if it works. etaH = pdict['etaH'].real*inp['fact'] + 1j*pdict['etaH'].imag etaV = pdict['etaV'].real*inp['fact'] + 1j*pdict['etaV'].imag return etaH, etaV def func_zeta(inp, pdict): # Dummy function to check if it works. etaH = pdict['zetaH']/inp['fact'] etaV = pdict['zetaV']/inp['fact'] return etaH, etaV model = {'src': [0, 0, 500], 'rec': [500, 0, 600], 'freqtime': [0.1, 1, 10]} res = 10 fact = 2 eta = {'res': fact*res, 'fact': fact, 'func_eta': func_eta} zeta = {'res': res, 'fact': fact, 'func_zeta': func_zeta} # Frequency domain fs standard = analytical(res=res, **model) outeta = analytical(res=eta, **model) assert_allclose(standard, outeta) outzeta = analytical(res=zeta, mpermH=fact, mpermV=fact, **model) assert_allclose(standard, outzeta) # Time domain dhs standard = analytical(res=res, solution='dhs', signal=0, **model) outeta = analytical(res=eta, solution='dhs', signal=0, **model) assert_allclose(standard, outeta) outzeta = analytical(res=zeta, solution='dhs', signal=0, mpermH=fact, mpermV=fact, **model) assert_allclose(standard, outzeta)
'res': [2e14, 10, 100, 10], # Res: [air, overb., target, half-space] 'epermH': [1, 1, 1, 1], # El. permittivity: default values 'freqtime': t, # Times 'signal': 0, # 0: Impulse response 'ftarg': { 'dlf': 'key_81_CosSin_2009' }, # Shorter filter then the default 'verb': 1, # Verbosity; set to 3 to see all parameters } ############################################################################### # Compute # ------- # Compute with default eperm_air = 1 res_1 = empymod.dipole(**model) # Set horizontal and vertical electric permittivity of air to 0 model['epermH'][0] = 0 # Note that for empymod < v2.0.0 you have to set `epermH` AND `epermV`. From # v2.0.0 onwards `eperm` is assumed isotropic if `epermV` is not provided, and # `epermV` is therefore internally a copy of `epermH`. # Compute with eperm_air = 0 res_0 = empymod.dipole(**model) ############################################################################### # Plot result # ----------- # # As it can be seen, setting :math:`\varepsilon_{air} =` 0 improves the land
np.repeat(y * scl, 7), (depth[rr] + dfrec[dfsw]) * scl ] # Get model-name modname = str(ab) + '_' + str(freq) + '_' + str(sr) + str(rr) # Run model inp = { 'src': isrc, 'rec': irec, 'depth': depth[:-1] * scl, 'res': ires, 'aniso': ianiso, 'freqtime': ifreq, 'ab': ab, 'opt': 'parallel', 'epermH': iepermH, 'epermV': iepermV, 'mpermH': impermH, 'mpermV': impermV, 'verb': 0, 'xdirect': True } em = dipole(**inp) # Store input and result out[modname] = (inp, em) # Store data np.savez_compressed('../data/regression.npz', res=out)
# ---------------------------------- # # Calculate # ~~~~~~~~~ inpdat = { 'src': [0, 0, zsrc], 'rec': [fx, fy, zrec], 'depth': depth, 'freqtime': 1, 'aniso': aniso, 'ab': ab, 'verb': verb } fEM = empymod.dipole(**inpdat, res=res) fEMBG = empymod.dipole(**inpdat, res=resBG) ############################################################################### # Plot # ~~~~ fig = plt.figure(figsize=(8, 6), facecolor='w') fig.subplots_adjust(wspace=.25, hspace=.4) fig.suptitle(name + ': src-x, rec-x; f = 1 Hz', fontsize=16, y=1) # Plot Amplitude ax1 = plt.subplot(2, 2, 1) plt.semilogy(fx / 1000, fEMBG.amp, label='BG') plt.semilogy(fx / 1000, fEM.amp, label='Anomaly') plt.legend(loc='best')
rhs = [2e14, 1 / 3, 1, 1, 1] # Half-space # Common model parameters (deep sea parameters) model = { 'src': [0, 0, 975], # Source location 'rec': [x, x * 0, 1000], # Receiver location 'depth': [0, 1000, 2000, 2040], # 1 km water, target 40 m thick 1 km below 'freqtime': 0.5, # Frequencies 'verb': 1, # Verbosity } ############################################################################### # Calculation # ----------- target = empymod.dipole(res=rtg, **model) tgTM, tgTE = empymod.tmtemod.dipole(res=rtg, **model) # Without reservoir notarg = empymod.dipole(res=rhs, **model) ntTM, ntTE = empymod.tmtemod.dipole(res=rhs, **model) ############################################################################### # Figure 1 # ~~~~~~~~ # # Plot all reflected contributions (without direct field), for the models with # and without a reservoir. plt.figure(figsize=(10, 4))
'aniso': aniso, 'epermH': eperm, 'epermV': eperm, 'ht': 'fht', 'verb': 2 } ############################################################################### # Impulse response # ~~~~~~~~~~~~~~~~ ex = ee_xx_impulse(res[1], aniso[1], rec[0], t) inparg['signal'] = 0 # signal 0 = impulse print('QWE') qwe = empymod.dipole(**inparg, ft='qwe') print('FHT (Sine)') sin = empymod.dipole(**inparg, ft='sin', ftarg='key_81_CosSin_2009') print('FFTLog') ftl = empymod.dipole(**inparg, ft='fftlog') print('FFT') fft = empymod.dipole(**inparg, ft='fft', ftarg=[.0005, 2**20, '', 10]) ############################################################################### # => `FFTLog` is the fastest by quite a margin, followed by the `Sine`-filter. # What cannot see from the output (set `verb` to something bigger than 2 to see # it) is how many frequencies each method used: # # - QWE: 159 (0.000794328 - 63095.7 Hz) # - Sine: 116 (5.33905E-06 - 52028 Hz) # - FFTLog: 60 (0.000178575 - 141.847 Hz)
epm_loop = empymod.loop(src=[0, 0, 0, 0, 90], rec=[rxx, ryy, 10, 0, 0], **model).reshape(np.shape(rx)) ############################################################################### # 2.1 Point dipoles at (x, y) using ``empymod.dipole`` # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # - (0.5, 0), ab=42 # - (0, 0.5), ab=41 # - (-0.5, 0), ab=-42 # - (0, -0.5), ab=-41 # rec_dip = [rxx, ryy, 10] square_pts = +empymod.dipole(src=[+0.5, +0.0, 0], rec=rec_dip, ab=42, **model).reshape(np.shape(rx)) square_pts += empymod.dipole(src=[+0.0, +0.5, 0], rec=rec_dip, ab=41, **model).reshape(np.shape(rx)) square_pts -= empymod.dipole(src=[-0.5, +0.0, 0], rec=rec_dip, ab=42, **model).reshape(np.shape(rx)) square_pts -= empymod.dipole(src=[+0.0, -0.5, 0], rec=rec_dip, ab=41, **model).reshape(np.shape(rx)) plot_result(epm_loop, square_pts, x, 'Loop made of four points', vmin=-13, vmax=-5, rx=x) ############################################################################### # 2.2 Finite length dipoles using ``empymod.bipole`` # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # Each simulated with a 5pt Gaussian quadrature. The dipoles are:
off = np.linspace(500, 10000, 301) ############################################################################### # LHS # ``` # # In the left-handed system positive :math:`z` is downwards. So we have to # define our model by beginning with the air layer, followed by water, # background, target, and background again. This means that all our # depth-values are positive, as the air-interface :math:`z_0` is at 0 m. lhs = empymod.dipole( src=[0, 0, 100], rec=[off, np.zeros(off.size), 200], depth=[0, 300, 1000, 1050], res=[1e20, 0.3, 1, 50, 1], # depth=[1050, 1000, 300, 0], # Alternative way, LHS high to low. # res=[1, 50, 1, 0.3, 1e20], # " " " freqtime=1, verb=0) ############################################################################### # RHS # ``` # # In the right-handed system positive :math:`z` is upwards. So we have to # define our model by beginning with the background, followed by the target, # background again, water, and air. This means that all our depth-values are # negative. rhs = empymod.dipole(
x, ], np.size(y), axis=0) ry = np.repeat([ y, ], np.size(x), axis=0) ry = ry.transpose() # Compute the electric field efield = empymod.dipole( src=[0, 0, 150], rec=[rx.ravel(), ry.ravel(), 200], depth=[0, 200, 1000, 1200], res=[2e14, 1 / 3, 1, 50, 1], aniso=[1, 1, np.sqrt(10), 1, 1], freqtime=0.5, epermH=[1, 80, 17, 2.1, 17], epermV=[1, 80, 17, 2.1, 17], mpermH=[1, 1, 1, 1, 1], mpermV=[1, 1, 1, 1, 1], ab=11, htarg={ 'pts_per_dec': -1 }, ).reshape(np.shape(rx)) ############################################################################### # Plot # ---- # Create a similar colormap as Hunziker et al., 2015. cmap = plt.cm.get_cmap("jet", 61)
def test_coordinate_systems(): srcLHS = (0, 0, -10) srcRHS = (0, 0, +10) x = np.arange(1, 11) * 1000 recLHS = (x, x, +3) recRHS = (x, x, -3) air, hs, tg = 2e14, 100, 1000 z0, z1, z2 = 0, 10, 20 inp = {'freqtime': 1, 'verb': 1} inpLHS = {'src': srcLHS, 'rec': recLHS} inpRHS = {'src': srcRHS, 'rec': recRHS} for ab in [11, 31, 23, 33, 25, 35, 16, 66, 51, 61, 43, 63, 44, 65, 56, 66]: # Sign switches occur for each z-component; each m-component sign = 1 if ab % 10 > 3: # If True: magnetic src sign *= -1 if ab // 10 > 3: # If True: magnetic rec sign *= -1 if str(ab)[0] in ['3', '6']: # Vertical source component sign *= -1 if str(ab)[1] in ['3', '6']: # Vertical receiver component sign *= -1 inp['ab'] = ab # # 2-layer case # Default/original: LHS low to high orig = dipole(depth=z0, res=[air, hs], **inpLHS, **inp) # Alternatives LHS: low to high and high to low LHSl2h = dipole(depth=[z0, np.infty], res=[air, hs], **inpLHS, **inp) LHSh2l = dipole(depth=[np.infty, z0], res=[hs, air], **inpLHS, **inp) assert_allclose(orig, LHSl2h) assert_allclose(orig, LHSh2l) # Alternatives LHS: low to high and high to low RHSlth = sign * dipole( depth=[-np.infty, -z0], res=[hs, air], **inpRHS, **inp) RHSh2l = sign * dipole( depth=[-z0, -np.infty], res=[air, hs], **inpRHS, **inp) assert_allclose(orig, RHSlth) assert_allclose(orig, RHSh2l) # # 4-layer case # Default/original: LHS low to high orig = dipole(depth=[z0, z1, z2], res=[air, hs, tg, hs], **inpLHS, **inp) # Alternatives LHS: low to high and high to low LHSh2l = dipole(depth=[z2, z1, z0], res=[hs, tg, hs, air], **inpLHS, **inp) assert_allclose(orig, LHSh2l) # Alternatives LHS: low to high and high to low RHSlth = sign * dipole( depth=[-z2, -z1, -z0], res=[hs, tg, hs, air], **inpRHS, **inp) RHSh2l = sign * dipole( depth=[-z0, -z1, -z2], res=[air, hs, tg, hs], **inpRHS, **inp) assert_allclose(orig, RHSlth) assert_allclose(orig, RHSh2l)
# Calculate analytical solution resp = empymod.analytical(params['src'], params['rec'], params['res'][1], params['freqtime'], solution='dhs', aniso=params['aniso'][1], ab=params['ab'], verb=params['verb']) ############################################################################### # Calculate numerically the model using different Hankel options # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ standard = empymod.dipole(**params, htarg=[hfilt, 0]) laggedco = empymod.dipole(**params, htarg=[hfilt, -1]) spline10 = empymod.dipole(**params, htarg=[hfilt, 10]) spline30 = empymod.dipole(**params, htarg=[hfilt, 30]) splin100 = empymod.dipole(**params, htarg=[hfilt, 100]) ############################################################################### # Results # ~~~~~~~ plt.figure(figsize=(10, 4)) plt.suptitle('Hankel transform example; frequency = ' + str(params['freqtime']) + ' Hz', y=1.05, fontsize=15)
inp2 = { 'src': [0, 0, 0.001], 'rec': [1000, 0, 0.001], 'depth': [0, 500, 525], 'res': [2e14, 20, 500, 20], 'freqtime': t, 'verb': 1 } # HS model inp1 = dc(inp2) inp1['depth'] = inp2['depth'][0] inp1['res'] = inp2['res'][:2] # Calculate responses sths = empymod.dipole(**inp1, signal=1) # Step, HS sttg = empymod.dipole(**inp2, signal=1) # " " Target imhs = empymod.dipole(**inp1, signal=0, ft='fftlog') # Impulse, HS imtg = empymod.dipole(**inp2, signal=0, ft='fftlog') # " " Target ############################################################################### # Plot # ~~~~ plt.figure(figsize=(9, 4)) plt.subplots_adjust(wspace=.3) # Step response plt.subplot(121) plt.title('(a)') plt.plot(np.r_[0, 0, t],