简表:半高展宽插值修正 + 只统计导出峰 + Q_system 与 R_50%H
- 修正半高交点插值(原来用了上一点,左展宽会被压到 0.1 px 量级) - 统计只覆盖被选中导出的峰,pick 掉的连续结构不再进入 Q - 新增 R_50%H = lambda / FWHM_lambda 与 peak_summary.csv 的 wavelength_nm / fwhm_nm / R 列
This commit is contained in:
1 parent
5e40fe65db
commit
234e3c1bb5
1 file changed
+33
-14
+33
-14
@@ -868,15 +868,18 @@ def ten_percent_widths(spectrum: "SpectrumData", line: dict,
|
||||
position += step
|
||||
current = float(net[position])
|
||||
if current <= level:
|
||||
# interpolate between the two bracketing samples
|
||||
# interpolate between the bracketing samples: x[position] is below
|
||||
# the level, x[position - step] is above it
|
||||
span = previous - current
|
||||
offset = (previous - level) / span if span else 0.0
|
||||
return float(x[position]) - step * offset * float(x[1] - x[0])
|
||||
fraction = (level - current) / span if span else 0.0
|
||||
crossing = (float(x[position])
|
||||
+ fraction * (float(x[position - step]) - float(x[position])))
|
||||
return abs(crossing - center)
|
||||
previous = current
|
||||
return float("nan")
|
||||
|
||||
left = center - walk(-1)
|
||||
right = walk(+1) - center
|
||||
left = walk(-1)
|
||||
right = walk(+1)
|
||||
ratio = (right / left) if np.isfinite(left) and np.isfinite(right) and left > 0 else float("nan")
|
||||
return {"channel": channel, "left_px": left, "right_px": right,
|
||||
"ratio": ratio, "level_adu": level}
|
||||
@@ -1506,8 +1509,11 @@ def run(args) -> int:
|
||||
if args.output is None:
|
||||
args.output = str(default_output_directory(args.input, indices))
|
||||
|
||||
# Only the peaks being exported enter the summary: with --pick the user has
|
||||
# already thrown away the continuum bumps and other non-line features.
|
||||
chosen = [line for line in lines if line["id"] in selected]
|
||||
shapes = []
|
||||
for line in lines:
|
||||
for line in chosen:
|
||||
gaps = [abs(other["sensor_x_px"] - line["sensor_x_px"])
|
||||
for other in lines if other is not line]
|
||||
limit = 0.5 * min(gaps) if gaps else float("nan")
|
||||
@@ -1516,7 +1522,7 @@ def run(args) -> int:
|
||||
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):
|
||||
for line, shape in zip(chosen, shapes):
|
||||
ratio = shape["ratio"]
|
||||
if not np.isfinite(ratio) or ratio <= 0:
|
||||
continue
|
||||
@@ -1534,11 +1540,22 @@ def run(args) -> int:
|
||||
"q_system": q_system, "n_lines": len(ratios)}}
|
||||
result = export_all(hq, spectrum, lines, calibration, selected, args, meta_out)
|
||||
|
||||
def resolving_power(line):
|
||||
wave = line.get("wavelength_nm", float("nan"))
|
||||
width = line.get("fwhm_nm", float("nan"))
|
||||
if not (np.isfinite(wave) and np.isfinite(width)) or width <= 0:
|
||||
return float("nan")
|
||||
return float(wave / width)
|
||||
|
||||
powers = [resolving_power(line) for line in chosen]
|
||||
write_csv(result["output"] / "peak_summary.csv",
|
||||
["id", "x_px", "left_half_px", "right_half_px", "ratio_right_over_left"],
|
||||
["id", "x_px", "left_half_px", "right_half_px", "ratio_right_over_left",
|
||||
"wavelength_nm", "fwhm_nm", "R_50pctH"],
|
||||
([line["id"], _num(line["sensor_x_px"], 4), _num(shape["left_px"], 4),
|
||||
_num(shape["right_px"], 4), _num(shape["ratio"], 4)]
|
||||
for line, shape in zip(lines, shapes)))
|
||||
_num(shape["right_px"], 4), _num(shape["ratio"], 4),
|
||||
_num(line.get("wavelength_nm"), 4), _num(line.get("fwhm_nm"), 4),
|
||||
_num(power, 5)]
|
||||
for line, shape, power in zip(chosen, shapes, powers)))
|
||||
|
||||
tell("")
|
||||
tell(f"{'':2s}{'id':4s}{'nm':>10s}{'x_px':>10s}{'ch':>4s}{'SNR':>9s}{'height':>9s}"
|
||||
@@ -1563,16 +1580,18 @@ def run(args) -> int:
|
||||
if lines:
|
||||
tell("")
|
||||
tell("half-height widths (asymmetry = right / left):")
|
||||
tell(f"{'id':6s}{'x_px':>11s}{'left':>9s}{'right':>9s}{'ratio':>8s}")
|
||||
for line, shape in zip(lines, shapes):
|
||||
tell(f"{'id':6s}{'x_px':>11s}{'left':>9s}{'right':>9s}{'ratio':>8s}"
|
||||
f"{'R_50%H':>9s}")
|
||||
for line, shape, power in zip(chosen, shapes, powers):
|
||||
def _shape(value):
|
||||
return f"{'nan':>8s}" if not np.isfinite(value) else f"{value:8.3f}"
|
||||
tell(f"{line['id']:6s}{line['sensor_x_px']:11.3f}"
|
||||
f"{_shape(shape['left_px'])}{_shape(shape['right_px'])}"
|
||||
f"{_shape(shape['ratio'])}")
|
||||
f"{_shape(shape['ratio'])}"
|
||||
f"{('nan' if not np.isfinite(power) else f'{power:9.0f}'):>9s}")
|
||||
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)")
|
||||
f"N = {len(ratios)} of {len(chosen)} exported)")
|
||||
tell(f"exported : {result['output'].expanduser().resolve()}")
|
||||
if calibration is not None:
|
||||
outside = [line["id"] for line in lines if line["extrapolated"]]
|
||||
|
||||
Reference in new issue
Block a user