fix: 精确栅格化竞对信号
This commit is contained in:
@@ -128,6 +128,8 @@ QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如
|
||||
|
||||
正采样量 Grid 的 `ssb_rsrp_dl > 0` 或空值透明。有效像元 alpha 为 `191`,约 75% 不透明度。
|
||||
|
||||
竟对信号按 Grid 原始多边形进行像元中心栅格化,不再直接填满几何外包矩形。只有像元中心落在通过筛选的 Grid 内部时才着色,可避免相邻合格 Grid 的边界像元覆盖到被排除 Grid。单市场图和全量图使用同一套精确几何规则。
|
||||
|
||||
## 图例说明文件
|
||||
|
||||
每次运行会在 `output/` 根目录更新两份独立图例文件,不重复放入各市场 ZIP:
|
||||
|
||||
@@ -169,6 +169,11 @@
|
||||
- 汇总用户量性能优化保持逐市场计算口径:每个市场继续使用自身 4G+5G 合并结果和市场级阈值,但只分配有效记录像元范围加 `HEATMAP_SMOOTH_RADIUS` 边距的局部数组,再按原顺序写入全量画布。
|
||||
- 局部渲染不拼接、不重采样单市场 TIFF,汇总像元大小、全量画布原点、阈值、平滑半径和市场覆盖顺序均保持不变;新增 `render_scope = market_local_window` 和逐市场 `render_window`/`render_buffer_pixels` 便于追踪优化效果。
|
||||
|
||||
## 2026-07-27
|
||||
- 排查 `grid20_id = 524518003`:其移动弱覆盖占比为 `13 / 55 = 23.64%`,筛选函数已正确排除;现有 TIF 中中心像元透明,但外包矩形的 20 个像元有 10 个被周边合格 Grid 的 `floor/ceil` 像元窗口重叠着色。
|
||||
- 竟对信号由外包矩形填色改为原始 Grid 多边形的像元中心栅格化。只有像元中心位于合格几何内部时才累计 RSRP 或设置零采样红色,从而隔离相邻 Grid;用户量渲染逻辑不变。
|
||||
- 单市场和全量竟对信号共用 `export_market_grid_outputs`,因此均采用同一精确几何规则;`summary.json` 的竟对信号结果新增 `geometry_rasterization = pixel_center_inside_polygon` 和 `exact_geometry_pixels`。
|
||||
|
||||
## 2026-08-03
|
||||
- 按当前 `main.py` 输入依赖清理 `source/` 本地数据:删除已由 `GridMap.gpkg` 替代的 `MarketMap.gpkg`,以及主流程不再要求或打开的 `Building.gpkg`。
|
||||
- 当前 `source/` 必需文件保留为 `GridMap.gpkg`、`Grid_5G.gpkg`、`Grid_4G.gpkg`、`BuildingInfo.gpkg`、`CellData.gpkg` 和 `GIS.qgz`;同步移除未使用的 `BUILDING_GPKG` 常量。
|
||||
|
||||
@@ -139,6 +139,8 @@ flowchart LR
|
||||
|
||||
未通过筛选的位置保持透明;对于竟对 MR 总采样点大于 `0` 的 Grid,`ssb_rsrp_dl` 为空或大于 `0` 时也保持透明。该模型保留 Grid 边界和原始 RSRP 档位,便于在 QGIS 中精确定位目标栅格。
|
||||
|
||||
竟对信号采用原始 Grid 多边形的像元中心栅格化:只有像元中心位于合格 Grid 内部时才写入颜色,不再按几何外包矩形整块填色。该规则同时用于单市场和全量图,可避免相邻合格 Grid 的边界像元串入被排除 Grid。
|
||||
|
||||
### 7. GeoPackage 图层结构与样式保留
|
||||
|
||||
建筑信息成果并非普通属性表导出,而是保留为标准 GeoPackage 空间图层。
|
||||
|
||||
@@ -1128,6 +1128,14 @@ def pixel_window_for_bounds(bounds, minx, maxy, pixel_width, pixel_height, width
|
||||
return row_start, row_stop, col_start, col_stop
|
||||
|
||||
|
||||
def pixel_center_mask_for_geometry(geometry, window, minx, maxy, pixel_width, pixel_height):
|
||||
row_start, row_stop, col_start, col_stop = window
|
||||
x_coordinates = minx + (np.arange(col_start, col_stop, dtype=np.float64) + 0.5) * pixel_width
|
||||
y_coordinates = maxy - (np.arange(row_start, row_stop, dtype=np.float64) + 0.5) * pixel_height
|
||||
x_grid, y_grid = np.meshgrid(x_coordinates, y_coordinates)
|
||||
return np.asarray(shapely.contains_xy(geometry, x_grid, y_grid), dtype=bool)
|
||||
|
||||
|
||||
def pixel_window_from_point(x, y, minx, maxy, pixel_width, pixel_height, width, height):
|
||||
col = int((x - minx) / pixel_width)
|
||||
row = int((maxy - y) / pixel_height)
|
||||
@@ -1698,10 +1706,20 @@ def export_market_grid_outputs(
|
||||
MOBILE_TOTAL_FIELD,
|
||||
MOBILE_WEAK_COVER_FIELD,
|
||||
)
|
||||
skipped_no_value = {field: 0 for field in raster_fields}
|
||||
painted_cells = {field: 0 for field in raster_fields}
|
||||
raster_cells = []
|
||||
user_count_records = {}
|
||||
competitor_signal_value_sum = np.zeros((height, width), dtype=np.float32)
|
||||
competitor_signal_value_weight = np.zeros((height, width), dtype=np.uint16)
|
||||
zero_total_mask = np.zeros((height, width), dtype=bool)
|
||||
competitor_signal_cells = 0
|
||||
zero_total_cells = 0
|
||||
exact_geometry_pixels = 0
|
||||
exclusion_counts = {
|
||||
"invalid_fields": 0,
|
||||
"mobile_weak_ratio": 0,
|
||||
"competitor_weak_ratio": 0,
|
||||
"invalid_rsrp": 0,
|
||||
"no_center_pixels": 0,
|
||||
}
|
||||
|
||||
fields = list(
|
||||
dict.fromkeys(
|
||||
@@ -1750,9 +1768,6 @@ def export_market_grid_outputs(
|
||||
for index, row in enumerate(batch_rows):
|
||||
values = dict(zip(fields, row[2:]))
|
||||
numeric_values = {field: to_float(values.get(field)) for field in raster_fields}
|
||||
for field, value in numeric_values.items():
|
||||
if value is None:
|
||||
skipped_no_value[field] += 1
|
||||
|
||||
if not valid_mask[index]:
|
||||
continue
|
||||
@@ -1784,23 +1799,6 @@ def export_market_grid_outputs(
|
||||
if window is None:
|
||||
continue
|
||||
|
||||
row_start, row_stop, col_start, col_stop = window
|
||||
for field, value in numeric_values.items():
|
||||
if value is not None:
|
||||
painted_cells[field] += 1
|
||||
raster_cells.append(
|
||||
(
|
||||
row_start,
|
||||
row_stop,
|
||||
col_start,
|
||||
col_stop,
|
||||
numeric_values[EXCELLENT_CELL_FIELD],
|
||||
numeric_values[RSRP_FIELD],
|
||||
numeric_values[WEAK_COVER_FIELD],
|
||||
numeric_values[MOBILE_TOTAL_FIELD],
|
||||
numeric_values[MOBILE_WEAK_COVER_FIELD],
|
||||
)
|
||||
)
|
||||
if user_count_path is not None:
|
||||
user_count_5g_clipped_rows += 1
|
||||
if not merge_user_count_record(
|
||||
@@ -1812,6 +1810,62 @@ def export_market_grid_outputs(
|
||||
prefer_geometry=True,
|
||||
):
|
||||
user_count_5g_invalid_grid_ids += 1
|
||||
|
||||
competitor_total = numeric_values[EXCELLENT_CELL_FIELD]
|
||||
competitor_rsrp = numeric_values[RSRP_FIELD]
|
||||
competitor_weak = numeric_values[WEAK_COVER_FIELD]
|
||||
mobile_total = numeric_values[MOBILE_TOTAL_FIELD]
|
||||
mobile_weak = numeric_values[MOBILE_WEAK_COVER_FIELD]
|
||||
exclusion_reason = competitor_signal_filter_reason(
|
||||
mobile_weak,
|
||||
mobile_total,
|
||||
competitor_weak,
|
||||
competitor_total,
|
||||
)
|
||||
if exclusion_reason is not None:
|
||||
exclusion_counts[exclusion_reason] += 1
|
||||
continue
|
||||
if competitor_total != 0 and (competitor_rsrp is None or competitor_rsrp > 0):
|
||||
exclusion_counts["invalid_rsrp"] += 1
|
||||
continue
|
||||
|
||||
signal_window = pixel_window_for_bounds(
|
||||
geometry_bounds[index],
|
||||
minx,
|
||||
maxy,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
width,
|
||||
height,
|
||||
)
|
||||
if signal_window is None:
|
||||
exclusion_counts["no_center_pixels"] += 1
|
||||
continue
|
||||
geometry_mask = pixel_center_mask_for_geometry(
|
||||
geometries[index],
|
||||
signal_window,
|
||||
minx,
|
||||
maxy,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
)
|
||||
geometry_pixel_count = int(np.count_nonzero(geometry_mask))
|
||||
if geometry_pixel_count == 0:
|
||||
exclusion_counts["no_center_pixels"] += 1
|
||||
continue
|
||||
|
||||
row_start, row_stop, col_start, col_stop = signal_window
|
||||
if competitor_total == 0:
|
||||
zero_total_view = zero_total_mask[row_start:row_stop, col_start:col_stop]
|
||||
zero_total_view |= geometry_mask
|
||||
zero_total_cells += 1
|
||||
else:
|
||||
value_sum_view = competitor_signal_value_sum[row_start:row_stop, col_start:col_stop]
|
||||
value_weight_view = competitor_signal_value_weight[row_start:row_stop, col_start:col_stop]
|
||||
value_sum_view[geometry_mask] += competitor_rsrp
|
||||
value_weight_view[geometry_mask] += 1
|
||||
competitor_signal_cells += 1
|
||||
exact_geometry_pixels += geometry_pixel_count
|
||||
finally:
|
||||
if csv_file is not None:
|
||||
csv_file.close()
|
||||
@@ -1861,43 +1915,6 @@ def export_market_grid_outputs(
|
||||
user_count_result.update(merged_user_count_metadata(user_count_records, source_stats))
|
||||
del user_count_state
|
||||
|
||||
competitor_signal_value_sum = np.zeros((height, width), dtype=np.float32)
|
||||
competitor_signal_value_weight = np.zeros((height, width), dtype=np.uint16)
|
||||
zero_total_mask = np.zeros((height, width), dtype=bool)
|
||||
competitor_signal_cells = 0
|
||||
zero_total_cells = 0
|
||||
exclusion_counts = {
|
||||
"invalid_fields": 0,
|
||||
"mobile_weak_ratio": 0,
|
||||
"competitor_weak_ratio": 0,
|
||||
"invalid_rsrp": 0,
|
||||
}
|
||||
for cell in raster_cells:
|
||||
competitor_total = cell[4]
|
||||
competitor_rsrp = cell[5]
|
||||
competitor_weak = cell[6]
|
||||
mobile_total = cell[7]
|
||||
mobile_weak = cell[8]
|
||||
exclusion_reason = competitor_signal_filter_reason(
|
||||
mobile_weak,
|
||||
mobile_total,
|
||||
competitor_weak,
|
||||
competitor_total,
|
||||
)
|
||||
if exclusion_reason is not None:
|
||||
exclusion_counts[exclusion_reason] += 1
|
||||
continue
|
||||
row_start, row_stop, col_start, col_stop = cell[:4]
|
||||
if competitor_total == 0:
|
||||
zero_total_mask[row_start:row_stop, col_start:col_stop] = True
|
||||
zero_total_cells += 1
|
||||
else:
|
||||
if competitor_rsrp is None or competitor_rsrp > 0:
|
||||
exclusion_counts["invalid_rsrp"] += 1
|
||||
continue
|
||||
competitor_signal_value_sum[row_start:row_stop, col_start:col_stop] += competitor_rsrp
|
||||
competitor_signal_value_weight[row_start:row_stop, col_start:col_stop] += 1
|
||||
competitor_signal_cells += 1
|
||||
competitor_signal_state = {
|
||||
"value_sum": competitor_signal_value_sum,
|
||||
"value_weight": competitor_signal_value_weight,
|
||||
@@ -1920,6 +1937,8 @@ def export_market_grid_outputs(
|
||||
competitor_signal_result.update({
|
||||
"data_source": str(GRID_5G_GPKG),
|
||||
"uses_merged_user_count": False,
|
||||
"geometry_rasterization": "pixel_center_inside_polygon",
|
||||
"exact_geometry_pixels": exact_geometry_pixels,
|
||||
"mobile_weak_ratio_formula": f"{MOBILE_WEAK_COVER_FIELD} / {MOBILE_TOTAL_FIELD} * 100",
|
||||
"mobile_weak_ratio_operator": "<",
|
||||
"mobile_weak_ratio_threshold": COMPETITOR_SIGNAL_MOBILE_WEAK_RATIO_MAX,
|
||||
|
||||
@@ -153,6 +153,46 @@ class CompetitorSignalTest(unittest.TestCase):
|
||||
self.assertEqual(valid_mask.tolist(), [[True] * 10 + [False, False]])
|
||||
self.assertEqual(colors[0, 10:].tolist(), [[0, 0, 0], [0, 0, 0]])
|
||||
|
||||
def test_adjacent_grid_geometries_do_not_share_pixels(self):
|
||||
canvas = {
|
||||
"minx": -0.1,
|
||||
"maxy": 1.0,
|
||||
"pixel_width": 0.25,
|
||||
"pixel_height": 0.25,
|
||||
"width": 9,
|
||||
"height": 4,
|
||||
}
|
||||
left_geometry = box(0, 0, 1, 1)
|
||||
right_geometry = box(1, 0, 2, 1)
|
||||
left_window = main.pixel_window_for_bounds(left_geometry.bounds, **canvas)
|
||||
right_window = main.pixel_window_for_bounds(right_geometry.bounds, **canvas)
|
||||
left_mask = main.pixel_center_mask_for_geometry(
|
||||
left_geometry,
|
||||
left_window,
|
||||
canvas["minx"],
|
||||
canvas["maxy"],
|
||||
canvas["pixel_width"],
|
||||
canvas["pixel_height"],
|
||||
)
|
||||
right_mask = main.pixel_center_mask_for_geometry(
|
||||
right_geometry,
|
||||
right_window,
|
||||
canvas["minx"],
|
||||
canvas["maxy"],
|
||||
canvas["pixel_width"],
|
||||
canvas["pixel_height"],
|
||||
)
|
||||
left_pixels = np.zeros((canvas["height"], canvas["width"]), dtype=bool)
|
||||
right_pixels = np.zeros_like(left_pixels)
|
||||
lr0, lr1, lc0, lc1 = left_window
|
||||
rr0, rr1, rc0, rc1 = right_window
|
||||
left_pixels[lr0:lr1, lc0:lc1] = left_mask
|
||||
right_pixels[rr0:rr1, rc0:rc1] = right_mask
|
||||
|
||||
self.assertFalse(np.any(left_pixels & right_pixels))
|
||||
self.assertFalse(left_pixels[:, 4].any())
|
||||
self.assertTrue(right_pixels[:, 4].all())
|
||||
|
||||
def test_zero_competitor_samples_render_red_without_rsrp(self):
|
||||
state = {
|
||||
"value_sum": np.array([[-90.0, 0.0]], dtype=np.float32),
|
||||
|
||||
Reference in New Issue
Block a user