跨通道聚类改用拟合中心:通道间偏差超过 --group-tol 就分成两条峰

检测位置只差 1 px、但 R/G 拟合中心差了 6 px 的那种线,以前会被合成一条;

现在按拟合中心聚类,分开后可在 pick 里按 m 手动合并。
This commit is contained in:
starcells committed 2026-11-14 15:37:29 +08:00
1 parent 5ed1733ccc
commit 31e41f6519
1 file changed
+4 -4
+4 -4
View File
@@ -801,10 +801,10 @@ def group_channels(peaks: dict[str, list[dict]], tolerance_px: float,
merge_tolerance_px: float = 1.5) -> list[dict]:
"""Merge per-channel peaks that belong to the same spectral line."""
# Cluster on the detected local maxima, not on the fitted centres: a single
# peak fit inside a blend is pulled towards its neighbour and would wrongly
# merge two resolved lines.
flat = [(item["sensor_x_px"], channel, item)
# Cluster on the fitted centres: if two channels put the line more than
# `tolerance_px` apart they are not the same feature, and the user can still
# join them by hand in the picker (m).
flat = [(item.get("center_px", item["sensor_x_px"]), channel, item)
for channel, items in peaks.items() for item in items]
flat.sort(key=lambda row: row[0])
groups: list[list[tuple[float, str, dict]]] = []