mirror of
https://github.com/wassname/simpegSeis.git
synced 2026-09-09 11:34:31 +08:00
763 KiB
763 KiB
In [1]:
# add simpegseisc directory to path
import os
if '..' not in os.sys.path:
os.sys.path.append('..')In [2]:
from simpegseis import *
%pylab inline
from SimPEG.Utils import mkvcPopulating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['linalg'] `%matplotlib` prevents importing * from pylab and numpy
In [11]:
# Step1: set time
dt = 0.8e-4
ntime = 1700
time = np.arange(ntime)*dt
# Step4: set mesh
cs = 0.5
cs = 0.5
hx = np.ones(500.)*cs
hy = np.ones(200.)*cs
mesh = Mesh.TensorMesh([hx, hy], 'CC')
# Step2: set Tx and Rx
tlag = 0.008
options={'tlag':tlag, 'fmain':100.} # You need to set waveform to set Tx
nrx = 99
xtemp_rx = np.arange(nrx)*2.5+2.5+mesh.vectorCCx.min()
xy_rx = np.c_[xtemp_rx, np.ones(nrx)*mesh.vectorCCy.max()]
rx = AcousticRx(xy_rx)
tx = AcousticSrc(np.r_[mesh.vectorCCx.min(), mesh.vectorCCy.max()], time, [rx], **options)
# Step3: set survey (pass txlist)
survey = SurveyAcoustic([tx])
wave = tx.RickerWavelet()
# Step5: set problem (pass mesh) and pair with survey
prob = AcousticProblemPML(mesh)
prob.pair(survey)
# Step6: set boundary
prob.setPMLBC(20, dt, bcflag='left', const=1.)
prob.storefield = True
# Step7: set velocity model and check stability
v = np.ones(mesh.nC)*1500.
v[mesh.gridCC[:,1]<30.] = 800.
v[mesh.gridCC[:,1]<0.] = 2300.
prob.stabilitycheck(v, time, 100.)You are good to go:) >> Stability information dt: 8.00e-05 s Optimal dt: 1.09e-04 s Cell per wavelength (G): 1.60e+01 Optimal G: 1.60e+01
In [12]:
mesh.plotImage(v)Out [12]:
(<matplotlib.collections.QuadMesh at 0x7fc0bee43090>,)
In [13]:
plt.plot(time, wave)Out [13]:
[<matplotlib.lines.Line2D at 0x7fc0bedaf850>]
In [14]:
# Step8: run forward
U = prob.fields(v)>> Start Computing Acoustic Wave >> dt: 8.00e-05 s >> Optimal dt: 1.09e-04 s >> Main frequency, fmain: 1.00e+02 Hz >> Cell per wavelength (G): 1.60e+01 Src at (-124.75, -124.75): 1/ 1 >>Elapsed time: 4.37e+01 s
In [15]:
# Step9: project data
data = survey.projectFields(U)In [16]:
print 50./1500.0.0333333333333
In [17]:
icount = 1699
fig, ax = plt.subplots(1,1, figsize = (8, 5))
extent = [mesh.vectorCCx.min(), mesh.vectorCCx.max(), mesh.vectorCCy.min()-mesh.vectorCCy.max(), mesh.vectorCCy.max()-mesh.vectorCCy.max()]
ax.imshow(np.flipud(U[0][:,icount].reshape((mesh.nCx, mesh.nCy), order = 'F').T), cmap = 'binary', extent=extent)
ax.imshow(np.flipud(v.reshape((mesh.nCx, mesh.nCy), order = 'F').T), cmap = 'jet', extent=extent, alpha = 0.2) Out [17]:
<matplotlib.image.AxesImage at 0x7fc0bed48810>
In [18]:
print data[0].shape(99, 1700)
In [28]:
from JSAnimation import IPython_display
from matplotlib import animation
fig, ax = plt.subplots(1,1, figsize = (8, 8))
ax.set_xlabel('Easting (m)', fontsize = 16)
ax.set_ylabel('Depth (m)', fontsize = 16)
extent = [mesh.vectorCCx.min(), mesh.vectorCCx.max(), mesh.vectorCCy.min()-mesh.vectorCCy.max(), mesh.vectorCCy.max()-mesh.vectorCCy.max()]
ax.set_xlim(extent[:2])
ax.set_ylim(extent[2:])
nskip = 79
def animate(i_id):
icount = i_id*nskip
frame = ax.imshow(np.flipud(U[0][:,icount].reshape((mesh.nCx, mesh.nCy), order = 'F').T), cmap = 'binary', extent=extent)
ax.imshow(np.flipud(v.reshape((mesh.nCx, mesh.nCy), order = 'F').T), cmap = 'jet', extent=extent, alpha = 0.2)
return frame
anim = animation.FuncAnimation(fig, animate, frames=20, interval=40, blit=True)[1;31m---------------------------------------------------------------------------[0m
[1;31mNameError[0m Traceback (most recent call last)
[1;32m<ipython-input-28-894a9449f93f>[0m in [0;36m<module>[1;34m()[0m
[0;32m 21[0m [1;32mreturn[0m [0mframe[0m[1;33m[0m[0m
[0;32m 22[0m [1;33m[0m[0m
[1;32m---> 23[1;33m [0manim[0m [1;33m=[0m [0manimation[0m[1;33m.[0m[0mFuncAnimation[0m[1;33m([0m[0mfig[0m[1;33m,[0m [0manimate[0m[1;33m,[0m [0minit_func[0m[1;33m=[0m[0minit[0m[1;33m,[0m [0mframes[0m[1;33m=[0m[1;36m20[0m[1;33m,[0m [0minterval[0m[1;33m=[0m[1;36m40[0m[1;33m,[0m [0mblit[0m[1;33m=[0m[0mTrue[0m[1;33m)[0m[1;33m[0m[0m
[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m__init__[1;34m(self, fig, func, frames, init_func, fargs, save_count, **kwargs)[0m
[0;32m 1163[0m [0mself[0m[1;33m.[0m[0m_save_seq[0m [1;33m=[0m [1;33m[[0m[1;33m][0m[1;33m[0m[0m
[0;32m 1164[0m [1;33m[0m[0m
[1;32m-> 1165[1;33m [0mTimedAnimation[0m[1;33m.[0m[0m__init__[0m[1;33m([0m[0mself[0m[1;33m,[0m [0mfig[0m[1;33m,[0m [1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 1166[0m [1;33m[0m[0m
[0;32m 1167[0m [1;31m# Need to reset the saved seq, since right now it will contain data[0m[1;33m[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m__init__[1;34m(self, fig, interval, repeat_delay, repeat, event_source, *args, **kwargs)[0m
[0;32m 1007[0m [1;33m[0m[0m
[0;32m 1008[0m Animation.__init__(self, fig, event_source=event_source,
[1;32m-> 1009[1;33m *args, **kwargs)
[0m[0;32m 1010[0m [1;33m[0m[0m
[0;32m 1011[0m [1;32mdef[0m [0m_step[0m[1;33m([0m[0mself[0m[1;33m,[0m [1;33m*[0m[0margs[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m__init__[1;34m(self, fig, event_source, blit)[0m
[0;32m 634[0m self._stop)
[0;32m 635[0m [1;32mif[0m [0mself[0m[1;33m.[0m[0m_blit[0m[1;33m:[0m[1;33m[0m[0m
[1;32m--> 636[1;33m [0mself[0m[1;33m.[0m[0m_setup_blit[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 637[0m [1;33m[0m[0m
[0;32m 638[0m [1;32mdef[0m [0m_start[0m[1;33m([0m[0mself[0m[1;33m,[0m [1;33m*[0m[0margs[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m_setup_blit[1;34m(self)[0m
[0;32m 905[0m self._resize_id = self._fig.canvas.mpl_connect('resize_event',
[0;32m 906[0m self._handle_resize)
[1;32m--> 907[1;33m [0mself[0m[1;33m.[0m[0m_post_draw[0m[1;33m([0m[0mNone[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0m_blit[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 908[0m [1;33m[0m[0m
[0;32m 909[0m [1;32mdef[0m [0m_handle_resize[0m[1;33m([0m[0mself[0m[1;33m,[0m [1;33m*[0m[0margs[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m_post_draw[1;34m(self, framedata, blit)[0m
[0;32m 870[0m [0mself[0m[1;33m.[0m[0m_blit_draw[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m_drawn_artists[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0m_blit_cache[0m[1;33m)[0m[1;33m[0m[0m
[0;32m 871[0m [1;32melse[0m[1;33m:[0m[1;33m[0m[0m
[1;32m--> 872[1;33m [0mself[0m[1;33m.[0m[0m_fig[0m[1;33m.[0m[0mcanvas[0m[1;33m.[0m[0mdraw_idle[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 873[0m [1;33m[0m[0m
[0;32m 874[0m [1;31m# The rest of the code in this class is to facilitate easy blitting[0m[1;33m[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc[0m in [0;36mdraw_idle[1;34m(self, *args, **kwargs)[0m
[0;32m 2024[0m [1;32mif[0m [1;32mnot[0m [0mself[0m[1;33m.[0m[0m_is_idle_drawing[0m[1;33m:[0m[1;33m[0m[0m
[0;32m 2025[0m [1;32mwith[0m [0mself[0m[1;33m.[0m[0m_idle_draw_cntx[0m[1;33m([0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m-> 2026[1;33m [0mself[0m[1;33m.[0m[0mdraw[0m[1;33m([0m[1;33m*[0m[0margs[0m[1;33m,[0m [1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 2027[0m [1;33m[0m[0m
[0;32m 2028[0m [1;32mdef[0m [0mdraw_cursor[0m[1;33m([0m[0mself[0m[1;33m,[0m [0mevent[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc[0m in [0;36mdraw[1;34m(self)[0m
[0;32m 472[0m [1;33m[0m[0m
[0;32m 473[0m [1;32mtry[0m[1;33m:[0m[1;33m[0m[0m
[1;32m--> 474[1;33m [0mself[0m[1;33m.[0m[0mfigure[0m[1;33m.[0m[0mdraw[0m[1;33m([0m[0mself[0m[1;33m.[0m[0mrenderer[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 475[0m [1;32mfinally[0m[1;33m:[0m[1;33m[0m[0m
[0;32m 476[0m [0mRendererAgg[0m[1;33m.[0m[0mlock[0m[1;33m.[0m[0mrelease[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/artist.pyc[0m in [0;36mdraw_wrapper[1;34m(artist, renderer, *args, **kwargs)[0m
[0;32m 59[0m [1;32mdef[0m [0mdraw_wrapper[0m[1;33m([0m[0martist[0m[1;33m,[0m [0mrenderer[0m[1;33m,[0m [1;33m*[0m[0margs[0m[1;33m,[0m [1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[0;32m 60[0m [0mbefore[0m[1;33m([0m[0martist[0m[1;33m,[0m [0mrenderer[0m[1;33m)[0m[1;33m[0m[0m
[1;32m---> 61[1;33m [0mdraw[0m[1;33m([0m[0martist[0m[1;33m,[0m [0mrenderer[0m[1;33m,[0m [1;33m*[0m[0margs[0m[1;33m,[0m [1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 62[0m [0mafter[0m[1;33m([0m[0martist[0m[1;33m,[0m [0mrenderer[0m[1;33m)[0m[1;33m[0m[0m
[0;32m 63[0m [1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/figure.pyc[0m in [0;36mdraw[1;34m(self, renderer)[0m
[0;32m 1163[0m [1;33m[0m[0m
[0;32m 1164[0m [0mself[0m[1;33m.[0m[0m_cachedRenderer[0m [1;33m=[0m [0mrenderer[0m[1;33m[0m[0m
[1;32m-> 1165[1;33m [0mself[0m[1;33m.[0m[0mcanvas[0m[1;33m.[0m[0mdraw_event[0m[1;33m([0m[0mrenderer[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 1166[0m [1;33m[0m[0m
[0;32m 1167[0m [1;32mdef[0m [0mdraw_artist[0m[1;33m([0m[0mself[0m[1;33m,[0m [0ma[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc[0m in [0;36mdraw_event[1;34m(self, renderer)[0m
[0;32m 1807[0m [0ms[0m [1;33m=[0m [1;34m'draw_event'[0m[1;33m[0m[0m
[0;32m 1808[0m [0mevent[0m [1;33m=[0m [0mDrawEvent[0m[1;33m([0m[0ms[0m[1;33m,[0m [0mself[0m[1;33m,[0m [0mrenderer[0m[1;33m)[0m[1;33m[0m[0m
[1;32m-> 1809[1;33m [0mself[0m[1;33m.[0m[0mcallbacks[0m[1;33m.[0m[0mprocess[0m[1;33m([0m[0ms[0m[1;33m,[0m [0mevent[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 1810[0m [1;33m[0m[0m
[0;32m 1811[0m [1;32mdef[0m [0mresize_event[0m[1;33m([0m[0mself[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/cbook.pyc[0m in [0;36mprocess[1;34m(self, s, *args, **kwargs)[0m
[0;32m 561[0m [1;32mfor[0m [0mcid[0m[1;33m,[0m [0mproxy[0m [1;32min[0m [0mlist[0m[1;33m([0m[0msix[0m[1;33m.[0m[0miteritems[0m[1;33m([0m[0mself[0m[1;33m.[0m[0mcallbacks[0m[1;33m[[0m[0ms[0m[1;33m][0m[1;33m)[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[0;32m 562[0m [1;32mtry[0m[1;33m:[0m[1;33m[0m[0m
[1;32m--> 563[1;33m [0mproxy[0m[1;33m([0m[1;33m*[0m[0margs[0m[1;33m,[0m [1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 564[0m [1;32mexcept[0m [0mReferenceError[0m[1;33m:[0m[1;33m[0m[0m
[0;32m 565[0m [0mself[0m[1;33m.[0m[0m_remove_proxy[0m[1;33m([0m[0mproxy[0m[1;33m)[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/cbook.pyc[0m in [0;36m__call__[1;34m(self, *args, **kwargs)[0m
[0;32m 428[0m [0mmtd[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mfunc[0m[1;33m[0m[0m
[0;32m 429[0m [1;31m# invoke the callable and return the result[0m[1;33m[0m[1;33m[0m[0m
[1;32m--> 430[1;33m [1;32mreturn[0m [0mmtd[0m[1;33m([0m[1;33m*[0m[0margs[0m[1;33m,[0m [1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 431[0m [1;33m[0m[0m
[0;32m 432[0m [1;32mdef[0m [0m__eq__[0m[1;33m([0m[0mself[0m[1;33m,[0m [0mother[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m_start[1;34m(self, *args)[0m
[0;32m 646[0m [1;33m[0m[0m
[0;32m 647[0m [1;31m# Now do any initial draw[0m[1;33m[0m[1;33m[0m[0m
[1;32m--> 648[1;33m [0mself[0m[1;33m.[0m[0m_init_draw[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 649[0m [1;33m[0m[0m
[0;32m 650[0m [1;31m# Add our callback for stepping the animation and[0m[1;33m[0m[1;33m[0m[0m
[1;32m/home/isisilon/.virtualenvs/main/local/lib/python2.7/site-packages/matplotlib/animation.pyc[0m in [0;36m_init_draw[1;34m(self)[0m
[0;32m 1194[0m [1;33m[0m[0m
[0;32m 1195[0m [1;32melse[0m[1;33m:[0m[1;33m[0m[0m
[1;32m-> 1196[1;33m [0mself[0m[1;33m.[0m[0m_drawn_artists[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0m_init_func[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 1197[0m [1;32mif[0m [0mself[0m[1;33m.[0m[0m_blit[0m[1;33m:[0m[1;33m[0m[0m
[0;32m 1198[0m [1;32mfor[0m [0ma[0m [1;32min[0m [0mself[0m[1;33m.[0m[0m_drawn_artists[0m[1;33m:[0m[1;33m[0m[0m
[1;32m<ipython-input-28-894a9449f93f>[0m in [0;36minit[1;34m()[0m
[0;32m 11[0m [1;31m# initialization function: plot the background of each frame[0m[1;33m[0m[1;33m[0m[0m
[0;32m 12[0m [1;32mdef[0m [0minit[0m[1;33m([0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m
[1;32m---> 13[1;33m [0mline[0m[1;33m.[0m[0mset_data[0m[1;33m([0m[1;33m[[0m[1;33m][0m[1;33m,[0m [1;33m[[0m[1;33m][0m[1;33m)[0m[1;33m[0m[0m
[0m[0;32m 14[0m [1;32mreturn[0m [1;33m([0m[0mline[0m[1;33m,[0m[1;33m)[0m[1;33m[0m[0m
[0;32m 15[0m [1;33m[0m[0m
[1;31mNameError[0m: global name 'line' is not definedIn [40]:
from JSAnimation import IPython_display
from matplotlib import animation
from IPython.display import HTML
fig, ax = plt.subplots(1,1, figsize = (8, 8))
ax.set_xlabel('Easting (m)', fontsize = 16)
ax.set_ylabel('Depth (m)', fontsize = 16)
extent = [mesh.vectorCCx.min(), mesh.vectorCCx.max(), mesh.vectorCCy.min()-mesh.vectorCCy.max(), mesh.vectorCCy.max()-mesh.vectorCCy.max()]
ax.set_xlim(extent[:2])
ax.set_ylim(extent[2:])
nskip = 79
def animate(i_id):
icount = i_id*nskip
frame = ax.imshow(np.flipud(U[0][:,icount].reshape((mesh.nCx, mesh.nCy), order = 'F').T), cmap = 'binary', extent=extent)
ax.imshow(np.flipud(v.reshape((mesh.nCx, mesh.nCy), order = 'F').T), cmap = 'jet', extent=extent, alpha = 0.2)
return frame
animation.FuncAnimation(fig, animate, frames=20, interval=40, blit=False)Out [40]:
– + Once Loop Reflect
In [ ]:
In [20]:
def traveltime(x, h, v):
d = np.sqrt((0.5*x)**2+h**2)
t = 2*(d/v)
return tIn [21]:
print traveltime(2.5, 20., 800.)0.0500975610684
In [22]:
def intercTime(x, h, v1, v2):
out = 2*h*np.sqrt(v2**2-v1**2)/(v1*v2)In [23]:
# print intercTime(0., 20., 800.)In [24]:
print (2*20)/800.0.05
In [25]:
extent = [0,2, 0, 2]
fig, ax = plt.subplots(1,1, figsize = (8, 5))
ax.imshow(data[0].T, cmap = 'RdBu', extent=extent) Out [25]:
<matplotlib.image.AxesImage at 0x7fc0a1a46050>
In [26]:
fig, ax = plt.subplots(1,1, figsize=(12, 4))
ax.plot(time+tlag, data[0][0,:])
ax.grid(True)In [ ]:
In [ ]: