示例#1
0
文件: interp2d.py 项目: fzouari/pyEIT
def demo():
    """demo shows how to interpolate on regular/irregular grids"""
    # 1. create mesh
    mesh_obj, _ = layer_circle(n_layer=8, n_fan=6)
    pts = mesh_obj["node"]
    tri = mesh_obj["element"]

    # set anomaly
    anomaly = [{"x": 0.5, "y": 0.5, "d": 0.2, "perm": 100.0}]
    mesh_new = set_perm(mesh_obj, anomaly=anomaly)

    # 2. interpolate using averaged neighbor triangle area
    perm_node = sim2pts(pts, tri, mesh_new["perm"])

    # 3. interpolate on grids (irregular or regular) using IDW, sigmod
    xg, yg, mask = meshgrid(pts)
    im = np.ones_like(mask)
    # mapping from values on xy to values on xyi
    xy = np.mean(pts[tri], axis=1)
    xyi = np.vstack((xg.flatten(), yg.flatten())).T
    # w_mat = weight_idw(xy, xyi)
    w_mat = weight_sigmod(xy, xyi)
    im = np.dot(w_mat.T, mesh_new["perm"])
    # im = weight_linear_rbf(xy, xyi, mesh_new['perm'])
    im[mask] = 0.0
    # reshape to grid size
    im = im.reshape(xg.shape)
    # Inverse mapping
    # w_mat_T_inv = np.linalg.pinv(w_mat.T)
    w_mat_T_inv = w_mat
    mesh_new_r = np.dot(w_mat_T_inv, im)

    # plot mesh and interpolated mesh (tri2pts)
    fig, axs = plt.subplots(1, 3)
    ax1, ax2, ax3 = axs[0], axs[1], axs[2]

    ax1.set_aspect('equal')
    ax1.triplot(pts[:, 0], pts[:, 1], tri)
    im1 = ax1.tripcolor(pts[:, 0], pts[:, 1], tri, mesh_new['perm'])

    ax2.set_aspect('equal')
    ax2.triplot(pts[:, 0], pts[:, 1], tri)
    im2 = ax2.tripcolor(pts[:, 0], pts[:, 1], tri, perm_node, shading='flat')

    # plot interpolated values
    fig, ax = plt.subplots(figsize=fig_size)
    ax.set_aspect("equal")
    ax.triplot(pts[:, 0], pts[:, 1], tri, alpha=0.5)
    im3 = ax.pcolor(xg, yg, im, edgecolors=None, linewidth=0, alpha=0.8)
    fig.colorbar(im3, orientation="vertical")
    plt.show()
示例#2
0
def demo():
    """demo shows how to interpolate on regular/irregular grids"""
    # 1. create mesh
    mesh_obj, _ = layer_circle(n_layer=8, n_fan=6)
    pts = mesh_obj['node']
    tri = mesh_obj['element']

    # set anomaly
    anomaly = [{'x': 0.5, 'y': 0.5, 'd': 0.2, 'perm': 100.0}]
    mesh_new = set_perm(mesh_obj, anomaly=anomaly)

    # 2. interpolate using averaged neighbor triangle area
    perm_node = sim2pts(pts, tri, mesh_new['perm'])

    # plot mesh and interpolated mesh (tri2pts)
    fig_size = (6, 4)
    fig = plt.figure(figsize=fig_size)
    ax = fig.add_subplot(111)
    ax.set_aspect('equal')
    ax.triplot(pts[:, 0], pts[:, 1], tri)
    im1 = ax.tripcolor(pts[:, 0], pts[:, 1], tri, mesh_new['perm'])
    fig.colorbar(im1, orientation='vertical')

    fig = plt.figure(figsize=fig_size)
    ax2 = fig.add_subplot(111)
    ax2.set_aspect('equal')
    ax2.triplot(pts[:, 0], pts[:, 1], tri)
    im2 = ax2.tripcolor(pts[:, 0], pts[:, 1], tri, perm_node, shading='flat')
    fig.colorbar(im2, orientation='vertical')

    # 3. interpolate on grids (irregular or regular) using IDW, sigmod
    xg, yg, mask = meshgrid(pts)
    im = np.ones_like(mask)
    # mapping from values on xy to values on xyi
    xy = np.mean(pts[tri], axis=1)
    xyi = np.vstack((xg.flatten(), yg.flatten())).T
    # w_mat = weight_idw(xy, xyi)
    w_mat = weight_sigmod(xy, xyi)
    im = np.dot(w_mat.T, mesh_new['perm'])
    # im = weight_linear_rbf(xy, xyi, mesh_new['perm'])
    im[mask] = 0.
    # reshape to grid size
    im = im.reshape(xg.shape)

    # plot interpolated values
    fig, ax = plt.subplots(figsize=fig_size)
    ax.set_aspect('equal')
    ax.triplot(pts[:, 0], pts[:, 1], tri, alpha=0.5)
    im3 = ax.pcolor(xg, yg, im, edgecolors=None, linewidth=0, alpha=0.8)
    fig.colorbar(im3, orientation='vertical')
    plt.show()
示例#3
0
from __future__ import division, absolute_import, print_function

# numeric
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

# pyEIT
import pyeit.mesh as mesh
from pyeit.eit.interp2d import tri_area, sim2pts
from pyeit.mesh import quality
from pyeit.eit.fem import Forward
from pyeit.eit.utils import eit_scan_lines
""" 0. build mesh """
mesh_obj, el_pos = mesh.layer_circle(n_layer=8, n_fan=6)
# mesh_obj, el_pos = mesh.create()

# extract node, element, alpha
pts = mesh_obj['node']
tri = mesh_obj['element']
x, y = pts[:, 0], pts[:, 1]
quality.stats(pts, tri)


def calc_sens(fwd, ex_mat):
    """
    see Adler2017 on IEEE TBME, pp 5, figure 6,
    Electrical Impedance Tomography: Tissue Properties to Image Measures
    """
    # solving EIT problem