From 5e40fe65dbb2f0206bd0fce7c0619fead65fe65d Mon Sep 17 00:00:00 2001 From: StarCells Date: Sat, 14 Nov 2026 16:37:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E8=A1=A8=E6=9C=AB=E5=B0=BE=E8=BE=93?= =?UTF-8?q?=E5=87=BA=20Q=5Fsystem=20=3D=20exp(mean|ln=20A=5Fi|)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - A_i = 半高右展宽/左展宽;宽带结构(FWHM > 3x 中位数)与翼被截断的线不计入 - 同时打印参与统计的峰编号与 N --- peak_finder.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/peak_finder.py b/peak_finder.py index b8c62c3..3bae0be 100644 --- a/peak_finder.py +++ b/peak_finder.py @@ -1505,9 +1505,6 @@ def run(args) -> int: if args.output is None: args.output = str(default_output_directory(args.input, indices)) - meta_out = {"created": _timestamp(), - "recording": str(Path(args.input).expanduser().resolve())} - result = export_all(hq, spectrum, lines, calibration, selected, args, meta_out) shapes = [] for line in lines: @@ -1515,6 +1512,28 @@ def run(args) -> int: for other in lines if other is not line] limit = 0.5 * min(gaps) if gaps else float("nan") shapes.append(ten_percent_widths(spectrum, line, limit_px=limit)) + widths = np.array([line["fwhm_px"] for line in lines + if np.isfinite(line["fwhm_px"])]) + median_width = float(np.median(widths)) if widths.size else float("nan") + ratios, used_ids = [], [] + for line, shape in zip(lines, shapes): + ratio = shape["ratio"] + if not np.isfinite(ratio) or ratio <= 0: + continue + if (np.isfinite(median_width) and np.isfinite(line["fwhm_px"]) + and line["fwhm_px"] > 3.0 * median_width): + continue # broad continuum structure, not a line + ratios.append(ratio) + used_ids.append(line["id"]) + q_system = (float(np.exp(np.mean(np.abs(np.log(ratios))))) if ratios else float("nan")) + + meta_out = {"created": _timestamp(), + "recording": str(Path(args.input).expanduser().resolve()), + "asymmetry": {"formula": "Q_system = exp(mean(|ln(A_i)|))", + "A_i": "right_half_width / left_half_width", + "q_system": q_system, "n_lines": len(ratios)}} + result = export_all(hq, spectrum, lines, calibration, selected, args, meta_out) + write_csv(result["output"] / "peak_summary.csv", ["id", "x_px", "left_half_px", "right_half_px", "ratio_right_over_left"], ([line["id"], _num(line["sensor_x_px"], 4), _num(shape["left_px"], 4), @@ -1551,6 +1570,9 @@ def run(args) -> int: tell(f"{line['id']:6s}{line['sensor_x_px']:11.3f}" f"{_shape(shape['left_px'])}{_shape(shape['right_px'])}" f"{_shape(shape['ratio'])}") + if np.isfinite(q_system): + tell(f"Q_system = exp(mean|ln A_i|) = {q_system:.4f} (A_i = right/left, " + f"N = {len(ratios)} of {len(lines)} lines)") tell(f"exported : {result['output'].expanduser().resolve()}") if calibration is not None: outside = [line["id"] for line in lines if line["extrapolated"]]