diff --git a/src/gui/panels/step12_viz_panel.py b/src/gui/panels/step12_viz_panel.py index 606eb85..14fa2c3 100644 --- a/src/gui/panels/step12_viz_panel.py +++ b/src/gui/panels/step12_viz_panel.py @@ -46,16 +46,31 @@ def _viz_training_spectra_csv_path(work_path: Path) -> Path: def _viz_infer_wavelength_start_column(df: pd.DataFrame) -> Union[str, int]: """推断光谱起始列(training_spectra 通常以波长数值为列名,未必含 UTM_Y)。""" + import re + # 兼容前缀:nm / nm_ / wavelength / wl / λ / wave_len(大小写不敏感) + _PREFIX_RE = re.compile(r"^(?:nm|wavelength|wl|\u03bb|wave_len)[_\s\-]*", re.IGNORECASE) for i, col in enumerate(df.columns): name = str(col).strip().lstrip("\ufeff") + # 1) 直接纯数字(如 "700.0") try: v = float(name) except ValueError: - continue - if 200.0 <= v <= 3000.0: + v = None + if v is not None and 200.0 <= v <= 3000.0: return i + # 2) 剥前缀后再试(如 "nm_700"、"wavelength_800.0"、"WL 900") + stripped = _PREFIX_RE.sub("", name) + if stripped != name: + try: + v = float(stripped) + except ValueError: + continue + if 200.0 <= v <= 3000.0: + return i if "UTM_Y" in df.columns: return "UTM_Y" + # 兜底分支触发时打印所有列名,便于下次失败时一眼看到根因 + print(f"DEBUG: 尝试解析的列名: {df.columns.tolist()}") return 0