fix: 修复 ContentMapper 类体被模块级函数截断的严重 bug
问题: 批量生成专题图时报 'ContentMapper' object has no attribute 'process_data' 根因: _local_krige_block_worker (0空格缩进,模块级) 被错误地插入在 ContentMapper 类体中间 (line 819), 导致类定义在此处终止。 之后 19 个方法 (_idw_interpolation, read_csv_data, create_content_map, visualize_raster, prepare_shared_context, process_data, process_batch...) 全部脱离类变成模块级函数。 AST 验证: ContentMapper 仅剩 9 个方法。 修复: 将 _local_krige_block_worker 移至文件末尾 (模块级正确位置), ContentMapper 恢复为 28 个方法的完整类。
This commit is contained in:
@ -815,35 +815,6 @@ class ContentMapper:
|
|||||||
)
|
)
|
||||||
return np.array(z), bx_min, bx_max, by_min, by_max
|
return np.array(z), bx_min, bx_max, by_min, by_max
|
||||||
|
|
||||||
|
|
||||||
def _local_krige_block_worker(args):
|
|
||||||
"""单个局部克里金块任务(独立进程入口,必须为模块级函数)"""
|
|
||||||
(local_pts, local_vals, sub_grid_x, sub_grid_y,
|
|
||||||
bx_min, bx_max, by_min, by_max,
|
|
||||||
grid_dx, grid_dy, block_ix, block_iy, total) = args
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from pykrige.ok import OrdinaryKriging
|
|
||||||
|
|
||||||
if len(local_pts) < 3:
|
|
||||||
return (None, bx_min, bx_max, by_min, by_max)
|
|
||||||
|
|
||||||
print(f" [LocalKrige] 块 ({block_iy},{block_ix}) [{block_iy * 100 + block_ix}/{total}] "
|
|
||||||
f"采样点={len(local_pts)}, 网格={len(sub_grid_x)}×{len(sub_grid_y)}")
|
|
||||||
|
|
||||||
ok = OrdinaryKriging(
|
|
||||||
local_pts[:, 0], local_pts[:, 1], local_vals,
|
|
||||||
variogram_model='spherical',
|
|
||||||
verbose=False,
|
|
||||||
enable_plotting=False,
|
|
||||||
)
|
|
||||||
z, ss = ok.execute(
|
|
||||||
'grid', sub_grid_x, sub_grid_y,
|
|
||||||
backend='loop',
|
|
||||||
n_closest_points=min(15, len(local_pts)),
|
|
||||||
)
|
|
||||||
return (np.array(z), bx_min, bx_max, by_min, by_max)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _idw_interpolation(points, values, grid_xx, grid_yy,
|
def _idw_interpolation(points, values, grid_xx, grid_yy,
|
||||||
power=2, n_neighbors=15):
|
power=2, n_neighbors=15):
|
||||||
@ -3304,3 +3275,36 @@ if __name__ == "__main__":
|
|||||||
# resolution=50
|
# resolution=50
|
||||||
# )
|
# )
|
||||||
# """)
|
# """)
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════
|
||||||
|
# 模块级函数:多进程 worker(必须在类外部定义,供 Pool.map 使用)
|
||||||
|
# ═══════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
def _local_krige_block_worker(args):
|
||||||
|
"""单个局部克里金块任务(独立进程入口,必须为模块级函数)"""
|
||||||
|
(local_pts, local_vals, sub_grid_x, sub_grid_y,
|
||||||
|
bx_min, bx_max, by_min, by_max,
|
||||||
|
grid_dx, grid_dy, block_ix, block_iy, total) = args
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from pykrige.ok import OrdinaryKriging
|
||||||
|
|
||||||
|
if len(local_pts) < 3:
|
||||||
|
return (None, bx_min, bx_max, by_min, by_max)
|
||||||
|
|
||||||
|
print(f" [LocalKrige] 块 ({block_iy},{block_ix}) [{block_iy * 100 + block_ix}/{total}] "
|
||||||
|
f"采样点={len(local_pts)}, 网格={len(sub_grid_x)}×{len(sub_grid_y)}")
|
||||||
|
|
||||||
|
ok = OrdinaryKriging(
|
||||||
|
local_pts[:, 0], local_pts[:, 1], local_vals,
|
||||||
|
variogram_model='spherical',
|
||||||
|
verbose=False,
|
||||||
|
enable_plotting=False,
|
||||||
|
)
|
||||||
|
z, ss = ok.execute(
|
||||||
|
'grid', sub_grid_x, sub_grid_y,
|
||||||
|
backend='loop',
|
||||||
|
n_closest_points=min(15, len(local_pts)),
|
||||||
|
)
|
||||||
|
return (np.array(z), bx_min, bx_max, by_min, by_max)
|
||||||
|
|||||||
Reference in New Issue
Block a user