from fatiando import utils from fatiando.geothermal.climsig import linear, SingleChange from fatiando.vis import mpl # Generating synthetic data amp = 5.43 age = 78.2 # along a well at these depths zp = numpy.arange(0, 100, 1) temp, error = utils.contaminate(linear(amp, age, zp), 0.02, percent=True, return_stddev=True) # Preparing for the inversion data = SingleChange(temp, zp, mode='linear').config('levmarq', initial=[1, 1]) amp_, age_ = data.fit().estimate_ print "Linear change in temperature" print " true: amp=%.3f age=%.3f" % (amp, age) print " estimated: amp=%.3f age=%.3f" % (amp_, age_) mpl.figure(figsize=(4, 5)) mpl.title("Residual well temperature") mpl.plot(temp, zp, 'ok', label='Observed') mpl.plot(data.predicted(), zp, '--r', linewidth=3, label='Predicted') mpl.legend(loc='lower right', numpoints=1) mpl.xlabel("Temperature (C)") mpl.ylabel("Z (m)") mpl.ylim(100, 0) mpl.show()
dt = wavefd.scalar_maxdt(area, shape, np.max(velocity)) duration = 2.5 maxit = int(duration/dt) stations = [[75*ds, 125*ds]] # x, z coordinate of the seismometer snapshots = 3 # every 3 iterations plots one simulation = wavefd.scalar(velocity, area, dt, maxit, sources, stations, snapshots) # This part makes an animation using matplotlibs animation API background = (velocity-4000)*10**-1 fig = mpl.figure(figsize=(8, 6)) mpl.subplots_adjust(right=0.98, left=0.11, hspace=0.5, top=0.93) mpl.subplot2grid((4, 3), (0,0), colspan=3,rowspan=3) wavefield = mpl.imshow(np.zeros_like(velocity), extent=area, cmap=mpl.cm.gray_r, vmin=-1000, vmax=1000) mpl.points(stations, '^b', size=8) mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)') mpl.ylabel('z (km)') mpl.m2km() mpl.subplot2grid((4,3), (3,0), colspan=3) seismogram1, = mpl.plot([],[],'-k') mpl.xlim(0, duration) mpl.ylim(-200, 200) mpl.ylabel('Amplitude') times = np.linspace(0, dt*maxit, maxit) # This function updates the plot every few timesteps def animate(i): t, u, seismogram = simulation.next() seismogram1.set_data(times[:t+1], seismogram[0][:t+1]) wavefield.set_array(background[::-1]+u[::-1]) return wavefield, seismogram1
maxit = int(duration/dt) stations = [[2200+i*dx, 0] for i in range(220)] # x, z coordinate of the seismometers snapshot = int(0.004/dt) # Plot a snapshot of the simulation every 4 miliseconds print "dt for simulation is ", dt print "max iteration for simulation is ", maxit print "duration for simulation is ", duration simulation = wavefd.elastic_psv(lamb, mu, density, area, dt, maxit, sources, stations, snapshot, padding=50, taper=0.01) # This part makes an animation using matplotlibs animation API fig = mpl.figure(figsize=(12, 5)) # Start with everything zero and grab the plot so that it can be updated later mpl.imshow(pvel[::-1], extent=area, alpha=0.25) wavefield = mpl.imshow(np.zeros(shape), extent=area, vmin=-10**-7, vmax=10**-7, alpha=0.75, cmap=mpl.cm.gray_r) mpl.points(stations, '.k') mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)') mpl.ylabel('z (km)') mpl.m2km() times = np.linspace(0, maxit*dt, maxit) # the only way for getting the feedback response of the seimograms global seismograms # This function updates the plot every few timesteps def animate(i): # Simulation will yield panels corresponding to P and S waves because # xz2ps=True t, ux, uz, xcomp, zcomp = simulation.next() mpl.title('time: %0.3f s' % (times[t])) # wavefield.set_array((p + s)[::-1]) wavefield.set_data(uz[::-1])
percent=True, return_stddev=True) # Assume that the thicknesses are unknown. In this case, use a mesh of many # thin layers and invert for each slowness thick = 10. mesh = [thick] * int(sum(thickness) / thick) solver = (LayeredStraight(tts, zp, mesh) + 5 * Smoothness1D(len(mesh))).fit() velocity_ = solver.estimate_ mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.grid() mpl.title("Vertical seismic profile") mpl.plot(tts, zp, 'ok', label='Observed') mpl.plot(solver[0].predicted(), zp, '-r', linewidth=3, label='Predicted') mpl.legend(loc='upper right', numpoints=1) mpl.xlabel("Travel-time (s)") mpl.ylabel("Z (m)") mpl.ylim(sum(mesh), 0) mpl.subplot(1, 2, 2) mpl.grid() mpl.title("True velocity + smooth estimate") mpl.layers(mesh, velocity_, '.-k', linewidth=2, label='Estimated') mpl.layers(thickness, velocity, '--b', linewidth=2, label='True') mpl.ylim(sum(mesh), 0) mpl.xlim(0, 10000) mpl.legend(loc='upper right', numpoints=1) mpl.xlabel("Velocity (m/s)") mpl.ylabel("Z (m)") mpl.show()
return_stddev=True) # Make the solver and run the inversion using damping regularization # (assumes known thicknesses of the layers) solver = (LayeredStraight(tts, zp, thickness) + 0.1 * Damping(len(thickness))).fit() velocity_ = solver.estimate_ # Plot the results mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.grid() mpl.title("Vertical seismic profile") mpl.plot(tts, zp, 'ok', label='Observed') mpl.plot(solver[0].predicted(), zp, '-r', linewidth=3, label='Predicted') mpl.legend(loc='upper right', numpoints=1) mpl.xlabel("Travel-time (s)") mpl.ylabel("Z (m)") mpl.ylim(sum(thickness), 0) mpl.subplot(1, 2, 2) mpl.grid() mpl.title("Velocity profile") mpl.layers(thickness, velocity_, 'o-k', linewidth=2, label='Estimated') mpl.layers(thickness, velocity, '--b', linewidth=2, label='True') mpl.ylim(zmax, zmin) mpl.xlim(vmin, vmax) leg = mpl.legend(loc='upper right', numpoints=1) leg.get_frame().set_alpha(0.5) mpl.xlabel("Velocity (m/s)") mpl.ylabel("Z (m)") mpl.show()
dt, maxit, sources, stations, snapshot, padding=50, taper=0.01, xz2ps=True) # This part makes an animation using matplotlibs animation API fig = mpl.figure(figsize=(12, 5)) mpl.subplot(2, 2, 2) mpl.title('x component') xseismogram, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-10**(-3), 10**(-3)) mpl.subplot(2, 2, 4) mpl.title('z component') zseismogram, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-10**(-3), 10**(-3)) mpl.subplot(1, 2, 1) # Start with everything zero and grab the plot so that it can be updated later wavefield = mpl.imshow(np.zeros(shape), extent=area, vmin=-10**-6, vmax=10**-6, cmap=mpl.cm.gray_r) mpl.points(stations, '^k') mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)')
percent=True, return_stddev=True) # Preparing for the inversion p, residuals = climsig.iabrupt(temp, zp) est_amp, est_age = p mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.title("Climate signal (abrupt)") mpl.plot(temp, zp, 'ok', label='Observed') mpl.plot(temp - residuals, zp, '--r', linewidth=3, label='Predicted') mpl.legend(loc='lower right', numpoints=1) mpl.xlabel("Temperature (C)") mpl.ylabel("Z") mpl.ylim(100, 0) ax = mpl.subplot(1, 2, 2) ax2 = mpl.twinx() mpl.title("Age and amplitude") width = 0.3 ax.bar([1 - width], [age], width, color='b', label="True") ax.bar([1], [est_age], width, color='r', label="Estimate") ax2.bar([2 - width], [amp], width, color='b') ax2.bar([2], [est_amp], width, color='r') ax.legend(loc='upper center', numpoints=1) ax.set_ylabel("Age (years)") ax2.set_ylabel("Amplitude (C)") ax.set_xticks([1, 2]) ax.set_xticklabels(['Age', 'Amplitude']) ax.set_ylim(0, 70) ax2.set_ylim(0, 4)
sources, stations, snapshots, padding=70, taper=0.005, xz2ps=True) # This part makes an animation using matplotlibs animation API background = 10**-5 * ((density - density.min()) / density.max()) fig = mpl.figure(figsize=(10, 8)) mpl.subplots_adjust(right=0.98, left=0.11, hspace=0.3, top=0.93) mpl.subplot(3, 1, 1) mpl.title('x seismogram') xseismogram, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-0.05, 0.05) mpl.ylabel('Amplitude') mpl.subplot(3, 1, 2) mpl.title('z seismogram') zseismogram, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-0.05, 0.05) mpl.ylabel('Amplitude') ax = mpl.subplot(3, 1, 3) mpl.title('time: 0.0 s') wavefield = mpl.imshow(background, extent=area, cmap=mpl.cm.gray_r, vmin=-0.00001, vmax=0.00001) mpl.points(stations, '^b', size=8)
0.02, percent=True, return_stddev=True) # Assume that the thicknesses are unknown. In this case, use a mesh of many # thin layers and invert for each slowness thick = 10. mesh = [thick]*int(sum(thickness)/thick) solver = (LayeredStraight(tts, zp, mesh) + 5*Smoothness1D(len(mesh))).fit() velocity_ = solver.estimate_ mpl.figure(figsize=(12,5)) mpl.subplot(1, 2, 1) mpl.grid() mpl.title("Vertical seismic profile") mpl.plot(tts, zp, 'ok', label='Observed') mpl.plot(solver.predicted(), zp, '-r', linewidth=3, label='Predicted') mpl.legend(loc='upper right', numpoints=1) mpl.xlabel("Travel-time (s)") mpl.ylabel("Z (m)") mpl.ylim(sum(mesh), 0) mpl.subplot(1, 2, 2) mpl.grid() mpl.title("True velocity + smooth estimate") mpl.layers(mesh, velocity_, '.-k', linewidth=2, label='Estimated') mpl.layers(thickness, velocity, '--b', linewidth=2, label='True') mpl.ylim(sum(mesh), 0) mpl.xlim(0, 10000) mpl.legend(loc='upper right', numpoints=1) mpl.xlabel("Velocity (m/s)") mpl.ylabel("Z (m)") mpl.show()
snapshots = 3 # every 3 iterations plots one simulation = wavefd.scalar(velocity, area, dt, maxit, sources, stations, snapshots) # This part makes an animation using matplotlibs animation API background = (velocity - 4000) * 10**-1 fig = mpl.figure(figsize=(8, 6)) mpl.subplots_adjust(right=0.98, left=0.11, hspace=0.5, top=0.93) mpl.subplot2grid((4, 3), (0, 0), colspan=3, rowspan=3) wavefield = mpl.imshow(np.zeros_like(velocity), extent=area, cmap=mpl.cm.gray_r, vmin=-1000, vmax=1000) mpl.points(stations, '^b', size=8) mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)') mpl.ylabel('z (km)') mpl.m2km() mpl.subplot2grid((4, 3), (3, 0), colspan=3) seismogram1, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-200, 200) mpl.ylabel('Amplitude') times = np.linspace(0, dt * maxit, maxit) # This function updates the plot every few timesteps def animate(i): t, u, seismogram = simulation.next() seismogram1.set_data(times[:t + 1], seismogram[0][:t + 1])
maxit = int(duration / dt) stations = [[50000, 0]] # x, z coordinate of the seismometer snapshot = int(0.5 / dt) # Plot a snapshot of the simulation every 0.5 seconds simulation = wavefd.elastic_sh(mu, density, area, dt, maxit, sources, stations, snapshot, padding=50, taper=0.01) # This part makes an animation using matplotlibs animation API fig = mpl.figure(figsize=(14, 5)) ax = mpl.subplot(1, 2, 2) mpl.title('Wavefield') # Start with everything zero and grab the plot so that it can be updated later wavefield_plt = mpl.imshow(np.zeros(shape), extent=area, vmin=-10 ** (-5), vmax=10 ** (-5), cmap=mpl.cm.gray_r) mpl.points(stations, '^b') mpl.xlim(area[:2]) mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)') mpl.ylabel('z (km)') mpl.subplot(1, 2, 1) seismogram_plt, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-10 ** (-4), 10 ** (-4)) mpl.xlabel('time (s)') mpl.ylabel('Amplitude') times = np.linspace(0, duration, maxit) # Update the plot everytime the simulation yields def animate(i): """ Grab the iteration number, displacment panel and seismograms
maxit = int(duration/dt) stations = [[550000, 0]] snapshots = int(1./dt) simulation = wavefd.elastic_psv(lamb, mu, density, area, dt, maxit, sources, stations, snapshots, padding=70, taper=0.005, xz2ps=True) # This part makes an animation using matplotlibs animation API background = 10**-5*((pvel - pvel.min())/pvel.max()) fig = mpl.figure(figsize=(10, 8)) mpl.subplots_adjust(right=0.98, left=0.11, hspace=0.3, top=0.93) mpl.subplot(2, 1, 1) mpl.title('x seismogram') xseismogram, = mpl.plot([],[],'-k') mpl.xlim(0, duration) mpl.ylim(-0.05, 0.05) mpl.ylabel('Amplitude') ax = mpl.subplot(2, 1, 2) mpl.title('time: 0.0 s') wavefield = mpl.imshow(density, extent=area, cmap=mpl.cm.gray_r, vmin=-0.00001, vmax=0.00001) mpl.points(stations, '^b', size=8) #mpl.text(500000, 20000, 'Crust') #mpl.text(500000, 60000, 'Mantle') fig.text(0.8, 0.5, 'Seismometer') mpl.xlim(area[:2]) mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)') mpl.ylabel('z (km)') mpl.m2km() times = np.linspace(0, dt*maxit, maxit)
dt = wavefd.maxdt(area, shape, svel.max()) duration = 250 maxit = int(duration / dt) stations = [[100000, 0], [700000, 0]] snapshots = int(1. / dt) simulation = wavefd.elastic_sh(mu, density, area, dt, maxit, sources, stations, snapshots, padding=70, taper=0.005) # This part makes an animation using matplotlibs animation API fig = mpl.figure(figsize=(10, 8)) mpl.subplots_adjust(right=0.98, left=0.11, hspace=0.3, top=0.93) mpl.subplot(3, 1, 1) mpl.title('Seismogram 1') seismogram1, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-0.1, 0.1) mpl.ylabel('Amplitude') mpl.subplot(3, 1, 2) mpl.title('Seismogram 2') seismogram2, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-0.1, 0.1) mpl.ylabel('Amplitude') ax = mpl.subplot(3, 1, 3) mpl.title('time: 0.0 s') wavefield = mpl.imshow(np.zeros_like(density), extent=area, cmap=mpl.cm.gray_r, vmin=-0.005, vmax=0.005) mpl.points(stations, '^b', size=8) fig.text(0.82, 0.33, 'Seismometer 2') fig.text(0.16, 0.33, 'Seismometer 1') mpl.ylim(area[2:][::-1])
0.02, percent=True, return_stddev=True) # Make the solver and run the inversion using damping regularization # (assumes known thicknesses of the layers) solver = (LayeredStraight(tts, zp, thickness) + 0.1 * Damping(len(thickness))).fit() velocity_ = solver.estimate_ # Plot the results mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.grid() mpl.title("Vertical seismic profile") mpl.plot(tts, zp, 'ok', label='Observed') mpl.plot(solver[0].predicted(), zp, '-r', linewidth=3, label='Predicted') mpl.legend(loc='upper right', numpoints=1) mpl.xlabel("Travel-time (s)") mpl.ylabel("Z (m)") mpl.ylim(sum(thickness), 0) mpl.subplot(1, 2, 2) mpl.grid() mpl.title("Velocity profile") mpl.layers(thickness, velocity_, 'o-k', linewidth=2, label='Estimated') mpl.layers(thickness, velocity, '--b', linewidth=2, label='True') mpl.ylim(zmax, zmin) mpl.xlim(vmin, vmax) leg = mpl.legend(loc='upper right', numpoints=1) leg.get_frame().set_alpha(0.5) mpl.xlabel("Velocity (m/s)") mpl.ylabel("Z (m)") mpl.show()
maxit, sources, stations, snapshots, padding=70, taper=0.005) # This part makes an animation using matplotlibs animation API background = svel * 5 * 10**-7 fig = mpl.figure(figsize=(10, 8)) mpl.subplots_adjust(right=0.98, left=0.11, hspace=0.3, top=0.93) mpl.subplot(3, 1, 1) mpl.title('Seismogram 1') seismogram1, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-0.1, 0.1) mpl.ylabel('Amplitude') mpl.subplot(3, 1, 2) mpl.title('Seismogram 2') seismogram2, = mpl.plot([], [], '-k') mpl.xlim(0, duration) mpl.ylim(-0.1, 0.1) mpl.ylabel('Amplitude') ax = mpl.subplot(3, 1, 3) mpl.title('time: 0.0 s') wavefield = mpl.imshow(background, extent=area, cmap=mpl.cm.gray_r, vmin=-0.005, vmax=0.005) mpl.points(stations, '^b', size=8)
snapshot, padding=50, taper=0.01) # This part makes an animation using matplotlibs animation API fig = mpl.figure(figsize=(12, 5)) # Start with everything zero and grab the plot so that it can be updated later mpl.imshow(pvel[::-1], extent=area, alpha=0.25) wavefield = mpl.imshow(np.zeros(shape), extent=area, vmin=-10**-7, vmax=10**-7, alpha=0.75, cmap=mpl.cm.gray_r) mpl.points(stations, '.k') mpl.ylim(area[2:][::-1]) mpl.xlabel('x (km)') mpl.ylabel('z (km)') mpl.m2km() times = np.linspace(0, maxit * dt, maxit) # the only way for getting the feedback response of the seimograms global seismograms # This function updates the plot every few timesteps def animate(i): # Simulation will yield panels corresponding to P and S waves because # xz2ps=True t, ux, uz, xcomp, zcomp = simulation.next() mpl.title('time: %0.3f s' % (times[t])) # wavefield.set_array((p + s)[::-1])