diff --git a/spectro_core.py b/spectro_core.py index 4b73b07..f9dc564 100644 --- a/spectro_core.py +++ b/spectro_core.py @@ -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]]] = []