bounds = [-5000, 5000, -5000, 5000, 0, 5000] area = bounds[:4] #axis = plt.figure().gca() #plt.axis('scaled') verts = [[-2000, -3000], [-2000, 2000], [3000, 3000], [2000, -3000]] model = [ geometry.PolygonalPrism( #giplt.draw_polygon(area, axis, xy2ne=True), verts, # Use only induced magnetization #0, 2000, {'magnetization': 2})] 0, 2000, {'magnetization': giutils.ang2vec(2, inc, dec)}) ] # Calculate the effect shape = (100, 100) xp, yp, zp = gridder.regular(area, shape, z=-500) tf = polyprism.tf(xp, yp, zp, model, inc, dec) # and plot it plt.figure() plt.axis('scaled') plt.title("Total field anomalyproduced by prism model (nT)") giplt.contourf(yp, xp, tf, shape, 20) plt.colorbar() for p in model: giplt.polygon(p, '.-k', xy2ne=True) giplt.set_area(area) giplt.m2km() plt.show()
'ymax': ymax, 'dx': dx, 'dy': dy, 'nx': nx, 'ny': ny } bgascgrd = xyz2Grid(x, y, bgas_contf) grid2srf(bgascgrd) args = dict(shape=shape, levels=20, cmap=plt.cm.RdBu_r) fig, axes = plt.subplots(2, 2, figsize=(10, 10)) plt.sca(axes[0, 0]) plt.title("Derivative of BGA in X") plt.axis('scaled') giplt.contourf(x, y, bgas_dx, **args) plt.colorbar(pad=0).set_label('mGal/m') giplt.m2km() plt.sca(axes[0, 1]) plt.title("Derivative of BGA in Y") plt.axis('scaled') giplt.contourf(x, y, bgas_dy, **args) plt.colorbar(pad=0).set_label('mGal/m') giplt.m2km() plt.sca(axes[1, 0]) plt.title("Derivative of BGA in Z") plt.axis('scaled') giplt.contourf(x, y, bgas_dz, **args) plt.colorbar(pad=0).set_label('mGal/m')
meshfile = r"d:\msh.txt" #StringIO() densfile = r"d:\den.txt" #StringIO() mesh = PrismMesh((0, 10, 0, 20, 0, 5), (5, 2, 2)) mesh.addprop('density', 1000.0 * np.random.rand(20)) mesh.dump(meshfile, densfile, 'density') #print(meshfile.getvalue().strip()) #print(densfile.getvalue().strip()) model = [] for i, layer in enumerate(mesh.layers()): for j, p in enumerate(layer): #print(i,j, p) x1 = mesh.get_layer(i)[j].x1 x2 = mesh.get_layer(i)[j].x2 y1 = mesh.get_layer(i)[j].y1 y2 = mesh.get_layer(i)[j].y2 z1 = mesh.get_layer(i)[j].z1 z2 = mesh.get_layer(i)[j].z2 den = mesh.get_layer(i)[j].props model.append(geometry.Prism(x1, x2, y1, y2, z1, z2, den)) #model.append(geometry.Prism(x1, x2, y1, y2, z1, z2, {'density': 1000})) xp, yp, zp = gridder.regular((-5, 15, -5, 25), (20, 20), z=-1) field = prism.gz(xp, yp, zp, model) plt.figure(figsize=(8, 9)) plt.axis('scaled') plt.title('forward gravity anomaly') levels = giplt.contourf(yp, xp, field, (20, 20), 15) cb = plt.colorbar() giplt.contour(yp, xp, field, (20, 20), levels, clabel=False, linewidth=0.1) plt.show()
shape = (100, 100) z0 = -500 x, y, z = gridder.regular(area, shape, z=z0) tf = giutils.contaminate(prism.tf(x, y, z, model, inc, dec), 1, seed=0) # Reduce to the pole using FFT. Since there is only induced magnetization, the # magnetization direction (sinc and sdec) is the same as the geomagnetic field pole = pftrans.reduce_to_pole(x, y, tf, shape, inc, dec, sinc=inc, sdec=dec) # Calculate the true value at the pole for comparison true = prism.tf(x, y, z, model, 90, 0, pmag=giutils.ang2vec(10, 90, 0)) fig, axes = plt.subplots(1, 3, figsize=(14, 4)) for ax in axes: ax.set_aspect('equal') plt.sca(axes[0]) plt.title("Original total field anomaly") giplt.contourf(y, x, tf, shape, 30, cmap=plt.cm.RdBu_r) plt.colorbar(pad=0).set_label('nT') giplt.m2km() plt.sca(axes[1]) plt.title("True value at pole") giplt.contourf(y, x, true, shape, 30, cmap=plt.cm.RdBu_r) plt.colorbar(pad=0).set_label('nT') giplt.m2km() plt.sca(axes[2]) plt.title("Reduced to the pole") giplt.contourf(y, x, pole, shape, 30, cmap=plt.cm.RdBu_r) plt.colorbar(pad=0).set_label('nT') giplt.m2km() plt.tight_layout() plt.show()
for i in range(len(field_gra1)): f.write('{} {} {} {}\n'.format(yp[i],xp[i],zp[i],np.array(field_gra1[i]).ravel()[0])) with open(magoutfile1, 'w') as f: f.write('! model 2 magtotal-field magnetic anomaly (nT) with 5% noise\n') f.write('{}\n'.format(len(field_mag1))) for i in range(len(field_mag1)): f.write('{} {} {} {}\n'.format(yp[i],xp[i],zp[i],np.array(field_mag1[i]).ravel()[0])) #画图 plt.figure(figsize=(16, 16)) plt.subplot(2, 2, 1) plt.axis('scaled') plt.title('model 2 gravity anomlay (mGal)') levels = giplt.contourf(yp , xp , field_gra, nshape, 15) cb = plt.colorbar(orientation='horizontal') giplt.contour(yp, xp, field_gra, nshape, levels, clabel=False, linewidth=0.1) plt.subplot(2, 2, 2) plt.axis('scaled') plt.title('model 2 magtotal-field magnetic anomaly (nT)') levels = giplt.contourf(yp , xp , field_mag, nshape, 15) cb = plt.colorbar(orientation='horizontal') giplt.contour(yp, xp, field_mag, nshape, levels, clabel=False, linewidth=0.1) plt.subplot(2, 2, 3) plt.axis('scaled') plt.title('model 2 gravity anomlay (mGal) with 5% noise') levels = giplt.contourf(yp , xp , field_gra1, nshape, 15)
area = [-5000, 5000, -5000, 5000] model = [Prism(-3000, 3000, -1000, 1000, 0, 1000, {'density': 1000})] shape = (100, 100) xp, yp, zp = gridder.regular(area, shape, z=-500) data = [ 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) ] # Calculate the 3 invariants invariants = tensor.invariants(data) data = data + invariants # and plot it plt.figure() plt.axis('scaled') plt.suptitle("Tensor and invariants (Eotvos)") titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz', 'I1', 'I2', 'I'] for i in range(len(data)): plt.subplot(3, 3, i + 1) plt.title(titles[i]) levels = 20 if i == 8: levels = np.linspace(0, 1, levels) giplt.contourf(yp, xp, data[i], shape, levels, cmap=plt.cm.RdBu_r) plt.colorbar() giplt.m2km() plt.show()
# -*- coding: utf-8 -*- """ Created on Sun Dec 2 11:36:59 2018 使用giplt画等值线图 @author: chens """ from geoist import gridder import matplotlib.pyplot as plt from geoist.vis import giplt area = [-20, 20, -50, 50] x, y = gridder.scatter(area, n=100) data = x**2 + y**2 plt.figure() plt.axis('scaled') giplt.contourf(y, x, data, shape=(50, 50), levels=30, interp=True) plt.colorbar(orientation='horizontal') plt.plot(y, x, '.k') plt.xlabel('y (East-West)') plt.ylabel('x (North-South)') plt.show()
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' ] plt.figure(figsize=(8, 9)) plt.subplots_adjust(left=0.03, right=0.95, bottom=0.05, top=0.92, hspace=0.3) plt.suptitle("Potential fields produced by a 3 prism model") for i, field in enumerate(fields): plt.subplot(4, 3, i + 3) plt.axis('scaled') plt.title(titles[i]) levels = giplt.contourf(yp * 0.001, xp * 0.001, field, shape, 15) cb = plt.colorbar() giplt.contour(yp * 0.001, xp * 0.001, field, shape, levels, clabel=False, linewidth=0.1) plt.show()
x, y, z = gridder.regular(area, shape, z=z0) gz = giutils.contaminate(prism.gz(x, y, z, model), 0.5, seed=0) height = 1000 # How much higher to go gzcontf = pftrans.upcontinue(x, y, gz, shape, height) # Compute the true value at the new height for comparison gztrue = prism.gz(x, y, z - height, model) args = dict(shape=shape, levels=20, cmap=plt.cm.RdBu_r) fig, axes = plt.subplots(1, 3, figsize=(12, 3.5)) axes = axes.ravel() plt.sca(axes[0]) plt.title("Original") plt.axis('scaled') giplt.contourf(x, y, gz, **args) plt.colorbar(pad=0).set_label('mGal') giplt.m2km() plt.sca(axes[1]) plt.title('True higher') plt.axis('scaled') giplt.contourf(y, x, gztrue, **args) plt.colorbar(pad=0).set_label('mGal') giplt.m2km() plt.sca(axes[2]) plt.title("Continued (Fourier)") plt.axis('scaled') giplt.contourf(y, x, gzcontf, **args) plt.colorbar(pad=0).set_label('mGal') giplt.m2km() plt.tight_layout()
# -*- coding: utf-8 -*- """ Created on Sun Dec 2 11:36:59 2018 使用giplt画投影地图 @author: chens """ # 3rd packages import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap # local packages from geoist.vis import giplt from geoist import gridder area = [-20, 20, -50, 50] x, y = gridder.scatter(area, n=100) data = x**2 + y**2 plt.figure() bm = giplt.basemap(area, projection='robin') giplt.draw_countries(bm) giplt.draw_coastlines(bm) giplt.contourf(y, x, data, shape=(50, 50), levels=30, interp=True, basemap=bm) plt.colorbar(orientation='horizontal') plt.show()
""" # 3rd imports import matplotlib.pyplot as plt # local imports from geoist import gridder from geoist.inversion import geometry from geoist.pfm import prism, giutils from geoist.vis import giplt model = [geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': 1000})] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-200) components = [prism.gxx, prism.gxy, prism.gxz, prism.gyy, prism.gyz, prism.gzz] print("Calculate the tensor components and contaminate with 5 Eotvos noise") ftg = [giutils.contaminate(comp(xp, yp, zp, model), 5.0) for comp in components] print("Plotting...") plt.figure(figsize=(14, 6)) plt.suptitle("Contaminated FTG data") names = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] for i, data in enumerate(ftg): plt.subplot(2, 3, i + 1) plt.title(names[i]) plt.axis('scaled') levels = giplt.contourf(xp * 0.001, yp * 0.001, data, (100, 100), 12) plt.colorbar() giplt.contour(xp * 0.001, yp * 0.001, data, shape, levels, clabel=False) plt.show()
x, y, elev = Grid2Xyz(grid1) x, y, fga = Grid2Xyz(grid2) x, y, bgas = Grid2Xyz(grid3) x, y, bgar = Grid2Xyz(grid4) shape = (grid3.getGeoDict().nx, grid3.getGeoDict().ny) height = 1000 # How much higher to go bgas_contf = pftrans.upcontinue(x, y, bgas, shape, height) args = dict(shape=shape, levels=20, cmap=plt.cm.RdBu_r) fig, axes = plt.subplots(1, 2, figsize=(10, 5)) axes = axes.ravel() plt.sca(axes[0]) plt.title("Original") plt.axis('scaled') giplt.contourf(x, y, bgas, **args) plt.colorbar(pad=0).set_label('mGal') giplt.m2km() plt.sca(axes[1]) plt.title('Upward continuation 1000m') plt.axis('scaled') giplt.contourf(x, y, bgas_contf, **args) plt.colorbar(pad=0).set_label('mGal') giplt.m2km() fig.tight_layout() fig, axes = plt.subplots(2, 2, figsize=(10, 10)) plt.sca(axes[0, 0]) plt.title("Elevation") plt.axis('scaled') giplt.contourf(x, y, elev, **args)
tesseroid.gxx(lons, lats, heights, model), tesseroid.gxy(lons, lats, heights, model), tesseroid.gxz(lons, lats, heights, model), tesseroid.gyy(lons, lats, heights, model), tesseroid.gyz(lons, lats, heights, model), tesseroid.gzz(lons, lats, heights, model) ] print("Time it took: %s" % (time.time() - start)) titles = [ 'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz' ] bm = giplt.basemap(area, 'merc') plt.figure() plt.title(titles[0]) giplt.contourf(lons, lats, fields[0], shape, 40, basemap=bm) giplt.draw_coastlines(bm) plt.colorbar() plt.figure() for i, field in enumerate(fields[1:4]): plt.subplot(1, 3, i + 1) plt.title(titles[i + 1]) giplt.contourf(lons, lats, field, shape, 40, basemap=bm) giplt.draw_coastlines(bm) plt.colorbar() plt.figure() for i, field in enumerate(fields[4:]): plt.subplot(2, 3, i + 1) plt.title(titles[i + 4]) giplt.contourf(lons, lats, field, shape, 40, basemap=bm) giplt.draw_coastlines(bm)
xp, yp, zp = gridder.regular(area, shape, z=z0) gz = giutils.contaminate(prism.gz(xp, yp, zp, model), 0.001) # Need to convert gz to SI units so that the result can be converted to Eotvos gxz = giutils.si2eotvos(pftrans.derivx(xp, yp, giutils.mgal2si(gz), shape)) gyz = giutils.si2eotvos(pftrans.derivy(xp, yp, giutils.mgal2si(gz), shape)) gzz = giutils.si2eotvos(pftrans.derivz(xp, yp, giutils.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) plt.figure() plt.title("Original gravity anomaly") plt.axis('scaled') giplt.contourf(xp, yp, gz, shape, 15) plt.colorbar(shrink=0.7) giplt.m2km() plt.figure(figsize=(14, 10)) plt.subplots_adjust(top=0.95, left=0.05, right=0.95) plt.subplot(2, 3, 1) plt.title("x deriv (contour) + true (color map)") plt.axis('scaled') levels = giplt.contourf(yp, xp, gxz_true, shape, 12) plt.colorbar(shrink=0.7) giplt.contour(yp, xp, gxz, shape, 12, color='k') giplt.m2km() plt.subplot(2, 3, 2) plt.title("y deriv (contour) + true (color map)") plt.axis('scaled')
# gridToVTK(str(work_dir/"results"),xs,ys,zs,cellData={"recover":arr.reshape(nz,ny,nx), # "orig":model_density}) # field0 = prism.gz(small_model.xp, small_model.yp, small_model.zp, small_model.mesh) shape = (nobsyx[0], nobsyx[1]) # plot field fig = plt.figure(figsize=(16, 8)) # original field axes = fig.subplots(2, 2) # plt.axis('scaled') ca = axes[0][0] plt.sca(ca) levels = giplt.contourf(small_model.yp * 0.001, small_model.xp * 0.001, field0, shape, 15) cb = plt.colorbar() giplt.contour(small_model.yp * 0.001, small_model.xp * 0.001, field0, shape, levels, clabel=False, linewidth=0.1) ca.set_title('gravity anomlay') # field from frequency ca = axes[0][1] plt.sca(ca) # levels = giplt.contourf(small_model.yp * 0.001, small_model.xp * 0.001, # small_model.obs_field, shape, 15)
kk=np.array(kernel) kk=np.transpose(kernel) #kernel matrix for inversion, 500 cells * 400 points field0=np.mat(kk)*np.transpose(np.mat(density.ravel())) field = giutils.contaminate(np.array(field0).ravel(), 0.05, percent = True) #零均值 print(field.mean()) #field = field + 300. # field.mean() #画图 plt.figure(figsize=(16, 8)) plt.subplot(1, 2, 1) plt.title('gravity anomlay') plt.axis('scaled') levels = giplt.contourf(yp * 0.001, xp * 0.001, field0, nshape, 15) cb = plt.colorbar(orientation='horizontal') giplt.contour(yp * 0.001, xp * 0.001, field0, nshape, levels, clabel=False, linewidth=0.1) plt.subplot(1, 2, 2) plt.title('gravity anomlay with 5% noise') plt.axis('scaled') levels = giplt.contourf(yp * 0.001, xp * 0.001, field, nshape, 15) cb = plt.colorbar(orientation='horizontal') giplt.contour(yp * 0.001, xp * 0.001, field, nshape, levels, clabel=False, linewidth=0.1) plt.show() print('starting inversion') smop = SmoothOperator()
depths = [0, 1000, 2000, 3000, 4000] model = [] for i in range(1, len(depths)): #axes = plt.figure().gca() #plt.axis('scaled') #for p in model: # giplt.polygon(p, '.-k', xy2ne=True) verts = [[-5000, -3000], [-5000, 4000], [5000, 3000], [2000, -5000]] model.append( geometry.PolygonalPrism( #giplt.draw_polygon(area, axes, xy2ne=True), verts, depths[i - 1], depths[i], {'density': 500})) # Calculate the effect shape = (100, 100) xp, yp, zp = gridder.regular(area, shape, z=-1) gz = polyprism.gz(xp, yp, zp, model) # and plot it plt.figure() plt.axis('scaled') plt.title("gz produced by prism model (mGal)") giplt.contourf(yp, xp, gz, shape, 20) plt.colorbar() for p in model: giplt.polygon(p, '.-k', xy2ne=True) giplt.set_area(area) plt.show()
# The regional field inc, dec = 30, -15 bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ geometry.Prism(-4000, -3000, -4000, -3000, 0, 2000, {'magnetization': giutils.ang2vec(1, inc, dec)}), geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'magnetization': giutils.ang2vec(1, inc, dec)}), # This prism will have magnetization in a different direction geometry.Prism(2000, 4000, 3000, 4000, 0, 2000, {'magnetization': giutils.ang2vec(3, -10, 45)}) ] # Create a regular grid at 100m height shape = (200, 200) area = bounds[:4] xp, yp, zp = gridder.regular(area, shape, z=-500) # Calculate the anomaly for a given regional field tf = prism.tf(xp, yp, zp, model, inc, dec) # Plot plt.figure() plt.title("Total-field anomaly (nT)") plt.axis('scaled') giplt.contourf(yp, xp, tf, shape, 15) plt.colorbar() plt.xlabel('East y (km)') plt.ylabel('North x (km)') giplt.m2km() plt.show()
0, 1000, {'density': 500}) ] # Calculate the effect shape = (100, 100) xp, yp, zp = gridder.regular(area, shape, z=-500) data = [ polyprism.gxx(xp, yp, zp, model), polyprism.gxy(xp, yp, zp, model), polyprism.gxz(xp, yp, zp, model), polyprism.gyy(xp, yp, zp, model), polyprism.gyz(xp, yp, zp, model), polyprism.gzz(xp, yp, zp, model) ] # and plot it titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] plt.figure() plt.axis('scaled') plt.suptitle("Gravity tensor produced by prism model (Eotvos)") for i in range(len(data)): plt.subplot(3, 2, i + 1) plt.title(titles[i]) giplt.contourf(yp, xp, data[i], shape, 20) plt.colorbar() for p in model: giplt.polygon(p, '.-k', xy2ne=True) giplt.set_area(area) giplt.m2km() plt.show()
## 3. wave2num if __name__ == '__main__': print('hello freqinv!') shape = (156, 156) gu, gulist, xp, yp, zp = gen_grav(shape) titles = [ 'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz' ] plt.figure(figsize=(8, 8)) plt.axis('scaled') plt.title(titles[0]) levels = giplt.contourf(yp * 0.001, xp * 0.001, gu, shape, 15) cb = plt.colorbar() giplt.contour(yp * 0.001, xp * 0.001, gu, shape, levels, clabel=False, linewidth=0.1) plt.show() plt.figure(figsize=(8, 8)) plt.axis('scaled') plt.title('gz by freq') levels = giplt.contourf(yp * 0.001, xp * 0.001, gulist, shape, 15) cb = plt.colorbar()
from geoist.inversion import geometry from geoist.pfm import prism, pftrans, giutils from geoist.vis import giplt model = [geometry.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': 10})] area = (-5000, 5000, -5000, 5000) shape = (100, 100) z0 = -500 x, y, z = gridder.regular(area, shape, z=z0) inc, dec = -30, 0 tf = giutils.contaminate(prism.tf(x, y, z, model, inc, dec), 0.001, percent=True) # Need to convert gz to SI units so that the result is also in SI total_grad_amp = pftrans.tga(x, y, giutils.nt2si(tf), shape) plt.figure() plt.subplot(1, 2, 1) plt.title("Original total field anomaly") plt.axis('scaled') giplt.contourf(y, x, tf, shape, 30, cmap=plt.cm.RdBu_r) plt.colorbar(orientation='horizontal').set_label('nT') giplt.m2km() plt.subplot(1, 2, 2) plt.title("Total Gradient Amplitude") plt.axis('scaled') giplt.contourf(y, x, total_grad_amp, shape, 30, cmap=plt.cm.RdBu_r) plt.colorbar(orientation='horizontal').set_label('nT/m') giplt.m2km() plt.show()