np.meshgrid()与网络表格

数组是如何绘制表格的?

我们先将两个数组传入np.meshgrid(),查看该函数是如何绘制网格的。

import numpy as np

x = np.linspace(-2, 2, 5)
y = np.linspace(-2, 2, 5)

X, Y = np.meshgrid(x, y)
Z = X**2 + Y**2 - 1

print("X显示:","\n",X)
print("Y显示:","\n",Y)

输出的结果是:

X显示: 
 [[-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]]
Y显示: 
 [[-2. -2. -2. -2. -2.]
 [-1. -1. -1. -1. -1.]
 [ 0.  0.  0.  0.  0.]
 [ 1.  1.  1.  1.  1.]
 [ 2.  2.  2.  2.  2.]]

通过观察我们发现,经过X, Y = np.meshgrid(x, y)操作,它将我们的x数据纵向复制了5份,而将Y 转置之后横向复制了5份。

分别绘制X和Y图像

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-2, 2, 5)
y = np.linspace(-2, 2, 5)

X, Y = np.meshgrid(x, y)
Z = X**2 + Y**2 - 1

print("X显示:","\n",X)
print("Y显示:","\n",Y)
plt.figure()
plt.plot(X, Y, color='red',marker='*',linestyle='--')
plt.grid(True)

X, Y = np.meshgrid(x, y,indexing='ij')
Z = X**2 + Y**2 - 1
plt.figure()
plt.plot(X, Y, color='red',marker='*',linestyle='--')
plt.grid(True)
plt.show()

绘制出来的结果显示为:
在这里插入图片描述
在这里插入图片描述

绘制等高线

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-2, 2, 5)
y = np.linspace(-2, 2, 5)


X, Y = np.meshgrid(x, y,indexing='ij')
Z = X**2 + Y**2 - 1
plt.figure()
plt.plot(X, Y, color='red',marker='*',linestyle='--')
plt.grid(True)

fig, (ax1, ax2) = plt.subplots(2)
ax1.contourf(X, Y, Z)
ax2.contour(X, Y, Z)  # 与contourf区别在于不同高度面不填充颜色


plt.figure()
ax = plt.gca()
cor = ax.contour(X, Y, Z, [-1, 0, 1, 3])
plt.clabel(cor, fontsize=10)
plt.grid(True)
plt.show()

图像显示如下:
在这里插入图片描述
在这里插入图片描述

参考:
https://blog.youkuaiyun.com/goodgoodstudyddp/article/details/106436558
https://blog.youkuaiyun.com/qq_38701868/article/details/99694048

def create_gabor_filter(theta, sigma=2.5, frequency=0.25, phase=0): """Create a 2D Gabor filter with specified parameters""" size = 19 x, y = np.meshgrid(np.linspace(-1, 1, size), np.linspace(-1, 1, size)) x_rot = x * np.cos(theta) + y * np.sin(theta) y_rot = -x * np.sin(theta) + y * np.cos(theta) gabor = np.exp(-(x_rot**2 + (y_rot**2)*2) / (2 * sigma**2)) * \ np.cos(2 * np.pi * frequency * x_rot + phase) max_val = np.max(gabor) min_val = np.min(gabor) if max_val != min_val: gabor = (gabor - min_val) / (max_val - min_val) gabor = gabor - 0.5 return gabor num_filters = 6 thetas =[0, np.pi/4, np.pi/2.0,0, np.pi/4, np.pi/2.0] sigmas = np.linspace(1.2, 4.0, num_filters) frequencies = [0.05,0.05,0.05,0.1,0.1,0.1] phases = np.random.choice([0, np.pi/2, np.pi, 3*np.pi/2], num_filters) gabor_filters = [ create_gabor_filter( theta=thetas[i], sigma=sigmas[i], frequency=frequencies[i], phase=phases[i] ) for i in range(num_filters) ] plt.figure(figsize=(12, 8)) for i, filt in enumerate(gabor_filters): plt.subplot(2, 3, i + 1) plt.imshow(filt, cmap='coolwarm', vmin=-0.5, vmax=0.5) plt.title(f'{int(thetas[i] * 180 / np.pi)}°(frequency:{frequencies[i]})', fontsize=10) plt.axis('off') plt.suptitle('Gabor Filters ', x=0.5,y=0.99, fontsize=16) plt.tight_layout() plt.show() gabor_features = [convolve(M, filt, mode='nearest') for filt in gabor_filters] cmap = 'inferno' plt.figure(figsize=(12, 8)) for i, feat in enumerate(gabor_features): plt.subplot(2,3, i+1 ) plt.imshow( feat, cmap=cmap, vmin=np.percentile(feat, 5), vmax=np.percentile(feat, 95) ) plt.title(f'{int(thetas[i] * 180 / np.pi)}°(frequency:{frequencies[i]})', fontsize=10) plt.axis('off') plt.suptitle('Gabor Filter Responses', y=0.99, fontsize=16) plt.tight_layout() plt.show() 目前已有以上代码,请你添加一部分代码计算几种gabor filter应用到例图M上的的相应强度并打印
09-18
你是一位matlabpython代码资深专家,要求将下列python代码改为matlab代码,要报错 ##import numpy as npimport matplotlib.pyplot as plt# 中文的使用import matplotlib as mplmpl.rcParams["font.sans-serif"]=["kaiti"]mpl.rcParams["axes.unicode_minus"]=Falsefrom matplotlib import cbookfrom matplotlib import cmfrom matplotlib.colors import LightSourceimport pandas as pdfrom mpl_toolkits.mplot3d import axes3ddata = pd.read_excel(r"E:\zm\附件.xlsx",index_col=0) # 《《《《要改路径z = data.valuesz = z.max()-z# Load and format datanrows, ncols = z.shapex = np.linspace(0, 4, ncols)y = np.linspace(0, 5, nrows)x, y = np.meshgrid(x, y)# region = np.s_[5:50, 5:50]# x, y, z = x[region], y[region], z[region]# Set up plotfig, ax = plt.subplots(subplot_kw=dict(projection='3d'))ls = LightSource(270, 45)# To use a custom hillshading mode, override the built-in shading and pass# in the rgb colors of the shaded surface calculated from "shade".rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,linewidth=0, antialiased=False, shade=False)ax.set_zticks(np.linspace(0,z.max(),8),np.round(np.linspace(0,z.max(),8)[::-1],2))#plt.savefig(r"E:\zm\1.png",dpi = 1000)plt.show()import numpy as npimport pandas as pdDe = lambda D0,y,ap,bp:D0-y*np.sin((bp-90)*np.pi/180)*np.tan(ap*np.pi/180)D =lambda x,De,po:(De-x*np.tan(po*np.pi/180))po = lambda ap,bp: np.arctan(np.cos((bp-90)*np.pi/180)*np.tan(ap*np.pi/180))*180/np.piW = lambda D,x,po: (D-x*np.tan(po*np.pi/180))*(np.sin((th/2)*np.pi/180)/np.sin((90-po-th/2)*np.pi/180)+np.sin((th/2)*np.pi/180)/np.sin((90+po-th/2)*np.pi/180))*np.cos((po)*np.pi/180)YT= lambda d,po: d*(np.sin((90+th/2)*np.pi/180)/np.sin((90-th/2-po)*np.pi/180))*np.cos(po*np.pi/180)y = np.arange(0,2.4,0.3)*1852apk = [0.39983871280891276]D0 = 84.4th = 120dd = [0]while dd[-1]<((5+5-3.3999999999999995)*4/((5-3.3999999999999995)**2+4**2)**0.5)*1852: di = np.arange(0,1000,1) dd+= [dd[-1]+di[np.argmin(np.abs((W(D0,dd[-1]+di,apk[-1])-YT(di,apk[-1]))/W(D0,dd[-1]+di,apk[-1]))-0.1)]] print(dd[-1]) #apk += [apk[-1] -(apk[0]-0.3)*dd[-1]/(5*4/((5-3.3999999999999995)**2+4**2)**0.5)*1852]# dd = [257.95,1257.94,2257.9300000000003,3087.21,4087.2,5087.19,6087.179999999999,7087.169999999999,7506.629999999999,8506.619999999999]# print(dd)xx = 5 - (np.array(dd)*((5-3.3999999999999995)**2+4**2)**0.5/4)/1852# xx = [4.84998885,4.26844339,3.68689793,3.20462909,2.62308363,2.04153817,1.45999271,0.87844725,0.63450975,0.05296429]# while xx[-1]>3.3999999999999995-5:# xx += [xx[-1]-(0.63450975-0.05296429)]print(xx)
07-07
import numpy as np import pandas as pd import os import rasterio import numpy as np import os import pandas as pd # 参数设置 cellsize = 5 k = 5 pi = np.pi # 获取桌面路径 desktop = os.path.join(os.path.expanduser("~"), "Desktop") filename = "map.tif" file_path = os.path.join(desktop, filename) # 读取栅格数据 def read_map(file_path): with rasterio.open(file_path) as src: map_data = src.read(1) return map_data # 坡度计算函数(向量化) def podu_vectorized(map_data): # 使用卷积核计算 dx 和 dy kernel_x = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) * k / (8 * cellsize) kernel_y = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) * k / (8 * cellsize) dx = convolve2d(map_data, kernel_x, mode='same', boundary='symm') dy = convolve2d(map_data, kernel_y, mode='same', boundary='symm') slope_rad = np.arctan(np.hypot(dx, dy)) slope_deg = np.degrees(slope_rad) return np.round(slope_deg, 4) # 假设你已经有的 NumPy 数组如下: # slope_data: (H, W) 形状的二维数组,表示每个点的坡度 # normals_data: (H, W, 3) 形状的三维数组,表示每个点的法向量 [x, y, z] # 示例数据模拟(请替换为你自己的实际数据) H, W = 12500, 12500 slope_data = np.random.uniform(0, 45, size=(H, W)) # 模拟坡度数据 normals_data = np.random.randn(H, W, 3) # 模拟法向量数据 normals_data /= np.linalg.norm(normals_data, axis=2)[..., np.newaxis] # 单位化法向量 # 获取桌面路径 desktop = os.path.join(os.path.expanduser("~"), "Desktop") # 构建坐标网格 x_coords = np.arange(W) y_coords = np.arange(H) xx, yy = np.meshgrid(x_coords, y_coords) # 将数据展平为一维数组用于构建 DataFrame df_slope = pd.DataFrame({ 'x': xx.flatten(), 'y': yy.flatten(), 'slope': slope_data.flatten() }) df_normals = pd.DataFrame({ 'x': xx.flatten(), 'y': yy.flatten(), 'normal_x': normals_data[:, :, 0].flatten(), 'normal_y': normals_data[:, :, 1].flatten(), 'normal_z': normals_data[:, :, 2].flatten() }) # 保存为 CSV 文件 slope_file = os.path.join(desktop, "slope_with_coords.csv") normals_file = os.path.join(desktop, "normals_with_coords.csv") df_slope.to_csv(slope_file, index=False) df_normals.to_csv(normals_file, index=False) print(f"坡度数据已保存至 {slope_file}") print(f"法向量数据已保存至 {normals_file}")
07-14
将整个海域进行分区,分为3*3共9个区域,并分别对每个区域进行最小二乘法拟合,完成图像输出以及相关数据输出(平面方程,拟合质量评估 import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy.spatial import KDTree from tqdm import tqdm from concurrent.futures import ProcessPoolExecutor import matplotlib plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False #读取数据 def read_data(file_path): df = pd.read_excel(file_path, header=None) data = df.values x_coords_nautical = data[0, 1:].astype(float) x_coords_meter = x_coords_nautical * 1852 y_coords_meter = [] depth_data_meter = [] for i in range(1, len(data)): y_coords_meter.append(float(data[i, 0]) * 1852) depth_data_meter.append(data[i, 1:].astype(float)) return np.array(depth_data_meter), np.array(x_coords_meter), np.array(y_coords_meter) #最小二乘法拟合 def least_squares_fit(x_coords, y_coords, depth_data): X, Y = np.meshgrid(x_coords, y_coords) A = np.column_stack((X.flatten()[:, np.newaxis], Y.flatten()[:, np.newaxis], np.ones((X.size, 1)))) B = depth_data.flatten() coefficients, residuals, rank, s = np.linalg.lstsq(A, B, rcond=None) a, b, c = coefficients Z_fit = a * X + b * Y + c residuals = depth_data - Z_fit ssr = np.sum(residuals**2) y_mean = np.mean(depth_data) sst = np.sum((depth_data - y_mean)**2) ssr_model = np.sum((Z_fit - y_mean)**2) r_squared = 1 - ssr / sst mse = ssr / (depth_data.size - 3) return a, b, c, ssr, r_squared, mse #评估 def evaluate_fit(depth_data, Z_fit): residuals = depth_data - Z_fit #残差平方和(SSR) ssr = np.sum(residuals**2) #总平方和(SST) y_mean = np.mean(depth_data) sst = np.sum((depth_data - y_mean)**2) #回归平方和(SSR_model) ssr_model = np.sum((Z_fit - y_mean)**2) #决定系数R² r_squared = 1 - ssr / sst #调整后的决定系数R²_adj(考虑变量数量) n = depth_data.size # 样本数量 p = 2 # 自变量数量 r_squared_adj = 1 - (1 - r_squared) * (n - 1) / (n - p - 1) #均方误差(MSE) mse = ssr / (n - p - 1) # 自由度调整 #平均绝对误差(MAE) mae = np.mean(np.abs(residuals)) #平均绝对百分比误差(MAPE) mape = np.mean(np.abs(residuals / depth_data)) * 100 return { 'SSR': ssr, 'SST': sst, 'SSR_model': ssr_model, 'R_squared': r_squared, 'R_squared_adj': r_squared_adj, 'MSE': mse, 'MAE': mae, 'MAPE': mape } #3d def plot_seafloor(x_coords, y_coords, depth_data): X, Y = np.meshgrid(x_coords, y_coords) fig = plt.figure(figsize=(12, 8)) ax = fig.add_subplot(111, projection='3d') surf = ax.plot_surface(X, Y, depth_data, cmap='terrain', linewidth=0, antialiased=True) fig.colorbar(surf, shrink=0.5, aspect=5, label='水深 (米)') ax.set_xlabel('东西方向位置 (米)') ax.set_ylabel('南北方向位置 (米)') ax.set_zlabel('水深 (米)') ax.set_title('三维海底地形图') ax.view_init(elev=35, azim=-45) plt.tight_layout() plt.savefig("seafloor_terrain.png", dpi=300, bbox_inches='tight') plt.show() #2d def plot_depth_contour(x_coords, y_coords, depth_data): X, Y = np.meshgrid(x_coords, y_coords) plt.figure(figsize=(12, 8)) contour = plt.contourf(X, Y, depth_data, levels=100, cmap='terrain') plt.colorbar(contour, label='水深 (米)') cline = plt.contour(X, Y, depth_data, levels=100, colors='black', linewidths=0.5) plt.clabel(cline, inline=True, fontsize=8) plt.xlabel('东西方向位置 (米)') plt.ylabel('南北方向位置 (米)') plt.title('二维水深等高线图') plt.tight_layout() plt.savefig("depth_contour.png", dpi=300, bbox_inches='tight') plt.show() #最小二乘法拟合3d def plot_fitted_plane(x_coords, y_coords, depth_data, a, b, c): X, Y = np.meshgrid(x_coords, y_coords) Z = a * X + b * Y + c fig = plt.figure(figsize=(12, 8)) ax = fig.add_subplot(111, projection='3d') surf_real = ax.plot_surface(X, Y, depth_data, cmap='terrain', linewidth=0, antialiased=True, alpha=0.7) surf_fit = ax.plot_surface(X, Y, Z, cmap='viridis', linewidth=0, antialiased=True, alpha=0.7) fig.colorbar(surf_real, shrink=0.5, aspect=5, label='水深 (米)') ax.set_xlabel('东西方向位置 (米)') ax.set_ylabel('南北方向位置 (米)') ax.set_zlabel('水深 (米)') ax.set_title('海底地形最小二乘法拟合平面') ax.view_init(elev=35, azim=-45) plt.tight_layout() plt.savefig("fitted_plane.png", dpi=300, bbox_inches='tight') plt.show() #最小二乘法拟合2d def plot_fitted_contour(x_coords, y_coords, depth_data, a, b, c): X, Y = np.meshgrid(x_coords, y_coords) Z = a * X + b * Y + c plt.figure(figsize=(12, 8)) contour_real = plt.contourf(X, Y, depth_data, levels=50, cmap='terrain', alpha=0.7) contour_fit = plt.contour(X, Y, Z, levels=20, cmap='viridis', linewidths=2) plt.colorbar(contour_real, label='水深 (米)') plt.clabel(contour_fit, inline=True, fontsize=8) plt.xlabel('东西方向位置 (米)') plt.ylabel('南北方向位置 (米)') plt.title('原始海底地形最小二乘法拟合等高线') plt.tight_layout() plt.savefig("fitted_contour.png", dpi=300, bbox_inches='tight') plt.show() #主程序 if __name__ == "__main__": file_path = "C:/Users/Yeah/Desktop/数模/第七题/B题/附件(数据).xlsx" depth_data, x_coords, y_coords = read_data(file_path) #实际地形图 plot_seafloor(x_coords, y_coords, depth_data) plot_depth_contour(x_coords, y_coords, depth_data) #最小二乘法拟合 a, b, c, ssr, r_squared, mse = least_squares_fit(x_coords, y_coords, depth_data) print(f"\n最小二乘法拟合结果:") print(f"平面方程: z = {a:.4f}x + {b:.4f}y + {c:.4f}") print(f"其中x为东西方向,y为南北方向,z为水深") #评估指标 print(f"\n拟合质量评估:") print(f"残差平方和 (SSR): {ssr:.4f}") print(f"决定系数 (R²): {r_squared:.4f}") print(f"均方误差 (MSE): {mse:.4f}") #拟合图像 plot_fitted_plane(x_coords, y_coords, depth_data, a, b, c) plot_fitted_contour(x_coords, y_coords, depth_data, a, b, c)
08-27
检查输出,预估计算时间(表格数据250*200个) import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy.spatial import KDTree from tqdm import tqdm from concurrent.futures import ProcessPoolExecutor def read_data(file_path): df = pd.read_excel(file_path, header=None) data = df.values x_coords_nautical = data[0, 1:].astype(float) x_coords_meter = x_coords_nautical * 1852 y_coords_meter = [] depth_data_meter = [] for i in range(1, len(data)): y_coords_meter.append(float(data[i, 0]) * 1852) depth_data_meter.append(data[i, 1:].astype(float)) return np.array(depth_data_meter), np.array(x_coords_meter), np.array(y_coords_meter) def calculate_gradient(depth_data): grad_x, grad_y = np.gradient(depth_data) return grad_x, grad_y def build_coord_tree(x_coords, y_coords): X, Y = np.meshgrid(x_coords, y_coords) coords = np.column_stack((X.ravel(), Y.ravel())) tree = KDTree(coords) return tree, X, Y def find_depth(x, y, tree, depth_data, X, Y): x_clipped = np.clip(x, X[0, 0], X[-1, -1]) y_clipped = np.clip(y, Y[0, 0], Y[-1, -1]) _, idx = tree.query((x_clipped, y_clipped)) return X.ravel()[idx], Y.ravel()[idx], depth_data.ravel()[idx] def compute_coverage_width(D): return D * np.tan(np.radians(60)) # 半角 60°,开角 120° def dynamic_parallel_spacing(D): W = compute_coverage_width(D) return W * (1 - 0.15) # 15% 重叠率 def build_coverage_map(x_coords, y_coords, points): coverage_map = np.zeros((len(y_coords), len(x_coords)), dtype=bool) for x, y, _ in points: xi = np.argmin(np.abs(x_coords - x)) yi = np.argmin(np.abs(y_coords - y)) coverage_map[yi, xi] = True return coverage_map def adaptive_survey(x_coords, y_coords, depth_data, grad_threshold=0.05, sector_radius=200, num_sector_lines=12, sector_angle=60): X, Y = np.meshgrid(x_coords, y_coords) grad_x, grad_y = calculate_gradient(depth_data) grad_magnitude = np.sqrt(grad_x ** 2 + grad_y ** 2) tree, _, _ = build_coord_tree(x_coords, y_coords) all_points = [] coverage_map = np.zeros_like(depth_data, dtype=bool) pbar = tqdm(total=len(y_coords) * len(x_coords), desc="布设测线进度", unit="cell") for i in range(len(y_coords)): for j in range(len(x_coords)): pbar.update(1) x_center = x_coords[j] y_center = y_coords[i] depth_center = depth_data[i, j] grad = grad_magnitude[i, j] if grad < grad_threshold: if grad > 0: angle = np.arctan2(grad_y[i, j], grad_x[i, j]) - np.pi / 2 else: angle = 0 coverage_width = compute_coverage_width(depth_center) spacing = dynamic_parallel_spacing(coverage_width) x_start = x_center - spacing * np.cos(angle) * 2 y_start = y_center - spacing * np.sin(angle) * 2 x_end = x_center + spacing * np.cos(angle) * 2 y_end = y_center + spacing * np.sin(angle) * 2 x_line = np.linspace(x_start, x_end, 10) y_line = np.linspace(y_start, y_end, 10) for x, y in zip(x_line, y_line): _, _, depth = find_depth(x, y, tree, depth_data, X, Y) all_points.append((x, y, depth)) xi = np.argmin(np.abs(x_coords - x)) yi = np.argmin(np.abs(y_coords - y)) coverage_map[yi, xi] = True else: angles = np.linspace(-np.radians(sector_angle / 2), np.radians(sector_angle / 2), num_sector_lines) for angle in angles: x_end = x_center + sector_radius * np.cos(angle) y_end = y_center + sector_radius * np.sin(angle) x_end = np.clip(x_end, x_coords.min(), x_coords.max()) y_end = np.clip(y_end, y_coords.min(), y_coords.max()) x_line = np.linspace(x_center, x_end, 8) y_line = np.linspace(y_center, y_end, 8) for x, y in zip(x_line, y_line): _, _, depth = find_depth(x, y, tree, depth_data, X, Y) all_points.append((x, y, depth)) xi = np.argmin(np.abs(x_coords - x)) yi = np.argmin(np.abs(y_coords - y)) coverage_map[yi, xi] = True pbar.close() return all_points, coverage_map def optimize_path(points): if not points: return [] path = [points[0]] remaining = points[1:] while remaining: last = path[-1] distances = [np.hypot(p[0] - last[0], p[1] - last[1]) for p in remaining] nearest_idx = np.argmin(distances) path.append(remaining.pop(nearest_idx)) return path def plot_coverage(x_coords, y_coords, coverage_map, filename="coverage_map.png"): plt.figure(figsize=(10, 8)) plt.imshow(coverage_map, cmap='gray_r', origin='lower', extent=[x_coords[0], x_coords[-1], y_coords[0], y_coords[-1]]) plt.title("测线覆盖图") plt.xlabel("X 坐标 (米)") plt.ylabel("Y 坐标 (米)") plt.colorbar(label='覆盖状态') plt.grid(False) plt.savefig(filename) plt.close() def plot_survey_path_colored(points, filename="survey_path_colored.png"): points_array = np.array(points) plt.figure(figsize=(10, 8)) sc = plt.scatter(points_array[:, 0], points_array[:, 1], c=points_array[:, 2], cmap='viridis', s=2) plt.colorbar(sc, label="深度 (米)") plt.title("测线路径图(按深度着色)") plt.xlabel("X 坐标 (米)") plt.ylabel("Y 坐标 (米)") plt.grid(True) plt.savefig(filename) plt.close() def save_to_csv(points, filename="survey_points.csv"): df = pd.DataFrame(points, columns=["x", "y", "depth"]) df.to_csv(filename, index=False) # 主程序入口 if __name__ == "__main__": file_path = "C:/Users/Yeah/Desktop/数模/第七题/B题/附件(数据).xlsx" depth_data, x_coords, y_coords = read_data(file_path) all_points, coverage_map = adaptive_survey(x_coords, y_coords, depth_data) optimized_path = optimize_path(all_points) plot_coverage(x_coords, y_coords, coverage_map) plot_survey_path_colored(all_points) uncovered_ratio = np.sum(~coverage_map) / coverage_map.size * 100 total_length = sum(np.hypot(p2[0]-p1[0], p2[1]-p1[1]) for p1, p2 in zip(optimized_path, optimized_path[1:])) print(f"未覆盖区域占比: {uncovered_ratio:.2f}%") print(f"测线总长度: {total_length:.2f} 米") print(f"总测量点数: {len(all_points)}") save_to_csv(all_points)
08-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dream_Bri

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值