def get_coeff(x, y, P1, P2, P3): XY = np.asarray((x, y)) d1 = misc.dist_point_line(XY, P2, P3) / dpl1 d2 = misc.dist_point_line(XY, P1, P3) / dpl2 d3 = misc.dist_point_line(XY, P1, P2) / dpl3 dsum = d1 + d2 + d3 return np.squeeze(np.transpose([d1 / dsum, d2 / dsum, d3 / dsum]))
def _get_interp_tri(x_in, y_in, gr_x, gr_y, method=None): """ For each value (x_in, y_in) returns _indexes of the closets 3 values (Delaunay) in the (gr_x, gr_y) table, and the corresponding coefficients. @method: tri_surf', 'plan_interp' """ methods = ['tri_surf', 'plan_interp'] calling = 'interp_3D' pc.log_.message('Entering interp 3D', calling=calling) if not pc.config.INSTALLED['Triangulation']: pc.log_.error('Triangulation package not available from matplotlib.', calling=calling) return None if method is None: method = methods[0] if method not in methods: pc.log_.error('{0} is not a valid method'.format(method), calling=calling) return None n_points = np.size(x_in) indexes = np.zeros((n_points, 3), dtype=int) - 1 coeffs = np.zeros((n_points, 3)) if method == 'tri_surf': def get_coeff(x, y, P1, P2, P3): v1x = P1[0] - x v1y = P1[1] - y v2x = P2[0] - x v2y = P2[1] - y v3x = P3[0] - x v3y = P3[1] - y d1 = abs(v2x * v3y - v2y * v3x) d2 = abs(v1x * v3y - v1y * v3x) d3 = abs(v1x * v2y - v1y * v2x) dsum = d1 + d2 + d3 return np.squeeze(np.transpose([d1 / dsum, d2 / dsum, d3 / dsum])) elif method == 'plan_interp': def get_coeff(x, y, P1, P2, P3): XY = np.asarray((x, y)) d1 = misc.dist_point_line(XY, P2, P3) / dpl1 d2 = misc.dist_point_line(XY, P1, P3) / dpl2 d3 = misc.dist_point_line(XY, P1, P2) / dpl3 dsum = d1 + d2 + d3 return np.squeeze(np.transpose([d1 / dsum, d2 / dsum, d3 / dsum])) tri = Triangulation(gr_x, gr_y) pc.log_.message('Triangulation done', calling=calling) n_triangles = tri.triangle_nodes.shape[0] for i, triangle in enumerate(tri.triangle_nodes): T1 = np.asarray((gr_x[triangle[0]], gr_y[triangle[0]])) T2 = np.asarray((gr_x[triangle[1]], gr_y[triangle[1]])) T3 = np.asarray((gr_x[triangle[2]], gr_y[triangle[2]])) points_inside = misc.points_inside_triangle(x_in, y_in, T1, T2, T3) pc.log_.message('{0} points inside triangle {1} over {2}'.format( points_inside.sum(), i, n_triangles), calling=calling) if method == 'plan_interp': dpl1 = misc.dist_point_line(T1, T2, T3) dpl2 = misc.dist_point_line(T2, T3, T1) dpl3 = misc.dist_point_line(T3, T1, T2) if points_inside.sum() != 0: indexes[points_inside] = triangle coeffs[points_inside] = get_coeff(x_in[points_inside], y_in[points_inside], T1, T2, T3) return indexes, coeffs
def _get_interp_tri(x_in, y_in, gr_x, gr_y, method=None): """ For each value (x_in, y_in) returns _indexes of the closets 3 values (Delaunay) in the (gr_x, gr_y) table, and the corresponding coefficients. @method: tri_surf', 'plan_interp' """ methods = ['tri_surf', 'plan_interp'] calling = 'interp_3D' pc.log_.message('Entering interp 3D', calling = calling) if not pc.config.INSTALLED['Triangulation']: pc.log_.error('Triangulation package not available from matplotlib.', calling = calling) return None if method is None: method = methods[0] if method not in methods: pc.log_.error('{0} is not a valid method'.format(method), calling = calling) return None n_points = np.size(x_in) indexes = np.zeros((n_points, 3), dtype=int) - 1 coeffs = np.zeros((n_points, 3)) if method == 'tri_surf': def get_coeff(x, y, P1, P2, P3): v1x = P1[0]-x v1y = P1[1]-y v2x = P2[0]-x v2y = P2[1]-y v3x = P3[0]-x v3y = P3[1]-y d1 = abs(v2x*v3y-v2y*v3x) d2 = abs(v1x*v3y-v1y*v3x) d3 = abs(v1x*v2y-v1y*v2x) dsum = d1 + d2 + d3 return np.squeeze(np.transpose([d1 / dsum, d2 / dsum, d3 / dsum])) elif method == 'plan_interp': def get_coeff(x, y, P1, P2, P3): XY = np.asarray((x, y)) d1 = misc.dist_point_line(XY, P2, P3) / dpl1 d2 = misc.dist_point_line(XY, P1, P3) / dpl2 d3 = misc.dist_point_line(XY, P1, P2) / dpl3 dsum = d1 + d2 + d3 return np.squeeze(np.transpose([d1 / dsum, d2 / dsum, d3 / dsum])) tri = Triangulation(gr_x, gr_y) pc.log_.message('Triangulation done', calling = calling) n_triangles = tri.triangle_nodes.shape[0] for i, triangle in enumerate(tri.triangle_nodes): T1 = np.asarray((gr_x[triangle[0]], gr_y[triangle[0]])) T2 = np.asarray((gr_x[triangle[1]], gr_y[triangle[1]])) T3 = np.asarray((gr_x[triangle[2]], gr_y[triangle[2]])) points_inside = misc.points_inside_triangle(x_in, y_in, T1, T2, T3) pc.log_.message('{0} points inside triangle {1} over {2}'.format(points_inside.sum(), i, n_triangles), calling = calling) if method == 'plan_interp': dpl1 = misc.dist_point_line(T1, T2, T3) dpl2 = misc.dist_point_line(T2, T3, T1) dpl3 = misc.dist_point_line(T3, T1, T2) if points_inside.sum() != 0: indexes[points_inside] = triangle coeffs[points_inside] = get_coeff(x_in[points_inside], y_in[points_inside], T1, T2, T3) return indexes, coeffs