feat: 增加信号差用户量热力图
This commit is contained in:
@@ -39,3 +39,5 @@
|
||||
- 采样点数量热力图会先平滑字段值,再按 `EXCELLENT_COLORS` 在红、黄、蓝、绿之间连续插值;图例写入 `output/excellent_heatmap_legend.csv`,每个市场的实际阈值写入 `summary.json` 的 `excellent_heatmap_results`。
|
||||
- 当前测试市场 `JM010404` 的 `mr_dl_excellent_cell_dl` 去重分位阈值为 `[1204.0, 749.0, 471.0]`,输出验证为 886 种有效颜色加透明背景。
|
||||
- 输出文件名已改为业务中文名:RSRP 连续热力图输出 `信号.tif`,`mr_dl_excellent_cell_dl` 用户量热力图输出 `用户量.tif`;文件名由 `SIGNAL_OUTPUT_FILENAME` 和 `USER_COUNT_OUTPUT_FILENAME` 配置。
|
||||
- 新增 `mr_dl_lt105_weak_cover_rate_dl` 信号差用户量连续热力图,输出为 `output/JMXXXX/信号差用户量.tif`,复用用户量热力图的去重分位阈值、红黄蓝绿连续渐变、透明度和平滑规则。
|
||||
- 当前测试市场 `JM010404` 的 `mr_dl_lt105_weak_cover_rate_dl` 去重分位阈值为 `[30.43, 16.95, 9.47]`,输出验证为 889 种有效颜色加透明背景。
|
||||
|
||||
@@ -19,6 +19,7 @@ MARKET_GPKG = DEFAULT_SOURCE_DIR / "MarketMap.gpkg" # 市场网格 GeoPackage
|
||||
GRID_GPKG = DEFAULT_SOURCE_DIR / "grid.gpkg" # Grid 栅格指标 GeoPackage 文件路径。
|
||||
RSRP_FIELD = "ssb_rsrp_dx" # 用于生成热力图的电信 RSRP 字段名。
|
||||
EXCELLENT_CELL_FIELD = "mr_dl_excellent_cell_dl" # 用于生成采样点数量热力图的字段名,值越大越红。
|
||||
WEAK_COVER_FIELD = "mr_dl_lt105_weak_cover_rate_dl" # 用于生成信号差用户量热力图的字段名,值越大越红。
|
||||
MARKET_LAYER = None # 市场网格图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
GRID_LAYER = None # Grid 指标图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
MARKET_CODE_FIELD = "micro_grid" # 市场网格编码字段,用于输出文件夹名,例如 JM010404。
|
||||
@@ -30,6 +31,7 @@ HEATMAP_BAD_RSRP = -110.0 # 热力图红色端阈值;RSRP 小于等于该值
|
||||
HEATMAP_SMOOTH_RADIUS = 10 # 热力图平滑半径,数值越大边界感越弱但细节越柔。
|
||||
HEATMAP_ALPHA = 191 # 热力图有效像元透明度;191 约等于 75% 不透明度。
|
||||
USER_COUNT_OUTPUT_FILENAME = "用户量.tif" # 采样点数量热力图输出文件名。
|
||||
WEAK_COVER_OUTPUT_FILENAME = "信号差用户量.tif" # 信号差用户量热力图输出文件名。
|
||||
EXCELLENT_PERCENT_STEPS = (0.2, 0.4, 0.6) # 去重值降序分位阈值,默认按前 20%、40%、60% 作为连续渐变控制点。
|
||||
EXCELLENT_COLORS = (
|
||||
(255, 0, 0), # 高值端,红色。
|
||||
@@ -86,6 +88,10 @@ def excellent_heatmap_raster_filename(_field):
|
||||
return USER_COUNT_OUTPUT_FILENAME
|
||||
|
||||
|
||||
def weak_cover_heatmap_raster_filename(_field):
|
||||
return WEAK_COVER_OUTPUT_FILENAME
|
||||
|
||||
|
||||
def gpkg_blob_to_wkb(blob):
|
||||
data = bytes(blob)
|
||||
if data[:2] != b"GP":
|
||||
@@ -617,6 +623,19 @@ def write_excellent_heatmap_legend(output_dir, field):
|
||||
return legend_path
|
||||
|
||||
|
||||
def write_weak_cover_heatmap_legend(output_dir, field):
|
||||
legend_path = output_dir / "weak_cover_heatmap_legend.csv"
|
||||
with legend_path.open("w", newline="", encoding="utf-8-sig") as file:
|
||||
writer = csv.writer(file)
|
||||
writer.writerow(["field", "control_point", "red", "green", "blue", "alpha", "meaning"])
|
||||
writer.writerow([field, "threshold_20_percent", *EXCELLENT_COLORS[0], HEATMAP_ALPHA, "high end"])
|
||||
writer.writerow([field, "threshold_40_percent", *EXCELLENT_COLORS[1], HEATMAP_ALPHA, "high-middle control"])
|
||||
writer.writerow([field, "threshold_60_percent", *EXCELLENT_COLORS[2], HEATMAP_ALPHA, "low-middle control"])
|
||||
writer.writerow([field, "minimum", *EXCELLENT_COLORS[3], HEATMAP_ALPHA, "low end"])
|
||||
writer.writerow([field, "nodata", 0, 0, 0, 0, "transparent no data"])
|
||||
return legend_path
|
||||
|
||||
|
||||
def main():
|
||||
if SCALE <= 0:
|
||||
raise ValueError("SCALE 必须大于 0")
|
||||
@@ -631,7 +650,11 @@ def main():
|
||||
if market_layer.srs_id != 4326 or grid_layer.srs_id != 4326:
|
||||
raise ValueError("当前脚本只处理 EPSG:4326 的输入图层")
|
||||
|
||||
require_columns(grid_conn, grid_layer.table_name, [RSRP_FIELD, EXCELLENT_CELL_FIELD, "longitude", "latitude"])
|
||||
require_columns(
|
||||
grid_conn,
|
||||
grid_layer.table_name,
|
||||
[RSRP_FIELD, EXCELLENT_CELL_FIELD, WEAK_COVER_FIELD, "longitude", "latitude"],
|
||||
)
|
||||
grid_rtree = rtree_name(grid_conn, grid_layer)
|
||||
pixel_width = PIXEL_WIDTH
|
||||
pixel_height = PIXEL_HEIGHT
|
||||
@@ -653,16 +676,20 @@ def main():
|
||||
|
||||
heatmap_legend_path = write_heatmap_legend(OUTPUT_DIR, RSRP_FIELD)
|
||||
excellent_legend_path = write_excellent_heatmap_legend(OUTPUT_DIR, EXCELLENT_CELL_FIELD)
|
||||
weak_cover_legend_path = write_weak_cover_heatmap_legend(OUTPUT_DIR, WEAK_COVER_FIELD)
|
||||
heatmap_results = []
|
||||
excellent_heatmap_results = []
|
||||
weak_cover_heatmap_results = []
|
||||
print(f"市场网格数量:{len(markets)}")
|
||||
print(f"Grid 图层:{grid_layer.table_name}")
|
||||
print(f"RSRP 字段:{RSRP_FIELD}")
|
||||
print(f"采样点字段:{EXCELLENT_CELL_FIELD}")
|
||||
print(f"信号差用户量字段:{WEAK_COVER_FIELD}")
|
||||
print(f"分辨率倍数:{SCALE}")
|
||||
print(f"像元大小:{pixel_width}, {pixel_height}")
|
||||
print(f"热力图图例:{heatmap_legend_path}")
|
||||
print(f"采样点热力图图例:{excellent_legend_path}")
|
||||
print(f"信号差用户量热力图图例:{weak_cover_legend_path}")
|
||||
|
||||
for index, market in enumerate(markets, start=1):
|
||||
market_dir = market_output_dir(OUTPUT_DIR, market)
|
||||
@@ -733,18 +760,53 @@ def main():
|
||||
f"阈值:{excellent_result['thresholds']}"
|
||||
)
|
||||
|
||||
weak_cover_path = market_dir / weak_cover_heatmap_raster_filename(WEAK_COVER_FIELD)
|
||||
if weak_cover_path.exists() and not OVERWRITE:
|
||||
print(f" 跳过已存在信号差用户量热力图:{weak_cover_path.name}")
|
||||
weak_cover_heatmap_results.append(
|
||||
{
|
||||
"market_code": market.code,
|
||||
"market_name": market.name,
|
||||
"market_dir": str(market_dir),
|
||||
"output": str(weak_cover_path),
|
||||
"skipped": True,
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
print(f" 导出信号差用户量热力图:{weak_cover_path.name}")
|
||||
weak_cover_result = export_market_excellent_heatmap_tif(
|
||||
grid_conn,
|
||||
grid_layer,
|
||||
grid_rtree,
|
||||
market,
|
||||
WEAK_COVER_FIELD,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
weak_cover_path,
|
||||
)
|
||||
weak_cover_result["market_dir"] = str(market_dir)
|
||||
weak_cover_result["skipped"] = False
|
||||
weak_cover_heatmap_results.append(weak_cover_result)
|
||||
print(
|
||||
f" 信号差用户量热力图像素:{weak_cover_result['width']}x{weak_cover_result['height']},"
|
||||
f"阈值:{weak_cover_result['thresholds']}"
|
||||
)
|
||||
|
||||
summary_path = OUTPUT_DIR / "summary.json"
|
||||
summary = {
|
||||
"market_gpkg": str(MARKET_GPKG),
|
||||
"grid_gpkg": str(GRID_GPKG),
|
||||
"rsrp_field": RSRP_FIELD,
|
||||
"excellent_cell_field": EXCELLENT_CELL_FIELD,
|
||||
"weak_cover_field": WEAK_COVER_FIELD,
|
||||
"clip_mode": CLIP_MODE,
|
||||
"scale": SCALE,
|
||||
"pixel_width": pixel_width,
|
||||
"pixel_height": pixel_height,
|
||||
"heatmap_results": heatmap_results,
|
||||
"excellent_heatmap_results": excellent_heatmap_results,
|
||||
"weak_cover_heatmap_results": weak_cover_heatmap_results,
|
||||
}
|
||||
summary_path.write_text(json.dumps(summary, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
print(f"汇总:{summary_path}")
|
||||
|
||||
Reference in New Issue
Block a user