def test_harvest_restrict(): def fill(i, case): # Returns density of 10 for center prism and prism given by 'case' cdir = {'above': 4, 'below': 22, 'north': 14, 'south': 12, 'east': 16, 'west': 10} if i == 13: return 10 for key in cdir: if case == key and i == cdir.get(key): return 10 return 0 # The test cases as string list cases = ['above', 'below', 'north', 'south', 'east', 'west'] # Create reference model bounds = (0, 3, 0, 3, 0, 3) shape = (3, 3, 3) shapegz = (10, 10) for testcase in cases: mref = PrismMesh(bounds, shape) mesh = mref.copy() mref.addprop('density', [fill(i, testcase) for i in xrange(mref.size)]) # Calculate reference gravity field xp, yp, zp = gridder.regular(bounds[:4], shapegz, z=-1) gzref = prism.gz(xp, yp, zp, mref) # Initiate harvest hgref = [harvester.Gz(xp, yp, zp, gzref)] loc = [[1.5, 1.5, 1.5, {'density': 10}]] seeds = harvester.sow(loc, mesh) # est0 should be incorrect and thus fail wilst est1 should yield the # same geometry as mref est0, pred0 = harvester.harvest(hgref, seeds, mesh, compactness=0.1, threshold=0.001, restrict=[testcase]) est1, pred1 = harvester.harvest(hgref, seeds, mesh, compactness=0.1, threshold=0.001) res0 = mesh.copy() res0.addprop('density', est0['density']) res1 = mesh.copy() res1.addprop('density', est1['density']) l0 = [] l1 = [] for i, p in enumerate(res0): l0.append(p.props['density'] == mref[i].props['density']) for i, p in enumerate(res1): l1.append(p.props['density'] == mref[i].props['density']) assert not np.all(l0) assert np.all(l1)
# Inversion setup # Create a mesh mesh = PrismMesh(bounds, (30, 30, 30)) # Wrap the data so that harvester can use it data = [harvester.Gxx(xp, yp, zp, gxx), harvester.Gxy(xp, yp, zp, gxy), harvester.Gxz(xp, yp, zp, gxz), harvester.Gyy(xp, yp, zp, gyy), harvester.Gyz(xp, yp, zp, gyz), harvester.Gzz(xp, yp, zp, gzz)] # Make the seeds seeds = harvester.sow([ [500, 400, 210, {'density':1000}], [500, 550, 510, {'density':1000}]], mesh) # Run the inversioin estimate, predicted = harvester.harvest(data, seeds, mesh, compactness=0.5, threshold=0.001) # Put the estimated density values in the mesh mesh.addprop('density', estimate['density']) # Plot the adjustment mpl.figure() mpl.suptitle("True: color | Inversion: contour") 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, 12) mpl.colorbar() mpl.contour(yp, xp, predicted[i], shape, levels, color='k') mpl.xlabel('y (km)') mpl.ylabel('x (km)')
mesher.Prism(2000, 2500, 2000, 2500, 500, 1000, props2), mesher.Prism(7500, 8000, 5500, 6500, 500, 1000, props2), mesher.Prism(1500, 2000, 4000, 5000, 500, 1000, props2) ] area = bounds[:4] shape = (50, 50) x, y, z = gridder.regular(area, shape, z=-1) gz = utils.contaminate(prism.gz(x, y, z, model), 0.1) mesh = mesher.PrismMesh(bounds, (20, 40, 40)) seeds = harvester.sow([[5000, 5000, 1000, props]], mesh) # Run the inversion without using weights data = [harvester.Gz(x, y, z, gz)] estimate, predicted = harvester.harvest(data, seeds, mesh, compactness=1.5, threshold=0.001) mesh.addprop('density', estimate['density']) bodies = mesher.vremove(0, 'density', mesh) mpl.figure() mpl.axis('scaled') mpl.title('No weights: Observed (color) vs Predicted (black)') levels = mpl.contourf(y, x, gz, shape, 17) mpl.colorbar() mpl.contour(y, x, predicted[0], shape, levels, color='k') mpl.m2km() mpl.xlabel('East (km)') mpl.ylabel('North (km)') myv.figure() plot = myv.prisms(model, 'density', style='wireframe', linewidth=4)
shape = (3, 3, 3) shapegz = (10, 10) for testcase in cases: mref = PrismMesh(bounds, shape) mesh = mref.copy() mref.addprop('density', [fill(i, testcase) for i in xrange(mref.size)]) # Calculate reference gravity field xp, yp, zp = gridder.regular(bounds[:4], shapegz, z=-1) gzref = prism.gz(xp, yp, zp, mref) # Initiate harvest hgref = [harvester.Gz(xp, yp, zp, gzref)] loc = [[1.5, 1.5, 1.5, {'density': 10}]] seeds = harvester.sow(loc, mesh) # est0 should be incorrect and thus fail wilst est1 should yield the # same geometry as mref est0, pred0 = harvester.harvest(hgref, seeds, mesh, compactness=0.1, threshold=0.001, restrict=[testcase]) est1, pred1 = harvester.harvest(hgref, seeds, mesh, compactness=0.1, threshold=0.001) res0 = mesh.copy() res0.addprop('density', est0['density']) res1 = mesh.copy() res1.addprop('density', est1['density']) l0 = [] l1 = [] for i, p in enumerate(res0): l0.append(p.props['density'] == mref[i].props['density']) for i, p in enumerate(res1): l1.append(p.props['density'] == mref[i].props['density']) assert not np.all(l0) assert np.all(l1)