return_stddev=True) solver = Homogeneous(traveltime, recs, vp, vs) # Pick the initial estimate and fit mpl.figure() mpl.axis('scaled') mpl.suptitle("Choose the initial estimate") mpl.points(rec_points, '^r') mpl.points(src, '*y') initial = mpl.pick_points(area, mpl.gca(), marker='*', color='b') if len(initial) > 1: print "Don't be greedy! Pick only one point" sys.exit() estimate = solver.config('levmarq', initial=initial[0]).fit().estimate_ mpl.figure(figsize=(10,4)) mpl.subplot(1, 2, 1) mpl.title('Epicenter + %d recording stations' % (len(recs))) mpl.axis('scaled') mpl.points(src, '*y', label="True") mpl.points(recs, '^r', label="Stations") mpl.points(initial, '*b', label="Initial") mpl.points([estimate], '*g', label="Estimate") mpl.set_area(area) mpl.legend(loc='lower right', shadow=True, numpoints=1, prop={'size':12}) mpl.xlabel("X") mpl.ylabel("Y") ax = mpl.subplot(1, 2, 2) mpl.title('Travel-time residuals + error bars') s = numpy.arange(len(traveltime)) + 1 width = 0.3 mpl.bar(s - width, traveltime, width, color='g', label="Observed",
gzz = utils.si2eotvos(transform.derivz(xp, yp, utils.mgal2si(gz), shape)) gxz_true = prism.gxz(xp, yp, zp, model) gyz_true = prism.gyz(xp, yp, zp, model) gzz_true = prism.gzz(xp, yp, zp, model) mpl.figure() mpl.title("Original gravity anomaly") mpl.axis('scaled') mpl.contourf(xp, yp, gz, shape, 15) mpl.colorbar(shrink=0.7) mpl.m2km() mpl.figure(figsize=(14, 10)) mpl.subplots_adjust(top=0.95, left=0.05, right=0.95) mpl.subplot(2, 3, 1) mpl.title("x deriv (contour) + true (color map)") mpl.axis('scaled') levels = mpl.contourf(yp, xp, gxz_true, shape, 12) mpl.colorbar(shrink=0.7) mpl.contour(yp, xp, gxz, shape, 12, color='k') mpl.m2km() mpl.subplot(2, 3, 2) mpl.title("y deriv (contour) + true (color map)") mpl.axis('scaled') levels = mpl.contourf(yp, xp, gyz_true, shape, 12) mpl.colorbar(shrink=0.7) mpl.contour(yp, xp, gyz, shape, 12, color='k') mpl.m2km() mpl.subplot(2, 3, 3) mpl.title("z deriv (contour) + true (color map)")
shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) noise = 2 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 10) mpl.contour(yp, xp, tensor[i], shape, levels) mpl.m2km() mpl.show() # Get the eigenvectors from the tensor data eigenvals, eigenvecs = gravmag.tensor.eigen(tensor) # Use the first eigenvector to estimate the center of mass cm, sigma = gravmag.tensor.center_of_mass(xp, yp, zp, eigenvecs[0]) print "Sigma = %g" % (sigma) # Plot the prism and the estimated center of mass myv.figure() myv.points([cm], size=300.) myv.prisms(prisms, prop='density', opacity=0.5)
fields = [prism.potential(xp, yp, zp, model), prism.gx(xp, yp, zp, model), prism.gy(xp, yp, zp, model), prism.gz(xp, yp, zp, model), prism.gxx(xp, yp, zp, model), prism.gxy(xp, yp, zp, model), prism.gxz(xp, yp, zp, model), prism.gyy(xp, yp, zp, model), prism.gyz(xp, yp, zp, model), prism.gzz(xp, yp, zp, model)] titles = ['potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure(figsize=(8, 9)) mpl.subplots_adjust(left=0.03, right=0.95, bottom=0.05, top=0.92, hspace=0.3) mpl.suptitle("Potential fields produced by a 3 prism model") for i, field in enumerate(fields): mpl.subplot(4, 3, i + 3) mpl.axis('scaled') mpl.title(titles[i]) levels = mpl.contourf(yp*0.001, xp*0.001, field, shape, 15) cb = mpl.colorbar() mpl.contour(yp*0.001, xp*0.001, field, shape, levels, clabel=False, linewidth=0.1) mpl.show() myv.figure() myv.prisms(model, prop='density') axes = myv.axes(myv.outline()) myv.wall_bottom(axes.axes.bounds, opacity=0.2) myv.wall_north(axes.axes.bounds) myv.show()
# Generating synthetic data amp = 3 age = 54 zp = numpy.arange(0, 100, 1) temp, error = utils.contaminate(climsig.abrupt(amp, age, zp), 0.02, 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')
solver.fit() # Add the estimated density distribution to the layer object for plotting and # forward modeling layer.addprop('density', solver.estimate_) residuals = solver[0].residuals() print("Residuals:") print("mean:", residuals.mean()) print("stddev:", residuals.std()) # Now I can forward model the layer at a greater height and check against the # true solution of the prism gz_true = prism.gz(x, y, z - 500, model) gz_up = sphere.gz(x, y, z - 500, layer) mpl.figure(figsize=(14, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (kg.m^-3)') mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (mGal)') levels = mpl.contour(y, x, gz, shape, 15, color='r') mpl.contour(y, x, solver[0].predicted(), shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (mGal)') mpl.hist(residuals, bins=10)
xp, yp, zp = gridder.regular(dataarea, shape, z=-500) tensor = [ gravmag.polyprism.gxx(xp, yp, zp, prisms), gravmag.polyprism.gxy(xp, yp, zp, prisms), gravmag.polyprism.gxz(xp, yp, zp, prisms), gravmag.polyprism.gyy(xp, yp, zp, prisms), gravmag.polyprism.gyz(xp, yp, zp, prisms), gravmag.polyprism.gzz(xp, yp, zp, prisms) ] # Calculate the 3 invariants invariants = gravmag.tensor.invariants(tensor) data = tensor + invariants # and plot it mpl.figure() mpl.axis('scaled') mpl.suptitle("Tensor and invariants produced by prism model (Eotvos)") titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz', 'I1', 'I2', 'I'] for i in xrange(len(data)): mpl.subplot(3, 3, i + 1) mpl.title(titles[i]) levels = 20 if i == 8: levels = numpy.linspace(0, 1, levels) mpl.contourf(yp, xp, data[i], shape, levels) mpl.colorbar() for p in prisms: mpl.polygon(p, '.-k', xy2ne=True) mpl.set_area(dataarea) mpl.m2km() mpl.show()
utils.contaminate(gravmag.prism.gz(x, y, z, model), noisegz), utils.contaminate(gravmag.prism.gxx(x, y, z, model), noise), utils.contaminate(gravmag.prism.gxy(x, y, z, model), noise), utils.contaminate(gravmag.prism.gxz(x, y, z, model), noise), utils.contaminate(gravmag.prism.gyy(x, y, z, model), noise), utils.contaminate(gravmag.prism.gyz(x, y, z, model), noise), utils.contaminate(gravmag.prism.gzz(x, y, z, model), noise)] with open('data.txt', 'w') as f: f.write(logger.header(comment='#')) f.write("# Noise corrupted gz and tensor components:\n") f.write("# noise = %g Eotvos\n" % (noise)) f.write("# noise = %g mGal\n" % (noisegz)) f.write("# coordinates are in meters\n") f.write("# gz in mGal and tensor in Eotvos\n") f.write("# x y z height gz gxx gxy gxz gyy gyz gzz\n") numpy.savetxt(f, numpy.transpose(data)) # Show it mpl.figure(figsize=(10, 9)) names = "z height gz gxx gxy gxz gyy gyz gzz".split() for i, comp in enumerate(data[2:]): mpl.subplot(3, 3, i + 1) mpl.axis('scaled') mpl.title(names[i]) levels = mpl.contourf(y*0.001, x*0.001, comp, shape, 8) mpl.contour(y*0.001, x*0.001, comp, shape, levels) if i == 3: mpl.ylabel('North = x (km)') if i == 7: mpl.xlabel('East = y (km)') mpl.show()
""" Vis: Plot contour lines and filled contours """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate some data to plot area = (-40, 0, 10, -50) shape = (100, 100) lon, lat = gridder.regular(area, shape) data = utils.gaussian2d(lon, lat, 10, 20, -20, -20, angle=-45) mpl.figure() # Filled contour plot mpl.subplot(221) mpl.title('Filled contours') mpl.contourf(lon, lat, data, shape, 50) mpl.colorbar() # Contour plot mpl.subplot(222) mpl.title('Line contours') mpl.contour(lon, lat, data, shape, 10, color='r', style='dashed') # Mix contour and contourf # contour and contourf return a list of the contour values mpl.subplot(223) mpl.title('Filled contours + line contours') levels = mpl.contourf(lon, lat, data, shape, 10) mpl.colorbar()
# Get the iterator. This part only generates an iterator object. The actual # computations take place at each iteration in the for loop below dt = wavefd.maxdt(area, shape, pvel.max()) duration = 130 maxit = int(duration/dt) stations = [[400000, 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*((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)
g, _ = gridder.pad_array(gz, padtype='OddReflectionTaper') pads.append(g.flatten()) # Get coordinate vectors N = gridder.pad_coords(xy, gz.shape, nps) shapepad = g.shape # Generate new meshgrid and plot results yp = N[1] xp = N[0] titles = ['Original', 'Zero', 'Mean', 'Edge', 'Linear Taper', 'Reflection', 'Odd Reflection', 'Odd Reflection/Taper'] mpl.figure(figsize=(17, 9)) mpl.suptitle('Padding algorithms for a 2D array') for ii, p in enumerate(pads): mpl.subplot(2, 4, ii+2) mpl.axis('scaled') mpl.title(titles[ii+1]) levels = mpl.contourf(yp*0.001, xp*0.001, p, shapepad, 15) cb = mpl.colorbar() mpl.contour(yp*0.001, xp*0.001, p, shapepad, levels, clabel=False, linewidth=0.1) mpl.subplot(2, 4, 1) mpl.axis('scaled') mpl.title(titles[0]) levels = mpl.contourf(y*0.001, x*0.001, gz, shape, 15) cb = mpl.colorbar() mpl.contour(y*0.001, x*0.001, gz, shape, levels, clabel=False, linewidth=0.1) mpl.show()
oTimeBeforePlotting = datetime.now() #-----Drawing----- #Plot the model myv.figure() myv.prisms(lModel, 'density', style='surface') axes = myv.axes(myv.outline()) myv.wall_bottom(axes.axes.bounds) myv.wall_north(axes.axes.bounds) myv.title("Geological Model") # Plot the forward modelled signal mpl.figure(figsize=(16,5)) mpl.subplot(121) mpl.title("Original signal") mpl.axis('scaled') mpl.contourf(aYGridCoords, aXGridCoords, aObservedSignal, tSignalSize, 50) #last arg is number of contours mpl.colorbar() mpl.xlabel('East (km)') mpl.ylabel('North (km)') mpl.m2km() mpl.subplot(122) mpl.title("Forward modelled signal") mpl.axis('scaled') mpl.contourf(aYGridCoords, aXGridCoords, aCalcSignal, tSignalSize, 50) #last arg is number of contours mpl.colorbar() mpl.xlabel('East (km)') mpl.ylabel('North (km)')
Vis: Plotting irregularly sampled map data """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate random points x, y = gridder.scatter((-2, 2, -2, 2), n=200) # And calculate a 2D Gaussian on these points z = utils.gaussian2d(x, y, 1, 1) # Functions pcolor, contour and contourf take an interp argument # If it is True, will interpolate the data before plotting using the specified # grid shape shape = (100, 100) mpl.figure() mpl.subplot(2, 2, 1) mpl.axis('scaled') mpl.title("contourf") mpl.contourf(x, y, z, shape, 50, interp=True) mpl.subplot(2, 2, 2) mpl.axis('scaled') mpl.title("contour") mpl.contour(x, y, z, shape, 15, interp=True) mpl.subplot(2, 2, 3) mpl.axis('scaled') mpl.title("pcolor") mpl.pcolor(x, y, z, shape, interp=True) # You can tell these functions to extrapolate the data to fill in the margins mpl.subplot(2, 2, 4) mpl.axis('scaled') mpl.title("contourf extrapolate")
print "mean:", residuals.mean() print "stddev:", residuals.std() # Now I can forward model the layer at the south pole and check against the # true solution of the prism tfpole = prism.tf(x, y, z, model, -90, 0) tfreduced = sphere.tf(x, y, z, layer, -90, 0) mpl.figure() mpl.suptitle('L-curve') mpl.title("Estimated regularization parameter: %g" % (solver.regul_param_)) solver.plot_lcurve() mpl.grid() mpl.figure(figsize=(14, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (A/m)') mpl.pcolor(layer.y, layer.x, layer.props['magnetization'], layer.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (nT)') levels = mpl.contour(y, x, tf, shape, 15, color='r') mpl.contour(y, x, solver.predicted(), shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (nT)') mpl.hist(residuals, bins=10)
# Get the iterator. This part only generates an iterator object. The actual # computations take place at each iteration in the for loop below dt = wavefd.maxdt(area, shape, pvel.max()) duration = 100 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])
bounds = [0, 1000, 0, 1000, 0, 1000] area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-150) noise = 0.5 gxx = utils.contaminate(gm.prism.gxx(xp, yp, zp, model), noise) gxy = utils.contaminate(gm.prism.gxy(xp, yp, zp, model), noise) gxz = utils.contaminate(gm.prism.gxz(xp, yp, zp, model), noise) gyy = utils.contaminate(gm.prism.gyy(xp, yp, zp, model), noise) gyz = utils.contaminate(gm.prism.gyz(xp, yp, zp, model), noise) gzz = utils.contaminate(gm.prism.gzz(xp, yp, zp, model), noise) tensor = [gxx, gxy, gxz, gyy, gyz, gzz] titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] # plot the data mpl.figure() for i in xrange(len(tensor)): mpl.subplot(2, 3, i + 1) mpl.title(titles[i]) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 30) mpl.colorbar() mpl.xlabel('y (km)') mpl.ylabel('x (km)') mpl.m2km() mpl.show() # Inversion setup # Create a mesh mesh = PrismMesh(bounds, (30, 30, 30)) # Wrap the data so that harvester can use it data = [ gm.harvester.Gxx(xp, yp, zp, gxx),
gravmag.prism.gz(xp, yp, zp, prisms), gravmag.prism.gxx(xp, yp, zp, prisms), gravmag.prism.gxy(xp, yp, zp, prisms), gravmag.prism.gxz(xp, yp, zp, prisms), gravmag.prism.gyy(xp, yp, zp, prisms), gravmag.prism.gyz(xp, yp, zp, prisms), gravmag.prism.gzz(xp, yp, zp, prisms) ] titles = [ 'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz' ] mpl.figure(figsize=(8, 9)) mpl.subplots_adjust(left=0.03, right=0.95, bottom=0.05, top=0.92, hspace=0.3) mpl.suptitle("Potential fields produced by a 3 prism model") for i, field in enumerate(fields): mpl.subplot(4, 3, i + 3) mpl.axis('scaled') mpl.title(titles[i]) levels = mpl.contourf(yp * 0.001, xp * 0.001, field, shape, 15) cb = mpl.colorbar() mpl.contour(yp * 0.001, xp * 0.001, field, shape, levels, clabel=False, linewidth=0.1) mpl.show() myv.figure() myv.prisms(prisms, prop='density')
area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-1) # Add a constant baselevel baselevel = 10 # Convert from nanoTesla to Tesla because euler and derivatives require things # in SI tf = (utils.nt2si(prism.tf(xp, yp, zp, model, inc, dec)) + baselevel) # Calculate the derivatives using FFT xderiv = fourier.derivx(xp, yp, tf, shape) yderiv = fourier.derivy(xp, yp, tf, shape) zderiv = fourier.derivz(xp, yp, tf, shape) mpl.figure() titles = ['Total field', 'x derivative', 'y derivative', 'z derivative'] for i, f in enumerate([tf, xderiv, yderiv, zderiv]): mpl.subplot(2, 2, i + 1) mpl.title(titles[i]) mpl.axis('scaled') mpl.contourf(yp, xp, f, shape, 50) mpl.colorbar() mpl.m2km() mpl.show() # Run the Euler deconvolution on the whole dataset euler = Classic(xp, yp, zp, tf, xderiv, yderiv, zderiv, 3).fit() print "Base level used: %g" % (baselevel) print "Estimated:" print " Base level: %g" % (euler.baselevel_) print " Source location: %s" % (str(euler.estimate_)) myv.figure()
area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-1) # Add a constant baselevel baselevel = 10 # Convert from nanoTesla to Tesla because euler and derivatives require things # in SI tf = (utils.nt2si(gravmag.prism.tf(xp, yp, zp, model, inc, dec)) + baselevel) # Calculate the derivatives using FFT xderiv = gravmag.fourier.derivx(xp, yp, tf, shape) yderiv = gravmag.fourier.derivy(xp, yp, tf, shape) zderiv = gravmag.fourier.derivz(xp, yp, tf, shape) mpl.figure() titles = ['Total field', 'x derivative', 'y derivative', 'z derivative'] for i, f in enumerate([tf, xderiv, yderiv, zderiv]): mpl.subplot(2, 2, i + 1) mpl.title(titles[i]) mpl.axis('scaled') mpl.contourf(yp, xp, f, shape, 50) mpl.colorbar() mpl.m2km() mpl.show() # Run the euler deconvolution on a single window # Structural index is 3 results = gravmag.euler.classic(xp, yp, zp, tf, xderiv, yderiv, zderiv, 3) print "Base level used: %g" % (baselevel) print "Estimated base level: %g" % (results['baselevel']) myv.figure() myv.points([results['point']], size=300.)
import numpy from fatiando import utils, mesher from fatiando.gravmag import talwani from fatiando.vis import mpl # Notice that the last two number are switched. # This way, the z axis in the plots points down. area = (-5000, 5000, 5000, 0) axes = mpl.figure().gca() mpl.xlabel("X") mpl.ylabel("Z") mpl.axis('scaled') polygons = [mesher.Polygon(mpl.draw_polygon(area, axes), {'density': 500})] xp = numpy.arange(-4500, 4500, 100) zp = numpy.zeros_like(xp) gz = talwani.gz(xp, zp, polygons) mpl.figure() mpl.axis('scaled') mpl.subplot(2, 1, 1) mpl.title(r"Gravity anomaly produced by the model") mpl.plot(xp, gz, '-k', linewidth=2) mpl.ylabel("mGal") mpl.xlim(-5000, 5000) mpl.subplot(2, 1, 2) mpl.polygon(polygons[0], 'o-k', linewidth=2, fill='k', alpha=0.5) mpl.xlabel("X") mpl.ylabel("Z") mpl.set_area(area) mpl.show()
print("~~~~~~~~~~Total Time:", oTimeEndTot - oTimeBeginTot) oTimeBeforePlotting = datetime.now() #-----Drawing----- #Plot the model myv.figure() myv.prisms(lModel, 'density', style='surface') axes = myv.axes(myv.outline()) myv.wall_bottom(axes.axes.bounds) myv.wall_north(axes.axes.bounds) myv.title("Geological Model") # Plot the forward modelled signal mpl.figure(figsize=(16, 5)) mpl.subplot(121) mpl.title("Original signal") mpl.axis('scaled') mpl.contourf(aYGridCoords, aXGridCoords, aObservedSignal, tSignalSize, 50) #last arg is number of contours mpl.colorbar() mpl.xlabel('East (km)') mpl.ylabel('North (km)') mpl.m2km() mpl.subplot(122) mpl.title("Forward modelled signal") mpl.axis('scaled') mpl.contourf(aYGridCoords, aXGridCoords, aCalcSignal, tSignalSize, 50) #last arg is number of contours mpl.colorbar()
bounds = [0, 1000, 0, 1000, 0, 1000] area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-150) noise = 0.5 gxx = utils.contaminate(gm.prism.gxx(xp, yp, zp, model), noise) gxy = utils.contaminate(gm.prism.gxy(xp, yp, zp, model), noise) gxz = utils.contaminate(gm.prism.gxz(xp, yp, zp, model), noise) gyy = utils.contaminate(gm.prism.gyy(xp, yp, zp, model), noise) gyz = utils.contaminate(gm.prism.gyz(xp, yp, zp, model), noise) gzz = utils.contaminate(gm.prism.gzz(xp, yp, zp, model), noise) tensor = [gxx, gxy, gxz, gyy, gyz, gzz] titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] # plot the data mpl.figure() for i in xrange(len(tensor)): mpl.subplot(2, 3, i + 1) mpl.title(titles[i]) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 30) mpl.colorbar() mpl.xlabel('y (km)') mpl.ylabel('x (km)') mpl.m2km() mpl.show() # Inversion setup # Create a mesh mesh = PrismMesh(bounds, (30, 30, 30)) # Wrap the data so that harvester can use it data = [gm.harvester.Gxx(xp, yp, zp, gxx), gm.harvester.Gxy(xp, yp, zp, gxy),
# Generate random points area = (-2, 2, -2, 2) x, y = gridder.scatter(area, n=200, seed=0) # And calculate 2D Gaussians on these points as sample data def data(x, y): return (utils.gaussian2d(x, y, -0.6, -1) - utils.gaussian2d(x, y, 1.5, 1.5)) z = data(x, y) shape = (100, 100) # First, we need to know the real data at the grid points grdx, grdy = gridder.regular(area, shape) grdz = data(grdx, grdy) mpl.figure() mpl.subplot(2, 2, 1) mpl.axis('scaled') mpl.title("True grid data") mpl.plot(x, y, '.k', label='Data points') mpl.contourf(grdx, grdy, grdz, shape, 50) mpl.colorbar() mpl.legend(loc='lower right', numpoints=1) # Use the default interpolation (cubic) grdx, grdy, grdz = gridder.interp(x, y, z, shape) mpl.subplot(2, 2, 2) mpl.axis('scaled') mpl.title("Interpolated using cubic minimum-curvature") mpl.plot(x, y, '.k', label='Data points') mpl.contourf(grdx, grdy, grdz, shape, 50) mpl.colorbar()
tf = contaminate(sphere.tf(x, y, z, model, inc, dec), 5.0, seed=0) # Give the centers of the dipoles centers = [[3000, 3000, 1000], [7000, 7000, 1000]] # Estimate the magnetization vectors solver = DipoleMagDir(x, y, z, tf, inc, dec, centers).fit() # Print the estimated and true dipole monents, inclinations and declinations print 'Estimated magnetization (intensity, inclination, declination)' for e in solver.estimate_: print e # Plot the fit and the normalized histogram of the residuals mpl.figure(figsize=(14, 5)) mpl.subplot(1, 2, 1) mpl.title("Total Field Anomaly (nT)", fontsize=14) mpl.axis('scaled') nlevels = mpl.contour(y, x, tf, (50, 50), 15, interp=True, color='r', label='Observed', linewidth=2.0) mpl.contour(y, x, solver.predicted(), (50, 50), nlevels, interp=True, color='b', label='Predicted', style='dashed', linewidth=2.0) mpl.legend(loc='upper left', shadow=True, prop={'size': 13}) mpl.xlabel('East y (m)', fontsize=14) mpl.ylabel('North x (m)', fontsize=14) mpl.subplot(1, 2, 2) residuals_mean = numpy.mean(solver.residuals()) residuals_std = numpy.std(solver.residuals()) # Each residual is subtracted from the mean and the resulting # difference is divided by the standard deviation s = (solver.residuals() - residuals_mean) / residuals_std
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 * ((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,
Meshing: Making a grid of 3D point sources """ from fatiando import mesher, utils, gravmag, gridder from fatiando.vis import mpl grid = mesher.PointGrid([0, 1000, 0, 2000], 500, (50, 50)) # Add some density to the grid grid.addprop('density', 1000000000*utils.gaussian2d(grid.x, grid.y, 100, 500, x0=500, y0=1000, angle=-60)) # and some magnetization inc, dec = -45, 0 grid.addprop('magnetization', [d/100.*utils.ang2vec(1, inc, dec) for d in grid.props['density']]) # plot the layer mpl.figure() mpl.subplot(2, 1, 1) mpl.axis('scaled') mpl.title('Density (mass)') mpl.pcolor(grid.y, grid.x, grid.props['density'], grid.shape) mpl.colorbar() mpl.subplot(2, 1, 2) mpl.axis('scaled') mpl.title('Magnetization intensity (dipole moment)') mpl.pcolor(grid.y, grid.x, utils.vecnorm(grid.props['magnetization']), grid.shape) mpl.colorbar() mpl.show() # Now do some calculations with the grid shape = (100, 100) x, y, z = gridder.regular(grid.area, shape, z=0)
area = (-5000, 5000, -5000, 5000) xp, yp, zp = gridder.regular(area, shape, z=-150) noise = 2 tensor = [utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise)] # Get the eigenvectors from the tensor data eigenvals, eigenvecs = gravmag.tensor.eigen(tensor) # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 10) mpl.contour(yp, xp, tensor[i], shape, levels) mpl.m2km() mpl.show() # Pick the centers of the expanding windows # The number of final solutions will be the number of points picked mpl.figure() mpl.suptitle('Pick the centers of the expanding windows') mpl.axis('scaled') mpl.contourf(yp, xp, tensor[-1], shape, 50) mpl.colorbar() centers = mpl.pick_points(area, mpl.gca(), xy2ne=True)
mesh.addprop('vp', tomo.estimate_) # Plot the L-curve annd print the regularization parameter estimated mpl.figure() mpl.title('L-curve: triangle marks the best solution') tomo.plot_lcurve() print "Estimated regularization parameter: %g" % (tomo.regul_param_) # Calculate and print the standard deviation of the residuals # Should be close to the data error if the inversion was able to fit the data residuals = tomo.residuals() print "Assumed error: %g" % (error) print "Standard deviation of residuals: %g" % (np.std(residuals)) mpl.figure(figsize=(14, 5)) mpl.subplot(1, 2, 1) mpl.axis('scaled') mpl.title('Vp model') mpl.squaremesh(model, prop='vp', cmap=mpl.cm.seismic) cb = mpl.colorbar() cb.set_label('Velocity') mpl.points(src_loc, '*y', label="Sources") mpl.points(rec_loc, '^r', label="Receivers") mpl.legend(loc='lower left', shadow=True, numpoints=1, prop={'size': 10}) mpl.m2km() mpl.subplot(1, 2, 2) mpl.axis('scaled') mpl.title('Tomography result') mpl.squaremesh(mesh, prop='vp', vmin=4000, vmax=10000, cmap=mpl.cm.seismic) cb = mpl.colorbar() cb.set_label('Velocity')
area = (lon.min(), lon.max(), lat.min(), lat.max()) # First, lets calculate the gravity disturbance (e.g., the free-air anomaly) # We'll do this using the closed form of the normal gravity for the WGS84 # ellipsoid gamma = normal_gravity.gamma_closed_form(lat, height) disturbance = gravity - gamma # Now we can remove the effect of the Bouguer plate to obtain the Bouguer # anomaly. We'll use the standard densities of 2.67 g.cm^-3 for crust and 1.04 # g.cm^-3 for water. bouguer = disturbance - normal_gravity.bouguer_plate(topo) mpl.figure(figsize=(14, 3.5)) bm = mpl.basemap(area, projection='merc') mpl.subplot(131) mpl.title('Gravity (mGal)') mpl.contourf(lon, lat, gravity, shape, 60, cmap=mpl.cm.Reds, basemap=bm) mpl.colorbar(pad=0) mpl.subplot(132) mpl.title('Gravity disturbance (mGal)') amp = np.abs(disturbance).max() mpl.contourf(lon, lat, disturbance, shape, 60, cmap=mpl.cm.RdBu_r, basemap=bm, vmin=-amp, vmax=amp) mpl.colorbar(pad=0) mpl.subplot(133) mpl.title('Bouguer anomaly (mGal)') mpl.contourf(lon, lat, bouguer, shape, 60, cmap=mpl.cm.Reds, basemap=bm) mpl.colorbar(pad=0) mpl.show()