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) cb = plt.colorbar(orientation='horizontal') giplt.contour(yp, xp, field_gra1, nshape, levels, clabel=False, linewidth=0.1)
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() giplt.contour(yp * 0.001, xp * 0.001, gulist, shape, levels,
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() nz = shape[0] ny = shape[1] nx = shape[2]
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()
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') levels = giplt.contourf(yp, xp, gyz_true, shape, 12) plt.colorbar(shrink=0.7) giplt.contour(yp, xp, gyz, shape, 12, color='k') giplt.m2km() plt.subplot(2, 3, 3) plt.title("z deriv (contour) + true (color map)") plt.axis('scaled') levels = giplt.contourf(yp, xp, gzz_true, shape, 8) plt.colorbar(shrink=0.7) giplt.contour(yp, xp, gzz, shape, levels, color='k') giplt.m2km()
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 = (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) levels = giplt.contourf(small_model.yp * 0.001, small_model.xp * 0.001, small_model.obs_field, shape, 15) cb = plt.colorbar() giplt.contour(small_model.yp * 0.001, small_model.xp * 0.001,
""" # 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()
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 plt.figure(figsize=(14, 5)) plt.subplot(1, 2, 1) plt.title("Total Field Anomaly (nT)", fontsize=14) plt.axis('scaled') nlevels = giplt.contour(y, x, tf, (50, 50), 15, interp=True, color='r', label='Observed', linewidth=2.0) giplt.contour(y, x, solver.predicted(), (50, 50), nlevels, interp=True, color='b', label='Predicted', style='dashed', linewidth=2.0) plt.legend(loc='upper left', shadow=True, prop={'size': 13}) plt.xlabel('East y (m)', fontsize=14) plt.ylabel('North x (m)', fontsize=14)